three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. var REVISION = '123dev';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = "100";
  259. var GLSL3 = "300 es";
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === void 0) {
  682. offset = 0;
  683. }
  684. this.x = array[offset];
  685. this.y = array[offset + 1];
  686. return this;
  687. };
  688. _proto.toArray = function toArray(array, offset) {
  689. if (array === void 0) {
  690. array = [];
  691. }
  692. if (offset === void 0) {
  693. offset = 0;
  694. }
  695. array[offset] = this.x;
  696. array[offset + 1] = this.y;
  697. return array;
  698. };
  699. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  700. if (offset !== undefined) {
  701. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  702. }
  703. this.x = attribute.getX(index);
  704. this.y = attribute.getY(index);
  705. return this;
  706. };
  707. _proto.rotateAround = function rotateAround(center, angle) {
  708. var c = Math.cos(angle),
  709. s = Math.sin(angle);
  710. var x = this.x - center.x;
  711. var y = this.y - center.y;
  712. this.x = x * c - y * s + center.x;
  713. this.y = x * s + y * c + center.y;
  714. return this;
  715. };
  716. _proto.random = function random() {
  717. this.x = Math.random();
  718. this.y = Math.random();
  719. return this;
  720. };
  721. _createClass(Vector2, [{
  722. key: "width",
  723. get: function get() {
  724. return this.x;
  725. },
  726. set: function set(value) {
  727. this.x = value;
  728. }
  729. }, {
  730. key: "height",
  731. get: function get() {
  732. return this.y;
  733. },
  734. set: function set(value) {
  735. this.y = value;
  736. }
  737. }]);
  738. return Vector2;
  739. }();
  740. var Matrix3 = /*#__PURE__*/function () {
  741. function Matrix3() {
  742. Object.defineProperty(this, 'isMatrix3', {
  743. value: true
  744. });
  745. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  746. if (arguments.length > 0) {
  747. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  748. }
  749. }
  750. var _proto = Matrix3.prototype;
  751. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  752. var te = this.elements;
  753. te[0] = n11;
  754. te[1] = n21;
  755. te[2] = n31;
  756. te[3] = n12;
  757. te[4] = n22;
  758. te[5] = n32;
  759. te[6] = n13;
  760. te[7] = n23;
  761. te[8] = n33;
  762. return this;
  763. };
  764. _proto.identity = function identity() {
  765. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  766. return this;
  767. };
  768. _proto.clone = function clone() {
  769. return new this.constructor().fromArray(this.elements);
  770. };
  771. _proto.copy = function copy(m) {
  772. var te = this.elements;
  773. var me = m.elements;
  774. te[0] = me[0];
  775. te[1] = me[1];
  776. te[2] = me[2];
  777. te[3] = me[3];
  778. te[4] = me[4];
  779. te[5] = me[5];
  780. te[6] = me[6];
  781. te[7] = me[7];
  782. te[8] = me[8];
  783. return this;
  784. };
  785. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  786. xAxis.setFromMatrix3Column(this, 0);
  787. yAxis.setFromMatrix3Column(this, 1);
  788. zAxis.setFromMatrix3Column(this, 2);
  789. return this;
  790. };
  791. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  792. var me = m.elements;
  793. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  794. return this;
  795. };
  796. _proto.multiply = function multiply(m) {
  797. return this.multiplyMatrices(this, m);
  798. };
  799. _proto.premultiply = function premultiply(m) {
  800. return this.multiplyMatrices(m, this);
  801. };
  802. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  803. var ae = a.elements;
  804. var be = b.elements;
  805. var te = this.elements;
  806. var a11 = ae[0],
  807. a12 = ae[3],
  808. a13 = ae[6];
  809. var a21 = ae[1],
  810. a22 = ae[4],
  811. a23 = ae[7];
  812. var a31 = ae[2],
  813. a32 = ae[5],
  814. a33 = ae[8];
  815. var b11 = be[0],
  816. b12 = be[3],
  817. b13 = be[6];
  818. var b21 = be[1],
  819. b22 = be[4],
  820. b23 = be[7];
  821. var b31 = be[2],
  822. b32 = be[5],
  823. b33 = be[8];
  824. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  825. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  826. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  827. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  828. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  829. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  830. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  831. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  832. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  833. return this;
  834. };
  835. _proto.multiplyScalar = function multiplyScalar(s) {
  836. var te = this.elements;
  837. te[0] *= s;
  838. te[3] *= s;
  839. te[6] *= s;
  840. te[1] *= s;
  841. te[4] *= s;
  842. te[7] *= s;
  843. te[2] *= s;
  844. te[5] *= s;
  845. te[8] *= s;
  846. return this;
  847. };
  848. _proto.determinant = function determinant() {
  849. var te = this.elements;
  850. var a = te[0],
  851. b = te[1],
  852. c = te[2],
  853. d = te[3],
  854. e = te[4],
  855. f = te[5],
  856. g = te[6],
  857. h = te[7],
  858. i = te[8];
  859. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  860. };
  861. _proto.invert = function invert() {
  862. var te = this.elements,
  863. n11 = te[0],
  864. n21 = te[1],
  865. n31 = te[2],
  866. n12 = te[3],
  867. n22 = te[4],
  868. n32 = te[5],
  869. n13 = te[6],
  870. n23 = te[7],
  871. n33 = te[8],
  872. t11 = n33 * n22 - n32 * n23,
  873. t12 = n32 * n13 - n33 * n12,
  874. t13 = n23 * n12 - n22 * n13,
  875. det = n11 * t11 + n21 * t12 + n31 * t13;
  876. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  877. var detInv = 1 / det;
  878. te[0] = t11 * detInv;
  879. te[1] = (n31 * n23 - n33 * n21) * detInv;
  880. te[2] = (n32 * n21 - n31 * n22) * detInv;
  881. te[3] = t12 * detInv;
  882. te[4] = (n33 * n11 - n31 * n13) * detInv;
  883. te[5] = (n31 * n12 - n32 * n11) * detInv;
  884. te[6] = t13 * detInv;
  885. te[7] = (n21 * n13 - n23 * n11) * detInv;
  886. te[8] = (n22 * n11 - n21 * n12) * detInv;
  887. return this;
  888. };
  889. _proto.transpose = function transpose() {
  890. var tmp;
  891. var m = this.elements;
  892. tmp = m[1];
  893. m[1] = m[3];
  894. m[3] = tmp;
  895. tmp = m[2];
  896. m[2] = m[6];
  897. m[6] = tmp;
  898. tmp = m[5];
  899. m[5] = m[7];
  900. m[7] = tmp;
  901. return this;
  902. };
  903. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  904. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  905. };
  906. _proto.transposeIntoArray = function transposeIntoArray(r) {
  907. var m = this.elements;
  908. r[0] = m[0];
  909. r[1] = m[3];
  910. r[2] = m[6];
  911. r[3] = m[1];
  912. r[4] = m[4];
  913. r[5] = m[7];
  914. r[6] = m[2];
  915. r[7] = m[5];
  916. r[8] = m[8];
  917. return this;
  918. };
  919. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  920. var c = Math.cos(rotation);
  921. var s = Math.sin(rotation);
  922. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  923. };
  924. _proto.scale = function scale(sx, sy) {
  925. var te = this.elements;
  926. te[0] *= sx;
  927. te[3] *= sx;
  928. te[6] *= sx;
  929. te[1] *= sy;
  930. te[4] *= sy;
  931. te[7] *= sy;
  932. return this;
  933. };
  934. _proto.rotate = function rotate(theta) {
  935. var c = Math.cos(theta);
  936. var s = Math.sin(theta);
  937. var te = this.elements;
  938. var a11 = te[0],
  939. a12 = te[3],
  940. a13 = te[6];
  941. var a21 = te[1],
  942. a22 = te[4],
  943. a23 = te[7];
  944. te[0] = c * a11 + s * a21;
  945. te[3] = c * a12 + s * a22;
  946. te[6] = c * a13 + s * a23;
  947. te[1] = -s * a11 + c * a21;
  948. te[4] = -s * a12 + c * a22;
  949. te[7] = -s * a13 + c * a23;
  950. return this;
  951. };
  952. _proto.translate = function translate(tx, ty) {
  953. var te = this.elements;
  954. te[0] += tx * te[2];
  955. te[3] += tx * te[5];
  956. te[6] += tx * te[8];
  957. te[1] += ty * te[2];
  958. te[4] += ty * te[5];
  959. te[7] += ty * te[8];
  960. return this;
  961. };
  962. _proto.equals = function equals(matrix) {
  963. var te = this.elements;
  964. var me = matrix.elements;
  965. for (var i = 0; i < 9; i++) {
  966. if (te[i] !== me[i]) return false;
  967. }
  968. return true;
  969. };
  970. _proto.fromArray = function fromArray(array, offset) {
  971. if (offset === void 0) {
  972. offset = 0;
  973. }
  974. for (var i = 0; i < 9; i++) {
  975. this.elements[i] = array[i + offset];
  976. }
  977. return this;
  978. };
  979. _proto.toArray = function toArray(array, offset) {
  980. if (array === void 0) {
  981. array = [];
  982. }
  983. if (offset === void 0) {
  984. offset = 0;
  985. }
  986. var te = this.elements;
  987. array[offset] = te[0];
  988. array[offset + 1] = te[1];
  989. array[offset + 2] = te[2];
  990. array[offset + 3] = te[3];
  991. array[offset + 4] = te[4];
  992. array[offset + 5] = te[5];
  993. array[offset + 6] = te[6];
  994. array[offset + 7] = te[7];
  995. array[offset + 8] = te[8];
  996. return array;
  997. };
  998. return Matrix3;
  999. }();
  1000. var _canvas;
  1001. var ImageUtils = {
  1002. getDataURL: function getDataURL(image) {
  1003. if (/^data:/i.test(image.src)) {
  1004. return image.src;
  1005. }
  1006. if (typeof HTMLCanvasElement == 'undefined') {
  1007. return image.src;
  1008. }
  1009. var canvas;
  1010. if (image instanceof HTMLCanvasElement) {
  1011. canvas = image;
  1012. } else {
  1013. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1014. _canvas.width = image.width;
  1015. _canvas.height = image.height;
  1016. var context = _canvas.getContext('2d');
  1017. if (image instanceof ImageData) {
  1018. context.putImageData(image, 0, 0);
  1019. } else {
  1020. context.drawImage(image, 0, 0, image.width, image.height);
  1021. }
  1022. canvas = _canvas;
  1023. }
  1024. if (canvas.width > 2048 || canvas.height > 2048) {
  1025. return canvas.toDataURL('image/jpeg', 0.6);
  1026. } else {
  1027. return canvas.toDataURL('image/png');
  1028. }
  1029. }
  1030. };
  1031. var textureId = 0;
  1032. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1033. if (image === void 0) {
  1034. image = Texture.DEFAULT_IMAGE;
  1035. }
  1036. if (mapping === void 0) {
  1037. mapping = Texture.DEFAULT_MAPPING;
  1038. }
  1039. if (wrapS === void 0) {
  1040. wrapS = ClampToEdgeWrapping;
  1041. }
  1042. if (wrapT === void 0) {
  1043. wrapT = ClampToEdgeWrapping;
  1044. }
  1045. if (magFilter === void 0) {
  1046. magFilter = LinearFilter;
  1047. }
  1048. if (minFilter === void 0) {
  1049. minFilter = LinearMipmapLinearFilter;
  1050. }
  1051. if (format === void 0) {
  1052. format = RGBAFormat;
  1053. }
  1054. if (type === void 0) {
  1055. type = UnsignedByteType;
  1056. }
  1057. if (anisotropy === void 0) {
  1058. anisotropy = 1;
  1059. }
  1060. if (encoding === void 0) {
  1061. encoding = LinearEncoding;
  1062. }
  1063. Object.defineProperty(this, 'id', {
  1064. value: textureId++
  1065. });
  1066. this.uuid = MathUtils.generateUUID();
  1067. this.name = '';
  1068. this.image = image;
  1069. this.mipmaps = [];
  1070. this.mapping = mapping;
  1071. this.wrapS = wrapS;
  1072. this.wrapT = wrapT;
  1073. this.magFilter = magFilter;
  1074. this.minFilter = minFilter;
  1075. this.anisotropy = anisotropy;
  1076. this.format = format;
  1077. this.internalFormat = null;
  1078. this.type = type;
  1079. this.offset = new Vector2(0, 0);
  1080. this.repeat = new Vector2(1, 1);
  1081. this.center = new Vector2(0, 0);
  1082. this.rotation = 0;
  1083. this.matrixAutoUpdate = true;
  1084. this.matrix = new Matrix3();
  1085. this.generateMipmaps = true;
  1086. this.premultiplyAlpha = false;
  1087. this.flipY = true;
  1088. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1089. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1090. //
  1091. // Also changing the encoding after already used by a Material will not automatically make the Material
  1092. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1093. this.encoding = encoding;
  1094. this.version = 0;
  1095. this.onUpdate = null;
  1096. }
  1097. Texture.DEFAULT_IMAGE = undefined;
  1098. Texture.DEFAULT_MAPPING = UVMapping;
  1099. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1100. constructor: Texture,
  1101. isTexture: true,
  1102. updateMatrix: function updateMatrix() {
  1103. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1104. },
  1105. clone: function clone() {
  1106. return new this.constructor().copy(this);
  1107. },
  1108. copy: function copy(source) {
  1109. this.name = source.name;
  1110. this.image = source.image;
  1111. this.mipmaps = source.mipmaps.slice(0);
  1112. this.mapping = source.mapping;
  1113. this.wrapS = source.wrapS;
  1114. this.wrapT = source.wrapT;
  1115. this.magFilter = source.magFilter;
  1116. this.minFilter = source.minFilter;
  1117. this.anisotropy = source.anisotropy;
  1118. this.format = source.format;
  1119. this.internalFormat = source.internalFormat;
  1120. this.type = source.type;
  1121. this.offset.copy(source.offset);
  1122. this.repeat.copy(source.repeat);
  1123. this.center.copy(source.center);
  1124. this.rotation = source.rotation;
  1125. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1126. this.matrix.copy(source.matrix);
  1127. this.generateMipmaps = source.generateMipmaps;
  1128. this.premultiplyAlpha = source.premultiplyAlpha;
  1129. this.flipY = source.flipY;
  1130. this.unpackAlignment = source.unpackAlignment;
  1131. this.encoding = source.encoding;
  1132. return this;
  1133. },
  1134. toJSON: function toJSON(meta) {
  1135. var isRootObject = meta === undefined || typeof meta === 'string';
  1136. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1137. return meta.textures[this.uuid];
  1138. }
  1139. var output = {
  1140. metadata: {
  1141. version: 4.5,
  1142. type: 'Texture',
  1143. generator: 'Texture.toJSON'
  1144. },
  1145. uuid: this.uuid,
  1146. name: this.name,
  1147. mapping: this.mapping,
  1148. repeat: [this.repeat.x, this.repeat.y],
  1149. offset: [this.offset.x, this.offset.y],
  1150. center: [this.center.x, this.center.y],
  1151. rotation: this.rotation,
  1152. wrap: [this.wrapS, this.wrapT],
  1153. format: this.format,
  1154. type: this.type,
  1155. encoding: this.encoding,
  1156. minFilter: this.minFilter,
  1157. magFilter: this.magFilter,
  1158. anisotropy: this.anisotropy,
  1159. flipY: this.flipY,
  1160. premultiplyAlpha: this.premultiplyAlpha,
  1161. unpackAlignment: this.unpackAlignment
  1162. };
  1163. if (this.image !== undefined) {
  1164. // TODO: Move to THREE.Image
  1165. var image = this.image;
  1166. if (image.uuid === undefined) {
  1167. image.uuid = MathUtils.generateUUID(); // UGH
  1168. }
  1169. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1170. var url;
  1171. if (Array.isArray(image)) {
  1172. // process array of images e.g. CubeTexture
  1173. url = [];
  1174. for (var i = 0, l = image.length; i < l; i++) {
  1175. // check cube texture with data textures
  1176. if (image[i].isDataTexture) {
  1177. url.push(serializeImage(image[i].image));
  1178. } else {
  1179. url.push(serializeImage(image[i]));
  1180. }
  1181. }
  1182. } else {
  1183. // process single image
  1184. url = serializeImage(image);
  1185. }
  1186. meta.images[image.uuid] = {
  1187. uuid: image.uuid,
  1188. url: url
  1189. };
  1190. }
  1191. output.image = image.uuid;
  1192. }
  1193. if (!isRootObject) {
  1194. meta.textures[this.uuid] = output;
  1195. }
  1196. return output;
  1197. },
  1198. dispose: function dispose() {
  1199. this.dispatchEvent({
  1200. type: 'dispose'
  1201. });
  1202. },
  1203. transformUv: function transformUv(uv) {
  1204. if (this.mapping !== UVMapping) return uv;
  1205. uv.applyMatrix3(this.matrix);
  1206. if (uv.x < 0 || uv.x > 1) {
  1207. switch (this.wrapS) {
  1208. case RepeatWrapping:
  1209. uv.x = uv.x - Math.floor(uv.x);
  1210. break;
  1211. case ClampToEdgeWrapping:
  1212. uv.x = uv.x < 0 ? 0 : 1;
  1213. break;
  1214. case MirroredRepeatWrapping:
  1215. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1216. uv.x = Math.ceil(uv.x) - uv.x;
  1217. } else {
  1218. uv.x = uv.x - Math.floor(uv.x);
  1219. }
  1220. break;
  1221. }
  1222. }
  1223. if (uv.y < 0 || uv.y > 1) {
  1224. switch (this.wrapT) {
  1225. case RepeatWrapping:
  1226. uv.y = uv.y - Math.floor(uv.y);
  1227. break;
  1228. case ClampToEdgeWrapping:
  1229. uv.y = uv.y < 0 ? 0 : 1;
  1230. break;
  1231. case MirroredRepeatWrapping:
  1232. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1233. uv.y = Math.ceil(uv.y) - uv.y;
  1234. } else {
  1235. uv.y = uv.y - Math.floor(uv.y);
  1236. }
  1237. break;
  1238. }
  1239. }
  1240. if (this.flipY) {
  1241. uv.y = 1 - uv.y;
  1242. }
  1243. return uv;
  1244. }
  1245. });
  1246. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1247. set: function set(value) {
  1248. if (value === true) this.version++;
  1249. }
  1250. });
  1251. function serializeImage(image) {
  1252. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1253. // default images
  1254. return ImageUtils.getDataURL(image);
  1255. } else {
  1256. if (image.data) {
  1257. // images of DataTexture
  1258. return {
  1259. data: Array.prototype.slice.call(image.data),
  1260. width: image.width,
  1261. height: image.height,
  1262. type: image.data.constructor.name
  1263. };
  1264. } else {
  1265. console.warn('THREE.Texture: Unable to serialize Texture.');
  1266. return {};
  1267. }
  1268. }
  1269. }
  1270. var Vector4 = /*#__PURE__*/function () {
  1271. function Vector4(x, y, z, w) {
  1272. if (x === void 0) {
  1273. x = 0;
  1274. }
  1275. if (y === void 0) {
  1276. y = 0;
  1277. }
  1278. if (z === void 0) {
  1279. z = 0;
  1280. }
  1281. if (w === void 0) {
  1282. w = 1;
  1283. }
  1284. Object.defineProperty(this, 'isVector4', {
  1285. value: true
  1286. });
  1287. this.x = x;
  1288. this.y = y;
  1289. this.z = z;
  1290. this.w = w;
  1291. }
  1292. var _proto = Vector4.prototype;
  1293. _proto.set = function set(x, y, z, w) {
  1294. this.x = x;
  1295. this.y = y;
  1296. this.z = z;
  1297. this.w = w;
  1298. return this;
  1299. };
  1300. _proto.setScalar = function setScalar(scalar) {
  1301. this.x = scalar;
  1302. this.y = scalar;
  1303. this.z = scalar;
  1304. this.w = scalar;
  1305. return this;
  1306. };
  1307. _proto.setX = function setX(x) {
  1308. this.x = x;
  1309. return this;
  1310. };
  1311. _proto.setY = function setY(y) {
  1312. this.y = y;
  1313. return this;
  1314. };
  1315. _proto.setZ = function setZ(z) {
  1316. this.z = z;
  1317. return this;
  1318. };
  1319. _proto.setW = function setW(w) {
  1320. this.w = w;
  1321. return this;
  1322. };
  1323. _proto.setComponent = function setComponent(index, value) {
  1324. switch (index) {
  1325. case 0:
  1326. this.x = value;
  1327. break;
  1328. case 1:
  1329. this.y = value;
  1330. break;
  1331. case 2:
  1332. this.z = value;
  1333. break;
  1334. case 3:
  1335. this.w = value;
  1336. break;
  1337. default:
  1338. throw new Error('index is out of range: ' + index);
  1339. }
  1340. return this;
  1341. };
  1342. _proto.getComponent = function getComponent(index) {
  1343. switch (index) {
  1344. case 0:
  1345. return this.x;
  1346. case 1:
  1347. return this.y;
  1348. case 2:
  1349. return this.z;
  1350. case 3:
  1351. return this.w;
  1352. default:
  1353. throw new Error('index is out of range: ' + index);
  1354. }
  1355. };
  1356. _proto.clone = function clone() {
  1357. return new this.constructor(this.x, this.y, this.z, this.w);
  1358. };
  1359. _proto.copy = function copy(v) {
  1360. this.x = v.x;
  1361. this.y = v.y;
  1362. this.z = v.z;
  1363. this.w = v.w !== undefined ? v.w : 1;
  1364. return this;
  1365. };
  1366. _proto.add = function add(v, w) {
  1367. if (w !== undefined) {
  1368. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1369. return this.addVectors(v, w);
  1370. }
  1371. this.x += v.x;
  1372. this.y += v.y;
  1373. this.z += v.z;
  1374. this.w += v.w;
  1375. return this;
  1376. };
  1377. _proto.addScalar = function addScalar(s) {
  1378. this.x += s;
  1379. this.y += s;
  1380. this.z += s;
  1381. this.w += s;
  1382. return this;
  1383. };
  1384. _proto.addVectors = function addVectors(a, b) {
  1385. this.x = a.x + b.x;
  1386. this.y = a.y + b.y;
  1387. this.z = a.z + b.z;
  1388. this.w = a.w + b.w;
  1389. return this;
  1390. };
  1391. _proto.addScaledVector = function addScaledVector(v, s) {
  1392. this.x += v.x * s;
  1393. this.y += v.y * s;
  1394. this.z += v.z * s;
  1395. this.w += v.w * s;
  1396. return this;
  1397. };
  1398. _proto.sub = function sub(v, w) {
  1399. if (w !== undefined) {
  1400. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1401. return this.subVectors(v, w);
  1402. }
  1403. this.x -= v.x;
  1404. this.y -= v.y;
  1405. this.z -= v.z;
  1406. this.w -= v.w;
  1407. return this;
  1408. };
  1409. _proto.subScalar = function subScalar(s) {
  1410. this.x -= s;
  1411. this.y -= s;
  1412. this.z -= s;
  1413. this.w -= s;
  1414. return this;
  1415. };
  1416. _proto.subVectors = function subVectors(a, b) {
  1417. this.x = a.x - b.x;
  1418. this.y = a.y - b.y;
  1419. this.z = a.z - b.z;
  1420. this.w = a.w - b.w;
  1421. return this;
  1422. };
  1423. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1424. this.x *= scalar;
  1425. this.y *= scalar;
  1426. this.z *= scalar;
  1427. this.w *= scalar;
  1428. return this;
  1429. };
  1430. _proto.applyMatrix4 = function applyMatrix4(m) {
  1431. var x = this.x,
  1432. y = this.y,
  1433. z = this.z,
  1434. w = this.w;
  1435. var e = m.elements;
  1436. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1437. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1438. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1439. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1440. return this;
  1441. };
  1442. _proto.divideScalar = function divideScalar(scalar) {
  1443. return this.multiplyScalar(1 / scalar);
  1444. };
  1445. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1446. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1447. // q is assumed to be normalized
  1448. this.w = 2 * Math.acos(q.w);
  1449. var s = Math.sqrt(1 - q.w * q.w);
  1450. if (s < 0.0001) {
  1451. this.x = 1;
  1452. this.y = 0;
  1453. this.z = 0;
  1454. } else {
  1455. this.x = q.x / s;
  1456. this.y = q.y / s;
  1457. this.z = q.z / s;
  1458. }
  1459. return this;
  1460. };
  1461. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1462. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1463. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1464. var angle, x, y, z; // variables for result
  1465. var epsilon = 0.01,
  1466. // margin to allow for rounding errors
  1467. epsilon2 = 0.1,
  1468. // margin to distinguish between 0 and 180 degrees
  1469. te = m.elements,
  1470. m11 = te[0],
  1471. m12 = te[4],
  1472. m13 = te[8],
  1473. m21 = te[1],
  1474. m22 = te[5],
  1475. m23 = te[9],
  1476. m31 = te[2],
  1477. m32 = te[6],
  1478. m33 = te[10];
  1479. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1480. // singularity found
  1481. // first check for identity matrix which must have +1 for all terms
  1482. // in leading diagonal and zero in other terms
  1483. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1484. // this singularity is identity matrix so angle = 0
  1485. this.set(1, 0, 0, 0);
  1486. return this; // zero angle, arbitrary axis
  1487. } // otherwise this singularity is angle = 180
  1488. angle = Math.PI;
  1489. var xx = (m11 + 1) / 2;
  1490. var yy = (m22 + 1) / 2;
  1491. var zz = (m33 + 1) / 2;
  1492. var xy = (m12 + m21) / 4;
  1493. var xz = (m13 + m31) / 4;
  1494. var yz = (m23 + m32) / 4;
  1495. if (xx > yy && xx > zz) {
  1496. // m11 is the largest diagonal term
  1497. if (xx < epsilon) {
  1498. x = 0;
  1499. y = 0.707106781;
  1500. z = 0.707106781;
  1501. } else {
  1502. x = Math.sqrt(xx);
  1503. y = xy / x;
  1504. z = xz / x;
  1505. }
  1506. } else if (yy > zz) {
  1507. // m22 is the largest diagonal term
  1508. if (yy < epsilon) {
  1509. x = 0.707106781;
  1510. y = 0;
  1511. z = 0.707106781;
  1512. } else {
  1513. y = Math.sqrt(yy);
  1514. x = xy / y;
  1515. z = yz / y;
  1516. }
  1517. } else {
  1518. // m33 is the largest diagonal term so base result on this
  1519. if (zz < epsilon) {
  1520. x = 0.707106781;
  1521. y = 0.707106781;
  1522. z = 0;
  1523. } else {
  1524. z = Math.sqrt(zz);
  1525. x = xz / z;
  1526. y = yz / z;
  1527. }
  1528. }
  1529. this.set(x, y, z, angle);
  1530. return this; // return 180 deg rotation
  1531. } // as we have reached here there are no singularities so we can handle normally
  1532. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1533. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1534. // caught by singularity test above, but I've left it in just in case
  1535. this.x = (m32 - m23) / s;
  1536. this.y = (m13 - m31) / s;
  1537. this.z = (m21 - m12) / s;
  1538. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1539. return this;
  1540. };
  1541. _proto.min = function min(v) {
  1542. this.x = Math.min(this.x, v.x);
  1543. this.y = Math.min(this.y, v.y);
  1544. this.z = Math.min(this.z, v.z);
  1545. this.w = Math.min(this.w, v.w);
  1546. return this;
  1547. };
  1548. _proto.max = function max(v) {
  1549. this.x = Math.max(this.x, v.x);
  1550. this.y = Math.max(this.y, v.y);
  1551. this.z = Math.max(this.z, v.z);
  1552. this.w = Math.max(this.w, v.w);
  1553. return this;
  1554. };
  1555. _proto.clamp = function clamp(min, max) {
  1556. // assumes min < max, componentwise
  1557. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1558. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1559. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1560. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1561. return this;
  1562. };
  1563. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1564. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1565. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1566. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1567. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1568. return this;
  1569. };
  1570. _proto.clampLength = function clampLength(min, max) {
  1571. var length = this.length();
  1572. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1573. };
  1574. _proto.floor = function floor() {
  1575. this.x = Math.floor(this.x);
  1576. this.y = Math.floor(this.y);
  1577. this.z = Math.floor(this.z);
  1578. this.w = Math.floor(this.w);
  1579. return this;
  1580. };
  1581. _proto.ceil = function ceil() {
  1582. this.x = Math.ceil(this.x);
  1583. this.y = Math.ceil(this.y);
  1584. this.z = Math.ceil(this.z);
  1585. this.w = Math.ceil(this.w);
  1586. return this;
  1587. };
  1588. _proto.round = function round() {
  1589. this.x = Math.round(this.x);
  1590. this.y = Math.round(this.y);
  1591. this.z = Math.round(this.z);
  1592. this.w = Math.round(this.w);
  1593. return this;
  1594. };
  1595. _proto.roundToZero = function roundToZero() {
  1596. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1597. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1598. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1599. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1600. return this;
  1601. };
  1602. _proto.negate = function negate() {
  1603. this.x = -this.x;
  1604. this.y = -this.y;
  1605. this.z = -this.z;
  1606. this.w = -this.w;
  1607. return this;
  1608. };
  1609. _proto.dot = function dot(v) {
  1610. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1611. };
  1612. _proto.lengthSq = function lengthSq() {
  1613. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1614. };
  1615. _proto.length = function length() {
  1616. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1617. };
  1618. _proto.manhattanLength = function manhattanLength() {
  1619. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1620. };
  1621. _proto.normalize = function normalize() {
  1622. return this.divideScalar(this.length() || 1);
  1623. };
  1624. _proto.setLength = function setLength(length) {
  1625. return this.normalize().multiplyScalar(length);
  1626. };
  1627. _proto.lerp = function lerp(v, alpha) {
  1628. this.x += (v.x - this.x) * alpha;
  1629. this.y += (v.y - this.y) * alpha;
  1630. this.z += (v.z - this.z) * alpha;
  1631. this.w += (v.w - this.w) * alpha;
  1632. return this;
  1633. };
  1634. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1635. this.x = v1.x + (v2.x - v1.x) * alpha;
  1636. this.y = v1.y + (v2.y - v1.y) * alpha;
  1637. this.z = v1.z + (v2.z - v1.z) * alpha;
  1638. this.w = v1.w + (v2.w - v1.w) * alpha;
  1639. return this;
  1640. };
  1641. _proto.equals = function equals(v) {
  1642. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1643. };
  1644. _proto.fromArray = function fromArray(array, offset) {
  1645. if (offset === void 0) {
  1646. offset = 0;
  1647. }
  1648. this.x = array[offset];
  1649. this.y = array[offset + 1];
  1650. this.z = array[offset + 2];
  1651. this.w = array[offset + 3];
  1652. return this;
  1653. };
  1654. _proto.toArray = function toArray(array, offset) {
  1655. if (array === void 0) {
  1656. array = [];
  1657. }
  1658. if (offset === void 0) {
  1659. offset = 0;
  1660. }
  1661. array[offset] = this.x;
  1662. array[offset + 1] = this.y;
  1663. array[offset + 2] = this.z;
  1664. array[offset + 3] = this.w;
  1665. return array;
  1666. };
  1667. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1668. if (offset !== undefined) {
  1669. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1670. }
  1671. this.x = attribute.getX(index);
  1672. this.y = attribute.getY(index);
  1673. this.z = attribute.getZ(index);
  1674. this.w = attribute.getW(index);
  1675. return this;
  1676. };
  1677. _proto.random = function random() {
  1678. this.x = Math.random();
  1679. this.y = Math.random();
  1680. this.z = Math.random();
  1681. this.w = Math.random();
  1682. return this;
  1683. };
  1684. _createClass(Vector4, [{
  1685. key: "width",
  1686. get: function get() {
  1687. return this.z;
  1688. },
  1689. set: function set(value) {
  1690. this.z = value;
  1691. }
  1692. }, {
  1693. key: "height",
  1694. get: function get() {
  1695. return this.w;
  1696. },
  1697. set: function set(value) {
  1698. this.w = value;
  1699. }
  1700. }]);
  1701. return Vector4;
  1702. }();
  1703. /*
  1704. In options, we can specify:
  1705. * Texture parameters for an auto-generated target texture
  1706. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1707. */
  1708. function WebGLRenderTarget(width, height, options) {
  1709. this.width = width;
  1710. this.height = height;
  1711. this.scissor = new Vector4(0, 0, width, height);
  1712. this.scissorTest = false;
  1713. this.viewport = new Vector4(0, 0, width, height);
  1714. options = options || {};
  1715. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1716. this.texture.image = {};
  1717. this.texture.image.width = width;
  1718. this.texture.image.height = height;
  1719. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1720. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1721. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1722. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1723. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1724. }
  1725. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1726. constructor: WebGLRenderTarget,
  1727. isWebGLRenderTarget: true,
  1728. setSize: function setSize(width, height) {
  1729. if (this.width !== width || this.height !== height) {
  1730. this.width = width;
  1731. this.height = height;
  1732. this.texture.image.width = width;
  1733. this.texture.image.height = height;
  1734. this.dispose();
  1735. }
  1736. this.viewport.set(0, 0, width, height);
  1737. this.scissor.set(0, 0, width, height);
  1738. },
  1739. clone: function clone() {
  1740. return new this.constructor().copy(this);
  1741. },
  1742. copy: function copy(source) {
  1743. this.width = source.width;
  1744. this.height = source.height;
  1745. this.viewport.copy(source.viewport);
  1746. this.texture = source.texture.clone();
  1747. this.depthBuffer = source.depthBuffer;
  1748. this.stencilBuffer = source.stencilBuffer;
  1749. this.depthTexture = source.depthTexture;
  1750. return this;
  1751. },
  1752. dispose: function dispose() {
  1753. this.dispatchEvent({
  1754. type: 'dispose'
  1755. });
  1756. }
  1757. });
  1758. function WebGLMultisampleRenderTarget(width, height, options) {
  1759. WebGLRenderTarget.call(this, width, height, options);
  1760. this.samples = 4;
  1761. }
  1762. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1763. constructor: WebGLMultisampleRenderTarget,
  1764. isWebGLMultisampleRenderTarget: true,
  1765. copy: function copy(source) {
  1766. WebGLRenderTarget.prototype.copy.call(this, source);
  1767. this.samples = source.samples;
  1768. return this;
  1769. }
  1770. });
  1771. var Quaternion = /*#__PURE__*/function () {
  1772. function Quaternion(x, y, z, w) {
  1773. if (x === void 0) {
  1774. x = 0;
  1775. }
  1776. if (y === void 0) {
  1777. y = 0;
  1778. }
  1779. if (z === void 0) {
  1780. z = 0;
  1781. }
  1782. if (w === void 0) {
  1783. w = 1;
  1784. }
  1785. Object.defineProperty(this, 'isQuaternion', {
  1786. value: true
  1787. });
  1788. this._x = x;
  1789. this._y = y;
  1790. this._z = z;
  1791. this._w = w;
  1792. }
  1793. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1794. return qm.copy(qa).slerp(qb, t);
  1795. };
  1796. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1797. // fuzz-free, array-based Quaternion SLERP operation
  1798. var x0 = src0[srcOffset0 + 0],
  1799. y0 = src0[srcOffset0 + 1],
  1800. z0 = src0[srcOffset0 + 2],
  1801. w0 = src0[srcOffset0 + 3];
  1802. var x1 = src1[srcOffset1 + 0],
  1803. y1 = src1[srcOffset1 + 1],
  1804. z1 = src1[srcOffset1 + 2],
  1805. w1 = src1[srcOffset1 + 3];
  1806. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1807. var s = 1 - t;
  1808. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1809. dir = cos >= 0 ? 1 : -1,
  1810. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1811. if (sqrSin > Number.EPSILON) {
  1812. var sin = Math.sqrt(sqrSin),
  1813. len = Math.atan2(sin, cos * dir);
  1814. s = Math.sin(s * len) / sin;
  1815. t = Math.sin(t * len) / sin;
  1816. }
  1817. var tDir = t * dir;
  1818. x0 = x0 * s + x1 * tDir;
  1819. y0 = y0 * s + y1 * tDir;
  1820. z0 = z0 * s + z1 * tDir;
  1821. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1822. if (s === 1 - t) {
  1823. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1824. x0 *= f;
  1825. y0 *= f;
  1826. z0 *= f;
  1827. w0 *= f;
  1828. }
  1829. }
  1830. dst[dstOffset] = x0;
  1831. dst[dstOffset + 1] = y0;
  1832. dst[dstOffset + 2] = z0;
  1833. dst[dstOffset + 3] = w0;
  1834. };
  1835. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1836. var x0 = src0[srcOffset0];
  1837. var y0 = src0[srcOffset0 + 1];
  1838. var z0 = src0[srcOffset0 + 2];
  1839. var w0 = src0[srcOffset0 + 3];
  1840. var x1 = src1[srcOffset1];
  1841. var y1 = src1[srcOffset1 + 1];
  1842. var z1 = src1[srcOffset1 + 2];
  1843. var w1 = src1[srcOffset1 + 3];
  1844. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1845. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1846. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1847. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1848. return dst;
  1849. };
  1850. var _proto = Quaternion.prototype;
  1851. _proto.set = function set(x, y, z, w) {
  1852. this._x = x;
  1853. this._y = y;
  1854. this._z = z;
  1855. this._w = w;
  1856. this._onChangeCallback();
  1857. return this;
  1858. };
  1859. _proto.clone = function clone() {
  1860. return new this.constructor(this._x, this._y, this._z, this._w);
  1861. };
  1862. _proto.copy = function copy(quaternion) {
  1863. this._x = quaternion.x;
  1864. this._y = quaternion.y;
  1865. this._z = quaternion.z;
  1866. this._w = quaternion.w;
  1867. this._onChangeCallback();
  1868. return this;
  1869. };
  1870. _proto.setFromEuler = function setFromEuler(euler, update) {
  1871. if (!(euler && euler.isEuler)) {
  1872. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1873. }
  1874. var x = euler._x,
  1875. y = euler._y,
  1876. z = euler._z,
  1877. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1878. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1879. // content/SpinCalc.m
  1880. var cos = Math.cos;
  1881. var sin = Math.sin;
  1882. var c1 = cos(x / 2);
  1883. var c2 = cos(y / 2);
  1884. var c3 = cos(z / 2);
  1885. var s1 = sin(x / 2);
  1886. var s2 = sin(y / 2);
  1887. var s3 = sin(z / 2);
  1888. switch (order) {
  1889. case 'XYZ':
  1890. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1891. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1892. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1893. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1894. break;
  1895. case 'YXZ':
  1896. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1897. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1898. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1899. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1900. break;
  1901. case 'ZXY':
  1902. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1903. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1904. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1905. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1906. break;
  1907. case 'ZYX':
  1908. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1909. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1910. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1911. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1912. break;
  1913. case 'YZX':
  1914. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1915. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1916. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1917. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1918. break;
  1919. case 'XZY':
  1920. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1921. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1922. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1923. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1924. break;
  1925. default:
  1926. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1927. }
  1928. if (update !== false) this._onChangeCallback();
  1929. return this;
  1930. };
  1931. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1932. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1933. // assumes axis is normalized
  1934. var halfAngle = angle / 2,
  1935. s = Math.sin(halfAngle);
  1936. this._x = axis.x * s;
  1937. this._y = axis.y * s;
  1938. this._z = axis.z * s;
  1939. this._w = Math.cos(halfAngle);
  1940. this._onChangeCallback();
  1941. return this;
  1942. };
  1943. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1944. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1945. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1946. var te = m.elements,
  1947. m11 = te[0],
  1948. m12 = te[4],
  1949. m13 = te[8],
  1950. m21 = te[1],
  1951. m22 = te[5],
  1952. m23 = te[9],
  1953. m31 = te[2],
  1954. m32 = te[6],
  1955. m33 = te[10],
  1956. trace = m11 + m22 + m33;
  1957. if (trace > 0) {
  1958. var s = 0.5 / Math.sqrt(trace + 1.0);
  1959. this._w = 0.25 / s;
  1960. this._x = (m32 - m23) * s;
  1961. this._y = (m13 - m31) * s;
  1962. this._z = (m21 - m12) * s;
  1963. } else if (m11 > m22 && m11 > m33) {
  1964. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1965. this._w = (m32 - m23) / _s;
  1966. this._x = 0.25 * _s;
  1967. this._y = (m12 + m21) / _s;
  1968. this._z = (m13 + m31) / _s;
  1969. } else if (m22 > m33) {
  1970. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1971. this._w = (m13 - m31) / _s2;
  1972. this._x = (m12 + m21) / _s2;
  1973. this._y = 0.25 * _s2;
  1974. this._z = (m23 + m32) / _s2;
  1975. } else {
  1976. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1977. this._w = (m21 - m12) / _s3;
  1978. this._x = (m13 + m31) / _s3;
  1979. this._y = (m23 + m32) / _s3;
  1980. this._z = 0.25 * _s3;
  1981. }
  1982. this._onChangeCallback();
  1983. return this;
  1984. };
  1985. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1986. // assumes direction vectors vFrom and vTo are normalized
  1987. var EPS = 0.000001;
  1988. var r = vFrom.dot(vTo) + 1;
  1989. if (r < EPS) {
  1990. r = 0;
  1991. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1992. this._x = -vFrom.y;
  1993. this._y = vFrom.x;
  1994. this._z = 0;
  1995. this._w = r;
  1996. } else {
  1997. this._x = 0;
  1998. this._y = -vFrom.z;
  1999. this._z = vFrom.y;
  2000. this._w = r;
  2001. }
  2002. } else {
  2003. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2004. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2005. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2006. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2007. this._w = r;
  2008. }
  2009. return this.normalize();
  2010. };
  2011. _proto.angleTo = function angleTo(q) {
  2012. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2013. };
  2014. _proto.rotateTowards = function rotateTowards(q, step) {
  2015. var angle = this.angleTo(q);
  2016. if (angle === 0) return this;
  2017. var t = Math.min(1, step / angle);
  2018. this.slerp(q, t);
  2019. return this;
  2020. };
  2021. _proto.identity = function identity() {
  2022. return this.set(0, 0, 0, 1);
  2023. };
  2024. _proto.invert = function invert() {
  2025. // quaternion is assumed to have unit length
  2026. return this.conjugate();
  2027. };
  2028. _proto.conjugate = function conjugate() {
  2029. this._x *= -1;
  2030. this._y *= -1;
  2031. this._z *= -1;
  2032. this._onChangeCallback();
  2033. return this;
  2034. };
  2035. _proto.dot = function dot(v) {
  2036. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2037. };
  2038. _proto.lengthSq = function lengthSq() {
  2039. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2040. };
  2041. _proto.length = function length() {
  2042. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2043. };
  2044. _proto.normalize = function normalize() {
  2045. var l = this.length();
  2046. if (l === 0) {
  2047. this._x = 0;
  2048. this._y = 0;
  2049. this._z = 0;
  2050. this._w = 1;
  2051. } else {
  2052. l = 1 / l;
  2053. this._x = this._x * l;
  2054. this._y = this._y * l;
  2055. this._z = this._z * l;
  2056. this._w = this._w * l;
  2057. }
  2058. this._onChangeCallback();
  2059. return this;
  2060. };
  2061. _proto.multiply = function multiply(q, p) {
  2062. if (p !== undefined) {
  2063. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2064. return this.multiplyQuaternions(q, p);
  2065. }
  2066. return this.multiplyQuaternions(this, q);
  2067. };
  2068. _proto.premultiply = function premultiply(q) {
  2069. return this.multiplyQuaternions(q, this);
  2070. };
  2071. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2072. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2073. var qax = a._x,
  2074. qay = a._y,
  2075. qaz = a._z,
  2076. qaw = a._w;
  2077. var qbx = b._x,
  2078. qby = b._y,
  2079. qbz = b._z,
  2080. qbw = b._w;
  2081. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2082. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2083. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2084. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2085. this._onChangeCallback();
  2086. return this;
  2087. };
  2088. _proto.slerp = function slerp(qb, t) {
  2089. if (t === 0) return this;
  2090. if (t === 1) return this.copy(qb);
  2091. var x = this._x,
  2092. y = this._y,
  2093. z = this._z,
  2094. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2095. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2096. if (cosHalfTheta < 0) {
  2097. this._w = -qb._w;
  2098. this._x = -qb._x;
  2099. this._y = -qb._y;
  2100. this._z = -qb._z;
  2101. cosHalfTheta = -cosHalfTheta;
  2102. } else {
  2103. this.copy(qb);
  2104. }
  2105. if (cosHalfTheta >= 1.0) {
  2106. this._w = w;
  2107. this._x = x;
  2108. this._y = y;
  2109. this._z = z;
  2110. return this;
  2111. }
  2112. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2113. if (sqrSinHalfTheta <= Number.EPSILON) {
  2114. var s = 1 - t;
  2115. this._w = s * w + t * this._w;
  2116. this._x = s * x + t * this._x;
  2117. this._y = s * y + t * this._y;
  2118. this._z = s * z + t * this._z;
  2119. this.normalize();
  2120. this._onChangeCallback();
  2121. return this;
  2122. }
  2123. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2124. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2125. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2126. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2127. this._w = w * ratioA + this._w * ratioB;
  2128. this._x = x * ratioA + this._x * ratioB;
  2129. this._y = y * ratioA + this._y * ratioB;
  2130. this._z = z * ratioA + this._z * ratioB;
  2131. this._onChangeCallback();
  2132. return this;
  2133. };
  2134. _proto.equals = function equals(quaternion) {
  2135. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2136. };
  2137. _proto.fromArray = function fromArray(array, offset) {
  2138. if (offset === void 0) {
  2139. offset = 0;
  2140. }
  2141. this._x = array[offset];
  2142. this._y = array[offset + 1];
  2143. this._z = array[offset + 2];
  2144. this._w = array[offset + 3];
  2145. this._onChangeCallback();
  2146. return this;
  2147. };
  2148. _proto.toArray = function toArray(array, offset) {
  2149. if (array === void 0) {
  2150. array = [];
  2151. }
  2152. if (offset === void 0) {
  2153. offset = 0;
  2154. }
  2155. array[offset] = this._x;
  2156. array[offset + 1] = this._y;
  2157. array[offset + 2] = this._z;
  2158. array[offset + 3] = this._w;
  2159. return array;
  2160. };
  2161. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2162. this._x = attribute.getX(index);
  2163. this._y = attribute.getY(index);
  2164. this._z = attribute.getZ(index);
  2165. this._w = attribute.getW(index);
  2166. return this;
  2167. };
  2168. _proto._onChange = function _onChange(callback) {
  2169. this._onChangeCallback = callback;
  2170. return this;
  2171. };
  2172. _proto._onChangeCallback = function _onChangeCallback() {};
  2173. _createClass(Quaternion, [{
  2174. key: "x",
  2175. get: function get() {
  2176. return this._x;
  2177. },
  2178. set: function set(value) {
  2179. this._x = value;
  2180. this._onChangeCallback();
  2181. }
  2182. }, {
  2183. key: "y",
  2184. get: function get() {
  2185. return this._y;
  2186. },
  2187. set: function set(value) {
  2188. this._y = value;
  2189. this._onChangeCallback();
  2190. }
  2191. }, {
  2192. key: "z",
  2193. get: function get() {
  2194. return this._z;
  2195. },
  2196. set: function set(value) {
  2197. this._z = value;
  2198. this._onChangeCallback();
  2199. }
  2200. }, {
  2201. key: "w",
  2202. get: function get() {
  2203. return this._w;
  2204. },
  2205. set: function set(value) {
  2206. this._w = value;
  2207. this._onChangeCallback();
  2208. }
  2209. }]);
  2210. return Quaternion;
  2211. }();
  2212. var Vector3 = /*#__PURE__*/function () {
  2213. function Vector3(x, y, z) {
  2214. if (x === void 0) {
  2215. x = 0;
  2216. }
  2217. if (y === void 0) {
  2218. y = 0;
  2219. }
  2220. if (z === void 0) {
  2221. z = 0;
  2222. }
  2223. Object.defineProperty(this, 'isVector3', {
  2224. value: true
  2225. });
  2226. this.x = x;
  2227. this.y = y;
  2228. this.z = z;
  2229. }
  2230. var _proto = Vector3.prototype;
  2231. _proto.set = function set(x, y, z) {
  2232. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2233. this.x = x;
  2234. this.y = y;
  2235. this.z = z;
  2236. return this;
  2237. };
  2238. _proto.setScalar = function setScalar(scalar) {
  2239. this.x = scalar;
  2240. this.y = scalar;
  2241. this.z = scalar;
  2242. return this;
  2243. };
  2244. _proto.setX = function setX(x) {
  2245. this.x = x;
  2246. return this;
  2247. };
  2248. _proto.setY = function setY(y) {
  2249. this.y = y;
  2250. return this;
  2251. };
  2252. _proto.setZ = function setZ(z) {
  2253. this.z = z;
  2254. return this;
  2255. };
  2256. _proto.setComponent = function setComponent(index, value) {
  2257. switch (index) {
  2258. case 0:
  2259. this.x = value;
  2260. break;
  2261. case 1:
  2262. this.y = value;
  2263. break;
  2264. case 2:
  2265. this.z = value;
  2266. break;
  2267. default:
  2268. throw new Error('index is out of range: ' + index);
  2269. }
  2270. return this;
  2271. };
  2272. _proto.getComponent = function getComponent(index) {
  2273. switch (index) {
  2274. case 0:
  2275. return this.x;
  2276. case 1:
  2277. return this.y;
  2278. case 2:
  2279. return this.z;
  2280. default:
  2281. throw new Error('index is out of range: ' + index);
  2282. }
  2283. };
  2284. _proto.clone = function clone() {
  2285. return new this.constructor(this.x, this.y, this.z);
  2286. };
  2287. _proto.copy = function copy(v) {
  2288. this.x = v.x;
  2289. this.y = v.y;
  2290. this.z = v.z;
  2291. return this;
  2292. };
  2293. _proto.add = function add(v, w) {
  2294. if (w !== undefined) {
  2295. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2296. return this.addVectors(v, w);
  2297. }
  2298. this.x += v.x;
  2299. this.y += v.y;
  2300. this.z += v.z;
  2301. return this;
  2302. };
  2303. _proto.addScalar = function addScalar(s) {
  2304. this.x += s;
  2305. this.y += s;
  2306. this.z += s;
  2307. return this;
  2308. };
  2309. _proto.addVectors = function addVectors(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.addScaledVector = function addScaledVector(v, s) {
  2316. this.x += v.x * s;
  2317. this.y += v.y * s;
  2318. this.z += v.z * s;
  2319. return this;
  2320. };
  2321. _proto.sub = function sub(v, w) {
  2322. if (w !== undefined) {
  2323. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2324. return this.subVectors(v, w);
  2325. }
  2326. this.x -= v.x;
  2327. this.y -= v.y;
  2328. this.z -= v.z;
  2329. return this;
  2330. };
  2331. _proto.subScalar = function subScalar(s) {
  2332. this.x -= s;
  2333. this.y -= s;
  2334. this.z -= s;
  2335. return this;
  2336. };
  2337. _proto.subVectors = function subVectors(a, b) {
  2338. this.x = a.x - b.x;
  2339. this.y = a.y - b.y;
  2340. this.z = a.z - b.z;
  2341. return this;
  2342. };
  2343. _proto.multiply = function multiply(v, w) {
  2344. if (w !== undefined) {
  2345. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2346. return this.multiplyVectors(v, w);
  2347. }
  2348. this.x *= v.x;
  2349. this.y *= v.y;
  2350. this.z *= v.z;
  2351. return this;
  2352. };
  2353. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2354. this.x *= scalar;
  2355. this.y *= scalar;
  2356. this.z *= scalar;
  2357. return this;
  2358. };
  2359. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2360. this.x = a.x * b.x;
  2361. this.y = a.y * b.y;
  2362. this.z = a.z * b.z;
  2363. return this;
  2364. };
  2365. _proto.applyEuler = function applyEuler(euler) {
  2366. if (!(euler && euler.isEuler)) {
  2367. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2368. }
  2369. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2370. };
  2371. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2372. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2373. };
  2374. _proto.applyMatrix3 = function applyMatrix3(m) {
  2375. var x = this.x,
  2376. y = this.y,
  2377. z = this.z;
  2378. var e = m.elements;
  2379. this.x = e[0] * x + e[3] * y + e[6] * z;
  2380. this.y = e[1] * x + e[4] * y + e[7] * z;
  2381. this.z = e[2] * x + e[5] * y + e[8] * z;
  2382. return this;
  2383. };
  2384. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2385. return this.applyMatrix3(m).normalize();
  2386. };
  2387. _proto.applyMatrix4 = function applyMatrix4(m) {
  2388. var x = this.x,
  2389. y = this.y,
  2390. z = this.z;
  2391. var e = m.elements;
  2392. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2393. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2394. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2395. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2396. return this;
  2397. };
  2398. _proto.applyQuaternion = function applyQuaternion(q) {
  2399. var x = this.x,
  2400. y = this.y,
  2401. z = this.z;
  2402. var qx = q.x,
  2403. qy = q.y,
  2404. qz = q.z,
  2405. qw = q.w; // calculate quat * vector
  2406. var ix = qw * x + qy * z - qz * y;
  2407. var iy = qw * y + qz * x - qx * z;
  2408. var iz = qw * z + qx * y - qy * x;
  2409. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2410. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2411. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2412. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2413. return this;
  2414. };
  2415. _proto.project = function project(camera) {
  2416. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2417. };
  2418. _proto.unproject = function unproject(camera) {
  2419. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2420. };
  2421. _proto.transformDirection = function transformDirection(m) {
  2422. // input: THREE.Matrix4 affine matrix
  2423. // vector interpreted as a direction
  2424. var x = this.x,
  2425. y = this.y,
  2426. z = this.z;
  2427. var e = m.elements;
  2428. this.x = e[0] * x + e[4] * y + e[8] * z;
  2429. this.y = e[1] * x + e[5] * y + e[9] * z;
  2430. this.z = e[2] * x + e[6] * y + e[10] * z;
  2431. return this.normalize();
  2432. };
  2433. _proto.divide = function divide(v) {
  2434. this.x /= v.x;
  2435. this.y /= v.y;
  2436. this.z /= v.z;
  2437. return this;
  2438. };
  2439. _proto.divideScalar = function divideScalar(scalar) {
  2440. return this.multiplyScalar(1 / scalar);
  2441. };
  2442. _proto.min = function min(v) {
  2443. this.x = Math.min(this.x, v.x);
  2444. this.y = Math.min(this.y, v.y);
  2445. this.z = Math.min(this.z, v.z);
  2446. return this;
  2447. };
  2448. _proto.max = function max(v) {
  2449. this.x = Math.max(this.x, v.x);
  2450. this.y = Math.max(this.y, v.y);
  2451. this.z = Math.max(this.z, v.z);
  2452. return this;
  2453. };
  2454. _proto.clamp = function clamp(min, max) {
  2455. // assumes min < max, componentwise
  2456. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2457. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2458. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2459. return this;
  2460. };
  2461. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2462. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2463. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2464. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2465. return this;
  2466. };
  2467. _proto.clampLength = function clampLength(min, max) {
  2468. var length = this.length();
  2469. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2470. };
  2471. _proto.floor = function floor() {
  2472. this.x = Math.floor(this.x);
  2473. this.y = Math.floor(this.y);
  2474. this.z = Math.floor(this.z);
  2475. return this;
  2476. };
  2477. _proto.ceil = function ceil() {
  2478. this.x = Math.ceil(this.x);
  2479. this.y = Math.ceil(this.y);
  2480. this.z = Math.ceil(this.z);
  2481. return this;
  2482. };
  2483. _proto.round = function round() {
  2484. this.x = Math.round(this.x);
  2485. this.y = Math.round(this.y);
  2486. this.z = Math.round(this.z);
  2487. return this;
  2488. };
  2489. _proto.roundToZero = function roundToZero() {
  2490. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2491. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2492. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2493. return this;
  2494. };
  2495. _proto.negate = function negate() {
  2496. this.x = -this.x;
  2497. this.y = -this.y;
  2498. this.z = -this.z;
  2499. return this;
  2500. };
  2501. _proto.dot = function dot(v) {
  2502. return this.x * v.x + this.y * v.y + this.z * v.z;
  2503. } // TODO lengthSquared?
  2504. ;
  2505. _proto.lengthSq = function lengthSq() {
  2506. return this.x * this.x + this.y * this.y + this.z * this.z;
  2507. };
  2508. _proto.length = function length() {
  2509. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2510. };
  2511. _proto.manhattanLength = function manhattanLength() {
  2512. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2513. };
  2514. _proto.normalize = function normalize() {
  2515. return this.divideScalar(this.length() || 1);
  2516. };
  2517. _proto.setLength = function setLength(length) {
  2518. return this.normalize().multiplyScalar(length);
  2519. };
  2520. _proto.lerp = function lerp(v, alpha) {
  2521. this.x += (v.x - this.x) * alpha;
  2522. this.y += (v.y - this.y) * alpha;
  2523. this.z += (v.z - this.z) * alpha;
  2524. return this;
  2525. };
  2526. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2527. this.x = v1.x + (v2.x - v1.x) * alpha;
  2528. this.y = v1.y + (v2.y - v1.y) * alpha;
  2529. this.z = v1.z + (v2.z - v1.z) * alpha;
  2530. return this;
  2531. };
  2532. _proto.cross = function cross(v, w) {
  2533. if (w !== undefined) {
  2534. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2535. return this.crossVectors(v, w);
  2536. }
  2537. return this.crossVectors(this, v);
  2538. };
  2539. _proto.crossVectors = function crossVectors(a, b) {
  2540. var ax = a.x,
  2541. ay = a.y,
  2542. az = a.z;
  2543. var bx = b.x,
  2544. by = b.y,
  2545. bz = b.z;
  2546. this.x = ay * bz - az * by;
  2547. this.y = az * bx - ax * bz;
  2548. this.z = ax * by - ay * bx;
  2549. return this;
  2550. };
  2551. _proto.projectOnVector = function projectOnVector(v) {
  2552. var denominator = v.lengthSq();
  2553. if (denominator === 0) return this.set(0, 0, 0);
  2554. var scalar = v.dot(this) / denominator;
  2555. return this.copy(v).multiplyScalar(scalar);
  2556. };
  2557. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2558. _vector.copy(this).projectOnVector(planeNormal);
  2559. return this.sub(_vector);
  2560. };
  2561. _proto.reflect = function reflect(normal) {
  2562. // reflect incident vector off plane orthogonal to normal
  2563. // normal is assumed to have unit length
  2564. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2565. };
  2566. _proto.angleTo = function angleTo(v) {
  2567. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2568. if (denominator === 0) return Math.PI / 2;
  2569. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2570. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2571. };
  2572. _proto.distanceTo = function distanceTo(v) {
  2573. return Math.sqrt(this.distanceToSquared(v));
  2574. };
  2575. _proto.distanceToSquared = function distanceToSquared(v) {
  2576. var dx = this.x - v.x,
  2577. dy = this.y - v.y,
  2578. dz = this.z - v.z;
  2579. return dx * dx + dy * dy + dz * dz;
  2580. };
  2581. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2582. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2583. };
  2584. _proto.setFromSpherical = function setFromSpherical(s) {
  2585. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2586. };
  2587. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2588. var sinPhiRadius = Math.sin(phi) * radius;
  2589. this.x = sinPhiRadius * Math.sin(theta);
  2590. this.y = Math.cos(phi) * radius;
  2591. this.z = sinPhiRadius * Math.cos(theta);
  2592. return this;
  2593. };
  2594. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2595. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2596. };
  2597. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2598. this.x = radius * Math.sin(theta);
  2599. this.y = y;
  2600. this.z = radius * Math.cos(theta);
  2601. return this;
  2602. };
  2603. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2604. var e = m.elements;
  2605. this.x = e[12];
  2606. this.y = e[13];
  2607. this.z = e[14];
  2608. return this;
  2609. };
  2610. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2611. var sx = this.setFromMatrixColumn(m, 0).length();
  2612. var sy = this.setFromMatrixColumn(m, 1).length();
  2613. var sz = this.setFromMatrixColumn(m, 2).length();
  2614. this.x = sx;
  2615. this.y = sy;
  2616. this.z = sz;
  2617. return this;
  2618. };
  2619. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2620. return this.fromArray(m.elements, index * 4);
  2621. };
  2622. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2623. return this.fromArray(m.elements, index * 3);
  2624. };
  2625. _proto.equals = function equals(v) {
  2626. return v.x === this.x && v.y === this.y && v.z === this.z;
  2627. };
  2628. _proto.fromArray = function fromArray(array, offset) {
  2629. if (offset === void 0) {
  2630. offset = 0;
  2631. }
  2632. this.x = array[offset];
  2633. this.y = array[offset + 1];
  2634. this.z = array[offset + 2];
  2635. return this;
  2636. };
  2637. _proto.toArray = function toArray(array, offset) {
  2638. if (array === void 0) {
  2639. array = [];
  2640. }
  2641. if (offset === void 0) {
  2642. offset = 0;
  2643. }
  2644. array[offset] = this.x;
  2645. array[offset + 1] = this.y;
  2646. array[offset + 2] = this.z;
  2647. return array;
  2648. };
  2649. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2650. if (offset !== undefined) {
  2651. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2652. }
  2653. this.x = attribute.getX(index);
  2654. this.y = attribute.getY(index);
  2655. this.z = attribute.getZ(index);
  2656. return this;
  2657. };
  2658. _proto.random = function random() {
  2659. this.x = Math.random();
  2660. this.y = Math.random();
  2661. this.z = Math.random();
  2662. return this;
  2663. };
  2664. return Vector3;
  2665. }();
  2666. var _vector = /*@__PURE__*/new Vector3();
  2667. var _quaternion = /*@__PURE__*/new Quaternion();
  2668. var Box3 = /*#__PURE__*/function () {
  2669. function Box3(min, max) {
  2670. Object.defineProperty(this, 'isBox3', {
  2671. value: true
  2672. });
  2673. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2674. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2675. }
  2676. var _proto = Box3.prototype;
  2677. _proto.set = function set(min, max) {
  2678. this.min.copy(min);
  2679. this.max.copy(max);
  2680. return this;
  2681. };
  2682. _proto.setFromArray = function setFromArray(array) {
  2683. var minX = +Infinity;
  2684. var minY = +Infinity;
  2685. var minZ = +Infinity;
  2686. var maxX = -Infinity;
  2687. var maxY = -Infinity;
  2688. var maxZ = -Infinity;
  2689. for (var i = 0, l = array.length; i < l; i += 3) {
  2690. var x = array[i];
  2691. var y = array[i + 1];
  2692. var z = array[i + 2];
  2693. if (x < minX) minX = x;
  2694. if (y < minY) minY = y;
  2695. if (z < minZ) minZ = z;
  2696. if (x > maxX) maxX = x;
  2697. if (y > maxY) maxY = y;
  2698. if (z > maxZ) maxZ = z;
  2699. }
  2700. this.min.set(minX, minY, minZ);
  2701. this.max.set(maxX, maxY, maxZ);
  2702. return this;
  2703. };
  2704. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2705. var minX = +Infinity;
  2706. var minY = +Infinity;
  2707. var minZ = +Infinity;
  2708. var maxX = -Infinity;
  2709. var maxY = -Infinity;
  2710. var maxZ = -Infinity;
  2711. for (var i = 0, l = attribute.count; i < l; i++) {
  2712. var x = attribute.getX(i);
  2713. var y = attribute.getY(i);
  2714. var z = attribute.getZ(i);
  2715. if (x < minX) minX = x;
  2716. if (y < minY) minY = y;
  2717. if (z < minZ) minZ = z;
  2718. if (x > maxX) maxX = x;
  2719. if (y > maxY) maxY = y;
  2720. if (z > maxZ) maxZ = z;
  2721. }
  2722. this.min.set(minX, minY, minZ);
  2723. this.max.set(maxX, maxY, maxZ);
  2724. return this;
  2725. };
  2726. _proto.setFromPoints = function setFromPoints(points) {
  2727. this.makeEmpty();
  2728. for (var i = 0, il = points.length; i < il; i++) {
  2729. this.expandByPoint(points[i]);
  2730. }
  2731. return this;
  2732. };
  2733. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2734. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2735. this.min.copy(center).sub(halfSize);
  2736. this.max.copy(center).add(halfSize);
  2737. return this;
  2738. };
  2739. _proto.setFromObject = function setFromObject(object) {
  2740. this.makeEmpty();
  2741. return this.expandByObject(object);
  2742. };
  2743. _proto.clone = function clone() {
  2744. return new this.constructor().copy(this);
  2745. };
  2746. _proto.copy = function copy(box) {
  2747. this.min.copy(box.min);
  2748. this.max.copy(box.max);
  2749. return this;
  2750. };
  2751. _proto.makeEmpty = function makeEmpty() {
  2752. this.min.x = this.min.y = this.min.z = +Infinity;
  2753. this.max.x = this.max.y = this.max.z = -Infinity;
  2754. return this;
  2755. };
  2756. _proto.isEmpty = function isEmpty() {
  2757. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2758. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2759. };
  2760. _proto.getCenter = function getCenter(target) {
  2761. if (target === undefined) {
  2762. console.warn('THREE.Box3: .getCenter() target is now required');
  2763. target = new Vector3();
  2764. }
  2765. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2766. };
  2767. _proto.getSize = function getSize(target) {
  2768. if (target === undefined) {
  2769. console.warn('THREE.Box3: .getSize() target is now required');
  2770. target = new Vector3();
  2771. }
  2772. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2773. };
  2774. _proto.expandByPoint = function expandByPoint(point) {
  2775. this.min.min(point);
  2776. this.max.max(point);
  2777. return this;
  2778. };
  2779. _proto.expandByVector = function expandByVector(vector) {
  2780. this.min.sub(vector);
  2781. this.max.add(vector);
  2782. return this;
  2783. };
  2784. _proto.expandByScalar = function expandByScalar(scalar) {
  2785. this.min.addScalar(-scalar);
  2786. this.max.addScalar(scalar);
  2787. return this;
  2788. };
  2789. _proto.expandByObject = function expandByObject(object) {
  2790. // Computes the world-axis-aligned bounding box of an object (including its children),
  2791. // accounting for both the object's, and children's, world transforms
  2792. object.updateWorldMatrix(false, false);
  2793. var geometry = object.geometry;
  2794. if (geometry !== undefined) {
  2795. if (geometry.boundingBox === null) {
  2796. geometry.computeBoundingBox();
  2797. }
  2798. _box.copy(geometry.boundingBox);
  2799. _box.applyMatrix4(object.matrixWorld);
  2800. this.union(_box);
  2801. }
  2802. var children = object.children;
  2803. for (var i = 0, l = children.length; i < l; i++) {
  2804. this.expandByObject(children[i]);
  2805. }
  2806. return this;
  2807. };
  2808. _proto.containsPoint = function containsPoint(point) {
  2809. 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;
  2810. };
  2811. _proto.containsBox = function containsBox(box) {
  2812. 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;
  2813. };
  2814. _proto.getParameter = function getParameter(point, target) {
  2815. // This can potentially have a divide by zero if the box
  2816. // has a size dimension of 0.
  2817. if (target === undefined) {
  2818. console.warn('THREE.Box3: .getParameter() target is now required');
  2819. target = new Vector3();
  2820. }
  2821. 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));
  2822. };
  2823. _proto.intersectsBox = function intersectsBox(box) {
  2824. // using 6 splitting planes to rule out intersections.
  2825. 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;
  2826. };
  2827. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2828. // Find the point on the AABB closest to the sphere center.
  2829. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2830. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2831. };
  2832. _proto.intersectsPlane = function intersectsPlane(plane) {
  2833. // We compute the minimum and maximum dot product values. If those values
  2834. // are on the same side (back or front) of the plane, then there is no intersection.
  2835. var min, max;
  2836. if (plane.normal.x > 0) {
  2837. min = plane.normal.x * this.min.x;
  2838. max = plane.normal.x * this.max.x;
  2839. } else {
  2840. min = plane.normal.x * this.max.x;
  2841. max = plane.normal.x * this.min.x;
  2842. }
  2843. if (plane.normal.y > 0) {
  2844. min += plane.normal.y * this.min.y;
  2845. max += plane.normal.y * this.max.y;
  2846. } else {
  2847. min += plane.normal.y * this.max.y;
  2848. max += plane.normal.y * this.min.y;
  2849. }
  2850. if (plane.normal.z > 0) {
  2851. min += plane.normal.z * this.min.z;
  2852. max += plane.normal.z * this.max.z;
  2853. } else {
  2854. min += plane.normal.z * this.max.z;
  2855. max += plane.normal.z * this.min.z;
  2856. }
  2857. return min <= -plane.constant && max >= -plane.constant;
  2858. };
  2859. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2860. if (this.isEmpty()) {
  2861. return false;
  2862. } // compute box center and extents
  2863. this.getCenter(_center);
  2864. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2865. _v0.subVectors(triangle.a, _center);
  2866. _v1.subVectors(triangle.b, _center);
  2867. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2868. _f0.subVectors(_v1, _v0);
  2869. _f1.subVectors(_v2, _v1);
  2870. _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
  2871. // 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
  2872. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2873. 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];
  2874. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2875. return false;
  2876. } // test 3 face normals from the aabb
  2877. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2878. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2879. return false;
  2880. } // finally testing the face normal of the triangle
  2881. // use already existing triangle edge vectors here
  2882. _triangleNormal.crossVectors(_f0, _f1);
  2883. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2884. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2885. };
  2886. _proto.clampPoint = function clampPoint(point, target) {
  2887. if (target === undefined) {
  2888. console.warn('THREE.Box3: .clampPoint() target is now required');
  2889. target = new Vector3();
  2890. }
  2891. return target.copy(point).clamp(this.min, this.max);
  2892. };
  2893. _proto.distanceToPoint = function distanceToPoint(point) {
  2894. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2895. return clampedPoint.sub(point).length();
  2896. };
  2897. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2898. if (target === undefined) {
  2899. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2900. }
  2901. this.getCenter(target.center);
  2902. target.radius = this.getSize(_vector$1).length() * 0.5;
  2903. return target;
  2904. };
  2905. _proto.intersect = function intersect(box) {
  2906. this.min.max(box.min);
  2907. 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.
  2908. if (this.isEmpty()) this.makeEmpty();
  2909. return this;
  2910. };
  2911. _proto.union = function union(box) {
  2912. this.min.min(box.min);
  2913. this.max.max(box.max);
  2914. return this;
  2915. };
  2916. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2917. // transform of empty box is an empty box.
  2918. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2919. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2920. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2921. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2922. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2923. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2924. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2925. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2926. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2927. this.setFromPoints(_points);
  2928. return this;
  2929. };
  2930. _proto.translate = function translate(offset) {
  2931. this.min.add(offset);
  2932. this.max.add(offset);
  2933. return this;
  2934. };
  2935. _proto.equals = function equals(box) {
  2936. return box.min.equals(this.min) && box.max.equals(this.max);
  2937. };
  2938. return Box3;
  2939. }();
  2940. function satForAxes(axes, v0, v1, v2, extents) {
  2941. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2942. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2943. 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
  2944. var p0 = v0.dot(_testAxis);
  2945. var p1 = v1.dot(_testAxis);
  2946. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2947. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2948. // points of the projected triangle are outside the projected half-length of the aabb
  2949. // the axis is seperating and we can exit
  2950. return false;
  2951. }
  2952. }
  2953. return true;
  2954. }
  2955. 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()];
  2956. var _vector$1 = /*@__PURE__*/new Vector3();
  2957. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2958. var _v0 = /*@__PURE__*/new Vector3();
  2959. var _v1 = /*@__PURE__*/new Vector3();
  2960. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2961. var _f0 = /*@__PURE__*/new Vector3();
  2962. var _f1 = /*@__PURE__*/new Vector3();
  2963. var _f2 = /*@__PURE__*/new Vector3();
  2964. var _center = /*@__PURE__*/new Vector3();
  2965. var _extents = /*@__PURE__*/new Vector3();
  2966. var _triangleNormal = /*@__PURE__*/new Vector3();
  2967. var _testAxis = /*@__PURE__*/new Vector3();
  2968. var _box$1 = /*@__PURE__*/new Box3();
  2969. var Sphere = /*#__PURE__*/function () {
  2970. function Sphere(center, radius) {
  2971. this.center = center !== undefined ? center : new Vector3();
  2972. this.radius = radius !== undefined ? radius : -1;
  2973. }
  2974. var _proto = Sphere.prototype;
  2975. _proto.set = function set(center, radius) {
  2976. this.center.copy(center);
  2977. this.radius = radius;
  2978. return this;
  2979. };
  2980. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2981. var center = this.center;
  2982. if (optionalCenter !== undefined) {
  2983. center.copy(optionalCenter);
  2984. } else {
  2985. _box$1.setFromPoints(points).getCenter(center);
  2986. }
  2987. var maxRadiusSq = 0;
  2988. for (var i = 0, il = points.length; i < il; i++) {
  2989. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2990. }
  2991. this.radius = Math.sqrt(maxRadiusSq);
  2992. return this;
  2993. };
  2994. _proto.clone = function clone() {
  2995. return new this.constructor().copy(this);
  2996. };
  2997. _proto.copy = function copy(sphere) {
  2998. this.center.copy(sphere.center);
  2999. this.radius = sphere.radius;
  3000. return this;
  3001. };
  3002. _proto.isEmpty = function isEmpty() {
  3003. return this.radius < 0;
  3004. };
  3005. _proto.makeEmpty = function makeEmpty() {
  3006. this.center.set(0, 0, 0);
  3007. this.radius = -1;
  3008. return this;
  3009. };
  3010. _proto.containsPoint = function containsPoint(point) {
  3011. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3012. };
  3013. _proto.distanceToPoint = function distanceToPoint(point) {
  3014. return point.distanceTo(this.center) - this.radius;
  3015. };
  3016. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3017. var radiusSum = this.radius + sphere.radius;
  3018. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3019. };
  3020. _proto.intersectsBox = function intersectsBox(box) {
  3021. return box.intersectsSphere(this);
  3022. };
  3023. _proto.intersectsPlane = function intersectsPlane(plane) {
  3024. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3025. };
  3026. _proto.clampPoint = function clampPoint(point, target) {
  3027. var deltaLengthSq = this.center.distanceToSquared(point);
  3028. if (target === undefined) {
  3029. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3030. target = new Vector3();
  3031. }
  3032. target.copy(point);
  3033. if (deltaLengthSq > this.radius * this.radius) {
  3034. target.sub(this.center).normalize();
  3035. target.multiplyScalar(this.radius).add(this.center);
  3036. }
  3037. return target;
  3038. };
  3039. _proto.getBoundingBox = function getBoundingBox(target) {
  3040. if (target === undefined) {
  3041. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3042. target = new Box3();
  3043. }
  3044. if (this.isEmpty()) {
  3045. // Empty sphere produces empty bounding box
  3046. target.makeEmpty();
  3047. return target;
  3048. }
  3049. target.set(this.center, this.center);
  3050. target.expandByScalar(this.radius);
  3051. return target;
  3052. };
  3053. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3054. this.center.applyMatrix4(matrix);
  3055. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3056. return this;
  3057. };
  3058. _proto.translate = function translate(offset) {
  3059. this.center.add(offset);
  3060. return this;
  3061. };
  3062. _proto.equals = function equals(sphere) {
  3063. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3064. };
  3065. return Sphere;
  3066. }();
  3067. var _vector$2 = /*@__PURE__*/new Vector3();
  3068. var _segCenter = /*@__PURE__*/new Vector3();
  3069. var _segDir = /*@__PURE__*/new Vector3();
  3070. var _diff = /*@__PURE__*/new Vector3();
  3071. var _edge1 = /*@__PURE__*/new Vector3();
  3072. var _edge2 = /*@__PURE__*/new Vector3();
  3073. var _normal = /*@__PURE__*/new Vector3();
  3074. var Ray = /*#__PURE__*/function () {
  3075. function Ray(origin, direction) {
  3076. this.origin = origin !== undefined ? origin : new Vector3();
  3077. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3078. }
  3079. var _proto = Ray.prototype;
  3080. _proto.set = function set(origin, direction) {
  3081. this.origin.copy(origin);
  3082. this.direction.copy(direction);
  3083. return this;
  3084. };
  3085. _proto.clone = function clone() {
  3086. return new this.constructor().copy(this);
  3087. };
  3088. _proto.copy = function copy(ray) {
  3089. this.origin.copy(ray.origin);
  3090. this.direction.copy(ray.direction);
  3091. return this;
  3092. };
  3093. _proto.at = function at(t, target) {
  3094. if (target === undefined) {
  3095. console.warn('THREE.Ray: .at() target is now required');
  3096. target = new Vector3();
  3097. }
  3098. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3099. };
  3100. _proto.lookAt = function lookAt(v) {
  3101. this.direction.copy(v).sub(this.origin).normalize();
  3102. return this;
  3103. };
  3104. _proto.recast = function recast(t) {
  3105. this.origin.copy(this.at(t, _vector$2));
  3106. return this;
  3107. };
  3108. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3109. if (target === undefined) {
  3110. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3111. target = new Vector3();
  3112. }
  3113. target.subVectors(point, this.origin);
  3114. var directionDistance = target.dot(this.direction);
  3115. if (directionDistance < 0) {
  3116. return target.copy(this.origin);
  3117. }
  3118. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3119. };
  3120. _proto.distanceToPoint = function distanceToPoint(point) {
  3121. return Math.sqrt(this.distanceSqToPoint(point));
  3122. };
  3123. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3124. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3125. if (directionDistance < 0) {
  3126. return this.origin.distanceToSquared(point);
  3127. }
  3128. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3129. return _vector$2.distanceToSquared(point);
  3130. };
  3131. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3132. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3133. // It returns the min distance between the ray and the segment
  3134. // defined by v0 and v1
  3135. // It can also set two optional targets :
  3136. // - The closest point on the ray
  3137. // - The closest point on the segment
  3138. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3139. _segDir.copy(v1).sub(v0).normalize();
  3140. _diff.copy(this.origin).sub(_segCenter);
  3141. var segExtent = v0.distanceTo(v1) * 0.5;
  3142. var a01 = -this.direction.dot(_segDir);
  3143. var b0 = _diff.dot(this.direction);
  3144. var b1 = -_diff.dot(_segDir);
  3145. var c = _diff.lengthSq();
  3146. var det = Math.abs(1 - a01 * a01);
  3147. var s0, s1, sqrDist, extDet;
  3148. if (det > 0) {
  3149. // The ray and segment are not parallel.
  3150. s0 = a01 * b1 - b0;
  3151. s1 = a01 * b0 - b1;
  3152. extDet = segExtent * det;
  3153. if (s0 >= 0) {
  3154. if (s1 >= -extDet) {
  3155. if (s1 <= extDet) {
  3156. // region 0
  3157. // Minimum at interior points of ray and segment.
  3158. var invDet = 1 / det;
  3159. s0 *= invDet;
  3160. s1 *= invDet;
  3161. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3162. } else {
  3163. // region 1
  3164. s1 = segExtent;
  3165. s0 = Math.max(0, -(a01 * s1 + b0));
  3166. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3167. }
  3168. } else {
  3169. // region 5
  3170. s1 = -segExtent;
  3171. s0 = Math.max(0, -(a01 * s1 + b0));
  3172. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3173. }
  3174. } else {
  3175. if (s1 <= -extDet) {
  3176. // region 4
  3177. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3178. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3179. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3180. } else if (s1 <= extDet) {
  3181. // region 3
  3182. s0 = 0;
  3183. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3184. sqrDist = s1 * (s1 + 2 * b1) + c;
  3185. } else {
  3186. // region 2
  3187. s0 = Math.max(0, -(a01 * segExtent + b0));
  3188. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3189. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3190. }
  3191. }
  3192. } else {
  3193. // Ray and segment are parallel.
  3194. s1 = a01 > 0 ? -segExtent : segExtent;
  3195. s0 = Math.max(0, -(a01 * s1 + b0));
  3196. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3197. }
  3198. if (optionalPointOnRay) {
  3199. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3200. }
  3201. if (optionalPointOnSegment) {
  3202. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3203. }
  3204. return sqrDist;
  3205. };
  3206. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3207. _vector$2.subVectors(sphere.center, this.origin);
  3208. var tca = _vector$2.dot(this.direction);
  3209. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3210. var radius2 = sphere.radius * sphere.radius;
  3211. if (d2 > radius2) return null;
  3212. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3213. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3214. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3215. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3216. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3217. // in order to always return an intersect point that is in front of the ray.
  3218. 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
  3219. return this.at(t0, target);
  3220. };
  3221. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3222. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3223. };
  3224. _proto.distanceToPlane = function distanceToPlane(plane) {
  3225. var denominator = plane.normal.dot(this.direction);
  3226. if (denominator === 0) {
  3227. // line is coplanar, return origin
  3228. if (plane.distanceToPoint(this.origin) === 0) {
  3229. return 0;
  3230. } // Null is preferable to undefined since undefined means.... it is undefined
  3231. return null;
  3232. }
  3233. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3234. return t >= 0 ? t : null;
  3235. };
  3236. _proto.intersectPlane = function intersectPlane(plane, target) {
  3237. var t = this.distanceToPlane(plane);
  3238. if (t === null) {
  3239. return null;
  3240. }
  3241. return this.at(t, target);
  3242. };
  3243. _proto.intersectsPlane = function intersectsPlane(plane) {
  3244. // check if the ray lies on the plane first
  3245. var distToPoint = plane.distanceToPoint(this.origin);
  3246. if (distToPoint === 0) {
  3247. return true;
  3248. }
  3249. var denominator = plane.normal.dot(this.direction);
  3250. if (denominator * distToPoint < 0) {
  3251. return true;
  3252. } // ray origin is behind the plane (and is pointing behind it)
  3253. return false;
  3254. };
  3255. _proto.intersectBox = function intersectBox(box, target) {
  3256. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3257. var invdirx = 1 / this.direction.x,
  3258. invdiry = 1 / this.direction.y,
  3259. invdirz = 1 / this.direction.z;
  3260. var origin = this.origin;
  3261. if (invdirx >= 0) {
  3262. tmin = (box.min.x - origin.x) * invdirx;
  3263. tmax = (box.max.x - origin.x) * invdirx;
  3264. } else {
  3265. tmin = (box.max.x - origin.x) * invdirx;
  3266. tmax = (box.min.x - origin.x) * invdirx;
  3267. }
  3268. if (invdiry >= 0) {
  3269. tymin = (box.min.y - origin.y) * invdiry;
  3270. tymax = (box.max.y - origin.y) * invdiry;
  3271. } else {
  3272. tymin = (box.max.y - origin.y) * invdiry;
  3273. tymax = (box.min.y - origin.y) * invdiry;
  3274. }
  3275. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3276. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3277. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3278. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3279. if (invdirz >= 0) {
  3280. tzmin = (box.min.z - origin.z) * invdirz;
  3281. tzmax = (box.max.z - origin.z) * invdirz;
  3282. } else {
  3283. tzmin = (box.max.z - origin.z) * invdirz;
  3284. tzmax = (box.min.z - origin.z) * invdirz;
  3285. }
  3286. if (tmin > tzmax || tzmin > tmax) return null;
  3287. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3288. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3289. if (tmax < 0) return null;
  3290. return this.at(tmin >= 0 ? tmin : tmax, target);
  3291. };
  3292. _proto.intersectsBox = function intersectsBox(box) {
  3293. return this.intersectBox(box, _vector$2) !== null;
  3294. };
  3295. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3296. // Compute the offset origin, edges, and normal.
  3297. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3298. _edge1.subVectors(b, a);
  3299. _edge2.subVectors(c, a);
  3300. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3301. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3302. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3303. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3304. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3305. var DdN = this.direction.dot(_normal);
  3306. var sign;
  3307. if (DdN > 0) {
  3308. if (backfaceCulling) return null;
  3309. sign = 1;
  3310. } else if (DdN < 0) {
  3311. sign = -1;
  3312. DdN = -DdN;
  3313. } else {
  3314. return null;
  3315. }
  3316. _diff.subVectors(this.origin, a);
  3317. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3318. if (DdQxE2 < 0) {
  3319. return null;
  3320. }
  3321. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3322. if (DdE1xQ < 0) {
  3323. return null;
  3324. } // b1+b2 > 1, no intersection
  3325. if (DdQxE2 + DdE1xQ > DdN) {
  3326. return null;
  3327. } // Line intersects triangle, check if ray does.
  3328. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3329. if (QdN < 0) {
  3330. return null;
  3331. } // Ray intersects triangle.
  3332. return this.at(QdN / DdN, target);
  3333. };
  3334. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3335. this.origin.applyMatrix4(matrix4);
  3336. this.direction.transformDirection(matrix4);
  3337. return this;
  3338. };
  3339. _proto.equals = function equals(ray) {
  3340. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3341. };
  3342. return Ray;
  3343. }();
  3344. var Matrix4 = /*#__PURE__*/function () {
  3345. function Matrix4() {
  3346. Object.defineProperty(this, 'isMatrix4', {
  3347. value: true
  3348. });
  3349. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3350. if (arguments.length > 0) {
  3351. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3352. }
  3353. }
  3354. var _proto = Matrix4.prototype;
  3355. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3356. var te = this.elements;
  3357. te[0] = n11;
  3358. te[4] = n12;
  3359. te[8] = n13;
  3360. te[12] = n14;
  3361. te[1] = n21;
  3362. te[5] = n22;
  3363. te[9] = n23;
  3364. te[13] = n24;
  3365. te[2] = n31;
  3366. te[6] = n32;
  3367. te[10] = n33;
  3368. te[14] = n34;
  3369. te[3] = n41;
  3370. te[7] = n42;
  3371. te[11] = n43;
  3372. te[15] = n44;
  3373. return this;
  3374. };
  3375. _proto.identity = function identity() {
  3376. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3377. return this;
  3378. };
  3379. _proto.clone = function clone() {
  3380. return new Matrix4().fromArray(this.elements);
  3381. };
  3382. _proto.copy = function copy(m) {
  3383. var te = this.elements;
  3384. var me = m.elements;
  3385. te[0] = me[0];
  3386. te[1] = me[1];
  3387. te[2] = me[2];
  3388. te[3] = me[3];
  3389. te[4] = me[4];
  3390. te[5] = me[5];
  3391. te[6] = me[6];
  3392. te[7] = me[7];
  3393. te[8] = me[8];
  3394. te[9] = me[9];
  3395. te[10] = me[10];
  3396. te[11] = me[11];
  3397. te[12] = me[12];
  3398. te[13] = me[13];
  3399. te[14] = me[14];
  3400. te[15] = me[15];
  3401. return this;
  3402. };
  3403. _proto.copyPosition = function copyPosition(m) {
  3404. var te = this.elements,
  3405. me = m.elements;
  3406. te[12] = me[12];
  3407. te[13] = me[13];
  3408. te[14] = me[14];
  3409. return this;
  3410. };
  3411. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3412. xAxis.setFromMatrixColumn(this, 0);
  3413. yAxis.setFromMatrixColumn(this, 1);
  3414. zAxis.setFromMatrixColumn(this, 2);
  3415. return this;
  3416. };
  3417. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3418. 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);
  3419. return this;
  3420. };
  3421. _proto.extractRotation = function extractRotation(m) {
  3422. // this method does not support reflection matrices
  3423. var te = this.elements;
  3424. var me = m.elements;
  3425. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3426. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3427. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3428. te[0] = me[0] * scaleX;
  3429. te[1] = me[1] * scaleX;
  3430. te[2] = me[2] * scaleX;
  3431. te[3] = 0;
  3432. te[4] = me[4] * scaleY;
  3433. te[5] = me[5] * scaleY;
  3434. te[6] = me[6] * scaleY;
  3435. te[7] = 0;
  3436. te[8] = me[8] * scaleZ;
  3437. te[9] = me[9] * scaleZ;
  3438. te[10] = me[10] * scaleZ;
  3439. te[11] = 0;
  3440. te[12] = 0;
  3441. te[13] = 0;
  3442. te[14] = 0;
  3443. te[15] = 1;
  3444. return this;
  3445. };
  3446. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3447. if (!(euler && euler.isEuler)) {
  3448. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3449. }
  3450. var te = this.elements;
  3451. var x = euler.x,
  3452. y = euler.y,
  3453. z = euler.z;
  3454. var a = Math.cos(x),
  3455. b = Math.sin(x);
  3456. var c = Math.cos(y),
  3457. d = Math.sin(y);
  3458. var e = Math.cos(z),
  3459. f = Math.sin(z);
  3460. if (euler.order === 'XYZ') {
  3461. var ae = a * e,
  3462. af = a * f,
  3463. be = b * e,
  3464. bf = b * f;
  3465. te[0] = c * e;
  3466. te[4] = -c * f;
  3467. te[8] = d;
  3468. te[1] = af + be * d;
  3469. te[5] = ae - bf * d;
  3470. te[9] = -b * c;
  3471. te[2] = bf - ae * d;
  3472. te[6] = be + af * d;
  3473. te[10] = a * c;
  3474. } else if (euler.order === 'YXZ') {
  3475. var ce = c * e,
  3476. cf = c * f,
  3477. de = d * e,
  3478. df = d * f;
  3479. te[0] = ce + df * b;
  3480. te[4] = de * b - cf;
  3481. te[8] = a * d;
  3482. te[1] = a * f;
  3483. te[5] = a * e;
  3484. te[9] = -b;
  3485. te[2] = cf * b - de;
  3486. te[6] = df + ce * b;
  3487. te[10] = a * c;
  3488. } else if (euler.order === 'ZXY') {
  3489. var _ce = c * e,
  3490. _cf = c * f,
  3491. _de = d * e,
  3492. _df = d * f;
  3493. te[0] = _ce - _df * b;
  3494. te[4] = -a * f;
  3495. te[8] = _de + _cf * b;
  3496. te[1] = _cf + _de * b;
  3497. te[5] = a * e;
  3498. te[9] = _df - _ce * b;
  3499. te[2] = -a * d;
  3500. te[6] = b;
  3501. te[10] = a * c;
  3502. } else if (euler.order === 'ZYX') {
  3503. var _ae = a * e,
  3504. _af = a * f,
  3505. _be = b * e,
  3506. _bf = b * f;
  3507. te[0] = c * e;
  3508. te[4] = _be * d - _af;
  3509. te[8] = _ae * d + _bf;
  3510. te[1] = c * f;
  3511. te[5] = _bf * d + _ae;
  3512. te[9] = _af * d - _be;
  3513. te[2] = -d;
  3514. te[6] = b * c;
  3515. te[10] = a * c;
  3516. } else if (euler.order === 'YZX') {
  3517. var ac = a * c,
  3518. ad = a * d,
  3519. bc = b * c,
  3520. bd = b * d;
  3521. te[0] = c * e;
  3522. te[4] = bd - ac * f;
  3523. te[8] = bc * f + ad;
  3524. te[1] = f;
  3525. te[5] = a * e;
  3526. te[9] = -b * e;
  3527. te[2] = -d * e;
  3528. te[6] = ad * f + bc;
  3529. te[10] = ac - bd * f;
  3530. } else if (euler.order === 'XZY') {
  3531. var _ac = a * c,
  3532. _ad = a * d,
  3533. _bc = b * c,
  3534. _bd = b * d;
  3535. te[0] = c * e;
  3536. te[4] = -f;
  3537. te[8] = d * e;
  3538. te[1] = _ac * f + _bd;
  3539. te[5] = a * e;
  3540. te[9] = _ad * f - _bc;
  3541. te[2] = _bc * f - _ad;
  3542. te[6] = b * e;
  3543. te[10] = _bd * f + _ac;
  3544. } // bottom row
  3545. te[3] = 0;
  3546. te[7] = 0;
  3547. te[11] = 0; // last column
  3548. te[12] = 0;
  3549. te[13] = 0;
  3550. te[14] = 0;
  3551. te[15] = 1;
  3552. return this;
  3553. };
  3554. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3555. return this.compose(_zero, q, _one);
  3556. };
  3557. _proto.lookAt = function lookAt(eye, target, up) {
  3558. var te = this.elements;
  3559. _z.subVectors(eye, target);
  3560. if (_z.lengthSq() === 0) {
  3561. // eye and target are in the same position
  3562. _z.z = 1;
  3563. }
  3564. _z.normalize();
  3565. _x.crossVectors(up, _z);
  3566. if (_x.lengthSq() === 0) {
  3567. // up and z are parallel
  3568. if (Math.abs(up.z) === 1) {
  3569. _z.x += 0.0001;
  3570. } else {
  3571. _z.z += 0.0001;
  3572. }
  3573. _z.normalize();
  3574. _x.crossVectors(up, _z);
  3575. }
  3576. _x.normalize();
  3577. _y.crossVectors(_z, _x);
  3578. te[0] = _x.x;
  3579. te[4] = _y.x;
  3580. te[8] = _z.x;
  3581. te[1] = _x.y;
  3582. te[5] = _y.y;
  3583. te[9] = _z.y;
  3584. te[2] = _x.z;
  3585. te[6] = _y.z;
  3586. te[10] = _z.z;
  3587. return this;
  3588. };
  3589. _proto.multiply = function multiply(m, n) {
  3590. if (n !== undefined) {
  3591. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3592. return this.multiplyMatrices(m, n);
  3593. }
  3594. return this.multiplyMatrices(this, m);
  3595. };
  3596. _proto.premultiply = function premultiply(m) {
  3597. return this.multiplyMatrices(m, this);
  3598. };
  3599. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3600. var ae = a.elements;
  3601. var be = b.elements;
  3602. var te = this.elements;
  3603. var a11 = ae[0],
  3604. a12 = ae[4],
  3605. a13 = ae[8],
  3606. a14 = ae[12];
  3607. var a21 = ae[1],
  3608. a22 = ae[5],
  3609. a23 = ae[9],
  3610. a24 = ae[13];
  3611. var a31 = ae[2],
  3612. a32 = ae[6],
  3613. a33 = ae[10],
  3614. a34 = ae[14];
  3615. var a41 = ae[3],
  3616. a42 = ae[7],
  3617. a43 = ae[11],
  3618. a44 = ae[15];
  3619. var b11 = be[0],
  3620. b12 = be[4],
  3621. b13 = be[8],
  3622. b14 = be[12];
  3623. var b21 = be[1],
  3624. b22 = be[5],
  3625. b23 = be[9],
  3626. b24 = be[13];
  3627. var b31 = be[2],
  3628. b32 = be[6],
  3629. b33 = be[10],
  3630. b34 = be[14];
  3631. var b41 = be[3],
  3632. b42 = be[7],
  3633. b43 = be[11],
  3634. b44 = be[15];
  3635. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3636. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3637. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3638. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3639. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3640. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3641. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3642. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3643. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3644. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3645. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3646. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3647. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3648. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3649. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3650. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3651. return this;
  3652. };
  3653. _proto.multiplyScalar = function multiplyScalar(s) {
  3654. var te = this.elements;
  3655. te[0] *= s;
  3656. te[4] *= s;
  3657. te[8] *= s;
  3658. te[12] *= s;
  3659. te[1] *= s;
  3660. te[5] *= s;
  3661. te[9] *= s;
  3662. te[13] *= s;
  3663. te[2] *= s;
  3664. te[6] *= s;
  3665. te[10] *= s;
  3666. te[14] *= s;
  3667. te[3] *= s;
  3668. te[7] *= s;
  3669. te[11] *= s;
  3670. te[15] *= s;
  3671. return this;
  3672. };
  3673. _proto.determinant = function determinant() {
  3674. var te = this.elements;
  3675. var n11 = te[0],
  3676. n12 = te[4],
  3677. n13 = te[8],
  3678. n14 = te[12];
  3679. var n21 = te[1],
  3680. n22 = te[5],
  3681. n23 = te[9],
  3682. n24 = te[13];
  3683. var n31 = te[2],
  3684. n32 = te[6],
  3685. n33 = te[10],
  3686. n34 = te[14];
  3687. var n41 = te[3],
  3688. n42 = te[7],
  3689. n43 = te[11],
  3690. n44 = te[15]; //TODO: make this more efficient
  3691. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3692. 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);
  3693. };
  3694. _proto.transpose = function transpose() {
  3695. var te = this.elements;
  3696. var tmp;
  3697. tmp = te[1];
  3698. te[1] = te[4];
  3699. te[4] = tmp;
  3700. tmp = te[2];
  3701. te[2] = te[8];
  3702. te[8] = tmp;
  3703. tmp = te[6];
  3704. te[6] = te[9];
  3705. te[9] = tmp;
  3706. tmp = te[3];
  3707. te[3] = te[12];
  3708. te[12] = tmp;
  3709. tmp = te[7];
  3710. te[7] = te[13];
  3711. te[13] = tmp;
  3712. tmp = te[11];
  3713. te[11] = te[14];
  3714. te[14] = tmp;
  3715. return this;
  3716. };
  3717. _proto.setPosition = function setPosition(x, y, z) {
  3718. var te = this.elements;
  3719. if (x.isVector3) {
  3720. te[12] = x.x;
  3721. te[13] = x.y;
  3722. te[14] = x.z;
  3723. } else {
  3724. te[12] = x;
  3725. te[13] = y;
  3726. te[14] = z;
  3727. }
  3728. return this;
  3729. };
  3730. _proto.invert = function invert() {
  3731. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3732. var te = this.elements,
  3733. n11 = te[0],
  3734. n21 = te[1],
  3735. n31 = te[2],
  3736. n41 = te[3],
  3737. n12 = te[4],
  3738. n22 = te[5],
  3739. n32 = te[6],
  3740. n42 = te[7],
  3741. n13 = te[8],
  3742. n23 = te[9],
  3743. n33 = te[10],
  3744. n43 = te[11],
  3745. n14 = te[12],
  3746. n24 = te[13],
  3747. n34 = te[14],
  3748. n44 = te[15],
  3749. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3750. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3751. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3752. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3753. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3754. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3755. var detInv = 1 / det;
  3756. te[0] = t11 * detInv;
  3757. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3758. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3759. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3760. te[4] = t12 * detInv;
  3761. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3762. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3763. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3764. te[8] = t13 * detInv;
  3765. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3766. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3767. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3768. te[12] = t14 * detInv;
  3769. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3770. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3771. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3772. return this;
  3773. };
  3774. _proto.scale = function scale(v) {
  3775. var te = this.elements;
  3776. var x = v.x,
  3777. y = v.y,
  3778. z = v.z;
  3779. te[0] *= x;
  3780. te[4] *= y;
  3781. te[8] *= z;
  3782. te[1] *= x;
  3783. te[5] *= y;
  3784. te[9] *= z;
  3785. te[2] *= x;
  3786. te[6] *= y;
  3787. te[10] *= z;
  3788. te[3] *= x;
  3789. te[7] *= y;
  3790. te[11] *= z;
  3791. return this;
  3792. };
  3793. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3794. var te = this.elements;
  3795. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3796. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3797. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3798. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3799. };
  3800. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3801. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3802. return this;
  3803. };
  3804. _proto.makeRotationX = function makeRotationX(theta) {
  3805. var c = Math.cos(theta),
  3806. s = Math.sin(theta);
  3807. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3808. return this;
  3809. };
  3810. _proto.makeRotationY = function makeRotationY(theta) {
  3811. var c = Math.cos(theta),
  3812. s = Math.sin(theta);
  3813. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3814. return this;
  3815. };
  3816. _proto.makeRotationZ = function makeRotationZ(theta) {
  3817. var c = Math.cos(theta),
  3818. s = Math.sin(theta);
  3819. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3820. return this;
  3821. };
  3822. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3823. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3824. var c = Math.cos(angle);
  3825. var s = Math.sin(angle);
  3826. var t = 1 - c;
  3827. var x = axis.x,
  3828. y = axis.y,
  3829. z = axis.z;
  3830. var tx = t * x,
  3831. ty = t * y;
  3832. 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);
  3833. return this;
  3834. };
  3835. _proto.makeScale = function makeScale(x, y, z) {
  3836. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3837. return this;
  3838. };
  3839. _proto.makeShear = function makeShear(x, y, z) {
  3840. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3841. return this;
  3842. };
  3843. _proto.compose = function compose(position, quaternion, scale) {
  3844. var te = this.elements;
  3845. var x = quaternion._x,
  3846. y = quaternion._y,
  3847. z = quaternion._z,
  3848. w = quaternion._w;
  3849. var x2 = x + x,
  3850. y2 = y + y,
  3851. z2 = z + z;
  3852. var xx = x * x2,
  3853. xy = x * y2,
  3854. xz = x * z2;
  3855. var yy = y * y2,
  3856. yz = y * z2,
  3857. zz = z * z2;
  3858. var wx = w * x2,
  3859. wy = w * y2,
  3860. wz = w * z2;
  3861. var sx = scale.x,
  3862. sy = scale.y,
  3863. sz = scale.z;
  3864. te[0] = (1 - (yy + zz)) * sx;
  3865. te[1] = (xy + wz) * sx;
  3866. te[2] = (xz - wy) * sx;
  3867. te[3] = 0;
  3868. te[4] = (xy - wz) * sy;
  3869. te[5] = (1 - (xx + zz)) * sy;
  3870. te[6] = (yz + wx) * sy;
  3871. te[7] = 0;
  3872. te[8] = (xz + wy) * sz;
  3873. te[9] = (yz - wx) * sz;
  3874. te[10] = (1 - (xx + yy)) * sz;
  3875. te[11] = 0;
  3876. te[12] = position.x;
  3877. te[13] = position.y;
  3878. te[14] = position.z;
  3879. te[15] = 1;
  3880. return this;
  3881. };
  3882. _proto.decompose = function decompose(position, quaternion, scale) {
  3883. var te = this.elements;
  3884. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3885. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3886. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3887. var det = this.determinant();
  3888. if (det < 0) sx = -sx;
  3889. position.x = te[12];
  3890. position.y = te[13];
  3891. position.z = te[14]; // scale the rotation part
  3892. _m1.copy(this);
  3893. var invSX = 1 / sx;
  3894. var invSY = 1 / sy;
  3895. var invSZ = 1 / sz;
  3896. _m1.elements[0] *= invSX;
  3897. _m1.elements[1] *= invSX;
  3898. _m1.elements[2] *= invSX;
  3899. _m1.elements[4] *= invSY;
  3900. _m1.elements[5] *= invSY;
  3901. _m1.elements[6] *= invSY;
  3902. _m1.elements[8] *= invSZ;
  3903. _m1.elements[9] *= invSZ;
  3904. _m1.elements[10] *= invSZ;
  3905. quaternion.setFromRotationMatrix(_m1);
  3906. scale.x = sx;
  3907. scale.y = sy;
  3908. scale.z = sz;
  3909. return this;
  3910. };
  3911. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3912. if (far === undefined) {
  3913. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3914. }
  3915. var te = this.elements;
  3916. var x = 2 * near / (right - left);
  3917. var y = 2 * near / (top - bottom);
  3918. var a = (right + left) / (right - left);
  3919. var b = (top + bottom) / (top - bottom);
  3920. var c = -(far + near) / (far - near);
  3921. var d = -2 * far * near / (far - near);
  3922. te[0] = x;
  3923. te[4] = 0;
  3924. te[8] = a;
  3925. te[12] = 0;
  3926. te[1] = 0;
  3927. te[5] = y;
  3928. te[9] = b;
  3929. te[13] = 0;
  3930. te[2] = 0;
  3931. te[6] = 0;
  3932. te[10] = c;
  3933. te[14] = d;
  3934. te[3] = 0;
  3935. te[7] = 0;
  3936. te[11] = -1;
  3937. te[15] = 0;
  3938. return this;
  3939. };
  3940. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3941. var te = this.elements;
  3942. var w = 1.0 / (right - left);
  3943. var h = 1.0 / (top - bottom);
  3944. var p = 1.0 / (far - near);
  3945. var x = (right + left) * w;
  3946. var y = (top + bottom) * h;
  3947. var z = (far + near) * p;
  3948. te[0] = 2 * w;
  3949. te[4] = 0;
  3950. te[8] = 0;
  3951. te[12] = -x;
  3952. te[1] = 0;
  3953. te[5] = 2 * h;
  3954. te[9] = 0;
  3955. te[13] = -y;
  3956. te[2] = 0;
  3957. te[6] = 0;
  3958. te[10] = -2 * p;
  3959. te[14] = -z;
  3960. te[3] = 0;
  3961. te[7] = 0;
  3962. te[11] = 0;
  3963. te[15] = 1;
  3964. return this;
  3965. };
  3966. _proto.equals = function equals(matrix) {
  3967. var te = this.elements;
  3968. var me = matrix.elements;
  3969. for (var i = 0; i < 16; i++) {
  3970. if (te[i] !== me[i]) return false;
  3971. }
  3972. return true;
  3973. };
  3974. _proto.fromArray = function fromArray(array, offset) {
  3975. if (offset === void 0) {
  3976. offset = 0;
  3977. }
  3978. for (var i = 0; i < 16; i++) {
  3979. this.elements[i] = array[i + offset];
  3980. }
  3981. return this;
  3982. };
  3983. _proto.toArray = function toArray(array, offset) {
  3984. if (array === void 0) {
  3985. array = [];
  3986. }
  3987. if (offset === void 0) {
  3988. offset = 0;
  3989. }
  3990. var te = this.elements;
  3991. array[offset] = te[0];
  3992. array[offset + 1] = te[1];
  3993. array[offset + 2] = te[2];
  3994. array[offset + 3] = te[3];
  3995. array[offset + 4] = te[4];
  3996. array[offset + 5] = te[5];
  3997. array[offset + 6] = te[6];
  3998. array[offset + 7] = te[7];
  3999. array[offset + 8] = te[8];
  4000. array[offset + 9] = te[9];
  4001. array[offset + 10] = te[10];
  4002. array[offset + 11] = te[11];
  4003. array[offset + 12] = te[12];
  4004. array[offset + 13] = te[13];
  4005. array[offset + 14] = te[14];
  4006. array[offset + 15] = te[15];
  4007. return array;
  4008. };
  4009. return Matrix4;
  4010. }();
  4011. var _v1$1 = /*@__PURE__*/new Vector3();
  4012. var _m1 = /*@__PURE__*/new Matrix4();
  4013. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4014. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4015. var _x = /*@__PURE__*/new Vector3();
  4016. var _y = /*@__PURE__*/new Vector3();
  4017. var _z = /*@__PURE__*/new Vector3();
  4018. var Euler = /*#__PURE__*/function () {
  4019. function Euler(x, y, z, order) {
  4020. if (x === void 0) {
  4021. x = 0;
  4022. }
  4023. if (y === void 0) {
  4024. y = 0;
  4025. }
  4026. if (z === void 0) {
  4027. z = 0;
  4028. }
  4029. if (order === void 0) {
  4030. order = Euler.DefaultOrder;
  4031. }
  4032. Object.defineProperty(this, 'isEuler', {
  4033. value: true
  4034. });
  4035. this._x = x;
  4036. this._y = y;
  4037. this._z = z;
  4038. this._order = order;
  4039. }
  4040. var _proto = Euler.prototype;
  4041. _proto.set = function set(x, y, z, order) {
  4042. this._x = x;
  4043. this._y = y;
  4044. this._z = z;
  4045. this._order = order || this._order;
  4046. this._onChangeCallback();
  4047. return this;
  4048. };
  4049. _proto.clone = function clone() {
  4050. return new this.constructor(this._x, this._y, this._z, this._order);
  4051. };
  4052. _proto.copy = function copy(euler) {
  4053. this._x = euler._x;
  4054. this._y = euler._y;
  4055. this._z = euler._z;
  4056. this._order = euler._order;
  4057. this._onChangeCallback();
  4058. return this;
  4059. };
  4060. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4061. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4062. var te = m.elements;
  4063. var m11 = te[0],
  4064. m12 = te[4],
  4065. m13 = te[8];
  4066. var m21 = te[1],
  4067. m22 = te[5],
  4068. m23 = te[9];
  4069. var m31 = te[2],
  4070. m32 = te[6],
  4071. m33 = te[10];
  4072. order = order || this._order;
  4073. switch (order) {
  4074. case 'XYZ':
  4075. this._y = Math.asin(clamp(m13, -1, 1));
  4076. if (Math.abs(m13) < 0.9999999) {
  4077. this._x = Math.atan2(-m23, m33);
  4078. this._z = Math.atan2(-m12, m11);
  4079. } else {
  4080. this._x = Math.atan2(m32, m22);
  4081. this._z = 0;
  4082. }
  4083. break;
  4084. case 'YXZ':
  4085. this._x = Math.asin(-clamp(m23, -1, 1));
  4086. if (Math.abs(m23) < 0.9999999) {
  4087. this._y = Math.atan2(m13, m33);
  4088. this._z = Math.atan2(m21, m22);
  4089. } else {
  4090. this._y = Math.atan2(-m31, m11);
  4091. this._z = 0;
  4092. }
  4093. break;
  4094. case 'ZXY':
  4095. this._x = Math.asin(clamp(m32, -1, 1));
  4096. if (Math.abs(m32) < 0.9999999) {
  4097. this._y = Math.atan2(-m31, m33);
  4098. this._z = Math.atan2(-m12, m22);
  4099. } else {
  4100. this._y = 0;
  4101. this._z = Math.atan2(m21, m11);
  4102. }
  4103. break;
  4104. case 'ZYX':
  4105. this._y = Math.asin(-clamp(m31, -1, 1));
  4106. if (Math.abs(m31) < 0.9999999) {
  4107. this._x = Math.atan2(m32, m33);
  4108. this._z = Math.atan2(m21, m11);
  4109. } else {
  4110. this._x = 0;
  4111. this._z = Math.atan2(-m12, m22);
  4112. }
  4113. break;
  4114. case 'YZX':
  4115. this._z = Math.asin(clamp(m21, -1, 1));
  4116. if (Math.abs(m21) < 0.9999999) {
  4117. this._x = Math.atan2(-m23, m22);
  4118. this._y = Math.atan2(-m31, m11);
  4119. } else {
  4120. this._x = 0;
  4121. this._y = Math.atan2(m13, m33);
  4122. }
  4123. break;
  4124. case 'XZY':
  4125. this._z = Math.asin(-clamp(m12, -1, 1));
  4126. if (Math.abs(m12) < 0.9999999) {
  4127. this._x = Math.atan2(m32, m22);
  4128. this._y = Math.atan2(m13, m11);
  4129. } else {
  4130. this._x = Math.atan2(-m23, m33);
  4131. this._y = 0;
  4132. }
  4133. break;
  4134. default:
  4135. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4136. }
  4137. this._order = order;
  4138. if (update !== false) this._onChangeCallback();
  4139. return this;
  4140. };
  4141. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4142. _matrix.makeRotationFromQuaternion(q);
  4143. return this.setFromRotationMatrix(_matrix, order, update);
  4144. };
  4145. _proto.setFromVector3 = function setFromVector3(v, order) {
  4146. return this.set(v.x, v.y, v.z, order || this._order);
  4147. };
  4148. _proto.reorder = function reorder(newOrder) {
  4149. // WARNING: this discards revolution information -bhouston
  4150. _quaternion$1.setFromEuler(this);
  4151. return this.setFromQuaternion(_quaternion$1, newOrder);
  4152. };
  4153. _proto.equals = function equals(euler) {
  4154. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4155. };
  4156. _proto.fromArray = function fromArray(array) {
  4157. this._x = array[0];
  4158. this._y = array[1];
  4159. this._z = array[2];
  4160. if (array[3] !== undefined) this._order = array[3];
  4161. this._onChangeCallback();
  4162. return this;
  4163. };
  4164. _proto.toArray = function toArray(array, offset) {
  4165. if (array === void 0) {
  4166. array = [];
  4167. }
  4168. if (offset === void 0) {
  4169. offset = 0;
  4170. }
  4171. array[offset] = this._x;
  4172. array[offset + 1] = this._y;
  4173. array[offset + 2] = this._z;
  4174. array[offset + 3] = this._order;
  4175. return array;
  4176. };
  4177. _proto.toVector3 = function toVector3(optionalResult) {
  4178. if (optionalResult) {
  4179. return optionalResult.set(this._x, this._y, this._z);
  4180. } else {
  4181. return new Vector3(this._x, this._y, this._z);
  4182. }
  4183. };
  4184. _proto._onChange = function _onChange(callback) {
  4185. this._onChangeCallback = callback;
  4186. return this;
  4187. };
  4188. _proto._onChangeCallback = function _onChangeCallback() {};
  4189. _createClass(Euler, [{
  4190. key: "x",
  4191. get: function get() {
  4192. return this._x;
  4193. },
  4194. set: function set(value) {
  4195. this._x = value;
  4196. this._onChangeCallback();
  4197. }
  4198. }, {
  4199. key: "y",
  4200. get: function get() {
  4201. return this._y;
  4202. },
  4203. set: function set(value) {
  4204. this._y = value;
  4205. this._onChangeCallback();
  4206. }
  4207. }, {
  4208. key: "z",
  4209. get: function get() {
  4210. return this._z;
  4211. },
  4212. set: function set(value) {
  4213. this._z = value;
  4214. this._onChangeCallback();
  4215. }
  4216. }, {
  4217. key: "order",
  4218. get: function get() {
  4219. return this._order;
  4220. },
  4221. set: function set(value) {
  4222. this._order = value;
  4223. this._onChangeCallback();
  4224. }
  4225. }]);
  4226. return Euler;
  4227. }();
  4228. Euler.DefaultOrder = 'XYZ';
  4229. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4230. var _matrix = /*@__PURE__*/new Matrix4();
  4231. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4232. var Layers = /*#__PURE__*/function () {
  4233. function Layers() {
  4234. this.mask = 1 | 0;
  4235. }
  4236. var _proto = Layers.prototype;
  4237. _proto.set = function set(channel) {
  4238. this.mask = 1 << channel | 0;
  4239. };
  4240. _proto.enable = function enable(channel) {
  4241. this.mask |= 1 << channel | 0;
  4242. };
  4243. _proto.enableAll = function enableAll() {
  4244. this.mask = 0xffffffff | 0;
  4245. };
  4246. _proto.toggle = function toggle(channel) {
  4247. this.mask ^= 1 << channel | 0;
  4248. };
  4249. _proto.disable = function disable(channel) {
  4250. this.mask &= ~(1 << channel | 0);
  4251. };
  4252. _proto.disableAll = function disableAll() {
  4253. this.mask = 0;
  4254. };
  4255. _proto.test = function test(layers) {
  4256. return (this.mask & layers.mask) !== 0;
  4257. };
  4258. return Layers;
  4259. }();
  4260. var _object3DId = 0;
  4261. var _v1$2 = new Vector3();
  4262. var _q1 = new Quaternion();
  4263. var _m1$1 = new Matrix4();
  4264. var _target = new Vector3();
  4265. var _position = new Vector3();
  4266. var _scale = new Vector3();
  4267. var _quaternion$2 = new Quaternion();
  4268. var _xAxis = new Vector3(1, 0, 0);
  4269. var _yAxis = new Vector3(0, 1, 0);
  4270. var _zAxis = new Vector3(0, 0, 1);
  4271. var _addedEvent = {
  4272. type: 'added'
  4273. };
  4274. var _removedEvent = {
  4275. type: 'removed'
  4276. };
  4277. function Object3D() {
  4278. Object.defineProperty(this, 'id', {
  4279. value: _object3DId++
  4280. });
  4281. this.uuid = MathUtils.generateUUID();
  4282. this.name = '';
  4283. this.type = 'Object3D';
  4284. this.parent = null;
  4285. this.children = [];
  4286. this.up = Object3D.DefaultUp.clone();
  4287. var position = new Vector3();
  4288. var rotation = new Euler();
  4289. var quaternion = new Quaternion();
  4290. var scale = new Vector3(1, 1, 1);
  4291. function onRotationChange() {
  4292. quaternion.setFromEuler(rotation, false);
  4293. }
  4294. function onQuaternionChange() {
  4295. rotation.setFromQuaternion(quaternion, undefined, false);
  4296. }
  4297. rotation._onChange(onRotationChange);
  4298. quaternion._onChange(onQuaternionChange);
  4299. Object.defineProperties(this, {
  4300. position: {
  4301. configurable: true,
  4302. enumerable: true,
  4303. value: position
  4304. },
  4305. rotation: {
  4306. configurable: true,
  4307. enumerable: true,
  4308. value: rotation
  4309. },
  4310. quaternion: {
  4311. configurable: true,
  4312. enumerable: true,
  4313. value: quaternion
  4314. },
  4315. scale: {
  4316. configurable: true,
  4317. enumerable: true,
  4318. value: scale
  4319. },
  4320. modelViewMatrix: {
  4321. value: new Matrix4()
  4322. },
  4323. normalMatrix: {
  4324. value: new Matrix3()
  4325. }
  4326. });
  4327. this.matrix = new Matrix4();
  4328. this.matrixWorld = new Matrix4();
  4329. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4330. this.matrixWorldNeedsUpdate = false;
  4331. this.layers = new Layers();
  4332. this.visible = true;
  4333. this.castShadow = false;
  4334. this.receiveShadow = false;
  4335. this.frustumCulled = true;
  4336. this.renderOrder = 0;
  4337. this.animations = [];
  4338. this.userData = {};
  4339. }
  4340. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4341. Object3D.DefaultMatrixAutoUpdate = true;
  4342. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4343. constructor: Object3D,
  4344. isObject3D: true,
  4345. onBeforeRender: function onBeforeRender() {},
  4346. onAfterRender: function onAfterRender() {},
  4347. applyMatrix4: function applyMatrix4(matrix) {
  4348. if (this.matrixAutoUpdate) this.updateMatrix();
  4349. this.matrix.premultiply(matrix);
  4350. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4351. },
  4352. applyQuaternion: function applyQuaternion(q) {
  4353. this.quaternion.premultiply(q);
  4354. return this;
  4355. },
  4356. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4357. // assumes axis is normalized
  4358. this.quaternion.setFromAxisAngle(axis, angle);
  4359. },
  4360. setRotationFromEuler: function setRotationFromEuler(euler) {
  4361. this.quaternion.setFromEuler(euler, true);
  4362. },
  4363. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4364. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4365. this.quaternion.setFromRotationMatrix(m);
  4366. },
  4367. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4368. // assumes q is normalized
  4369. this.quaternion.copy(q);
  4370. },
  4371. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4372. // rotate object on axis in object space
  4373. // axis is assumed to be normalized
  4374. _q1.setFromAxisAngle(axis, angle);
  4375. this.quaternion.multiply(_q1);
  4376. return this;
  4377. },
  4378. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4379. // rotate object on axis in world space
  4380. // axis is assumed to be normalized
  4381. // method assumes no rotated parent
  4382. _q1.setFromAxisAngle(axis, angle);
  4383. this.quaternion.premultiply(_q1);
  4384. return this;
  4385. },
  4386. rotateX: function rotateX(angle) {
  4387. return this.rotateOnAxis(_xAxis, angle);
  4388. },
  4389. rotateY: function rotateY(angle) {
  4390. return this.rotateOnAxis(_yAxis, angle);
  4391. },
  4392. rotateZ: function rotateZ(angle) {
  4393. return this.rotateOnAxis(_zAxis, angle);
  4394. },
  4395. translateOnAxis: function translateOnAxis(axis, distance) {
  4396. // translate object by distance along axis in object space
  4397. // axis is assumed to be normalized
  4398. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4399. this.position.add(_v1$2.multiplyScalar(distance));
  4400. return this;
  4401. },
  4402. translateX: function translateX(distance) {
  4403. return this.translateOnAxis(_xAxis, distance);
  4404. },
  4405. translateY: function translateY(distance) {
  4406. return this.translateOnAxis(_yAxis, distance);
  4407. },
  4408. translateZ: function translateZ(distance) {
  4409. return this.translateOnAxis(_zAxis, distance);
  4410. },
  4411. localToWorld: function localToWorld(vector) {
  4412. return vector.applyMatrix4(this.matrixWorld);
  4413. },
  4414. worldToLocal: function worldToLocal(vector) {
  4415. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  4416. },
  4417. lookAt: function lookAt(x, y, z) {
  4418. // This method does not support objects having non-uniformly-scaled parent(s)
  4419. if (x.isVector3) {
  4420. _target.copy(x);
  4421. } else {
  4422. _target.set(x, y, z);
  4423. }
  4424. var parent = this.parent;
  4425. this.updateWorldMatrix(true, false);
  4426. _position.setFromMatrixPosition(this.matrixWorld);
  4427. if (this.isCamera || this.isLight) {
  4428. _m1$1.lookAt(_position, _target, this.up);
  4429. } else {
  4430. _m1$1.lookAt(_target, _position, this.up);
  4431. }
  4432. this.quaternion.setFromRotationMatrix(_m1$1);
  4433. if (parent) {
  4434. _m1$1.extractRotation(parent.matrixWorld);
  4435. _q1.setFromRotationMatrix(_m1$1);
  4436. this.quaternion.premultiply(_q1.invert());
  4437. }
  4438. },
  4439. add: function add(object) {
  4440. if (arguments.length > 1) {
  4441. for (var i = 0; i < arguments.length; i++) {
  4442. this.add(arguments[i]);
  4443. }
  4444. return this;
  4445. }
  4446. if (object === this) {
  4447. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4448. return this;
  4449. }
  4450. if (object && object.isObject3D) {
  4451. if (object.parent !== null) {
  4452. object.parent.remove(object);
  4453. }
  4454. object.parent = this;
  4455. this.children.push(object);
  4456. object.dispatchEvent(_addedEvent);
  4457. } else {
  4458. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4459. }
  4460. return this;
  4461. },
  4462. remove: function remove(object) {
  4463. if (arguments.length > 1) {
  4464. for (var i = 0; i < arguments.length; i++) {
  4465. this.remove(arguments[i]);
  4466. }
  4467. return this;
  4468. }
  4469. var index = this.children.indexOf(object);
  4470. if (index !== -1) {
  4471. object.parent = null;
  4472. this.children.splice(index, 1);
  4473. object.dispatchEvent(_removedEvent);
  4474. }
  4475. return this;
  4476. },
  4477. clear: function clear() {
  4478. for (var i = 0; i < this.children.length; i++) {
  4479. var object = this.children[i];
  4480. object.parent = null;
  4481. object.dispatchEvent(_removedEvent);
  4482. }
  4483. this.children.length = 0;
  4484. return this;
  4485. },
  4486. attach: function attach(object) {
  4487. // adds object as a child of this, while maintaining the object's world transform
  4488. this.updateWorldMatrix(true, false);
  4489. _m1$1.copy(this.matrixWorld).invert();
  4490. if (object.parent !== null) {
  4491. object.parent.updateWorldMatrix(true, false);
  4492. _m1$1.multiply(object.parent.matrixWorld);
  4493. }
  4494. object.applyMatrix4(_m1$1);
  4495. object.updateWorldMatrix(false, false);
  4496. this.add(object);
  4497. return this;
  4498. },
  4499. getObjectById: function getObjectById(id) {
  4500. return this.getObjectByProperty('id', id);
  4501. },
  4502. getObjectByName: function getObjectByName(name) {
  4503. return this.getObjectByProperty('name', name);
  4504. },
  4505. getObjectByProperty: function getObjectByProperty(name, value) {
  4506. if (this[name] === value) return this;
  4507. for (var i = 0, l = this.children.length; i < l; i++) {
  4508. var child = this.children[i];
  4509. var object = child.getObjectByProperty(name, value);
  4510. if (object !== undefined) {
  4511. return object;
  4512. }
  4513. }
  4514. return undefined;
  4515. },
  4516. getWorldPosition: function getWorldPosition(target) {
  4517. if (target === undefined) {
  4518. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4519. target = new Vector3();
  4520. }
  4521. this.updateWorldMatrix(true, false);
  4522. return target.setFromMatrixPosition(this.matrixWorld);
  4523. },
  4524. getWorldQuaternion: function getWorldQuaternion(target) {
  4525. if (target === undefined) {
  4526. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4527. target = new Quaternion();
  4528. }
  4529. this.updateWorldMatrix(true, false);
  4530. this.matrixWorld.decompose(_position, target, _scale);
  4531. return target;
  4532. },
  4533. getWorldScale: function getWorldScale(target) {
  4534. if (target === undefined) {
  4535. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4536. target = new Vector3();
  4537. }
  4538. this.updateWorldMatrix(true, false);
  4539. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4540. return target;
  4541. },
  4542. getWorldDirection: function getWorldDirection(target) {
  4543. if (target === undefined) {
  4544. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4545. target = new Vector3();
  4546. }
  4547. this.updateWorldMatrix(true, false);
  4548. var e = this.matrixWorld.elements;
  4549. return target.set(e[8], e[9], e[10]).normalize();
  4550. },
  4551. raycast: function raycast() {},
  4552. traverse: function traverse(callback) {
  4553. callback(this);
  4554. var children = this.children;
  4555. for (var i = 0, l = children.length; i < l; i++) {
  4556. children[i].traverse(callback);
  4557. }
  4558. },
  4559. traverseVisible: function traverseVisible(callback) {
  4560. if (this.visible === false) return;
  4561. callback(this);
  4562. var children = this.children;
  4563. for (var i = 0, l = children.length; i < l; i++) {
  4564. children[i].traverseVisible(callback);
  4565. }
  4566. },
  4567. traverseAncestors: function traverseAncestors(callback) {
  4568. var parent = this.parent;
  4569. if (parent !== null) {
  4570. callback(parent);
  4571. parent.traverseAncestors(callback);
  4572. }
  4573. },
  4574. updateMatrix: function updateMatrix() {
  4575. this.matrix.compose(this.position, this.quaternion, this.scale);
  4576. this.matrixWorldNeedsUpdate = true;
  4577. },
  4578. updateMatrixWorld: function updateMatrixWorld(force) {
  4579. if (this.matrixAutoUpdate) this.updateMatrix();
  4580. if (this.matrixWorldNeedsUpdate || force) {
  4581. if (this.parent === null) {
  4582. this.matrixWorld.copy(this.matrix);
  4583. } else {
  4584. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4585. }
  4586. this.matrixWorldNeedsUpdate = false;
  4587. force = true;
  4588. } // update children
  4589. var children = this.children;
  4590. for (var i = 0, l = children.length; i < l; i++) {
  4591. children[i].updateMatrixWorld(force);
  4592. }
  4593. },
  4594. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4595. var parent = this.parent;
  4596. if (updateParents === true && parent !== null) {
  4597. parent.updateWorldMatrix(true, false);
  4598. }
  4599. if (this.matrixAutoUpdate) this.updateMatrix();
  4600. if (this.parent === null) {
  4601. this.matrixWorld.copy(this.matrix);
  4602. } else {
  4603. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4604. } // update children
  4605. if (updateChildren === true) {
  4606. var children = this.children;
  4607. for (var i = 0, l = children.length; i < l; i++) {
  4608. children[i].updateWorldMatrix(false, true);
  4609. }
  4610. }
  4611. },
  4612. toJSON: function toJSON(meta) {
  4613. // meta is a string when called from JSON.stringify
  4614. var isRootObject = meta === undefined || typeof meta === 'string';
  4615. var output = {}; // meta is a hash used to collect geometries, materials.
  4616. // not providing it implies that this is the root object
  4617. // being serialized.
  4618. if (isRootObject) {
  4619. // initialize meta obj
  4620. meta = {
  4621. geometries: {},
  4622. materials: {},
  4623. textures: {},
  4624. images: {},
  4625. shapes: {},
  4626. skeletons: {},
  4627. animations: {}
  4628. };
  4629. output.metadata = {
  4630. version: 4.5,
  4631. type: 'Object',
  4632. generator: 'Object3D.toJSON'
  4633. };
  4634. } // standard Object3D serialization
  4635. var object = {};
  4636. object.uuid = this.uuid;
  4637. object.type = this.type;
  4638. if (this.name !== '') object.name = this.name;
  4639. if (this.castShadow === true) object.castShadow = true;
  4640. if (this.receiveShadow === true) object.receiveShadow = true;
  4641. if (this.visible === false) object.visible = false;
  4642. if (this.frustumCulled === false) object.frustumCulled = false;
  4643. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4644. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4645. object.layers = this.layers.mask;
  4646. object.matrix = this.matrix.toArray();
  4647. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4648. if (this.isInstancedMesh) {
  4649. object.type = 'InstancedMesh';
  4650. object.count = this.count;
  4651. object.instanceMatrix = this.instanceMatrix.toJSON();
  4652. } //
  4653. function serialize(library, element) {
  4654. if (library[element.uuid] === undefined) {
  4655. library[element.uuid] = element.toJSON(meta);
  4656. }
  4657. return element.uuid;
  4658. }
  4659. if (this.isMesh || this.isLine || this.isPoints) {
  4660. object.geometry = serialize(meta.geometries, this.geometry);
  4661. var parameters = this.geometry.parameters;
  4662. if (parameters !== undefined && parameters.shapes !== undefined) {
  4663. var shapes = parameters.shapes;
  4664. if (Array.isArray(shapes)) {
  4665. for (var i = 0, l = shapes.length; i < l; i++) {
  4666. var shape = shapes[i];
  4667. serialize(meta.shapes, shape);
  4668. }
  4669. } else {
  4670. serialize(meta.shapes, shapes);
  4671. }
  4672. }
  4673. }
  4674. if (this.isSkinnedMesh) {
  4675. object.bindMode = this.bindMode;
  4676. object.bindMatrix = this.bindMatrix.toArray();
  4677. if (this.skeleton !== undefined) {
  4678. serialize(meta.skeletons, this.skeleton);
  4679. object.skeleton = this.skeleton.uuid;
  4680. }
  4681. }
  4682. if (this.material !== undefined) {
  4683. if (Array.isArray(this.material)) {
  4684. var uuids = [];
  4685. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4686. uuids.push(serialize(meta.materials, this.material[_i]));
  4687. }
  4688. object.material = uuids;
  4689. } else {
  4690. object.material = serialize(meta.materials, this.material);
  4691. }
  4692. } //
  4693. if (this.children.length > 0) {
  4694. object.children = [];
  4695. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4696. object.children.push(this.children[_i2].toJSON(meta).object);
  4697. }
  4698. } //
  4699. if (this.animations.length > 0) {
  4700. object.animations = [];
  4701. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  4702. var animation = this.animations[_i3];
  4703. object.animations.push(serialize(meta.animations, animation));
  4704. }
  4705. }
  4706. if (isRootObject) {
  4707. var geometries = extractFromCache(meta.geometries);
  4708. var materials = extractFromCache(meta.materials);
  4709. var textures = extractFromCache(meta.textures);
  4710. var images = extractFromCache(meta.images);
  4711. var _shapes = extractFromCache(meta.shapes);
  4712. var skeletons = extractFromCache(meta.skeletons);
  4713. var animations = extractFromCache(meta.animations);
  4714. if (geometries.length > 0) output.geometries = geometries;
  4715. if (materials.length > 0) output.materials = materials;
  4716. if (textures.length > 0) output.textures = textures;
  4717. if (images.length > 0) output.images = images;
  4718. if (_shapes.length > 0) output.shapes = _shapes;
  4719. if (skeletons.length > 0) output.skeletons = skeletons;
  4720. if (animations.length > 0) output.animations = animations;
  4721. }
  4722. output.object = object;
  4723. return output; // extract data from the cache hash
  4724. // remove metadata on each item
  4725. // and return as array
  4726. function extractFromCache(cache) {
  4727. var values = [];
  4728. for (var key in cache) {
  4729. var data = cache[key];
  4730. delete data.metadata;
  4731. values.push(data);
  4732. }
  4733. return values;
  4734. }
  4735. },
  4736. clone: function clone(recursive) {
  4737. return new this.constructor().copy(this, recursive);
  4738. },
  4739. copy: function copy(source, recursive) {
  4740. if (recursive === void 0) {
  4741. recursive = true;
  4742. }
  4743. this.name = source.name;
  4744. this.up.copy(source.up);
  4745. this.position.copy(source.position);
  4746. this.rotation.order = source.rotation.order;
  4747. this.quaternion.copy(source.quaternion);
  4748. this.scale.copy(source.scale);
  4749. this.matrix.copy(source.matrix);
  4750. this.matrixWorld.copy(source.matrixWorld);
  4751. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4752. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4753. this.layers.mask = source.layers.mask;
  4754. this.visible = source.visible;
  4755. this.castShadow = source.castShadow;
  4756. this.receiveShadow = source.receiveShadow;
  4757. this.frustumCulled = source.frustumCulled;
  4758. this.renderOrder = source.renderOrder;
  4759. this.userData = JSON.parse(JSON.stringify(source.userData));
  4760. if (recursive === true) {
  4761. for (var i = 0; i < source.children.length; i++) {
  4762. var child = source.children[i];
  4763. this.add(child.clone());
  4764. }
  4765. }
  4766. return this;
  4767. }
  4768. });
  4769. var _vector1 = /*@__PURE__*/new Vector3();
  4770. var _vector2 = /*@__PURE__*/new Vector3();
  4771. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4772. var Plane = /*#__PURE__*/function () {
  4773. function Plane(normal, constant) {
  4774. Object.defineProperty(this, 'isPlane', {
  4775. value: true
  4776. }); // normal is assumed to be normalized
  4777. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4778. this.constant = constant !== undefined ? constant : 0;
  4779. }
  4780. var _proto = Plane.prototype;
  4781. _proto.set = function set(normal, constant) {
  4782. this.normal.copy(normal);
  4783. this.constant = constant;
  4784. return this;
  4785. };
  4786. _proto.setComponents = function setComponents(x, y, z, w) {
  4787. this.normal.set(x, y, z);
  4788. this.constant = w;
  4789. return this;
  4790. };
  4791. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4792. this.normal.copy(normal);
  4793. this.constant = -point.dot(this.normal);
  4794. return this;
  4795. };
  4796. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4797. 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)?
  4798. this.setFromNormalAndCoplanarPoint(normal, a);
  4799. return this;
  4800. };
  4801. _proto.clone = function clone() {
  4802. return new this.constructor().copy(this);
  4803. };
  4804. _proto.copy = function copy(plane) {
  4805. this.normal.copy(plane.normal);
  4806. this.constant = plane.constant;
  4807. return this;
  4808. };
  4809. _proto.normalize = function normalize() {
  4810. // Note: will lead to a divide by zero if the plane is invalid.
  4811. var inverseNormalLength = 1.0 / this.normal.length();
  4812. this.normal.multiplyScalar(inverseNormalLength);
  4813. this.constant *= inverseNormalLength;
  4814. return this;
  4815. };
  4816. _proto.negate = function negate() {
  4817. this.constant *= -1;
  4818. this.normal.negate();
  4819. return this;
  4820. };
  4821. _proto.distanceToPoint = function distanceToPoint(point) {
  4822. return this.normal.dot(point) + this.constant;
  4823. };
  4824. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4825. return this.distanceToPoint(sphere.center) - sphere.radius;
  4826. };
  4827. _proto.projectPoint = function projectPoint(point, target) {
  4828. if (target === undefined) {
  4829. console.warn('THREE.Plane: .projectPoint() target is now required');
  4830. target = new Vector3();
  4831. }
  4832. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4833. };
  4834. _proto.intersectLine = function intersectLine(line, target) {
  4835. if (target === undefined) {
  4836. console.warn('THREE.Plane: .intersectLine() target is now required');
  4837. target = new Vector3();
  4838. }
  4839. var direction = line.delta(_vector1);
  4840. var denominator = this.normal.dot(direction);
  4841. if (denominator === 0) {
  4842. // line is coplanar, return origin
  4843. if (this.distanceToPoint(line.start) === 0) {
  4844. return target.copy(line.start);
  4845. } // Unsure if this is the correct method to handle this case.
  4846. return undefined;
  4847. }
  4848. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4849. if (t < 0 || t > 1) {
  4850. return undefined;
  4851. }
  4852. return target.copy(direction).multiplyScalar(t).add(line.start);
  4853. };
  4854. _proto.intersectsLine = function intersectsLine(line) {
  4855. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4856. var startSign = this.distanceToPoint(line.start);
  4857. var endSign = this.distanceToPoint(line.end);
  4858. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4859. };
  4860. _proto.intersectsBox = function intersectsBox(box) {
  4861. return box.intersectsPlane(this);
  4862. };
  4863. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4864. return sphere.intersectsPlane(this);
  4865. };
  4866. _proto.coplanarPoint = function coplanarPoint(target) {
  4867. if (target === undefined) {
  4868. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4869. target = new Vector3();
  4870. }
  4871. return target.copy(this.normal).multiplyScalar(-this.constant);
  4872. };
  4873. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4874. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4875. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4876. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4877. this.constant = -referencePoint.dot(normal);
  4878. return this;
  4879. };
  4880. _proto.translate = function translate(offset) {
  4881. this.constant -= offset.dot(this.normal);
  4882. return this;
  4883. };
  4884. _proto.equals = function equals(plane) {
  4885. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4886. };
  4887. return Plane;
  4888. }();
  4889. var _v0$1 = /*@__PURE__*/new Vector3();
  4890. var _v1$3 = /*@__PURE__*/new Vector3();
  4891. var _v2$1 = /*@__PURE__*/new Vector3();
  4892. var _v3 = /*@__PURE__*/new Vector3();
  4893. var _vab = /*@__PURE__*/new Vector3();
  4894. var _vac = /*@__PURE__*/new Vector3();
  4895. var _vbc = /*@__PURE__*/new Vector3();
  4896. var _vap = /*@__PURE__*/new Vector3();
  4897. var _vbp = /*@__PURE__*/new Vector3();
  4898. var _vcp = /*@__PURE__*/new Vector3();
  4899. var Triangle = /*#__PURE__*/function () {
  4900. function Triangle(a, b, c) {
  4901. this.a = a !== undefined ? a : new Vector3();
  4902. this.b = b !== undefined ? b : new Vector3();
  4903. this.c = c !== undefined ? c : new Vector3();
  4904. }
  4905. Triangle.getNormal = function getNormal(a, b, c, target) {
  4906. if (target === undefined) {
  4907. console.warn('THREE.Triangle: .getNormal() target is now required');
  4908. target = new Vector3();
  4909. }
  4910. target.subVectors(c, b);
  4911. _v0$1.subVectors(a, b);
  4912. target.cross(_v0$1);
  4913. var targetLengthSq = target.lengthSq();
  4914. if (targetLengthSq > 0) {
  4915. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4916. }
  4917. return target.set(0, 0, 0);
  4918. } // static/instance method to calculate barycentric coordinates
  4919. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4920. ;
  4921. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4922. _v0$1.subVectors(c, a);
  4923. _v1$3.subVectors(b, a);
  4924. _v2$1.subVectors(point, a);
  4925. var dot00 = _v0$1.dot(_v0$1);
  4926. var dot01 = _v0$1.dot(_v1$3);
  4927. var dot02 = _v0$1.dot(_v2$1);
  4928. var dot11 = _v1$3.dot(_v1$3);
  4929. var dot12 = _v1$3.dot(_v2$1);
  4930. var denom = dot00 * dot11 - dot01 * dot01;
  4931. if (target === undefined) {
  4932. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4933. target = new Vector3();
  4934. } // collinear or singular triangle
  4935. if (denom === 0) {
  4936. // arbitrary location outside of triangle?
  4937. // not sure if this is the best idea, maybe should be returning undefined
  4938. return target.set(-2, -1, -1);
  4939. }
  4940. var invDenom = 1 / denom;
  4941. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4942. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4943. return target.set(1 - u - v, v, u);
  4944. };
  4945. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4946. this.getBarycoord(point, a, b, c, _v3);
  4947. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4948. };
  4949. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4950. this.getBarycoord(point, p1, p2, p3, _v3);
  4951. target.set(0, 0);
  4952. target.addScaledVector(uv1, _v3.x);
  4953. target.addScaledVector(uv2, _v3.y);
  4954. target.addScaledVector(uv3, _v3.z);
  4955. return target;
  4956. };
  4957. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4958. _v0$1.subVectors(c, b);
  4959. _v1$3.subVectors(a, b); // strictly front facing
  4960. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4961. };
  4962. var _proto = Triangle.prototype;
  4963. _proto.set = function set(a, b, c) {
  4964. this.a.copy(a);
  4965. this.b.copy(b);
  4966. this.c.copy(c);
  4967. return this;
  4968. };
  4969. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4970. this.a.copy(points[i0]);
  4971. this.b.copy(points[i1]);
  4972. this.c.copy(points[i2]);
  4973. return this;
  4974. };
  4975. _proto.clone = function clone() {
  4976. return new this.constructor().copy(this);
  4977. };
  4978. _proto.copy = function copy(triangle) {
  4979. this.a.copy(triangle.a);
  4980. this.b.copy(triangle.b);
  4981. this.c.copy(triangle.c);
  4982. return this;
  4983. };
  4984. _proto.getArea = function getArea() {
  4985. _v0$1.subVectors(this.c, this.b);
  4986. _v1$3.subVectors(this.a, this.b);
  4987. return _v0$1.cross(_v1$3).length() * 0.5;
  4988. };
  4989. _proto.getMidpoint = function getMidpoint(target) {
  4990. if (target === undefined) {
  4991. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4992. target = new Vector3();
  4993. }
  4994. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4995. };
  4996. _proto.getNormal = function getNormal(target) {
  4997. return Triangle.getNormal(this.a, this.b, this.c, target);
  4998. };
  4999. _proto.getPlane = function getPlane(target) {
  5000. if (target === undefined) {
  5001. console.warn('THREE.Triangle: .getPlane() target is now required');
  5002. target = new Plane();
  5003. }
  5004. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5005. };
  5006. _proto.getBarycoord = function getBarycoord(point, target) {
  5007. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5008. };
  5009. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5010. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5011. };
  5012. _proto.containsPoint = function containsPoint(point) {
  5013. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5014. };
  5015. _proto.isFrontFacing = function isFrontFacing(direction) {
  5016. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5017. };
  5018. _proto.intersectsBox = function intersectsBox(box) {
  5019. return box.intersectsTriangle(this);
  5020. };
  5021. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5022. if (target === undefined) {
  5023. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5024. target = new Vector3();
  5025. }
  5026. var a = this.a,
  5027. b = this.b,
  5028. c = this.c;
  5029. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5030. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5031. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5032. // basically, we're distinguishing which of the voronoi regions of the triangle
  5033. // the point lies in with the minimum amount of redundant computation.
  5034. _vab.subVectors(b, a);
  5035. _vac.subVectors(c, a);
  5036. _vap.subVectors(p, a);
  5037. var d1 = _vab.dot(_vap);
  5038. var d2 = _vac.dot(_vap);
  5039. if (d1 <= 0 && d2 <= 0) {
  5040. // vertex region of A; barycentric coords (1, 0, 0)
  5041. return target.copy(a);
  5042. }
  5043. _vbp.subVectors(p, b);
  5044. var d3 = _vab.dot(_vbp);
  5045. var d4 = _vac.dot(_vbp);
  5046. if (d3 >= 0 && d4 <= d3) {
  5047. // vertex region of B; barycentric coords (0, 1, 0)
  5048. return target.copy(b);
  5049. }
  5050. var vc = d1 * d4 - d3 * d2;
  5051. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5052. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5053. return target.copy(a).addScaledVector(_vab, v);
  5054. }
  5055. _vcp.subVectors(p, c);
  5056. var d5 = _vab.dot(_vcp);
  5057. var d6 = _vac.dot(_vcp);
  5058. if (d6 >= 0 && d5 <= d6) {
  5059. // vertex region of C; barycentric coords (0, 0, 1)
  5060. return target.copy(c);
  5061. }
  5062. var vb = d5 * d2 - d1 * d6;
  5063. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5064. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5065. return target.copy(a).addScaledVector(_vac, w);
  5066. }
  5067. var va = d3 * d6 - d5 * d4;
  5068. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5069. _vbc.subVectors(c, b);
  5070. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5071. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5072. } // face region
  5073. var denom = 1 / (va + vb + vc); // u = va * denom
  5074. v = vb * denom;
  5075. w = vc * denom;
  5076. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5077. };
  5078. _proto.equals = function equals(triangle) {
  5079. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5080. };
  5081. return Triangle;
  5082. }();
  5083. var _colorKeywords = {
  5084. 'aliceblue': 0xF0F8FF,
  5085. 'antiquewhite': 0xFAEBD7,
  5086. 'aqua': 0x00FFFF,
  5087. 'aquamarine': 0x7FFFD4,
  5088. 'azure': 0xF0FFFF,
  5089. 'beige': 0xF5F5DC,
  5090. 'bisque': 0xFFE4C4,
  5091. 'black': 0x000000,
  5092. 'blanchedalmond': 0xFFEBCD,
  5093. 'blue': 0x0000FF,
  5094. 'blueviolet': 0x8A2BE2,
  5095. 'brown': 0xA52A2A,
  5096. 'burlywood': 0xDEB887,
  5097. 'cadetblue': 0x5F9EA0,
  5098. 'chartreuse': 0x7FFF00,
  5099. 'chocolate': 0xD2691E,
  5100. 'coral': 0xFF7F50,
  5101. 'cornflowerblue': 0x6495ED,
  5102. 'cornsilk': 0xFFF8DC,
  5103. 'crimson': 0xDC143C,
  5104. 'cyan': 0x00FFFF,
  5105. 'darkblue': 0x00008B,
  5106. 'darkcyan': 0x008B8B,
  5107. 'darkgoldenrod': 0xB8860B,
  5108. 'darkgray': 0xA9A9A9,
  5109. 'darkgreen': 0x006400,
  5110. 'darkgrey': 0xA9A9A9,
  5111. 'darkkhaki': 0xBDB76B,
  5112. 'darkmagenta': 0x8B008B,
  5113. 'darkolivegreen': 0x556B2F,
  5114. 'darkorange': 0xFF8C00,
  5115. 'darkorchid': 0x9932CC,
  5116. 'darkred': 0x8B0000,
  5117. 'darksalmon': 0xE9967A,
  5118. 'darkseagreen': 0x8FBC8F,
  5119. 'darkslateblue': 0x483D8B,
  5120. 'darkslategray': 0x2F4F4F,
  5121. 'darkslategrey': 0x2F4F4F,
  5122. 'darkturquoise': 0x00CED1,
  5123. 'darkviolet': 0x9400D3,
  5124. 'deeppink': 0xFF1493,
  5125. 'deepskyblue': 0x00BFFF,
  5126. 'dimgray': 0x696969,
  5127. 'dimgrey': 0x696969,
  5128. 'dodgerblue': 0x1E90FF,
  5129. 'firebrick': 0xB22222,
  5130. 'floralwhite': 0xFFFAF0,
  5131. 'forestgreen': 0x228B22,
  5132. 'fuchsia': 0xFF00FF,
  5133. 'gainsboro': 0xDCDCDC,
  5134. 'ghostwhite': 0xF8F8FF,
  5135. 'gold': 0xFFD700,
  5136. 'goldenrod': 0xDAA520,
  5137. 'gray': 0x808080,
  5138. 'green': 0x008000,
  5139. 'greenyellow': 0xADFF2F,
  5140. 'grey': 0x808080,
  5141. 'honeydew': 0xF0FFF0,
  5142. 'hotpink': 0xFF69B4,
  5143. 'indianred': 0xCD5C5C,
  5144. 'indigo': 0x4B0082,
  5145. 'ivory': 0xFFFFF0,
  5146. 'khaki': 0xF0E68C,
  5147. 'lavender': 0xE6E6FA,
  5148. 'lavenderblush': 0xFFF0F5,
  5149. 'lawngreen': 0x7CFC00,
  5150. 'lemonchiffon': 0xFFFACD,
  5151. 'lightblue': 0xADD8E6,
  5152. 'lightcoral': 0xF08080,
  5153. 'lightcyan': 0xE0FFFF,
  5154. 'lightgoldenrodyellow': 0xFAFAD2,
  5155. 'lightgray': 0xD3D3D3,
  5156. 'lightgreen': 0x90EE90,
  5157. 'lightgrey': 0xD3D3D3,
  5158. 'lightpink': 0xFFB6C1,
  5159. 'lightsalmon': 0xFFA07A,
  5160. 'lightseagreen': 0x20B2AA,
  5161. 'lightskyblue': 0x87CEFA,
  5162. 'lightslategray': 0x778899,
  5163. 'lightslategrey': 0x778899,
  5164. 'lightsteelblue': 0xB0C4DE,
  5165. 'lightyellow': 0xFFFFE0,
  5166. 'lime': 0x00FF00,
  5167. 'limegreen': 0x32CD32,
  5168. 'linen': 0xFAF0E6,
  5169. 'magenta': 0xFF00FF,
  5170. 'maroon': 0x800000,
  5171. 'mediumaquamarine': 0x66CDAA,
  5172. 'mediumblue': 0x0000CD,
  5173. 'mediumorchid': 0xBA55D3,
  5174. 'mediumpurple': 0x9370DB,
  5175. 'mediumseagreen': 0x3CB371,
  5176. 'mediumslateblue': 0x7B68EE,
  5177. 'mediumspringgreen': 0x00FA9A,
  5178. 'mediumturquoise': 0x48D1CC,
  5179. 'mediumvioletred': 0xC71585,
  5180. 'midnightblue': 0x191970,
  5181. 'mintcream': 0xF5FFFA,
  5182. 'mistyrose': 0xFFE4E1,
  5183. 'moccasin': 0xFFE4B5,
  5184. 'navajowhite': 0xFFDEAD,
  5185. 'navy': 0x000080,
  5186. 'oldlace': 0xFDF5E6,
  5187. 'olive': 0x808000,
  5188. 'olivedrab': 0x6B8E23,
  5189. 'orange': 0xFFA500,
  5190. 'orangered': 0xFF4500,
  5191. 'orchid': 0xDA70D6,
  5192. 'palegoldenrod': 0xEEE8AA,
  5193. 'palegreen': 0x98FB98,
  5194. 'paleturquoise': 0xAFEEEE,
  5195. 'palevioletred': 0xDB7093,
  5196. 'papayawhip': 0xFFEFD5,
  5197. 'peachpuff': 0xFFDAB9,
  5198. 'peru': 0xCD853F,
  5199. 'pink': 0xFFC0CB,
  5200. 'plum': 0xDDA0DD,
  5201. 'powderblue': 0xB0E0E6,
  5202. 'purple': 0x800080,
  5203. 'rebeccapurple': 0x663399,
  5204. 'red': 0xFF0000,
  5205. 'rosybrown': 0xBC8F8F,
  5206. 'royalblue': 0x4169E1,
  5207. 'saddlebrown': 0x8B4513,
  5208. 'salmon': 0xFA8072,
  5209. 'sandybrown': 0xF4A460,
  5210. 'seagreen': 0x2E8B57,
  5211. 'seashell': 0xFFF5EE,
  5212. 'sienna': 0xA0522D,
  5213. 'silver': 0xC0C0C0,
  5214. 'skyblue': 0x87CEEB,
  5215. 'slateblue': 0x6A5ACD,
  5216. 'slategray': 0x708090,
  5217. 'slategrey': 0x708090,
  5218. 'snow': 0xFFFAFA,
  5219. 'springgreen': 0x00FF7F,
  5220. 'steelblue': 0x4682B4,
  5221. 'tan': 0xD2B48C,
  5222. 'teal': 0x008080,
  5223. 'thistle': 0xD8BFD8,
  5224. 'tomato': 0xFF6347,
  5225. 'turquoise': 0x40E0D0,
  5226. 'violet': 0xEE82EE,
  5227. 'wheat': 0xF5DEB3,
  5228. 'white': 0xFFFFFF,
  5229. 'whitesmoke': 0xF5F5F5,
  5230. 'yellow': 0xFFFF00,
  5231. 'yellowgreen': 0x9ACD32
  5232. };
  5233. var _hslA = {
  5234. h: 0,
  5235. s: 0,
  5236. l: 0
  5237. };
  5238. var _hslB = {
  5239. h: 0,
  5240. s: 0,
  5241. l: 0
  5242. };
  5243. function hue2rgb(p, q, t) {
  5244. if (t < 0) t += 1;
  5245. if (t > 1) t -= 1;
  5246. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5247. if (t < 1 / 2) return q;
  5248. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5249. return p;
  5250. }
  5251. function SRGBToLinear(c) {
  5252. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5253. }
  5254. function LinearToSRGB(c) {
  5255. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5256. }
  5257. var Color = /*#__PURE__*/function () {
  5258. function Color(r, g, b) {
  5259. Object.defineProperty(this, 'isColor', {
  5260. value: true
  5261. });
  5262. if (g === undefined && b === undefined) {
  5263. // r is THREE.Color, hex or string
  5264. return this.set(r);
  5265. }
  5266. return this.setRGB(r, g, b);
  5267. }
  5268. var _proto = Color.prototype;
  5269. _proto.set = function set(value) {
  5270. if (value && value.isColor) {
  5271. this.copy(value);
  5272. } else if (typeof value === 'number') {
  5273. this.setHex(value);
  5274. } else if (typeof value === 'string') {
  5275. this.setStyle(value);
  5276. }
  5277. return this;
  5278. };
  5279. _proto.setScalar = function setScalar(scalar) {
  5280. this.r = scalar;
  5281. this.g = scalar;
  5282. this.b = scalar;
  5283. return this;
  5284. };
  5285. _proto.setHex = function setHex(hex) {
  5286. hex = Math.floor(hex);
  5287. this.r = (hex >> 16 & 255) / 255;
  5288. this.g = (hex >> 8 & 255) / 255;
  5289. this.b = (hex & 255) / 255;
  5290. return this;
  5291. };
  5292. _proto.setRGB = function setRGB(r, g, b) {
  5293. this.r = r;
  5294. this.g = g;
  5295. this.b = b;
  5296. return this;
  5297. };
  5298. _proto.setHSL = function setHSL(h, s, l) {
  5299. // h,s,l ranges are in 0.0 - 1.0
  5300. h = MathUtils.euclideanModulo(h, 1);
  5301. s = MathUtils.clamp(s, 0, 1);
  5302. l = MathUtils.clamp(l, 0, 1);
  5303. if (s === 0) {
  5304. this.r = this.g = this.b = l;
  5305. } else {
  5306. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5307. var q = 2 * l - p;
  5308. this.r = hue2rgb(q, p, h + 1 / 3);
  5309. this.g = hue2rgb(q, p, h);
  5310. this.b = hue2rgb(q, p, h - 1 / 3);
  5311. }
  5312. return this;
  5313. };
  5314. _proto.setStyle = function setStyle(style) {
  5315. function handleAlpha(string) {
  5316. if (string === undefined) return;
  5317. if (parseFloat(string) < 1) {
  5318. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5319. }
  5320. }
  5321. var m;
  5322. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5323. // rgb / hsl
  5324. var color;
  5325. var name = m[1];
  5326. var components = m[2];
  5327. switch (name) {
  5328. case 'rgb':
  5329. case 'rgba':
  5330. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5331. // rgb(255,0,0) rgba(255,0,0,0.5)
  5332. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5333. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5334. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5335. handleAlpha(color[5]);
  5336. return this;
  5337. }
  5338. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5339. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5340. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5341. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5342. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5343. handleAlpha(color[5]);
  5344. return this;
  5345. }
  5346. break;
  5347. case 'hsl':
  5348. case 'hsla':
  5349. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5350. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5351. var h = parseFloat(color[1]) / 360;
  5352. var s = parseInt(color[2], 10) / 100;
  5353. var l = parseInt(color[3], 10) / 100;
  5354. handleAlpha(color[5]);
  5355. return this.setHSL(h, s, l);
  5356. }
  5357. break;
  5358. }
  5359. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5360. // hex color
  5361. var hex = m[1];
  5362. var size = hex.length;
  5363. if (size === 3) {
  5364. // #ff0
  5365. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5366. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5367. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5368. return this;
  5369. } else if (size === 6) {
  5370. // #ff0000
  5371. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5372. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5373. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5374. return this;
  5375. }
  5376. }
  5377. if (style && style.length > 0) {
  5378. return this.setColorName(style);
  5379. }
  5380. return this;
  5381. };
  5382. _proto.setColorName = function setColorName(style) {
  5383. // color keywords
  5384. var hex = _colorKeywords[style];
  5385. if (hex !== undefined) {
  5386. // red
  5387. this.setHex(hex);
  5388. } else {
  5389. // unknown color
  5390. console.warn('THREE.Color: Unknown color ' + style);
  5391. }
  5392. return this;
  5393. };
  5394. _proto.clone = function clone() {
  5395. return new this.constructor(this.r, this.g, this.b);
  5396. };
  5397. _proto.copy = function copy(color) {
  5398. this.r = color.r;
  5399. this.g = color.g;
  5400. this.b = color.b;
  5401. return this;
  5402. };
  5403. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5404. if (gammaFactor === void 0) {
  5405. gammaFactor = 2.0;
  5406. }
  5407. this.r = Math.pow(color.r, gammaFactor);
  5408. this.g = Math.pow(color.g, gammaFactor);
  5409. this.b = Math.pow(color.b, gammaFactor);
  5410. return this;
  5411. };
  5412. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5413. if (gammaFactor === void 0) {
  5414. gammaFactor = 2.0;
  5415. }
  5416. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5417. this.r = Math.pow(color.r, safeInverse);
  5418. this.g = Math.pow(color.g, safeInverse);
  5419. this.b = Math.pow(color.b, safeInverse);
  5420. return this;
  5421. };
  5422. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5423. this.copyGammaToLinear(this, gammaFactor);
  5424. return this;
  5425. };
  5426. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5427. this.copyLinearToGamma(this, gammaFactor);
  5428. return this;
  5429. };
  5430. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5431. this.r = SRGBToLinear(color.r);
  5432. this.g = SRGBToLinear(color.g);
  5433. this.b = SRGBToLinear(color.b);
  5434. return this;
  5435. };
  5436. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5437. this.r = LinearToSRGB(color.r);
  5438. this.g = LinearToSRGB(color.g);
  5439. this.b = LinearToSRGB(color.b);
  5440. return this;
  5441. };
  5442. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5443. this.copySRGBToLinear(this);
  5444. return this;
  5445. };
  5446. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5447. this.copyLinearToSRGB(this);
  5448. return this;
  5449. };
  5450. _proto.getHex = function getHex() {
  5451. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5452. };
  5453. _proto.getHexString = function getHexString() {
  5454. return ('000000' + this.getHex().toString(16)).slice(-6);
  5455. };
  5456. _proto.getHSL = function getHSL(target) {
  5457. // h,s,l ranges are in 0.0 - 1.0
  5458. if (target === undefined) {
  5459. console.warn('THREE.Color: .getHSL() target is now required');
  5460. target = {
  5461. h: 0,
  5462. s: 0,
  5463. l: 0
  5464. };
  5465. }
  5466. var r = this.r,
  5467. g = this.g,
  5468. b = this.b;
  5469. var max = Math.max(r, g, b);
  5470. var min = Math.min(r, g, b);
  5471. var hue, saturation;
  5472. var lightness = (min + max) / 2.0;
  5473. if (min === max) {
  5474. hue = 0;
  5475. saturation = 0;
  5476. } else {
  5477. var delta = max - min;
  5478. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5479. switch (max) {
  5480. case r:
  5481. hue = (g - b) / delta + (g < b ? 6 : 0);
  5482. break;
  5483. case g:
  5484. hue = (b - r) / delta + 2;
  5485. break;
  5486. case b:
  5487. hue = (r - g) / delta + 4;
  5488. break;
  5489. }
  5490. hue /= 6;
  5491. }
  5492. target.h = hue;
  5493. target.s = saturation;
  5494. target.l = lightness;
  5495. return target;
  5496. };
  5497. _proto.getStyle = function getStyle() {
  5498. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5499. };
  5500. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5501. this.getHSL(_hslA);
  5502. _hslA.h += h;
  5503. _hslA.s += s;
  5504. _hslA.l += l;
  5505. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5506. return this;
  5507. };
  5508. _proto.add = function add(color) {
  5509. this.r += color.r;
  5510. this.g += color.g;
  5511. this.b += color.b;
  5512. return this;
  5513. };
  5514. _proto.addColors = function addColors(color1, color2) {
  5515. this.r = color1.r + color2.r;
  5516. this.g = color1.g + color2.g;
  5517. this.b = color1.b + color2.b;
  5518. return this;
  5519. };
  5520. _proto.addScalar = function addScalar(s) {
  5521. this.r += s;
  5522. this.g += s;
  5523. this.b += s;
  5524. return this;
  5525. };
  5526. _proto.sub = function sub(color) {
  5527. this.r = Math.max(0, this.r - color.r);
  5528. this.g = Math.max(0, this.g - color.g);
  5529. this.b = Math.max(0, this.b - color.b);
  5530. return this;
  5531. };
  5532. _proto.multiply = function multiply(color) {
  5533. this.r *= color.r;
  5534. this.g *= color.g;
  5535. this.b *= color.b;
  5536. return this;
  5537. };
  5538. _proto.multiplyScalar = function multiplyScalar(s) {
  5539. this.r *= s;
  5540. this.g *= s;
  5541. this.b *= s;
  5542. return this;
  5543. };
  5544. _proto.lerp = function lerp(color, alpha) {
  5545. this.r += (color.r - this.r) * alpha;
  5546. this.g += (color.g - this.g) * alpha;
  5547. this.b += (color.b - this.b) * alpha;
  5548. return this;
  5549. };
  5550. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5551. this.getHSL(_hslA);
  5552. color.getHSL(_hslB);
  5553. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5554. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5555. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5556. this.setHSL(h, s, l);
  5557. return this;
  5558. };
  5559. _proto.equals = function equals(c) {
  5560. return c.r === this.r && c.g === this.g && c.b === this.b;
  5561. };
  5562. _proto.fromArray = function fromArray(array, offset) {
  5563. if (offset === void 0) {
  5564. offset = 0;
  5565. }
  5566. this.r = array[offset];
  5567. this.g = array[offset + 1];
  5568. this.b = array[offset + 2];
  5569. return this;
  5570. };
  5571. _proto.toArray = function toArray(array, offset) {
  5572. if (array === void 0) {
  5573. array = [];
  5574. }
  5575. if (offset === void 0) {
  5576. offset = 0;
  5577. }
  5578. array[offset] = this.r;
  5579. array[offset + 1] = this.g;
  5580. array[offset + 2] = this.b;
  5581. return array;
  5582. };
  5583. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5584. this.r = attribute.getX(index);
  5585. this.g = attribute.getY(index);
  5586. this.b = attribute.getZ(index);
  5587. if (attribute.normalized === true) {
  5588. // assuming Uint8Array
  5589. this.r /= 255;
  5590. this.g /= 255;
  5591. this.b /= 255;
  5592. }
  5593. return this;
  5594. };
  5595. _proto.toJSON = function toJSON() {
  5596. return this.getHex();
  5597. };
  5598. return Color;
  5599. }();
  5600. Color.NAMES = _colorKeywords;
  5601. Color.prototype.r = 1;
  5602. Color.prototype.g = 1;
  5603. Color.prototype.b = 1;
  5604. var Face3 = /*#__PURE__*/function () {
  5605. function Face3(a, b, c, normal, color, materialIndex) {
  5606. if (materialIndex === void 0) {
  5607. materialIndex = 0;
  5608. }
  5609. this.a = a;
  5610. this.b = b;
  5611. this.c = c;
  5612. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5613. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5614. this.color = color && color.isColor ? color : new Color();
  5615. this.vertexColors = Array.isArray(color) ? color : [];
  5616. this.materialIndex = materialIndex;
  5617. }
  5618. var _proto = Face3.prototype;
  5619. _proto.clone = function clone() {
  5620. return new this.constructor().copy(this);
  5621. };
  5622. _proto.copy = function copy(source) {
  5623. this.a = source.a;
  5624. this.b = source.b;
  5625. this.c = source.c;
  5626. this.normal.copy(source.normal);
  5627. this.color.copy(source.color);
  5628. this.materialIndex = source.materialIndex;
  5629. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5630. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5631. }
  5632. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5633. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5634. }
  5635. return this;
  5636. };
  5637. return Face3;
  5638. }();
  5639. var materialId = 0;
  5640. function Material() {
  5641. Object.defineProperty(this, 'id', {
  5642. value: materialId++
  5643. });
  5644. this.uuid = MathUtils.generateUUID();
  5645. this.name = '';
  5646. this.type = 'Material';
  5647. this.fog = true;
  5648. this.blending = NormalBlending;
  5649. this.side = FrontSide;
  5650. this.flatShading = false;
  5651. this.vertexColors = false;
  5652. this.opacity = 1;
  5653. this.transparent = false;
  5654. this.blendSrc = SrcAlphaFactor;
  5655. this.blendDst = OneMinusSrcAlphaFactor;
  5656. this.blendEquation = AddEquation;
  5657. this.blendSrcAlpha = null;
  5658. this.blendDstAlpha = null;
  5659. this.blendEquationAlpha = null;
  5660. this.depthFunc = LessEqualDepth;
  5661. this.depthTest = true;
  5662. this.depthWrite = true;
  5663. this.stencilWriteMask = 0xff;
  5664. this.stencilFunc = AlwaysStencilFunc;
  5665. this.stencilRef = 0;
  5666. this.stencilFuncMask = 0xff;
  5667. this.stencilFail = KeepStencilOp;
  5668. this.stencilZFail = KeepStencilOp;
  5669. this.stencilZPass = KeepStencilOp;
  5670. this.stencilWrite = false;
  5671. this.clippingPlanes = null;
  5672. this.clipIntersection = false;
  5673. this.clipShadows = false;
  5674. this.shadowSide = null;
  5675. this.colorWrite = true;
  5676. this.precision = null; // override the renderer's default precision for this material
  5677. this.polygonOffset = false;
  5678. this.polygonOffsetFactor = 0;
  5679. this.polygonOffsetUnits = 0;
  5680. this.dithering = false;
  5681. this.alphaTest = 0;
  5682. this.premultipliedAlpha = false;
  5683. this.visible = true;
  5684. this.toneMapped = true;
  5685. this.userData = {};
  5686. this.version = 0;
  5687. }
  5688. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5689. constructor: Material,
  5690. isMaterial: true,
  5691. onBeforeCompile: function onBeforeCompile()
  5692. /* shaderobject, renderer */
  5693. {},
  5694. customProgramCacheKey: function customProgramCacheKey() {
  5695. return this.onBeforeCompile.toString();
  5696. },
  5697. setValues: function setValues(values) {
  5698. if (values === undefined) return;
  5699. for (var key in values) {
  5700. var newValue = values[key];
  5701. if (newValue === undefined) {
  5702. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5703. continue;
  5704. } // for backward compatability if shading is set in the constructor
  5705. if (key === 'shading') {
  5706. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5707. this.flatShading = newValue === FlatShading ? true : false;
  5708. continue;
  5709. }
  5710. var currentValue = this[key];
  5711. if (currentValue === undefined) {
  5712. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5713. continue;
  5714. }
  5715. if (currentValue && currentValue.isColor) {
  5716. currentValue.set(newValue);
  5717. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5718. currentValue.copy(newValue);
  5719. } else {
  5720. this[key] = newValue;
  5721. }
  5722. }
  5723. },
  5724. toJSON: function toJSON(meta) {
  5725. var isRoot = meta === undefined || typeof meta === 'string';
  5726. if (isRoot) {
  5727. meta = {
  5728. textures: {},
  5729. images: {}
  5730. };
  5731. }
  5732. var data = {
  5733. metadata: {
  5734. version: 4.5,
  5735. type: 'Material',
  5736. generator: 'Material.toJSON'
  5737. }
  5738. }; // standard Material serialization
  5739. data.uuid = this.uuid;
  5740. data.type = this.type;
  5741. if (this.name !== '') data.name = this.name;
  5742. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5743. if (this.roughness !== undefined) data.roughness = this.roughness;
  5744. if (this.metalness !== undefined) data.metalness = this.metalness;
  5745. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5746. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5747. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5748. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5749. if (this.shininess !== undefined) data.shininess = this.shininess;
  5750. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5751. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5752. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5753. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5754. }
  5755. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5756. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5757. }
  5758. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5759. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5760. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5761. }
  5762. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5763. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5764. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5765. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5766. if (this.aoMap && this.aoMap.isTexture) {
  5767. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5768. data.aoMapIntensity = this.aoMapIntensity;
  5769. }
  5770. if (this.bumpMap && this.bumpMap.isTexture) {
  5771. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5772. data.bumpScale = this.bumpScale;
  5773. }
  5774. if (this.normalMap && this.normalMap.isTexture) {
  5775. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5776. data.normalMapType = this.normalMapType;
  5777. data.normalScale = this.normalScale.toArray();
  5778. }
  5779. if (this.displacementMap && this.displacementMap.isTexture) {
  5780. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5781. data.displacementScale = this.displacementScale;
  5782. data.displacementBias = this.displacementBias;
  5783. }
  5784. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5785. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5786. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5787. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5788. if (this.envMap && this.envMap.isTexture) {
  5789. data.envMap = this.envMap.toJSON(meta).uuid;
  5790. data.reflectivity = this.reflectivity; // Scale behind envMap
  5791. data.refractionRatio = this.refractionRatio;
  5792. if (this.combine !== undefined) data.combine = this.combine;
  5793. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5794. }
  5795. if (this.gradientMap && this.gradientMap.isTexture) {
  5796. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5797. }
  5798. if (this.size !== undefined) data.size = this.size;
  5799. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5800. if (this.blending !== NormalBlending) data.blending = this.blending;
  5801. if (this.flatShading === true) data.flatShading = this.flatShading;
  5802. if (this.side !== FrontSide) data.side = this.side;
  5803. if (this.vertexColors) data.vertexColors = true;
  5804. if (this.opacity < 1) data.opacity = this.opacity;
  5805. if (this.transparent === true) data.transparent = this.transparent;
  5806. data.depthFunc = this.depthFunc;
  5807. data.depthTest = this.depthTest;
  5808. data.depthWrite = this.depthWrite;
  5809. data.stencilWrite = this.stencilWrite;
  5810. data.stencilWriteMask = this.stencilWriteMask;
  5811. data.stencilFunc = this.stencilFunc;
  5812. data.stencilRef = this.stencilRef;
  5813. data.stencilFuncMask = this.stencilFuncMask;
  5814. data.stencilFail = this.stencilFail;
  5815. data.stencilZFail = this.stencilZFail;
  5816. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5817. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5818. if (this.polygonOffset === true) data.polygonOffset = true;
  5819. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5820. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5821. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5822. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5823. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5824. if (this.scale !== undefined) data.scale = this.scale;
  5825. if (this.dithering === true) data.dithering = true;
  5826. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5827. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5828. if (this.wireframe === true) data.wireframe = this.wireframe;
  5829. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5830. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5831. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5832. if (this.morphTargets === true) data.morphTargets = true;
  5833. if (this.morphNormals === true) data.morphNormals = true;
  5834. if (this.skinning === true) data.skinning = true;
  5835. if (this.visible === false) data.visible = false;
  5836. if (this.toneMapped === false) data.toneMapped = false;
  5837. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5838. function extractFromCache(cache) {
  5839. var values = [];
  5840. for (var key in cache) {
  5841. var _data = cache[key];
  5842. delete _data.metadata;
  5843. values.push(_data);
  5844. }
  5845. return values;
  5846. }
  5847. if (isRoot) {
  5848. var textures = extractFromCache(meta.textures);
  5849. var images = extractFromCache(meta.images);
  5850. if (textures.length > 0) data.textures = textures;
  5851. if (images.length > 0) data.images = images;
  5852. }
  5853. return data;
  5854. },
  5855. clone: function clone() {
  5856. return new this.constructor().copy(this);
  5857. },
  5858. copy: function copy(source) {
  5859. this.name = source.name;
  5860. this.fog = source.fog;
  5861. this.blending = source.blending;
  5862. this.side = source.side;
  5863. this.flatShading = source.flatShading;
  5864. this.vertexColors = source.vertexColors;
  5865. this.opacity = source.opacity;
  5866. this.transparent = source.transparent;
  5867. this.blendSrc = source.blendSrc;
  5868. this.blendDst = source.blendDst;
  5869. this.blendEquation = source.blendEquation;
  5870. this.blendSrcAlpha = source.blendSrcAlpha;
  5871. this.blendDstAlpha = source.blendDstAlpha;
  5872. this.blendEquationAlpha = source.blendEquationAlpha;
  5873. this.depthFunc = source.depthFunc;
  5874. this.depthTest = source.depthTest;
  5875. this.depthWrite = source.depthWrite;
  5876. this.stencilWriteMask = source.stencilWriteMask;
  5877. this.stencilFunc = source.stencilFunc;
  5878. this.stencilRef = source.stencilRef;
  5879. this.stencilFuncMask = source.stencilFuncMask;
  5880. this.stencilFail = source.stencilFail;
  5881. this.stencilZFail = source.stencilZFail;
  5882. this.stencilZPass = source.stencilZPass;
  5883. this.stencilWrite = source.stencilWrite;
  5884. var srcPlanes = source.clippingPlanes;
  5885. var dstPlanes = null;
  5886. if (srcPlanes !== null) {
  5887. var n = srcPlanes.length;
  5888. dstPlanes = new Array(n);
  5889. for (var i = 0; i !== n; ++i) {
  5890. dstPlanes[i] = srcPlanes[i].clone();
  5891. }
  5892. }
  5893. this.clippingPlanes = dstPlanes;
  5894. this.clipIntersection = source.clipIntersection;
  5895. this.clipShadows = source.clipShadows;
  5896. this.shadowSide = source.shadowSide;
  5897. this.colorWrite = source.colorWrite;
  5898. this.precision = source.precision;
  5899. this.polygonOffset = source.polygonOffset;
  5900. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5901. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5902. this.dithering = source.dithering;
  5903. this.alphaTest = source.alphaTest;
  5904. this.premultipliedAlpha = source.premultipliedAlpha;
  5905. this.visible = source.visible;
  5906. this.toneMapped = source.toneMapped;
  5907. this.userData = JSON.parse(JSON.stringify(source.userData));
  5908. return this;
  5909. },
  5910. dispose: function dispose() {
  5911. this.dispatchEvent({
  5912. type: 'dispose'
  5913. });
  5914. }
  5915. });
  5916. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5917. set: function set(value) {
  5918. if (value === true) this.version++;
  5919. }
  5920. });
  5921. /**
  5922. * parameters = {
  5923. * color: <hex>,
  5924. * opacity: <float>,
  5925. * map: new THREE.Texture( <Image> ),
  5926. *
  5927. * lightMap: new THREE.Texture( <Image> ),
  5928. * lightMapIntensity: <float>
  5929. *
  5930. * aoMap: new THREE.Texture( <Image> ),
  5931. * aoMapIntensity: <float>
  5932. *
  5933. * specularMap: new THREE.Texture( <Image> ),
  5934. *
  5935. * alphaMap: new THREE.Texture( <Image> ),
  5936. *
  5937. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5938. * combine: THREE.Multiply,
  5939. * reflectivity: <float>,
  5940. * refractionRatio: <float>,
  5941. *
  5942. * depthTest: <bool>,
  5943. * depthWrite: <bool>,
  5944. *
  5945. * wireframe: <boolean>,
  5946. * wireframeLinewidth: <float>,
  5947. *
  5948. * skinning: <bool>,
  5949. * morphTargets: <bool>
  5950. * }
  5951. */
  5952. function MeshBasicMaterial(parameters) {
  5953. Material.call(this);
  5954. this.type = 'MeshBasicMaterial';
  5955. this.color = new Color(0xffffff); // emissive
  5956. this.map = null;
  5957. this.lightMap = null;
  5958. this.lightMapIntensity = 1.0;
  5959. this.aoMap = null;
  5960. this.aoMapIntensity = 1.0;
  5961. this.specularMap = null;
  5962. this.alphaMap = null;
  5963. this.envMap = null;
  5964. this.combine = MultiplyOperation;
  5965. this.reflectivity = 1;
  5966. this.refractionRatio = 0.98;
  5967. this.wireframe = false;
  5968. this.wireframeLinewidth = 1;
  5969. this.wireframeLinecap = 'round';
  5970. this.wireframeLinejoin = 'round';
  5971. this.skinning = false;
  5972. this.morphTargets = false;
  5973. this.setValues(parameters);
  5974. }
  5975. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5976. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5977. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5978. MeshBasicMaterial.prototype.copy = function (source) {
  5979. Material.prototype.copy.call(this, source);
  5980. this.color.copy(source.color);
  5981. this.map = source.map;
  5982. this.lightMap = source.lightMap;
  5983. this.lightMapIntensity = source.lightMapIntensity;
  5984. this.aoMap = source.aoMap;
  5985. this.aoMapIntensity = source.aoMapIntensity;
  5986. this.specularMap = source.specularMap;
  5987. this.alphaMap = source.alphaMap;
  5988. this.envMap = source.envMap;
  5989. this.combine = source.combine;
  5990. this.reflectivity = source.reflectivity;
  5991. this.refractionRatio = source.refractionRatio;
  5992. this.wireframe = source.wireframe;
  5993. this.wireframeLinewidth = source.wireframeLinewidth;
  5994. this.wireframeLinecap = source.wireframeLinecap;
  5995. this.wireframeLinejoin = source.wireframeLinejoin;
  5996. this.skinning = source.skinning;
  5997. this.morphTargets = source.morphTargets;
  5998. return this;
  5999. };
  6000. var _vector$3 = new Vector3();
  6001. var _vector2$1 = new Vector2();
  6002. function BufferAttribute(array, itemSize, normalized) {
  6003. if (Array.isArray(array)) {
  6004. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6005. }
  6006. this.name = '';
  6007. this.array = array;
  6008. this.itemSize = itemSize;
  6009. this.count = array !== undefined ? array.length / itemSize : 0;
  6010. this.normalized = normalized === true;
  6011. this.usage = StaticDrawUsage;
  6012. this.updateRange = {
  6013. offset: 0,
  6014. count: -1
  6015. };
  6016. this.version = 0;
  6017. }
  6018. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6019. set: function set(value) {
  6020. if (value === true) this.version++;
  6021. }
  6022. });
  6023. Object.assign(BufferAttribute.prototype, {
  6024. isBufferAttribute: true,
  6025. onUploadCallback: function onUploadCallback() {},
  6026. setUsage: function setUsage(value) {
  6027. this.usage = value;
  6028. return this;
  6029. },
  6030. copy: function copy(source) {
  6031. this.name = source.name;
  6032. this.array = new source.array.constructor(source.array);
  6033. this.itemSize = source.itemSize;
  6034. this.count = source.count;
  6035. this.normalized = source.normalized;
  6036. this.usage = source.usage;
  6037. return this;
  6038. },
  6039. copyAt: function copyAt(index1, attribute, index2) {
  6040. index1 *= this.itemSize;
  6041. index2 *= attribute.itemSize;
  6042. for (var i = 0, l = this.itemSize; i < l; i++) {
  6043. this.array[index1 + i] = attribute.array[index2 + i];
  6044. }
  6045. return this;
  6046. },
  6047. copyArray: function copyArray(array) {
  6048. this.array.set(array);
  6049. return this;
  6050. },
  6051. copyColorsArray: function copyColorsArray(colors) {
  6052. var array = this.array;
  6053. var offset = 0;
  6054. for (var i = 0, l = colors.length; i < l; i++) {
  6055. var color = colors[i];
  6056. if (color === undefined) {
  6057. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6058. color = new Color();
  6059. }
  6060. array[offset++] = color.r;
  6061. array[offset++] = color.g;
  6062. array[offset++] = color.b;
  6063. }
  6064. return this;
  6065. },
  6066. copyVector2sArray: function copyVector2sArray(vectors) {
  6067. var array = this.array;
  6068. var offset = 0;
  6069. for (var i = 0, l = vectors.length; i < l; i++) {
  6070. var vector = vectors[i];
  6071. if (vector === undefined) {
  6072. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6073. vector = new Vector2();
  6074. }
  6075. array[offset++] = vector.x;
  6076. array[offset++] = vector.y;
  6077. }
  6078. return this;
  6079. },
  6080. copyVector3sArray: function copyVector3sArray(vectors) {
  6081. var array = this.array;
  6082. var offset = 0;
  6083. for (var i = 0, l = vectors.length; i < l; i++) {
  6084. var vector = vectors[i];
  6085. if (vector === undefined) {
  6086. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6087. vector = new Vector3();
  6088. }
  6089. array[offset++] = vector.x;
  6090. array[offset++] = vector.y;
  6091. array[offset++] = vector.z;
  6092. }
  6093. return this;
  6094. },
  6095. copyVector4sArray: function copyVector4sArray(vectors) {
  6096. var array = this.array;
  6097. var offset = 0;
  6098. for (var i = 0, l = vectors.length; i < l; i++) {
  6099. var vector = vectors[i];
  6100. if (vector === undefined) {
  6101. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6102. vector = new Vector4();
  6103. }
  6104. array[offset++] = vector.x;
  6105. array[offset++] = vector.y;
  6106. array[offset++] = vector.z;
  6107. array[offset++] = vector.w;
  6108. }
  6109. return this;
  6110. },
  6111. applyMatrix3: function applyMatrix3(m) {
  6112. if (this.itemSize === 2) {
  6113. for (var i = 0, l = this.count; i < l; i++) {
  6114. _vector2$1.fromBufferAttribute(this, i);
  6115. _vector2$1.applyMatrix3(m);
  6116. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6117. }
  6118. } else if (this.itemSize === 3) {
  6119. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6120. _vector$3.fromBufferAttribute(this, _i);
  6121. _vector$3.applyMatrix3(m);
  6122. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6123. }
  6124. }
  6125. return this;
  6126. },
  6127. applyMatrix4: function applyMatrix4(m) {
  6128. for (var i = 0, l = this.count; i < l; i++) {
  6129. _vector$3.x = this.getX(i);
  6130. _vector$3.y = this.getY(i);
  6131. _vector$3.z = this.getZ(i);
  6132. _vector$3.applyMatrix4(m);
  6133. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6134. }
  6135. return this;
  6136. },
  6137. applyNormalMatrix: function applyNormalMatrix(m) {
  6138. for (var i = 0, l = this.count; i < l; i++) {
  6139. _vector$3.x = this.getX(i);
  6140. _vector$3.y = this.getY(i);
  6141. _vector$3.z = this.getZ(i);
  6142. _vector$3.applyNormalMatrix(m);
  6143. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6144. }
  6145. return this;
  6146. },
  6147. transformDirection: function transformDirection(m) {
  6148. for (var i = 0, l = this.count; i < l; i++) {
  6149. _vector$3.x = this.getX(i);
  6150. _vector$3.y = this.getY(i);
  6151. _vector$3.z = this.getZ(i);
  6152. _vector$3.transformDirection(m);
  6153. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6154. }
  6155. return this;
  6156. },
  6157. set: function set(value, offset) {
  6158. if (offset === void 0) {
  6159. offset = 0;
  6160. }
  6161. this.array.set(value, offset);
  6162. return this;
  6163. },
  6164. getX: function getX(index) {
  6165. return this.array[index * this.itemSize];
  6166. },
  6167. setX: function setX(index, x) {
  6168. this.array[index * this.itemSize] = x;
  6169. return this;
  6170. },
  6171. getY: function getY(index) {
  6172. return this.array[index * this.itemSize + 1];
  6173. },
  6174. setY: function setY(index, y) {
  6175. this.array[index * this.itemSize + 1] = y;
  6176. return this;
  6177. },
  6178. getZ: function getZ(index) {
  6179. return this.array[index * this.itemSize + 2];
  6180. },
  6181. setZ: function setZ(index, z) {
  6182. this.array[index * this.itemSize + 2] = z;
  6183. return this;
  6184. },
  6185. getW: function getW(index) {
  6186. return this.array[index * this.itemSize + 3];
  6187. },
  6188. setW: function setW(index, w) {
  6189. this.array[index * this.itemSize + 3] = w;
  6190. return this;
  6191. },
  6192. setXY: function setXY(index, x, y) {
  6193. index *= this.itemSize;
  6194. this.array[index + 0] = x;
  6195. this.array[index + 1] = y;
  6196. return this;
  6197. },
  6198. setXYZ: function setXYZ(index, x, y, z) {
  6199. index *= this.itemSize;
  6200. this.array[index + 0] = x;
  6201. this.array[index + 1] = y;
  6202. this.array[index + 2] = z;
  6203. return this;
  6204. },
  6205. setXYZW: function setXYZW(index, x, y, z, w) {
  6206. index *= this.itemSize;
  6207. this.array[index + 0] = x;
  6208. this.array[index + 1] = y;
  6209. this.array[index + 2] = z;
  6210. this.array[index + 3] = w;
  6211. return this;
  6212. },
  6213. onUpload: function onUpload(callback) {
  6214. this.onUploadCallback = callback;
  6215. return this;
  6216. },
  6217. clone: function clone() {
  6218. return new this.constructor(this.array, this.itemSize).copy(this);
  6219. },
  6220. toJSON: function toJSON() {
  6221. return {
  6222. itemSize: this.itemSize,
  6223. type: this.array.constructor.name,
  6224. array: Array.prototype.slice.call(this.array),
  6225. normalized: this.normalized
  6226. };
  6227. }
  6228. }); //
  6229. function Int8BufferAttribute(array, itemSize, normalized) {
  6230. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6231. }
  6232. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6233. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6234. function Uint8BufferAttribute(array, itemSize, normalized) {
  6235. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6236. }
  6237. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6238. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6239. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6240. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6241. }
  6242. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6243. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6244. function Int16BufferAttribute(array, itemSize, normalized) {
  6245. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6246. }
  6247. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6248. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6249. function Uint16BufferAttribute(array, itemSize, normalized) {
  6250. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6251. }
  6252. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6253. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6254. function Int32BufferAttribute(array, itemSize, normalized) {
  6255. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6256. }
  6257. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6258. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6259. function Uint32BufferAttribute(array, itemSize, normalized) {
  6260. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6261. }
  6262. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6263. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6264. function Float16BufferAttribute(array, itemSize, normalized) {
  6265. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6266. }
  6267. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6268. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6269. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6270. function Float32BufferAttribute(array, itemSize, normalized) {
  6271. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6272. }
  6273. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6274. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6275. function Float64BufferAttribute(array, itemSize, normalized) {
  6276. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6277. }
  6278. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6279. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6280. var DirectGeometry = /*#__PURE__*/function () {
  6281. function DirectGeometry() {
  6282. this.vertices = [];
  6283. this.normals = [];
  6284. this.colors = [];
  6285. this.uvs = [];
  6286. this.uvs2 = [];
  6287. this.groups = [];
  6288. this.morphTargets = {};
  6289. this.skinWeights = [];
  6290. this.skinIndices = []; // this.lineDistances = [];
  6291. this.boundingBox = null;
  6292. this.boundingSphere = null; // update flags
  6293. this.verticesNeedUpdate = false;
  6294. this.normalsNeedUpdate = false;
  6295. this.colorsNeedUpdate = false;
  6296. this.uvsNeedUpdate = false;
  6297. this.groupsNeedUpdate = false;
  6298. }
  6299. var _proto = DirectGeometry.prototype;
  6300. _proto.computeGroups = function computeGroups(geometry) {
  6301. var groups = [];
  6302. var group, i;
  6303. var materialIndex = undefined;
  6304. var faces = geometry.faces;
  6305. for (i = 0; i < faces.length; i++) {
  6306. var face = faces[i]; // materials
  6307. if (face.materialIndex !== materialIndex) {
  6308. materialIndex = face.materialIndex;
  6309. if (group !== undefined) {
  6310. group.count = i * 3 - group.start;
  6311. groups.push(group);
  6312. }
  6313. group = {
  6314. start: i * 3,
  6315. materialIndex: materialIndex
  6316. };
  6317. }
  6318. }
  6319. if (group !== undefined) {
  6320. group.count = i * 3 - group.start;
  6321. groups.push(group);
  6322. }
  6323. this.groups = groups;
  6324. };
  6325. _proto.fromGeometry = function fromGeometry(geometry) {
  6326. var faces = geometry.faces;
  6327. var vertices = geometry.vertices;
  6328. var faceVertexUvs = geometry.faceVertexUvs;
  6329. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6330. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6331. var morphTargets = geometry.morphTargets;
  6332. var morphTargetsLength = morphTargets.length;
  6333. var morphTargetsPosition;
  6334. if (morphTargetsLength > 0) {
  6335. morphTargetsPosition = [];
  6336. for (var i = 0; i < morphTargetsLength; i++) {
  6337. morphTargetsPosition[i] = {
  6338. name: morphTargets[i].name,
  6339. data: []
  6340. };
  6341. }
  6342. this.morphTargets.position = morphTargetsPosition;
  6343. }
  6344. var morphNormals = geometry.morphNormals;
  6345. var morphNormalsLength = morphNormals.length;
  6346. var morphTargetsNormal;
  6347. if (morphNormalsLength > 0) {
  6348. morphTargetsNormal = [];
  6349. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6350. morphTargetsNormal[_i] = {
  6351. name: morphNormals[_i].name,
  6352. data: []
  6353. };
  6354. }
  6355. this.morphTargets.normal = morphTargetsNormal;
  6356. } // skins
  6357. var skinIndices = geometry.skinIndices;
  6358. var skinWeights = geometry.skinWeights;
  6359. var hasSkinIndices = skinIndices.length === vertices.length;
  6360. var hasSkinWeights = skinWeights.length === vertices.length; //
  6361. if (vertices.length > 0 && faces.length === 0) {
  6362. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6363. }
  6364. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6365. var face = faces[_i2];
  6366. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6367. var vertexNormals = face.vertexNormals;
  6368. if (vertexNormals.length === 3) {
  6369. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6370. } else {
  6371. var normal = face.normal;
  6372. this.normals.push(normal, normal, normal);
  6373. }
  6374. var vertexColors = face.vertexColors;
  6375. if (vertexColors.length === 3) {
  6376. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6377. } else {
  6378. var color = face.color;
  6379. this.colors.push(color, color, color);
  6380. }
  6381. if (hasFaceVertexUv === true) {
  6382. var vertexUvs = faceVertexUvs[0][_i2];
  6383. if (vertexUvs !== undefined) {
  6384. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6385. } else {
  6386. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6387. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6388. }
  6389. }
  6390. if (hasFaceVertexUv2 === true) {
  6391. var _vertexUvs = faceVertexUvs[1][_i2];
  6392. if (_vertexUvs !== undefined) {
  6393. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6394. } else {
  6395. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6396. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6397. }
  6398. } // morphs
  6399. for (var j = 0; j < morphTargetsLength; j++) {
  6400. var morphTarget = morphTargets[j].vertices;
  6401. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6402. }
  6403. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6404. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6405. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6406. } // skins
  6407. if (hasSkinIndices) {
  6408. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6409. }
  6410. if (hasSkinWeights) {
  6411. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6412. }
  6413. }
  6414. this.computeGroups(geometry);
  6415. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6416. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6417. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6418. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6419. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6420. if (geometry.boundingSphere !== null) {
  6421. this.boundingSphere = geometry.boundingSphere.clone();
  6422. }
  6423. if (geometry.boundingBox !== null) {
  6424. this.boundingBox = geometry.boundingBox.clone();
  6425. }
  6426. return this;
  6427. };
  6428. return DirectGeometry;
  6429. }();
  6430. function arrayMax(array) {
  6431. if (array.length === 0) return -Infinity;
  6432. var max = array[0];
  6433. for (var i = 1, l = array.length; i < l; ++i) {
  6434. if (array[i] > max) max = array[i];
  6435. }
  6436. return max;
  6437. }
  6438. var TYPED_ARRAYS = {
  6439. Int8Array: Int8Array,
  6440. Uint8Array: Uint8Array,
  6441. // Workaround for IE11 pre KB2929437. See #11440
  6442. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6443. Int16Array: Int16Array,
  6444. Uint16Array: Uint16Array,
  6445. Int32Array: Int32Array,
  6446. Uint32Array: Uint32Array,
  6447. Float32Array: Float32Array,
  6448. Float64Array: Float64Array
  6449. };
  6450. function getTypedArray(type, buffer) {
  6451. return new TYPED_ARRAYS[type](buffer);
  6452. }
  6453. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6454. var _m1$2 = new Matrix4();
  6455. var _obj = new Object3D();
  6456. var _offset = new Vector3();
  6457. var _box$2 = new Box3();
  6458. var _boxMorphTargets = new Box3();
  6459. var _vector$4 = new Vector3();
  6460. function BufferGeometry() {
  6461. Object.defineProperty(this, 'id', {
  6462. value: _bufferGeometryId += 2
  6463. });
  6464. this.uuid = MathUtils.generateUUID();
  6465. this.name = '';
  6466. this.type = 'BufferGeometry';
  6467. this.index = null;
  6468. this.attributes = {};
  6469. this.morphAttributes = {};
  6470. this.morphTargetsRelative = false;
  6471. this.groups = [];
  6472. this.boundingBox = null;
  6473. this.boundingSphere = null;
  6474. this.drawRange = {
  6475. start: 0,
  6476. count: Infinity
  6477. };
  6478. this.userData = {};
  6479. }
  6480. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6481. constructor: BufferGeometry,
  6482. isBufferGeometry: true,
  6483. getIndex: function getIndex() {
  6484. return this.index;
  6485. },
  6486. setIndex: function setIndex(index) {
  6487. if (Array.isArray(index)) {
  6488. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6489. } else {
  6490. this.index = index;
  6491. }
  6492. return this;
  6493. },
  6494. getAttribute: function getAttribute(name) {
  6495. return this.attributes[name];
  6496. },
  6497. setAttribute: function setAttribute(name, attribute) {
  6498. this.attributes[name] = attribute;
  6499. return this;
  6500. },
  6501. deleteAttribute: function deleteAttribute(name) {
  6502. delete this.attributes[name];
  6503. return this;
  6504. },
  6505. hasAttribute: function hasAttribute(name) {
  6506. return this.attributes[name] !== undefined;
  6507. },
  6508. addGroup: function addGroup(start, count, materialIndex) {
  6509. if (materialIndex === void 0) {
  6510. materialIndex = 0;
  6511. }
  6512. this.groups.push({
  6513. start: start,
  6514. count: count,
  6515. materialIndex: materialIndex
  6516. });
  6517. },
  6518. clearGroups: function clearGroups() {
  6519. this.groups = [];
  6520. },
  6521. setDrawRange: function setDrawRange(start, count) {
  6522. this.drawRange.start = start;
  6523. this.drawRange.count = count;
  6524. },
  6525. applyMatrix4: function applyMatrix4(matrix) {
  6526. var position = this.attributes.position;
  6527. if (position !== undefined) {
  6528. position.applyMatrix4(matrix);
  6529. position.needsUpdate = true;
  6530. }
  6531. var normal = this.attributes.normal;
  6532. if (normal !== undefined) {
  6533. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6534. normal.applyNormalMatrix(normalMatrix);
  6535. normal.needsUpdate = true;
  6536. }
  6537. var tangent = this.attributes.tangent;
  6538. if (tangent !== undefined) {
  6539. tangent.transformDirection(matrix);
  6540. tangent.needsUpdate = true;
  6541. }
  6542. if (this.boundingBox !== null) {
  6543. this.computeBoundingBox();
  6544. }
  6545. if (this.boundingSphere !== null) {
  6546. this.computeBoundingSphere();
  6547. }
  6548. return this;
  6549. },
  6550. rotateX: function rotateX(angle) {
  6551. // rotate geometry around world x-axis
  6552. _m1$2.makeRotationX(angle);
  6553. this.applyMatrix4(_m1$2);
  6554. return this;
  6555. },
  6556. rotateY: function rotateY(angle) {
  6557. // rotate geometry around world y-axis
  6558. _m1$2.makeRotationY(angle);
  6559. this.applyMatrix4(_m1$2);
  6560. return this;
  6561. },
  6562. rotateZ: function rotateZ(angle) {
  6563. // rotate geometry around world z-axis
  6564. _m1$2.makeRotationZ(angle);
  6565. this.applyMatrix4(_m1$2);
  6566. return this;
  6567. },
  6568. translate: function translate(x, y, z) {
  6569. // translate geometry
  6570. _m1$2.makeTranslation(x, y, z);
  6571. this.applyMatrix4(_m1$2);
  6572. return this;
  6573. },
  6574. scale: function scale(x, y, z) {
  6575. // scale geometry
  6576. _m1$2.makeScale(x, y, z);
  6577. this.applyMatrix4(_m1$2);
  6578. return this;
  6579. },
  6580. lookAt: function lookAt(vector) {
  6581. _obj.lookAt(vector);
  6582. _obj.updateMatrix();
  6583. this.applyMatrix4(_obj.matrix);
  6584. return this;
  6585. },
  6586. center: function center() {
  6587. this.computeBoundingBox();
  6588. this.boundingBox.getCenter(_offset).negate();
  6589. this.translate(_offset.x, _offset.y, _offset.z);
  6590. return this;
  6591. },
  6592. setFromObject: function setFromObject(object) {
  6593. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6594. var geometry = object.geometry;
  6595. if (object.isPoints || object.isLine) {
  6596. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6597. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6598. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6599. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6600. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6601. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6602. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6603. }
  6604. if (geometry.boundingSphere !== null) {
  6605. this.boundingSphere = geometry.boundingSphere.clone();
  6606. }
  6607. if (geometry.boundingBox !== null) {
  6608. this.boundingBox = geometry.boundingBox.clone();
  6609. }
  6610. } else if (object.isMesh) {
  6611. if (geometry && geometry.isGeometry) {
  6612. this.fromGeometry(geometry);
  6613. }
  6614. }
  6615. return this;
  6616. },
  6617. setFromPoints: function setFromPoints(points) {
  6618. var position = [];
  6619. for (var i = 0, l = points.length; i < l; i++) {
  6620. var point = points[i];
  6621. position.push(point.x, point.y, point.z || 0);
  6622. }
  6623. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6624. return this;
  6625. },
  6626. updateFromObject: function updateFromObject(object) {
  6627. var geometry = object.geometry;
  6628. if (object.isMesh) {
  6629. var direct = geometry.__directGeometry;
  6630. if (geometry.elementsNeedUpdate === true) {
  6631. direct = undefined;
  6632. geometry.elementsNeedUpdate = false;
  6633. }
  6634. if (direct === undefined) {
  6635. return this.fromGeometry(geometry);
  6636. }
  6637. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6638. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6639. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6640. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6641. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6642. geometry.verticesNeedUpdate = false;
  6643. geometry.normalsNeedUpdate = false;
  6644. geometry.colorsNeedUpdate = false;
  6645. geometry.uvsNeedUpdate = false;
  6646. geometry.groupsNeedUpdate = false;
  6647. geometry = direct;
  6648. }
  6649. if (geometry.verticesNeedUpdate === true) {
  6650. var attribute = this.attributes.position;
  6651. if (attribute !== undefined) {
  6652. attribute.copyVector3sArray(geometry.vertices);
  6653. attribute.needsUpdate = true;
  6654. }
  6655. geometry.verticesNeedUpdate = false;
  6656. }
  6657. if (geometry.normalsNeedUpdate === true) {
  6658. var _attribute = this.attributes.normal;
  6659. if (_attribute !== undefined) {
  6660. _attribute.copyVector3sArray(geometry.normals);
  6661. _attribute.needsUpdate = true;
  6662. }
  6663. geometry.normalsNeedUpdate = false;
  6664. }
  6665. if (geometry.colorsNeedUpdate === true) {
  6666. var _attribute2 = this.attributes.color;
  6667. if (_attribute2 !== undefined) {
  6668. _attribute2.copyColorsArray(geometry.colors);
  6669. _attribute2.needsUpdate = true;
  6670. }
  6671. geometry.colorsNeedUpdate = false;
  6672. }
  6673. if (geometry.uvsNeedUpdate) {
  6674. var _attribute3 = this.attributes.uv;
  6675. if (_attribute3 !== undefined) {
  6676. _attribute3.copyVector2sArray(geometry.uvs);
  6677. _attribute3.needsUpdate = true;
  6678. }
  6679. geometry.uvsNeedUpdate = false;
  6680. }
  6681. if (geometry.lineDistancesNeedUpdate) {
  6682. var _attribute4 = this.attributes.lineDistance;
  6683. if (_attribute4 !== undefined) {
  6684. _attribute4.copyArray(geometry.lineDistances);
  6685. _attribute4.needsUpdate = true;
  6686. }
  6687. geometry.lineDistancesNeedUpdate = false;
  6688. }
  6689. if (geometry.groupsNeedUpdate) {
  6690. geometry.computeGroups(object.geometry);
  6691. this.groups = geometry.groups;
  6692. geometry.groupsNeedUpdate = false;
  6693. }
  6694. return this;
  6695. },
  6696. fromGeometry: function fromGeometry(geometry) {
  6697. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6698. return this.fromDirectGeometry(geometry.__directGeometry);
  6699. },
  6700. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6701. var positions = new Float32Array(geometry.vertices.length * 3);
  6702. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6703. if (geometry.normals.length > 0) {
  6704. var normals = new Float32Array(geometry.normals.length * 3);
  6705. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6706. }
  6707. if (geometry.colors.length > 0) {
  6708. var colors = new Float32Array(geometry.colors.length * 3);
  6709. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6710. }
  6711. if (geometry.uvs.length > 0) {
  6712. var uvs = new Float32Array(geometry.uvs.length * 2);
  6713. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6714. }
  6715. if (geometry.uvs2.length > 0) {
  6716. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6717. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6718. } // groups
  6719. this.groups = geometry.groups; // morphs
  6720. for (var name in geometry.morphTargets) {
  6721. var array = [];
  6722. var morphTargets = geometry.morphTargets[name];
  6723. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6724. var morphTarget = morphTargets[i];
  6725. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6726. attribute.name = morphTarget.name;
  6727. array.push(attribute.copyVector3sArray(morphTarget.data));
  6728. }
  6729. this.morphAttributes[name] = array;
  6730. } // skinning
  6731. if (geometry.skinIndices.length > 0) {
  6732. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6733. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6734. }
  6735. if (geometry.skinWeights.length > 0) {
  6736. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6737. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6738. } //
  6739. if (geometry.boundingSphere !== null) {
  6740. this.boundingSphere = geometry.boundingSphere.clone();
  6741. }
  6742. if (geometry.boundingBox !== null) {
  6743. this.boundingBox = geometry.boundingBox.clone();
  6744. }
  6745. return this;
  6746. },
  6747. computeBoundingBox: function computeBoundingBox() {
  6748. if (this.boundingBox === null) {
  6749. this.boundingBox = new Box3();
  6750. }
  6751. var position = this.attributes.position;
  6752. var morphAttributesPosition = this.morphAttributes.position;
  6753. if (position && position.isGLBufferAttribute) {
  6754. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6755. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6756. return;
  6757. }
  6758. if (position !== undefined) {
  6759. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6760. if (morphAttributesPosition) {
  6761. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6762. var morphAttribute = morphAttributesPosition[i];
  6763. _box$2.setFromBufferAttribute(morphAttribute);
  6764. if (this.morphTargetsRelative) {
  6765. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6766. this.boundingBox.expandByPoint(_vector$4);
  6767. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6768. this.boundingBox.expandByPoint(_vector$4);
  6769. } else {
  6770. this.boundingBox.expandByPoint(_box$2.min);
  6771. this.boundingBox.expandByPoint(_box$2.max);
  6772. }
  6773. }
  6774. }
  6775. } else {
  6776. this.boundingBox.makeEmpty();
  6777. }
  6778. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6779. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6780. }
  6781. },
  6782. computeBoundingSphere: function computeBoundingSphere() {
  6783. if (this.boundingSphere === null) {
  6784. this.boundingSphere = new Sphere();
  6785. }
  6786. var position = this.attributes.position;
  6787. var morphAttributesPosition = this.morphAttributes.position;
  6788. if (position && position.isGLBufferAttribute) {
  6789. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6790. this.boundingSphere.set(new Vector3(), Infinity);
  6791. return;
  6792. }
  6793. if (position) {
  6794. // first, find the center of the bounding sphere
  6795. var center = this.boundingSphere.center;
  6796. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6797. if (morphAttributesPosition) {
  6798. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6799. var morphAttribute = morphAttributesPosition[i];
  6800. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6801. if (this.morphTargetsRelative) {
  6802. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6803. _box$2.expandByPoint(_vector$4);
  6804. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6805. _box$2.expandByPoint(_vector$4);
  6806. } else {
  6807. _box$2.expandByPoint(_boxMorphTargets.min);
  6808. _box$2.expandByPoint(_boxMorphTargets.max);
  6809. }
  6810. }
  6811. }
  6812. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6813. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6814. var maxRadiusSq = 0;
  6815. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6816. _vector$4.fromBufferAttribute(position, _i);
  6817. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6818. } // process morph attributes if present
  6819. if (morphAttributesPosition) {
  6820. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6821. var _morphAttribute = morphAttributesPosition[_i2];
  6822. var morphTargetsRelative = this.morphTargetsRelative;
  6823. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6824. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6825. if (morphTargetsRelative) {
  6826. _offset.fromBufferAttribute(position, j);
  6827. _vector$4.add(_offset);
  6828. }
  6829. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6830. }
  6831. }
  6832. }
  6833. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6834. if (isNaN(this.boundingSphere.radius)) {
  6835. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6836. }
  6837. }
  6838. },
  6839. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6840. },
  6841. computeVertexNormals: function computeVertexNormals() {
  6842. var index = this.index;
  6843. var positionAttribute = this.getAttribute('position');
  6844. if (positionAttribute !== undefined) {
  6845. var normalAttribute = this.getAttribute('normal');
  6846. if (normalAttribute === undefined) {
  6847. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6848. this.setAttribute('normal', normalAttribute);
  6849. } else {
  6850. // reset existing normals to zero
  6851. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6852. normalAttribute.setXYZ(i, 0, 0, 0);
  6853. }
  6854. }
  6855. var pA = new Vector3(),
  6856. pB = new Vector3(),
  6857. pC = new Vector3();
  6858. var nA = new Vector3(),
  6859. nB = new Vector3(),
  6860. nC = new Vector3();
  6861. var cb = new Vector3(),
  6862. ab = new Vector3(); // indexed elements
  6863. if (index) {
  6864. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6865. var vA = index.getX(_i3 + 0);
  6866. var vB = index.getX(_i3 + 1);
  6867. var vC = index.getX(_i3 + 2);
  6868. pA.fromBufferAttribute(positionAttribute, vA);
  6869. pB.fromBufferAttribute(positionAttribute, vB);
  6870. pC.fromBufferAttribute(positionAttribute, vC);
  6871. cb.subVectors(pC, pB);
  6872. ab.subVectors(pA, pB);
  6873. cb.cross(ab);
  6874. nA.fromBufferAttribute(normalAttribute, vA);
  6875. nB.fromBufferAttribute(normalAttribute, vB);
  6876. nC.fromBufferAttribute(normalAttribute, vC);
  6877. nA.add(cb);
  6878. nB.add(cb);
  6879. nC.add(cb);
  6880. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6881. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6882. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6883. }
  6884. } else {
  6885. // non-indexed elements (unconnected triangle soup)
  6886. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6887. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6888. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6889. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6890. cb.subVectors(pC, pB);
  6891. ab.subVectors(pA, pB);
  6892. cb.cross(ab);
  6893. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6894. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6895. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6896. }
  6897. }
  6898. this.normalizeNormals();
  6899. normalAttribute.needsUpdate = true;
  6900. }
  6901. },
  6902. merge: function merge(geometry, offset) {
  6903. if (!(geometry && geometry.isBufferGeometry)) {
  6904. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6905. return;
  6906. }
  6907. if (offset === undefined) {
  6908. offset = 0;
  6909. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6910. }
  6911. var attributes = this.attributes;
  6912. for (var key in attributes) {
  6913. if (geometry.attributes[key] === undefined) continue;
  6914. var attribute1 = attributes[key];
  6915. var attributeArray1 = attribute1.array;
  6916. var attribute2 = geometry.attributes[key];
  6917. var attributeArray2 = attribute2.array;
  6918. var attributeOffset = attribute2.itemSize * offset;
  6919. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6920. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6921. attributeArray1[j] = attributeArray2[i];
  6922. }
  6923. }
  6924. return this;
  6925. },
  6926. normalizeNormals: function normalizeNormals() {
  6927. var normals = this.attributes.normal;
  6928. for (var i = 0, il = normals.count; i < il; i++) {
  6929. _vector$4.fromBufferAttribute(normals, i);
  6930. _vector$4.normalize();
  6931. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6932. }
  6933. },
  6934. toNonIndexed: function toNonIndexed() {
  6935. function convertBufferAttribute(attribute, indices) {
  6936. var array = attribute.array;
  6937. var itemSize = attribute.itemSize;
  6938. var normalized = attribute.normalized;
  6939. var array2 = new array.constructor(indices.length * itemSize);
  6940. var index = 0,
  6941. index2 = 0;
  6942. for (var i = 0, l = indices.length; i < l; i++) {
  6943. index = indices[i] * itemSize;
  6944. for (var j = 0; j < itemSize; j++) {
  6945. array2[index2++] = array[index++];
  6946. }
  6947. }
  6948. return new BufferAttribute(array2, itemSize, normalized);
  6949. } //
  6950. if (this.index === null) {
  6951. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6952. return this;
  6953. }
  6954. var geometry2 = new BufferGeometry();
  6955. var indices = this.index.array;
  6956. var attributes = this.attributes; // attributes
  6957. for (var name in attributes) {
  6958. var attribute = attributes[name];
  6959. var newAttribute = convertBufferAttribute(attribute, indices);
  6960. geometry2.setAttribute(name, newAttribute);
  6961. } // morph attributes
  6962. var morphAttributes = this.morphAttributes;
  6963. for (var _name in morphAttributes) {
  6964. var morphArray = [];
  6965. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6966. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6967. var _attribute5 = morphAttribute[i];
  6968. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6969. morphArray.push(_newAttribute);
  6970. }
  6971. geometry2.morphAttributes[_name] = morphArray;
  6972. }
  6973. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6974. var groups = this.groups;
  6975. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6976. var group = groups[_i5];
  6977. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6978. }
  6979. return geometry2;
  6980. },
  6981. toJSON: function toJSON() {
  6982. var data = {
  6983. metadata: {
  6984. version: 4.5,
  6985. type: 'BufferGeometry',
  6986. generator: 'BufferGeometry.toJSON'
  6987. }
  6988. }; // standard BufferGeometry serialization
  6989. data.uuid = this.uuid;
  6990. data.type = this.type;
  6991. if (this.name !== '') data.name = this.name;
  6992. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6993. if (this.parameters !== undefined) {
  6994. var parameters = this.parameters;
  6995. for (var key in parameters) {
  6996. if (parameters[key] !== undefined) data[key] = parameters[key];
  6997. }
  6998. return data;
  6999. }
  7000. data.data = {
  7001. attributes: {}
  7002. };
  7003. var index = this.index;
  7004. if (index !== null) {
  7005. data.data.index = {
  7006. type: index.array.constructor.name,
  7007. array: Array.prototype.slice.call(index.array)
  7008. };
  7009. }
  7010. var attributes = this.attributes;
  7011. for (var _key in attributes) {
  7012. var attribute = attributes[_key];
  7013. var attributeData = attribute.toJSON(data.data);
  7014. if (attribute.name !== '') attributeData.name = attribute.name;
  7015. data.data.attributes[_key] = attributeData;
  7016. }
  7017. var morphAttributes = {};
  7018. var hasMorphAttributes = false;
  7019. for (var _key2 in this.morphAttributes) {
  7020. var attributeArray = this.morphAttributes[_key2];
  7021. var array = [];
  7022. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7023. var _attribute6 = attributeArray[i];
  7024. var _attributeData = _attribute6.toJSON(data.data);
  7025. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  7026. array.push(_attributeData);
  7027. }
  7028. if (array.length > 0) {
  7029. morphAttributes[_key2] = array;
  7030. hasMorphAttributes = true;
  7031. }
  7032. }
  7033. if (hasMorphAttributes) {
  7034. data.data.morphAttributes = morphAttributes;
  7035. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7036. }
  7037. var groups = this.groups;
  7038. if (groups.length > 0) {
  7039. data.data.groups = JSON.parse(JSON.stringify(groups));
  7040. }
  7041. var boundingSphere = this.boundingSphere;
  7042. if (boundingSphere !== null) {
  7043. data.data.boundingSphere = {
  7044. center: boundingSphere.center.toArray(),
  7045. radius: boundingSphere.radius
  7046. };
  7047. }
  7048. return data;
  7049. },
  7050. clone: function clone() {
  7051. /*
  7052. // Handle primitives
  7053. const parameters = this.parameters;
  7054. if ( parameters !== undefined ) {
  7055. const values = [];
  7056. for ( const key in parameters ) {
  7057. values.push( parameters[ key ] );
  7058. }
  7059. const geometry = Object.create( this.constructor.prototype );
  7060. this.constructor.apply( geometry, values );
  7061. return geometry;
  7062. }
  7063. return new this.constructor().copy( this );
  7064. */
  7065. return new BufferGeometry().copy(this);
  7066. },
  7067. copy: function copy(source) {
  7068. // reset
  7069. this.index = null;
  7070. this.attributes = {};
  7071. this.morphAttributes = {};
  7072. this.groups = [];
  7073. this.boundingBox = null;
  7074. this.boundingSphere = null; // used for storing cloned, shared data
  7075. var data = {}; // name
  7076. this.name = source.name; // index
  7077. var index = source.index;
  7078. if (index !== null) {
  7079. this.setIndex(index.clone(data));
  7080. } // attributes
  7081. var attributes = source.attributes;
  7082. for (var name in attributes) {
  7083. var attribute = attributes[name];
  7084. this.setAttribute(name, attribute.clone(data));
  7085. } // morph attributes
  7086. var morphAttributes = source.morphAttributes;
  7087. for (var _name2 in morphAttributes) {
  7088. var array = [];
  7089. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7090. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7091. array.push(morphAttribute[i].clone(data));
  7092. }
  7093. this.morphAttributes[_name2] = array;
  7094. }
  7095. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7096. var groups = source.groups;
  7097. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  7098. var group = groups[_i6];
  7099. this.addGroup(group.start, group.count, group.materialIndex);
  7100. } // bounding box
  7101. var boundingBox = source.boundingBox;
  7102. if (boundingBox !== null) {
  7103. this.boundingBox = boundingBox.clone();
  7104. } // bounding sphere
  7105. var boundingSphere = source.boundingSphere;
  7106. if (boundingSphere !== null) {
  7107. this.boundingSphere = boundingSphere.clone();
  7108. } // draw range
  7109. this.drawRange.start = source.drawRange.start;
  7110. this.drawRange.count = source.drawRange.count; // user data
  7111. this.userData = source.userData;
  7112. return this;
  7113. },
  7114. dispose: function dispose() {
  7115. this.dispatchEvent({
  7116. type: 'dispose'
  7117. });
  7118. }
  7119. });
  7120. var _inverseMatrix = new Matrix4();
  7121. var _ray = new Ray();
  7122. var _sphere = new Sphere();
  7123. var _vA = new Vector3();
  7124. var _vB = new Vector3();
  7125. var _vC = new Vector3();
  7126. var _tempA = new Vector3();
  7127. var _tempB = new Vector3();
  7128. var _tempC = new Vector3();
  7129. var _morphA = new Vector3();
  7130. var _morphB = new Vector3();
  7131. var _morphC = new Vector3();
  7132. var _uvA = new Vector2();
  7133. var _uvB = new Vector2();
  7134. var _uvC = new Vector2();
  7135. var _intersectionPoint = new Vector3();
  7136. var _intersectionPointWorld = new Vector3();
  7137. function Mesh(geometry, material) {
  7138. Object3D.call(this);
  7139. this.type = 'Mesh';
  7140. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7141. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7142. this.updateMorphTargets();
  7143. }
  7144. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7145. constructor: Mesh,
  7146. isMesh: true,
  7147. copy: function copy(source) {
  7148. Object3D.prototype.copy.call(this, source);
  7149. if (source.morphTargetInfluences !== undefined) {
  7150. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7151. }
  7152. if (source.morphTargetDictionary !== undefined) {
  7153. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7154. }
  7155. this.material = source.material;
  7156. this.geometry = source.geometry;
  7157. return this;
  7158. },
  7159. updateMorphTargets: function updateMorphTargets() {
  7160. var geometry = this.geometry;
  7161. if (geometry.isBufferGeometry) {
  7162. var morphAttributes = geometry.morphAttributes;
  7163. var keys = Object.keys(morphAttributes);
  7164. if (keys.length > 0) {
  7165. var morphAttribute = morphAttributes[keys[0]];
  7166. if (morphAttribute !== undefined) {
  7167. this.morphTargetInfluences = [];
  7168. this.morphTargetDictionary = {};
  7169. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7170. var name = morphAttribute[m].name || String(m);
  7171. this.morphTargetInfluences.push(0);
  7172. this.morphTargetDictionary[name] = m;
  7173. }
  7174. }
  7175. }
  7176. } else {
  7177. var morphTargets = geometry.morphTargets;
  7178. if (morphTargets !== undefined && morphTargets.length > 0) {
  7179. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7180. }
  7181. }
  7182. },
  7183. raycast: function raycast(raycaster, intersects) {
  7184. var geometry = this.geometry;
  7185. var material = this.material;
  7186. var matrixWorld = this.matrixWorld;
  7187. if (material === undefined) return; // Checking boundingSphere distance to ray
  7188. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7189. _sphere.copy(geometry.boundingSphere);
  7190. _sphere.applyMatrix4(matrixWorld);
  7191. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7192. _inverseMatrix.copy(matrixWorld).invert();
  7193. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7194. if (geometry.boundingBox !== null) {
  7195. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7196. }
  7197. var intersection;
  7198. if (geometry.isBufferGeometry) {
  7199. var index = geometry.index;
  7200. var position = geometry.attributes.position;
  7201. var morphPosition = geometry.morphAttributes.position;
  7202. var morphTargetsRelative = geometry.morphTargetsRelative;
  7203. var uv = geometry.attributes.uv;
  7204. var uv2 = geometry.attributes.uv2;
  7205. var groups = geometry.groups;
  7206. var drawRange = geometry.drawRange;
  7207. if (index !== null) {
  7208. // indexed buffer geometry
  7209. if (Array.isArray(material)) {
  7210. for (var i = 0, il = groups.length; i < il; i++) {
  7211. var group = groups[i];
  7212. var groupMaterial = material[group.materialIndex];
  7213. var start = Math.max(group.start, drawRange.start);
  7214. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7215. for (var j = start, jl = end; j < jl; j += 3) {
  7216. var a = index.getX(j);
  7217. var b = index.getX(j + 1);
  7218. var c = index.getX(j + 2);
  7219. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7220. if (intersection) {
  7221. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7222. intersection.face.materialIndex = group.materialIndex;
  7223. intersects.push(intersection);
  7224. }
  7225. }
  7226. }
  7227. } else {
  7228. var _start = Math.max(0, drawRange.start);
  7229. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7230. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7231. var _a = index.getX(_i);
  7232. var _b = index.getX(_i + 1);
  7233. var _c = index.getX(_i + 2);
  7234. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7235. if (intersection) {
  7236. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7237. intersects.push(intersection);
  7238. }
  7239. }
  7240. }
  7241. } else if (position !== undefined) {
  7242. // non-indexed buffer geometry
  7243. if (Array.isArray(material)) {
  7244. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7245. var _group = groups[_i2];
  7246. var _groupMaterial = material[_group.materialIndex];
  7247. var _start2 = Math.max(_group.start, drawRange.start);
  7248. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7249. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7250. var _a2 = _j;
  7251. var _b2 = _j + 1;
  7252. var _c2 = _j + 2;
  7253. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7254. if (intersection) {
  7255. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7256. intersection.face.materialIndex = _group.materialIndex;
  7257. intersects.push(intersection);
  7258. }
  7259. }
  7260. }
  7261. } else {
  7262. var _start3 = Math.max(0, drawRange.start);
  7263. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7264. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7265. var _a3 = _i3;
  7266. var _b3 = _i3 + 1;
  7267. var _c3 = _i3 + 2;
  7268. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7269. if (intersection) {
  7270. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7271. intersects.push(intersection);
  7272. }
  7273. }
  7274. }
  7275. }
  7276. } else if (geometry.isGeometry) {
  7277. var isMultiMaterial = Array.isArray(material);
  7278. var vertices = geometry.vertices;
  7279. var faces = geometry.faces;
  7280. var uvs;
  7281. var faceVertexUvs = geometry.faceVertexUvs[0];
  7282. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7283. for (var f = 0, fl = faces.length; f < fl; f++) {
  7284. var face = faces[f];
  7285. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7286. if (faceMaterial === undefined) continue;
  7287. var fvA = vertices[face.a];
  7288. var fvB = vertices[face.b];
  7289. var fvC = vertices[face.c];
  7290. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7291. if (intersection) {
  7292. if (uvs && uvs[f]) {
  7293. var uvs_f = uvs[f];
  7294. _uvA.copy(uvs_f[0]);
  7295. _uvB.copy(uvs_f[1]);
  7296. _uvC.copy(uvs_f[2]);
  7297. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7298. }
  7299. intersection.face = face;
  7300. intersection.faceIndex = f;
  7301. intersects.push(intersection);
  7302. }
  7303. }
  7304. }
  7305. }
  7306. });
  7307. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7308. var intersect;
  7309. if (material.side === BackSide) {
  7310. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7311. } else {
  7312. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7313. }
  7314. if (intersect === null) return null;
  7315. _intersectionPointWorld.copy(point);
  7316. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7317. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7318. if (distance < raycaster.near || distance > raycaster.far) return null;
  7319. return {
  7320. distance: distance,
  7321. point: _intersectionPointWorld.clone(),
  7322. object: object
  7323. };
  7324. }
  7325. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7326. _vA.fromBufferAttribute(position, a);
  7327. _vB.fromBufferAttribute(position, b);
  7328. _vC.fromBufferAttribute(position, c);
  7329. var morphInfluences = object.morphTargetInfluences;
  7330. if (material.morphTargets && morphPosition && morphInfluences) {
  7331. _morphA.set(0, 0, 0);
  7332. _morphB.set(0, 0, 0);
  7333. _morphC.set(0, 0, 0);
  7334. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7335. var influence = morphInfluences[i];
  7336. var morphAttribute = morphPosition[i];
  7337. if (influence === 0) continue;
  7338. _tempA.fromBufferAttribute(morphAttribute, a);
  7339. _tempB.fromBufferAttribute(morphAttribute, b);
  7340. _tempC.fromBufferAttribute(morphAttribute, c);
  7341. if (morphTargetsRelative) {
  7342. _morphA.addScaledVector(_tempA, influence);
  7343. _morphB.addScaledVector(_tempB, influence);
  7344. _morphC.addScaledVector(_tempC, influence);
  7345. } else {
  7346. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7347. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7348. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7349. }
  7350. }
  7351. _vA.add(_morphA);
  7352. _vB.add(_morphB);
  7353. _vC.add(_morphC);
  7354. }
  7355. if (object.isSkinnedMesh) {
  7356. object.boneTransform(a, _vA);
  7357. object.boneTransform(b, _vB);
  7358. object.boneTransform(c, _vC);
  7359. }
  7360. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7361. if (intersection) {
  7362. if (uv) {
  7363. _uvA.fromBufferAttribute(uv, a);
  7364. _uvB.fromBufferAttribute(uv, b);
  7365. _uvC.fromBufferAttribute(uv, c);
  7366. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7367. }
  7368. if (uv2) {
  7369. _uvA.fromBufferAttribute(uv2, a);
  7370. _uvB.fromBufferAttribute(uv2, b);
  7371. _uvC.fromBufferAttribute(uv2, c);
  7372. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7373. }
  7374. var face = new Face3(a, b, c);
  7375. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7376. intersection.face = face;
  7377. }
  7378. return intersection;
  7379. }
  7380. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7381. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7382. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7383. var _this;
  7384. if (width === void 0) {
  7385. width = 1;
  7386. }
  7387. if (height === void 0) {
  7388. height = 1;
  7389. }
  7390. if (depth === void 0) {
  7391. depth = 1;
  7392. }
  7393. if (widthSegments === void 0) {
  7394. widthSegments = 1;
  7395. }
  7396. if (heightSegments === void 0) {
  7397. heightSegments = 1;
  7398. }
  7399. if (depthSegments === void 0) {
  7400. depthSegments = 1;
  7401. }
  7402. _this = _BufferGeometry.call(this) || this;
  7403. _this.type = 'BoxBufferGeometry';
  7404. _this.parameters = {
  7405. width: width,
  7406. height: height,
  7407. depth: depth,
  7408. widthSegments: widthSegments,
  7409. heightSegments: heightSegments,
  7410. depthSegments: depthSegments
  7411. };
  7412. var scope = _assertThisInitialized(_this); // segments
  7413. widthSegments = Math.floor(widthSegments);
  7414. heightSegments = Math.floor(heightSegments);
  7415. depthSegments = Math.floor(depthSegments); // buffers
  7416. var indices = [];
  7417. var vertices = [];
  7418. var normals = [];
  7419. var uvs = []; // helper variables
  7420. var numberOfVertices = 0;
  7421. var groupStart = 0; // build each side of the box geometry
  7422. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7423. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7424. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7425. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7426. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7427. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7428. // build geometry
  7429. _this.setIndex(indices);
  7430. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7431. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7432. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7433. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7434. var segmentWidth = width / gridX;
  7435. var segmentHeight = height / gridY;
  7436. var widthHalf = width / 2;
  7437. var heightHalf = height / 2;
  7438. var depthHalf = depth / 2;
  7439. var gridX1 = gridX + 1;
  7440. var gridY1 = gridY + 1;
  7441. var vertexCounter = 0;
  7442. var groupCount = 0;
  7443. var vector = new Vector3(); // generate vertices, normals and uvs
  7444. for (var iy = 0; iy < gridY1; iy++) {
  7445. var y = iy * segmentHeight - heightHalf;
  7446. for (var ix = 0; ix < gridX1; ix++) {
  7447. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7448. vector[u] = x * udir;
  7449. vector[v] = y * vdir;
  7450. vector[w] = depthHalf; // now apply vector to vertex buffer
  7451. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7452. vector[u] = 0;
  7453. vector[v] = 0;
  7454. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7455. normals.push(vector.x, vector.y, vector.z); // uvs
  7456. uvs.push(ix / gridX);
  7457. uvs.push(1 - iy / gridY); // counters
  7458. vertexCounter += 1;
  7459. }
  7460. } // indices
  7461. // 1. you need three indices to draw a single face
  7462. // 2. a single segment consists of two faces
  7463. // 3. so we need to generate six (2*3) indices per segment
  7464. for (var _iy = 0; _iy < gridY; _iy++) {
  7465. for (var _ix = 0; _ix < gridX; _ix++) {
  7466. var a = numberOfVertices + _ix + gridX1 * _iy;
  7467. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7468. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7469. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7470. indices.push(a, b, d);
  7471. indices.push(b, c, d); // increase counter
  7472. groupCount += 6;
  7473. }
  7474. } // add a group to the geometry. this will ensure multi material support
  7475. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7476. groupStart += groupCount; // update total number of vertices
  7477. numberOfVertices += vertexCounter;
  7478. }
  7479. return _this;
  7480. }
  7481. return BoxBufferGeometry;
  7482. }(BufferGeometry);
  7483. /**
  7484. * Uniform Utilities
  7485. */
  7486. function cloneUniforms(src) {
  7487. var dst = {};
  7488. for (var u in src) {
  7489. dst[u] = {};
  7490. for (var p in src[u]) {
  7491. var property = src[u][p];
  7492. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7493. dst[u][p] = property.clone();
  7494. } else if (Array.isArray(property)) {
  7495. dst[u][p] = property.slice();
  7496. } else {
  7497. dst[u][p] = property;
  7498. }
  7499. }
  7500. }
  7501. return dst;
  7502. }
  7503. function mergeUniforms(uniforms) {
  7504. var merged = {};
  7505. for (var u = 0; u < uniforms.length; u++) {
  7506. var tmp = cloneUniforms(uniforms[u]);
  7507. for (var p in tmp) {
  7508. merged[p] = tmp[p];
  7509. }
  7510. }
  7511. return merged;
  7512. } // Legacy
  7513. var UniformsUtils = {
  7514. clone: cloneUniforms,
  7515. merge: mergeUniforms
  7516. };
  7517. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7518. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7519. /**
  7520. * parameters = {
  7521. * defines: { "label" : "value" },
  7522. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7523. *
  7524. * fragmentShader: <string>,
  7525. * vertexShader: <string>,
  7526. *
  7527. * wireframe: <boolean>,
  7528. * wireframeLinewidth: <float>,
  7529. *
  7530. * lights: <bool>,
  7531. *
  7532. * skinning: <bool>,
  7533. * morphTargets: <bool>,
  7534. * morphNormals: <bool>
  7535. * }
  7536. */
  7537. function ShaderMaterial(parameters) {
  7538. Material.call(this);
  7539. this.type = 'ShaderMaterial';
  7540. this.defines = {};
  7541. this.uniforms = {};
  7542. this.vertexShader = default_vertex;
  7543. this.fragmentShader = default_fragment;
  7544. this.linewidth = 1;
  7545. this.wireframe = false;
  7546. this.wireframeLinewidth = 1;
  7547. this.fog = false; // set to use scene fog
  7548. this.lights = false; // set to use scene lights
  7549. this.clipping = false; // set to use user-defined clipping planes
  7550. this.skinning = false; // set to use skinning attribute streams
  7551. this.morphTargets = false; // set to use morph targets
  7552. this.morphNormals = false; // set to use morph normals
  7553. this.extensions = {
  7554. derivatives: false,
  7555. // set to use derivatives
  7556. fragDepth: false,
  7557. // set to use fragment depth values
  7558. drawBuffers: false,
  7559. // set to use draw buffers
  7560. shaderTextureLOD: false // set to use shader texture LOD
  7561. }; // When rendered geometry doesn't include these attributes but the material does,
  7562. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7563. this.defaultAttributeValues = {
  7564. 'color': [1, 1, 1],
  7565. 'uv': [0, 0],
  7566. 'uv2': [0, 0]
  7567. };
  7568. this.index0AttributeName = undefined;
  7569. this.uniformsNeedUpdate = false;
  7570. this.glslVersion = null;
  7571. if (parameters !== undefined) {
  7572. if (parameters.attributes !== undefined) {
  7573. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7574. }
  7575. this.setValues(parameters);
  7576. }
  7577. }
  7578. ShaderMaterial.prototype = Object.create(Material.prototype);
  7579. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7580. ShaderMaterial.prototype.isShaderMaterial = true;
  7581. ShaderMaterial.prototype.copy = function (source) {
  7582. Material.prototype.copy.call(this, source);
  7583. this.fragmentShader = source.fragmentShader;
  7584. this.vertexShader = source.vertexShader;
  7585. this.uniforms = cloneUniforms(source.uniforms);
  7586. this.defines = Object.assign({}, source.defines);
  7587. this.wireframe = source.wireframe;
  7588. this.wireframeLinewidth = source.wireframeLinewidth;
  7589. this.lights = source.lights;
  7590. this.clipping = source.clipping;
  7591. this.skinning = source.skinning;
  7592. this.morphTargets = source.morphTargets;
  7593. this.morphNormals = source.morphNormals;
  7594. this.extensions = Object.assign({}, source.extensions);
  7595. this.glslVersion = source.glslVersion;
  7596. return this;
  7597. };
  7598. ShaderMaterial.prototype.toJSON = function (meta) {
  7599. var data = Material.prototype.toJSON.call(this, meta);
  7600. data.glslVersion = this.glslVersion;
  7601. data.uniforms = {};
  7602. for (var name in this.uniforms) {
  7603. var uniform = this.uniforms[name];
  7604. var value = uniform.value;
  7605. if (value && value.isTexture) {
  7606. data.uniforms[name] = {
  7607. type: 't',
  7608. value: value.toJSON(meta).uuid
  7609. };
  7610. } else if (value && value.isColor) {
  7611. data.uniforms[name] = {
  7612. type: 'c',
  7613. value: value.getHex()
  7614. };
  7615. } else if (value && value.isVector2) {
  7616. data.uniforms[name] = {
  7617. type: 'v2',
  7618. value: value.toArray()
  7619. };
  7620. } else if (value && value.isVector3) {
  7621. data.uniforms[name] = {
  7622. type: 'v3',
  7623. value: value.toArray()
  7624. };
  7625. } else if (value && value.isVector4) {
  7626. data.uniforms[name] = {
  7627. type: 'v4',
  7628. value: value.toArray()
  7629. };
  7630. } else if (value && value.isMatrix3) {
  7631. data.uniforms[name] = {
  7632. type: 'm3',
  7633. value: value.toArray()
  7634. };
  7635. } else if (value && value.isMatrix4) {
  7636. data.uniforms[name] = {
  7637. type: 'm4',
  7638. value: value.toArray()
  7639. };
  7640. } else {
  7641. data.uniforms[name] = {
  7642. value: value
  7643. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7644. }
  7645. }
  7646. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7647. data.vertexShader = this.vertexShader;
  7648. data.fragmentShader = this.fragmentShader;
  7649. var extensions = {};
  7650. for (var key in this.extensions) {
  7651. if (this.extensions[key] === true) extensions[key] = true;
  7652. }
  7653. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7654. return data;
  7655. };
  7656. function Camera() {
  7657. Object3D.call(this);
  7658. this.type = 'Camera';
  7659. this.matrixWorldInverse = new Matrix4();
  7660. this.projectionMatrix = new Matrix4();
  7661. this.projectionMatrixInverse = new Matrix4();
  7662. }
  7663. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7664. constructor: Camera,
  7665. isCamera: true,
  7666. copy: function copy(source, recursive) {
  7667. Object3D.prototype.copy.call(this, source, recursive);
  7668. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7669. this.projectionMatrix.copy(source.projectionMatrix);
  7670. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7671. return this;
  7672. },
  7673. getWorldDirection: function getWorldDirection(target) {
  7674. if (target === undefined) {
  7675. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7676. target = new Vector3();
  7677. }
  7678. this.updateWorldMatrix(true, false);
  7679. var e = this.matrixWorld.elements;
  7680. return target.set(-e[8], -e[9], -e[10]).normalize();
  7681. },
  7682. updateMatrixWorld: function updateMatrixWorld(force) {
  7683. Object3D.prototype.updateMatrixWorld.call(this, force);
  7684. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7685. },
  7686. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7687. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7688. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  7689. },
  7690. clone: function clone() {
  7691. return new this.constructor().copy(this);
  7692. }
  7693. });
  7694. function PerspectiveCamera(fov, aspect, near, far) {
  7695. if (fov === void 0) {
  7696. fov = 50;
  7697. }
  7698. if (aspect === void 0) {
  7699. aspect = 1;
  7700. }
  7701. if (near === void 0) {
  7702. near = 0.1;
  7703. }
  7704. if (far === void 0) {
  7705. far = 2000;
  7706. }
  7707. Camera.call(this);
  7708. this.type = 'PerspectiveCamera';
  7709. this.fov = fov;
  7710. this.zoom = 1;
  7711. this.near = near;
  7712. this.far = far;
  7713. this.focus = 10;
  7714. this.aspect = aspect;
  7715. this.view = null;
  7716. this.filmGauge = 35; // width of the film (default in millimeters)
  7717. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7718. this.updateProjectionMatrix();
  7719. }
  7720. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7721. constructor: PerspectiveCamera,
  7722. isPerspectiveCamera: true,
  7723. copy: function copy(source, recursive) {
  7724. Camera.prototype.copy.call(this, source, recursive);
  7725. this.fov = source.fov;
  7726. this.zoom = source.zoom;
  7727. this.near = source.near;
  7728. this.far = source.far;
  7729. this.focus = source.focus;
  7730. this.aspect = source.aspect;
  7731. this.view = source.view === null ? null : Object.assign({}, source.view);
  7732. this.filmGauge = source.filmGauge;
  7733. this.filmOffset = source.filmOffset;
  7734. return this;
  7735. },
  7736. /**
  7737. * Sets the FOV by focal length in respect to the current .filmGauge.
  7738. *
  7739. * The default film gauge is 35, so that the focal length can be specified for
  7740. * a 35mm (full frame) camera.
  7741. *
  7742. * Values for focal length and film gauge must have the same unit.
  7743. */
  7744. setFocalLength: function setFocalLength(focalLength) {
  7745. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7746. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7747. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7748. this.updateProjectionMatrix();
  7749. },
  7750. /**
  7751. * Calculates the focal length from the current .fov and .filmGauge.
  7752. */
  7753. getFocalLength: function getFocalLength() {
  7754. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7755. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7756. },
  7757. getEffectiveFOV: function getEffectiveFOV() {
  7758. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7759. },
  7760. getFilmWidth: function getFilmWidth() {
  7761. // film not completely covered in portrait format (aspect < 1)
  7762. return this.filmGauge * Math.min(this.aspect, 1);
  7763. },
  7764. getFilmHeight: function getFilmHeight() {
  7765. // film not completely covered in landscape format (aspect > 1)
  7766. return this.filmGauge / Math.max(this.aspect, 1);
  7767. },
  7768. /**
  7769. * Sets an offset in a larger frustum. This is useful for multi-window or
  7770. * multi-monitor/multi-machine setups.
  7771. *
  7772. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7773. * the monitors are in grid like this
  7774. *
  7775. * +---+---+---+
  7776. * | A | B | C |
  7777. * +---+---+---+
  7778. * | D | E | F |
  7779. * +---+---+---+
  7780. *
  7781. * then for each monitor you would call it like this
  7782. *
  7783. * const w = 1920;
  7784. * const h = 1080;
  7785. * const fullWidth = w * 3;
  7786. * const fullHeight = h * 2;
  7787. *
  7788. * --A--
  7789. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7790. * --B--
  7791. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7792. * --C--
  7793. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7794. * --D--
  7795. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7796. * --E--
  7797. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7798. * --F--
  7799. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7800. *
  7801. * Note there is no reason monitors have to be the same size or in a grid.
  7802. */
  7803. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7804. this.aspect = fullWidth / fullHeight;
  7805. if (this.view === null) {
  7806. this.view = {
  7807. enabled: true,
  7808. fullWidth: 1,
  7809. fullHeight: 1,
  7810. offsetX: 0,
  7811. offsetY: 0,
  7812. width: 1,
  7813. height: 1
  7814. };
  7815. }
  7816. this.view.enabled = true;
  7817. this.view.fullWidth = fullWidth;
  7818. this.view.fullHeight = fullHeight;
  7819. this.view.offsetX = x;
  7820. this.view.offsetY = y;
  7821. this.view.width = width;
  7822. this.view.height = height;
  7823. this.updateProjectionMatrix();
  7824. },
  7825. clearViewOffset: function clearViewOffset() {
  7826. if (this.view !== null) {
  7827. this.view.enabled = false;
  7828. }
  7829. this.updateProjectionMatrix();
  7830. },
  7831. updateProjectionMatrix: function updateProjectionMatrix() {
  7832. var near = this.near;
  7833. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7834. var height = 2 * top;
  7835. var width = this.aspect * height;
  7836. var left = -0.5 * width;
  7837. var view = this.view;
  7838. if (this.view !== null && this.view.enabled) {
  7839. var fullWidth = view.fullWidth,
  7840. fullHeight = view.fullHeight;
  7841. left += view.offsetX * width / fullWidth;
  7842. top -= view.offsetY * height / fullHeight;
  7843. width *= view.width / fullWidth;
  7844. height *= view.height / fullHeight;
  7845. }
  7846. var skew = this.filmOffset;
  7847. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7848. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7849. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  7850. },
  7851. toJSON: function toJSON(meta) {
  7852. var data = Object3D.prototype.toJSON.call(this, meta);
  7853. data.object.fov = this.fov;
  7854. data.object.zoom = this.zoom;
  7855. data.object.near = this.near;
  7856. data.object.far = this.far;
  7857. data.object.focus = this.focus;
  7858. data.object.aspect = this.aspect;
  7859. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7860. data.object.filmGauge = this.filmGauge;
  7861. data.object.filmOffset = this.filmOffset;
  7862. return data;
  7863. }
  7864. });
  7865. var fov = 90,
  7866. aspect = 1;
  7867. function CubeCamera(near, far, renderTarget) {
  7868. Object3D.call(this);
  7869. this.type = 'CubeCamera';
  7870. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7871. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7872. return;
  7873. }
  7874. this.renderTarget = renderTarget;
  7875. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7876. cameraPX.layers = this.layers;
  7877. cameraPX.up.set(0, -1, 0);
  7878. cameraPX.lookAt(new Vector3(1, 0, 0));
  7879. this.add(cameraPX);
  7880. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7881. cameraNX.layers = this.layers;
  7882. cameraNX.up.set(0, -1, 0);
  7883. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7884. this.add(cameraNX);
  7885. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7886. cameraPY.layers = this.layers;
  7887. cameraPY.up.set(0, 0, 1);
  7888. cameraPY.lookAt(new Vector3(0, 1, 0));
  7889. this.add(cameraPY);
  7890. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7891. cameraNY.layers = this.layers;
  7892. cameraNY.up.set(0, 0, -1);
  7893. cameraNY.lookAt(new Vector3(0, -1, 0));
  7894. this.add(cameraNY);
  7895. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7896. cameraPZ.layers = this.layers;
  7897. cameraPZ.up.set(0, -1, 0);
  7898. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7899. this.add(cameraPZ);
  7900. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7901. cameraNZ.layers = this.layers;
  7902. cameraNZ.up.set(0, -1, 0);
  7903. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7904. this.add(cameraNZ);
  7905. this.update = function (renderer, scene) {
  7906. if (this.parent === null) this.updateMatrixWorld();
  7907. var currentXrEnabled = renderer.xr.enabled;
  7908. var currentRenderTarget = renderer.getRenderTarget();
  7909. renderer.xr.enabled = false;
  7910. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7911. renderTarget.texture.generateMipmaps = false;
  7912. renderer.setRenderTarget(renderTarget, 0);
  7913. renderer.render(scene, cameraPX);
  7914. renderer.setRenderTarget(renderTarget, 1);
  7915. renderer.render(scene, cameraNX);
  7916. renderer.setRenderTarget(renderTarget, 2);
  7917. renderer.render(scene, cameraPY);
  7918. renderer.setRenderTarget(renderTarget, 3);
  7919. renderer.render(scene, cameraNY);
  7920. renderer.setRenderTarget(renderTarget, 4);
  7921. renderer.render(scene, cameraPZ);
  7922. renderTarget.texture.generateMipmaps = generateMipmaps;
  7923. renderer.setRenderTarget(renderTarget, 5);
  7924. renderer.render(scene, cameraNZ);
  7925. renderer.setRenderTarget(currentRenderTarget);
  7926. renderer.xr.enabled = currentXrEnabled;
  7927. };
  7928. }
  7929. CubeCamera.prototype = Object.create(Object3D.prototype);
  7930. CubeCamera.prototype.constructor = CubeCamera;
  7931. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7932. images = images !== undefined ? images : [];
  7933. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7934. format = format !== undefined ? format : RGBFormat;
  7935. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7936. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7937. //
  7938. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7939. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7940. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7941. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7942. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7943. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7944. this._needsFlipEnvMap = true;
  7945. }
  7946. CubeTexture.prototype = Object.create(Texture.prototype);
  7947. CubeTexture.prototype.constructor = CubeTexture;
  7948. CubeTexture.prototype.isCubeTexture = true;
  7949. Object.defineProperty(CubeTexture.prototype, 'images', {
  7950. get: function get() {
  7951. return this.image;
  7952. },
  7953. set: function set(value) {
  7954. this.image = value;
  7955. }
  7956. });
  7957. function WebGLCubeRenderTarget(size, options, dummy) {
  7958. if (Number.isInteger(options)) {
  7959. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7960. options = dummy;
  7961. }
  7962. WebGLRenderTarget.call(this, size, size, options);
  7963. options = options || {};
  7964. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7965. this.texture._needsFlipEnvMap = false;
  7966. }
  7967. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7968. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7969. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7970. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7971. this.texture.type = texture.type;
  7972. this.texture.format = RGBAFormat; // see #18859
  7973. this.texture.encoding = texture.encoding;
  7974. this.texture.generateMipmaps = texture.generateMipmaps;
  7975. this.texture.minFilter = texture.minFilter;
  7976. this.texture.magFilter = texture.magFilter;
  7977. var shader = {
  7978. uniforms: {
  7979. tEquirect: {
  7980. value: null
  7981. }
  7982. },
  7983. vertexShader:
  7984. /* glsl */
  7985. "\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",
  7986. fragmentShader:
  7987. /* glsl */
  7988. "\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"
  7989. };
  7990. var geometry = new BoxBufferGeometry(5, 5, 5);
  7991. var material = new ShaderMaterial({
  7992. name: 'CubemapFromEquirect',
  7993. uniforms: cloneUniforms(shader.uniforms),
  7994. vertexShader: shader.vertexShader,
  7995. fragmentShader: shader.fragmentShader,
  7996. side: BackSide,
  7997. blending: NoBlending
  7998. });
  7999. material.uniforms.tEquirect.value = texture;
  8000. var mesh = new Mesh(geometry, material);
  8001. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8002. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8003. var camera = new CubeCamera(1, 10, this);
  8004. camera.update(renderer, mesh);
  8005. texture.minFilter = currentMinFilter;
  8006. mesh.geometry.dispose();
  8007. mesh.material.dispose();
  8008. return this;
  8009. };
  8010. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  8011. var currentRenderTarget = renderer.getRenderTarget();
  8012. for (var i = 0; i < 6; i++) {
  8013. renderer.setRenderTarget(this, i);
  8014. renderer.clear(color, depth, stencil);
  8015. }
  8016. renderer.setRenderTarget(currentRenderTarget);
  8017. };
  8018. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8019. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8020. this.image = {
  8021. data: data || null,
  8022. width: width || 1,
  8023. height: height || 1
  8024. };
  8025. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8026. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8027. this.generateMipmaps = false;
  8028. this.flipY = false;
  8029. this.unpackAlignment = 1;
  8030. this.needsUpdate = true;
  8031. }
  8032. DataTexture.prototype = Object.create(Texture.prototype);
  8033. DataTexture.prototype.constructor = DataTexture;
  8034. DataTexture.prototype.isDataTexture = true;
  8035. var _sphere$1 = /*@__PURE__*/new Sphere();
  8036. var _vector$5 = /*@__PURE__*/new Vector3();
  8037. var Frustum = /*#__PURE__*/function () {
  8038. function Frustum(p0, p1, p2, p3, p4, p5) {
  8039. 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()];
  8040. }
  8041. var _proto = Frustum.prototype;
  8042. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8043. var planes = this.planes;
  8044. planes[0].copy(p0);
  8045. planes[1].copy(p1);
  8046. planes[2].copy(p2);
  8047. planes[3].copy(p3);
  8048. planes[4].copy(p4);
  8049. planes[5].copy(p5);
  8050. return this;
  8051. };
  8052. _proto.clone = function clone() {
  8053. return new this.constructor().copy(this);
  8054. };
  8055. _proto.copy = function copy(frustum) {
  8056. var planes = this.planes;
  8057. for (var i = 0; i < 6; i++) {
  8058. planes[i].copy(frustum.planes[i]);
  8059. }
  8060. return this;
  8061. };
  8062. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8063. var planes = this.planes;
  8064. var me = m.elements;
  8065. var me0 = me[0],
  8066. me1 = me[1],
  8067. me2 = me[2],
  8068. me3 = me[3];
  8069. var me4 = me[4],
  8070. me5 = me[5],
  8071. me6 = me[6],
  8072. me7 = me[7];
  8073. var me8 = me[8],
  8074. me9 = me[9],
  8075. me10 = me[10],
  8076. me11 = me[11];
  8077. var me12 = me[12],
  8078. me13 = me[13],
  8079. me14 = me[14],
  8080. me15 = me[15];
  8081. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8082. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8083. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8084. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8085. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8086. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8087. return this;
  8088. };
  8089. _proto.intersectsObject = function intersectsObject(object) {
  8090. var geometry = object.geometry;
  8091. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8092. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8093. return this.intersectsSphere(_sphere$1);
  8094. };
  8095. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8096. _sphere$1.center.set(0, 0, 0);
  8097. _sphere$1.radius = 0.7071067811865476;
  8098. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8099. return this.intersectsSphere(_sphere$1);
  8100. };
  8101. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8102. var planes = this.planes;
  8103. var center = sphere.center;
  8104. var negRadius = -sphere.radius;
  8105. for (var i = 0; i < 6; i++) {
  8106. var distance = planes[i].distanceToPoint(center);
  8107. if (distance < negRadius) {
  8108. return false;
  8109. }
  8110. }
  8111. return true;
  8112. };
  8113. _proto.intersectsBox = function intersectsBox(box) {
  8114. var planes = this.planes;
  8115. for (var i = 0; i < 6; i++) {
  8116. var plane = planes[i]; // corner at max distance
  8117. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8118. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8119. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8120. if (plane.distanceToPoint(_vector$5) < 0) {
  8121. return false;
  8122. }
  8123. }
  8124. return true;
  8125. };
  8126. _proto.containsPoint = function containsPoint(point) {
  8127. var planes = this.planes;
  8128. for (var i = 0; i < 6; i++) {
  8129. if (planes[i].distanceToPoint(point) < 0) {
  8130. return false;
  8131. }
  8132. }
  8133. return true;
  8134. };
  8135. return Frustum;
  8136. }();
  8137. function WebGLAnimation() {
  8138. var context = null;
  8139. var isAnimating = false;
  8140. var animationLoop = null;
  8141. var requestId = null;
  8142. function onAnimationFrame(time, frame) {
  8143. animationLoop(time, frame);
  8144. requestId = context.requestAnimationFrame(onAnimationFrame);
  8145. }
  8146. return {
  8147. start: function start() {
  8148. if (isAnimating === true) return;
  8149. if (animationLoop === null) return;
  8150. requestId = context.requestAnimationFrame(onAnimationFrame);
  8151. isAnimating = true;
  8152. },
  8153. stop: function stop() {
  8154. context.cancelAnimationFrame(requestId);
  8155. isAnimating = false;
  8156. },
  8157. setAnimationLoop: function setAnimationLoop(callback) {
  8158. animationLoop = callback;
  8159. },
  8160. setContext: function setContext(value) {
  8161. context = value;
  8162. }
  8163. };
  8164. }
  8165. function WebGLAttributes(gl, capabilities) {
  8166. var isWebGL2 = capabilities.isWebGL2;
  8167. var buffers = new WeakMap();
  8168. function createBuffer(attribute, bufferType) {
  8169. var array = attribute.array;
  8170. var usage = attribute.usage;
  8171. var buffer = gl.createBuffer();
  8172. gl.bindBuffer(bufferType, buffer);
  8173. gl.bufferData(bufferType, array, usage);
  8174. attribute.onUploadCallback();
  8175. var type = 5126;
  8176. if (array instanceof Float32Array) {
  8177. type = 5126;
  8178. } else if (array instanceof Float64Array) {
  8179. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8180. } else if (array instanceof Uint16Array) {
  8181. if (attribute.isFloat16BufferAttribute) {
  8182. if (isWebGL2) {
  8183. type = 5131;
  8184. } else {
  8185. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8186. }
  8187. } else {
  8188. type = 5123;
  8189. }
  8190. } else if (array instanceof Int16Array) {
  8191. type = 5122;
  8192. } else if (array instanceof Uint32Array) {
  8193. type = 5125;
  8194. } else if (array instanceof Int32Array) {
  8195. type = 5124;
  8196. } else if (array instanceof Int8Array) {
  8197. type = 5120;
  8198. } else if (array instanceof Uint8Array) {
  8199. type = 5121;
  8200. }
  8201. return {
  8202. buffer: buffer,
  8203. type: type,
  8204. bytesPerElement: array.BYTES_PER_ELEMENT,
  8205. version: attribute.version
  8206. };
  8207. }
  8208. function updateBuffer(buffer, attribute, bufferType) {
  8209. var array = attribute.array;
  8210. var updateRange = attribute.updateRange;
  8211. gl.bindBuffer(bufferType, buffer);
  8212. if (updateRange.count === -1) {
  8213. // Not using update ranges
  8214. gl.bufferSubData(bufferType, 0, array);
  8215. } else {
  8216. if (isWebGL2) {
  8217. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8218. } else {
  8219. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8220. }
  8221. updateRange.count = -1; // reset range
  8222. }
  8223. } //
  8224. function get(attribute) {
  8225. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8226. return buffers.get(attribute);
  8227. }
  8228. function remove(attribute) {
  8229. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8230. var data = buffers.get(attribute);
  8231. if (data) {
  8232. gl.deleteBuffer(data.buffer);
  8233. buffers.delete(attribute);
  8234. }
  8235. }
  8236. function update(attribute, bufferType) {
  8237. if (attribute.isGLBufferAttribute) {
  8238. var cached = buffers.get(attribute);
  8239. if (!cached || cached.version < attribute.version) {
  8240. buffers.set(attribute, {
  8241. buffer: attribute.buffer,
  8242. type: attribute.type,
  8243. bytesPerElement: attribute.elementSize,
  8244. version: attribute.version
  8245. });
  8246. }
  8247. return;
  8248. }
  8249. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8250. var data = buffers.get(attribute);
  8251. if (data === undefined) {
  8252. buffers.set(attribute, createBuffer(attribute, bufferType));
  8253. } else if (data.version < attribute.version) {
  8254. updateBuffer(data.buffer, attribute, bufferType);
  8255. data.version = attribute.version;
  8256. }
  8257. }
  8258. return {
  8259. get: get,
  8260. remove: remove,
  8261. update: update
  8262. };
  8263. }
  8264. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8265. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8266. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8267. var _this;
  8268. if (width === void 0) {
  8269. width = 1;
  8270. }
  8271. if (height === void 0) {
  8272. height = 1;
  8273. }
  8274. if (widthSegments === void 0) {
  8275. widthSegments = 1;
  8276. }
  8277. if (heightSegments === void 0) {
  8278. heightSegments = 1;
  8279. }
  8280. _this = _BufferGeometry.call(this) || this;
  8281. _this.type = 'PlaneBufferGeometry';
  8282. _this.parameters = {
  8283. width: width,
  8284. height: height,
  8285. widthSegments: widthSegments,
  8286. heightSegments: heightSegments
  8287. };
  8288. var width_half = width / 2;
  8289. var height_half = height / 2;
  8290. var gridX = Math.floor(widthSegments);
  8291. var gridY = Math.floor(heightSegments);
  8292. var gridX1 = gridX + 1;
  8293. var gridY1 = gridY + 1;
  8294. var segment_width = width / gridX;
  8295. var segment_height = height / gridY; //
  8296. var indices = [];
  8297. var vertices = [];
  8298. var normals = [];
  8299. var uvs = [];
  8300. for (var iy = 0; iy < gridY1; iy++) {
  8301. var y = iy * segment_height - height_half;
  8302. for (var ix = 0; ix < gridX1; ix++) {
  8303. var x = ix * segment_width - width_half;
  8304. vertices.push(x, -y, 0);
  8305. normals.push(0, 0, 1);
  8306. uvs.push(ix / gridX);
  8307. uvs.push(1 - iy / gridY);
  8308. }
  8309. }
  8310. for (var _iy = 0; _iy < gridY; _iy++) {
  8311. for (var _ix = 0; _ix < gridX; _ix++) {
  8312. var a = _ix + gridX1 * _iy;
  8313. var b = _ix + gridX1 * (_iy + 1);
  8314. var c = _ix + 1 + gridX1 * (_iy + 1);
  8315. var d = _ix + 1 + gridX1 * _iy;
  8316. indices.push(a, b, d);
  8317. indices.push(b, c, d);
  8318. }
  8319. }
  8320. _this.setIndex(indices);
  8321. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8322. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8323. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8324. return _this;
  8325. }
  8326. return PlaneBufferGeometry;
  8327. }(BufferGeometry);
  8328. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8329. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8330. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8331. 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";
  8332. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8333. var begin_vertex = "vec3 transformed = vec3( position );";
  8334. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8335. 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";
  8336. 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";
  8337. 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";
  8338. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8339. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8340. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8341. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8342. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8343. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8344. 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";
  8345. 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}";
  8346. 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";
  8347. 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";
  8348. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8349. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8350. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8351. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8352. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8353. 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}";
  8354. 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";
  8355. 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";
  8356. 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";
  8357. 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";
  8358. 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";
  8359. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8360. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8361. 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";
  8362. 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";
  8363. 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}";
  8364. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8365. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8366. 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";
  8367. 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";
  8368. 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";
  8369. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8370. 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)";
  8371. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8372. 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)";
  8373. 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";
  8374. 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}";
  8375. 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";
  8376. 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";
  8377. 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";
  8378. 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";
  8379. 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";
  8380. 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";
  8381. 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";
  8382. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8383. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8384. 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";
  8385. 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";
  8386. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8387. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8388. 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";
  8389. 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";
  8390. 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";
  8391. 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;";
  8392. 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";
  8393. 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";
  8394. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8395. 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";
  8396. 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";
  8397. 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}";
  8398. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8399. 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;";
  8400. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8401. 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";
  8402. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8403. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8404. 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";
  8405. 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";
  8406. 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";
  8407. 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}";
  8408. 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";
  8409. 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";
  8410. 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";
  8411. 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";
  8412. 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";
  8413. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8414. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8415. 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; }";
  8416. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8417. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8418. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8419. 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";
  8420. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8421. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8422. 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";
  8423. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8424. 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";
  8425. 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}";
  8426. 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}";
  8427. 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}";
  8428. 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}";
  8429. 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}";
  8430. 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}";
  8431. 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}";
  8432. 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}";
  8433. 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}";
  8434. 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}";
  8435. 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}";
  8436. 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}";
  8437. 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}";
  8438. 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}";
  8439. 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}";
  8440. 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}";
  8441. 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}";
  8442. 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}";
  8443. 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}";
  8444. 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}";
  8445. 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}";
  8446. 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}";
  8447. 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}";
  8448. 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}";
  8449. 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}";
  8450. 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}";
  8451. 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}";
  8452. 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}";
  8453. 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}";
  8454. 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}";
  8455. 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}";
  8456. 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}";
  8457. var ShaderChunk = {
  8458. alphamap_fragment: alphamap_fragment,
  8459. alphamap_pars_fragment: alphamap_pars_fragment,
  8460. alphatest_fragment: alphatest_fragment,
  8461. aomap_fragment: aomap_fragment,
  8462. aomap_pars_fragment: aomap_pars_fragment,
  8463. begin_vertex: begin_vertex,
  8464. beginnormal_vertex: beginnormal_vertex,
  8465. bsdfs: bsdfs,
  8466. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8467. clipping_planes_fragment: clipping_planes_fragment,
  8468. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8469. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8470. clipping_planes_vertex: clipping_planes_vertex,
  8471. color_fragment: color_fragment,
  8472. color_pars_fragment: color_pars_fragment,
  8473. color_pars_vertex: color_pars_vertex,
  8474. color_vertex: color_vertex,
  8475. common: common,
  8476. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8477. defaultnormal_vertex: defaultnormal_vertex,
  8478. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8479. displacementmap_vertex: displacementmap_vertex,
  8480. emissivemap_fragment: emissivemap_fragment,
  8481. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8482. encodings_fragment: encodings_fragment,
  8483. encodings_pars_fragment: encodings_pars_fragment,
  8484. envmap_fragment: envmap_fragment,
  8485. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8486. envmap_pars_fragment: envmap_pars_fragment,
  8487. envmap_pars_vertex: envmap_pars_vertex,
  8488. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8489. envmap_vertex: envmap_vertex,
  8490. fog_vertex: fog_vertex,
  8491. fog_pars_vertex: fog_pars_vertex,
  8492. fog_fragment: fog_fragment,
  8493. fog_pars_fragment: fog_pars_fragment,
  8494. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8495. lightmap_fragment: lightmap_fragment,
  8496. lightmap_pars_fragment: lightmap_pars_fragment,
  8497. lights_lambert_vertex: lights_lambert_vertex,
  8498. lights_pars_begin: lights_pars_begin,
  8499. lights_toon_fragment: lights_toon_fragment,
  8500. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8501. lights_phong_fragment: lights_phong_fragment,
  8502. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8503. lights_physical_fragment: lights_physical_fragment,
  8504. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8505. lights_fragment_begin: lights_fragment_begin,
  8506. lights_fragment_maps: lights_fragment_maps,
  8507. lights_fragment_end: lights_fragment_end,
  8508. logdepthbuf_fragment: logdepthbuf_fragment,
  8509. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8510. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8511. logdepthbuf_vertex: logdepthbuf_vertex,
  8512. map_fragment: map_fragment,
  8513. map_pars_fragment: map_pars_fragment,
  8514. map_particle_fragment: map_particle_fragment,
  8515. map_particle_pars_fragment: map_particle_pars_fragment,
  8516. metalnessmap_fragment: metalnessmap_fragment,
  8517. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8518. morphnormal_vertex: morphnormal_vertex,
  8519. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8520. morphtarget_vertex: morphtarget_vertex,
  8521. normal_fragment_begin: normal_fragment_begin,
  8522. normal_fragment_maps: normal_fragment_maps,
  8523. normalmap_pars_fragment: normalmap_pars_fragment,
  8524. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8525. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8526. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8527. packing: packing,
  8528. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8529. project_vertex: project_vertex,
  8530. dithering_fragment: dithering_fragment,
  8531. dithering_pars_fragment: dithering_pars_fragment,
  8532. roughnessmap_fragment: roughnessmap_fragment,
  8533. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8534. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8535. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8536. shadowmap_vertex: shadowmap_vertex,
  8537. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8538. skinbase_vertex: skinbase_vertex,
  8539. skinning_pars_vertex: skinning_pars_vertex,
  8540. skinning_vertex: skinning_vertex,
  8541. skinnormal_vertex: skinnormal_vertex,
  8542. specularmap_fragment: specularmap_fragment,
  8543. specularmap_pars_fragment: specularmap_pars_fragment,
  8544. tonemapping_fragment: tonemapping_fragment,
  8545. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8546. transmissionmap_fragment: transmissionmap_fragment,
  8547. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8548. uv_pars_fragment: uv_pars_fragment,
  8549. uv_pars_vertex: uv_pars_vertex,
  8550. uv_vertex: uv_vertex,
  8551. uv2_pars_fragment: uv2_pars_fragment,
  8552. uv2_pars_vertex: uv2_pars_vertex,
  8553. uv2_vertex: uv2_vertex,
  8554. worldpos_vertex: worldpos_vertex,
  8555. background_frag: background_frag,
  8556. background_vert: background_vert,
  8557. cube_frag: cube_frag,
  8558. cube_vert: cube_vert,
  8559. depth_frag: depth_frag,
  8560. depth_vert: depth_vert,
  8561. distanceRGBA_frag: distanceRGBA_frag,
  8562. distanceRGBA_vert: distanceRGBA_vert,
  8563. equirect_frag: equirect_frag,
  8564. equirect_vert: equirect_vert,
  8565. linedashed_frag: linedashed_frag,
  8566. linedashed_vert: linedashed_vert,
  8567. meshbasic_frag: meshbasic_frag,
  8568. meshbasic_vert: meshbasic_vert,
  8569. meshlambert_frag: meshlambert_frag,
  8570. meshlambert_vert: meshlambert_vert,
  8571. meshmatcap_frag: meshmatcap_frag,
  8572. meshmatcap_vert: meshmatcap_vert,
  8573. meshtoon_frag: meshtoon_frag,
  8574. meshtoon_vert: meshtoon_vert,
  8575. meshphong_frag: meshphong_frag,
  8576. meshphong_vert: meshphong_vert,
  8577. meshphysical_frag: meshphysical_frag,
  8578. meshphysical_vert: meshphysical_vert,
  8579. normal_frag: normal_frag,
  8580. normal_vert: normal_vert,
  8581. points_frag: points_frag,
  8582. points_vert: points_vert,
  8583. shadow_frag: shadow_frag,
  8584. shadow_vert: shadow_vert,
  8585. sprite_frag: sprite_frag,
  8586. sprite_vert: sprite_vert
  8587. };
  8588. /**
  8589. * Uniforms library for shared webgl shaders
  8590. */
  8591. var UniformsLib = {
  8592. common: {
  8593. diffuse: {
  8594. value: new Color(0xeeeeee)
  8595. },
  8596. opacity: {
  8597. value: 1.0
  8598. },
  8599. map: {
  8600. value: null
  8601. },
  8602. uvTransform: {
  8603. value: new Matrix3()
  8604. },
  8605. uv2Transform: {
  8606. value: new Matrix3()
  8607. },
  8608. alphaMap: {
  8609. value: null
  8610. }
  8611. },
  8612. specularmap: {
  8613. specularMap: {
  8614. value: null
  8615. }
  8616. },
  8617. envmap: {
  8618. envMap: {
  8619. value: null
  8620. },
  8621. flipEnvMap: {
  8622. value: -1
  8623. },
  8624. reflectivity: {
  8625. value: 1.0
  8626. },
  8627. refractionRatio: {
  8628. value: 0.98
  8629. },
  8630. maxMipLevel: {
  8631. value: 0
  8632. }
  8633. },
  8634. aomap: {
  8635. aoMap: {
  8636. value: null
  8637. },
  8638. aoMapIntensity: {
  8639. value: 1
  8640. }
  8641. },
  8642. lightmap: {
  8643. lightMap: {
  8644. value: null
  8645. },
  8646. lightMapIntensity: {
  8647. value: 1
  8648. }
  8649. },
  8650. emissivemap: {
  8651. emissiveMap: {
  8652. value: null
  8653. }
  8654. },
  8655. bumpmap: {
  8656. bumpMap: {
  8657. value: null
  8658. },
  8659. bumpScale: {
  8660. value: 1
  8661. }
  8662. },
  8663. normalmap: {
  8664. normalMap: {
  8665. value: null
  8666. },
  8667. normalScale: {
  8668. value: new Vector2(1, 1)
  8669. }
  8670. },
  8671. displacementmap: {
  8672. displacementMap: {
  8673. value: null
  8674. },
  8675. displacementScale: {
  8676. value: 1
  8677. },
  8678. displacementBias: {
  8679. value: 0
  8680. }
  8681. },
  8682. roughnessmap: {
  8683. roughnessMap: {
  8684. value: null
  8685. }
  8686. },
  8687. metalnessmap: {
  8688. metalnessMap: {
  8689. value: null
  8690. }
  8691. },
  8692. gradientmap: {
  8693. gradientMap: {
  8694. value: null
  8695. }
  8696. },
  8697. fog: {
  8698. fogDensity: {
  8699. value: 0.00025
  8700. },
  8701. fogNear: {
  8702. value: 1
  8703. },
  8704. fogFar: {
  8705. value: 2000
  8706. },
  8707. fogColor: {
  8708. value: new Color(0xffffff)
  8709. }
  8710. },
  8711. lights: {
  8712. ambientLightColor: {
  8713. value: []
  8714. },
  8715. lightProbe: {
  8716. value: []
  8717. },
  8718. directionalLights: {
  8719. value: [],
  8720. properties: {
  8721. direction: {},
  8722. color: {}
  8723. }
  8724. },
  8725. directionalLightShadows: {
  8726. value: [],
  8727. properties: {
  8728. shadowBias: {},
  8729. shadowNormalBias: {},
  8730. shadowRadius: {},
  8731. shadowMapSize: {}
  8732. }
  8733. },
  8734. directionalShadowMap: {
  8735. value: []
  8736. },
  8737. directionalShadowMatrix: {
  8738. value: []
  8739. },
  8740. spotLights: {
  8741. value: [],
  8742. properties: {
  8743. color: {},
  8744. position: {},
  8745. direction: {},
  8746. distance: {},
  8747. coneCos: {},
  8748. penumbraCos: {},
  8749. decay: {}
  8750. }
  8751. },
  8752. spotLightShadows: {
  8753. value: [],
  8754. properties: {
  8755. shadowBias: {},
  8756. shadowNormalBias: {},
  8757. shadowRadius: {},
  8758. shadowMapSize: {}
  8759. }
  8760. },
  8761. spotShadowMap: {
  8762. value: []
  8763. },
  8764. spotShadowMatrix: {
  8765. value: []
  8766. },
  8767. pointLights: {
  8768. value: [],
  8769. properties: {
  8770. color: {},
  8771. position: {},
  8772. decay: {},
  8773. distance: {}
  8774. }
  8775. },
  8776. pointLightShadows: {
  8777. value: [],
  8778. properties: {
  8779. shadowBias: {},
  8780. shadowNormalBias: {},
  8781. shadowRadius: {},
  8782. shadowMapSize: {},
  8783. shadowCameraNear: {},
  8784. shadowCameraFar: {}
  8785. }
  8786. },
  8787. pointShadowMap: {
  8788. value: []
  8789. },
  8790. pointShadowMatrix: {
  8791. value: []
  8792. },
  8793. hemisphereLights: {
  8794. value: [],
  8795. properties: {
  8796. direction: {},
  8797. skyColor: {},
  8798. groundColor: {}
  8799. }
  8800. },
  8801. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8802. rectAreaLights: {
  8803. value: [],
  8804. properties: {
  8805. color: {},
  8806. position: {},
  8807. width: {},
  8808. height: {}
  8809. }
  8810. },
  8811. ltc_1: {
  8812. value: null
  8813. },
  8814. ltc_2: {
  8815. value: null
  8816. }
  8817. },
  8818. points: {
  8819. diffuse: {
  8820. value: new Color(0xeeeeee)
  8821. },
  8822. opacity: {
  8823. value: 1.0
  8824. },
  8825. size: {
  8826. value: 1.0
  8827. },
  8828. scale: {
  8829. value: 1.0
  8830. },
  8831. map: {
  8832. value: null
  8833. },
  8834. alphaMap: {
  8835. value: null
  8836. },
  8837. uvTransform: {
  8838. value: new Matrix3()
  8839. }
  8840. },
  8841. sprite: {
  8842. diffuse: {
  8843. value: new Color(0xeeeeee)
  8844. },
  8845. opacity: {
  8846. value: 1.0
  8847. },
  8848. center: {
  8849. value: new Vector2(0.5, 0.5)
  8850. },
  8851. rotation: {
  8852. value: 0.0
  8853. },
  8854. map: {
  8855. value: null
  8856. },
  8857. alphaMap: {
  8858. value: null
  8859. },
  8860. uvTransform: {
  8861. value: new Matrix3()
  8862. }
  8863. }
  8864. };
  8865. var ShaderLib = {
  8866. basic: {
  8867. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8868. vertexShader: ShaderChunk.meshbasic_vert,
  8869. fragmentShader: ShaderChunk.meshbasic_frag
  8870. },
  8871. lambert: {
  8872. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8873. emissive: {
  8874. value: new Color(0x000000)
  8875. }
  8876. }]),
  8877. vertexShader: ShaderChunk.meshlambert_vert,
  8878. fragmentShader: ShaderChunk.meshlambert_frag
  8879. },
  8880. phong: {
  8881. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8882. emissive: {
  8883. value: new Color(0x000000)
  8884. },
  8885. specular: {
  8886. value: new Color(0x111111)
  8887. },
  8888. shininess: {
  8889. value: 30
  8890. }
  8891. }]),
  8892. vertexShader: ShaderChunk.meshphong_vert,
  8893. fragmentShader: ShaderChunk.meshphong_frag
  8894. },
  8895. standard: {
  8896. 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, {
  8897. emissive: {
  8898. value: new Color(0x000000)
  8899. },
  8900. roughness: {
  8901. value: 1.0
  8902. },
  8903. metalness: {
  8904. value: 0.0
  8905. },
  8906. envMapIntensity: {
  8907. value: 1
  8908. } // temporary
  8909. }]),
  8910. vertexShader: ShaderChunk.meshphysical_vert,
  8911. fragmentShader: ShaderChunk.meshphysical_frag
  8912. },
  8913. toon: {
  8914. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8915. emissive: {
  8916. value: new Color(0x000000)
  8917. }
  8918. }]),
  8919. vertexShader: ShaderChunk.meshtoon_vert,
  8920. fragmentShader: ShaderChunk.meshtoon_frag
  8921. },
  8922. matcap: {
  8923. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8924. matcap: {
  8925. value: null
  8926. }
  8927. }]),
  8928. vertexShader: ShaderChunk.meshmatcap_vert,
  8929. fragmentShader: ShaderChunk.meshmatcap_frag
  8930. },
  8931. points: {
  8932. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8933. vertexShader: ShaderChunk.points_vert,
  8934. fragmentShader: ShaderChunk.points_frag
  8935. },
  8936. dashed: {
  8937. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8938. scale: {
  8939. value: 1
  8940. },
  8941. dashSize: {
  8942. value: 1
  8943. },
  8944. totalSize: {
  8945. value: 2
  8946. }
  8947. }]),
  8948. vertexShader: ShaderChunk.linedashed_vert,
  8949. fragmentShader: ShaderChunk.linedashed_frag
  8950. },
  8951. depth: {
  8952. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8953. vertexShader: ShaderChunk.depth_vert,
  8954. fragmentShader: ShaderChunk.depth_frag
  8955. },
  8956. normal: {
  8957. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8958. opacity: {
  8959. value: 1.0
  8960. }
  8961. }]),
  8962. vertexShader: ShaderChunk.normal_vert,
  8963. fragmentShader: ShaderChunk.normal_frag
  8964. },
  8965. sprite: {
  8966. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8967. vertexShader: ShaderChunk.sprite_vert,
  8968. fragmentShader: ShaderChunk.sprite_frag
  8969. },
  8970. background: {
  8971. uniforms: {
  8972. uvTransform: {
  8973. value: new Matrix3()
  8974. },
  8975. t2D: {
  8976. value: null
  8977. }
  8978. },
  8979. vertexShader: ShaderChunk.background_vert,
  8980. fragmentShader: ShaderChunk.background_frag
  8981. },
  8982. /* -------------------------------------------------------------------------
  8983. // Cube map shader
  8984. ------------------------------------------------------------------------- */
  8985. cube: {
  8986. uniforms: mergeUniforms([UniformsLib.envmap, {
  8987. opacity: {
  8988. value: 1.0
  8989. }
  8990. }]),
  8991. vertexShader: ShaderChunk.cube_vert,
  8992. fragmentShader: ShaderChunk.cube_frag
  8993. },
  8994. equirect: {
  8995. uniforms: {
  8996. tEquirect: {
  8997. value: null
  8998. }
  8999. },
  9000. vertexShader: ShaderChunk.equirect_vert,
  9001. fragmentShader: ShaderChunk.equirect_frag
  9002. },
  9003. distanceRGBA: {
  9004. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9005. referencePosition: {
  9006. value: new Vector3()
  9007. },
  9008. nearDistance: {
  9009. value: 1
  9010. },
  9011. farDistance: {
  9012. value: 1000
  9013. }
  9014. }]),
  9015. vertexShader: ShaderChunk.distanceRGBA_vert,
  9016. fragmentShader: ShaderChunk.distanceRGBA_frag
  9017. },
  9018. shadow: {
  9019. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9020. color: {
  9021. value: new Color(0x00000)
  9022. },
  9023. opacity: {
  9024. value: 1.0
  9025. }
  9026. }]),
  9027. vertexShader: ShaderChunk.shadow_vert,
  9028. fragmentShader: ShaderChunk.shadow_frag
  9029. }
  9030. };
  9031. ShaderLib.physical = {
  9032. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9033. clearcoat: {
  9034. value: 0
  9035. },
  9036. clearcoatMap: {
  9037. value: null
  9038. },
  9039. clearcoatRoughness: {
  9040. value: 0
  9041. },
  9042. clearcoatRoughnessMap: {
  9043. value: null
  9044. },
  9045. clearcoatNormalScale: {
  9046. value: new Vector2(1, 1)
  9047. },
  9048. clearcoatNormalMap: {
  9049. value: null
  9050. },
  9051. sheen: {
  9052. value: new Color(0x000000)
  9053. },
  9054. transmission: {
  9055. value: 0
  9056. },
  9057. transmissionMap: {
  9058. value: null
  9059. }
  9060. }]),
  9061. vertexShader: ShaderChunk.meshphysical_vert,
  9062. fragmentShader: ShaderChunk.meshphysical_frag
  9063. };
  9064. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9065. var clearColor = new Color(0x000000);
  9066. var clearAlpha = 0;
  9067. var planeMesh;
  9068. var boxMesh;
  9069. var currentBackground = null;
  9070. var currentBackgroundVersion = 0;
  9071. var currentTonemapping = null;
  9072. function render(renderList, scene, camera, forceClear) {
  9073. var background = scene.isScene === true ? scene.background : null;
  9074. if (background && background.isTexture) {
  9075. background = cubemaps.get(background);
  9076. } // Ignore background in AR
  9077. // TODO: Reconsider this.
  9078. var xr = renderer.xr;
  9079. var session = xr.getSession && xr.getSession();
  9080. if (session && session.environmentBlendMode === 'additive') {
  9081. background = null;
  9082. }
  9083. if (background === null) {
  9084. setClear(clearColor, clearAlpha);
  9085. } else if (background && background.isColor) {
  9086. setClear(background, 1);
  9087. forceClear = true;
  9088. }
  9089. if (renderer.autoClear || forceClear) {
  9090. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9091. }
  9092. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9093. if (boxMesh === undefined) {
  9094. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  9095. name: 'BackgroundCubeMaterial',
  9096. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9097. vertexShader: ShaderLib.cube.vertexShader,
  9098. fragmentShader: ShaderLib.cube.fragmentShader,
  9099. side: BackSide,
  9100. depthTest: false,
  9101. depthWrite: false,
  9102. fog: false
  9103. }));
  9104. boxMesh.geometry.deleteAttribute('normal');
  9105. boxMesh.geometry.deleteAttribute('uv');
  9106. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9107. this.matrixWorld.copyPosition(camera.matrixWorld);
  9108. }; // enable code injection for non-built-in material
  9109. Object.defineProperty(boxMesh.material, 'envMap', {
  9110. get: function get() {
  9111. return this.uniforms.envMap.value;
  9112. }
  9113. });
  9114. objects.update(boxMesh);
  9115. }
  9116. if (background.isWebGLCubeRenderTarget) {
  9117. // TODO Deprecate
  9118. background = background.texture;
  9119. }
  9120. boxMesh.material.uniforms.envMap.value = background;
  9121. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9122. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9123. boxMesh.material.needsUpdate = true;
  9124. currentBackground = background;
  9125. currentBackgroundVersion = background.version;
  9126. currentTonemapping = renderer.toneMapping;
  9127. } // push to the pre-sorted opaque render list
  9128. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9129. } else if (background && background.isTexture) {
  9130. if (planeMesh === undefined) {
  9131. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  9132. name: 'BackgroundMaterial',
  9133. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9134. vertexShader: ShaderLib.background.vertexShader,
  9135. fragmentShader: ShaderLib.background.fragmentShader,
  9136. side: FrontSide,
  9137. depthTest: false,
  9138. depthWrite: false,
  9139. fog: false
  9140. }));
  9141. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9142. Object.defineProperty(planeMesh.material, 'map', {
  9143. get: function get() {
  9144. return this.uniforms.t2D.value;
  9145. }
  9146. });
  9147. objects.update(planeMesh);
  9148. }
  9149. planeMesh.material.uniforms.t2D.value = background;
  9150. if (background.matrixAutoUpdate === true) {
  9151. background.updateMatrix();
  9152. }
  9153. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9154. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9155. planeMesh.material.needsUpdate = true;
  9156. currentBackground = background;
  9157. currentBackgroundVersion = background.version;
  9158. currentTonemapping = renderer.toneMapping;
  9159. } // push to the pre-sorted opaque render list
  9160. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9161. }
  9162. }
  9163. function setClear(color, alpha) {
  9164. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9165. }
  9166. return {
  9167. getClearColor: function getClearColor() {
  9168. return clearColor;
  9169. },
  9170. setClearColor: function setClearColor(color, alpha) {
  9171. if (alpha === void 0) {
  9172. alpha = 1;
  9173. }
  9174. clearColor.set(color);
  9175. clearAlpha = alpha;
  9176. setClear(clearColor, clearAlpha);
  9177. },
  9178. getClearAlpha: function getClearAlpha() {
  9179. return clearAlpha;
  9180. },
  9181. setClearAlpha: function setClearAlpha(alpha) {
  9182. clearAlpha = alpha;
  9183. setClear(clearColor, clearAlpha);
  9184. },
  9185. render: render
  9186. };
  9187. }
  9188. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9189. var maxVertexAttributes = gl.getParameter(34921);
  9190. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9191. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9192. var bindingStates = {};
  9193. var defaultState = createBindingState(null);
  9194. var currentState = defaultState;
  9195. function setup(object, material, program, geometry, index) {
  9196. var updateBuffers = false;
  9197. if (vaoAvailable) {
  9198. var state = getBindingState(geometry, program, material);
  9199. if (currentState !== state) {
  9200. currentState = state;
  9201. bindVertexArrayObject(currentState.object);
  9202. }
  9203. updateBuffers = needsUpdate(geometry, index);
  9204. if (updateBuffers) saveCache(geometry, index);
  9205. } else {
  9206. var wireframe = material.wireframe === true;
  9207. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9208. currentState.geometry = geometry.id;
  9209. currentState.program = program.id;
  9210. currentState.wireframe = wireframe;
  9211. updateBuffers = true;
  9212. }
  9213. }
  9214. if (object.isInstancedMesh === true) {
  9215. updateBuffers = true;
  9216. }
  9217. if (index !== null) {
  9218. attributes.update(index, 34963);
  9219. }
  9220. if (updateBuffers) {
  9221. setupVertexAttributes(object, material, program, geometry);
  9222. if (index !== null) {
  9223. gl.bindBuffer(34963, attributes.get(index).buffer);
  9224. }
  9225. }
  9226. }
  9227. function createVertexArrayObject() {
  9228. if (capabilities.isWebGL2) return gl.createVertexArray();
  9229. return extension.createVertexArrayOES();
  9230. }
  9231. function bindVertexArrayObject(vao) {
  9232. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9233. return extension.bindVertexArrayOES(vao);
  9234. }
  9235. function deleteVertexArrayObject(vao) {
  9236. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9237. return extension.deleteVertexArrayOES(vao);
  9238. }
  9239. function getBindingState(geometry, program, material) {
  9240. var wireframe = material.wireframe === true;
  9241. var programMap = bindingStates[geometry.id];
  9242. if (programMap === undefined) {
  9243. programMap = {};
  9244. bindingStates[geometry.id] = programMap;
  9245. }
  9246. var stateMap = programMap[program.id];
  9247. if (stateMap === undefined) {
  9248. stateMap = {};
  9249. programMap[program.id] = stateMap;
  9250. }
  9251. var state = stateMap[wireframe];
  9252. if (state === undefined) {
  9253. state = createBindingState(createVertexArrayObject());
  9254. stateMap[wireframe] = state;
  9255. }
  9256. return state;
  9257. }
  9258. function createBindingState(vao) {
  9259. var newAttributes = [];
  9260. var enabledAttributes = [];
  9261. var attributeDivisors = [];
  9262. for (var i = 0; i < maxVertexAttributes; i++) {
  9263. newAttributes[i] = 0;
  9264. enabledAttributes[i] = 0;
  9265. attributeDivisors[i] = 0;
  9266. }
  9267. return {
  9268. // for backward compatibility on non-VAO support browser
  9269. geometry: null,
  9270. program: null,
  9271. wireframe: false,
  9272. newAttributes: newAttributes,
  9273. enabledAttributes: enabledAttributes,
  9274. attributeDivisors: attributeDivisors,
  9275. object: vao,
  9276. attributes: {},
  9277. index: null
  9278. };
  9279. }
  9280. function needsUpdate(geometry, index) {
  9281. var cachedAttributes = currentState.attributes;
  9282. var geometryAttributes = geometry.attributes;
  9283. var attributesNum = 0;
  9284. for (var key in geometryAttributes) {
  9285. var cachedAttribute = cachedAttributes[key];
  9286. var geometryAttribute = geometryAttributes[key];
  9287. if (cachedAttribute === undefined) return true;
  9288. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9289. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9290. attributesNum++;
  9291. }
  9292. if (currentState.attributesNum !== attributesNum) return true;
  9293. if (currentState.index !== index) return true;
  9294. return false;
  9295. }
  9296. function saveCache(geometry, index) {
  9297. var cache = {};
  9298. var attributes = geometry.attributes;
  9299. var attributesNum = 0;
  9300. for (var key in attributes) {
  9301. var attribute = attributes[key];
  9302. var data = {};
  9303. data.attribute = attribute;
  9304. if (attribute.data) {
  9305. data.data = attribute.data;
  9306. }
  9307. cache[key] = data;
  9308. attributesNum++;
  9309. }
  9310. currentState.attributes = cache;
  9311. currentState.attributesNum = attributesNum;
  9312. currentState.index = index;
  9313. }
  9314. function initAttributes() {
  9315. var newAttributes = currentState.newAttributes;
  9316. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9317. newAttributes[i] = 0;
  9318. }
  9319. }
  9320. function enableAttribute(attribute) {
  9321. enableAttributeAndDivisor(attribute, 0);
  9322. }
  9323. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9324. var newAttributes = currentState.newAttributes;
  9325. var enabledAttributes = currentState.enabledAttributes;
  9326. var attributeDivisors = currentState.attributeDivisors;
  9327. newAttributes[attribute] = 1;
  9328. if (enabledAttributes[attribute] === 0) {
  9329. gl.enableVertexAttribArray(attribute);
  9330. enabledAttributes[attribute] = 1;
  9331. }
  9332. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9333. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9334. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9335. attributeDivisors[attribute] = meshPerAttribute;
  9336. }
  9337. }
  9338. function disableUnusedAttributes() {
  9339. var newAttributes = currentState.newAttributes;
  9340. var enabledAttributes = currentState.enabledAttributes;
  9341. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9342. if (enabledAttributes[i] !== newAttributes[i]) {
  9343. gl.disableVertexAttribArray(i);
  9344. enabledAttributes[i] = 0;
  9345. }
  9346. }
  9347. }
  9348. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9349. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9350. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9351. } else {
  9352. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9353. }
  9354. }
  9355. function setupVertexAttributes(object, material, program, geometry) {
  9356. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9357. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9358. }
  9359. initAttributes();
  9360. var geometryAttributes = geometry.attributes;
  9361. var programAttributes = program.getAttributes();
  9362. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9363. for (var name in programAttributes) {
  9364. var programAttribute = programAttributes[name];
  9365. if (programAttribute >= 0) {
  9366. var geometryAttribute = geometryAttributes[name];
  9367. if (geometryAttribute !== undefined) {
  9368. var normalized = geometryAttribute.normalized;
  9369. var size = geometryAttribute.itemSize;
  9370. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9371. if (attribute === undefined) continue;
  9372. var buffer = attribute.buffer;
  9373. var type = attribute.type;
  9374. var bytesPerElement = attribute.bytesPerElement;
  9375. if (geometryAttribute.isInterleavedBufferAttribute) {
  9376. var data = geometryAttribute.data;
  9377. var stride = data.stride;
  9378. var offset = geometryAttribute.offset;
  9379. if (data && data.isInstancedInterleavedBuffer) {
  9380. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9381. if (geometry._maxInstanceCount === undefined) {
  9382. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9383. }
  9384. } else {
  9385. enableAttribute(programAttribute);
  9386. }
  9387. gl.bindBuffer(34962, buffer);
  9388. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9389. } else {
  9390. if (geometryAttribute.isInstancedBufferAttribute) {
  9391. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9392. if (geometry._maxInstanceCount === undefined) {
  9393. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9394. }
  9395. } else {
  9396. enableAttribute(programAttribute);
  9397. }
  9398. gl.bindBuffer(34962, buffer);
  9399. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9400. }
  9401. } else if (name === 'instanceMatrix') {
  9402. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9403. if (_attribute === undefined) continue;
  9404. var _buffer = _attribute.buffer;
  9405. var _type = _attribute.type;
  9406. enableAttributeAndDivisor(programAttribute + 0, 1);
  9407. enableAttributeAndDivisor(programAttribute + 1, 1);
  9408. enableAttributeAndDivisor(programAttribute + 2, 1);
  9409. enableAttributeAndDivisor(programAttribute + 3, 1);
  9410. gl.bindBuffer(34962, _buffer);
  9411. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9412. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9413. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9414. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9415. } else if (name === 'instanceColor') {
  9416. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9417. if (_attribute2 === undefined) continue;
  9418. var _buffer2 = _attribute2.buffer;
  9419. var _type2 = _attribute2.type;
  9420. enableAttributeAndDivisor(programAttribute, 1);
  9421. gl.bindBuffer(34962, _buffer2);
  9422. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9423. } else if (materialDefaultAttributeValues !== undefined) {
  9424. var value = materialDefaultAttributeValues[name];
  9425. if (value !== undefined) {
  9426. switch (value.length) {
  9427. case 2:
  9428. gl.vertexAttrib2fv(programAttribute, value);
  9429. break;
  9430. case 3:
  9431. gl.vertexAttrib3fv(programAttribute, value);
  9432. break;
  9433. case 4:
  9434. gl.vertexAttrib4fv(programAttribute, value);
  9435. break;
  9436. default:
  9437. gl.vertexAttrib1fv(programAttribute, value);
  9438. }
  9439. }
  9440. }
  9441. }
  9442. }
  9443. disableUnusedAttributes();
  9444. }
  9445. function dispose() {
  9446. reset();
  9447. for (var geometryId in bindingStates) {
  9448. var programMap = bindingStates[geometryId];
  9449. for (var programId in programMap) {
  9450. var stateMap = programMap[programId];
  9451. for (var wireframe in stateMap) {
  9452. deleteVertexArrayObject(stateMap[wireframe].object);
  9453. delete stateMap[wireframe];
  9454. }
  9455. delete programMap[programId];
  9456. }
  9457. delete bindingStates[geometryId];
  9458. }
  9459. }
  9460. function releaseStatesOfGeometry(geometry) {
  9461. if (bindingStates[geometry.id] === undefined) return;
  9462. var programMap = bindingStates[geometry.id];
  9463. for (var programId in programMap) {
  9464. var stateMap = programMap[programId];
  9465. for (var wireframe in stateMap) {
  9466. deleteVertexArrayObject(stateMap[wireframe].object);
  9467. delete stateMap[wireframe];
  9468. }
  9469. delete programMap[programId];
  9470. }
  9471. delete bindingStates[geometry.id];
  9472. }
  9473. function releaseStatesOfProgram(program) {
  9474. for (var geometryId in bindingStates) {
  9475. var programMap = bindingStates[geometryId];
  9476. if (programMap[program.id] === undefined) continue;
  9477. var stateMap = programMap[program.id];
  9478. for (var wireframe in stateMap) {
  9479. deleteVertexArrayObject(stateMap[wireframe].object);
  9480. delete stateMap[wireframe];
  9481. }
  9482. delete programMap[program.id];
  9483. }
  9484. }
  9485. function reset() {
  9486. resetDefaultState();
  9487. if (currentState === defaultState) return;
  9488. currentState = defaultState;
  9489. bindVertexArrayObject(currentState.object);
  9490. } // for backward-compatilibity
  9491. function resetDefaultState() {
  9492. defaultState.geometry = null;
  9493. defaultState.program = null;
  9494. defaultState.wireframe = false;
  9495. }
  9496. return {
  9497. setup: setup,
  9498. reset: reset,
  9499. resetDefaultState: resetDefaultState,
  9500. dispose: dispose,
  9501. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9502. releaseStatesOfProgram: releaseStatesOfProgram,
  9503. initAttributes: initAttributes,
  9504. enableAttribute: enableAttribute,
  9505. disableUnusedAttributes: disableUnusedAttributes
  9506. };
  9507. }
  9508. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9509. var isWebGL2 = capabilities.isWebGL2;
  9510. var mode;
  9511. function setMode(value) {
  9512. mode = value;
  9513. }
  9514. function render(start, count) {
  9515. gl.drawArrays(mode, start, count);
  9516. info.update(count, mode, 1);
  9517. }
  9518. function renderInstances(start, count, primcount) {
  9519. if (primcount === 0) return;
  9520. var extension, methodName;
  9521. if (isWebGL2) {
  9522. extension = gl;
  9523. methodName = 'drawArraysInstanced';
  9524. } else {
  9525. extension = extensions.get('ANGLE_instanced_arrays');
  9526. methodName = 'drawArraysInstancedANGLE';
  9527. if (extension === null) {
  9528. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9529. return;
  9530. }
  9531. }
  9532. extension[methodName](mode, start, count, primcount);
  9533. info.update(count, mode, primcount);
  9534. } //
  9535. this.setMode = setMode;
  9536. this.render = render;
  9537. this.renderInstances = renderInstances;
  9538. }
  9539. function WebGLCapabilities(gl, extensions, parameters) {
  9540. var maxAnisotropy;
  9541. function getMaxAnisotropy() {
  9542. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9543. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9544. if (extension !== null) {
  9545. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9546. } else {
  9547. maxAnisotropy = 0;
  9548. }
  9549. return maxAnisotropy;
  9550. }
  9551. function getMaxPrecision(precision) {
  9552. if (precision === 'highp') {
  9553. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9554. return 'highp';
  9555. }
  9556. precision = 'mediump';
  9557. }
  9558. if (precision === 'mediump') {
  9559. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9560. return 'mediump';
  9561. }
  9562. }
  9563. return 'lowp';
  9564. }
  9565. /* eslint-disable no-undef */
  9566. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9567. /* eslint-enable no-undef */
  9568. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9569. var maxPrecision = getMaxPrecision(precision);
  9570. if (maxPrecision !== precision) {
  9571. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9572. precision = maxPrecision;
  9573. }
  9574. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9575. var maxTextures = gl.getParameter(34930);
  9576. var maxVertexTextures = gl.getParameter(35660);
  9577. var maxTextureSize = gl.getParameter(3379);
  9578. var maxCubemapSize = gl.getParameter(34076);
  9579. var maxAttributes = gl.getParameter(34921);
  9580. var maxVertexUniforms = gl.getParameter(36347);
  9581. var maxVaryings = gl.getParameter(36348);
  9582. var maxFragmentUniforms = gl.getParameter(36349);
  9583. var vertexTextures = maxVertexTextures > 0;
  9584. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9585. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9586. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9587. return {
  9588. isWebGL2: isWebGL2,
  9589. getMaxAnisotropy: getMaxAnisotropy,
  9590. getMaxPrecision: getMaxPrecision,
  9591. precision: precision,
  9592. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9593. maxTextures: maxTextures,
  9594. maxVertexTextures: maxVertexTextures,
  9595. maxTextureSize: maxTextureSize,
  9596. maxCubemapSize: maxCubemapSize,
  9597. maxAttributes: maxAttributes,
  9598. maxVertexUniforms: maxVertexUniforms,
  9599. maxVaryings: maxVaryings,
  9600. maxFragmentUniforms: maxFragmentUniforms,
  9601. vertexTextures: vertexTextures,
  9602. floatFragmentTextures: floatFragmentTextures,
  9603. floatVertexTextures: floatVertexTextures,
  9604. maxSamples: maxSamples
  9605. };
  9606. }
  9607. function WebGLClipping(properties) {
  9608. var scope = this;
  9609. var globalState = null,
  9610. numGlobalPlanes = 0,
  9611. localClippingEnabled = false,
  9612. renderingShadows = false;
  9613. var plane = new Plane(),
  9614. viewNormalMatrix = new Matrix3(),
  9615. uniform = {
  9616. value: null,
  9617. needsUpdate: false
  9618. };
  9619. this.uniform = uniform;
  9620. this.numPlanes = 0;
  9621. this.numIntersection = 0;
  9622. this.init = function (planes, enableLocalClipping, camera) {
  9623. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9624. // run another frame in order to reset the state:
  9625. numGlobalPlanes !== 0 || localClippingEnabled;
  9626. localClippingEnabled = enableLocalClipping;
  9627. globalState = projectPlanes(planes, camera, 0);
  9628. numGlobalPlanes = planes.length;
  9629. return enabled;
  9630. };
  9631. this.beginShadows = function () {
  9632. renderingShadows = true;
  9633. projectPlanes(null);
  9634. };
  9635. this.endShadows = function () {
  9636. renderingShadows = false;
  9637. resetGlobalState();
  9638. };
  9639. this.setState = function (material, camera, useCache) {
  9640. var planes = material.clippingPlanes,
  9641. clipIntersection = material.clipIntersection,
  9642. clipShadows = material.clipShadows;
  9643. var materialProperties = properties.get(material);
  9644. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9645. // there's no local clipping
  9646. if (renderingShadows) {
  9647. // there's no global clipping
  9648. projectPlanes(null);
  9649. } else {
  9650. resetGlobalState();
  9651. }
  9652. } else {
  9653. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9654. lGlobal = nGlobal * 4;
  9655. var dstArray = materialProperties.clippingState || null;
  9656. uniform.value = dstArray; // ensure unique state
  9657. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9658. for (var i = 0; i !== lGlobal; ++i) {
  9659. dstArray[i] = globalState[i];
  9660. }
  9661. materialProperties.clippingState = dstArray;
  9662. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9663. this.numPlanes += nGlobal;
  9664. }
  9665. };
  9666. function resetGlobalState() {
  9667. if (uniform.value !== globalState) {
  9668. uniform.value = globalState;
  9669. uniform.needsUpdate = numGlobalPlanes > 0;
  9670. }
  9671. scope.numPlanes = numGlobalPlanes;
  9672. scope.numIntersection = 0;
  9673. }
  9674. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9675. var nPlanes = planes !== null ? planes.length : 0;
  9676. var dstArray = null;
  9677. if (nPlanes !== 0) {
  9678. dstArray = uniform.value;
  9679. if (skipTransform !== true || dstArray === null) {
  9680. var flatSize = dstOffset + nPlanes * 4,
  9681. viewMatrix = camera.matrixWorldInverse;
  9682. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9683. if (dstArray === null || dstArray.length < flatSize) {
  9684. dstArray = new Float32Array(flatSize);
  9685. }
  9686. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9687. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9688. plane.normal.toArray(dstArray, i4);
  9689. dstArray[i4 + 3] = plane.constant;
  9690. }
  9691. }
  9692. uniform.value = dstArray;
  9693. uniform.needsUpdate = true;
  9694. }
  9695. scope.numPlanes = nPlanes;
  9696. scope.numIntersection = 0;
  9697. return dstArray;
  9698. }
  9699. }
  9700. function WebGLCubeMaps(renderer) {
  9701. var cubemaps = new WeakMap();
  9702. function mapTextureMapping(texture, mapping) {
  9703. if (mapping === EquirectangularReflectionMapping) {
  9704. texture.mapping = CubeReflectionMapping;
  9705. } else if (mapping === EquirectangularRefractionMapping) {
  9706. texture.mapping = CubeRefractionMapping;
  9707. }
  9708. return texture;
  9709. }
  9710. function get(texture) {
  9711. if (texture && texture.isTexture) {
  9712. var mapping = texture.mapping;
  9713. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9714. if (cubemaps.has(texture)) {
  9715. var cubemap = cubemaps.get(texture).texture;
  9716. return mapTextureMapping(cubemap, texture.mapping);
  9717. } else {
  9718. var image = texture.image;
  9719. if (image && image.height > 0) {
  9720. var currentRenderList = renderer.getRenderList();
  9721. var currentRenderTarget = renderer.getRenderTarget();
  9722. var currentRenderState = renderer.getRenderState();
  9723. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9724. renderTarget.fromEquirectangularTexture(renderer, texture);
  9725. cubemaps.set(texture, renderTarget);
  9726. renderer.setRenderTarget(currentRenderTarget);
  9727. renderer.setRenderList(currentRenderList);
  9728. renderer.setRenderState(currentRenderState);
  9729. texture.addEventListener('dispose', onTextureDispose);
  9730. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9731. } else {
  9732. // image not yet ready. try the conversion next frame
  9733. return null;
  9734. }
  9735. }
  9736. }
  9737. }
  9738. return texture;
  9739. }
  9740. function onTextureDispose(event) {
  9741. var texture = event.target;
  9742. texture.removeEventListener('dispose', onTextureDispose);
  9743. var cubemap = cubemaps.get(texture);
  9744. if (cubemap !== undefined) {
  9745. cubemaps.delete(texture);
  9746. cubemap.dispose();
  9747. }
  9748. }
  9749. function dispose() {
  9750. cubemaps = new WeakMap();
  9751. }
  9752. return {
  9753. get: get,
  9754. dispose: dispose
  9755. };
  9756. }
  9757. function WebGLExtensions(gl) {
  9758. var extensions = {};
  9759. return {
  9760. has: function has(name) {
  9761. if (extensions[name] !== undefined) {
  9762. return extensions[name] !== null;
  9763. }
  9764. var extension;
  9765. switch (name) {
  9766. case 'WEBGL_depth_texture':
  9767. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9768. break;
  9769. case 'EXT_texture_filter_anisotropic':
  9770. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9771. break;
  9772. case 'WEBGL_compressed_texture_s3tc':
  9773. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9774. break;
  9775. case 'WEBGL_compressed_texture_pvrtc':
  9776. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9777. break;
  9778. default:
  9779. extension = gl.getExtension(name);
  9780. }
  9781. extensions[name] = extension;
  9782. return extension !== null;
  9783. },
  9784. get: function get(name) {
  9785. if (!this.has(name)) {
  9786. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9787. }
  9788. return extensions[name];
  9789. }
  9790. };
  9791. }
  9792. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9793. var geometries = new WeakMap();
  9794. var wireframeAttributes = new WeakMap();
  9795. function onGeometryDispose(event) {
  9796. var geometry = event.target;
  9797. var buffergeometry = geometries.get(geometry);
  9798. if (buffergeometry.index !== null) {
  9799. attributes.remove(buffergeometry.index);
  9800. }
  9801. for (var name in buffergeometry.attributes) {
  9802. attributes.remove(buffergeometry.attributes[name]);
  9803. }
  9804. geometry.removeEventListener('dispose', onGeometryDispose);
  9805. geometries.delete(geometry);
  9806. var attribute = wireframeAttributes.get(buffergeometry);
  9807. if (attribute) {
  9808. attributes.remove(attribute);
  9809. wireframeAttributes.delete(buffergeometry);
  9810. }
  9811. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9812. if (geometry.isInstancedBufferGeometry === true) {
  9813. delete geometry._maxInstanceCount;
  9814. } //
  9815. info.memory.geometries--;
  9816. }
  9817. function get(object, geometry) {
  9818. var buffergeometry = geometries.get(geometry);
  9819. if (buffergeometry) return buffergeometry;
  9820. geometry.addEventListener('dispose', onGeometryDispose);
  9821. if (geometry.isBufferGeometry) {
  9822. buffergeometry = geometry;
  9823. } else if (geometry.isGeometry) {
  9824. if (geometry._bufferGeometry === undefined) {
  9825. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9826. }
  9827. buffergeometry = geometry._bufferGeometry;
  9828. }
  9829. geometries.set(geometry, buffergeometry);
  9830. info.memory.geometries++;
  9831. return buffergeometry;
  9832. }
  9833. function update(geometry) {
  9834. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9835. for (var name in geometryAttributes) {
  9836. attributes.update(geometryAttributes[name], 34962);
  9837. } // morph targets
  9838. var morphAttributes = geometry.morphAttributes;
  9839. for (var _name in morphAttributes) {
  9840. var array = morphAttributes[_name];
  9841. for (var i = 0, l = array.length; i < l; i++) {
  9842. attributes.update(array[i], 34962);
  9843. }
  9844. }
  9845. }
  9846. function updateWireframeAttribute(geometry) {
  9847. var indices = [];
  9848. var geometryIndex = geometry.index;
  9849. var geometryPosition = geometry.attributes.position;
  9850. var version = 0;
  9851. if (geometryIndex !== null) {
  9852. var array = geometryIndex.array;
  9853. version = geometryIndex.version;
  9854. for (var i = 0, l = array.length; i < l; i += 3) {
  9855. var a = array[i + 0];
  9856. var b = array[i + 1];
  9857. var c = array[i + 2];
  9858. indices.push(a, b, b, c, c, a);
  9859. }
  9860. } else {
  9861. var _array = geometryPosition.array;
  9862. version = geometryPosition.version;
  9863. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9864. var _a = _i + 0;
  9865. var _b = _i + 1;
  9866. var _c = _i + 2;
  9867. indices.push(_a, _b, _b, _c, _c, _a);
  9868. }
  9869. }
  9870. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9871. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9872. //
  9873. var previousAttribute = wireframeAttributes.get(geometry);
  9874. if (previousAttribute) attributes.remove(previousAttribute); //
  9875. wireframeAttributes.set(geometry, attribute);
  9876. }
  9877. function getWireframeAttribute(geometry) {
  9878. var currentAttribute = wireframeAttributes.get(geometry);
  9879. if (currentAttribute) {
  9880. var geometryIndex = geometry.index;
  9881. if (geometryIndex !== null) {
  9882. // if the attribute is obsolete, create a new one
  9883. if (currentAttribute.version < geometryIndex.version) {
  9884. updateWireframeAttribute(geometry);
  9885. }
  9886. }
  9887. } else {
  9888. updateWireframeAttribute(geometry);
  9889. }
  9890. return wireframeAttributes.get(geometry);
  9891. }
  9892. return {
  9893. get: get,
  9894. update: update,
  9895. getWireframeAttribute: getWireframeAttribute
  9896. };
  9897. }
  9898. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9899. var isWebGL2 = capabilities.isWebGL2;
  9900. var mode;
  9901. function setMode(value) {
  9902. mode = value;
  9903. }
  9904. var type, bytesPerElement;
  9905. function setIndex(value) {
  9906. type = value.type;
  9907. bytesPerElement = value.bytesPerElement;
  9908. }
  9909. function render(start, count) {
  9910. gl.drawElements(mode, count, type, start * bytesPerElement);
  9911. info.update(count, mode, 1);
  9912. }
  9913. function renderInstances(start, count, primcount) {
  9914. if (primcount === 0) return;
  9915. var extension, methodName;
  9916. if (isWebGL2) {
  9917. extension = gl;
  9918. methodName = 'drawElementsInstanced';
  9919. } else {
  9920. extension = extensions.get('ANGLE_instanced_arrays');
  9921. methodName = 'drawElementsInstancedANGLE';
  9922. if (extension === null) {
  9923. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9924. return;
  9925. }
  9926. }
  9927. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9928. info.update(count, mode, primcount);
  9929. } //
  9930. this.setMode = setMode;
  9931. this.setIndex = setIndex;
  9932. this.render = render;
  9933. this.renderInstances = renderInstances;
  9934. }
  9935. function WebGLInfo(gl) {
  9936. var memory = {
  9937. geometries: 0,
  9938. textures: 0
  9939. };
  9940. var render = {
  9941. frame: 0,
  9942. calls: 0,
  9943. triangles: 0,
  9944. points: 0,
  9945. lines: 0
  9946. };
  9947. function update(count, mode, instanceCount) {
  9948. render.calls++;
  9949. switch (mode) {
  9950. case 4:
  9951. render.triangles += instanceCount * (count / 3);
  9952. break;
  9953. case 1:
  9954. render.lines += instanceCount * (count / 2);
  9955. break;
  9956. case 3:
  9957. render.lines += instanceCount * (count - 1);
  9958. break;
  9959. case 2:
  9960. render.lines += instanceCount * count;
  9961. break;
  9962. case 0:
  9963. render.points += instanceCount * count;
  9964. break;
  9965. default:
  9966. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9967. break;
  9968. }
  9969. }
  9970. function reset() {
  9971. render.frame++;
  9972. render.calls = 0;
  9973. render.triangles = 0;
  9974. render.points = 0;
  9975. render.lines = 0;
  9976. }
  9977. return {
  9978. memory: memory,
  9979. render: render,
  9980. programs: null,
  9981. autoReset: true,
  9982. reset: reset,
  9983. update: update
  9984. };
  9985. }
  9986. function numericalSort(a, b) {
  9987. return a[0] - b[0];
  9988. }
  9989. function absNumericalSort(a, b) {
  9990. return Math.abs(b[1]) - Math.abs(a[1]);
  9991. }
  9992. function WebGLMorphtargets(gl) {
  9993. var influencesList = {};
  9994. var morphInfluences = new Float32Array(8);
  9995. var workInfluences = [];
  9996. for (var i = 0; i < 8; i++) {
  9997. workInfluences[i] = [i, 0];
  9998. }
  9999. function update(object, geometry, material, program) {
  10000. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10001. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10002. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10003. var influences = influencesList[geometry.id];
  10004. if (influences === undefined) {
  10005. // initialise list
  10006. influences = [];
  10007. for (var _i = 0; _i < length; _i++) {
  10008. influences[_i] = [_i, 0];
  10009. }
  10010. influencesList[geometry.id] = influences;
  10011. } // Collect influences
  10012. for (var _i2 = 0; _i2 < length; _i2++) {
  10013. var influence = influences[_i2];
  10014. influence[0] = _i2;
  10015. influence[1] = objectInfluences[_i2];
  10016. }
  10017. influences.sort(absNumericalSort);
  10018. for (var _i3 = 0; _i3 < 8; _i3++) {
  10019. if (_i3 < length && influences[_i3][1]) {
  10020. workInfluences[_i3][0] = influences[_i3][0];
  10021. workInfluences[_i3][1] = influences[_i3][1];
  10022. } else {
  10023. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10024. workInfluences[_i3][1] = 0;
  10025. }
  10026. }
  10027. workInfluences.sort(numericalSort);
  10028. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10029. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10030. var morphInfluencesSum = 0;
  10031. for (var _i4 = 0; _i4 < 8; _i4++) {
  10032. var _influence = workInfluences[_i4];
  10033. var index = _influence[0];
  10034. var value = _influence[1];
  10035. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10036. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10037. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10038. }
  10039. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10040. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10041. }
  10042. morphInfluences[_i4] = value;
  10043. morphInfluencesSum += value;
  10044. } else {
  10045. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10046. geometry.deleteAttribute('morphTarget' + _i4);
  10047. }
  10048. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10049. geometry.deleteAttribute('morphNormal' + _i4);
  10050. }
  10051. morphInfluences[_i4] = 0;
  10052. }
  10053. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10054. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10055. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10056. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10057. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10058. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10059. }
  10060. return {
  10061. update: update
  10062. };
  10063. }
  10064. function WebGLObjects(gl, geometries, attributes, info) {
  10065. var updateMap = new WeakMap();
  10066. function update(object) {
  10067. var frame = info.render.frame;
  10068. var geometry = object.geometry;
  10069. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10070. if (updateMap.get(buffergeometry) !== frame) {
  10071. if (geometry.isGeometry) {
  10072. buffergeometry.updateFromObject(object);
  10073. }
  10074. geometries.update(buffergeometry);
  10075. updateMap.set(buffergeometry, frame);
  10076. }
  10077. if (object.isInstancedMesh) {
  10078. attributes.update(object.instanceMatrix, 34962);
  10079. if (object.instanceColor !== null) {
  10080. attributes.update(object.instanceColor, 34962);
  10081. }
  10082. }
  10083. return buffergeometry;
  10084. }
  10085. function dispose() {
  10086. updateMap = new WeakMap();
  10087. }
  10088. return {
  10089. update: update,
  10090. dispose: dispose
  10091. };
  10092. }
  10093. function DataTexture2DArray(data, width, height, depth) {
  10094. if (data === void 0) {
  10095. data = null;
  10096. }
  10097. if (width === void 0) {
  10098. width = 1;
  10099. }
  10100. if (height === void 0) {
  10101. height = 1;
  10102. }
  10103. if (depth === void 0) {
  10104. depth = 1;
  10105. }
  10106. Texture.call(this, null);
  10107. this.image = {
  10108. data: data,
  10109. width: width,
  10110. height: height,
  10111. depth: depth
  10112. };
  10113. this.magFilter = NearestFilter;
  10114. this.minFilter = NearestFilter;
  10115. this.wrapR = ClampToEdgeWrapping;
  10116. this.generateMipmaps = false;
  10117. this.flipY = false;
  10118. this.needsUpdate = true;
  10119. }
  10120. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10121. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10122. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10123. function DataTexture3D(data, width, height, depth) {
  10124. if (data === void 0) {
  10125. data = null;
  10126. }
  10127. if (width === void 0) {
  10128. width = 1;
  10129. }
  10130. if (height === void 0) {
  10131. height = 1;
  10132. }
  10133. if (depth === void 0) {
  10134. depth = 1;
  10135. }
  10136. // We're going to add .setXXX() methods for setting properties later.
  10137. // Users can still set in DataTexture3D directly.
  10138. //
  10139. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10140. // texture.anisotropy = 16;
  10141. //
  10142. // See #14839
  10143. Texture.call(this, null);
  10144. this.image = {
  10145. data: data,
  10146. width: width,
  10147. height: height,
  10148. depth: depth
  10149. };
  10150. this.magFilter = NearestFilter;
  10151. this.minFilter = NearestFilter;
  10152. this.wrapR = ClampToEdgeWrapping;
  10153. this.generateMipmaps = false;
  10154. this.flipY = false;
  10155. this.needsUpdate = true;
  10156. }
  10157. DataTexture3D.prototype = Object.create(Texture.prototype);
  10158. DataTexture3D.prototype.constructor = DataTexture3D;
  10159. DataTexture3D.prototype.isDataTexture3D = true;
  10160. /**
  10161. * Uniforms of a program.
  10162. * Those form a tree structure with a special top-level container for the root,
  10163. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10164. *
  10165. *
  10166. * Properties of inner nodes including the top-level container:
  10167. *
  10168. * .seq - array of nested uniforms
  10169. * .map - nested uniforms by name
  10170. *
  10171. *
  10172. * Methods of all nodes except the top-level container:
  10173. *
  10174. * .setValue( gl, value, [textures] )
  10175. *
  10176. * uploads a uniform value(s)
  10177. * the 'textures' parameter is needed for sampler uniforms
  10178. *
  10179. *
  10180. * Static methods of the top-level container (textures factorizations):
  10181. *
  10182. * .upload( gl, seq, values, textures )
  10183. *
  10184. * sets uniforms in 'seq' to 'values[id].value'
  10185. *
  10186. * .seqWithValue( seq, values ) : filteredSeq
  10187. *
  10188. * filters 'seq' entries with corresponding entry in values
  10189. *
  10190. *
  10191. * Methods of the top-level container (textures factorizations):
  10192. *
  10193. * .setValue( gl, name, value, textures )
  10194. *
  10195. * sets uniform with name 'name' to 'value'
  10196. *
  10197. * .setOptional( gl, obj, prop )
  10198. *
  10199. * like .set for an optional property of the object
  10200. *
  10201. */
  10202. var emptyTexture = new Texture();
  10203. var emptyTexture2dArray = new DataTexture2DArray();
  10204. var emptyTexture3d = new DataTexture3D();
  10205. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10206. // Array Caches (provide typed arrays for temporary by size)
  10207. var arrayCacheF32 = [];
  10208. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10209. var mat4array = new Float32Array(16);
  10210. var mat3array = new Float32Array(9);
  10211. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10212. function flatten(array, nBlocks, blockSize) {
  10213. var firstElem = array[0];
  10214. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10215. // see http://jacksondunstan.com/articles/983
  10216. var n = nBlocks * blockSize;
  10217. var r = arrayCacheF32[n];
  10218. if (r === undefined) {
  10219. r = new Float32Array(n);
  10220. arrayCacheF32[n] = r;
  10221. }
  10222. if (nBlocks !== 0) {
  10223. firstElem.toArray(r, 0);
  10224. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10225. offset += blockSize;
  10226. array[i].toArray(r, offset);
  10227. }
  10228. }
  10229. return r;
  10230. }
  10231. function arraysEqual(a, b) {
  10232. if (a.length !== b.length) return false;
  10233. for (var i = 0, l = a.length; i < l; i++) {
  10234. if (a[i] !== b[i]) return false;
  10235. }
  10236. return true;
  10237. }
  10238. function copyArray(a, b) {
  10239. for (var i = 0, l = b.length; i < l; i++) {
  10240. a[i] = b[i];
  10241. }
  10242. } // Texture unit allocation
  10243. function allocTexUnits(textures, n) {
  10244. var r = arrayCacheI32[n];
  10245. if (r === undefined) {
  10246. r = new Int32Array(n);
  10247. arrayCacheI32[n] = r;
  10248. }
  10249. for (var i = 0; i !== n; ++i) {
  10250. r[i] = textures.allocateTextureUnit();
  10251. }
  10252. return r;
  10253. } // --- Setters ---
  10254. // Note: Defining these methods externally, because they come in a bunch
  10255. // and this way their names minify.
  10256. // Single scalar
  10257. function setValueV1f(gl, v) {
  10258. var cache = this.cache;
  10259. if (cache[0] === v) return;
  10260. gl.uniform1f(this.addr, v);
  10261. cache[0] = v;
  10262. } // Single float vector (from flat array or THREE.VectorN)
  10263. function setValueV2f(gl, v) {
  10264. var cache = this.cache;
  10265. if (v.x !== undefined) {
  10266. if (cache[0] !== v.x || cache[1] !== v.y) {
  10267. gl.uniform2f(this.addr, v.x, v.y);
  10268. cache[0] = v.x;
  10269. cache[1] = v.y;
  10270. }
  10271. } else {
  10272. if (arraysEqual(cache, v)) return;
  10273. gl.uniform2fv(this.addr, v);
  10274. copyArray(cache, v);
  10275. }
  10276. }
  10277. function setValueV3f(gl, v) {
  10278. var cache = this.cache;
  10279. if (v.x !== undefined) {
  10280. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10281. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10282. cache[0] = v.x;
  10283. cache[1] = v.y;
  10284. cache[2] = v.z;
  10285. }
  10286. } else if (v.r !== undefined) {
  10287. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10288. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10289. cache[0] = v.r;
  10290. cache[1] = v.g;
  10291. cache[2] = v.b;
  10292. }
  10293. } else {
  10294. if (arraysEqual(cache, v)) return;
  10295. gl.uniform3fv(this.addr, v);
  10296. copyArray(cache, v);
  10297. }
  10298. }
  10299. function setValueV4f(gl, v) {
  10300. var cache = this.cache;
  10301. if (v.x !== undefined) {
  10302. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10303. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10304. cache[0] = v.x;
  10305. cache[1] = v.y;
  10306. cache[2] = v.z;
  10307. cache[3] = v.w;
  10308. }
  10309. } else {
  10310. if (arraysEqual(cache, v)) return;
  10311. gl.uniform4fv(this.addr, v);
  10312. copyArray(cache, v);
  10313. }
  10314. } // Single matrix (from flat array or MatrixN)
  10315. function setValueM2(gl, v) {
  10316. var cache = this.cache;
  10317. var elements = v.elements;
  10318. if (elements === undefined) {
  10319. if (arraysEqual(cache, v)) return;
  10320. gl.uniformMatrix2fv(this.addr, false, v);
  10321. copyArray(cache, v);
  10322. } else {
  10323. if (arraysEqual(cache, elements)) return;
  10324. mat2array.set(elements);
  10325. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10326. copyArray(cache, elements);
  10327. }
  10328. }
  10329. function setValueM3(gl, v) {
  10330. var cache = this.cache;
  10331. var elements = v.elements;
  10332. if (elements === undefined) {
  10333. if (arraysEqual(cache, v)) return;
  10334. gl.uniformMatrix3fv(this.addr, false, v);
  10335. copyArray(cache, v);
  10336. } else {
  10337. if (arraysEqual(cache, elements)) return;
  10338. mat3array.set(elements);
  10339. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10340. copyArray(cache, elements);
  10341. }
  10342. }
  10343. function setValueM4(gl, v) {
  10344. var cache = this.cache;
  10345. var elements = v.elements;
  10346. if (elements === undefined) {
  10347. if (arraysEqual(cache, v)) return;
  10348. gl.uniformMatrix4fv(this.addr, false, v);
  10349. copyArray(cache, v);
  10350. } else {
  10351. if (arraysEqual(cache, elements)) return;
  10352. mat4array.set(elements);
  10353. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10354. copyArray(cache, elements);
  10355. }
  10356. } // Single texture (2D / Cube)
  10357. function setValueT1(gl, v, textures) {
  10358. var cache = this.cache;
  10359. var unit = textures.allocateTextureUnit();
  10360. if (cache[0] !== unit) {
  10361. gl.uniform1i(this.addr, unit);
  10362. cache[0] = unit;
  10363. }
  10364. textures.safeSetTexture2D(v || emptyTexture, unit);
  10365. }
  10366. function setValueT2DArray1(gl, v, textures) {
  10367. var cache = this.cache;
  10368. var unit = textures.allocateTextureUnit();
  10369. if (cache[0] !== unit) {
  10370. gl.uniform1i(this.addr, unit);
  10371. cache[0] = unit;
  10372. }
  10373. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10374. }
  10375. function setValueT3D1(gl, v, textures) {
  10376. var cache = this.cache;
  10377. var unit = textures.allocateTextureUnit();
  10378. if (cache[0] !== unit) {
  10379. gl.uniform1i(this.addr, unit);
  10380. cache[0] = unit;
  10381. }
  10382. textures.setTexture3D(v || emptyTexture3d, unit);
  10383. }
  10384. function setValueT6(gl, v, textures) {
  10385. var cache = this.cache;
  10386. var unit = textures.allocateTextureUnit();
  10387. if (cache[0] !== unit) {
  10388. gl.uniform1i(this.addr, unit);
  10389. cache[0] = unit;
  10390. }
  10391. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10392. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10393. function setValueV1i(gl, v) {
  10394. var cache = this.cache;
  10395. if (cache[0] === v) return;
  10396. gl.uniform1i(this.addr, v);
  10397. cache[0] = v;
  10398. }
  10399. function setValueV2i(gl, v) {
  10400. var cache = this.cache;
  10401. if (arraysEqual(cache, v)) return;
  10402. gl.uniform2iv(this.addr, v);
  10403. copyArray(cache, v);
  10404. }
  10405. function setValueV3i(gl, v) {
  10406. var cache = this.cache;
  10407. if (arraysEqual(cache, v)) return;
  10408. gl.uniform3iv(this.addr, v);
  10409. copyArray(cache, v);
  10410. }
  10411. function setValueV4i(gl, v) {
  10412. var cache = this.cache;
  10413. if (arraysEqual(cache, v)) return;
  10414. gl.uniform4iv(this.addr, v);
  10415. copyArray(cache, v);
  10416. } // uint
  10417. function setValueV1ui(gl, v) {
  10418. var cache = this.cache;
  10419. if (cache[0] === v) return;
  10420. gl.uniform1ui(this.addr, v);
  10421. cache[0] = v;
  10422. } // Helper to pick the right setter for the singular case
  10423. function getSingularSetter(type) {
  10424. switch (type) {
  10425. case 0x1406:
  10426. return setValueV1f;
  10427. // FLOAT
  10428. case 0x8b50:
  10429. return setValueV2f;
  10430. // _VEC2
  10431. case 0x8b51:
  10432. return setValueV3f;
  10433. // _VEC3
  10434. case 0x8b52:
  10435. return setValueV4f;
  10436. // _VEC4
  10437. case 0x8b5a:
  10438. return setValueM2;
  10439. // _MAT2
  10440. case 0x8b5b:
  10441. return setValueM3;
  10442. // _MAT3
  10443. case 0x8b5c:
  10444. return setValueM4;
  10445. // _MAT4
  10446. case 0x1404:
  10447. case 0x8b56:
  10448. return setValueV1i;
  10449. // INT, BOOL
  10450. case 0x8b53:
  10451. case 0x8b57:
  10452. return setValueV2i;
  10453. // _VEC2
  10454. case 0x8b54:
  10455. case 0x8b58:
  10456. return setValueV3i;
  10457. // _VEC3
  10458. case 0x8b55:
  10459. case 0x8b59:
  10460. return setValueV4i;
  10461. // _VEC4
  10462. case 0x1405:
  10463. return setValueV1ui;
  10464. // UINT
  10465. case 0x8b5e: // SAMPLER_2D
  10466. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10467. case 0x8dca: // INT_SAMPLER_2D
  10468. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10469. case 0x8b62:
  10470. // SAMPLER_2D_SHADOW
  10471. return setValueT1;
  10472. case 0x8b5f: // SAMPLER_3D
  10473. case 0x8dcb: // INT_SAMPLER_3D
  10474. case 0x8dd3:
  10475. // UNSIGNED_INT_SAMPLER_3D
  10476. return setValueT3D1;
  10477. case 0x8b60: // SAMPLER_CUBE
  10478. case 0x8dcc: // INT_SAMPLER_CUBE
  10479. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10480. case 0x8dc5:
  10481. // SAMPLER_CUBE_SHADOW
  10482. return setValueT6;
  10483. case 0x8dc1: // SAMPLER_2D_ARRAY
  10484. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10485. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10486. case 0x8dc4:
  10487. // SAMPLER_2D_ARRAY_SHADOW
  10488. return setValueT2DArray1;
  10489. }
  10490. } // Array of scalars
  10491. function setValueV1fArray(gl, v) {
  10492. gl.uniform1fv(this.addr, v);
  10493. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10494. function setValueV1iArray(gl, v) {
  10495. gl.uniform1iv(this.addr, v);
  10496. }
  10497. function setValueV2iArray(gl, v) {
  10498. gl.uniform2iv(this.addr, v);
  10499. }
  10500. function setValueV3iArray(gl, v) {
  10501. gl.uniform3iv(this.addr, v);
  10502. }
  10503. function setValueV4iArray(gl, v) {
  10504. gl.uniform4iv(this.addr, v);
  10505. } // Array of vectors (flat or from THREE classes)
  10506. function setValueV2fArray(gl, v) {
  10507. var data = flatten(v, this.size, 2);
  10508. gl.uniform2fv(this.addr, data);
  10509. }
  10510. function setValueV3fArray(gl, v) {
  10511. var data = flatten(v, this.size, 3);
  10512. gl.uniform3fv(this.addr, data);
  10513. }
  10514. function setValueV4fArray(gl, v) {
  10515. var data = flatten(v, this.size, 4);
  10516. gl.uniform4fv(this.addr, data);
  10517. } // Array of matrices (flat or from THREE clases)
  10518. function setValueM2Array(gl, v) {
  10519. var data = flatten(v, this.size, 4);
  10520. gl.uniformMatrix2fv(this.addr, false, data);
  10521. }
  10522. function setValueM3Array(gl, v) {
  10523. var data = flatten(v, this.size, 9);
  10524. gl.uniformMatrix3fv(this.addr, false, data);
  10525. }
  10526. function setValueM4Array(gl, v) {
  10527. var data = flatten(v, this.size, 16);
  10528. gl.uniformMatrix4fv(this.addr, false, data);
  10529. } // Array of textures (2D / Cube)
  10530. function setValueT1Array(gl, v, textures) {
  10531. var n = v.length;
  10532. var units = allocTexUnits(textures, n);
  10533. gl.uniform1iv(this.addr, units);
  10534. for (var i = 0; i !== n; ++i) {
  10535. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10536. }
  10537. }
  10538. function setValueT6Array(gl, v, textures) {
  10539. var n = v.length;
  10540. var units = allocTexUnits(textures, n);
  10541. gl.uniform1iv(this.addr, units);
  10542. for (var i = 0; i !== n; ++i) {
  10543. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10544. }
  10545. } // Helper to pick the right setter for a pure (bottom-level) array
  10546. function getPureArraySetter(type) {
  10547. switch (type) {
  10548. case 0x1406:
  10549. return setValueV1fArray;
  10550. // FLOAT
  10551. case 0x8b50:
  10552. return setValueV2fArray;
  10553. // _VEC2
  10554. case 0x8b51:
  10555. return setValueV3fArray;
  10556. // _VEC3
  10557. case 0x8b52:
  10558. return setValueV4fArray;
  10559. // _VEC4
  10560. case 0x8b5a:
  10561. return setValueM2Array;
  10562. // _MAT2
  10563. case 0x8b5b:
  10564. return setValueM3Array;
  10565. // _MAT3
  10566. case 0x8b5c:
  10567. return setValueM4Array;
  10568. // _MAT4
  10569. case 0x1404:
  10570. case 0x8b56:
  10571. return setValueV1iArray;
  10572. // INT, BOOL
  10573. case 0x8b53:
  10574. case 0x8b57:
  10575. return setValueV2iArray;
  10576. // _VEC2
  10577. case 0x8b54:
  10578. case 0x8b58:
  10579. return setValueV3iArray;
  10580. // _VEC3
  10581. case 0x8b55:
  10582. case 0x8b59:
  10583. return setValueV4iArray;
  10584. // _VEC4
  10585. case 0x8b5e: // SAMPLER_2D
  10586. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10587. case 0x8dca: // INT_SAMPLER_2D
  10588. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10589. case 0x8b62:
  10590. // SAMPLER_2D_SHADOW
  10591. return setValueT1Array;
  10592. case 0x8b60: // SAMPLER_CUBE
  10593. case 0x8dcc: // INT_SAMPLER_CUBE
  10594. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10595. case 0x8dc5:
  10596. // SAMPLER_CUBE_SHADOW
  10597. return setValueT6Array;
  10598. }
  10599. } // --- Uniform Classes ---
  10600. function SingleUniform(id, activeInfo, addr) {
  10601. this.id = id;
  10602. this.addr = addr;
  10603. this.cache = [];
  10604. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10605. }
  10606. function PureArrayUniform(id, activeInfo, addr) {
  10607. this.id = id;
  10608. this.addr = addr;
  10609. this.cache = [];
  10610. this.size = activeInfo.size;
  10611. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10612. }
  10613. PureArrayUniform.prototype.updateCache = function (data) {
  10614. var cache = this.cache;
  10615. if (data instanceof Float32Array && cache.length !== data.length) {
  10616. this.cache = new Float32Array(data.length);
  10617. }
  10618. copyArray(cache, data);
  10619. };
  10620. function StructuredUniform(id) {
  10621. this.id = id;
  10622. this.seq = [];
  10623. this.map = {};
  10624. }
  10625. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10626. var seq = this.seq;
  10627. for (var i = 0, n = seq.length; i !== n; ++i) {
  10628. var u = seq[i];
  10629. u.setValue(gl, value[u.id], textures);
  10630. }
  10631. }; // --- Top-level ---
  10632. // Parser - builds up the property tree from the path strings
  10633. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10634. // - the identifier (member name or array index)
  10635. // - followed by an optional right bracket (found when array index)
  10636. // - followed by an optional left bracket or dot (type of subscript)
  10637. //
  10638. // Note: These portions can be read in a non-overlapping fashion and
  10639. // allow straightforward parsing of the hierarchy that WebGL encodes
  10640. // in the uniform names.
  10641. function addUniform(container, uniformObject) {
  10642. container.seq.push(uniformObject);
  10643. container.map[uniformObject.id] = uniformObject;
  10644. }
  10645. function parseUniform(activeInfo, addr, container) {
  10646. var path = activeInfo.name,
  10647. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10648. RePathPart.lastIndex = 0;
  10649. while (true) {
  10650. var match = RePathPart.exec(path),
  10651. matchEnd = RePathPart.lastIndex;
  10652. var id = match[1];
  10653. var idIsIndex = match[2] === ']',
  10654. subscript = match[3];
  10655. if (idIsIndex) id = id | 0; // convert to integer
  10656. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10657. // bare name or "pure" bottom-level array "[0]" suffix
  10658. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10659. break;
  10660. } else {
  10661. // step into inner node / create it in case it doesn't exist
  10662. var map = container.map;
  10663. var next = map[id];
  10664. if (next === undefined) {
  10665. next = new StructuredUniform(id);
  10666. addUniform(container, next);
  10667. }
  10668. container = next;
  10669. }
  10670. }
  10671. } // Root Container
  10672. function WebGLUniforms(gl, program) {
  10673. this.seq = [];
  10674. this.map = {};
  10675. var n = gl.getProgramParameter(program, 35718);
  10676. for (var i = 0; i < n; ++i) {
  10677. var info = gl.getActiveUniform(program, i),
  10678. addr = gl.getUniformLocation(program, info.name);
  10679. parseUniform(info, addr, this);
  10680. }
  10681. }
  10682. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10683. var u = this.map[name];
  10684. if (u !== undefined) u.setValue(gl, value, textures);
  10685. };
  10686. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10687. var v = object[name];
  10688. if (v !== undefined) this.setValue(gl, name, v);
  10689. }; // Static interface
  10690. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10691. for (var i = 0, n = seq.length; i !== n; ++i) {
  10692. var u = seq[i],
  10693. v = values[u.id];
  10694. if (v.needsUpdate !== false) {
  10695. // note: always updating when .needsUpdate is undefined
  10696. u.setValue(gl, v.value, textures);
  10697. }
  10698. }
  10699. };
  10700. WebGLUniforms.seqWithValue = function (seq, values) {
  10701. var r = [];
  10702. for (var i = 0, n = seq.length; i !== n; ++i) {
  10703. var u = seq[i];
  10704. if (u.id in values) r.push(u);
  10705. }
  10706. return r;
  10707. };
  10708. function WebGLShader(gl, type, string) {
  10709. var shader = gl.createShader(type);
  10710. gl.shaderSource(shader, string);
  10711. gl.compileShader(shader);
  10712. return shader;
  10713. }
  10714. var programIdCount = 0;
  10715. function addLineNumbers(string) {
  10716. var lines = string.split('\n');
  10717. for (var i = 0; i < lines.length; i++) {
  10718. lines[i] = i + 1 + ': ' + lines[i];
  10719. }
  10720. return lines.join('\n');
  10721. }
  10722. function getEncodingComponents(encoding) {
  10723. switch (encoding) {
  10724. case LinearEncoding:
  10725. return ['Linear', '( value )'];
  10726. case sRGBEncoding:
  10727. return ['sRGB', '( value )'];
  10728. case RGBEEncoding:
  10729. return ['RGBE', '( value )'];
  10730. case RGBM7Encoding:
  10731. return ['RGBM', '( value, 7.0 )'];
  10732. case RGBM16Encoding:
  10733. return ['RGBM', '( value, 16.0 )'];
  10734. case RGBDEncoding:
  10735. return ['RGBD', '( value, 256.0 )'];
  10736. case GammaEncoding:
  10737. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10738. case LogLuvEncoding:
  10739. return ['LogLuv', '( value )'];
  10740. default:
  10741. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10742. return ['Linear', '( value )'];
  10743. }
  10744. }
  10745. function getShaderErrors(gl, shader, type) {
  10746. var status = gl.getShaderParameter(shader, 35713);
  10747. var log = gl.getShaderInfoLog(shader).trim();
  10748. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10749. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10750. var source = gl.getShaderSource(shader);
  10751. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10752. }
  10753. function getTexelDecodingFunction(functionName, encoding) {
  10754. var components = getEncodingComponents(encoding);
  10755. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10756. }
  10757. function getTexelEncodingFunction(functionName, encoding) {
  10758. var components = getEncodingComponents(encoding);
  10759. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10760. }
  10761. function getToneMappingFunction(functionName, toneMapping) {
  10762. var toneMappingName;
  10763. switch (toneMapping) {
  10764. case LinearToneMapping:
  10765. toneMappingName = 'Linear';
  10766. break;
  10767. case ReinhardToneMapping:
  10768. toneMappingName = 'Reinhard';
  10769. break;
  10770. case CineonToneMapping:
  10771. toneMappingName = 'OptimizedCineon';
  10772. break;
  10773. case ACESFilmicToneMapping:
  10774. toneMappingName = 'ACESFilmic';
  10775. break;
  10776. case CustomToneMapping:
  10777. toneMappingName = 'Custom';
  10778. break;
  10779. default:
  10780. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10781. toneMappingName = 'Linear';
  10782. }
  10783. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10784. }
  10785. function generateExtensions(parameters) {
  10786. 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' : ''];
  10787. return chunks.filter(filterEmptyLine).join('\n');
  10788. }
  10789. function generateDefines(defines) {
  10790. var chunks = [];
  10791. for (var name in defines) {
  10792. var value = defines[name];
  10793. if (value === false) continue;
  10794. chunks.push('#define ' + name + ' ' + value);
  10795. }
  10796. return chunks.join('\n');
  10797. }
  10798. function fetchAttributeLocations(gl, program) {
  10799. var attributes = {};
  10800. var n = gl.getProgramParameter(program, 35721);
  10801. for (var i = 0; i < n; i++) {
  10802. var info = gl.getActiveAttrib(program, i);
  10803. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10804. attributes[name] = gl.getAttribLocation(program, name);
  10805. }
  10806. return attributes;
  10807. }
  10808. function filterEmptyLine(string) {
  10809. return string !== '';
  10810. }
  10811. function replaceLightNums(string, parameters) {
  10812. 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);
  10813. }
  10814. function replaceClippingPlaneNums(string, parameters) {
  10815. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10816. } // Resolve Includes
  10817. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10818. function resolveIncludes(string) {
  10819. return string.replace(includePattern, includeReplacer);
  10820. }
  10821. function includeReplacer(match, include) {
  10822. var string = ShaderChunk[include];
  10823. if (string === undefined) {
  10824. throw new Error('Can not resolve #include <' + include + '>');
  10825. }
  10826. return resolveIncludes(string);
  10827. } // Unroll Loops
  10828. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10829. 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;
  10830. function unrollLoops(string) {
  10831. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10832. }
  10833. function deprecatedLoopReplacer(match, start, end, snippet) {
  10834. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10835. return loopReplacer(match, start, end, snippet);
  10836. }
  10837. function loopReplacer(match, start, end, snippet) {
  10838. var string = '';
  10839. for (var i = parseInt(start); i < parseInt(end); i++) {
  10840. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10841. }
  10842. return string;
  10843. } //
  10844. function generatePrecision(parameters) {
  10845. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10846. if (parameters.precision === "highp") {
  10847. precisionstring += "\n#define HIGH_PRECISION";
  10848. } else if (parameters.precision === "mediump") {
  10849. precisionstring += "\n#define MEDIUM_PRECISION";
  10850. } else if (parameters.precision === "lowp") {
  10851. precisionstring += "\n#define LOW_PRECISION";
  10852. }
  10853. return precisionstring;
  10854. }
  10855. function generateShadowMapTypeDefine(parameters) {
  10856. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10857. if (parameters.shadowMapType === PCFShadowMap) {
  10858. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10859. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10860. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10861. } else if (parameters.shadowMapType === VSMShadowMap) {
  10862. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10863. }
  10864. return shadowMapTypeDefine;
  10865. }
  10866. function generateEnvMapTypeDefine(parameters) {
  10867. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10868. if (parameters.envMap) {
  10869. switch (parameters.envMapMode) {
  10870. case CubeReflectionMapping:
  10871. case CubeRefractionMapping:
  10872. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10873. break;
  10874. case CubeUVReflectionMapping:
  10875. case CubeUVRefractionMapping:
  10876. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10877. break;
  10878. }
  10879. }
  10880. return envMapTypeDefine;
  10881. }
  10882. function generateEnvMapModeDefine(parameters) {
  10883. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10884. if (parameters.envMap) {
  10885. switch (parameters.envMapMode) {
  10886. case CubeRefractionMapping:
  10887. case CubeUVRefractionMapping:
  10888. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10889. break;
  10890. }
  10891. }
  10892. return envMapModeDefine;
  10893. }
  10894. function generateEnvMapBlendingDefine(parameters) {
  10895. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10896. if (parameters.envMap) {
  10897. switch (parameters.combine) {
  10898. case MultiplyOperation:
  10899. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10900. break;
  10901. case MixOperation:
  10902. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10903. break;
  10904. case AddOperation:
  10905. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10906. break;
  10907. }
  10908. }
  10909. return envMapBlendingDefine;
  10910. }
  10911. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10912. var gl = renderer.getContext();
  10913. var defines = parameters.defines;
  10914. var vertexShader = parameters.vertexShader;
  10915. var fragmentShader = parameters.fragmentShader;
  10916. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10917. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10918. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10919. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10920. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10921. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10922. var customDefines = generateDefines(defines);
  10923. var program = gl.createProgram();
  10924. var prefixVertex, prefixFragment;
  10925. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10926. if (parameters.isRawShaderMaterial) {
  10927. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10928. if (prefixVertex.length > 0) {
  10929. prefixVertex += '\n';
  10930. }
  10931. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10932. if (prefixFragment.length > 0) {
  10933. prefixFragment += '\n';
  10934. }
  10935. } else {
  10936. 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');
  10937. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10938. '#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
  10939. 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
  10940. 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');
  10941. }
  10942. vertexShader = resolveIncludes(vertexShader);
  10943. vertexShader = replaceLightNums(vertexShader, parameters);
  10944. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10945. fragmentShader = resolveIncludes(fragmentShader);
  10946. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10947. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10948. vertexShader = unrollLoops(vertexShader);
  10949. fragmentShader = unrollLoops(fragmentShader);
  10950. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10951. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10952. versionString = '#version 300 es\n';
  10953. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10954. 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;
  10955. }
  10956. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10957. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10958. // console.log( '*FRAGMENT*', fragmentGlsl );
  10959. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10960. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10961. gl.attachShader(program, glVertexShader);
  10962. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10963. if (parameters.index0AttributeName !== undefined) {
  10964. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10965. } else if (parameters.morphTargets === true) {
  10966. // programs with morphTargets displace position out of attribute 0
  10967. gl.bindAttribLocation(program, 0, 'position');
  10968. }
  10969. gl.linkProgram(program); // check for link errors
  10970. if (renderer.debug.checkShaderErrors) {
  10971. var programLog = gl.getProgramInfoLog(program).trim();
  10972. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10973. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10974. var runnable = true;
  10975. var haveDiagnostics = true;
  10976. if (gl.getProgramParameter(program, 35714) === false) {
  10977. runnable = false;
  10978. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10979. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10980. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10981. } else if (programLog !== '') {
  10982. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10983. } else if (vertexLog === '' || fragmentLog === '') {
  10984. haveDiagnostics = false;
  10985. }
  10986. if (haveDiagnostics) {
  10987. this.diagnostics = {
  10988. runnable: runnable,
  10989. programLog: programLog,
  10990. vertexShader: {
  10991. log: vertexLog,
  10992. prefix: prefixVertex
  10993. },
  10994. fragmentShader: {
  10995. log: fragmentLog,
  10996. prefix: prefixFragment
  10997. }
  10998. };
  10999. }
  11000. } // Clean up
  11001. // Crashes in iOS9 and iOS10. #18402
  11002. // gl.detachShader( program, glVertexShader );
  11003. // gl.detachShader( program, glFragmentShader );
  11004. gl.deleteShader(glVertexShader);
  11005. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11006. var cachedUniforms;
  11007. this.getUniforms = function () {
  11008. if (cachedUniforms === undefined) {
  11009. cachedUniforms = new WebGLUniforms(gl, program);
  11010. }
  11011. return cachedUniforms;
  11012. }; // set up caching for attribute locations
  11013. var cachedAttributes;
  11014. this.getAttributes = function () {
  11015. if (cachedAttributes === undefined) {
  11016. cachedAttributes = fetchAttributeLocations(gl, program);
  11017. }
  11018. return cachedAttributes;
  11019. }; // free resource
  11020. this.destroy = function () {
  11021. bindingStates.releaseStatesOfProgram(this);
  11022. gl.deleteProgram(program);
  11023. this.program = undefined;
  11024. }; //
  11025. this.name = parameters.shaderName;
  11026. this.id = programIdCount++;
  11027. this.cacheKey = cacheKey;
  11028. this.usedTimes = 1;
  11029. this.program = program;
  11030. this.vertexShader = glVertexShader;
  11031. this.fragmentShader = glFragmentShader;
  11032. return this;
  11033. }
  11034. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11035. var programs = [];
  11036. var isWebGL2 = capabilities.isWebGL2;
  11037. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11038. var floatVertexTextures = capabilities.floatVertexTextures;
  11039. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11040. var vertexTextures = capabilities.vertexTextures;
  11041. var precision = capabilities.precision;
  11042. var shaderIDs = {
  11043. MeshDepthMaterial: 'depth',
  11044. MeshDistanceMaterial: 'distanceRGBA',
  11045. MeshNormalMaterial: 'normal',
  11046. MeshBasicMaterial: 'basic',
  11047. MeshLambertMaterial: 'lambert',
  11048. MeshPhongMaterial: 'phong',
  11049. MeshToonMaterial: 'toon',
  11050. MeshStandardMaterial: 'physical',
  11051. MeshPhysicalMaterial: 'physical',
  11052. MeshMatcapMaterial: 'matcap',
  11053. LineBasicMaterial: 'basic',
  11054. LineDashedMaterial: 'dashed',
  11055. PointsMaterial: 'points',
  11056. ShadowMaterial: 'shadow',
  11057. SpriteMaterial: 'sprite'
  11058. };
  11059. 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"];
  11060. function getMaxBones(object) {
  11061. var skeleton = object.skeleton;
  11062. var bones = skeleton.bones;
  11063. if (floatVertexTextures) {
  11064. return 1024;
  11065. } else {
  11066. // default for when object is not specified
  11067. // ( for example when prebuilding shader to be used with multiple objects )
  11068. //
  11069. // - leave some extra space for other uniforms
  11070. // - limit here is ANGLE's 254 max uniform vectors
  11071. // (up to 54 should be safe)
  11072. var nVertexUniforms = maxVertexUniforms;
  11073. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11074. var maxBones = Math.min(nVertexMatrices, bones.length);
  11075. if (maxBones < bones.length) {
  11076. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11077. return 0;
  11078. }
  11079. return maxBones;
  11080. }
  11081. }
  11082. function getTextureEncodingFromMap(map) {
  11083. var encoding;
  11084. if (!map) {
  11085. encoding = LinearEncoding;
  11086. } else if (map.isTexture) {
  11087. encoding = map.encoding;
  11088. } else if (map.isWebGLRenderTarget) {
  11089. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  11090. encoding = map.texture.encoding;
  11091. }
  11092. return encoding;
  11093. }
  11094. function getParameters(material, lights, shadows, scene, object) {
  11095. var fog = scene.fog;
  11096. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11097. var envMap = cubemaps.get(material.envMap || environment);
  11098. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11099. // (not to blow over maxLights budget)
  11100. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11101. if (material.precision !== null) {
  11102. precision = capabilities.getMaxPrecision(material.precision);
  11103. if (precision !== material.precision) {
  11104. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11105. }
  11106. }
  11107. var vertexShader, fragmentShader;
  11108. if (shaderID) {
  11109. var shader = ShaderLib[shaderID];
  11110. vertexShader = shader.vertexShader;
  11111. fragmentShader = shader.fragmentShader;
  11112. } else {
  11113. vertexShader = material.vertexShader;
  11114. fragmentShader = material.fragmentShader;
  11115. }
  11116. var currentRenderTarget = renderer.getRenderTarget();
  11117. var parameters = {
  11118. isWebGL2: isWebGL2,
  11119. shaderID: shaderID,
  11120. shaderName: material.type,
  11121. vertexShader: vertexShader,
  11122. fragmentShader: fragmentShader,
  11123. defines: material.defines,
  11124. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11125. glslVersion: material.glslVersion,
  11126. precision: precision,
  11127. instancing: object.isInstancedMesh === true,
  11128. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11129. supportsVertexTextures: vertexTextures,
  11130. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11131. map: !!material.map,
  11132. mapEncoding: getTextureEncodingFromMap(material.map),
  11133. matcap: !!material.matcap,
  11134. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11135. envMap: !!envMap,
  11136. envMapMode: envMap && envMap.mapping,
  11137. envMapEncoding: getTextureEncodingFromMap(envMap),
  11138. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11139. lightMap: !!material.lightMap,
  11140. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11141. aoMap: !!material.aoMap,
  11142. emissiveMap: !!material.emissiveMap,
  11143. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11144. bumpMap: !!material.bumpMap,
  11145. normalMap: !!material.normalMap,
  11146. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11147. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11148. clearcoatMap: !!material.clearcoatMap,
  11149. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11150. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11151. displacementMap: !!material.displacementMap,
  11152. roughnessMap: !!material.roughnessMap,
  11153. metalnessMap: !!material.metalnessMap,
  11154. specularMap: !!material.specularMap,
  11155. alphaMap: !!material.alphaMap,
  11156. gradientMap: !!material.gradientMap,
  11157. sheen: !!material.sheen,
  11158. transmissionMap: !!material.transmissionMap,
  11159. combine: material.combine,
  11160. vertexTangents: material.normalMap && material.vertexTangents,
  11161. vertexColors: material.vertexColors,
  11162. 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,
  11163. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11164. fog: !!fog,
  11165. useFog: material.fog,
  11166. fogExp2: fog && fog.isFogExp2,
  11167. flatShading: material.flatShading,
  11168. sizeAttenuation: material.sizeAttenuation,
  11169. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11170. skinning: material.skinning && maxBones > 0,
  11171. maxBones: maxBones,
  11172. useVertexTexture: floatVertexTextures,
  11173. morphTargets: material.morphTargets,
  11174. morphNormals: material.morphNormals,
  11175. maxMorphTargets: renderer.maxMorphTargets,
  11176. maxMorphNormals: renderer.maxMorphNormals,
  11177. numDirLights: lights.directional.length,
  11178. numPointLights: lights.point.length,
  11179. numSpotLights: lights.spot.length,
  11180. numRectAreaLights: lights.rectArea.length,
  11181. numHemiLights: lights.hemi.length,
  11182. numDirLightShadows: lights.directionalShadowMap.length,
  11183. numPointLightShadows: lights.pointShadowMap.length,
  11184. numSpotLightShadows: lights.spotShadowMap.length,
  11185. numClippingPlanes: clipping.numPlanes,
  11186. numClipIntersection: clipping.numIntersection,
  11187. dithering: material.dithering,
  11188. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11189. shadowMapType: renderer.shadowMap.type,
  11190. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11191. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11192. premultipliedAlpha: material.premultipliedAlpha,
  11193. alphaTest: material.alphaTest,
  11194. doubleSided: material.side === DoubleSide,
  11195. flipSided: material.side === BackSide,
  11196. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11197. index0AttributeName: material.index0AttributeName,
  11198. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11199. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11200. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11201. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11202. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11203. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11204. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11205. customProgramCacheKey: material.customProgramCacheKey()
  11206. };
  11207. return parameters;
  11208. }
  11209. function getProgramCacheKey(parameters) {
  11210. var array = [];
  11211. if (parameters.shaderID) {
  11212. array.push(parameters.shaderID);
  11213. } else {
  11214. array.push(parameters.fragmentShader);
  11215. array.push(parameters.vertexShader);
  11216. }
  11217. if (parameters.defines !== undefined) {
  11218. for (var name in parameters.defines) {
  11219. array.push(name);
  11220. array.push(parameters.defines[name]);
  11221. }
  11222. }
  11223. if (parameters.isRawShaderMaterial === false) {
  11224. for (var i = 0; i < parameterNames.length; i++) {
  11225. array.push(parameters[parameterNames[i]]);
  11226. }
  11227. array.push(renderer.outputEncoding);
  11228. array.push(renderer.gammaFactor);
  11229. }
  11230. array.push(parameters.customProgramCacheKey);
  11231. return array.join();
  11232. }
  11233. function getUniforms(material) {
  11234. var shaderID = shaderIDs[material.type];
  11235. var uniforms;
  11236. if (shaderID) {
  11237. var shader = ShaderLib[shaderID];
  11238. uniforms = UniformsUtils.clone(shader.uniforms);
  11239. } else {
  11240. uniforms = material.uniforms;
  11241. }
  11242. return uniforms;
  11243. }
  11244. function acquireProgram(parameters, cacheKey) {
  11245. var program; // Check if code has been already compiled
  11246. for (var p = 0, pl = programs.length; p < pl; p++) {
  11247. var preexistingProgram = programs[p];
  11248. if (preexistingProgram.cacheKey === cacheKey) {
  11249. program = preexistingProgram;
  11250. ++program.usedTimes;
  11251. break;
  11252. }
  11253. }
  11254. if (program === undefined) {
  11255. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11256. programs.push(program);
  11257. }
  11258. return program;
  11259. }
  11260. function releaseProgram(program) {
  11261. if (--program.usedTimes === 0) {
  11262. // Remove from unordered set
  11263. var i = programs.indexOf(program);
  11264. programs[i] = programs[programs.length - 1];
  11265. programs.pop(); // Free WebGL resources
  11266. program.destroy();
  11267. }
  11268. }
  11269. return {
  11270. getParameters: getParameters,
  11271. getProgramCacheKey: getProgramCacheKey,
  11272. getUniforms: getUniforms,
  11273. acquireProgram: acquireProgram,
  11274. releaseProgram: releaseProgram,
  11275. // Exposed for resource monitoring & error feedback via renderer.info:
  11276. programs: programs
  11277. };
  11278. }
  11279. function WebGLProperties() {
  11280. var properties = new WeakMap();
  11281. function get(object) {
  11282. var map = properties.get(object);
  11283. if (map === undefined) {
  11284. map = {};
  11285. properties.set(object, map);
  11286. }
  11287. return map;
  11288. }
  11289. function remove(object) {
  11290. properties.delete(object);
  11291. }
  11292. function update(object, key, value) {
  11293. properties.get(object)[key] = value;
  11294. }
  11295. function dispose() {
  11296. properties = new WeakMap();
  11297. }
  11298. return {
  11299. get: get,
  11300. remove: remove,
  11301. update: update,
  11302. dispose: dispose
  11303. };
  11304. }
  11305. function painterSortStable(a, b) {
  11306. if (a.groupOrder !== b.groupOrder) {
  11307. return a.groupOrder - b.groupOrder;
  11308. } else if (a.renderOrder !== b.renderOrder) {
  11309. return a.renderOrder - b.renderOrder;
  11310. } else if (a.program !== b.program) {
  11311. return a.program.id - b.program.id;
  11312. } else if (a.material.id !== b.material.id) {
  11313. return a.material.id - b.material.id;
  11314. } else if (a.z !== b.z) {
  11315. return a.z - b.z;
  11316. } else {
  11317. return a.id - b.id;
  11318. }
  11319. }
  11320. function reversePainterSortStable(a, b) {
  11321. if (a.groupOrder !== b.groupOrder) {
  11322. return a.groupOrder - b.groupOrder;
  11323. } else if (a.renderOrder !== b.renderOrder) {
  11324. return a.renderOrder - b.renderOrder;
  11325. } else if (a.z !== b.z) {
  11326. return b.z - a.z;
  11327. } else {
  11328. return a.id - b.id;
  11329. }
  11330. }
  11331. function WebGLRenderList(properties) {
  11332. var renderItems = [];
  11333. var renderItemsIndex = 0;
  11334. var opaque = [];
  11335. var transparent = [];
  11336. var defaultProgram = {
  11337. id: -1
  11338. };
  11339. function init() {
  11340. renderItemsIndex = 0;
  11341. opaque.length = 0;
  11342. transparent.length = 0;
  11343. }
  11344. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11345. var renderItem = renderItems[renderItemsIndex];
  11346. var materialProperties = properties.get(material);
  11347. if (renderItem === undefined) {
  11348. renderItem = {
  11349. id: object.id,
  11350. object: object,
  11351. geometry: geometry,
  11352. material: material,
  11353. program: materialProperties.program || defaultProgram,
  11354. groupOrder: groupOrder,
  11355. renderOrder: object.renderOrder,
  11356. z: z,
  11357. group: group
  11358. };
  11359. renderItems[renderItemsIndex] = renderItem;
  11360. } else {
  11361. renderItem.id = object.id;
  11362. renderItem.object = object;
  11363. renderItem.geometry = geometry;
  11364. renderItem.material = material;
  11365. renderItem.program = materialProperties.program || defaultProgram;
  11366. renderItem.groupOrder = groupOrder;
  11367. renderItem.renderOrder = object.renderOrder;
  11368. renderItem.z = z;
  11369. renderItem.group = group;
  11370. }
  11371. renderItemsIndex++;
  11372. return renderItem;
  11373. }
  11374. function push(object, geometry, material, groupOrder, z, group) {
  11375. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11376. (material.transparent === true ? transparent : opaque).push(renderItem);
  11377. }
  11378. function unshift(object, geometry, material, groupOrder, z, group) {
  11379. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11380. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11381. }
  11382. function sort(customOpaqueSort, customTransparentSort) {
  11383. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11384. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11385. }
  11386. function finish() {
  11387. // Clear references from inactive renderItems in the list
  11388. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11389. var renderItem = renderItems[i];
  11390. if (renderItem.id === null) break;
  11391. renderItem.id = null;
  11392. renderItem.object = null;
  11393. renderItem.geometry = null;
  11394. renderItem.material = null;
  11395. renderItem.program = null;
  11396. renderItem.group = null;
  11397. }
  11398. }
  11399. return {
  11400. opaque: opaque,
  11401. transparent: transparent,
  11402. init: init,
  11403. push: push,
  11404. unshift: unshift,
  11405. finish: finish,
  11406. sort: sort
  11407. };
  11408. }
  11409. function WebGLRenderLists(properties) {
  11410. var lists = new WeakMap();
  11411. function get(scene, camera) {
  11412. var cameras = lists.get(scene);
  11413. var list;
  11414. if (cameras === undefined) {
  11415. list = new WebGLRenderList(properties);
  11416. lists.set(scene, new WeakMap());
  11417. lists.get(scene).set(camera, list);
  11418. } else {
  11419. list = cameras.get(camera);
  11420. if (list === undefined) {
  11421. list = new WebGLRenderList(properties);
  11422. cameras.set(camera, list);
  11423. }
  11424. }
  11425. return list;
  11426. }
  11427. function dispose() {
  11428. lists = new WeakMap();
  11429. }
  11430. return {
  11431. get: get,
  11432. dispose: dispose
  11433. };
  11434. }
  11435. function UniformsCache() {
  11436. var lights = {};
  11437. return {
  11438. get: function get(light) {
  11439. if (lights[light.id] !== undefined) {
  11440. return lights[light.id];
  11441. }
  11442. var uniforms;
  11443. switch (light.type) {
  11444. case 'DirectionalLight':
  11445. uniforms = {
  11446. direction: new Vector3(),
  11447. color: new Color()
  11448. };
  11449. break;
  11450. case 'SpotLight':
  11451. uniforms = {
  11452. position: new Vector3(),
  11453. direction: new Vector3(),
  11454. color: new Color(),
  11455. distance: 0,
  11456. coneCos: 0,
  11457. penumbraCos: 0,
  11458. decay: 0
  11459. };
  11460. break;
  11461. case 'PointLight':
  11462. uniforms = {
  11463. position: new Vector3(),
  11464. color: new Color(),
  11465. distance: 0,
  11466. decay: 0
  11467. };
  11468. break;
  11469. case 'HemisphereLight':
  11470. uniforms = {
  11471. direction: new Vector3(),
  11472. skyColor: new Color(),
  11473. groundColor: new Color()
  11474. };
  11475. break;
  11476. case 'RectAreaLight':
  11477. uniforms = {
  11478. color: new Color(),
  11479. position: new Vector3(),
  11480. halfWidth: new Vector3(),
  11481. halfHeight: new Vector3()
  11482. };
  11483. break;
  11484. }
  11485. lights[light.id] = uniforms;
  11486. return uniforms;
  11487. }
  11488. };
  11489. }
  11490. function ShadowUniformsCache() {
  11491. var lights = {};
  11492. return {
  11493. get: function get(light) {
  11494. if (lights[light.id] !== undefined) {
  11495. return lights[light.id];
  11496. }
  11497. var uniforms;
  11498. switch (light.type) {
  11499. case 'DirectionalLight':
  11500. uniforms = {
  11501. shadowBias: 0,
  11502. shadowNormalBias: 0,
  11503. shadowRadius: 1,
  11504. shadowMapSize: new Vector2()
  11505. };
  11506. break;
  11507. case 'SpotLight':
  11508. uniforms = {
  11509. shadowBias: 0,
  11510. shadowNormalBias: 0,
  11511. shadowRadius: 1,
  11512. shadowMapSize: new Vector2()
  11513. };
  11514. break;
  11515. case 'PointLight':
  11516. uniforms = {
  11517. shadowBias: 0,
  11518. shadowNormalBias: 0,
  11519. shadowRadius: 1,
  11520. shadowMapSize: new Vector2(),
  11521. shadowCameraNear: 1,
  11522. shadowCameraFar: 1000
  11523. };
  11524. break;
  11525. // TODO (abelnation): set RectAreaLight shadow uniforms
  11526. }
  11527. lights[light.id] = uniforms;
  11528. return uniforms;
  11529. }
  11530. };
  11531. }
  11532. var nextVersion = 0;
  11533. function shadowCastingLightsFirst(lightA, lightB) {
  11534. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11535. }
  11536. function WebGLLights(extensions, capabilities) {
  11537. var cache = new UniformsCache();
  11538. var shadowCache = ShadowUniformsCache();
  11539. var state = {
  11540. version: 0,
  11541. hash: {
  11542. directionalLength: -1,
  11543. pointLength: -1,
  11544. spotLength: -1,
  11545. rectAreaLength: -1,
  11546. hemiLength: -1,
  11547. numDirectionalShadows: -1,
  11548. numPointShadows: -1,
  11549. numSpotShadows: -1
  11550. },
  11551. ambient: [0, 0, 0],
  11552. probe: [],
  11553. directional: [],
  11554. directionalShadow: [],
  11555. directionalShadowMap: [],
  11556. directionalShadowMatrix: [],
  11557. spot: [],
  11558. spotShadow: [],
  11559. spotShadowMap: [],
  11560. spotShadowMatrix: [],
  11561. rectArea: [],
  11562. rectAreaLTC1: null,
  11563. rectAreaLTC2: null,
  11564. point: [],
  11565. pointShadow: [],
  11566. pointShadowMap: [],
  11567. pointShadowMatrix: [],
  11568. hemi: []
  11569. };
  11570. for (var i = 0; i < 9; i++) {
  11571. state.probe.push(new Vector3());
  11572. }
  11573. var vector3 = new Vector3();
  11574. var matrix4 = new Matrix4();
  11575. var matrix42 = new Matrix4();
  11576. function setup(lights, shadows, camera) {
  11577. var r = 0,
  11578. g = 0,
  11579. b = 0;
  11580. for (var _i = 0; _i < 9; _i++) {
  11581. state.probe[_i].set(0, 0, 0);
  11582. }
  11583. var directionalLength = 0;
  11584. var pointLength = 0;
  11585. var spotLength = 0;
  11586. var rectAreaLength = 0;
  11587. var hemiLength = 0;
  11588. var numDirectionalShadows = 0;
  11589. var numPointShadows = 0;
  11590. var numSpotShadows = 0;
  11591. var viewMatrix = camera.matrixWorldInverse;
  11592. lights.sort(shadowCastingLightsFirst);
  11593. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11594. var light = lights[_i2];
  11595. var color = light.color;
  11596. var intensity = light.intensity;
  11597. var distance = light.distance;
  11598. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11599. if (light.isAmbientLight) {
  11600. r += color.r * intensity;
  11601. g += color.g * intensity;
  11602. b += color.b * intensity;
  11603. } else if (light.isLightProbe) {
  11604. for (var j = 0; j < 9; j++) {
  11605. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11606. }
  11607. } else if (light.isDirectionalLight) {
  11608. var uniforms = cache.get(light);
  11609. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11610. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11611. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11612. uniforms.direction.sub(vector3);
  11613. uniforms.direction.transformDirection(viewMatrix);
  11614. if (light.castShadow) {
  11615. var shadow = light.shadow;
  11616. var shadowUniforms = shadowCache.get(light);
  11617. shadowUniforms.shadowBias = shadow.bias;
  11618. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11619. shadowUniforms.shadowRadius = shadow.radius;
  11620. shadowUniforms.shadowMapSize = shadow.mapSize;
  11621. state.directionalShadow[directionalLength] = shadowUniforms;
  11622. state.directionalShadowMap[directionalLength] = shadowMap;
  11623. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11624. numDirectionalShadows++;
  11625. }
  11626. state.directional[directionalLength] = uniforms;
  11627. directionalLength++;
  11628. } else if (light.isSpotLight) {
  11629. var _uniforms = cache.get(light);
  11630. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11631. _uniforms.position.applyMatrix4(viewMatrix);
  11632. _uniforms.color.copy(color).multiplyScalar(intensity);
  11633. _uniforms.distance = distance;
  11634. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11635. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11636. _uniforms.direction.sub(vector3);
  11637. _uniforms.direction.transformDirection(viewMatrix);
  11638. _uniforms.coneCos = Math.cos(light.angle);
  11639. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11640. _uniforms.decay = light.decay;
  11641. if (light.castShadow) {
  11642. var _shadow = light.shadow;
  11643. var _shadowUniforms = shadowCache.get(light);
  11644. _shadowUniforms.shadowBias = _shadow.bias;
  11645. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11646. _shadowUniforms.shadowRadius = _shadow.radius;
  11647. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11648. state.spotShadow[spotLength] = _shadowUniforms;
  11649. state.spotShadowMap[spotLength] = shadowMap;
  11650. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11651. numSpotShadows++;
  11652. }
  11653. state.spot[spotLength] = _uniforms;
  11654. spotLength++;
  11655. } else if (light.isRectAreaLight) {
  11656. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11657. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11658. // (b) intensity is the brightness of the light
  11659. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11660. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11661. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11662. matrix42.identity();
  11663. matrix4.copy(light.matrixWorld);
  11664. matrix4.premultiply(viewMatrix);
  11665. matrix42.extractRotation(matrix4);
  11666. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11667. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11668. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11669. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11670. // uniforms.distance = distance;
  11671. state.rectArea[rectAreaLength] = _uniforms2;
  11672. rectAreaLength++;
  11673. } else if (light.isPointLight) {
  11674. var _uniforms3 = cache.get(light);
  11675. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11676. _uniforms3.position.applyMatrix4(viewMatrix);
  11677. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11678. _uniforms3.distance = light.distance;
  11679. _uniforms3.decay = light.decay;
  11680. if (light.castShadow) {
  11681. var _shadow2 = light.shadow;
  11682. var _shadowUniforms2 = shadowCache.get(light);
  11683. _shadowUniforms2.shadowBias = _shadow2.bias;
  11684. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11685. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11686. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11687. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11688. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11689. state.pointShadow[pointLength] = _shadowUniforms2;
  11690. state.pointShadowMap[pointLength] = shadowMap;
  11691. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11692. numPointShadows++;
  11693. }
  11694. state.point[pointLength] = _uniforms3;
  11695. pointLength++;
  11696. } else if (light.isHemisphereLight) {
  11697. var _uniforms4 = cache.get(light);
  11698. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11699. _uniforms4.direction.transformDirection(viewMatrix);
  11700. _uniforms4.direction.normalize();
  11701. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11702. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11703. state.hemi[hemiLength] = _uniforms4;
  11704. hemiLength++;
  11705. }
  11706. }
  11707. if (rectAreaLength > 0) {
  11708. if (capabilities.isWebGL2) {
  11709. // WebGL 2
  11710. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11711. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11712. } else {
  11713. // WebGL 1
  11714. if (extensions.has('OES_texture_float_linear') === true) {
  11715. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11716. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11717. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11718. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11719. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11720. } else {
  11721. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11722. }
  11723. }
  11724. }
  11725. state.ambient[0] = r;
  11726. state.ambient[1] = g;
  11727. state.ambient[2] = b;
  11728. var hash = state.hash;
  11729. 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) {
  11730. state.directional.length = directionalLength;
  11731. state.spot.length = spotLength;
  11732. state.rectArea.length = rectAreaLength;
  11733. state.point.length = pointLength;
  11734. state.hemi.length = hemiLength;
  11735. state.directionalShadow.length = numDirectionalShadows;
  11736. state.directionalShadowMap.length = numDirectionalShadows;
  11737. state.pointShadow.length = numPointShadows;
  11738. state.pointShadowMap.length = numPointShadows;
  11739. state.spotShadow.length = numSpotShadows;
  11740. state.spotShadowMap.length = numSpotShadows;
  11741. state.directionalShadowMatrix.length = numDirectionalShadows;
  11742. state.pointShadowMatrix.length = numPointShadows;
  11743. state.spotShadowMatrix.length = numSpotShadows;
  11744. hash.directionalLength = directionalLength;
  11745. hash.pointLength = pointLength;
  11746. hash.spotLength = spotLength;
  11747. hash.rectAreaLength = rectAreaLength;
  11748. hash.hemiLength = hemiLength;
  11749. hash.numDirectionalShadows = numDirectionalShadows;
  11750. hash.numPointShadows = numPointShadows;
  11751. hash.numSpotShadows = numSpotShadows;
  11752. state.version = nextVersion++;
  11753. }
  11754. }
  11755. return {
  11756. setup: setup,
  11757. state: state
  11758. };
  11759. }
  11760. function WebGLRenderState(extensions, capabilities) {
  11761. var lights = new WebGLLights(extensions, capabilities);
  11762. var lightsArray = [];
  11763. var shadowsArray = [];
  11764. function init() {
  11765. lightsArray.length = 0;
  11766. shadowsArray.length = 0;
  11767. }
  11768. function pushLight(light) {
  11769. lightsArray.push(light);
  11770. }
  11771. function pushShadow(shadowLight) {
  11772. shadowsArray.push(shadowLight);
  11773. }
  11774. function setupLights(camera) {
  11775. lights.setup(lightsArray, shadowsArray, camera);
  11776. }
  11777. var state = {
  11778. lightsArray: lightsArray,
  11779. shadowsArray: shadowsArray,
  11780. lights: lights
  11781. };
  11782. return {
  11783. init: init,
  11784. state: state,
  11785. setupLights: setupLights,
  11786. pushLight: pushLight,
  11787. pushShadow: pushShadow
  11788. };
  11789. }
  11790. function WebGLRenderStates(extensions, capabilities) {
  11791. var renderStates = new WeakMap();
  11792. function get(scene, camera) {
  11793. var renderState;
  11794. if (renderStates.has(scene) === false) {
  11795. renderState = new WebGLRenderState(extensions, capabilities);
  11796. renderStates.set(scene, new WeakMap());
  11797. renderStates.get(scene).set(camera, renderState);
  11798. } else {
  11799. if (renderStates.get(scene).has(camera) === false) {
  11800. renderState = new WebGLRenderState(extensions, capabilities);
  11801. renderStates.get(scene).set(camera, renderState);
  11802. } else {
  11803. renderState = renderStates.get(scene).get(camera);
  11804. }
  11805. }
  11806. return renderState;
  11807. }
  11808. function dispose() {
  11809. renderStates = new WeakMap();
  11810. }
  11811. return {
  11812. get: get,
  11813. dispose: dispose
  11814. };
  11815. }
  11816. /**
  11817. * parameters = {
  11818. *
  11819. * opacity: <float>,
  11820. *
  11821. * map: new THREE.Texture( <Image> ),
  11822. *
  11823. * alphaMap: new THREE.Texture( <Image> ),
  11824. *
  11825. * displacementMap: new THREE.Texture( <Image> ),
  11826. * displacementScale: <float>,
  11827. * displacementBias: <float>,
  11828. *
  11829. * wireframe: <boolean>,
  11830. * wireframeLinewidth: <float>
  11831. * }
  11832. */
  11833. function MeshDepthMaterial(parameters) {
  11834. Material.call(this);
  11835. this.type = 'MeshDepthMaterial';
  11836. this.depthPacking = BasicDepthPacking;
  11837. this.skinning = false;
  11838. this.morphTargets = false;
  11839. this.map = null;
  11840. this.alphaMap = null;
  11841. this.displacementMap = null;
  11842. this.displacementScale = 1;
  11843. this.displacementBias = 0;
  11844. this.wireframe = false;
  11845. this.wireframeLinewidth = 1;
  11846. this.fog = false;
  11847. this.setValues(parameters);
  11848. }
  11849. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11850. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11851. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11852. MeshDepthMaterial.prototype.copy = function (source) {
  11853. Material.prototype.copy.call(this, source);
  11854. this.depthPacking = source.depthPacking;
  11855. this.skinning = source.skinning;
  11856. this.morphTargets = source.morphTargets;
  11857. this.map = source.map;
  11858. this.alphaMap = source.alphaMap;
  11859. this.displacementMap = source.displacementMap;
  11860. this.displacementScale = source.displacementScale;
  11861. this.displacementBias = source.displacementBias;
  11862. this.wireframe = source.wireframe;
  11863. this.wireframeLinewidth = source.wireframeLinewidth;
  11864. return this;
  11865. };
  11866. /**
  11867. * parameters = {
  11868. *
  11869. * referencePosition: <float>,
  11870. * nearDistance: <float>,
  11871. * farDistance: <float>,
  11872. *
  11873. * skinning: <bool>,
  11874. * morphTargets: <bool>,
  11875. *
  11876. * map: new THREE.Texture( <Image> ),
  11877. *
  11878. * alphaMap: new THREE.Texture( <Image> ),
  11879. *
  11880. * displacementMap: new THREE.Texture( <Image> ),
  11881. * displacementScale: <float>,
  11882. * displacementBias: <float>
  11883. *
  11884. * }
  11885. */
  11886. function MeshDistanceMaterial(parameters) {
  11887. Material.call(this);
  11888. this.type = 'MeshDistanceMaterial';
  11889. this.referencePosition = new Vector3();
  11890. this.nearDistance = 1;
  11891. this.farDistance = 1000;
  11892. this.skinning = false;
  11893. this.morphTargets = false;
  11894. this.map = null;
  11895. this.alphaMap = null;
  11896. this.displacementMap = null;
  11897. this.displacementScale = 1;
  11898. this.displacementBias = 0;
  11899. this.fog = false;
  11900. this.setValues(parameters);
  11901. }
  11902. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11903. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11904. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11905. MeshDistanceMaterial.prototype.copy = function (source) {
  11906. Material.prototype.copy.call(this, source);
  11907. this.referencePosition.copy(source.referencePosition);
  11908. this.nearDistance = source.nearDistance;
  11909. this.farDistance = source.farDistance;
  11910. this.skinning = source.skinning;
  11911. this.morphTargets = source.morphTargets;
  11912. this.map = source.map;
  11913. this.alphaMap = source.alphaMap;
  11914. this.displacementMap = source.displacementMap;
  11915. this.displacementScale = source.displacementScale;
  11916. this.displacementBias = source.displacementBias;
  11917. return this;
  11918. };
  11919. 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}";
  11920. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11921. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11922. var _frustum = new Frustum();
  11923. var _shadowMapSize = new Vector2(),
  11924. _viewportSize = new Vector2(),
  11925. _viewport = new Vector4(),
  11926. _depthMaterials = [],
  11927. _distanceMaterials = [],
  11928. _materialCache = {};
  11929. var shadowSide = {
  11930. 0: BackSide,
  11931. 1: FrontSide,
  11932. 2: DoubleSide
  11933. };
  11934. var shadowMaterialVertical = new ShaderMaterial({
  11935. defines: {
  11936. SAMPLE_RATE: 2.0 / 8.0,
  11937. HALF_SAMPLE_RATE: 1.0 / 8.0
  11938. },
  11939. uniforms: {
  11940. shadow_pass: {
  11941. value: null
  11942. },
  11943. resolution: {
  11944. value: new Vector2()
  11945. },
  11946. radius: {
  11947. value: 4.0
  11948. }
  11949. },
  11950. vertexShader: vsm_vert,
  11951. fragmentShader: vsm_frag
  11952. });
  11953. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11954. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11955. var fullScreenTri = new BufferGeometry();
  11956. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11957. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11958. var scope = this;
  11959. this.enabled = false;
  11960. this.autoUpdate = true;
  11961. this.needsUpdate = false;
  11962. this.type = PCFShadowMap;
  11963. this.render = function (lights, scene, camera) {
  11964. if (scope.enabled === false) return;
  11965. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11966. if (lights.length === 0) return;
  11967. var currentRenderTarget = _renderer.getRenderTarget();
  11968. var activeCubeFace = _renderer.getActiveCubeFace();
  11969. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11970. var _state = _renderer.state; // Set GL state for depth map.
  11971. _state.setBlending(NoBlending);
  11972. _state.buffers.color.setClear(1, 1, 1, 1);
  11973. _state.buffers.depth.setTest(true);
  11974. _state.setScissorTest(false); // render depth map
  11975. for (var i = 0, il = lights.length; i < il; i++) {
  11976. var light = lights[i];
  11977. var shadow = light.shadow;
  11978. if (shadow === undefined) {
  11979. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11980. continue;
  11981. }
  11982. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11983. _shadowMapSize.copy(shadow.mapSize);
  11984. var shadowFrameExtents = shadow.getFrameExtents();
  11985. _shadowMapSize.multiply(shadowFrameExtents);
  11986. _viewportSize.copy(shadow.mapSize);
  11987. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11988. if (_shadowMapSize.x > maxTextureSize) {
  11989. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11990. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11991. shadow.mapSize.x = _viewportSize.x;
  11992. }
  11993. if (_shadowMapSize.y > maxTextureSize) {
  11994. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11995. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11996. shadow.mapSize.y = _viewportSize.y;
  11997. }
  11998. }
  11999. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12000. var pars = {
  12001. minFilter: LinearFilter,
  12002. magFilter: LinearFilter,
  12003. format: RGBAFormat
  12004. };
  12005. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12006. shadow.map.texture.name = light.name + ".shadowMap";
  12007. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12008. shadow.camera.updateProjectionMatrix();
  12009. }
  12010. if (shadow.map === null) {
  12011. var _pars = {
  12012. minFilter: NearestFilter,
  12013. magFilter: NearestFilter,
  12014. format: RGBAFormat
  12015. };
  12016. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12017. shadow.map.texture.name = light.name + ".shadowMap";
  12018. shadow.camera.updateProjectionMatrix();
  12019. }
  12020. _renderer.setRenderTarget(shadow.map);
  12021. _renderer.clear();
  12022. var viewportCount = shadow.getViewportCount();
  12023. for (var vp = 0; vp < viewportCount; vp++) {
  12024. var viewport = shadow.getViewport(vp);
  12025. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12026. _state.viewport(_viewport);
  12027. shadow.updateMatrices(light, vp);
  12028. _frustum = shadow.getFrustum();
  12029. renderObject(scene, camera, shadow.camera, light, this.type);
  12030. } // do blur pass for VSM
  12031. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12032. VSMPass(shadow, camera);
  12033. }
  12034. shadow.needsUpdate = false;
  12035. }
  12036. scope.needsUpdate = false;
  12037. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12038. };
  12039. function VSMPass(shadow, camera) {
  12040. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12041. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12042. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12043. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12044. _renderer.setRenderTarget(shadow.mapPass);
  12045. _renderer.clear();
  12046. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  12047. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12048. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  12049. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  12050. _renderer.setRenderTarget(shadow.map);
  12051. _renderer.clear();
  12052. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  12053. }
  12054. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12055. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12056. var material = _depthMaterials[index];
  12057. if (material === undefined) {
  12058. material = new MeshDepthMaterial({
  12059. depthPacking: RGBADepthPacking,
  12060. morphTargets: useMorphing,
  12061. skinning: useSkinning
  12062. });
  12063. _depthMaterials[index] = material;
  12064. }
  12065. return material;
  12066. }
  12067. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12068. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12069. var material = _distanceMaterials[index];
  12070. if (material === undefined) {
  12071. material = new MeshDistanceMaterial({
  12072. morphTargets: useMorphing,
  12073. skinning: useSkinning
  12074. });
  12075. _distanceMaterials[index] = material;
  12076. }
  12077. return material;
  12078. }
  12079. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12080. var result = null;
  12081. var getMaterialVariant = getDepthMaterialVariant;
  12082. var customMaterial = object.customDepthMaterial;
  12083. if (light.isPointLight === true) {
  12084. getMaterialVariant = getDistanceMaterialVariant;
  12085. customMaterial = object.customDistanceMaterial;
  12086. }
  12087. if (customMaterial === undefined) {
  12088. var useMorphing = false;
  12089. if (material.morphTargets === true) {
  12090. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12091. }
  12092. var useSkinning = false;
  12093. if (object.isSkinnedMesh === true) {
  12094. if (material.skinning === true) {
  12095. useSkinning = true;
  12096. } else {
  12097. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12098. }
  12099. }
  12100. var useInstancing = object.isInstancedMesh === true;
  12101. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12102. } else {
  12103. result = customMaterial;
  12104. }
  12105. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12106. // in this case we need a unique material instance reflecting the
  12107. // appropriate state
  12108. var keyA = result.uuid,
  12109. keyB = material.uuid;
  12110. var materialsForVariant = _materialCache[keyA];
  12111. if (materialsForVariant === undefined) {
  12112. materialsForVariant = {};
  12113. _materialCache[keyA] = materialsForVariant;
  12114. }
  12115. var cachedMaterial = materialsForVariant[keyB];
  12116. if (cachedMaterial === undefined) {
  12117. cachedMaterial = result.clone();
  12118. materialsForVariant[keyB] = cachedMaterial;
  12119. }
  12120. result = cachedMaterial;
  12121. }
  12122. result.visible = material.visible;
  12123. result.wireframe = material.wireframe;
  12124. if (type === VSMShadowMap) {
  12125. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12126. } else {
  12127. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12128. }
  12129. result.clipShadows = material.clipShadows;
  12130. result.clippingPlanes = material.clippingPlanes;
  12131. result.clipIntersection = material.clipIntersection;
  12132. result.wireframeLinewidth = material.wireframeLinewidth;
  12133. result.linewidth = material.linewidth;
  12134. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12135. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12136. result.nearDistance = shadowCameraNear;
  12137. result.farDistance = shadowCameraFar;
  12138. }
  12139. return result;
  12140. }
  12141. function renderObject(object, camera, shadowCamera, light, type) {
  12142. if (object.visible === false) return;
  12143. var visible = object.layers.test(camera.layers);
  12144. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12145. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12146. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12147. var geometry = _objects.update(object);
  12148. var material = object.material;
  12149. if (Array.isArray(material)) {
  12150. var groups = geometry.groups;
  12151. for (var k = 0, kl = groups.length; k < kl; k++) {
  12152. var group = groups[k];
  12153. var groupMaterial = material[group.materialIndex];
  12154. if (groupMaterial && groupMaterial.visible) {
  12155. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12156. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12157. }
  12158. }
  12159. } else if (material.visible) {
  12160. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12161. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12162. }
  12163. }
  12164. }
  12165. var children = object.children;
  12166. for (var i = 0, l = children.length; i < l; i++) {
  12167. renderObject(children[i], camera, shadowCamera, light, type);
  12168. }
  12169. }
  12170. }
  12171. function WebGLState(gl, extensions, capabilities) {
  12172. var _equationToGL, _factorToGL;
  12173. var isWebGL2 = capabilities.isWebGL2;
  12174. function ColorBuffer() {
  12175. var locked = false;
  12176. var color = new Vector4();
  12177. var currentColorMask = null;
  12178. var currentColorClear = new Vector4(0, 0, 0, 0);
  12179. return {
  12180. setMask: function setMask(colorMask) {
  12181. if (currentColorMask !== colorMask && !locked) {
  12182. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12183. currentColorMask = colorMask;
  12184. }
  12185. },
  12186. setLocked: function setLocked(lock) {
  12187. locked = lock;
  12188. },
  12189. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12190. if (premultipliedAlpha === true) {
  12191. r *= a;
  12192. g *= a;
  12193. b *= a;
  12194. }
  12195. color.set(r, g, b, a);
  12196. if (currentColorClear.equals(color) === false) {
  12197. gl.clearColor(r, g, b, a);
  12198. currentColorClear.copy(color);
  12199. }
  12200. },
  12201. reset: function reset() {
  12202. locked = false;
  12203. currentColorMask = null;
  12204. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12205. }
  12206. };
  12207. }
  12208. function DepthBuffer() {
  12209. var locked = false;
  12210. var currentDepthMask = null;
  12211. var currentDepthFunc = null;
  12212. var currentDepthClear = null;
  12213. return {
  12214. setTest: function setTest(depthTest) {
  12215. if (depthTest) {
  12216. enable(2929);
  12217. } else {
  12218. disable(2929);
  12219. }
  12220. },
  12221. setMask: function setMask(depthMask) {
  12222. if (currentDepthMask !== depthMask && !locked) {
  12223. gl.depthMask(depthMask);
  12224. currentDepthMask = depthMask;
  12225. }
  12226. },
  12227. setFunc: function setFunc(depthFunc) {
  12228. if (currentDepthFunc !== depthFunc) {
  12229. if (depthFunc) {
  12230. switch (depthFunc) {
  12231. case NeverDepth:
  12232. gl.depthFunc(512);
  12233. break;
  12234. case AlwaysDepth:
  12235. gl.depthFunc(519);
  12236. break;
  12237. case LessDepth:
  12238. gl.depthFunc(513);
  12239. break;
  12240. case LessEqualDepth:
  12241. gl.depthFunc(515);
  12242. break;
  12243. case EqualDepth:
  12244. gl.depthFunc(514);
  12245. break;
  12246. case GreaterEqualDepth:
  12247. gl.depthFunc(518);
  12248. break;
  12249. case GreaterDepth:
  12250. gl.depthFunc(516);
  12251. break;
  12252. case NotEqualDepth:
  12253. gl.depthFunc(517);
  12254. break;
  12255. default:
  12256. gl.depthFunc(515);
  12257. }
  12258. } else {
  12259. gl.depthFunc(515);
  12260. }
  12261. currentDepthFunc = depthFunc;
  12262. }
  12263. },
  12264. setLocked: function setLocked(lock) {
  12265. locked = lock;
  12266. },
  12267. setClear: function setClear(depth) {
  12268. if (currentDepthClear !== depth) {
  12269. gl.clearDepth(depth);
  12270. currentDepthClear = depth;
  12271. }
  12272. },
  12273. reset: function reset() {
  12274. locked = false;
  12275. currentDepthMask = null;
  12276. currentDepthFunc = null;
  12277. currentDepthClear = null;
  12278. }
  12279. };
  12280. }
  12281. function StencilBuffer() {
  12282. var locked = false;
  12283. var currentStencilMask = null;
  12284. var currentStencilFunc = null;
  12285. var currentStencilRef = null;
  12286. var currentStencilFuncMask = null;
  12287. var currentStencilFail = null;
  12288. var currentStencilZFail = null;
  12289. var currentStencilZPass = null;
  12290. var currentStencilClear = null;
  12291. return {
  12292. setTest: function setTest(stencilTest) {
  12293. if (!locked) {
  12294. if (stencilTest) {
  12295. enable(2960);
  12296. } else {
  12297. disable(2960);
  12298. }
  12299. }
  12300. },
  12301. setMask: function setMask(stencilMask) {
  12302. if (currentStencilMask !== stencilMask && !locked) {
  12303. gl.stencilMask(stencilMask);
  12304. currentStencilMask = stencilMask;
  12305. }
  12306. },
  12307. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12308. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12309. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12310. currentStencilFunc = stencilFunc;
  12311. currentStencilRef = stencilRef;
  12312. currentStencilFuncMask = stencilMask;
  12313. }
  12314. },
  12315. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12316. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12317. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12318. currentStencilFail = stencilFail;
  12319. currentStencilZFail = stencilZFail;
  12320. currentStencilZPass = stencilZPass;
  12321. }
  12322. },
  12323. setLocked: function setLocked(lock) {
  12324. locked = lock;
  12325. },
  12326. setClear: function setClear(stencil) {
  12327. if (currentStencilClear !== stencil) {
  12328. gl.clearStencil(stencil);
  12329. currentStencilClear = stencil;
  12330. }
  12331. },
  12332. reset: function reset() {
  12333. locked = false;
  12334. currentStencilMask = null;
  12335. currentStencilFunc = null;
  12336. currentStencilRef = null;
  12337. currentStencilFuncMask = null;
  12338. currentStencilFail = null;
  12339. currentStencilZFail = null;
  12340. currentStencilZPass = null;
  12341. currentStencilClear = null;
  12342. }
  12343. };
  12344. } //
  12345. var colorBuffer = new ColorBuffer();
  12346. var depthBuffer = new DepthBuffer();
  12347. var stencilBuffer = new StencilBuffer();
  12348. var enabledCapabilities = {};
  12349. var currentProgram = null;
  12350. var currentBlendingEnabled = null;
  12351. var currentBlending = null;
  12352. var currentBlendEquation = null;
  12353. var currentBlendSrc = null;
  12354. var currentBlendDst = null;
  12355. var currentBlendEquationAlpha = null;
  12356. var currentBlendSrcAlpha = null;
  12357. var currentBlendDstAlpha = null;
  12358. var currentPremultipledAlpha = false;
  12359. var currentFlipSided = null;
  12360. var currentCullFace = null;
  12361. var currentLineWidth = null;
  12362. var currentPolygonOffsetFactor = null;
  12363. var currentPolygonOffsetUnits = null;
  12364. var maxTextures = gl.getParameter(35661);
  12365. var lineWidthAvailable = false;
  12366. var version = 0;
  12367. var glVersion = gl.getParameter(7938);
  12368. if (glVersion.indexOf('WebGL') !== -1) {
  12369. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12370. lineWidthAvailable = version >= 1.0;
  12371. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12372. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12373. lineWidthAvailable = version >= 2.0;
  12374. }
  12375. var currentTextureSlot = null;
  12376. var currentBoundTextures = {};
  12377. var currentScissor = new Vector4();
  12378. var currentViewport = new Vector4();
  12379. function createTexture(type, target, count) {
  12380. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12381. var texture = gl.createTexture();
  12382. gl.bindTexture(type, texture);
  12383. gl.texParameteri(type, 10241, 9728);
  12384. gl.texParameteri(type, 10240, 9728);
  12385. for (var i = 0; i < count; i++) {
  12386. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12387. }
  12388. return texture;
  12389. }
  12390. var emptyTextures = {};
  12391. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12392. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12393. colorBuffer.setClear(0, 0, 0, 1);
  12394. depthBuffer.setClear(1);
  12395. stencilBuffer.setClear(0);
  12396. enable(2929);
  12397. depthBuffer.setFunc(LessEqualDepth);
  12398. setFlipSided(false);
  12399. setCullFace(CullFaceBack);
  12400. enable(2884);
  12401. setBlending(NoBlending); //
  12402. function enable(id) {
  12403. if (enabledCapabilities[id] !== true) {
  12404. gl.enable(id);
  12405. enabledCapabilities[id] = true;
  12406. }
  12407. }
  12408. function disable(id) {
  12409. if (enabledCapabilities[id] !== false) {
  12410. gl.disable(id);
  12411. enabledCapabilities[id] = false;
  12412. }
  12413. }
  12414. function useProgram(program) {
  12415. if (currentProgram !== program) {
  12416. gl.useProgram(program);
  12417. currentProgram = program;
  12418. return true;
  12419. }
  12420. return false;
  12421. }
  12422. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12423. if (isWebGL2) {
  12424. equationToGL[MinEquation] = 32775;
  12425. equationToGL[MaxEquation] = 32776;
  12426. } else {
  12427. var extension = extensions.get('EXT_blend_minmax');
  12428. if (extension !== null) {
  12429. equationToGL[MinEquation] = extension.MIN_EXT;
  12430. equationToGL[MaxEquation] = extension.MAX_EXT;
  12431. }
  12432. }
  12433. 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);
  12434. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12435. if (blending === NoBlending) {
  12436. if (currentBlendingEnabled) {
  12437. disable(3042);
  12438. currentBlendingEnabled = false;
  12439. }
  12440. return;
  12441. }
  12442. if (!currentBlendingEnabled) {
  12443. enable(3042);
  12444. currentBlendingEnabled = true;
  12445. }
  12446. if (blending !== CustomBlending) {
  12447. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12448. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12449. gl.blendEquation(32774);
  12450. currentBlendEquation = AddEquation;
  12451. currentBlendEquationAlpha = AddEquation;
  12452. }
  12453. if (premultipliedAlpha) {
  12454. switch (blending) {
  12455. case NormalBlending:
  12456. gl.blendFuncSeparate(1, 771, 1, 771);
  12457. break;
  12458. case AdditiveBlending:
  12459. gl.blendFunc(1, 1);
  12460. break;
  12461. case SubtractiveBlending:
  12462. gl.blendFuncSeparate(0, 0, 769, 771);
  12463. break;
  12464. case MultiplyBlending:
  12465. gl.blendFuncSeparate(0, 768, 0, 770);
  12466. break;
  12467. default:
  12468. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12469. break;
  12470. }
  12471. } else {
  12472. switch (blending) {
  12473. case NormalBlending:
  12474. gl.blendFuncSeparate(770, 771, 1, 771);
  12475. break;
  12476. case AdditiveBlending:
  12477. gl.blendFunc(770, 1);
  12478. break;
  12479. case SubtractiveBlending:
  12480. gl.blendFunc(0, 769);
  12481. break;
  12482. case MultiplyBlending:
  12483. gl.blendFunc(0, 768);
  12484. break;
  12485. default:
  12486. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12487. break;
  12488. }
  12489. }
  12490. currentBlendSrc = null;
  12491. currentBlendDst = null;
  12492. currentBlendSrcAlpha = null;
  12493. currentBlendDstAlpha = null;
  12494. currentBlending = blending;
  12495. currentPremultipledAlpha = premultipliedAlpha;
  12496. }
  12497. return;
  12498. } // custom blending
  12499. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12500. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12501. blendDstAlpha = blendDstAlpha || blendDst;
  12502. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12503. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12504. currentBlendEquation = blendEquation;
  12505. currentBlendEquationAlpha = blendEquationAlpha;
  12506. }
  12507. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12508. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12509. currentBlendSrc = blendSrc;
  12510. currentBlendDst = blendDst;
  12511. currentBlendSrcAlpha = blendSrcAlpha;
  12512. currentBlendDstAlpha = blendDstAlpha;
  12513. }
  12514. currentBlending = blending;
  12515. currentPremultipledAlpha = null;
  12516. }
  12517. function setMaterial(material, frontFaceCW) {
  12518. material.side === DoubleSide ? disable(2884) : enable(2884);
  12519. var flipSided = material.side === BackSide;
  12520. if (frontFaceCW) flipSided = !flipSided;
  12521. setFlipSided(flipSided);
  12522. 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);
  12523. depthBuffer.setFunc(material.depthFunc);
  12524. depthBuffer.setTest(material.depthTest);
  12525. depthBuffer.setMask(material.depthWrite);
  12526. colorBuffer.setMask(material.colorWrite);
  12527. var stencilWrite = material.stencilWrite;
  12528. stencilBuffer.setTest(stencilWrite);
  12529. if (stencilWrite) {
  12530. stencilBuffer.setMask(material.stencilWriteMask);
  12531. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12532. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12533. }
  12534. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12535. } //
  12536. function setFlipSided(flipSided) {
  12537. if (currentFlipSided !== flipSided) {
  12538. if (flipSided) {
  12539. gl.frontFace(2304);
  12540. } else {
  12541. gl.frontFace(2305);
  12542. }
  12543. currentFlipSided = flipSided;
  12544. }
  12545. }
  12546. function setCullFace(cullFace) {
  12547. if (cullFace !== CullFaceNone) {
  12548. enable(2884);
  12549. if (cullFace !== currentCullFace) {
  12550. if (cullFace === CullFaceBack) {
  12551. gl.cullFace(1029);
  12552. } else if (cullFace === CullFaceFront) {
  12553. gl.cullFace(1028);
  12554. } else {
  12555. gl.cullFace(1032);
  12556. }
  12557. }
  12558. } else {
  12559. disable(2884);
  12560. }
  12561. currentCullFace = cullFace;
  12562. }
  12563. function setLineWidth(width) {
  12564. if (width !== currentLineWidth) {
  12565. if (lineWidthAvailable) gl.lineWidth(width);
  12566. currentLineWidth = width;
  12567. }
  12568. }
  12569. function setPolygonOffset(polygonOffset, factor, units) {
  12570. if (polygonOffset) {
  12571. enable(32823);
  12572. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12573. gl.polygonOffset(factor, units);
  12574. currentPolygonOffsetFactor = factor;
  12575. currentPolygonOffsetUnits = units;
  12576. }
  12577. } else {
  12578. disable(32823);
  12579. }
  12580. }
  12581. function setScissorTest(scissorTest) {
  12582. if (scissorTest) {
  12583. enable(3089);
  12584. } else {
  12585. disable(3089);
  12586. }
  12587. } // texture
  12588. function activeTexture(webglSlot) {
  12589. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12590. if (currentTextureSlot !== webglSlot) {
  12591. gl.activeTexture(webglSlot);
  12592. currentTextureSlot = webglSlot;
  12593. }
  12594. }
  12595. function bindTexture(webglType, webglTexture) {
  12596. if (currentTextureSlot === null) {
  12597. activeTexture();
  12598. }
  12599. var boundTexture = currentBoundTextures[currentTextureSlot];
  12600. if (boundTexture === undefined) {
  12601. boundTexture = {
  12602. type: undefined,
  12603. texture: undefined
  12604. };
  12605. currentBoundTextures[currentTextureSlot] = boundTexture;
  12606. }
  12607. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12608. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12609. boundTexture.type = webglType;
  12610. boundTexture.texture = webglTexture;
  12611. }
  12612. }
  12613. function unbindTexture() {
  12614. var boundTexture = currentBoundTextures[currentTextureSlot];
  12615. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12616. gl.bindTexture(boundTexture.type, null);
  12617. boundTexture.type = undefined;
  12618. boundTexture.texture = undefined;
  12619. }
  12620. }
  12621. function compressedTexImage2D() {
  12622. try {
  12623. gl.compressedTexImage2D.apply(gl, arguments);
  12624. } catch (error) {
  12625. console.error('THREE.WebGLState:', error);
  12626. }
  12627. }
  12628. function texImage2D() {
  12629. try {
  12630. gl.texImage2D.apply(gl, arguments);
  12631. } catch (error) {
  12632. console.error('THREE.WebGLState:', error);
  12633. }
  12634. }
  12635. function texImage3D() {
  12636. try {
  12637. gl.texImage3D.apply(gl, arguments);
  12638. } catch (error) {
  12639. console.error('THREE.WebGLState:', error);
  12640. }
  12641. } //
  12642. function scissor(scissor) {
  12643. if (currentScissor.equals(scissor) === false) {
  12644. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12645. currentScissor.copy(scissor);
  12646. }
  12647. }
  12648. function viewport(viewport) {
  12649. if (currentViewport.equals(viewport) === false) {
  12650. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12651. currentViewport.copy(viewport);
  12652. }
  12653. } //
  12654. function reset() {
  12655. enabledCapabilities = {};
  12656. currentTextureSlot = null;
  12657. currentBoundTextures = {};
  12658. currentProgram = null;
  12659. currentBlendingEnabled = null;
  12660. currentBlending = null;
  12661. currentBlendEquation = null;
  12662. currentBlendSrc = null;
  12663. currentBlendDst = null;
  12664. currentBlendEquationAlpha = null;
  12665. currentBlendSrcAlpha = null;
  12666. currentBlendDstAlpha = null;
  12667. currentPremultipledAlpha = false;
  12668. currentFlipSided = null;
  12669. currentCullFace = null;
  12670. currentLineWidth = null;
  12671. currentPolygonOffsetFactor = null;
  12672. currentPolygonOffsetUnits = null;
  12673. colorBuffer.reset();
  12674. depthBuffer.reset();
  12675. stencilBuffer.reset();
  12676. }
  12677. return {
  12678. buffers: {
  12679. color: colorBuffer,
  12680. depth: depthBuffer,
  12681. stencil: stencilBuffer
  12682. },
  12683. enable: enable,
  12684. disable: disable,
  12685. useProgram: useProgram,
  12686. setBlending: setBlending,
  12687. setMaterial: setMaterial,
  12688. setFlipSided: setFlipSided,
  12689. setCullFace: setCullFace,
  12690. setLineWidth: setLineWidth,
  12691. setPolygonOffset: setPolygonOffset,
  12692. setScissorTest: setScissorTest,
  12693. activeTexture: activeTexture,
  12694. bindTexture: bindTexture,
  12695. unbindTexture: unbindTexture,
  12696. compressedTexImage2D: compressedTexImage2D,
  12697. texImage2D: texImage2D,
  12698. texImage3D: texImage3D,
  12699. scissor: scissor,
  12700. viewport: viewport,
  12701. reset: reset
  12702. };
  12703. }
  12704. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12705. var _wrappingToGL, _filterToGL;
  12706. var isWebGL2 = capabilities.isWebGL2;
  12707. var maxTextures = capabilities.maxTextures;
  12708. var maxCubemapSize = capabilities.maxCubemapSize;
  12709. var maxTextureSize = capabilities.maxTextureSize;
  12710. var maxSamples = capabilities.maxSamples;
  12711. var _videoTextures = new WeakMap();
  12712. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12713. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12714. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12715. var useOffscreenCanvas = false;
  12716. try {
  12717. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12718. } catch (err) {// Ignore any errors
  12719. }
  12720. function createCanvas(width, height) {
  12721. // Use OffscreenCanvas when available. Specially needed in web workers
  12722. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12723. }
  12724. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12725. var scale = 1; // handle case if texture exceeds max size
  12726. if (image.width > maxSize || image.height > maxSize) {
  12727. scale = maxSize / Math.max(image.width, image.height);
  12728. } // only perform resize if necessary
  12729. if (scale < 1 || needsPowerOfTwo === true) {
  12730. // only perform resize for certain image types
  12731. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12732. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12733. var width = floor(scale * image.width);
  12734. var height = floor(scale * image.height);
  12735. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12736. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12737. canvas.width = width;
  12738. canvas.height = height;
  12739. var context = canvas.getContext('2d');
  12740. context.drawImage(image, 0, 0, width, height);
  12741. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12742. return canvas;
  12743. } else {
  12744. if ('data' in image) {
  12745. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12746. }
  12747. return image;
  12748. }
  12749. }
  12750. return image;
  12751. }
  12752. function isPowerOfTwo(image) {
  12753. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12754. }
  12755. function textureNeedsPowerOfTwo(texture) {
  12756. if (isWebGL2) return false;
  12757. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12758. }
  12759. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12760. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12761. }
  12762. function generateMipmap(target, texture, width, height) {
  12763. _gl.generateMipmap(target);
  12764. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12765. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12766. }
  12767. function getInternalFormat(internalFormatName, glFormat, glType) {
  12768. if (isWebGL2 === false) return glFormat;
  12769. if (internalFormatName !== null) {
  12770. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12771. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12772. }
  12773. var internalFormat = glFormat;
  12774. if (glFormat === 6403) {
  12775. if (glType === 5126) internalFormat = 33326;
  12776. if (glType === 5131) internalFormat = 33325;
  12777. if (glType === 5121) internalFormat = 33321;
  12778. }
  12779. if (glFormat === 6407) {
  12780. if (glType === 5126) internalFormat = 34837;
  12781. if (glType === 5131) internalFormat = 34843;
  12782. if (glType === 5121) internalFormat = 32849;
  12783. }
  12784. if (glFormat === 6408) {
  12785. if (glType === 5126) internalFormat = 34836;
  12786. if (glType === 5131) internalFormat = 34842;
  12787. if (glType === 5121) internalFormat = 32856;
  12788. }
  12789. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12790. extensions.get('EXT_color_buffer_float');
  12791. }
  12792. return internalFormat;
  12793. } // Fallback filters for non-power-of-2 textures
  12794. function filterFallback(f) {
  12795. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12796. return 9728;
  12797. }
  12798. return 9729;
  12799. } //
  12800. function onTextureDispose(event) {
  12801. var texture = event.target;
  12802. texture.removeEventListener('dispose', onTextureDispose);
  12803. deallocateTexture(texture);
  12804. if (texture.isVideoTexture) {
  12805. _videoTextures.delete(texture);
  12806. }
  12807. info.memory.textures--;
  12808. }
  12809. function onRenderTargetDispose(event) {
  12810. var renderTarget = event.target;
  12811. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12812. deallocateRenderTarget(renderTarget);
  12813. info.memory.textures--;
  12814. } //
  12815. function deallocateTexture(texture) {
  12816. var textureProperties = properties.get(texture);
  12817. if (textureProperties.__webglInit === undefined) return;
  12818. _gl.deleteTexture(textureProperties.__webglTexture);
  12819. properties.remove(texture);
  12820. }
  12821. function deallocateRenderTarget(renderTarget) {
  12822. var renderTargetProperties = properties.get(renderTarget);
  12823. var textureProperties = properties.get(renderTarget.texture);
  12824. if (!renderTarget) return;
  12825. if (textureProperties.__webglTexture !== undefined) {
  12826. _gl.deleteTexture(textureProperties.__webglTexture);
  12827. }
  12828. if (renderTarget.depthTexture) {
  12829. renderTarget.depthTexture.dispose();
  12830. }
  12831. if (renderTarget.isWebGLCubeRenderTarget) {
  12832. for (var i = 0; i < 6; i++) {
  12833. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12834. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12835. }
  12836. } else {
  12837. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12838. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12839. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12840. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12841. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12842. }
  12843. properties.remove(renderTarget.texture);
  12844. properties.remove(renderTarget);
  12845. } //
  12846. var textureUnits = 0;
  12847. function resetTextureUnits() {
  12848. textureUnits = 0;
  12849. }
  12850. function allocateTextureUnit() {
  12851. var textureUnit = textureUnits;
  12852. if (textureUnit >= maxTextures) {
  12853. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12854. }
  12855. textureUnits += 1;
  12856. return textureUnit;
  12857. } //
  12858. function setTexture2D(texture, slot) {
  12859. var textureProperties = properties.get(texture);
  12860. if (texture.isVideoTexture) updateVideoTexture(texture);
  12861. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12862. var image = texture.image;
  12863. if (image === undefined) {
  12864. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12865. } else if (image.complete === false) {
  12866. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12867. } else {
  12868. uploadTexture(textureProperties, texture, slot);
  12869. return;
  12870. }
  12871. }
  12872. state.activeTexture(33984 + slot);
  12873. state.bindTexture(3553, textureProperties.__webglTexture);
  12874. }
  12875. function setTexture2DArray(texture, slot) {
  12876. var textureProperties = properties.get(texture);
  12877. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12878. uploadTexture(textureProperties, texture, slot);
  12879. return;
  12880. }
  12881. state.activeTexture(33984 + slot);
  12882. state.bindTexture(35866, textureProperties.__webglTexture);
  12883. }
  12884. function setTexture3D(texture, slot) {
  12885. var textureProperties = properties.get(texture);
  12886. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12887. uploadTexture(textureProperties, texture, slot);
  12888. return;
  12889. }
  12890. state.activeTexture(33984 + slot);
  12891. state.bindTexture(32879, textureProperties.__webglTexture);
  12892. }
  12893. function setTextureCube(texture, slot) {
  12894. var textureProperties = properties.get(texture);
  12895. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12896. uploadCubeTexture(textureProperties, texture, slot);
  12897. return;
  12898. }
  12899. state.activeTexture(33984 + slot);
  12900. state.bindTexture(34067, textureProperties.__webglTexture);
  12901. }
  12902. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12903. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12904. function setTextureParameters(textureType, texture, supportsMips) {
  12905. if (supportsMips) {
  12906. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12907. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12908. if (textureType === 32879 || textureType === 35866) {
  12909. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12910. }
  12911. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12912. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12913. } else {
  12914. _gl.texParameteri(textureType, 10242, 33071);
  12915. _gl.texParameteri(textureType, 10243, 33071);
  12916. if (textureType === 32879 || textureType === 35866) {
  12917. _gl.texParameteri(textureType, 32882, 33071);
  12918. }
  12919. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12920. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12921. }
  12922. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12923. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12924. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12925. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12926. }
  12927. }
  12928. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12929. if (extension) {
  12930. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12931. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12932. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12933. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12934. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12935. }
  12936. }
  12937. }
  12938. function initTexture(textureProperties, texture) {
  12939. if (textureProperties.__webglInit === undefined) {
  12940. textureProperties.__webglInit = true;
  12941. texture.addEventListener('dispose', onTextureDispose);
  12942. textureProperties.__webglTexture = _gl.createTexture();
  12943. info.memory.textures++;
  12944. }
  12945. }
  12946. function uploadTexture(textureProperties, texture, slot) {
  12947. var textureType = 3553;
  12948. if (texture.isDataTexture2DArray) textureType = 35866;
  12949. if (texture.isDataTexture3D) textureType = 32879;
  12950. initTexture(textureProperties, texture);
  12951. state.activeTexture(33984 + slot);
  12952. state.bindTexture(textureType, textureProperties.__webglTexture);
  12953. _gl.pixelStorei(37440, texture.flipY);
  12954. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12955. _gl.pixelStorei(3317, texture.unpackAlignment);
  12956. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12957. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12958. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12959. glFormat = utils.convert(texture.format);
  12960. var glType = utils.convert(texture.type),
  12961. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12962. setTextureParameters(textureType, texture, supportsMips);
  12963. var mipmap;
  12964. var mipmaps = texture.mipmaps;
  12965. if (texture.isDepthTexture) {
  12966. // populate depth texture with dummy data
  12967. glInternalFormat = 6402;
  12968. if (isWebGL2) {
  12969. if (texture.type === FloatType) {
  12970. glInternalFormat = 36012;
  12971. } else if (texture.type === UnsignedIntType) {
  12972. glInternalFormat = 33190;
  12973. } else if (texture.type === UnsignedInt248Type) {
  12974. glInternalFormat = 35056;
  12975. } else {
  12976. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12977. }
  12978. } else {
  12979. if (texture.type === FloatType) {
  12980. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12981. }
  12982. } // validation checks for WebGL 1
  12983. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12984. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12985. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12986. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12987. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12988. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12989. texture.type = UnsignedShortType;
  12990. glType = utils.convert(texture.type);
  12991. }
  12992. }
  12993. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12994. // Depth stencil textures need the DEPTH_STENCIL internal format
  12995. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12996. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12997. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12998. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12999. if (texture.type !== UnsignedInt248Type) {
  13000. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13001. texture.type = UnsignedInt248Type;
  13002. glType = utils.convert(texture.type);
  13003. }
  13004. } //
  13005. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13006. } else if (texture.isDataTexture) {
  13007. // use manually created mipmaps if available
  13008. // if there are no manual mipmaps
  13009. // set 0 level mipmap and then use GL to generate other mipmap levels
  13010. if (mipmaps.length > 0 && supportsMips) {
  13011. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13012. mipmap = mipmaps[i];
  13013. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13014. }
  13015. texture.generateMipmaps = false;
  13016. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13017. } else {
  13018. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13019. textureProperties.__maxMipLevel = 0;
  13020. }
  13021. } else if (texture.isCompressedTexture) {
  13022. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13023. mipmap = mipmaps[_i];
  13024. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13025. if (glFormat !== null) {
  13026. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13027. } else {
  13028. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13029. }
  13030. } else {
  13031. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13032. }
  13033. }
  13034. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13035. } else if (texture.isDataTexture2DArray) {
  13036. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13037. textureProperties.__maxMipLevel = 0;
  13038. } else if (texture.isDataTexture3D) {
  13039. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13040. textureProperties.__maxMipLevel = 0;
  13041. } else {
  13042. // regular Texture (image, video, canvas)
  13043. // use manually created mipmaps if available
  13044. // if there are no manual mipmaps
  13045. // set 0 level mipmap and then use GL to generate other mipmap levels
  13046. if (mipmaps.length > 0 && supportsMips) {
  13047. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13048. mipmap = mipmaps[_i2];
  13049. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13050. }
  13051. texture.generateMipmaps = false;
  13052. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13053. } else {
  13054. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13055. textureProperties.__maxMipLevel = 0;
  13056. }
  13057. }
  13058. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13059. generateMipmap(textureType, texture, image.width, image.height);
  13060. }
  13061. textureProperties.__version = texture.version;
  13062. if (texture.onUpdate) texture.onUpdate(texture);
  13063. }
  13064. function uploadCubeTexture(textureProperties, texture, slot) {
  13065. if (texture.image.length !== 6) return;
  13066. initTexture(textureProperties, texture);
  13067. state.activeTexture(33984 + slot);
  13068. state.bindTexture(34067, textureProperties.__webglTexture);
  13069. _gl.pixelStorei(37440, texture.flipY);
  13070. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13071. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13072. var cubeImage = [];
  13073. for (var i = 0; i < 6; i++) {
  13074. if (!isCompressed && !isDataTexture) {
  13075. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13076. } else {
  13077. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13078. }
  13079. }
  13080. var image = cubeImage[0],
  13081. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13082. glFormat = utils.convert(texture.format),
  13083. glType = utils.convert(texture.type),
  13084. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13085. setTextureParameters(34067, texture, supportsMips);
  13086. var mipmaps;
  13087. if (isCompressed) {
  13088. for (var _i3 = 0; _i3 < 6; _i3++) {
  13089. mipmaps = cubeImage[_i3].mipmaps;
  13090. for (var j = 0; j < mipmaps.length; j++) {
  13091. var mipmap = mipmaps[j];
  13092. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13093. if (glFormat !== null) {
  13094. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13095. } else {
  13096. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13097. }
  13098. } else {
  13099. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13100. }
  13101. }
  13102. }
  13103. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13104. } else {
  13105. mipmaps = texture.mipmaps;
  13106. for (var _i4 = 0; _i4 < 6; _i4++) {
  13107. if (isDataTexture) {
  13108. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13109. for (var _j = 0; _j < mipmaps.length; _j++) {
  13110. var _mipmap = mipmaps[_j];
  13111. var mipmapImage = _mipmap.image[_i4].image;
  13112. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13113. }
  13114. } else {
  13115. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13116. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13117. var _mipmap2 = mipmaps[_j2];
  13118. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13119. }
  13120. }
  13121. }
  13122. textureProperties.__maxMipLevel = mipmaps.length;
  13123. }
  13124. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13125. // We assume images for cube map have the same size.
  13126. generateMipmap(34067, texture, image.width, image.height);
  13127. }
  13128. textureProperties.__version = texture.version;
  13129. if (texture.onUpdate) texture.onUpdate(texture);
  13130. } // Render targets
  13131. // Setup storage for target texture and bind it to correct framebuffer
  13132. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13133. var glFormat = utils.convert(renderTarget.texture.format);
  13134. var glType = utils.convert(renderTarget.texture.type);
  13135. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13136. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13137. _gl.bindFramebuffer(36160, framebuffer);
  13138. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13139. _gl.bindFramebuffer(36160, null);
  13140. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13141. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13142. _gl.bindRenderbuffer(36161, renderbuffer);
  13143. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13144. var glInternalFormat = 33189;
  13145. if (isMultisample) {
  13146. var depthTexture = renderTarget.depthTexture;
  13147. if (depthTexture && depthTexture.isDepthTexture) {
  13148. if (depthTexture.type === FloatType) {
  13149. glInternalFormat = 36012;
  13150. } else if (depthTexture.type === UnsignedIntType) {
  13151. glInternalFormat = 33190;
  13152. }
  13153. }
  13154. var samples = getRenderTargetSamples(renderTarget);
  13155. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13156. } else {
  13157. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13158. }
  13159. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13160. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13161. if (isMultisample) {
  13162. var _samples = getRenderTargetSamples(renderTarget);
  13163. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13164. } else {
  13165. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13166. }
  13167. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13168. } else {
  13169. var glFormat = utils.convert(renderTarget.texture.format);
  13170. var glType = utils.convert(renderTarget.texture.type);
  13171. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13172. if (isMultisample) {
  13173. var _samples2 = getRenderTargetSamples(renderTarget);
  13174. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13175. } else {
  13176. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13177. }
  13178. }
  13179. _gl.bindRenderbuffer(36161, null);
  13180. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13181. function setupDepthTexture(framebuffer, renderTarget) {
  13182. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13183. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13184. _gl.bindFramebuffer(36160, framebuffer);
  13185. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13186. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13187. } // upload an empty depth texture with framebuffer size
  13188. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13189. renderTarget.depthTexture.image.width = renderTarget.width;
  13190. renderTarget.depthTexture.image.height = renderTarget.height;
  13191. renderTarget.depthTexture.needsUpdate = true;
  13192. }
  13193. setTexture2D(renderTarget.depthTexture, 0);
  13194. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13195. if (renderTarget.depthTexture.format === DepthFormat) {
  13196. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13197. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13198. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13199. } else {
  13200. throw new Error('Unknown depthTexture format');
  13201. }
  13202. } // Setup GL resources for a non-texture depth buffer
  13203. function setupDepthRenderbuffer(renderTarget) {
  13204. var renderTargetProperties = properties.get(renderTarget);
  13205. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13206. if (renderTarget.depthTexture) {
  13207. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13208. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13209. } else {
  13210. if (isCube) {
  13211. renderTargetProperties.__webglDepthbuffer = [];
  13212. for (var i = 0; i < 6; i++) {
  13213. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13214. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13215. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13216. }
  13217. } else {
  13218. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13219. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13220. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13221. }
  13222. }
  13223. _gl.bindFramebuffer(36160, null);
  13224. } // Set up GL resources for the render target
  13225. function setupRenderTarget(renderTarget) {
  13226. var renderTargetProperties = properties.get(renderTarget);
  13227. var textureProperties = properties.get(renderTarget.texture);
  13228. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13229. textureProperties.__webglTexture = _gl.createTexture();
  13230. info.memory.textures++;
  13231. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13232. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13233. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13234. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13235. renderTarget.texture.format = RGBAFormat;
  13236. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13237. } // Setup framebuffer
  13238. if (isCube) {
  13239. renderTargetProperties.__webglFramebuffer = [];
  13240. for (var i = 0; i < 6; i++) {
  13241. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13242. }
  13243. } else {
  13244. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13245. if (isMultisample) {
  13246. if (isWebGL2) {
  13247. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13248. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13249. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13250. var glFormat = utils.convert(renderTarget.texture.format);
  13251. var glType = utils.convert(renderTarget.texture.type);
  13252. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13253. var samples = getRenderTargetSamples(renderTarget);
  13254. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13255. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13256. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13257. _gl.bindRenderbuffer(36161, null);
  13258. if (renderTarget.depthBuffer) {
  13259. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13260. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13261. }
  13262. _gl.bindFramebuffer(36160, null);
  13263. } else {
  13264. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13265. }
  13266. }
  13267. } // Setup color buffer
  13268. if (isCube) {
  13269. state.bindTexture(34067, textureProperties.__webglTexture);
  13270. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13271. for (var _i5 = 0; _i5 < 6; _i5++) {
  13272. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13273. }
  13274. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13275. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13276. }
  13277. state.bindTexture(34067, null);
  13278. } else {
  13279. state.bindTexture(3553, textureProperties.__webglTexture);
  13280. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13281. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13282. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13283. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13284. }
  13285. state.bindTexture(3553, null);
  13286. } // Setup depth and stencil buffers
  13287. if (renderTarget.depthBuffer) {
  13288. setupDepthRenderbuffer(renderTarget);
  13289. }
  13290. }
  13291. function updateRenderTargetMipmap(renderTarget) {
  13292. var texture = renderTarget.texture;
  13293. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13294. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13295. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13296. var webglTexture = properties.get(texture).__webglTexture;
  13297. state.bindTexture(target, webglTexture);
  13298. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13299. state.bindTexture(target, null);
  13300. }
  13301. }
  13302. function updateMultisampleRenderTarget(renderTarget) {
  13303. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13304. if (isWebGL2) {
  13305. var renderTargetProperties = properties.get(renderTarget);
  13306. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13307. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13308. var width = renderTarget.width;
  13309. var height = renderTarget.height;
  13310. var mask = 16384;
  13311. if (renderTarget.depthBuffer) mask |= 256;
  13312. if (renderTarget.stencilBuffer) mask |= 1024;
  13313. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13314. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13315. } else {
  13316. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13317. }
  13318. }
  13319. }
  13320. function getRenderTargetSamples(renderTarget) {
  13321. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13322. }
  13323. function updateVideoTexture(texture) {
  13324. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13325. if (_videoTextures.get(texture) !== frame) {
  13326. _videoTextures.set(texture, frame);
  13327. texture.update();
  13328. }
  13329. } // backwards compatibility
  13330. var warnedTexture2D = false;
  13331. var warnedTextureCube = false;
  13332. function safeSetTexture2D(texture, slot) {
  13333. if (texture && texture.isWebGLRenderTarget) {
  13334. if (warnedTexture2D === false) {
  13335. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13336. warnedTexture2D = true;
  13337. }
  13338. texture = texture.texture;
  13339. }
  13340. setTexture2D(texture, slot);
  13341. }
  13342. function safeSetTextureCube(texture, slot) {
  13343. if (texture && texture.isWebGLCubeRenderTarget) {
  13344. if (warnedTextureCube === false) {
  13345. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13346. warnedTextureCube = true;
  13347. }
  13348. texture = texture.texture;
  13349. }
  13350. setTextureCube(texture, slot);
  13351. } //
  13352. this.allocateTextureUnit = allocateTextureUnit;
  13353. this.resetTextureUnits = resetTextureUnits;
  13354. this.setTexture2D = setTexture2D;
  13355. this.setTexture2DArray = setTexture2DArray;
  13356. this.setTexture3D = setTexture3D;
  13357. this.setTextureCube = setTextureCube;
  13358. this.setupRenderTarget = setupRenderTarget;
  13359. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13360. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13361. this.safeSetTexture2D = safeSetTexture2D;
  13362. this.safeSetTextureCube = safeSetTextureCube;
  13363. }
  13364. function WebGLUtils(gl, extensions, capabilities) {
  13365. var isWebGL2 = capabilities.isWebGL2;
  13366. function convert(p) {
  13367. var extension;
  13368. if (p === UnsignedByteType) return 5121;
  13369. if (p === UnsignedShort4444Type) return 32819;
  13370. if (p === UnsignedShort5551Type) return 32820;
  13371. if (p === UnsignedShort565Type) return 33635;
  13372. if (p === ByteType) return 5120;
  13373. if (p === ShortType) return 5122;
  13374. if (p === UnsignedShortType) return 5123;
  13375. if (p === IntType) return 5124;
  13376. if (p === UnsignedIntType) return 5125;
  13377. if (p === FloatType) return 5126;
  13378. if (p === HalfFloatType) {
  13379. if (isWebGL2) return 5131;
  13380. extension = extensions.get('OES_texture_half_float');
  13381. if (extension !== null) {
  13382. return extension.HALF_FLOAT_OES;
  13383. } else {
  13384. return null;
  13385. }
  13386. }
  13387. if (p === AlphaFormat) return 6406;
  13388. if (p === RGBFormat) return 6407;
  13389. if (p === RGBAFormat) return 6408;
  13390. if (p === LuminanceFormat) return 6409;
  13391. if (p === LuminanceAlphaFormat) return 6410;
  13392. if (p === DepthFormat) return 6402;
  13393. if (p === DepthStencilFormat) return 34041;
  13394. if (p === RedFormat) return 6403; // WebGL2 formats.
  13395. if (p === RedIntegerFormat) return 36244;
  13396. if (p === RGFormat) return 33319;
  13397. if (p === RGIntegerFormat) return 33320;
  13398. if (p === RGBIntegerFormat) return 36248;
  13399. if (p === RGBAIntegerFormat) return 36249;
  13400. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13401. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13402. if (extension !== null) {
  13403. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13404. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13405. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13406. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13407. } else {
  13408. return null;
  13409. }
  13410. }
  13411. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13412. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13413. if (extension !== null) {
  13414. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13415. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13416. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13417. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13418. } else {
  13419. return null;
  13420. }
  13421. }
  13422. if (p === RGB_ETC1_Format) {
  13423. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13424. if (extension !== null) {
  13425. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13426. } else {
  13427. return null;
  13428. }
  13429. }
  13430. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13431. extension = extensions.get('WEBGL_compressed_texture_etc');
  13432. if (extension !== null) {
  13433. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13434. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13435. }
  13436. }
  13437. 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) {
  13438. extension = extensions.get('WEBGL_compressed_texture_astc');
  13439. if (extension !== null) {
  13440. // TODO Complete?
  13441. return p;
  13442. } else {
  13443. return null;
  13444. }
  13445. }
  13446. if (p === RGBA_BPTC_Format) {
  13447. extension = extensions.get('EXT_texture_compression_bptc');
  13448. if (extension !== null) {
  13449. // TODO Complete?
  13450. return p;
  13451. } else {
  13452. return null;
  13453. }
  13454. }
  13455. if (p === UnsignedInt248Type) {
  13456. if (isWebGL2) return 34042;
  13457. extension = extensions.get('WEBGL_depth_texture');
  13458. if (extension !== null) {
  13459. return extension.UNSIGNED_INT_24_8_WEBGL;
  13460. } else {
  13461. return null;
  13462. }
  13463. }
  13464. }
  13465. return {
  13466. convert: convert
  13467. };
  13468. }
  13469. function ArrayCamera(array) {
  13470. if (array === void 0) {
  13471. array = [];
  13472. }
  13473. PerspectiveCamera.call(this);
  13474. this.cameras = array;
  13475. }
  13476. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13477. constructor: ArrayCamera,
  13478. isArrayCamera: true
  13479. });
  13480. function Group() {
  13481. Object3D.call(this);
  13482. this.type = 'Group';
  13483. }
  13484. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13485. constructor: Group,
  13486. isGroup: true
  13487. });
  13488. function WebXRController() {
  13489. this._targetRay = null;
  13490. this._grip = null;
  13491. this._hand = null;
  13492. }
  13493. Object.assign(WebXRController.prototype, {
  13494. constructor: WebXRController,
  13495. getHandSpace: function getHandSpace() {
  13496. if (this._hand === null) {
  13497. this._hand = new Group();
  13498. this._hand.matrixAutoUpdate = false;
  13499. this._hand.visible = false;
  13500. this._hand.joints = [];
  13501. this._hand.inputState = {
  13502. pinching: false
  13503. };
  13504. if (window.XRHand) {
  13505. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13506. // The transform of this joint will be updated with the joint pose on each frame
  13507. var joint = new Group();
  13508. joint.matrixAutoUpdate = false;
  13509. joint.visible = false;
  13510. this._hand.joints.push(joint); // ??
  13511. this._hand.add(joint);
  13512. }
  13513. }
  13514. }
  13515. return this._hand;
  13516. },
  13517. getTargetRaySpace: function getTargetRaySpace() {
  13518. if (this._targetRay === null) {
  13519. this._targetRay = new Group();
  13520. this._targetRay.matrixAutoUpdate = false;
  13521. this._targetRay.visible = false;
  13522. }
  13523. return this._targetRay;
  13524. },
  13525. getGripSpace: function getGripSpace() {
  13526. if (this._grip === null) {
  13527. this._grip = new Group();
  13528. this._grip.matrixAutoUpdate = false;
  13529. this._grip.visible = false;
  13530. }
  13531. return this._grip;
  13532. },
  13533. dispatchEvent: function dispatchEvent(event) {
  13534. if (this._targetRay !== null) {
  13535. this._targetRay.dispatchEvent(event);
  13536. }
  13537. if (this._grip !== null) {
  13538. this._grip.dispatchEvent(event);
  13539. }
  13540. if (this._hand !== null) {
  13541. this._hand.dispatchEvent(event);
  13542. }
  13543. return this;
  13544. },
  13545. disconnect: function disconnect(inputSource) {
  13546. this.dispatchEvent({
  13547. type: 'disconnected',
  13548. data: inputSource
  13549. });
  13550. if (this._targetRay !== null) {
  13551. this._targetRay.visible = false;
  13552. }
  13553. if (this._grip !== null) {
  13554. this._grip.visible = false;
  13555. }
  13556. if (this._hand !== null) {
  13557. this._hand.visible = false;
  13558. }
  13559. return this;
  13560. },
  13561. update: function update(inputSource, frame, referenceSpace) {
  13562. var inputPose = null;
  13563. var gripPose = null;
  13564. var handPose = null;
  13565. var targetRay = this._targetRay;
  13566. var grip = this._grip;
  13567. var hand = this._hand;
  13568. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  13569. if (hand && inputSource.hand) {
  13570. handPose = true;
  13571. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13572. if (inputSource.hand[i]) {
  13573. // Update the joints groups with the XRJoint poses
  13574. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13575. var joint = hand.joints[i];
  13576. if (jointPose !== null) {
  13577. joint.matrix.fromArray(jointPose.transform.matrix);
  13578. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13579. joint.jointRadius = jointPose.radius;
  13580. }
  13581. joint.visible = jointPose !== null; // Custom events
  13582. // Check pinch
  13583. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13584. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13585. var distance = indexTip.position.distanceTo(thumbTip.position);
  13586. var distanceToPinch = 0.02;
  13587. var threshold = 0.005;
  13588. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13589. hand.inputState.pinching = false;
  13590. this.dispatchEvent({
  13591. type: "pinchend",
  13592. handedness: inputSource.handedness,
  13593. target: this
  13594. });
  13595. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13596. hand.inputState.pinching = true;
  13597. this.dispatchEvent({
  13598. type: "pinchstart",
  13599. handedness: inputSource.handedness,
  13600. target: this
  13601. });
  13602. }
  13603. }
  13604. }
  13605. } else {
  13606. if (targetRay !== null) {
  13607. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13608. if (inputPose !== null) {
  13609. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13610. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13611. }
  13612. }
  13613. if (grip !== null && inputSource.gripSpace) {
  13614. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13615. if (gripPose !== null) {
  13616. grip.matrix.fromArray(gripPose.transform.matrix);
  13617. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13618. }
  13619. }
  13620. }
  13621. }
  13622. if (targetRay !== null) {
  13623. targetRay.visible = inputPose !== null;
  13624. }
  13625. if (grip !== null) {
  13626. grip.visible = gripPose !== null;
  13627. }
  13628. if (hand !== null) {
  13629. hand.visible = handPose !== null;
  13630. }
  13631. return this;
  13632. }
  13633. });
  13634. function WebXRManager(renderer, gl) {
  13635. var scope = this;
  13636. var session = null;
  13637. var framebufferScaleFactor = 1.0;
  13638. var referenceSpace = null;
  13639. var referenceSpaceType = 'local-floor';
  13640. var pose = null;
  13641. var controllers = [];
  13642. var inputSourcesMap = new Map(); //
  13643. var cameraL = new PerspectiveCamera();
  13644. cameraL.layers.enable(1);
  13645. cameraL.viewport = new Vector4();
  13646. var cameraR = new PerspectiveCamera();
  13647. cameraR.layers.enable(2);
  13648. cameraR.viewport = new Vector4();
  13649. var cameras = [cameraL, cameraR];
  13650. var cameraVR = new ArrayCamera();
  13651. cameraVR.layers.enable(1);
  13652. cameraVR.layers.enable(2);
  13653. var _currentDepthNear = null;
  13654. var _currentDepthFar = null; //
  13655. this.enabled = false;
  13656. this.isPresenting = false;
  13657. this.getController = function (index) {
  13658. var controller = controllers[index];
  13659. if (controller === undefined) {
  13660. controller = new WebXRController();
  13661. controllers[index] = controller;
  13662. }
  13663. return controller.getTargetRaySpace();
  13664. };
  13665. this.getControllerGrip = function (index) {
  13666. var controller = controllers[index];
  13667. if (controller === undefined) {
  13668. controller = new WebXRController();
  13669. controllers[index] = controller;
  13670. }
  13671. return controller.getGripSpace();
  13672. };
  13673. this.getHand = function (index) {
  13674. var controller = controllers[index];
  13675. if (controller === undefined) {
  13676. controller = new WebXRController();
  13677. controllers[index] = controller;
  13678. }
  13679. return controller.getHandSpace();
  13680. }; //
  13681. function onSessionEvent(event) {
  13682. var controller = inputSourcesMap.get(event.inputSource);
  13683. if (controller) {
  13684. controller.dispatchEvent({
  13685. type: event.type,
  13686. data: event.inputSource
  13687. });
  13688. }
  13689. }
  13690. function onSessionEnd() {
  13691. inputSourcesMap.forEach(function (controller, inputSource) {
  13692. controller.disconnect(inputSource);
  13693. });
  13694. inputSourcesMap.clear(); //
  13695. renderer.setFramebuffer(null);
  13696. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13697. animation.stop();
  13698. scope.isPresenting = false;
  13699. scope.dispatchEvent({
  13700. type: 'sessionend'
  13701. });
  13702. }
  13703. function onRequestReferenceSpace(value) {
  13704. referenceSpace = value;
  13705. animation.setContext(session);
  13706. animation.start();
  13707. scope.isPresenting = true;
  13708. scope.dispatchEvent({
  13709. type: 'sessionstart'
  13710. });
  13711. }
  13712. this.setFramebufferScaleFactor = function (value) {
  13713. framebufferScaleFactor = value;
  13714. if (scope.isPresenting === true) {
  13715. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13716. }
  13717. };
  13718. this.setReferenceSpaceType = function (value) {
  13719. referenceSpaceType = value;
  13720. if (scope.isPresenting === true) {
  13721. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13722. }
  13723. };
  13724. this.getReferenceSpace = function () {
  13725. return referenceSpace;
  13726. };
  13727. this.getSession = function () {
  13728. return session;
  13729. };
  13730. this.setSession = function (value) {
  13731. session = value;
  13732. if (session !== null) {
  13733. session.addEventListener('select', onSessionEvent);
  13734. session.addEventListener('selectstart', onSessionEvent);
  13735. session.addEventListener('selectend', onSessionEvent);
  13736. session.addEventListener('squeeze', onSessionEvent);
  13737. session.addEventListener('squeezestart', onSessionEvent);
  13738. session.addEventListener('squeezeend', onSessionEvent);
  13739. session.addEventListener('end', onSessionEnd);
  13740. var attributes = gl.getContextAttributes();
  13741. if (attributes.xrCompatible !== true) {
  13742. gl.makeXRCompatible();
  13743. }
  13744. var layerInit = {
  13745. antialias: attributes.antialias,
  13746. alpha: attributes.alpha,
  13747. depth: attributes.depth,
  13748. stencil: attributes.stencil,
  13749. framebufferScaleFactor: framebufferScaleFactor
  13750. }; // eslint-disable-next-line no-undef
  13751. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13752. session.updateRenderState({
  13753. baseLayer: baseLayer
  13754. });
  13755. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13756. session.addEventListener('inputsourceschange', updateInputSources);
  13757. }
  13758. };
  13759. function updateInputSources(event) {
  13760. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13761. for (var i = 0; i < controllers.length; i++) {
  13762. inputSourcesMap.set(inputSources[i], controllers[i]);
  13763. } // Notify disconnected
  13764. for (var _i = 0; _i < event.removed.length; _i++) {
  13765. var inputSource = event.removed[_i];
  13766. var controller = inputSourcesMap.get(inputSource);
  13767. if (controller) {
  13768. controller.dispatchEvent({
  13769. type: 'disconnected',
  13770. data: inputSource
  13771. });
  13772. inputSourcesMap.delete(inputSource);
  13773. }
  13774. } // Notify connected
  13775. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13776. var _inputSource = event.added[_i2];
  13777. var _controller = inputSourcesMap.get(_inputSource);
  13778. if (_controller) {
  13779. _controller.dispatchEvent({
  13780. type: 'connected',
  13781. data: _inputSource
  13782. });
  13783. }
  13784. }
  13785. } //
  13786. var cameraLPos = new Vector3();
  13787. var cameraRPos = new Vector3();
  13788. /**
  13789. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13790. * the cameras' projection and world matrices have already been set.
  13791. * And that near and far planes are identical for both cameras.
  13792. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13793. */
  13794. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13795. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13796. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13797. var ipd = cameraLPos.distanceTo(cameraRPos);
  13798. var projL = cameraL.projectionMatrix.elements;
  13799. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13800. // most likely identical top and bottom frustum extents.
  13801. // Use the left camera for these values.
  13802. var near = projL[14] / (projL[10] - 1);
  13803. var far = projL[14] / (projL[10] + 1);
  13804. var topFov = (projL[9] + 1) / projL[5];
  13805. var bottomFov = (projL[9] - 1) / projL[5];
  13806. var leftFov = (projL[8] - 1) / projL[0];
  13807. var rightFov = (projR[8] + 1) / projR[0];
  13808. var left = near * leftFov;
  13809. var right = near * rightFov; // Calculate the new camera's position offset from the
  13810. // left camera. xOffset should be roughly half `ipd`.
  13811. var zOffset = ipd / (-leftFov + rightFov);
  13812. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13813. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13814. camera.translateX(xOffset);
  13815. camera.translateZ(zOffset);
  13816. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13817. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  13818. // the values so that the near plane's position does not change in world space,
  13819. // although must now be relative to the new union camera.
  13820. var near2 = near + zOffset;
  13821. var far2 = far + zOffset;
  13822. var left2 = left - xOffset;
  13823. var right2 = right + (ipd - xOffset);
  13824. var top2 = topFov * far / far2 * near2;
  13825. var bottom2 = bottomFov * far / far2 * near2;
  13826. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13827. }
  13828. function updateCamera(camera, parent) {
  13829. if (parent === null) {
  13830. camera.matrixWorld.copy(camera.matrix);
  13831. } else {
  13832. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13833. }
  13834. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  13835. }
  13836. this.getCamera = function (camera) {
  13837. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13838. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13839. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13840. // Note that the new renderState won't apply until the next frame. See #18320
  13841. session.updateRenderState({
  13842. depthNear: cameraVR.near,
  13843. depthFar: cameraVR.far
  13844. });
  13845. _currentDepthNear = cameraVR.near;
  13846. _currentDepthFar = cameraVR.far;
  13847. }
  13848. var parent = camera.parent;
  13849. var cameras = cameraVR.cameras;
  13850. updateCamera(cameraVR, parent);
  13851. for (var i = 0; i < cameras.length; i++) {
  13852. updateCamera(cameras[i], parent);
  13853. } // update camera and its children
  13854. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13855. var children = camera.children;
  13856. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13857. children[_i3].updateMatrixWorld(true);
  13858. } // update projection matrix for proper view frustum culling
  13859. if (cameras.length === 2) {
  13860. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13861. } else {
  13862. // assume single camera setup (AR)
  13863. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13864. }
  13865. return cameraVR;
  13866. }; // Animation Loop
  13867. var onAnimationFrameCallback = null;
  13868. function onAnimationFrame(time, frame) {
  13869. pose = frame.getViewerPose(referenceSpace);
  13870. if (pose !== null) {
  13871. var views = pose.views;
  13872. var baseLayer = session.renderState.baseLayer;
  13873. renderer.setFramebuffer(baseLayer.framebuffer);
  13874. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13875. if (views.length !== cameraVR.cameras.length) {
  13876. cameraVR.cameras.length = 0;
  13877. cameraVRNeedsUpdate = true;
  13878. }
  13879. for (var i = 0; i < views.length; i++) {
  13880. var view = views[i];
  13881. var viewport = baseLayer.getViewport(view);
  13882. var camera = cameras[i];
  13883. camera.matrix.fromArray(view.transform.matrix);
  13884. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13885. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13886. if (i === 0) {
  13887. cameraVR.matrix.copy(camera.matrix);
  13888. }
  13889. if (cameraVRNeedsUpdate === true) {
  13890. cameraVR.cameras.push(camera);
  13891. }
  13892. }
  13893. } //
  13894. var inputSources = session.inputSources;
  13895. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13896. var controller = controllers[_i4];
  13897. var inputSource = inputSources[_i4];
  13898. controller.update(inputSource, frame, referenceSpace);
  13899. }
  13900. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13901. }
  13902. var animation = new WebGLAnimation();
  13903. animation.setAnimationLoop(onAnimationFrame);
  13904. this.setAnimationLoop = function (callback) {
  13905. onAnimationFrameCallback = callback;
  13906. };
  13907. this.dispose = function () {};
  13908. }
  13909. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13910. function WebGLMaterials(properties) {
  13911. function refreshFogUniforms(uniforms, fog) {
  13912. uniforms.fogColor.value.copy(fog.color);
  13913. if (fog.isFog) {
  13914. uniforms.fogNear.value = fog.near;
  13915. uniforms.fogFar.value = fog.far;
  13916. } else if (fog.isFogExp2) {
  13917. uniforms.fogDensity.value = fog.density;
  13918. }
  13919. }
  13920. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13921. if (material.isMeshBasicMaterial) {
  13922. refreshUniformsCommon(uniforms, material);
  13923. } else if (material.isMeshLambertMaterial) {
  13924. refreshUniformsCommon(uniforms, material);
  13925. refreshUniformsLambert(uniforms, material);
  13926. } else if (material.isMeshToonMaterial) {
  13927. refreshUniformsCommon(uniforms, material);
  13928. refreshUniformsToon(uniforms, material);
  13929. } else if (material.isMeshPhongMaterial) {
  13930. refreshUniformsCommon(uniforms, material);
  13931. refreshUniformsPhong(uniforms, material);
  13932. } else if (material.isMeshStandardMaterial) {
  13933. refreshUniformsCommon(uniforms, material);
  13934. if (material.isMeshPhysicalMaterial) {
  13935. refreshUniformsPhysical(uniforms, material);
  13936. } else {
  13937. refreshUniformsStandard(uniforms, material);
  13938. }
  13939. } else if (material.isMeshMatcapMaterial) {
  13940. refreshUniformsCommon(uniforms, material);
  13941. refreshUniformsMatcap(uniforms, material);
  13942. } else if (material.isMeshDepthMaterial) {
  13943. refreshUniformsCommon(uniforms, material);
  13944. refreshUniformsDepth(uniforms, material);
  13945. } else if (material.isMeshDistanceMaterial) {
  13946. refreshUniformsCommon(uniforms, material);
  13947. refreshUniformsDistance(uniforms, material);
  13948. } else if (material.isMeshNormalMaterial) {
  13949. refreshUniformsCommon(uniforms, material);
  13950. refreshUniformsNormal(uniforms, material);
  13951. } else if (material.isLineBasicMaterial) {
  13952. refreshUniformsLine(uniforms, material);
  13953. if (material.isLineDashedMaterial) {
  13954. refreshUniformsDash(uniforms, material);
  13955. }
  13956. } else if (material.isPointsMaterial) {
  13957. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13958. } else if (material.isSpriteMaterial) {
  13959. refreshUniformsSprites(uniforms, material);
  13960. } else if (material.isShadowMaterial) {
  13961. uniforms.color.value.copy(material.color);
  13962. uniforms.opacity.value = material.opacity;
  13963. } else if (material.isShaderMaterial) {
  13964. material.uniformsNeedUpdate = false; // #15581
  13965. }
  13966. }
  13967. function refreshUniformsCommon(uniforms, material) {
  13968. uniforms.opacity.value = material.opacity;
  13969. if (material.color) {
  13970. uniforms.diffuse.value.copy(material.color);
  13971. }
  13972. if (material.emissive) {
  13973. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13974. }
  13975. if (material.map) {
  13976. uniforms.map.value = material.map;
  13977. }
  13978. if (material.alphaMap) {
  13979. uniforms.alphaMap.value = material.alphaMap;
  13980. }
  13981. if (material.specularMap) {
  13982. uniforms.specularMap.value = material.specularMap;
  13983. }
  13984. var envMap = properties.get(material).envMap;
  13985. if (envMap) {
  13986. uniforms.envMap.value = envMap;
  13987. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13988. uniforms.reflectivity.value = material.reflectivity;
  13989. uniforms.refractionRatio.value = material.refractionRatio;
  13990. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13991. if (maxMipLevel !== undefined) {
  13992. uniforms.maxMipLevel.value = maxMipLevel;
  13993. }
  13994. }
  13995. if (material.lightMap) {
  13996. uniforms.lightMap.value = material.lightMap;
  13997. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13998. }
  13999. if (material.aoMap) {
  14000. uniforms.aoMap.value = material.aoMap;
  14001. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14002. } // uv repeat and offset setting priorities
  14003. // 1. color map
  14004. // 2. specular map
  14005. // 3. displacementMap map
  14006. // 4. normal map
  14007. // 5. bump map
  14008. // 6. roughnessMap map
  14009. // 7. metalnessMap map
  14010. // 8. alphaMap map
  14011. // 9. emissiveMap map
  14012. // 10. clearcoat map
  14013. // 11. clearcoat normal map
  14014. // 12. clearcoat roughnessMap map
  14015. var uvScaleMap;
  14016. if (material.map) {
  14017. uvScaleMap = material.map;
  14018. } else if (material.specularMap) {
  14019. uvScaleMap = material.specularMap;
  14020. } else if (material.displacementMap) {
  14021. uvScaleMap = material.displacementMap;
  14022. } else if (material.normalMap) {
  14023. uvScaleMap = material.normalMap;
  14024. } else if (material.bumpMap) {
  14025. uvScaleMap = material.bumpMap;
  14026. } else if (material.roughnessMap) {
  14027. uvScaleMap = material.roughnessMap;
  14028. } else if (material.metalnessMap) {
  14029. uvScaleMap = material.metalnessMap;
  14030. } else if (material.alphaMap) {
  14031. uvScaleMap = material.alphaMap;
  14032. } else if (material.emissiveMap) {
  14033. uvScaleMap = material.emissiveMap;
  14034. } else if (material.clearcoatMap) {
  14035. uvScaleMap = material.clearcoatMap;
  14036. } else if (material.clearcoatNormalMap) {
  14037. uvScaleMap = material.clearcoatNormalMap;
  14038. } else if (material.clearcoatRoughnessMap) {
  14039. uvScaleMap = material.clearcoatRoughnessMap;
  14040. }
  14041. if (uvScaleMap !== undefined) {
  14042. // backwards compatibility
  14043. if (uvScaleMap.isWebGLRenderTarget) {
  14044. uvScaleMap = uvScaleMap.texture;
  14045. }
  14046. if (uvScaleMap.matrixAutoUpdate === true) {
  14047. uvScaleMap.updateMatrix();
  14048. }
  14049. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14050. } // uv repeat and offset setting priorities for uv2
  14051. // 1. ao map
  14052. // 2. light map
  14053. var uv2ScaleMap;
  14054. if (material.aoMap) {
  14055. uv2ScaleMap = material.aoMap;
  14056. } else if (material.lightMap) {
  14057. uv2ScaleMap = material.lightMap;
  14058. }
  14059. if (uv2ScaleMap !== undefined) {
  14060. // backwards compatibility
  14061. if (uv2ScaleMap.isWebGLRenderTarget) {
  14062. uv2ScaleMap = uv2ScaleMap.texture;
  14063. }
  14064. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14065. uv2ScaleMap.updateMatrix();
  14066. }
  14067. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14068. }
  14069. }
  14070. function refreshUniformsLine(uniforms, material) {
  14071. uniforms.diffuse.value.copy(material.color);
  14072. uniforms.opacity.value = material.opacity;
  14073. }
  14074. function refreshUniformsDash(uniforms, material) {
  14075. uniforms.dashSize.value = material.dashSize;
  14076. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14077. uniforms.scale.value = material.scale;
  14078. }
  14079. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14080. uniforms.diffuse.value.copy(material.color);
  14081. uniforms.opacity.value = material.opacity;
  14082. uniforms.size.value = material.size * pixelRatio;
  14083. uniforms.scale.value = height * 0.5;
  14084. if (material.map) {
  14085. uniforms.map.value = material.map;
  14086. }
  14087. if (material.alphaMap) {
  14088. uniforms.alphaMap.value = material.alphaMap;
  14089. } // uv repeat and offset setting priorities
  14090. // 1. color map
  14091. // 2. alpha map
  14092. var uvScaleMap;
  14093. if (material.map) {
  14094. uvScaleMap = material.map;
  14095. } else if (material.alphaMap) {
  14096. uvScaleMap = material.alphaMap;
  14097. }
  14098. if (uvScaleMap !== undefined) {
  14099. if (uvScaleMap.matrixAutoUpdate === true) {
  14100. uvScaleMap.updateMatrix();
  14101. }
  14102. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14103. }
  14104. }
  14105. function refreshUniformsSprites(uniforms, material) {
  14106. uniforms.diffuse.value.copy(material.color);
  14107. uniforms.opacity.value = material.opacity;
  14108. uniforms.rotation.value = material.rotation;
  14109. if (material.map) {
  14110. uniforms.map.value = material.map;
  14111. }
  14112. if (material.alphaMap) {
  14113. uniforms.alphaMap.value = material.alphaMap;
  14114. } // uv repeat and offset setting priorities
  14115. // 1. color map
  14116. // 2. alpha map
  14117. var uvScaleMap;
  14118. if (material.map) {
  14119. uvScaleMap = material.map;
  14120. } else if (material.alphaMap) {
  14121. uvScaleMap = material.alphaMap;
  14122. }
  14123. if (uvScaleMap !== undefined) {
  14124. if (uvScaleMap.matrixAutoUpdate === true) {
  14125. uvScaleMap.updateMatrix();
  14126. }
  14127. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14128. }
  14129. }
  14130. function refreshUniformsLambert(uniforms, material) {
  14131. if (material.emissiveMap) {
  14132. uniforms.emissiveMap.value = material.emissiveMap;
  14133. }
  14134. }
  14135. function refreshUniformsPhong(uniforms, material) {
  14136. uniforms.specular.value.copy(material.specular);
  14137. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14138. if (material.emissiveMap) {
  14139. uniforms.emissiveMap.value = material.emissiveMap;
  14140. }
  14141. if (material.bumpMap) {
  14142. uniforms.bumpMap.value = material.bumpMap;
  14143. uniforms.bumpScale.value = material.bumpScale;
  14144. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14145. }
  14146. if (material.normalMap) {
  14147. uniforms.normalMap.value = material.normalMap;
  14148. uniforms.normalScale.value.copy(material.normalScale);
  14149. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14150. }
  14151. if (material.displacementMap) {
  14152. uniforms.displacementMap.value = material.displacementMap;
  14153. uniforms.displacementScale.value = material.displacementScale;
  14154. uniforms.displacementBias.value = material.displacementBias;
  14155. }
  14156. }
  14157. function refreshUniformsToon(uniforms, material) {
  14158. if (material.gradientMap) {
  14159. uniforms.gradientMap.value = material.gradientMap;
  14160. }
  14161. if (material.emissiveMap) {
  14162. uniforms.emissiveMap.value = material.emissiveMap;
  14163. }
  14164. if (material.bumpMap) {
  14165. uniforms.bumpMap.value = material.bumpMap;
  14166. uniforms.bumpScale.value = material.bumpScale;
  14167. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14168. }
  14169. if (material.normalMap) {
  14170. uniforms.normalMap.value = material.normalMap;
  14171. uniforms.normalScale.value.copy(material.normalScale);
  14172. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14173. }
  14174. if (material.displacementMap) {
  14175. uniforms.displacementMap.value = material.displacementMap;
  14176. uniforms.displacementScale.value = material.displacementScale;
  14177. uniforms.displacementBias.value = material.displacementBias;
  14178. }
  14179. }
  14180. function refreshUniformsStandard(uniforms, material) {
  14181. uniforms.roughness.value = material.roughness;
  14182. uniforms.metalness.value = material.metalness;
  14183. if (material.roughnessMap) {
  14184. uniforms.roughnessMap.value = material.roughnessMap;
  14185. }
  14186. if (material.metalnessMap) {
  14187. uniforms.metalnessMap.value = material.metalnessMap;
  14188. }
  14189. if (material.emissiveMap) {
  14190. uniforms.emissiveMap.value = material.emissiveMap;
  14191. }
  14192. if (material.bumpMap) {
  14193. uniforms.bumpMap.value = material.bumpMap;
  14194. uniforms.bumpScale.value = material.bumpScale;
  14195. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14196. }
  14197. if (material.normalMap) {
  14198. uniforms.normalMap.value = material.normalMap;
  14199. uniforms.normalScale.value.copy(material.normalScale);
  14200. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14201. }
  14202. if (material.displacementMap) {
  14203. uniforms.displacementMap.value = material.displacementMap;
  14204. uniforms.displacementScale.value = material.displacementScale;
  14205. uniforms.displacementBias.value = material.displacementBias;
  14206. }
  14207. var envMap = properties.get(material).envMap;
  14208. if (envMap) {
  14209. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14210. uniforms.envMapIntensity.value = material.envMapIntensity;
  14211. }
  14212. }
  14213. function refreshUniformsPhysical(uniforms, material) {
  14214. refreshUniformsStandard(uniforms, material);
  14215. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14216. uniforms.clearcoat.value = material.clearcoat;
  14217. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14218. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14219. if (material.clearcoatMap) {
  14220. uniforms.clearcoatMap.value = material.clearcoatMap;
  14221. }
  14222. if (material.clearcoatRoughnessMap) {
  14223. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14224. }
  14225. if (material.clearcoatNormalMap) {
  14226. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14227. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14228. if (material.side === BackSide) {
  14229. uniforms.clearcoatNormalScale.value.negate();
  14230. }
  14231. }
  14232. uniforms.transmission.value = material.transmission;
  14233. if (material.transmissionMap) {
  14234. uniforms.transmissionMap.value = material.transmissionMap;
  14235. }
  14236. }
  14237. function refreshUniformsMatcap(uniforms, material) {
  14238. if (material.matcap) {
  14239. uniforms.matcap.value = material.matcap;
  14240. }
  14241. if (material.bumpMap) {
  14242. uniforms.bumpMap.value = material.bumpMap;
  14243. uniforms.bumpScale.value = material.bumpScale;
  14244. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14245. }
  14246. if (material.normalMap) {
  14247. uniforms.normalMap.value = material.normalMap;
  14248. uniforms.normalScale.value.copy(material.normalScale);
  14249. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14250. }
  14251. if (material.displacementMap) {
  14252. uniforms.displacementMap.value = material.displacementMap;
  14253. uniforms.displacementScale.value = material.displacementScale;
  14254. uniforms.displacementBias.value = material.displacementBias;
  14255. }
  14256. }
  14257. function refreshUniformsDepth(uniforms, material) {
  14258. if (material.displacementMap) {
  14259. uniforms.displacementMap.value = material.displacementMap;
  14260. uniforms.displacementScale.value = material.displacementScale;
  14261. uniforms.displacementBias.value = material.displacementBias;
  14262. }
  14263. }
  14264. function refreshUniformsDistance(uniforms, material) {
  14265. if (material.displacementMap) {
  14266. uniforms.displacementMap.value = material.displacementMap;
  14267. uniforms.displacementScale.value = material.displacementScale;
  14268. uniforms.displacementBias.value = material.displacementBias;
  14269. }
  14270. uniforms.referencePosition.value.copy(material.referencePosition);
  14271. uniforms.nearDistance.value = material.nearDistance;
  14272. uniforms.farDistance.value = material.farDistance;
  14273. }
  14274. function refreshUniformsNormal(uniforms, material) {
  14275. if (material.bumpMap) {
  14276. uniforms.bumpMap.value = material.bumpMap;
  14277. uniforms.bumpScale.value = material.bumpScale;
  14278. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14279. }
  14280. if (material.normalMap) {
  14281. uniforms.normalMap.value = material.normalMap;
  14282. uniforms.normalScale.value.copy(material.normalScale);
  14283. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14284. }
  14285. if (material.displacementMap) {
  14286. uniforms.displacementMap.value = material.displacementMap;
  14287. uniforms.displacementScale.value = material.displacementScale;
  14288. uniforms.displacementBias.value = material.displacementBias;
  14289. }
  14290. }
  14291. return {
  14292. refreshFogUniforms: refreshFogUniforms,
  14293. refreshMaterialUniforms: refreshMaterialUniforms
  14294. };
  14295. }
  14296. function createCanvasElement() {
  14297. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14298. canvas.style.display = 'block';
  14299. return canvas;
  14300. }
  14301. function WebGLRenderer(parameters) {
  14302. parameters = parameters || {};
  14303. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14304. _context = parameters.context !== undefined ? parameters.context : null,
  14305. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14306. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14307. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14308. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14309. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14310. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14311. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14312. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14313. var currentRenderList = null;
  14314. var currentRenderState = null; // public properties
  14315. this.domElement = _canvas; // Debug configuration container
  14316. this.debug = {
  14317. /**
  14318. * Enables error checking and reporting when shader programs are being compiled
  14319. * @type {boolean}
  14320. */
  14321. checkShaderErrors: true
  14322. }; // clearing
  14323. this.autoClear = true;
  14324. this.autoClearColor = true;
  14325. this.autoClearDepth = true;
  14326. this.autoClearStencil = true; // scene graph
  14327. this.sortObjects = true; // user-defined clipping
  14328. this.clippingPlanes = [];
  14329. this.localClippingEnabled = false; // physically based shading
  14330. this.gammaFactor = 2.0; // for backwards compatibility
  14331. this.outputEncoding = LinearEncoding; // physical lights
  14332. this.physicallyCorrectLights = false; // tone mapping
  14333. this.toneMapping = NoToneMapping;
  14334. this.toneMappingExposure = 1.0; // morphs
  14335. this.maxMorphTargets = 8;
  14336. this.maxMorphNormals = 4; // internal properties
  14337. var _this = this;
  14338. var _isContextLost = false; // internal state cache
  14339. var _framebuffer = null;
  14340. var _currentActiveCubeFace = 0;
  14341. var _currentActiveMipmapLevel = 0;
  14342. var _currentRenderTarget = null;
  14343. var _currentFramebuffer = null;
  14344. var _currentMaterialId = -1;
  14345. var _currentCamera = null;
  14346. var _currentArrayCamera = null;
  14347. var _currentViewport = new Vector4();
  14348. var _currentScissor = new Vector4();
  14349. var _currentScissorTest = null; //
  14350. var _width = _canvas.width;
  14351. var _height = _canvas.height;
  14352. var _pixelRatio = 1;
  14353. var _opaqueSort = null;
  14354. var _transparentSort = null;
  14355. var _viewport = new Vector4(0, 0, _width, _height);
  14356. var _scissor = new Vector4(0, 0, _width, _height);
  14357. var _scissorTest = false; // frustum
  14358. var _frustum = new Frustum(); // clipping
  14359. var _clippingEnabled = false;
  14360. var _localClippingEnabled = false; // camera matrices cache
  14361. var _projScreenMatrix = new Matrix4();
  14362. var _vector3 = new Vector3();
  14363. var _emptyScene = {
  14364. background: null,
  14365. fog: null,
  14366. environment: null,
  14367. overrideMaterial: null,
  14368. isScene: true
  14369. };
  14370. function getTargetPixelRatio() {
  14371. return _currentRenderTarget === null ? _pixelRatio : 1;
  14372. } // initialize
  14373. var _gl = _context;
  14374. function getContext(contextNames, contextAttributes) {
  14375. for (var i = 0; i < contextNames.length; i++) {
  14376. var contextName = contextNames[i];
  14377. var context = _canvas.getContext(contextName, contextAttributes);
  14378. if (context !== null) return context;
  14379. }
  14380. return null;
  14381. }
  14382. try {
  14383. var contextAttributes = {
  14384. alpha: _alpha,
  14385. depth: _depth,
  14386. stencil: _stencil,
  14387. antialias: _antialias,
  14388. premultipliedAlpha: _premultipliedAlpha,
  14389. preserveDrawingBuffer: _preserveDrawingBuffer,
  14390. powerPreference: _powerPreference,
  14391. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14392. }; // event listeners must be registered before WebGL context is created, see #12753
  14393. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14394. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14395. if (_gl === null) {
  14396. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14397. if (_this.isWebGL1Renderer === true) {
  14398. contextNames.shift();
  14399. }
  14400. _gl = getContext(contextNames, contextAttributes);
  14401. if (_gl === null) {
  14402. if (getContext(contextNames)) {
  14403. throw new Error('Error creating WebGL context with your selected attributes.');
  14404. } else {
  14405. throw new Error('Error creating WebGL context.');
  14406. }
  14407. }
  14408. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14409. if (_gl.getShaderPrecisionFormat === undefined) {
  14410. _gl.getShaderPrecisionFormat = function () {
  14411. return {
  14412. 'rangeMin': 1,
  14413. 'rangeMax': 1,
  14414. 'precision': 1
  14415. };
  14416. };
  14417. }
  14418. } catch (error) {
  14419. console.error('THREE.WebGLRenderer: ' + error.message);
  14420. throw error;
  14421. }
  14422. var extensions, capabilities, state, info;
  14423. var properties, textures, cubemaps, attributes, geometries, objects;
  14424. var programCache, materials, renderLists, renderStates, clipping;
  14425. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14426. var utils, bindingStates;
  14427. function initGLContext() {
  14428. extensions = new WebGLExtensions(_gl);
  14429. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14430. if (capabilities.isWebGL2 === false) {
  14431. extensions.get('WEBGL_depth_texture');
  14432. extensions.get('OES_texture_float');
  14433. extensions.get('OES_texture_half_float');
  14434. extensions.get('OES_texture_half_float_linear');
  14435. extensions.get('OES_standard_derivatives');
  14436. extensions.get('OES_element_index_uint');
  14437. extensions.get('OES_vertex_array_object');
  14438. extensions.get('ANGLE_instanced_arrays');
  14439. }
  14440. extensions.get('OES_texture_float_linear');
  14441. utils = new WebGLUtils(_gl, extensions, capabilities);
  14442. state = new WebGLState(_gl, extensions, capabilities);
  14443. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14444. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14445. info = new WebGLInfo(_gl);
  14446. properties = new WebGLProperties();
  14447. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14448. cubemaps = new WebGLCubeMaps(_this);
  14449. attributes = new WebGLAttributes(_gl, capabilities);
  14450. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14451. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14452. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14453. morphtargets = new WebGLMorphtargets(_gl);
  14454. clipping = new WebGLClipping(properties);
  14455. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14456. materials = new WebGLMaterials(properties);
  14457. renderLists = new WebGLRenderLists(properties);
  14458. renderStates = new WebGLRenderStates(extensions, capabilities);
  14459. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14460. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14461. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14462. info.programs = programCache.programs;
  14463. _this.capabilities = capabilities;
  14464. _this.extensions = extensions;
  14465. _this.properties = properties;
  14466. _this.renderLists = renderLists;
  14467. _this.state = state;
  14468. _this.info = info;
  14469. }
  14470. initGLContext(); // xr
  14471. var xr = new WebXRManager(_this, _gl);
  14472. this.xr = xr; // shadow map
  14473. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14474. this.shadowMap = shadowMap; // API
  14475. this.getContext = function () {
  14476. return _gl;
  14477. };
  14478. this.getContextAttributes = function () {
  14479. return _gl.getContextAttributes();
  14480. };
  14481. this.forceContextLoss = function () {
  14482. var extension = extensions.get('WEBGL_lose_context');
  14483. if (extension) extension.loseContext();
  14484. };
  14485. this.forceContextRestore = function () {
  14486. var extension = extensions.get('WEBGL_lose_context');
  14487. if (extension) extension.restoreContext();
  14488. };
  14489. this.getPixelRatio = function () {
  14490. return _pixelRatio;
  14491. };
  14492. this.setPixelRatio = function (value) {
  14493. if (value === undefined) return;
  14494. _pixelRatio = value;
  14495. this.setSize(_width, _height, false);
  14496. };
  14497. this.getSize = function (target) {
  14498. if (target === undefined) {
  14499. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14500. target = new Vector2();
  14501. }
  14502. return target.set(_width, _height);
  14503. };
  14504. this.setSize = function (width, height, updateStyle) {
  14505. if (xr.isPresenting) {
  14506. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14507. return;
  14508. }
  14509. _width = width;
  14510. _height = height;
  14511. _canvas.width = Math.floor(width * _pixelRatio);
  14512. _canvas.height = Math.floor(height * _pixelRatio);
  14513. if (updateStyle !== false) {
  14514. _canvas.style.width = width + 'px';
  14515. _canvas.style.height = height + 'px';
  14516. }
  14517. this.setViewport(0, 0, width, height);
  14518. };
  14519. this.getDrawingBufferSize = function (target) {
  14520. if (target === undefined) {
  14521. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14522. target = new Vector2();
  14523. }
  14524. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14525. };
  14526. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14527. _width = width;
  14528. _height = height;
  14529. _pixelRatio = pixelRatio;
  14530. _canvas.width = Math.floor(width * pixelRatio);
  14531. _canvas.height = Math.floor(height * pixelRatio);
  14532. this.setViewport(0, 0, width, height);
  14533. };
  14534. this.getCurrentViewport = function (target) {
  14535. if (target === undefined) {
  14536. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14537. target = new Vector4();
  14538. }
  14539. return target.copy(_currentViewport);
  14540. };
  14541. this.getViewport = function (target) {
  14542. return target.copy(_viewport);
  14543. };
  14544. this.setViewport = function (x, y, width, height) {
  14545. if (x.isVector4) {
  14546. _viewport.set(x.x, x.y, x.z, x.w);
  14547. } else {
  14548. _viewport.set(x, y, width, height);
  14549. }
  14550. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14551. };
  14552. this.getScissor = function (target) {
  14553. return target.copy(_scissor);
  14554. };
  14555. this.setScissor = function (x, y, width, height) {
  14556. if (x.isVector4) {
  14557. _scissor.set(x.x, x.y, x.z, x.w);
  14558. } else {
  14559. _scissor.set(x, y, width, height);
  14560. }
  14561. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14562. };
  14563. this.getScissorTest = function () {
  14564. return _scissorTest;
  14565. };
  14566. this.setScissorTest = function (boolean) {
  14567. state.setScissorTest(_scissorTest = boolean);
  14568. };
  14569. this.setOpaqueSort = function (method) {
  14570. _opaqueSort = method;
  14571. };
  14572. this.setTransparentSort = function (method) {
  14573. _transparentSort = method;
  14574. }; // Clearing
  14575. this.getClearColor = function () {
  14576. return background.getClearColor();
  14577. };
  14578. this.setClearColor = function () {
  14579. background.setClearColor.apply(background, arguments);
  14580. };
  14581. this.getClearAlpha = function () {
  14582. return background.getClearAlpha();
  14583. };
  14584. this.setClearAlpha = function () {
  14585. background.setClearAlpha.apply(background, arguments);
  14586. };
  14587. this.clear = function (color, depth, stencil) {
  14588. var bits = 0;
  14589. if (color === undefined || color) bits |= 16384;
  14590. if (depth === undefined || depth) bits |= 256;
  14591. if (stencil === undefined || stencil) bits |= 1024;
  14592. _gl.clear(bits);
  14593. };
  14594. this.clearColor = function () {
  14595. this.clear(true, false, false);
  14596. };
  14597. this.clearDepth = function () {
  14598. this.clear(false, true, false);
  14599. };
  14600. this.clearStencil = function () {
  14601. this.clear(false, false, true);
  14602. }; //
  14603. this.dispose = function () {
  14604. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14605. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14606. renderLists.dispose();
  14607. renderStates.dispose();
  14608. properties.dispose();
  14609. cubemaps.dispose();
  14610. objects.dispose();
  14611. bindingStates.dispose();
  14612. xr.dispose();
  14613. animation.stop();
  14614. }; // Events
  14615. function onContextLost(event) {
  14616. event.preventDefault();
  14617. console.log('THREE.WebGLRenderer: Context Lost.');
  14618. _isContextLost = true;
  14619. }
  14620. function onContextRestore()
  14621. /* event */
  14622. {
  14623. console.log('THREE.WebGLRenderer: Context Restored.');
  14624. _isContextLost = false;
  14625. initGLContext();
  14626. }
  14627. function onMaterialDispose(event) {
  14628. var material = event.target;
  14629. material.removeEventListener('dispose', onMaterialDispose);
  14630. deallocateMaterial(material);
  14631. } // Buffer deallocation
  14632. function deallocateMaterial(material) {
  14633. releaseMaterialProgramReference(material);
  14634. properties.remove(material);
  14635. }
  14636. function releaseMaterialProgramReference(material) {
  14637. var programInfo = properties.get(material).program;
  14638. if (programInfo !== undefined) {
  14639. programCache.releaseProgram(programInfo);
  14640. }
  14641. } // Buffer rendering
  14642. function renderObjectImmediate(object, program) {
  14643. object.render(function (object) {
  14644. _this.renderBufferImmediate(object, program);
  14645. });
  14646. }
  14647. this.renderBufferImmediate = function (object, program) {
  14648. bindingStates.initAttributes();
  14649. var buffers = properties.get(object);
  14650. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14651. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14652. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14653. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14654. var programAttributes = program.getAttributes();
  14655. if (object.hasPositions) {
  14656. _gl.bindBuffer(34962, buffers.position);
  14657. _gl.bufferData(34962, object.positionArray, 35048);
  14658. bindingStates.enableAttribute(programAttributes.position);
  14659. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14660. }
  14661. if (object.hasNormals) {
  14662. _gl.bindBuffer(34962, buffers.normal);
  14663. _gl.bufferData(34962, object.normalArray, 35048);
  14664. bindingStates.enableAttribute(programAttributes.normal);
  14665. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14666. }
  14667. if (object.hasUvs) {
  14668. _gl.bindBuffer(34962, buffers.uv);
  14669. _gl.bufferData(34962, object.uvArray, 35048);
  14670. bindingStates.enableAttribute(programAttributes.uv);
  14671. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14672. }
  14673. if (object.hasColors) {
  14674. _gl.bindBuffer(34962, buffers.color);
  14675. _gl.bufferData(34962, object.colorArray, 35048);
  14676. bindingStates.enableAttribute(programAttributes.color);
  14677. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14678. }
  14679. bindingStates.disableUnusedAttributes();
  14680. _gl.drawArrays(4, 0, object.count);
  14681. object.count = 0;
  14682. };
  14683. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14684. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14685. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14686. var program = setProgram(camera, scene, material, object);
  14687. state.setMaterial(material, frontFaceCW); //
  14688. var index = geometry.index;
  14689. var position = geometry.attributes.position; //
  14690. if (index === null) {
  14691. if (position === undefined || position.count === 0) return;
  14692. } else if (index.count === 0) {
  14693. return;
  14694. } //
  14695. var rangeFactor = 1;
  14696. if (material.wireframe === true) {
  14697. index = geometries.getWireframeAttribute(geometry);
  14698. rangeFactor = 2;
  14699. }
  14700. if (material.morphTargets || material.morphNormals) {
  14701. morphtargets.update(object, geometry, material, program);
  14702. }
  14703. bindingStates.setup(object, material, program, geometry, index);
  14704. var attribute;
  14705. var renderer = bufferRenderer;
  14706. if (index !== null) {
  14707. attribute = attributes.get(index);
  14708. renderer = indexedBufferRenderer;
  14709. renderer.setIndex(attribute);
  14710. } //
  14711. var dataCount = index !== null ? index.count : position.count;
  14712. var rangeStart = geometry.drawRange.start * rangeFactor;
  14713. var rangeCount = geometry.drawRange.count * rangeFactor;
  14714. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14715. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14716. var drawStart = Math.max(rangeStart, groupStart);
  14717. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14718. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14719. if (drawCount === 0) return; //
  14720. if (object.isMesh) {
  14721. if (material.wireframe === true) {
  14722. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14723. renderer.setMode(1);
  14724. } else {
  14725. renderer.setMode(4);
  14726. }
  14727. } else if (object.isLine) {
  14728. var lineWidth = material.linewidth;
  14729. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14730. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14731. if (object.isLineSegments) {
  14732. renderer.setMode(1);
  14733. } else if (object.isLineLoop) {
  14734. renderer.setMode(2);
  14735. } else {
  14736. renderer.setMode(3);
  14737. }
  14738. } else if (object.isPoints) {
  14739. renderer.setMode(0);
  14740. } else if (object.isSprite) {
  14741. renderer.setMode(4);
  14742. }
  14743. if (object.isInstancedMesh) {
  14744. renderer.renderInstances(drawStart, drawCount, object.count);
  14745. } else if (geometry.isInstancedBufferGeometry) {
  14746. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14747. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14748. } else {
  14749. renderer.render(drawStart, drawCount);
  14750. }
  14751. }; // Compile
  14752. this.compile = function (scene, camera) {
  14753. currentRenderState = renderStates.get(scene, camera);
  14754. currentRenderState.init();
  14755. scene.traverseVisible(function (object) {
  14756. if (object.isLight && object.layers.test(camera.layers)) {
  14757. currentRenderState.pushLight(object);
  14758. if (object.castShadow) {
  14759. currentRenderState.pushShadow(object);
  14760. }
  14761. }
  14762. });
  14763. currentRenderState.setupLights(camera);
  14764. var compiled = new WeakMap();
  14765. scene.traverse(function (object) {
  14766. var material = object.material;
  14767. if (material) {
  14768. if (Array.isArray(material)) {
  14769. for (var i = 0; i < material.length; i++) {
  14770. var material2 = material[i];
  14771. if (compiled.has(material2) === false) {
  14772. initMaterial(material2, scene, object);
  14773. compiled.set(material2);
  14774. }
  14775. }
  14776. } else if (compiled.has(material) === false) {
  14777. initMaterial(material, scene, object);
  14778. compiled.set(material);
  14779. }
  14780. }
  14781. });
  14782. }; // Animation Loop
  14783. var onAnimationFrameCallback = null;
  14784. function onAnimationFrame(time) {
  14785. if (xr.isPresenting) return;
  14786. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14787. }
  14788. var animation = new WebGLAnimation();
  14789. animation.setAnimationLoop(onAnimationFrame);
  14790. if (typeof window !== 'undefined') animation.setContext(window);
  14791. this.setAnimationLoop = function (callback) {
  14792. onAnimationFrameCallback = callback;
  14793. xr.setAnimationLoop(callback);
  14794. callback === null ? animation.stop() : animation.start();
  14795. }; // Rendering
  14796. this.render = function (scene, camera) {
  14797. var renderTarget, forceClear;
  14798. if (arguments[2] !== undefined) {
  14799. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14800. renderTarget = arguments[2];
  14801. }
  14802. if (arguments[3] !== undefined) {
  14803. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14804. forceClear = arguments[3];
  14805. }
  14806. if (camera !== undefined && camera.isCamera !== true) {
  14807. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14808. return;
  14809. }
  14810. if (_isContextLost === true) return; // reset caching for this frame
  14811. bindingStates.resetDefaultState();
  14812. _currentMaterialId = -1;
  14813. _currentCamera = null; // update scene graph
  14814. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14815. if (camera.parent === null) camera.updateMatrixWorld();
  14816. if (xr.enabled === true && xr.isPresenting === true) {
  14817. camera = xr.getCamera(camera);
  14818. } //
  14819. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14820. currentRenderState = renderStates.get(scene, camera);
  14821. currentRenderState.init();
  14822. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14823. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14824. _localClippingEnabled = this.localClippingEnabled;
  14825. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14826. currentRenderList = renderLists.get(scene, camera);
  14827. currentRenderList.init();
  14828. projectObject(scene, camera, 0, _this.sortObjects);
  14829. currentRenderList.finish();
  14830. if (_this.sortObjects === true) {
  14831. currentRenderList.sort(_opaqueSort, _transparentSort);
  14832. } //
  14833. if (_clippingEnabled === true) clipping.beginShadows();
  14834. var shadowsArray = currentRenderState.state.shadowsArray;
  14835. shadowMap.render(shadowsArray, scene, camera);
  14836. currentRenderState.setupLights(camera);
  14837. if (_clippingEnabled === true) clipping.endShadows(); //
  14838. if (this.info.autoReset === true) this.info.reset();
  14839. if (renderTarget !== undefined) {
  14840. this.setRenderTarget(renderTarget);
  14841. } //
  14842. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14843. var opaqueObjects = currentRenderList.opaque;
  14844. var transparentObjects = currentRenderList.transparent;
  14845. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14846. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14847. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14848. if (_currentRenderTarget !== null) {
  14849. // Generate mipmap if we're using any kind of mipmap filtering
  14850. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14851. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14852. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14853. state.buffers.depth.setTest(true);
  14854. state.buffers.depth.setMask(true);
  14855. state.buffers.color.setMask(true);
  14856. state.setPolygonOffset(false); // _gl.finish();
  14857. currentRenderList = null;
  14858. currentRenderState = null;
  14859. };
  14860. function projectObject(object, camera, groupOrder, sortObjects) {
  14861. if (object.visible === false) return;
  14862. var visible = object.layers.test(camera.layers);
  14863. if (visible) {
  14864. if (object.isGroup) {
  14865. groupOrder = object.renderOrder;
  14866. } else if (object.isLOD) {
  14867. if (object.autoUpdate === true) object.update(camera);
  14868. } else if (object.isLight) {
  14869. currentRenderState.pushLight(object);
  14870. if (object.castShadow) {
  14871. currentRenderState.pushShadow(object);
  14872. }
  14873. } else if (object.isSprite) {
  14874. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14875. if (sortObjects) {
  14876. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14877. }
  14878. var geometry = objects.update(object);
  14879. var material = object.material;
  14880. if (material.visible) {
  14881. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14882. }
  14883. }
  14884. } else if (object.isImmediateRenderObject) {
  14885. if (sortObjects) {
  14886. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14887. }
  14888. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14889. } else if (object.isMesh || object.isLine || object.isPoints) {
  14890. if (object.isSkinnedMesh) {
  14891. // update skeleton only once in a frame
  14892. if (object.skeleton.frame !== info.render.frame) {
  14893. object.skeleton.update();
  14894. object.skeleton.frame = info.render.frame;
  14895. }
  14896. }
  14897. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14898. if (sortObjects) {
  14899. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14900. }
  14901. var _geometry = objects.update(object);
  14902. var _material = object.material;
  14903. if (Array.isArray(_material)) {
  14904. var groups = _geometry.groups;
  14905. for (var i = 0, l = groups.length; i < l; i++) {
  14906. var group = groups[i];
  14907. var groupMaterial = _material[group.materialIndex];
  14908. if (groupMaterial && groupMaterial.visible) {
  14909. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14910. }
  14911. }
  14912. } else if (_material.visible) {
  14913. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14914. }
  14915. }
  14916. }
  14917. }
  14918. var children = object.children;
  14919. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14920. projectObject(children[_i], camera, groupOrder, sortObjects);
  14921. }
  14922. }
  14923. function renderObjects(renderList, scene, camera) {
  14924. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14925. for (var i = 0, l = renderList.length; i < l; i++) {
  14926. var renderItem = renderList[i];
  14927. var object = renderItem.object;
  14928. var geometry = renderItem.geometry;
  14929. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14930. var group = renderItem.group;
  14931. if (camera.isArrayCamera) {
  14932. _currentArrayCamera = camera;
  14933. var cameras = camera.cameras;
  14934. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14935. var camera2 = cameras[j];
  14936. if (object.layers.test(camera2.layers)) {
  14937. state.viewport(_currentViewport.copy(camera2.viewport));
  14938. currentRenderState.setupLights(camera2);
  14939. renderObject(object, scene, camera2, geometry, material, group);
  14940. }
  14941. }
  14942. } else {
  14943. _currentArrayCamera = null;
  14944. renderObject(object, scene, camera, geometry, material, group);
  14945. }
  14946. }
  14947. }
  14948. function renderObject(object, scene, camera, geometry, material, group) {
  14949. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14950. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14951. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14952. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14953. if (object.isImmediateRenderObject) {
  14954. var program = setProgram(camera, scene, material, object);
  14955. state.setMaterial(material);
  14956. bindingStates.reset();
  14957. renderObjectImmediate(object, program);
  14958. } else {
  14959. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14960. }
  14961. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14962. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14963. }
  14964. function initMaterial(material, scene, object) {
  14965. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14966. var materialProperties = properties.get(material);
  14967. var lights = currentRenderState.state.lights;
  14968. var shadowsArray = currentRenderState.state.shadowsArray;
  14969. var lightsStateVersion = lights.state.version;
  14970. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14971. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14972. var program = materialProperties.program;
  14973. var programChange = true;
  14974. if (program === undefined) {
  14975. // new material
  14976. material.addEventListener('dispose', onMaterialDispose);
  14977. } else if (program.cacheKey !== programCacheKey) {
  14978. // changed glsl or parameters
  14979. releaseMaterialProgramReference(material);
  14980. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14981. programChange = false;
  14982. } else if (parameters.shaderID !== undefined) {
  14983. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14984. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14985. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14986. return;
  14987. } else {
  14988. // only rebuild uniform list
  14989. programChange = false;
  14990. }
  14991. if (programChange) {
  14992. parameters.uniforms = programCache.getUniforms(material);
  14993. material.onBeforeCompile(parameters, _this);
  14994. program = programCache.acquireProgram(parameters, programCacheKey);
  14995. materialProperties.program = program;
  14996. materialProperties.uniforms = parameters.uniforms;
  14997. materialProperties.outputEncoding = parameters.outputEncoding;
  14998. }
  14999. var uniforms = materialProperties.uniforms;
  15000. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15001. materialProperties.numClippingPlanes = clipping.numPlanes;
  15002. materialProperties.numIntersection = clipping.numIntersection;
  15003. uniforms.clippingPlanes = clipping.uniform;
  15004. }
  15005. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15006. materialProperties.fog = scene.fog;
  15007. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  15008. materialProperties.needsLights = materialNeedsLights(material);
  15009. materialProperties.lightsStateVersion = lightsStateVersion;
  15010. if (materialProperties.needsLights) {
  15011. // wire up the material to this renderer's lighting state
  15012. uniforms.ambientLightColor.value = lights.state.ambient;
  15013. uniforms.lightProbe.value = lights.state.probe;
  15014. uniforms.directionalLights.value = lights.state.directional;
  15015. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15016. uniforms.spotLights.value = lights.state.spot;
  15017. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15018. uniforms.rectAreaLights.value = lights.state.rectArea;
  15019. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15020. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15021. uniforms.pointLights.value = lights.state.point;
  15022. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15023. uniforms.hemisphereLights.value = lights.state.hemi;
  15024. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15025. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15026. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15027. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15028. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15029. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15030. }
  15031. var progUniforms = materialProperties.program.getUniforms();
  15032. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15033. materialProperties.uniformsList = uniformsList;
  15034. }
  15035. function setProgram(camera, scene, material, object) {
  15036. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15037. textures.resetTextureUnits();
  15038. var fog = scene.fog;
  15039. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15040. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15041. var envMap = cubemaps.get(material.envMap || environment);
  15042. var materialProperties = properties.get(material);
  15043. var lights = currentRenderState.state.lights;
  15044. if (_clippingEnabled === true) {
  15045. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15046. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15047. // object instead of the material, once it becomes feasible
  15048. // (#8465, #8379)
  15049. clipping.setState(material, camera, useCache);
  15050. }
  15051. }
  15052. if (material.version === materialProperties.__version) {
  15053. if (material.fog && materialProperties.fog !== fog) {
  15054. initMaterial(material, scene, object);
  15055. } else if (materialProperties.environment !== environment) {
  15056. initMaterial(material, scene, object);
  15057. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15058. initMaterial(material, scene, object);
  15059. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15060. initMaterial(material, scene, object);
  15061. } else if (materialProperties.outputEncoding !== encoding) {
  15062. initMaterial(material, scene, object);
  15063. } else if (materialProperties.envMap !== envMap) {
  15064. initMaterial(material, scene, object);
  15065. }
  15066. } else {
  15067. initMaterial(material, scene, object);
  15068. materialProperties.__version = material.version;
  15069. }
  15070. var refreshProgram = false;
  15071. var refreshMaterial = false;
  15072. var refreshLights = false;
  15073. var program = materialProperties.program,
  15074. p_uniforms = program.getUniforms(),
  15075. m_uniforms = materialProperties.uniforms;
  15076. if (state.useProgram(program.program)) {
  15077. refreshProgram = true;
  15078. refreshMaterial = true;
  15079. refreshLights = true;
  15080. }
  15081. if (material.id !== _currentMaterialId) {
  15082. _currentMaterialId = material.id;
  15083. refreshMaterial = true;
  15084. }
  15085. if (refreshProgram || _currentCamera !== camera) {
  15086. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15087. if (capabilities.logarithmicDepthBuffer) {
  15088. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15089. }
  15090. if (_currentCamera !== camera) {
  15091. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15092. // now, in case this material supports lights - or later, when
  15093. // the next material that does gets activated:
  15094. refreshMaterial = true; // set to true on material change
  15095. refreshLights = true; // remains set until update done
  15096. } // load material specific uniforms
  15097. // (shader material also gets them for the sake of genericity)
  15098. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15099. var uCamPos = p_uniforms.map.cameraPosition;
  15100. if (uCamPos !== undefined) {
  15101. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15102. }
  15103. }
  15104. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15105. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15106. }
  15107. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15108. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15109. }
  15110. } // skinning uniforms must be set even if material didn't change
  15111. // auto-setting of texture unit for bone texture must go before other textures
  15112. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15113. if (material.skinning) {
  15114. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15115. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15116. var skeleton = object.skeleton;
  15117. if (skeleton) {
  15118. var bones = skeleton.bones;
  15119. if (capabilities.floatVertexTextures) {
  15120. if (skeleton.boneTexture === null) {
  15121. // layout (1 matrix = 4 pixels)
  15122. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15123. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15124. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15125. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15126. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15127. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15128. size = MathUtils.ceilPowerOfTwo(size);
  15129. size = Math.max(size, 4);
  15130. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15131. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15132. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15133. skeleton.boneMatrices = boneMatrices;
  15134. skeleton.boneTexture = boneTexture;
  15135. skeleton.boneTextureSize = size;
  15136. }
  15137. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15138. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15139. } else {
  15140. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15141. }
  15142. }
  15143. }
  15144. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15145. materialProperties.receiveShadow = object.receiveShadow;
  15146. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15147. }
  15148. if (refreshMaterial) {
  15149. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15150. if (materialProperties.needsLights) {
  15151. // the current material requires lighting info
  15152. // note: all lighting uniforms are always set correctly
  15153. // they simply reference the renderer's state for their
  15154. // values
  15155. //
  15156. // use the current material's .needsUpdate flags to set
  15157. // the GL state when required
  15158. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15159. } // refresh uniforms common to several materials
  15160. if (fog && material.fog) {
  15161. materials.refreshFogUniforms(m_uniforms, fog);
  15162. }
  15163. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15164. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15165. }
  15166. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15167. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15168. material.uniformsNeedUpdate = false;
  15169. }
  15170. if (material.isSpriteMaterial) {
  15171. p_uniforms.setValue(_gl, 'center', object.center);
  15172. } // common matrices
  15173. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15174. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15175. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15176. return program;
  15177. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15178. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15179. uniforms.ambientLightColor.needsUpdate = value;
  15180. uniforms.lightProbe.needsUpdate = value;
  15181. uniforms.directionalLights.needsUpdate = value;
  15182. uniforms.directionalLightShadows.needsUpdate = value;
  15183. uniforms.pointLights.needsUpdate = value;
  15184. uniforms.pointLightShadows.needsUpdate = value;
  15185. uniforms.spotLights.needsUpdate = value;
  15186. uniforms.spotLightShadows.needsUpdate = value;
  15187. uniforms.rectAreaLights.needsUpdate = value;
  15188. uniforms.hemisphereLights.needsUpdate = value;
  15189. }
  15190. function materialNeedsLights(material) {
  15191. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15192. } //
  15193. this.setFramebuffer = function (value) {
  15194. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15195. _framebuffer = value;
  15196. };
  15197. this.getActiveCubeFace = function () {
  15198. return _currentActiveCubeFace;
  15199. };
  15200. this.getActiveMipmapLevel = function () {
  15201. return _currentActiveMipmapLevel;
  15202. };
  15203. this.getRenderList = function () {
  15204. return currentRenderList;
  15205. };
  15206. this.setRenderList = function (renderList) {
  15207. currentRenderList = renderList;
  15208. };
  15209. this.getRenderState = function () {
  15210. return currentRenderState;
  15211. };
  15212. this.setRenderState = function (renderState) {
  15213. currentRenderState = renderState;
  15214. };
  15215. this.getRenderTarget = function () {
  15216. return _currentRenderTarget;
  15217. };
  15218. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15219. if (activeCubeFace === void 0) {
  15220. activeCubeFace = 0;
  15221. }
  15222. if (activeMipmapLevel === void 0) {
  15223. activeMipmapLevel = 0;
  15224. }
  15225. _currentRenderTarget = renderTarget;
  15226. _currentActiveCubeFace = activeCubeFace;
  15227. _currentActiveMipmapLevel = activeMipmapLevel;
  15228. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15229. textures.setupRenderTarget(renderTarget);
  15230. }
  15231. var framebuffer = _framebuffer;
  15232. var isCube = false;
  15233. if (renderTarget) {
  15234. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15235. if (renderTarget.isWebGLCubeRenderTarget) {
  15236. framebuffer = __webglFramebuffer[activeCubeFace];
  15237. isCube = true;
  15238. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15239. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15240. } else {
  15241. framebuffer = __webglFramebuffer;
  15242. }
  15243. _currentViewport.copy(renderTarget.viewport);
  15244. _currentScissor.copy(renderTarget.scissor);
  15245. _currentScissorTest = renderTarget.scissorTest;
  15246. } else {
  15247. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15248. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15249. _currentScissorTest = _scissorTest;
  15250. }
  15251. if (_currentFramebuffer !== framebuffer) {
  15252. _gl.bindFramebuffer(36160, framebuffer);
  15253. _currentFramebuffer = framebuffer;
  15254. }
  15255. state.viewport(_currentViewport);
  15256. state.scissor(_currentScissor);
  15257. state.setScissorTest(_currentScissorTest);
  15258. if (isCube) {
  15259. var textureProperties = properties.get(renderTarget.texture);
  15260. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15261. }
  15262. };
  15263. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15264. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15265. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15266. return;
  15267. }
  15268. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15269. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15270. framebuffer = framebuffer[activeCubeFaceIndex];
  15271. }
  15272. if (framebuffer) {
  15273. var restore = false;
  15274. if (framebuffer !== _currentFramebuffer) {
  15275. _gl.bindFramebuffer(36160, framebuffer);
  15276. restore = true;
  15277. }
  15278. try {
  15279. var texture = renderTarget.texture;
  15280. var textureFormat = texture.format;
  15281. var textureType = texture.type;
  15282. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15283. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15284. return;
  15285. }
  15286. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15287. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15288. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15289. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15290. return;
  15291. }
  15292. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15293. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15294. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15295. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15296. }
  15297. } else {
  15298. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15299. }
  15300. } finally {
  15301. if (restore) {
  15302. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15303. }
  15304. }
  15305. }
  15306. };
  15307. this.copyFramebufferToTexture = function (position, texture, level) {
  15308. if (level === void 0) {
  15309. level = 0;
  15310. }
  15311. var levelScale = Math.pow(2, -level);
  15312. var width = Math.floor(texture.image.width * levelScale);
  15313. var height = Math.floor(texture.image.height * levelScale);
  15314. var glFormat = utils.convert(texture.format);
  15315. textures.setTexture2D(texture, 0);
  15316. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15317. state.unbindTexture();
  15318. };
  15319. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15320. if (level === void 0) {
  15321. level = 0;
  15322. }
  15323. var width = srcTexture.image.width;
  15324. var height = srcTexture.image.height;
  15325. var glFormat = utils.convert(dstTexture.format);
  15326. var glType = utils.convert(dstTexture.type);
  15327. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15328. // parameters, make sure they are correct for the dstTexture
  15329. _gl.pixelStorei(37440, dstTexture.flipY);
  15330. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15331. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15332. if (srcTexture.isDataTexture) {
  15333. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15334. } else {
  15335. if (srcTexture.isCompressedTexture) {
  15336. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15337. } else {
  15338. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15339. }
  15340. } // Generate mipmaps only when copying level 0
  15341. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15342. state.unbindTexture();
  15343. };
  15344. this.initTexture = function (texture) {
  15345. textures.setTexture2D(texture, 0);
  15346. state.unbindTexture();
  15347. };
  15348. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15349. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15350. detail: this
  15351. })); // eslint-disable-line no-undef
  15352. }
  15353. }
  15354. function WebGL1Renderer(parameters) {
  15355. WebGLRenderer.call(this, parameters);
  15356. }
  15357. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15358. constructor: WebGL1Renderer,
  15359. isWebGL1Renderer: true
  15360. });
  15361. var FogExp2 = /*#__PURE__*/function () {
  15362. function FogExp2(color, density) {
  15363. Object.defineProperty(this, 'isFogExp2', {
  15364. value: true
  15365. });
  15366. this.name = '';
  15367. this.color = new Color(color);
  15368. this.density = density !== undefined ? density : 0.00025;
  15369. }
  15370. var _proto = FogExp2.prototype;
  15371. _proto.clone = function clone() {
  15372. return new FogExp2(this.color, this.density);
  15373. };
  15374. _proto.toJSON = function toJSON()
  15375. /* meta */
  15376. {
  15377. return {
  15378. type: 'FogExp2',
  15379. color: this.color.getHex(),
  15380. density: this.density
  15381. };
  15382. };
  15383. return FogExp2;
  15384. }();
  15385. var Fog = /*#__PURE__*/function () {
  15386. function Fog(color, near, far) {
  15387. Object.defineProperty(this, 'isFog', {
  15388. value: true
  15389. });
  15390. this.name = '';
  15391. this.color = new Color(color);
  15392. this.near = near !== undefined ? near : 1;
  15393. this.far = far !== undefined ? far : 1000;
  15394. }
  15395. var _proto = Fog.prototype;
  15396. _proto.clone = function clone() {
  15397. return new Fog(this.color, this.near, this.far);
  15398. };
  15399. _proto.toJSON = function toJSON()
  15400. /* meta */
  15401. {
  15402. return {
  15403. type: 'Fog',
  15404. color: this.color.getHex(),
  15405. near: this.near,
  15406. far: this.far
  15407. };
  15408. };
  15409. return Fog;
  15410. }();
  15411. var Scene = /*#__PURE__*/function (_Object3D) {
  15412. _inheritsLoose(Scene, _Object3D);
  15413. function Scene() {
  15414. var _this;
  15415. _this = _Object3D.call(this) || this;
  15416. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15417. value: true
  15418. });
  15419. _this.type = 'Scene';
  15420. _this.background = null;
  15421. _this.environment = null;
  15422. _this.fog = null;
  15423. _this.overrideMaterial = null;
  15424. _this.autoUpdate = true; // checked by the renderer
  15425. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15426. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15427. detail: _assertThisInitialized(_this)
  15428. })); // eslint-disable-line no-undef
  15429. }
  15430. return _this;
  15431. }
  15432. var _proto = Scene.prototype;
  15433. _proto.copy = function copy(source, recursive) {
  15434. _Object3D.prototype.copy.call(this, source, recursive);
  15435. if (source.background !== null) this.background = source.background.clone();
  15436. if (source.environment !== null) this.environment = source.environment.clone();
  15437. if (source.fog !== null) this.fog = source.fog.clone();
  15438. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15439. this.autoUpdate = source.autoUpdate;
  15440. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15441. return this;
  15442. };
  15443. _proto.toJSON = function toJSON(meta) {
  15444. var data = _Object3D.prototype.toJSON.call(this, meta);
  15445. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15446. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15447. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15448. return data;
  15449. };
  15450. return Scene;
  15451. }(Object3D);
  15452. function InterleavedBuffer(array, stride) {
  15453. this.array = array;
  15454. this.stride = stride;
  15455. this.count = array !== undefined ? array.length / stride : 0;
  15456. this.usage = StaticDrawUsage;
  15457. this.updateRange = {
  15458. offset: 0,
  15459. count: -1
  15460. };
  15461. this.version = 0;
  15462. this.uuid = MathUtils.generateUUID();
  15463. }
  15464. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15465. set: function set(value) {
  15466. if (value === true) this.version++;
  15467. }
  15468. });
  15469. Object.assign(InterleavedBuffer.prototype, {
  15470. isInterleavedBuffer: true,
  15471. onUploadCallback: function onUploadCallback() {},
  15472. setUsage: function setUsage(value) {
  15473. this.usage = value;
  15474. return this;
  15475. },
  15476. copy: function copy(source) {
  15477. this.array = new source.array.constructor(source.array);
  15478. this.count = source.count;
  15479. this.stride = source.stride;
  15480. this.usage = source.usage;
  15481. return this;
  15482. },
  15483. copyAt: function copyAt(index1, attribute, index2) {
  15484. index1 *= this.stride;
  15485. index2 *= attribute.stride;
  15486. for (var i = 0, l = this.stride; i < l; i++) {
  15487. this.array[index1 + i] = attribute.array[index2 + i];
  15488. }
  15489. return this;
  15490. },
  15491. set: function set(value, offset) {
  15492. if (offset === void 0) {
  15493. offset = 0;
  15494. }
  15495. this.array.set(value, offset);
  15496. return this;
  15497. },
  15498. clone: function clone(data) {
  15499. if (data.arrayBuffers === undefined) {
  15500. data.arrayBuffers = {};
  15501. }
  15502. if (this.array.buffer._uuid === undefined) {
  15503. this.array.buffer._uuid = MathUtils.generateUUID();
  15504. }
  15505. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15506. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15507. }
  15508. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15509. var ib = new InterleavedBuffer(array, this.stride);
  15510. ib.setUsage(this.usage);
  15511. return ib;
  15512. },
  15513. onUpload: function onUpload(callback) {
  15514. this.onUploadCallback = callback;
  15515. return this;
  15516. },
  15517. toJSON: function toJSON(data) {
  15518. if (data.arrayBuffers === undefined) {
  15519. data.arrayBuffers = {};
  15520. } // generate UUID for array buffer if necessary
  15521. if (this.array.buffer._uuid === undefined) {
  15522. this.array.buffer._uuid = MathUtils.generateUUID();
  15523. }
  15524. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15525. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15526. } //
  15527. return {
  15528. uuid: this.uuid,
  15529. buffer: this.array.buffer._uuid,
  15530. type: this.array.constructor.name,
  15531. stride: this.stride
  15532. };
  15533. }
  15534. });
  15535. var _vector$6 = new Vector3();
  15536. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15537. this.name = '';
  15538. this.data = interleavedBuffer;
  15539. this.itemSize = itemSize;
  15540. this.offset = offset;
  15541. this.normalized = normalized === true;
  15542. }
  15543. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15544. count: {
  15545. get: function get() {
  15546. return this.data.count;
  15547. }
  15548. },
  15549. array: {
  15550. get: function get() {
  15551. return this.data.array;
  15552. }
  15553. },
  15554. needsUpdate: {
  15555. set: function set(value) {
  15556. this.data.needsUpdate = value;
  15557. }
  15558. }
  15559. });
  15560. Object.assign(InterleavedBufferAttribute.prototype, {
  15561. isInterleavedBufferAttribute: true,
  15562. applyMatrix4: function applyMatrix4(m) {
  15563. for (var i = 0, l = this.data.count; i < l; i++) {
  15564. _vector$6.x = this.getX(i);
  15565. _vector$6.y = this.getY(i);
  15566. _vector$6.z = this.getZ(i);
  15567. _vector$6.applyMatrix4(m);
  15568. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15569. }
  15570. return this;
  15571. },
  15572. setX: function setX(index, x) {
  15573. this.data.array[index * this.data.stride + this.offset] = x;
  15574. return this;
  15575. },
  15576. setY: function setY(index, y) {
  15577. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15578. return this;
  15579. },
  15580. setZ: function setZ(index, z) {
  15581. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15582. return this;
  15583. },
  15584. setW: function setW(index, w) {
  15585. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15586. return this;
  15587. },
  15588. getX: function getX(index) {
  15589. return this.data.array[index * this.data.stride + this.offset];
  15590. },
  15591. getY: function getY(index) {
  15592. return this.data.array[index * this.data.stride + this.offset + 1];
  15593. },
  15594. getZ: function getZ(index) {
  15595. return this.data.array[index * this.data.stride + this.offset + 2];
  15596. },
  15597. getW: function getW(index) {
  15598. return this.data.array[index * this.data.stride + this.offset + 3];
  15599. },
  15600. setXY: function setXY(index, x, y) {
  15601. index = index * this.data.stride + this.offset;
  15602. this.data.array[index + 0] = x;
  15603. this.data.array[index + 1] = y;
  15604. return this;
  15605. },
  15606. setXYZ: function setXYZ(index, x, y, z) {
  15607. index = index * this.data.stride + this.offset;
  15608. this.data.array[index + 0] = x;
  15609. this.data.array[index + 1] = y;
  15610. this.data.array[index + 2] = z;
  15611. return this;
  15612. },
  15613. setXYZW: function setXYZW(index, x, y, z, w) {
  15614. index = index * this.data.stride + this.offset;
  15615. this.data.array[index + 0] = x;
  15616. this.data.array[index + 1] = y;
  15617. this.data.array[index + 2] = z;
  15618. this.data.array[index + 3] = w;
  15619. return this;
  15620. },
  15621. clone: function clone(data) {
  15622. if (data === undefined) {
  15623. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15624. var array = [];
  15625. for (var i = 0; i < this.count; i++) {
  15626. var index = i * this.data.stride + this.offset;
  15627. for (var j = 0; j < this.itemSize; j++) {
  15628. array.push(this.data.array[index + j]);
  15629. }
  15630. }
  15631. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15632. } else {
  15633. if (data.interleavedBuffers === undefined) {
  15634. data.interleavedBuffers = {};
  15635. }
  15636. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15637. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15638. }
  15639. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15640. }
  15641. },
  15642. toJSON: function toJSON(data) {
  15643. if (data === undefined) {
  15644. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15645. var array = [];
  15646. for (var i = 0; i < this.count; i++) {
  15647. var index = i * this.data.stride + this.offset;
  15648. for (var j = 0; j < this.itemSize; j++) {
  15649. array.push(this.data.array[index + j]);
  15650. }
  15651. } // deinterleave data and save it as an ordinary buffer attribute for now
  15652. return {
  15653. itemSize: this.itemSize,
  15654. type: this.array.constructor.name,
  15655. array: array,
  15656. normalized: this.normalized
  15657. };
  15658. } else {
  15659. // save as true interlaved attribtue
  15660. if (data.interleavedBuffers === undefined) {
  15661. data.interleavedBuffers = {};
  15662. }
  15663. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15664. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15665. }
  15666. return {
  15667. isInterleavedBufferAttribute: true,
  15668. itemSize: this.itemSize,
  15669. data: this.data.uuid,
  15670. offset: this.offset,
  15671. normalized: this.normalized
  15672. };
  15673. }
  15674. }
  15675. });
  15676. /**
  15677. * parameters = {
  15678. * color: <hex>,
  15679. * map: new THREE.Texture( <Image> ),
  15680. * alphaMap: new THREE.Texture( <Image> ),
  15681. * rotation: <float>,
  15682. * sizeAttenuation: <bool>
  15683. * }
  15684. */
  15685. function SpriteMaterial(parameters) {
  15686. Material.call(this);
  15687. this.type = 'SpriteMaterial';
  15688. this.color = new Color(0xffffff);
  15689. this.map = null;
  15690. this.alphaMap = null;
  15691. this.rotation = 0;
  15692. this.sizeAttenuation = true;
  15693. this.transparent = true;
  15694. this.setValues(parameters);
  15695. }
  15696. SpriteMaterial.prototype = Object.create(Material.prototype);
  15697. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15698. SpriteMaterial.prototype.isSpriteMaterial = true;
  15699. SpriteMaterial.prototype.copy = function (source) {
  15700. Material.prototype.copy.call(this, source);
  15701. this.color.copy(source.color);
  15702. this.map = source.map;
  15703. this.alphaMap = source.alphaMap;
  15704. this.rotation = source.rotation;
  15705. this.sizeAttenuation = source.sizeAttenuation;
  15706. return this;
  15707. };
  15708. var _geometry;
  15709. var _intersectPoint = new Vector3();
  15710. var _worldScale = new Vector3();
  15711. var _mvPosition = new Vector3();
  15712. var _alignedPosition = new Vector2();
  15713. var _rotatedPosition = new Vector2();
  15714. var _viewWorldMatrix = new Matrix4();
  15715. var _vA$1 = new Vector3();
  15716. var _vB$1 = new Vector3();
  15717. var _vC$1 = new Vector3();
  15718. var _uvA$1 = new Vector2();
  15719. var _uvB$1 = new Vector2();
  15720. var _uvC$1 = new Vector2();
  15721. function Sprite(material) {
  15722. Object3D.call(this);
  15723. this.type = 'Sprite';
  15724. if (_geometry === undefined) {
  15725. _geometry = new BufferGeometry();
  15726. 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]);
  15727. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15728. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15729. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15730. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15731. }
  15732. this.geometry = _geometry;
  15733. this.material = material !== undefined ? material : new SpriteMaterial();
  15734. this.center = new Vector2(0.5, 0.5);
  15735. }
  15736. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15737. constructor: Sprite,
  15738. isSprite: true,
  15739. raycast: function raycast(raycaster, intersects) {
  15740. if (raycaster.camera === null) {
  15741. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15742. }
  15743. _worldScale.setFromMatrixScale(this.matrixWorld);
  15744. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15745. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15746. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15747. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15748. _worldScale.multiplyScalar(-_mvPosition.z);
  15749. }
  15750. var rotation = this.material.rotation;
  15751. var sin, cos;
  15752. if (rotation !== 0) {
  15753. cos = Math.cos(rotation);
  15754. sin = Math.sin(rotation);
  15755. }
  15756. var center = this.center;
  15757. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15758. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15759. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15760. _uvA$1.set(0, 0);
  15761. _uvB$1.set(1, 0);
  15762. _uvC$1.set(1, 1); // check first triangle
  15763. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15764. if (intersect === null) {
  15765. // check second triangle
  15766. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15767. _uvB$1.set(0, 1);
  15768. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15769. if (intersect === null) {
  15770. return;
  15771. }
  15772. }
  15773. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15774. if (distance < raycaster.near || distance > raycaster.far) return;
  15775. intersects.push({
  15776. distance: distance,
  15777. point: _intersectPoint.clone(),
  15778. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15779. face: null,
  15780. object: this
  15781. });
  15782. },
  15783. copy: function copy(source) {
  15784. Object3D.prototype.copy.call(this, source);
  15785. if (source.center !== undefined) this.center.copy(source.center);
  15786. this.material = source.material;
  15787. return this;
  15788. }
  15789. });
  15790. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15791. // compute position in camera space
  15792. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15793. if (sin !== undefined) {
  15794. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15795. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15796. } else {
  15797. _rotatedPosition.copy(_alignedPosition);
  15798. }
  15799. vertexPosition.copy(mvPosition);
  15800. vertexPosition.x += _rotatedPosition.x;
  15801. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15802. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15803. }
  15804. var _v1$4 = new Vector3();
  15805. var _v2$2 = new Vector3();
  15806. function LOD() {
  15807. Object3D.call(this);
  15808. this._currentLevel = 0;
  15809. this.type = 'LOD';
  15810. Object.defineProperties(this, {
  15811. levels: {
  15812. enumerable: true,
  15813. value: []
  15814. }
  15815. });
  15816. this.autoUpdate = true;
  15817. }
  15818. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15819. constructor: LOD,
  15820. isLOD: true,
  15821. copy: function copy(source) {
  15822. Object3D.prototype.copy.call(this, source, false);
  15823. var levels = source.levels;
  15824. for (var i = 0, l = levels.length; i < l; i++) {
  15825. var level = levels[i];
  15826. this.addLevel(level.object.clone(), level.distance);
  15827. }
  15828. this.autoUpdate = source.autoUpdate;
  15829. return this;
  15830. },
  15831. addLevel: function addLevel(object, distance) {
  15832. if (distance === void 0) {
  15833. distance = 0;
  15834. }
  15835. distance = Math.abs(distance);
  15836. var levels = this.levels;
  15837. var l;
  15838. for (l = 0; l < levels.length; l++) {
  15839. if (distance < levels[l].distance) {
  15840. break;
  15841. }
  15842. }
  15843. levels.splice(l, 0, {
  15844. distance: distance,
  15845. object: object
  15846. });
  15847. this.add(object);
  15848. return this;
  15849. },
  15850. getCurrentLevel: function getCurrentLevel() {
  15851. return this._currentLevel;
  15852. },
  15853. getObjectForDistance: function getObjectForDistance(distance) {
  15854. var levels = this.levels;
  15855. if (levels.length > 0) {
  15856. var i, l;
  15857. for (i = 1, l = levels.length; i < l; i++) {
  15858. if (distance < levels[i].distance) {
  15859. break;
  15860. }
  15861. }
  15862. return levels[i - 1].object;
  15863. }
  15864. return null;
  15865. },
  15866. raycast: function raycast(raycaster, intersects) {
  15867. var levels = this.levels;
  15868. if (levels.length > 0) {
  15869. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15870. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15871. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15872. }
  15873. },
  15874. update: function update(camera) {
  15875. var levels = this.levels;
  15876. if (levels.length > 1) {
  15877. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15878. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15879. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15880. levels[0].object.visible = true;
  15881. var i, l;
  15882. for (i = 1, l = levels.length; i < l; i++) {
  15883. if (distance >= levels[i].distance) {
  15884. levels[i - 1].object.visible = false;
  15885. levels[i].object.visible = true;
  15886. } else {
  15887. break;
  15888. }
  15889. }
  15890. this._currentLevel = i - 1;
  15891. for (; i < l; i++) {
  15892. levels[i].object.visible = false;
  15893. }
  15894. }
  15895. },
  15896. toJSON: function toJSON(meta) {
  15897. var data = Object3D.prototype.toJSON.call(this, meta);
  15898. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15899. data.object.levels = [];
  15900. var levels = this.levels;
  15901. for (var i = 0, l = levels.length; i < l; i++) {
  15902. var level = levels[i];
  15903. data.object.levels.push({
  15904. object: level.object.uuid,
  15905. distance: level.distance
  15906. });
  15907. }
  15908. return data;
  15909. }
  15910. });
  15911. function SkinnedMesh(geometry, material) {
  15912. if (geometry && geometry.isGeometry) {
  15913. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15914. }
  15915. Mesh.call(this, geometry, material);
  15916. this.type = 'SkinnedMesh';
  15917. this.bindMode = 'attached';
  15918. this.bindMatrix = new Matrix4();
  15919. this.bindMatrixInverse = new Matrix4();
  15920. }
  15921. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15922. constructor: SkinnedMesh,
  15923. isSkinnedMesh: true,
  15924. copy: function copy(source) {
  15925. Mesh.prototype.copy.call(this, source);
  15926. this.bindMode = source.bindMode;
  15927. this.bindMatrix.copy(source.bindMatrix);
  15928. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15929. this.skeleton = source.skeleton;
  15930. return this;
  15931. },
  15932. bind: function bind(skeleton, bindMatrix) {
  15933. this.skeleton = skeleton;
  15934. if (bindMatrix === undefined) {
  15935. this.updateMatrixWorld(true);
  15936. this.skeleton.calculateInverses();
  15937. bindMatrix = this.matrixWorld;
  15938. }
  15939. this.bindMatrix.copy(bindMatrix);
  15940. this.bindMatrixInverse.copy(bindMatrix).invert();
  15941. },
  15942. pose: function pose() {
  15943. this.skeleton.pose();
  15944. },
  15945. normalizeSkinWeights: function normalizeSkinWeights() {
  15946. var vector = new Vector4();
  15947. var skinWeight = this.geometry.attributes.skinWeight;
  15948. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15949. vector.x = skinWeight.getX(i);
  15950. vector.y = skinWeight.getY(i);
  15951. vector.z = skinWeight.getZ(i);
  15952. vector.w = skinWeight.getW(i);
  15953. var scale = 1.0 / vector.manhattanLength();
  15954. if (scale !== Infinity) {
  15955. vector.multiplyScalar(scale);
  15956. } else {
  15957. vector.set(1, 0, 0, 0); // do something reasonable
  15958. }
  15959. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15960. }
  15961. },
  15962. updateMatrixWorld: function updateMatrixWorld(force) {
  15963. Mesh.prototype.updateMatrixWorld.call(this, force);
  15964. if (this.bindMode === 'attached') {
  15965. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  15966. } else if (this.bindMode === 'detached') {
  15967. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  15968. } else {
  15969. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15970. }
  15971. },
  15972. boneTransform: function () {
  15973. var basePosition = new Vector3();
  15974. var skinIndex = new Vector4();
  15975. var skinWeight = new Vector4();
  15976. var vector = new Vector3();
  15977. var matrix = new Matrix4();
  15978. return function (index, target) {
  15979. var skeleton = this.skeleton;
  15980. var geometry = this.geometry;
  15981. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15982. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15983. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15984. target.set(0, 0, 0);
  15985. for (var i = 0; i < 4; i++) {
  15986. var weight = skinWeight.getComponent(i);
  15987. if (weight !== 0) {
  15988. var boneIndex = skinIndex.getComponent(i);
  15989. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15990. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15991. }
  15992. }
  15993. return target.applyMatrix4(this.bindMatrixInverse);
  15994. };
  15995. }()
  15996. });
  15997. function Bone() {
  15998. Object3D.call(this);
  15999. this.type = 'Bone';
  16000. }
  16001. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16002. constructor: Bone,
  16003. isBone: true
  16004. });
  16005. var _offsetMatrix = new Matrix4();
  16006. var _identityMatrix = new Matrix4();
  16007. function Skeleton(bones, boneInverses) {
  16008. if (bones === void 0) {
  16009. bones = [];
  16010. }
  16011. if (boneInverses === void 0) {
  16012. boneInverses = [];
  16013. }
  16014. this.uuid = MathUtils.generateUUID();
  16015. this.bones = bones.slice(0);
  16016. this.boneInverses = boneInverses;
  16017. this.boneMatrices = null;
  16018. this.boneTexture = null;
  16019. this.boneTextureSize = 0;
  16020. this.frame = -1;
  16021. this.init();
  16022. }
  16023. Object.assign(Skeleton.prototype, {
  16024. init: function init() {
  16025. var bones = this.bones;
  16026. var boneInverses = this.boneInverses;
  16027. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16028. if (boneInverses.length === 0) {
  16029. this.calculateInverses();
  16030. } else {
  16031. // handle special case
  16032. if (bones.length !== boneInverses.length) {
  16033. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16034. this.boneInverses = [];
  16035. for (var i = 0, il = this.bones.length; i < il; i++) {
  16036. this.boneInverses.push(new Matrix4());
  16037. }
  16038. }
  16039. }
  16040. },
  16041. calculateInverses: function calculateInverses() {
  16042. this.boneInverses.length = 0;
  16043. for (var i = 0, il = this.bones.length; i < il; i++) {
  16044. var inverse = new Matrix4();
  16045. if (this.bones[i]) {
  16046. inverse.copy(this.bones[i].matrixWorld).invert();
  16047. }
  16048. this.boneInverses.push(inverse);
  16049. }
  16050. },
  16051. pose: function pose() {
  16052. // recover the bind-time world matrices
  16053. for (var i = 0, il = this.bones.length; i < il; i++) {
  16054. var bone = this.bones[i];
  16055. if (bone) {
  16056. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16057. }
  16058. } // compute the local matrices, positions, rotations and scales
  16059. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16060. var _bone = this.bones[_i];
  16061. if (_bone) {
  16062. if (_bone.parent && _bone.parent.isBone) {
  16063. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16064. _bone.matrix.multiply(_bone.matrixWorld);
  16065. } else {
  16066. _bone.matrix.copy(_bone.matrixWorld);
  16067. }
  16068. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16069. }
  16070. }
  16071. },
  16072. update: function update() {
  16073. var bones = this.bones;
  16074. var boneInverses = this.boneInverses;
  16075. var boneMatrices = this.boneMatrices;
  16076. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16077. for (var i = 0, il = bones.length; i < il; i++) {
  16078. // compute the offset between the current and the original transform
  16079. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16080. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16081. _offsetMatrix.toArray(boneMatrices, i * 16);
  16082. }
  16083. if (boneTexture !== null) {
  16084. boneTexture.needsUpdate = true;
  16085. }
  16086. },
  16087. clone: function clone() {
  16088. return new Skeleton(this.bones, this.boneInverses);
  16089. },
  16090. getBoneByName: function getBoneByName(name) {
  16091. for (var i = 0, il = this.bones.length; i < il; i++) {
  16092. var bone = this.bones[i];
  16093. if (bone.name === name) {
  16094. return bone;
  16095. }
  16096. }
  16097. return undefined;
  16098. },
  16099. dispose: function dispose() {
  16100. if (this.boneTexture !== null) {
  16101. this.boneTexture.dispose();
  16102. this.boneTexture = null;
  16103. }
  16104. },
  16105. fromJSON: function fromJSON(json, bones) {
  16106. this.uuid = json.uuid;
  16107. for (var i = 0, l = json.bones.length; i < l; i++) {
  16108. var uuid = json.bones[i];
  16109. var bone = bones[uuid];
  16110. if (bone === undefined) {
  16111. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16112. bone = new Bone();
  16113. }
  16114. this.bones.push(bone);
  16115. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16116. }
  16117. this.init();
  16118. return this;
  16119. },
  16120. toJSON: function toJSON() {
  16121. var data = {
  16122. metadata: {
  16123. version: 4.5,
  16124. type: 'Skeleton',
  16125. generator: 'Skeleton.toJSON'
  16126. },
  16127. bones: [],
  16128. boneInverses: []
  16129. };
  16130. data.uuid = this.uuid;
  16131. var bones = this.bones;
  16132. var boneInverses = this.boneInverses;
  16133. for (var i = 0, l = bones.length; i < l; i++) {
  16134. var bone = bones[i];
  16135. data.bones.push(bone.uuid);
  16136. var boneInverse = boneInverses[i];
  16137. data.boneInverses.push(boneInverse.toArray());
  16138. }
  16139. return data;
  16140. }
  16141. });
  16142. var _instanceLocalMatrix = new Matrix4();
  16143. var _instanceWorldMatrix = new Matrix4();
  16144. var _instanceIntersects = [];
  16145. var _mesh = new Mesh();
  16146. function InstancedMesh(geometry, material, count) {
  16147. Mesh.call(this, geometry, material);
  16148. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16149. this.instanceColor = null;
  16150. this.count = count;
  16151. this.frustumCulled = false;
  16152. }
  16153. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16154. constructor: InstancedMesh,
  16155. isInstancedMesh: true,
  16156. copy: function copy(source) {
  16157. Mesh.prototype.copy.call(this, source);
  16158. this.instanceMatrix.copy(source.instanceMatrix);
  16159. this.count = source.count;
  16160. return this;
  16161. },
  16162. getColorAt: function getColorAt(index, color) {
  16163. color.fromArray(this.instanceColor.array, index * 3);
  16164. },
  16165. getMatrixAt: function getMatrixAt(index, matrix) {
  16166. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16167. },
  16168. raycast: function raycast(raycaster, intersects) {
  16169. var matrixWorld = this.matrixWorld;
  16170. var raycastTimes = this.count;
  16171. _mesh.geometry = this.geometry;
  16172. _mesh.material = this.material;
  16173. if (_mesh.material === undefined) return;
  16174. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16175. // calculate the world matrix for each instance
  16176. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16177. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16178. _mesh.matrixWorld = _instanceWorldMatrix;
  16179. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16180. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16181. var intersect = _instanceIntersects[i];
  16182. intersect.instanceId = instanceId;
  16183. intersect.object = this;
  16184. intersects.push(intersect);
  16185. }
  16186. _instanceIntersects.length = 0;
  16187. }
  16188. },
  16189. setColorAt: function setColorAt(index, color) {
  16190. if (this.instanceColor === null) {
  16191. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16192. }
  16193. color.toArray(this.instanceColor.array, index * 3);
  16194. },
  16195. setMatrixAt: function setMatrixAt(index, matrix) {
  16196. matrix.toArray(this.instanceMatrix.array, index * 16);
  16197. },
  16198. updateMorphTargets: function updateMorphTargets() {}
  16199. });
  16200. /**
  16201. * parameters = {
  16202. * color: <hex>,
  16203. * opacity: <float>,
  16204. *
  16205. * linewidth: <float>,
  16206. * linecap: "round",
  16207. * linejoin: "round"
  16208. * }
  16209. */
  16210. function LineBasicMaterial(parameters) {
  16211. Material.call(this);
  16212. this.type = 'LineBasicMaterial';
  16213. this.color = new Color(0xffffff);
  16214. this.linewidth = 1;
  16215. this.linecap = 'round';
  16216. this.linejoin = 'round';
  16217. this.morphTargets = false;
  16218. this.setValues(parameters);
  16219. }
  16220. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16221. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16222. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16223. LineBasicMaterial.prototype.copy = function (source) {
  16224. Material.prototype.copy.call(this, source);
  16225. this.color.copy(source.color);
  16226. this.linewidth = source.linewidth;
  16227. this.linecap = source.linecap;
  16228. this.linejoin = source.linejoin;
  16229. this.morphTargets = source.morphTargets;
  16230. return this;
  16231. };
  16232. var _start = new Vector3();
  16233. var _end = new Vector3();
  16234. var _inverseMatrix$1 = new Matrix4();
  16235. var _ray$1 = new Ray();
  16236. var _sphere$2 = new Sphere();
  16237. function Line(geometry, material, mode) {
  16238. if (mode === 1) {
  16239. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  16240. }
  16241. Object3D.call(this);
  16242. this.type = 'Line';
  16243. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16244. this.material = material !== undefined ? material : new LineBasicMaterial();
  16245. this.updateMorphTargets();
  16246. }
  16247. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16248. constructor: Line,
  16249. isLine: true,
  16250. copy: function copy(source) {
  16251. Object3D.prototype.copy.call(this, source);
  16252. this.material = source.material;
  16253. this.geometry = source.geometry;
  16254. return this;
  16255. },
  16256. computeLineDistances: function computeLineDistances() {
  16257. var geometry = this.geometry;
  16258. if (geometry.isBufferGeometry) {
  16259. // we assume non-indexed geometry
  16260. if (geometry.index === null) {
  16261. var positionAttribute = geometry.attributes.position;
  16262. var lineDistances = [0];
  16263. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16264. _start.fromBufferAttribute(positionAttribute, i - 1);
  16265. _end.fromBufferAttribute(positionAttribute, i);
  16266. lineDistances[i] = lineDistances[i - 1];
  16267. lineDistances[i] += _start.distanceTo(_end);
  16268. }
  16269. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16270. } else {
  16271. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16272. }
  16273. } else if (geometry.isGeometry) {
  16274. var vertices = geometry.vertices;
  16275. var _lineDistances = geometry.lineDistances;
  16276. _lineDistances[0] = 0;
  16277. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16278. _lineDistances[_i] = _lineDistances[_i - 1];
  16279. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16280. }
  16281. }
  16282. return this;
  16283. },
  16284. raycast: function raycast(raycaster, intersects) {
  16285. var geometry = this.geometry;
  16286. var matrixWorld = this.matrixWorld;
  16287. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16288. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16289. _sphere$2.copy(geometry.boundingSphere);
  16290. _sphere$2.applyMatrix4(matrixWorld);
  16291. _sphere$2.radius += threshold;
  16292. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16293. _inverseMatrix$1.copy(matrixWorld).invert();
  16294. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16295. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16296. var localThresholdSq = localThreshold * localThreshold;
  16297. var vStart = new Vector3();
  16298. var vEnd = new Vector3();
  16299. var interSegment = new Vector3();
  16300. var interRay = new Vector3();
  16301. var step = this.isLineSegments ? 2 : 1;
  16302. if (geometry.isBufferGeometry) {
  16303. var index = geometry.index;
  16304. var attributes = geometry.attributes;
  16305. var positionAttribute = attributes.position;
  16306. if (index !== null) {
  16307. var indices = index.array;
  16308. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16309. var a = indices[i];
  16310. var b = indices[i + 1];
  16311. vStart.fromBufferAttribute(positionAttribute, a);
  16312. vEnd.fromBufferAttribute(positionAttribute, b);
  16313. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16314. if (distSq > localThresholdSq) continue;
  16315. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16316. var distance = raycaster.ray.origin.distanceTo(interRay);
  16317. if (distance < raycaster.near || distance > raycaster.far) continue;
  16318. intersects.push({
  16319. distance: distance,
  16320. // What do we want? intersection point on the ray or on the segment??
  16321. // point: raycaster.ray.at( distance ),
  16322. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16323. index: i,
  16324. face: null,
  16325. faceIndex: null,
  16326. object: this
  16327. });
  16328. }
  16329. } else {
  16330. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16331. vStart.fromBufferAttribute(positionAttribute, _i2);
  16332. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16333. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16334. if (_distSq > localThresholdSq) continue;
  16335. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16336. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16337. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16338. intersects.push({
  16339. distance: _distance,
  16340. // What do we want? intersection point on the ray or on the segment??
  16341. // point: raycaster.ray.at( distance ),
  16342. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16343. index: _i2,
  16344. face: null,
  16345. faceIndex: null,
  16346. object: this
  16347. });
  16348. }
  16349. }
  16350. } else if (geometry.isGeometry) {
  16351. var vertices = geometry.vertices;
  16352. var nbVertices = vertices.length;
  16353. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16354. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16355. if (_distSq2 > localThresholdSq) continue;
  16356. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16357. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16358. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16359. intersects.push({
  16360. distance: _distance2,
  16361. // What do we want? intersection point on the ray or on the segment??
  16362. // point: raycaster.ray.at( distance ),
  16363. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16364. index: _i3,
  16365. face: null,
  16366. faceIndex: null,
  16367. object: this
  16368. });
  16369. }
  16370. }
  16371. },
  16372. updateMorphTargets: function updateMorphTargets() {
  16373. var geometry = this.geometry;
  16374. if (geometry.isBufferGeometry) {
  16375. var morphAttributes = geometry.morphAttributes;
  16376. var keys = Object.keys(morphAttributes);
  16377. if (keys.length > 0) {
  16378. var morphAttribute = morphAttributes[keys[0]];
  16379. if (morphAttribute !== undefined) {
  16380. this.morphTargetInfluences = [];
  16381. this.morphTargetDictionary = {};
  16382. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16383. var name = morphAttribute[m].name || String(m);
  16384. this.morphTargetInfluences.push(0);
  16385. this.morphTargetDictionary[name] = m;
  16386. }
  16387. }
  16388. }
  16389. } else {
  16390. var morphTargets = geometry.morphTargets;
  16391. if (morphTargets !== undefined && morphTargets.length > 0) {
  16392. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16393. }
  16394. }
  16395. }
  16396. });
  16397. var _start$1 = new Vector3();
  16398. var _end$1 = new Vector3();
  16399. function LineSegments(geometry, material) {
  16400. Line.call(this, geometry, material);
  16401. this.type = 'LineSegments';
  16402. }
  16403. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16404. constructor: LineSegments,
  16405. isLineSegments: true,
  16406. computeLineDistances: function computeLineDistances() {
  16407. var geometry = this.geometry;
  16408. if (geometry.isBufferGeometry) {
  16409. // we assume non-indexed geometry
  16410. if (geometry.index === null) {
  16411. var positionAttribute = geometry.attributes.position;
  16412. var lineDistances = [];
  16413. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16414. _start$1.fromBufferAttribute(positionAttribute, i);
  16415. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16416. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16417. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16418. }
  16419. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16420. } else {
  16421. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16422. }
  16423. } else if (geometry.isGeometry) {
  16424. var vertices = geometry.vertices;
  16425. var _lineDistances = geometry.lineDistances;
  16426. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16427. _start$1.copy(vertices[_i]);
  16428. _end$1.copy(vertices[_i + 1]);
  16429. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16430. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16431. }
  16432. }
  16433. return this;
  16434. }
  16435. });
  16436. function LineLoop(geometry, material) {
  16437. Line.call(this, geometry, material);
  16438. this.type = 'LineLoop';
  16439. }
  16440. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16441. constructor: LineLoop,
  16442. isLineLoop: true
  16443. });
  16444. /**
  16445. * parameters = {
  16446. * color: <hex>,
  16447. * opacity: <float>,
  16448. * map: new THREE.Texture( <Image> ),
  16449. * alphaMap: new THREE.Texture( <Image> ),
  16450. *
  16451. * size: <float>,
  16452. * sizeAttenuation: <bool>
  16453. *
  16454. * morphTargets: <bool>
  16455. * }
  16456. */
  16457. function PointsMaterial(parameters) {
  16458. Material.call(this);
  16459. this.type = 'PointsMaterial';
  16460. this.color = new Color(0xffffff);
  16461. this.map = null;
  16462. this.alphaMap = null;
  16463. this.size = 1;
  16464. this.sizeAttenuation = true;
  16465. this.morphTargets = false;
  16466. this.setValues(parameters);
  16467. }
  16468. PointsMaterial.prototype = Object.create(Material.prototype);
  16469. PointsMaterial.prototype.constructor = PointsMaterial;
  16470. PointsMaterial.prototype.isPointsMaterial = true;
  16471. PointsMaterial.prototype.copy = function (source) {
  16472. Material.prototype.copy.call(this, source);
  16473. this.color.copy(source.color);
  16474. this.map = source.map;
  16475. this.alphaMap = source.alphaMap;
  16476. this.size = source.size;
  16477. this.sizeAttenuation = source.sizeAttenuation;
  16478. this.morphTargets = source.morphTargets;
  16479. return this;
  16480. };
  16481. var _inverseMatrix$2 = new Matrix4();
  16482. var _ray$2 = new Ray();
  16483. var _sphere$3 = new Sphere();
  16484. var _position$1 = new Vector3();
  16485. function Points(geometry, material) {
  16486. Object3D.call(this);
  16487. this.type = 'Points';
  16488. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16489. this.material = material !== undefined ? material : new PointsMaterial();
  16490. this.updateMorphTargets();
  16491. }
  16492. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16493. constructor: Points,
  16494. isPoints: true,
  16495. copy: function copy(source) {
  16496. Object3D.prototype.copy.call(this, source);
  16497. this.material = source.material;
  16498. this.geometry = source.geometry;
  16499. return this;
  16500. },
  16501. raycast: function raycast(raycaster, intersects) {
  16502. var geometry = this.geometry;
  16503. var matrixWorld = this.matrixWorld;
  16504. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16505. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16506. _sphere$3.copy(geometry.boundingSphere);
  16507. _sphere$3.applyMatrix4(matrixWorld);
  16508. _sphere$3.radius += threshold;
  16509. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16510. _inverseMatrix$2.copy(matrixWorld).invert();
  16511. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16512. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16513. var localThresholdSq = localThreshold * localThreshold;
  16514. if (geometry.isBufferGeometry) {
  16515. var index = geometry.index;
  16516. var attributes = geometry.attributes;
  16517. var positionAttribute = attributes.position;
  16518. if (index !== null) {
  16519. var indices = index.array;
  16520. for (var i = 0, il = indices.length; i < il; i++) {
  16521. var a = indices[i];
  16522. _position$1.fromBufferAttribute(positionAttribute, a);
  16523. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16524. }
  16525. } else {
  16526. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16527. _position$1.fromBufferAttribute(positionAttribute, _i);
  16528. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16529. }
  16530. }
  16531. } else {
  16532. var vertices = geometry.vertices;
  16533. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16534. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16535. }
  16536. }
  16537. },
  16538. updateMorphTargets: function updateMorphTargets() {
  16539. var geometry = this.geometry;
  16540. if (geometry.isBufferGeometry) {
  16541. var morphAttributes = geometry.morphAttributes;
  16542. var keys = Object.keys(morphAttributes);
  16543. if (keys.length > 0) {
  16544. var morphAttribute = morphAttributes[keys[0]];
  16545. if (morphAttribute !== undefined) {
  16546. this.morphTargetInfluences = [];
  16547. this.morphTargetDictionary = {};
  16548. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16549. var name = morphAttribute[m].name || String(m);
  16550. this.morphTargetInfluences.push(0);
  16551. this.morphTargetDictionary[name] = m;
  16552. }
  16553. }
  16554. }
  16555. } else {
  16556. var morphTargets = geometry.morphTargets;
  16557. if (morphTargets !== undefined && morphTargets.length > 0) {
  16558. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16559. }
  16560. }
  16561. }
  16562. });
  16563. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16564. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16565. if (rayPointDistanceSq < localThresholdSq) {
  16566. var intersectPoint = new Vector3();
  16567. _ray$2.closestPointToPoint(point, intersectPoint);
  16568. intersectPoint.applyMatrix4(matrixWorld);
  16569. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16570. if (distance < raycaster.near || distance > raycaster.far) return;
  16571. intersects.push({
  16572. distance: distance,
  16573. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16574. point: intersectPoint,
  16575. index: index,
  16576. face: null,
  16577. object: object
  16578. });
  16579. }
  16580. }
  16581. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16582. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16583. this.format = format !== undefined ? format : RGBFormat;
  16584. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16585. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16586. this.generateMipmaps = false;
  16587. var scope = this;
  16588. function updateVideo() {
  16589. scope.needsUpdate = true;
  16590. video.requestVideoFrameCallback(updateVideo);
  16591. }
  16592. if ('requestVideoFrameCallback' in video) {
  16593. video.requestVideoFrameCallback(updateVideo);
  16594. }
  16595. }
  16596. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16597. constructor: VideoTexture,
  16598. clone: function clone() {
  16599. return new this.constructor(this.image).copy(this);
  16600. },
  16601. isVideoTexture: true,
  16602. update: function update() {
  16603. var video = this.image;
  16604. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16605. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16606. this.needsUpdate = true;
  16607. }
  16608. }
  16609. });
  16610. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16611. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16612. this.image = {
  16613. width: width,
  16614. height: height
  16615. };
  16616. this.mipmaps = mipmaps; // no flipping for cube textures
  16617. // (also flipping doesn't work for compressed textures )
  16618. this.flipY = false; // can't generate mipmaps for compressed textures
  16619. // mips must be embedded in DDS files
  16620. this.generateMipmaps = false;
  16621. }
  16622. CompressedTexture.prototype = Object.create(Texture.prototype);
  16623. CompressedTexture.prototype.constructor = CompressedTexture;
  16624. CompressedTexture.prototype.isCompressedTexture = true;
  16625. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16626. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16627. this.needsUpdate = true;
  16628. }
  16629. CanvasTexture.prototype = Object.create(Texture.prototype);
  16630. CanvasTexture.prototype.constructor = CanvasTexture;
  16631. CanvasTexture.prototype.isCanvasTexture = true;
  16632. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16633. format = format !== undefined ? format : DepthFormat;
  16634. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16635. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16636. }
  16637. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16638. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16639. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16640. this.image = {
  16641. width: width,
  16642. height: height
  16643. };
  16644. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16645. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16646. this.flipY = false;
  16647. this.generateMipmaps = false;
  16648. }
  16649. DepthTexture.prototype = Object.create(Texture.prototype);
  16650. DepthTexture.prototype.constructor = DepthTexture;
  16651. DepthTexture.prototype.isDepthTexture = true;
  16652. var _geometryId = 0; // Geometry uses even numbers as Id
  16653. var _m1$3 = new Matrix4();
  16654. var _obj$1 = new Object3D();
  16655. var _offset$1 = new Vector3();
  16656. function Geometry() {
  16657. Object.defineProperty(this, 'id', {
  16658. value: _geometryId += 2
  16659. });
  16660. this.uuid = MathUtils.generateUUID();
  16661. this.name = '';
  16662. this.type = 'Geometry';
  16663. this.vertices = [];
  16664. this.colors = [];
  16665. this.faces = [];
  16666. this.faceVertexUvs = [[]];
  16667. this.morphTargets = [];
  16668. this.morphNormals = [];
  16669. this.skinWeights = [];
  16670. this.skinIndices = [];
  16671. this.lineDistances = [];
  16672. this.boundingBox = null;
  16673. this.boundingSphere = null; // update flags
  16674. this.elementsNeedUpdate = false;
  16675. this.verticesNeedUpdate = false;
  16676. this.uvsNeedUpdate = false;
  16677. this.normalsNeedUpdate = false;
  16678. this.colorsNeedUpdate = false;
  16679. this.lineDistancesNeedUpdate = false;
  16680. this.groupsNeedUpdate = false;
  16681. }
  16682. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16683. constructor: Geometry,
  16684. isGeometry: true,
  16685. applyMatrix4: function applyMatrix4(matrix) {
  16686. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16687. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16688. var vertex = this.vertices[i];
  16689. vertex.applyMatrix4(matrix);
  16690. }
  16691. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16692. var face = this.faces[_i];
  16693. face.normal.applyMatrix3(normalMatrix).normalize();
  16694. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16695. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16696. }
  16697. }
  16698. if (this.boundingBox !== null) {
  16699. this.computeBoundingBox();
  16700. }
  16701. if (this.boundingSphere !== null) {
  16702. this.computeBoundingSphere();
  16703. }
  16704. this.verticesNeedUpdate = true;
  16705. this.normalsNeedUpdate = true;
  16706. return this;
  16707. },
  16708. rotateX: function rotateX(angle) {
  16709. // rotate geometry around world x-axis
  16710. _m1$3.makeRotationX(angle);
  16711. this.applyMatrix4(_m1$3);
  16712. return this;
  16713. },
  16714. rotateY: function rotateY(angle) {
  16715. // rotate geometry around world y-axis
  16716. _m1$3.makeRotationY(angle);
  16717. this.applyMatrix4(_m1$3);
  16718. return this;
  16719. },
  16720. rotateZ: function rotateZ(angle) {
  16721. // rotate geometry around world z-axis
  16722. _m1$3.makeRotationZ(angle);
  16723. this.applyMatrix4(_m1$3);
  16724. return this;
  16725. },
  16726. translate: function translate(x, y, z) {
  16727. // translate geometry
  16728. _m1$3.makeTranslation(x, y, z);
  16729. this.applyMatrix4(_m1$3);
  16730. return this;
  16731. },
  16732. scale: function scale(x, y, z) {
  16733. // scale geometry
  16734. _m1$3.makeScale(x, y, z);
  16735. this.applyMatrix4(_m1$3);
  16736. return this;
  16737. },
  16738. lookAt: function lookAt(vector) {
  16739. _obj$1.lookAt(vector);
  16740. _obj$1.updateMatrix();
  16741. this.applyMatrix4(_obj$1.matrix);
  16742. return this;
  16743. },
  16744. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16745. var scope = this;
  16746. var index = geometry.index !== null ? geometry.index : undefined;
  16747. var attributes = geometry.attributes;
  16748. if (attributes.position === undefined) {
  16749. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16750. return this;
  16751. }
  16752. var position = attributes.position;
  16753. var normal = attributes.normal;
  16754. var color = attributes.color;
  16755. var uv = attributes.uv;
  16756. var uv2 = attributes.uv2;
  16757. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16758. for (var i = 0; i < position.count; i++) {
  16759. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16760. if (color !== undefined) {
  16761. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16762. }
  16763. }
  16764. function addFace(a, b, c, materialIndex) {
  16765. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16766. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16767. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16768. scope.faces.push(face);
  16769. if (uv !== undefined) {
  16770. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16771. }
  16772. if (uv2 !== undefined) {
  16773. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16774. }
  16775. }
  16776. var groups = geometry.groups;
  16777. if (groups.length > 0) {
  16778. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16779. var group = groups[_i2];
  16780. var start = group.start;
  16781. var count = group.count;
  16782. for (var j = start, jl = start + count; j < jl; j += 3) {
  16783. if (index !== undefined) {
  16784. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16785. } else {
  16786. addFace(j, j + 1, j + 2, group.materialIndex);
  16787. }
  16788. }
  16789. }
  16790. } else {
  16791. if (index !== undefined) {
  16792. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16793. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16794. }
  16795. } else {
  16796. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16797. addFace(_i4, _i4 + 1, _i4 + 2);
  16798. }
  16799. }
  16800. }
  16801. this.computeFaceNormals();
  16802. if (geometry.boundingBox !== null) {
  16803. this.boundingBox = geometry.boundingBox.clone();
  16804. }
  16805. if (geometry.boundingSphere !== null) {
  16806. this.boundingSphere = geometry.boundingSphere.clone();
  16807. }
  16808. return this;
  16809. },
  16810. center: function center() {
  16811. this.computeBoundingBox();
  16812. this.boundingBox.getCenter(_offset$1).negate();
  16813. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16814. return this;
  16815. },
  16816. normalize: function normalize() {
  16817. this.computeBoundingSphere();
  16818. var center = this.boundingSphere.center;
  16819. var radius = this.boundingSphere.radius;
  16820. var s = radius === 0 ? 1 : 1.0 / radius;
  16821. var matrix = new Matrix4();
  16822. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16823. this.applyMatrix4(matrix);
  16824. return this;
  16825. },
  16826. computeFaceNormals: function computeFaceNormals() {
  16827. var cb = new Vector3(),
  16828. ab = new Vector3();
  16829. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16830. var face = this.faces[f];
  16831. var vA = this.vertices[face.a];
  16832. var vB = this.vertices[face.b];
  16833. var vC = this.vertices[face.c];
  16834. cb.subVectors(vC, vB);
  16835. ab.subVectors(vA, vB);
  16836. cb.cross(ab);
  16837. cb.normalize();
  16838. face.normal.copy(cb);
  16839. }
  16840. },
  16841. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16842. if (areaWeighted === void 0) {
  16843. areaWeighted = true;
  16844. }
  16845. var vertices = new Array(this.vertices.length);
  16846. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16847. vertices[v] = new Vector3();
  16848. }
  16849. if (areaWeighted) {
  16850. // vertex normals weighted by triangle areas
  16851. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16852. var cb = new Vector3(),
  16853. ab = new Vector3();
  16854. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16855. var face = this.faces[f];
  16856. var vA = this.vertices[face.a];
  16857. var vB = this.vertices[face.b];
  16858. var vC = this.vertices[face.c];
  16859. cb.subVectors(vC, vB);
  16860. ab.subVectors(vA, vB);
  16861. cb.cross(ab);
  16862. vertices[face.a].add(cb);
  16863. vertices[face.b].add(cb);
  16864. vertices[face.c].add(cb);
  16865. }
  16866. } else {
  16867. this.computeFaceNormals();
  16868. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16869. var _face = this.faces[_f];
  16870. vertices[_face.a].add(_face.normal);
  16871. vertices[_face.b].add(_face.normal);
  16872. vertices[_face.c].add(_face.normal);
  16873. }
  16874. }
  16875. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16876. vertices[_v].normalize();
  16877. }
  16878. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16879. var _face2 = this.faces[_f2];
  16880. var vertexNormals = _face2.vertexNormals;
  16881. if (vertexNormals.length === 3) {
  16882. vertexNormals[0].copy(vertices[_face2.a]);
  16883. vertexNormals[1].copy(vertices[_face2.b]);
  16884. vertexNormals[2].copy(vertices[_face2.c]);
  16885. } else {
  16886. vertexNormals[0] = vertices[_face2.a].clone();
  16887. vertexNormals[1] = vertices[_face2.b].clone();
  16888. vertexNormals[2] = vertices[_face2.c].clone();
  16889. }
  16890. }
  16891. if (this.faces.length > 0) {
  16892. this.normalsNeedUpdate = true;
  16893. }
  16894. },
  16895. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16896. this.computeFaceNormals();
  16897. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16898. var face = this.faces[f];
  16899. var vertexNormals = face.vertexNormals;
  16900. if (vertexNormals.length === 3) {
  16901. vertexNormals[0].copy(face.normal);
  16902. vertexNormals[1].copy(face.normal);
  16903. vertexNormals[2].copy(face.normal);
  16904. } else {
  16905. vertexNormals[0] = face.normal.clone();
  16906. vertexNormals[1] = face.normal.clone();
  16907. vertexNormals[2] = face.normal.clone();
  16908. }
  16909. }
  16910. if (this.faces.length > 0) {
  16911. this.normalsNeedUpdate = true;
  16912. }
  16913. },
  16914. computeMorphNormals: function computeMorphNormals() {
  16915. // save original normals
  16916. // - create temp variables on first access
  16917. // otherwise just copy (for faster repeated calls)
  16918. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16919. var face = this.faces[f];
  16920. if (!face.__originalFaceNormal) {
  16921. face.__originalFaceNormal = face.normal.clone();
  16922. } else {
  16923. face.__originalFaceNormal.copy(face.normal);
  16924. }
  16925. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16926. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16927. if (!face.__originalVertexNormals[i]) {
  16928. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16929. } else {
  16930. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16931. }
  16932. }
  16933. } // use temp geometry to compute face and vertex normals for each morph
  16934. var tmpGeo = new Geometry();
  16935. tmpGeo.faces = this.faces;
  16936. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16937. // create on first access
  16938. if (!this.morphNormals[_i5]) {
  16939. this.morphNormals[_i5] = {};
  16940. this.morphNormals[_i5].faceNormals = [];
  16941. this.morphNormals[_i5].vertexNormals = [];
  16942. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16943. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16944. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16945. var faceNormal = new Vector3();
  16946. var vertexNormals = {
  16947. a: new Vector3(),
  16948. b: new Vector3(),
  16949. c: new Vector3()
  16950. };
  16951. dstNormalsFace.push(faceNormal);
  16952. dstNormalsVertex.push(vertexNormals);
  16953. }
  16954. }
  16955. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16956. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16957. tmpGeo.computeFaceNormals();
  16958. tmpGeo.computeVertexNormals(); // store morph normals
  16959. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16960. var _face3 = this.faces[_f4];
  16961. var _faceNormal = morphNormals.faceNormals[_f4];
  16962. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16963. _faceNormal.copy(_face3.normal);
  16964. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16965. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16966. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16967. }
  16968. } // restore original normals
  16969. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16970. var _face4 = this.faces[_f5];
  16971. _face4.normal = _face4.__originalFaceNormal;
  16972. _face4.vertexNormals = _face4.__originalVertexNormals;
  16973. }
  16974. },
  16975. computeBoundingBox: function computeBoundingBox() {
  16976. if (this.boundingBox === null) {
  16977. this.boundingBox = new Box3();
  16978. }
  16979. this.boundingBox.setFromPoints(this.vertices);
  16980. },
  16981. computeBoundingSphere: function computeBoundingSphere() {
  16982. if (this.boundingSphere === null) {
  16983. this.boundingSphere = new Sphere();
  16984. }
  16985. this.boundingSphere.setFromPoints(this.vertices);
  16986. },
  16987. merge: function merge(geometry, matrix, materialIndexOffset) {
  16988. if (materialIndexOffset === void 0) {
  16989. materialIndexOffset = 0;
  16990. }
  16991. if (!(geometry && geometry.isGeometry)) {
  16992. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16993. return;
  16994. }
  16995. var normalMatrix;
  16996. var vertexOffset = this.vertices.length,
  16997. vertices1 = this.vertices,
  16998. vertices2 = geometry.vertices,
  16999. faces1 = this.faces,
  17000. faces2 = geometry.faces,
  17001. colors1 = this.colors,
  17002. colors2 = geometry.colors;
  17003. if (matrix !== undefined) {
  17004. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  17005. } // vertices
  17006. for (var i = 0, il = vertices2.length; i < il; i++) {
  17007. var vertex = vertices2[i];
  17008. var vertexCopy = vertex.clone();
  17009. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  17010. vertices1.push(vertexCopy);
  17011. } // colors
  17012. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  17013. colors1.push(colors2[_i6].clone());
  17014. } // faces
  17015. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  17016. var face = faces2[_i7];
  17017. var normal = void 0,
  17018. color = void 0;
  17019. var faceVertexNormals = face.vertexNormals,
  17020. faceVertexColors = face.vertexColors;
  17021. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  17022. faceCopy.normal.copy(face.normal);
  17023. if (normalMatrix !== undefined) {
  17024. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  17025. }
  17026. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  17027. normal = faceVertexNormals[j].clone();
  17028. if (normalMatrix !== undefined) {
  17029. normal.applyMatrix3(normalMatrix).normalize();
  17030. }
  17031. faceCopy.vertexNormals.push(normal);
  17032. }
  17033. faceCopy.color.copy(face.color);
  17034. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  17035. color = faceVertexColors[_j];
  17036. faceCopy.vertexColors.push(color.clone());
  17037. }
  17038. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  17039. faces1.push(faceCopy);
  17040. } // uvs
  17041. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  17042. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  17043. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  17044. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  17045. var uvs2 = faceVertexUvs2[_j2],
  17046. uvsCopy = [];
  17047. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  17048. uvsCopy.push(uvs2[k].clone());
  17049. }
  17050. this.faceVertexUvs[_i8].push(uvsCopy);
  17051. }
  17052. }
  17053. },
  17054. mergeMesh: function mergeMesh(mesh) {
  17055. if (!(mesh && mesh.isMesh)) {
  17056. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  17057. return;
  17058. }
  17059. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  17060. this.merge(mesh.geometry, mesh.matrix);
  17061. },
  17062. /*
  17063. * Checks for duplicate vertices with hashmap.
  17064. * Duplicated vertices are removed
  17065. * and faces' vertices are updated.
  17066. */
  17067. mergeVertices: function mergeVertices(precisionPoints) {
  17068. if (precisionPoints === void 0) {
  17069. precisionPoints = 4;
  17070. }
  17071. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  17072. var unique = [],
  17073. changes = [];
  17074. var precision = Math.pow(10, precisionPoints);
  17075. for (var i = 0, il = this.vertices.length; i < il; i++) {
  17076. var v = this.vertices[i];
  17077. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  17078. if (verticesMap[key] === undefined) {
  17079. verticesMap[key] = i;
  17080. unique.push(this.vertices[i]);
  17081. changes[i] = unique.length - 1;
  17082. } else {
  17083. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  17084. changes[i] = changes[verticesMap[key]];
  17085. }
  17086. } // if faces are completely degenerate after merging vertices, we
  17087. // have to remove them from the geometry.
  17088. var faceIndicesToRemove = [];
  17089. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  17090. var face = this.faces[_i9];
  17091. face.a = changes[face.a];
  17092. face.b = changes[face.b];
  17093. face.c = changes[face.c];
  17094. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  17095. // we have to remove the face as nothing can be saved
  17096. for (var n = 0; n < 3; n++) {
  17097. if (indices[n] === indices[(n + 1) % 3]) {
  17098. faceIndicesToRemove.push(_i9);
  17099. break;
  17100. }
  17101. }
  17102. }
  17103. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  17104. var idx = faceIndicesToRemove[_i10];
  17105. this.faces.splice(idx, 1);
  17106. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  17107. this.faceVertexUvs[j].splice(idx, 1);
  17108. }
  17109. } // Use unique set of vertices
  17110. var diff = this.vertices.length - unique.length;
  17111. this.vertices = unique;
  17112. return diff;
  17113. },
  17114. setFromPoints: function setFromPoints(points) {
  17115. this.vertices = [];
  17116. for (var i = 0, l = points.length; i < l; i++) {
  17117. var point = points[i];
  17118. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  17119. }
  17120. return this;
  17121. },
  17122. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  17123. var faces = this.faces;
  17124. var length = faces.length; // tag faces
  17125. for (var i = 0; i < length; i++) {
  17126. faces[i]._id = i;
  17127. } // sort faces
  17128. function materialIndexSort(a, b) {
  17129. return a.materialIndex - b.materialIndex;
  17130. }
  17131. faces.sort(materialIndexSort); // sort uvs
  17132. var uvs1 = this.faceVertexUvs[0];
  17133. var uvs2 = this.faceVertexUvs[1];
  17134. var newUvs1, newUvs2;
  17135. if (uvs1 && uvs1.length === length) newUvs1 = [];
  17136. if (uvs2 && uvs2.length === length) newUvs2 = [];
  17137. for (var _i11 = 0; _i11 < length; _i11++) {
  17138. var id = faces[_i11]._id;
  17139. if (newUvs1) newUvs1.push(uvs1[id]);
  17140. if (newUvs2) newUvs2.push(uvs2[id]);
  17141. }
  17142. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  17143. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  17144. },
  17145. toJSON: function toJSON() {
  17146. var data = {
  17147. metadata: {
  17148. version: 4.5,
  17149. type: 'Geometry',
  17150. generator: 'Geometry.toJSON'
  17151. }
  17152. }; // standard Geometry serialization
  17153. data.uuid = this.uuid;
  17154. data.type = this.type;
  17155. if (this.name !== '') data.name = this.name;
  17156. if (this.parameters !== undefined) {
  17157. var parameters = this.parameters;
  17158. for (var key in parameters) {
  17159. if (parameters[key] !== undefined) data[key] = parameters[key];
  17160. }
  17161. return data;
  17162. }
  17163. var vertices = [];
  17164. for (var i = 0; i < this.vertices.length; i++) {
  17165. var vertex = this.vertices[i];
  17166. vertices.push(vertex.x, vertex.y, vertex.z);
  17167. }
  17168. var faces = [];
  17169. var normals = [];
  17170. var normalsHash = {};
  17171. var colors = [];
  17172. var colorsHash = {};
  17173. var uvs = [];
  17174. var uvsHash = {};
  17175. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  17176. var face = this.faces[_i12];
  17177. var hasMaterial = true;
  17178. var hasFaceUv = false; // deprecated
  17179. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  17180. var hasFaceNormal = face.normal.length() > 0;
  17181. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  17182. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  17183. var hasFaceVertexColor = face.vertexColors.length > 0;
  17184. var faceType = 0;
  17185. faceType = setBit(faceType, 0, 0); // isQuad
  17186. faceType = setBit(faceType, 1, hasMaterial);
  17187. faceType = setBit(faceType, 2, hasFaceUv);
  17188. faceType = setBit(faceType, 3, hasFaceVertexUv);
  17189. faceType = setBit(faceType, 4, hasFaceNormal);
  17190. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  17191. faceType = setBit(faceType, 6, hasFaceColor);
  17192. faceType = setBit(faceType, 7, hasFaceVertexColor);
  17193. faces.push(faceType);
  17194. faces.push(face.a, face.b, face.c);
  17195. faces.push(face.materialIndex);
  17196. if (hasFaceVertexUv) {
  17197. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  17198. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  17199. }
  17200. if (hasFaceNormal) {
  17201. faces.push(getNormalIndex(face.normal));
  17202. }
  17203. if (hasFaceVertexNormal) {
  17204. var vertexNormals = face.vertexNormals;
  17205. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  17206. }
  17207. if (hasFaceColor) {
  17208. faces.push(getColorIndex(face.color));
  17209. }
  17210. if (hasFaceVertexColor) {
  17211. var vertexColors = face.vertexColors;
  17212. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  17213. }
  17214. }
  17215. function setBit(value, position, enabled) {
  17216. return enabled ? value | 1 << position : value & ~(1 << position);
  17217. }
  17218. function getNormalIndex(normal) {
  17219. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  17220. if (normalsHash[hash] !== undefined) {
  17221. return normalsHash[hash];
  17222. }
  17223. normalsHash[hash] = normals.length / 3;
  17224. normals.push(normal.x, normal.y, normal.z);
  17225. return normalsHash[hash];
  17226. }
  17227. function getColorIndex(color) {
  17228. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  17229. if (colorsHash[hash] !== undefined) {
  17230. return colorsHash[hash];
  17231. }
  17232. colorsHash[hash] = colors.length;
  17233. colors.push(color.getHex());
  17234. return colorsHash[hash];
  17235. }
  17236. function getUvIndex(uv) {
  17237. var hash = uv.x.toString() + uv.y.toString();
  17238. if (uvsHash[hash] !== undefined) {
  17239. return uvsHash[hash];
  17240. }
  17241. uvsHash[hash] = uvs.length / 2;
  17242. uvs.push(uv.x, uv.y);
  17243. return uvsHash[hash];
  17244. }
  17245. data.data = {};
  17246. data.data.vertices = vertices;
  17247. data.data.normals = normals;
  17248. if (colors.length > 0) data.data.colors = colors;
  17249. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  17250. data.data.faces = faces;
  17251. return data;
  17252. },
  17253. clone: function clone() {
  17254. /*
  17255. // Handle primitives
  17256. const parameters = this.parameters;
  17257. if ( parameters !== undefined ) {
  17258. const values = [];
  17259. for ( const key in parameters ) {
  17260. values.push( parameters[ key ] );
  17261. }
  17262. const geometry = Object.create( this.constructor.prototype );
  17263. this.constructor.apply( geometry, values );
  17264. return geometry;
  17265. }
  17266. return new this.constructor().copy( this );
  17267. */
  17268. return new Geometry().copy(this);
  17269. },
  17270. copy: function copy(source) {
  17271. // reset
  17272. this.vertices = [];
  17273. this.colors = [];
  17274. this.faces = [];
  17275. this.faceVertexUvs = [[]];
  17276. this.morphTargets = [];
  17277. this.morphNormals = [];
  17278. this.skinWeights = [];
  17279. this.skinIndices = [];
  17280. this.lineDistances = [];
  17281. this.boundingBox = null;
  17282. this.boundingSphere = null; // name
  17283. this.name = source.name; // vertices
  17284. var vertices = source.vertices;
  17285. for (var i = 0, il = vertices.length; i < il; i++) {
  17286. this.vertices.push(vertices[i].clone());
  17287. } // colors
  17288. var colors = source.colors;
  17289. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17290. this.colors.push(colors[_i13].clone());
  17291. } // faces
  17292. var faces = source.faces;
  17293. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17294. this.faces.push(faces[_i14].clone());
  17295. } // face vertex uvs
  17296. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17297. var faceVertexUvs = source.faceVertexUvs[_i15];
  17298. if (this.faceVertexUvs[_i15] === undefined) {
  17299. this.faceVertexUvs[_i15] = [];
  17300. }
  17301. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17302. var uvs = faceVertexUvs[j],
  17303. uvsCopy = [];
  17304. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17305. var uv = uvs[k];
  17306. uvsCopy.push(uv.clone());
  17307. }
  17308. this.faceVertexUvs[_i15].push(uvsCopy);
  17309. }
  17310. } // morph targets
  17311. var morphTargets = source.morphTargets;
  17312. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17313. var morphTarget = {};
  17314. morphTarget.name = morphTargets[_i16].name; // vertices
  17315. if (morphTargets[_i16].vertices !== undefined) {
  17316. morphTarget.vertices = [];
  17317. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17318. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17319. }
  17320. } // normals
  17321. if (morphTargets[_i16].normals !== undefined) {
  17322. morphTarget.normals = [];
  17323. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17324. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17325. }
  17326. }
  17327. this.morphTargets.push(morphTarget);
  17328. } // morph normals
  17329. var morphNormals = source.morphNormals;
  17330. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17331. var morphNormal = {}; // vertex normals
  17332. if (morphNormals[_i17].vertexNormals !== undefined) {
  17333. morphNormal.vertexNormals = [];
  17334. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17335. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17336. var destVertexNormal = {};
  17337. destVertexNormal.a = srcVertexNormal.a.clone();
  17338. destVertexNormal.b = srcVertexNormal.b.clone();
  17339. destVertexNormal.c = srcVertexNormal.c.clone();
  17340. morphNormal.vertexNormals.push(destVertexNormal);
  17341. }
  17342. } // face normals
  17343. if (morphNormals[_i17].faceNormals !== undefined) {
  17344. morphNormal.faceNormals = [];
  17345. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17346. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17347. }
  17348. }
  17349. this.morphNormals.push(morphNormal);
  17350. } // skin weights
  17351. var skinWeights = source.skinWeights;
  17352. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17353. this.skinWeights.push(skinWeights[_i18].clone());
  17354. } // skin indices
  17355. var skinIndices = source.skinIndices;
  17356. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17357. this.skinIndices.push(skinIndices[_i19].clone());
  17358. } // line distances
  17359. var lineDistances = source.lineDistances;
  17360. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17361. this.lineDistances.push(lineDistances[_i20]);
  17362. } // bounding box
  17363. var boundingBox = source.boundingBox;
  17364. if (boundingBox !== null) {
  17365. this.boundingBox = boundingBox.clone();
  17366. } // bounding sphere
  17367. var boundingSphere = source.boundingSphere;
  17368. if (boundingSphere !== null) {
  17369. this.boundingSphere = boundingSphere.clone();
  17370. } // update flags
  17371. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17372. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17373. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17374. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17375. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17376. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17377. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17378. return this;
  17379. },
  17380. dispose: function dispose() {
  17381. this.dispatchEvent({
  17382. type: 'dispose'
  17383. });
  17384. }
  17385. });
  17386. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17387. _inheritsLoose(BoxGeometry, _Geometry);
  17388. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17389. var _this;
  17390. _this = _Geometry.call(this) || this;
  17391. _this.type = 'BoxGeometry';
  17392. _this.parameters = {
  17393. width: width,
  17394. height: height,
  17395. depth: depth,
  17396. widthSegments: widthSegments,
  17397. heightSegments: heightSegments,
  17398. depthSegments: depthSegments
  17399. };
  17400. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17401. _this.mergeVertices();
  17402. return _this;
  17403. }
  17404. return BoxGeometry;
  17405. }(Geometry);
  17406. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17407. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17408. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17409. var _this;
  17410. if (radius === void 0) {
  17411. radius = 1;
  17412. }
  17413. if (segments === void 0) {
  17414. segments = 8;
  17415. }
  17416. if (thetaStart === void 0) {
  17417. thetaStart = 0;
  17418. }
  17419. if (thetaLength === void 0) {
  17420. thetaLength = Math.PI * 2;
  17421. }
  17422. _this = _BufferGeometry.call(this) || this;
  17423. _this.type = 'CircleBufferGeometry';
  17424. _this.parameters = {
  17425. radius: radius,
  17426. segments: segments,
  17427. thetaStart: thetaStart,
  17428. thetaLength: thetaLength
  17429. };
  17430. segments = Math.max(3, segments); // buffers
  17431. var indices = [];
  17432. var vertices = [];
  17433. var normals = [];
  17434. var uvs = []; // helper variables
  17435. var vertex = new Vector3();
  17436. var uv = new Vector2(); // center point
  17437. vertices.push(0, 0, 0);
  17438. normals.push(0, 0, 1);
  17439. uvs.push(0.5, 0.5);
  17440. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17441. var segment = thetaStart + s / segments * thetaLength; // vertex
  17442. vertex.x = radius * Math.cos(segment);
  17443. vertex.y = radius * Math.sin(segment);
  17444. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17445. normals.push(0, 0, 1); // uvs
  17446. uv.x = (vertices[i] / radius + 1) / 2;
  17447. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17448. uvs.push(uv.x, uv.y);
  17449. } // indices
  17450. for (var _i = 1; _i <= segments; _i++) {
  17451. indices.push(_i, _i + 1, 0);
  17452. } // build geometry
  17453. _this.setIndex(indices);
  17454. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17455. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17456. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17457. return _this;
  17458. }
  17459. return CircleBufferGeometry;
  17460. }(BufferGeometry);
  17461. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17462. _inheritsLoose(CircleGeometry, _Geometry);
  17463. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17464. var _this;
  17465. _this = _Geometry.call(this) || this;
  17466. _this.type = 'CircleGeometry';
  17467. _this.parameters = {
  17468. radius: radius,
  17469. segments: segments,
  17470. thetaStart: thetaStart,
  17471. thetaLength: thetaLength
  17472. };
  17473. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17474. _this.mergeVertices();
  17475. return _this;
  17476. }
  17477. return CircleGeometry;
  17478. }(Geometry);
  17479. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17480. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17481. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17482. var _this;
  17483. if (radiusTop === void 0) {
  17484. radiusTop = 1;
  17485. }
  17486. if (radiusBottom === void 0) {
  17487. radiusBottom = 1;
  17488. }
  17489. if (height === void 0) {
  17490. height = 1;
  17491. }
  17492. if (radialSegments === void 0) {
  17493. radialSegments = 8;
  17494. }
  17495. if (heightSegments === void 0) {
  17496. heightSegments = 1;
  17497. }
  17498. if (openEnded === void 0) {
  17499. openEnded = false;
  17500. }
  17501. if (thetaStart === void 0) {
  17502. thetaStart = 0;
  17503. }
  17504. if (thetaLength === void 0) {
  17505. thetaLength = Math.PI * 2;
  17506. }
  17507. _this = _BufferGeometry.call(this) || this;
  17508. _this.type = 'CylinderBufferGeometry';
  17509. _this.parameters = {
  17510. radiusTop: radiusTop,
  17511. radiusBottom: radiusBottom,
  17512. height: height,
  17513. radialSegments: radialSegments,
  17514. heightSegments: heightSegments,
  17515. openEnded: openEnded,
  17516. thetaStart: thetaStart,
  17517. thetaLength: thetaLength
  17518. };
  17519. var scope = _assertThisInitialized(_this);
  17520. radialSegments = Math.floor(radialSegments);
  17521. heightSegments = Math.floor(heightSegments); // buffers
  17522. var indices = [];
  17523. var vertices = [];
  17524. var normals = [];
  17525. var uvs = []; // helper variables
  17526. var index = 0;
  17527. var indexArray = [];
  17528. var halfHeight = height / 2;
  17529. var groupStart = 0; // generate geometry
  17530. generateTorso();
  17531. if (openEnded === false) {
  17532. if (radiusTop > 0) generateCap(true);
  17533. if (radiusBottom > 0) generateCap(false);
  17534. } // build geometry
  17535. _this.setIndex(indices);
  17536. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17537. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17538. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17539. function generateTorso() {
  17540. var normal = new Vector3();
  17541. var vertex = new Vector3();
  17542. var groupCount = 0; // this will be used to calculate the normal
  17543. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17544. for (var y = 0; y <= heightSegments; y++) {
  17545. var indexRow = [];
  17546. var v = y / heightSegments; // calculate the radius of the current row
  17547. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17548. for (var x = 0; x <= radialSegments; x++) {
  17549. var u = x / radialSegments;
  17550. var theta = u * thetaLength + thetaStart;
  17551. var sinTheta = Math.sin(theta);
  17552. var cosTheta = Math.cos(theta); // vertex
  17553. vertex.x = radius * sinTheta;
  17554. vertex.y = -v * height + halfHeight;
  17555. vertex.z = radius * cosTheta;
  17556. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17557. normal.set(sinTheta, slope, cosTheta).normalize();
  17558. normals.push(normal.x, normal.y, normal.z); // uv
  17559. uvs.push(u, 1 - v); // save index of vertex in respective row
  17560. indexRow.push(index++);
  17561. } // now save vertices of the row in our index array
  17562. indexArray.push(indexRow);
  17563. } // generate indices
  17564. for (var _x = 0; _x < radialSegments; _x++) {
  17565. for (var _y = 0; _y < heightSegments; _y++) {
  17566. // we use the index array to access the correct indices
  17567. var a = indexArray[_y][_x];
  17568. var b = indexArray[_y + 1][_x];
  17569. var c = indexArray[_y + 1][_x + 1];
  17570. var d = indexArray[_y][_x + 1]; // faces
  17571. indices.push(a, b, d);
  17572. indices.push(b, c, d); // update group counter
  17573. groupCount += 6;
  17574. }
  17575. } // add a group to the geometry. this will ensure multi material support
  17576. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17577. groupStart += groupCount;
  17578. }
  17579. function generateCap(top) {
  17580. // save the index of the first center vertex
  17581. var centerIndexStart = index;
  17582. var uv = new Vector2();
  17583. var vertex = new Vector3();
  17584. var groupCount = 0;
  17585. var radius = top === true ? radiusTop : radiusBottom;
  17586. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17587. // because the geometry needs one set of uvs per face,
  17588. // we must generate a center vertex per face/segment
  17589. for (var x = 1; x <= radialSegments; x++) {
  17590. // vertex
  17591. vertices.push(0, halfHeight * sign, 0); // normal
  17592. normals.push(0, sign, 0); // uv
  17593. uvs.push(0.5, 0.5); // increase index
  17594. index++;
  17595. } // save the index of the last center vertex
  17596. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17597. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17598. var u = _x2 / radialSegments;
  17599. var theta = u * thetaLength + thetaStart;
  17600. var cosTheta = Math.cos(theta);
  17601. var sinTheta = Math.sin(theta); // vertex
  17602. vertex.x = radius * sinTheta;
  17603. vertex.y = halfHeight * sign;
  17604. vertex.z = radius * cosTheta;
  17605. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17606. normals.push(0, sign, 0); // uv
  17607. uv.x = cosTheta * 0.5 + 0.5;
  17608. uv.y = sinTheta * 0.5 * sign + 0.5;
  17609. uvs.push(uv.x, uv.y); // increase index
  17610. index++;
  17611. } // generate indices
  17612. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17613. var c = centerIndexStart + _x3;
  17614. var i = centerIndexEnd + _x3;
  17615. if (top === true) {
  17616. // face top
  17617. indices.push(i, i + 1, c);
  17618. } else {
  17619. // face bottom
  17620. indices.push(i + 1, i, c);
  17621. }
  17622. groupCount += 3;
  17623. } // add a group to the geometry. this will ensure multi material support
  17624. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17625. groupStart += groupCount;
  17626. }
  17627. return _this;
  17628. }
  17629. return CylinderBufferGeometry;
  17630. }(BufferGeometry);
  17631. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17632. _inheritsLoose(CylinderGeometry, _Geometry);
  17633. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17634. var _this;
  17635. _this = _Geometry.call(this) || this;
  17636. _this.type = 'CylinderGeometry';
  17637. _this.parameters = {
  17638. radiusTop: radiusTop,
  17639. radiusBottom: radiusBottom,
  17640. height: height,
  17641. radialSegments: radialSegments,
  17642. heightSegments: heightSegments,
  17643. openEnded: openEnded,
  17644. thetaStart: thetaStart,
  17645. thetaLength: thetaLength
  17646. };
  17647. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17648. _this.mergeVertices();
  17649. return _this;
  17650. }
  17651. return CylinderGeometry;
  17652. }(Geometry);
  17653. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17654. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17655. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17656. var _this;
  17657. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17658. _this.type = 'ConeGeometry';
  17659. _this.parameters = {
  17660. radius: radius,
  17661. height: height,
  17662. radialSegments: radialSegments,
  17663. heightSegments: heightSegments,
  17664. openEnded: openEnded,
  17665. thetaStart: thetaStart,
  17666. thetaLength: thetaLength
  17667. };
  17668. return _this;
  17669. }
  17670. return ConeGeometry;
  17671. }(CylinderGeometry);
  17672. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17673. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17674. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17675. var _this;
  17676. if (radius === void 0) {
  17677. radius = 1;
  17678. }
  17679. if (height === void 0) {
  17680. height = 1;
  17681. }
  17682. if (radialSegments === void 0) {
  17683. radialSegments = 8;
  17684. }
  17685. if (heightSegments === void 0) {
  17686. heightSegments = 1;
  17687. }
  17688. if (openEnded === void 0) {
  17689. openEnded = false;
  17690. }
  17691. if (thetaStart === void 0) {
  17692. thetaStart = 0;
  17693. }
  17694. if (thetaLength === void 0) {
  17695. thetaLength = Math.PI * 2;
  17696. }
  17697. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17698. _this.type = 'ConeBufferGeometry';
  17699. _this.parameters = {
  17700. radius: radius,
  17701. height: height,
  17702. radialSegments: radialSegments,
  17703. heightSegments: heightSegments,
  17704. openEnded: openEnded,
  17705. thetaStart: thetaStart,
  17706. thetaLength: thetaLength
  17707. };
  17708. return _this;
  17709. }
  17710. return ConeBufferGeometry;
  17711. }(CylinderBufferGeometry);
  17712. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17713. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17714. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17715. var _this;
  17716. if (radius === void 0) {
  17717. radius = 1;
  17718. }
  17719. if (detail === void 0) {
  17720. detail = 0;
  17721. }
  17722. _this = _BufferGeometry.call(this) || this;
  17723. _this.type = 'PolyhedronBufferGeometry';
  17724. _this.parameters = {
  17725. vertices: vertices,
  17726. indices: indices,
  17727. radius: radius,
  17728. detail: detail
  17729. }; // default buffer data
  17730. var vertexBuffer = [];
  17731. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17732. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17733. applyRadius(radius); // finally, create the uv data
  17734. generateUVs(); // build non-indexed geometry
  17735. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17736. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17737. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17738. if (detail === 0) {
  17739. _this.computeVertexNormals(); // flat normals
  17740. } else {
  17741. _this.normalizeNormals(); // smooth normals
  17742. } // helper functions
  17743. function subdivide(detail) {
  17744. var a = new Vector3();
  17745. var b = new Vector3();
  17746. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17747. for (var i = 0; i < indices.length; i += 3) {
  17748. // get the vertices of the face
  17749. getVertexByIndex(indices[i + 0], a);
  17750. getVertexByIndex(indices[i + 1], b);
  17751. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17752. subdivideFace(a, b, c, detail);
  17753. }
  17754. }
  17755. function subdivideFace(a, b, c, detail) {
  17756. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17757. var v = []; // construct all of the vertices for this subdivision
  17758. for (var i = 0; i <= cols; i++) {
  17759. v[i] = [];
  17760. var aj = a.clone().lerp(c, i / cols);
  17761. var bj = b.clone().lerp(c, i / cols);
  17762. var rows = cols - i;
  17763. for (var j = 0; j <= rows; j++) {
  17764. if (j === 0 && i === cols) {
  17765. v[i][j] = aj;
  17766. } else {
  17767. v[i][j] = aj.clone().lerp(bj, j / rows);
  17768. }
  17769. }
  17770. } // construct all of the faces
  17771. for (var _i = 0; _i < cols; _i++) {
  17772. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17773. var k = Math.floor(_j / 2);
  17774. if (_j % 2 === 0) {
  17775. pushVertex(v[_i][k + 1]);
  17776. pushVertex(v[_i + 1][k]);
  17777. pushVertex(v[_i][k]);
  17778. } else {
  17779. pushVertex(v[_i][k + 1]);
  17780. pushVertex(v[_i + 1][k + 1]);
  17781. pushVertex(v[_i + 1][k]);
  17782. }
  17783. }
  17784. }
  17785. }
  17786. function applyRadius(radius) {
  17787. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17788. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17789. vertex.x = vertexBuffer[i + 0];
  17790. vertex.y = vertexBuffer[i + 1];
  17791. vertex.z = vertexBuffer[i + 2];
  17792. vertex.normalize().multiplyScalar(radius);
  17793. vertexBuffer[i + 0] = vertex.x;
  17794. vertexBuffer[i + 1] = vertex.y;
  17795. vertexBuffer[i + 2] = vertex.z;
  17796. }
  17797. }
  17798. function generateUVs() {
  17799. var vertex = new Vector3();
  17800. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17801. vertex.x = vertexBuffer[i + 0];
  17802. vertex.y = vertexBuffer[i + 1];
  17803. vertex.z = vertexBuffer[i + 2];
  17804. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17805. var v = inclination(vertex) / Math.PI + 0.5;
  17806. uvBuffer.push(u, 1 - v);
  17807. }
  17808. correctUVs();
  17809. correctSeam();
  17810. }
  17811. function correctSeam() {
  17812. // handle case when face straddles the seam, see #3269
  17813. for (var i = 0; i < uvBuffer.length; i += 6) {
  17814. // uv data of a single face
  17815. var x0 = uvBuffer[i + 0];
  17816. var x1 = uvBuffer[i + 2];
  17817. var x2 = uvBuffer[i + 4];
  17818. var max = Math.max(x0, x1, x2);
  17819. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17820. if (max > 0.9 && min < 0.1) {
  17821. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17822. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17823. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17824. }
  17825. }
  17826. }
  17827. function pushVertex(vertex) {
  17828. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17829. }
  17830. function getVertexByIndex(index, vertex) {
  17831. var stride = index * 3;
  17832. vertex.x = vertices[stride + 0];
  17833. vertex.y = vertices[stride + 1];
  17834. vertex.z = vertices[stride + 2];
  17835. }
  17836. function correctUVs() {
  17837. var a = new Vector3();
  17838. var b = new Vector3();
  17839. var c = new Vector3();
  17840. var centroid = new Vector3();
  17841. var uvA = new Vector2();
  17842. var uvB = new Vector2();
  17843. var uvC = new Vector2();
  17844. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17845. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17846. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17847. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17848. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17849. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17850. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17851. centroid.copy(a).add(b).add(c).divideScalar(3);
  17852. var azi = azimuth(centroid);
  17853. correctUV(uvA, j + 0, a, azi);
  17854. correctUV(uvB, j + 2, b, azi);
  17855. correctUV(uvC, j + 4, c, azi);
  17856. }
  17857. }
  17858. function correctUV(uv, stride, vector, azimuth) {
  17859. if (azimuth < 0 && uv.x === 1) {
  17860. uvBuffer[stride] = uv.x - 1;
  17861. }
  17862. if (vector.x === 0 && vector.z === 0) {
  17863. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17864. }
  17865. } // Angle around the Y axis, counter-clockwise when looking from above.
  17866. function azimuth(vector) {
  17867. return Math.atan2(vector.z, -vector.x);
  17868. } // Angle above the XZ plane.
  17869. function inclination(vector) {
  17870. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17871. }
  17872. return _this;
  17873. }
  17874. return PolyhedronBufferGeometry;
  17875. }(BufferGeometry);
  17876. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17877. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17878. function DodecahedronBufferGeometry(radius, detail) {
  17879. var _this;
  17880. if (radius === void 0) {
  17881. radius = 1;
  17882. }
  17883. if (detail === void 0) {
  17884. detail = 0;
  17885. }
  17886. var t = (1 + Math.sqrt(5)) / 2;
  17887. var r = 1 / t;
  17888. var vertices = [// (±1, ±1, ±1)
  17889. -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/φ, ±φ)
  17890. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17891. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17892. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17893. 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];
  17894. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17895. _this.type = 'DodecahedronBufferGeometry';
  17896. _this.parameters = {
  17897. radius: radius,
  17898. detail: detail
  17899. };
  17900. return _this;
  17901. }
  17902. return DodecahedronBufferGeometry;
  17903. }(PolyhedronBufferGeometry);
  17904. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17905. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17906. function DodecahedronGeometry(radius, detail) {
  17907. var _this;
  17908. _this = _Geometry.call(this) || this;
  17909. _this.type = 'DodecahedronGeometry';
  17910. _this.parameters = {
  17911. radius: radius,
  17912. detail: detail
  17913. };
  17914. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17915. _this.mergeVertices();
  17916. return _this;
  17917. }
  17918. return DodecahedronGeometry;
  17919. }(Geometry);
  17920. var _v0$2 = new Vector3();
  17921. var _v1$5 = new Vector3();
  17922. var _normal$1 = new Vector3();
  17923. var _triangle = new Triangle();
  17924. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17925. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17926. function EdgesGeometry(geometry, thresholdAngle) {
  17927. var _this;
  17928. _this = _BufferGeometry.call(this) || this;
  17929. _this.type = 'EdgesGeometry';
  17930. _this.parameters = {
  17931. thresholdAngle: thresholdAngle
  17932. };
  17933. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17934. if (geometry.isGeometry) {
  17935. geometry = new BufferGeometry().fromGeometry(geometry);
  17936. }
  17937. var precisionPoints = 4;
  17938. var precision = Math.pow(10, precisionPoints);
  17939. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17940. var indexAttr = geometry.getIndex();
  17941. var positionAttr = geometry.getAttribute('position');
  17942. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17943. var indexArr = [0, 0, 0];
  17944. var vertKeys = ['a', 'b', 'c'];
  17945. var hashes = new Array(3);
  17946. var edgeData = {};
  17947. var vertices = [];
  17948. for (var i = 0; i < indexCount; i += 3) {
  17949. if (indexAttr) {
  17950. indexArr[0] = indexAttr.getX(i);
  17951. indexArr[1] = indexAttr.getX(i + 1);
  17952. indexArr[2] = indexAttr.getX(i + 2);
  17953. } else {
  17954. indexArr[0] = i;
  17955. indexArr[1] = i + 1;
  17956. indexArr[2] = i + 2;
  17957. }
  17958. var a = _triangle.a,
  17959. b = _triangle.b,
  17960. c = _triangle.c;
  17961. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17962. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17963. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17964. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17965. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17966. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17967. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17968. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17969. continue;
  17970. } // iterate over every edge
  17971. for (var j = 0; j < 3; j++) {
  17972. // get the first and next vertex making up the edge
  17973. var jNext = (j + 1) % 3;
  17974. var vecHash0 = hashes[j];
  17975. var vecHash1 = hashes[jNext];
  17976. var v0 = _triangle[vertKeys[j]];
  17977. var v1 = _triangle[vertKeys[jNext]];
  17978. var hash = vecHash0 + "_" + vecHash1;
  17979. var reverseHash = vecHash1 + "_" + vecHash0;
  17980. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17981. // if we found a sibling edge add it into the vertex array if
  17982. // it meets the angle threshold and delete the edge from the map.
  17983. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17984. vertices.push(v0.x, v0.y, v0.z);
  17985. vertices.push(v1.x, v1.y, v1.z);
  17986. }
  17987. edgeData[reverseHash] = null;
  17988. } else if (!(hash in edgeData)) {
  17989. // if we've already got an edge here then skip adding a new one
  17990. edgeData[hash] = {
  17991. index0: indexArr[j],
  17992. index1: indexArr[jNext],
  17993. normal: _normal$1.clone()
  17994. };
  17995. }
  17996. }
  17997. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17998. for (var key in edgeData) {
  17999. if (edgeData[key]) {
  18000. var _edgeData$key = edgeData[key],
  18001. index0 = _edgeData$key.index0,
  18002. index1 = _edgeData$key.index1;
  18003. _v0$2.fromBufferAttribute(positionAttr, index0);
  18004. _v1$5.fromBufferAttribute(positionAttr, index1);
  18005. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  18006. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  18007. }
  18008. }
  18009. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18010. return _this;
  18011. }
  18012. return EdgesGeometry;
  18013. }(BufferGeometry);
  18014. /**
  18015. * Port from https://github.com/mapbox/earcut (v2.2.2)
  18016. */
  18017. var Earcut = {
  18018. triangulate: function triangulate(data, holeIndices, dim) {
  18019. dim = dim || 2;
  18020. var hasHoles = holeIndices && holeIndices.length;
  18021. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  18022. var outerNode = linkedList(data, 0, outerLen, dim, true);
  18023. var triangles = [];
  18024. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  18025. var minX, minY, maxX, maxY, x, y, invSize;
  18026. 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
  18027. if (data.length > 80 * dim) {
  18028. minX = maxX = data[0];
  18029. minY = maxY = data[1];
  18030. for (var i = dim; i < outerLen; i += dim) {
  18031. x = data[i];
  18032. y = data[i + 1];
  18033. if (x < minX) minX = x;
  18034. if (y < minY) minY = y;
  18035. if (x > maxX) maxX = x;
  18036. if (y > maxY) maxY = y;
  18037. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18038. invSize = Math.max(maxX - minX, maxY - minY);
  18039. invSize = invSize !== 0 ? 1 / invSize : 0;
  18040. }
  18041. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  18042. return triangles;
  18043. }
  18044. }; // create a circular doubly linked list from polygon points in the specified winding order
  18045. function linkedList(data, start, end, dim, clockwise) {
  18046. var i, last;
  18047. if (clockwise === signedArea(data, start, end, dim) > 0) {
  18048. for (i = start; i < end; i += dim) {
  18049. last = insertNode(i, data[i], data[i + 1], last);
  18050. }
  18051. } else {
  18052. for (i = end - dim; i >= start; i -= dim) {
  18053. last = insertNode(i, data[i], data[i + 1], last);
  18054. }
  18055. }
  18056. if (last && equals(last, last.next)) {
  18057. removeNode(last);
  18058. last = last.next;
  18059. }
  18060. return last;
  18061. } // eliminate colinear or duplicate points
  18062. function filterPoints(start, end) {
  18063. if (!start) return start;
  18064. if (!end) end = start;
  18065. var p = start,
  18066. again;
  18067. do {
  18068. again = false;
  18069. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  18070. removeNode(p);
  18071. p = end = p.prev;
  18072. if (p === p.next) break;
  18073. again = true;
  18074. } else {
  18075. p = p.next;
  18076. }
  18077. } while (again || p !== end);
  18078. return end;
  18079. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  18080. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  18081. if (!ear) return; // interlink polygon nodes in z-order
  18082. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  18083. var stop = ear,
  18084. prev,
  18085. next; // iterate through ears, slicing them one by one
  18086. while (ear.prev !== ear.next) {
  18087. prev = ear.prev;
  18088. next = ear.next;
  18089. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  18090. // cut off the triangle
  18091. triangles.push(prev.i / dim);
  18092. triangles.push(ear.i / dim);
  18093. triangles.push(next.i / dim);
  18094. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  18095. ear = next.next;
  18096. stop = next.next;
  18097. continue;
  18098. }
  18099. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  18100. if (ear === stop) {
  18101. // try filtering points and slicing again
  18102. if (!pass) {
  18103. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  18104. } else if (pass === 1) {
  18105. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  18106. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  18107. } else if (pass === 2) {
  18108. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  18109. }
  18110. break;
  18111. }
  18112. }
  18113. } // check whether a polygon node forms a valid ear with adjacent nodes
  18114. function isEar(ear) {
  18115. var a = ear.prev,
  18116. b = ear,
  18117. c = ear.next;
  18118. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18119. // now make sure we don't have other points inside the potential ear
  18120. var p = ear.next.next;
  18121. while (p !== ear.prev) {
  18122. 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;
  18123. p = p.next;
  18124. }
  18125. return true;
  18126. }
  18127. function isEarHashed(ear, minX, minY, invSize) {
  18128. var a = ear.prev,
  18129. b = ear,
  18130. c = ear.next;
  18131. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18132. // triangle bbox; min & max are calculated like this for speed
  18133. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18134. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18135. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18136. 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;
  18137. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18138. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18139. var p = ear.prevZ,
  18140. n = ear.nextZ; // look for points inside the triangle in both directions
  18141. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18142. 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;
  18143. p = p.prevZ;
  18144. 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;
  18145. n = n.nextZ;
  18146. } // look for remaining points in decreasing z-order
  18147. while (p && p.z >= minZ) {
  18148. 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;
  18149. p = p.prevZ;
  18150. } // look for remaining points in increasing z-order
  18151. while (n && n.z <= maxZ) {
  18152. 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;
  18153. n = n.nextZ;
  18154. }
  18155. return true;
  18156. } // go through all polygon nodes and cure small local self-intersections
  18157. function cureLocalIntersections(start, triangles, dim) {
  18158. var p = start;
  18159. do {
  18160. var a = p.prev,
  18161. b = p.next.next;
  18162. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18163. triangles.push(a.i / dim);
  18164. triangles.push(p.i / dim);
  18165. triangles.push(b.i / dim); // remove two nodes involved
  18166. removeNode(p);
  18167. removeNode(p.next);
  18168. p = start = b;
  18169. }
  18170. p = p.next;
  18171. } while (p !== start);
  18172. return filterPoints(p);
  18173. } // try splitting polygon into two and triangulate them independently
  18174. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18175. // look for a valid diagonal that divides the polygon into two
  18176. var a = start;
  18177. do {
  18178. var b = a.next.next;
  18179. while (b !== a.prev) {
  18180. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18181. // split the polygon in two by the diagonal
  18182. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18183. a = filterPoints(a, a.next);
  18184. c = filterPoints(c, c.next); // run earcut on each half
  18185. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18186. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18187. return;
  18188. }
  18189. b = b.next;
  18190. }
  18191. a = a.next;
  18192. } while (a !== start);
  18193. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18194. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18195. var queue = [];
  18196. var i, len, start, end, list;
  18197. for (i = 0, len = holeIndices.length; i < len; i++) {
  18198. start = holeIndices[i] * dim;
  18199. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18200. list = linkedList(data, start, end, dim, false);
  18201. if (list === list.next) list.steiner = true;
  18202. queue.push(getLeftmost(list));
  18203. }
  18204. queue.sort(compareX); // process holes from left to right
  18205. for (i = 0; i < queue.length; i++) {
  18206. eliminateHole(queue[i], outerNode);
  18207. outerNode = filterPoints(outerNode, outerNode.next);
  18208. }
  18209. return outerNode;
  18210. }
  18211. function compareX(a, b) {
  18212. return a.x - b.x;
  18213. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18214. function eliminateHole(hole, outerNode) {
  18215. outerNode = findHoleBridge(hole, outerNode);
  18216. if (outerNode) {
  18217. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18218. filterPoints(outerNode, outerNode.next);
  18219. filterPoints(b, b.next);
  18220. }
  18221. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18222. function findHoleBridge(hole, outerNode) {
  18223. var p = outerNode;
  18224. var hx = hole.x;
  18225. var hy = hole.y;
  18226. var qx = -Infinity,
  18227. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18228. // segment's endpoint with lesser x will be potential connection point
  18229. do {
  18230. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18231. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18232. if (x <= hx && x > qx) {
  18233. qx = x;
  18234. if (x === hx) {
  18235. if (hy === p.y) return p;
  18236. if (hy === p.next.y) return p.next;
  18237. }
  18238. m = p.x < p.next.x ? p : p.next;
  18239. }
  18240. }
  18241. p = p.next;
  18242. } while (p !== outerNode);
  18243. if (!m) return null;
  18244. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18245. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18246. // if there are no points found, we have a valid connection;
  18247. // otherwise choose the point of the minimum angle with the ray as connection point
  18248. var stop = m,
  18249. mx = m.x,
  18250. my = m.y;
  18251. var tanMin = Infinity,
  18252. tan;
  18253. p = m;
  18254. do {
  18255. 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)) {
  18256. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18257. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18258. m = p;
  18259. tanMin = tan;
  18260. }
  18261. }
  18262. p = p.next;
  18263. } while (p !== stop);
  18264. return m;
  18265. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18266. function sectorContainsSector(m, p) {
  18267. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18268. } // interlink polygon nodes in z-order
  18269. function indexCurve(start, minX, minY, invSize) {
  18270. var p = start;
  18271. do {
  18272. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18273. p.prevZ = p.prev;
  18274. p.nextZ = p.next;
  18275. p = p.next;
  18276. } while (p !== start);
  18277. p.prevZ.nextZ = null;
  18278. p.prevZ = null;
  18279. sortLinked(p);
  18280. } // Simon Tatham's linked list merge sort algorithm
  18281. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18282. function sortLinked(list) {
  18283. var i,
  18284. p,
  18285. q,
  18286. e,
  18287. tail,
  18288. numMerges,
  18289. pSize,
  18290. qSize,
  18291. inSize = 1;
  18292. do {
  18293. p = list;
  18294. list = null;
  18295. tail = null;
  18296. numMerges = 0;
  18297. while (p) {
  18298. numMerges++;
  18299. q = p;
  18300. pSize = 0;
  18301. for (i = 0; i < inSize; i++) {
  18302. pSize++;
  18303. q = q.nextZ;
  18304. if (!q) break;
  18305. }
  18306. qSize = inSize;
  18307. while (pSize > 0 || qSize > 0 && q) {
  18308. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18309. e = p;
  18310. p = p.nextZ;
  18311. pSize--;
  18312. } else {
  18313. e = q;
  18314. q = q.nextZ;
  18315. qSize--;
  18316. }
  18317. if (tail) tail.nextZ = e;else list = e;
  18318. e.prevZ = tail;
  18319. tail = e;
  18320. }
  18321. p = q;
  18322. }
  18323. tail.nextZ = null;
  18324. inSize *= 2;
  18325. } while (numMerges > 1);
  18326. return list;
  18327. } // z-order of a point given coords and inverse of the longer side of data bbox
  18328. function zOrder(x, y, minX, minY, invSize) {
  18329. // coords are transformed into non-negative 15-bit integer range
  18330. x = 32767 * (x - minX) * invSize;
  18331. y = 32767 * (y - minY) * invSize;
  18332. x = (x | x << 8) & 0x00FF00FF;
  18333. x = (x | x << 4) & 0x0F0F0F0F;
  18334. x = (x | x << 2) & 0x33333333;
  18335. x = (x | x << 1) & 0x55555555;
  18336. y = (y | y << 8) & 0x00FF00FF;
  18337. y = (y | y << 4) & 0x0F0F0F0F;
  18338. y = (y | y << 2) & 0x33333333;
  18339. y = (y | y << 1) & 0x55555555;
  18340. return x | y << 1;
  18341. } // find the leftmost node of a polygon ring
  18342. function getLeftmost(start) {
  18343. var p = start,
  18344. leftmost = start;
  18345. do {
  18346. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18347. p = p.next;
  18348. } while (p !== start);
  18349. return leftmost;
  18350. } // check if a point lies within a convex triangle
  18351. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18352. 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;
  18353. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18354. function isValidDiagonal(a, b) {
  18355. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18356. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18357. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18358. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18359. } // signed area of a triangle
  18360. function area(p, q, r) {
  18361. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18362. } // check if two points are equal
  18363. function equals(p1, p2) {
  18364. return p1.x === p2.x && p1.y === p2.y;
  18365. } // check if two segments intersect
  18366. function intersects(p1, q1, p2, q2) {
  18367. var o1 = sign(area(p1, q1, p2));
  18368. var o2 = sign(area(p1, q1, q2));
  18369. var o3 = sign(area(p2, q2, p1));
  18370. var o4 = sign(area(p2, q2, q1));
  18371. if (o1 !== o2 && o3 !== o4) return true; // general case
  18372. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18373. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18374. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18375. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18376. return false;
  18377. } // for collinear points p, q, r, check if point q lies on segment pr
  18378. function onSegment(p, q, r) {
  18379. 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);
  18380. }
  18381. function sign(num) {
  18382. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18383. } // check if a polygon diagonal intersects any polygon segments
  18384. function intersectsPolygon(a, b) {
  18385. var p = a;
  18386. do {
  18387. 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;
  18388. p = p.next;
  18389. } while (p !== a);
  18390. return false;
  18391. } // check if a polygon diagonal is locally inside the polygon
  18392. function locallyInside(a, b) {
  18393. 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;
  18394. } // check if the middle point of a polygon diagonal is inside the polygon
  18395. function middleInside(a, b) {
  18396. var p = a,
  18397. inside = false;
  18398. var px = (a.x + b.x) / 2,
  18399. py = (a.y + b.y) / 2;
  18400. do {
  18401. 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;
  18402. p = p.next;
  18403. } while (p !== a);
  18404. return inside;
  18405. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18406. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18407. function splitPolygon(a, b) {
  18408. var a2 = new Node(a.i, a.x, a.y),
  18409. b2 = new Node(b.i, b.x, b.y),
  18410. an = a.next,
  18411. bp = b.prev;
  18412. a.next = b;
  18413. b.prev = a;
  18414. a2.next = an;
  18415. an.prev = a2;
  18416. b2.next = a2;
  18417. a2.prev = b2;
  18418. bp.next = b2;
  18419. b2.prev = bp;
  18420. return b2;
  18421. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18422. function insertNode(i, x, y, last) {
  18423. var p = new Node(i, x, y);
  18424. if (!last) {
  18425. p.prev = p;
  18426. p.next = p;
  18427. } else {
  18428. p.next = last.next;
  18429. p.prev = last;
  18430. last.next.prev = p;
  18431. last.next = p;
  18432. }
  18433. return p;
  18434. }
  18435. function removeNode(p) {
  18436. p.next.prev = p.prev;
  18437. p.prev.next = p.next;
  18438. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18439. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18440. }
  18441. function Node(i, x, y) {
  18442. // vertex index in coordinates array
  18443. this.i = i; // vertex coordinates
  18444. this.x = x;
  18445. this.y = y; // previous and next vertex nodes in a polygon ring
  18446. this.prev = null;
  18447. this.next = null; // z-order curve value
  18448. this.z = null; // previous and next nodes in z-order
  18449. this.prevZ = null;
  18450. this.nextZ = null; // indicates whether this is a steiner point
  18451. this.steiner = false;
  18452. }
  18453. function signedArea(data, start, end, dim) {
  18454. var sum = 0;
  18455. for (var i = start, j = end - dim; i < end; i += dim) {
  18456. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18457. j = i;
  18458. }
  18459. return sum;
  18460. }
  18461. var ShapeUtils = {
  18462. // calculate area of the contour polygon
  18463. area: function area(contour) {
  18464. var n = contour.length;
  18465. var a = 0.0;
  18466. for (var p = n - 1, q = 0; q < n; p = q++) {
  18467. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18468. }
  18469. return a * 0.5;
  18470. },
  18471. isClockWise: function isClockWise(pts) {
  18472. return ShapeUtils.area(pts) < 0;
  18473. },
  18474. triangulateShape: function triangulateShape(contour, holes) {
  18475. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18476. var holeIndices = []; // array of hole indices
  18477. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18478. removeDupEndPts(contour);
  18479. addContour(vertices, contour); //
  18480. var holeIndex = contour.length;
  18481. holes.forEach(removeDupEndPts);
  18482. for (var i = 0; i < holes.length; i++) {
  18483. holeIndices.push(holeIndex);
  18484. holeIndex += holes[i].length;
  18485. addContour(vertices, holes[i]);
  18486. } //
  18487. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18488. for (var _i = 0; _i < triangles.length; _i += 3) {
  18489. faces.push(triangles.slice(_i, _i + 3));
  18490. }
  18491. return faces;
  18492. }
  18493. };
  18494. function removeDupEndPts(points) {
  18495. var l = points.length;
  18496. if (l > 2 && points[l - 1].equals(points[0])) {
  18497. points.pop();
  18498. }
  18499. }
  18500. function addContour(vertices, contour) {
  18501. for (var i = 0; i < contour.length; i++) {
  18502. vertices.push(contour[i].x);
  18503. vertices.push(contour[i].y);
  18504. }
  18505. }
  18506. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18507. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18508. function ExtrudeBufferGeometry(shapes, options) {
  18509. var _this;
  18510. _this = _BufferGeometry.call(this) || this;
  18511. _this.type = 'ExtrudeBufferGeometry';
  18512. _this.parameters = {
  18513. shapes: shapes,
  18514. options: options
  18515. };
  18516. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18517. var scope = _assertThisInitialized(_this);
  18518. var verticesArray = [];
  18519. var uvArray = [];
  18520. for (var i = 0, l = shapes.length; i < l; i++) {
  18521. var shape = shapes[i];
  18522. addShape(shape);
  18523. } // build geometry
  18524. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18525. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18526. _this.computeVertexNormals(); // functions
  18527. function addShape(shape) {
  18528. var placeholder = []; // options
  18529. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18530. var steps = options.steps !== undefined ? options.steps : 1;
  18531. var depth = options.depth !== undefined ? options.depth : 100;
  18532. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18533. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18534. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18535. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18536. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18537. var extrudePath = options.extrudePath;
  18538. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18539. if (options.amount !== undefined) {
  18540. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18541. depth = options.amount;
  18542. } //
  18543. var extrudePts,
  18544. extrudeByPath = false;
  18545. var splineTube, binormal, normal, position2;
  18546. if (extrudePath) {
  18547. extrudePts = extrudePath.getSpacedPoints(steps);
  18548. extrudeByPath = true;
  18549. bevelEnabled = false; // bevels not supported for path extrusion
  18550. // SETUP TNB variables
  18551. // TODO1 - have a .isClosed in spline?
  18552. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18553. binormal = new Vector3();
  18554. normal = new Vector3();
  18555. position2 = new Vector3();
  18556. } // Safeguards if bevels are not enabled
  18557. if (!bevelEnabled) {
  18558. bevelSegments = 0;
  18559. bevelThickness = 0;
  18560. bevelSize = 0;
  18561. bevelOffset = 0;
  18562. } // Variables initialization
  18563. var shapePoints = shape.extractPoints(curveSegments);
  18564. var vertices = shapePoints.shape;
  18565. var holes = shapePoints.holes;
  18566. var reverse = !ShapeUtils.isClockWise(vertices);
  18567. if (reverse) {
  18568. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18569. for (var h = 0, hl = holes.length; h < hl; h++) {
  18570. var ahole = holes[h];
  18571. if (ShapeUtils.isClockWise(ahole)) {
  18572. holes[h] = ahole.reverse();
  18573. }
  18574. }
  18575. }
  18576. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18577. /* Vertices */
  18578. var contour = vertices; // vertices has all points but contour has only points of circumference
  18579. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18580. var _ahole = holes[_h];
  18581. vertices = vertices.concat(_ahole);
  18582. }
  18583. function scalePt2(pt, vec, size) {
  18584. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18585. return vec.clone().multiplyScalar(size).add(pt);
  18586. }
  18587. var vlen = vertices.length,
  18588. flen = faces.length; // Find directions for point movement
  18589. function getBevelVec(inPt, inPrev, inNext) {
  18590. // computes for inPt the corresponding point inPt' on a new contour
  18591. // shifted by 1 unit (length of normalized vector) to the left
  18592. // if we walk along contour clockwise, this new contour is outside the old one
  18593. //
  18594. // inPt' is the intersection of the two lines parallel to the two
  18595. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18596. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18597. // good reading for geometry algorithms (here: line-line intersection)
  18598. // http://geomalgorithms.com/a05-_intersect-1.html
  18599. var v_prev_x = inPt.x - inPrev.x,
  18600. v_prev_y = inPt.y - inPrev.y;
  18601. var v_next_x = inNext.x - inPt.x,
  18602. v_next_y = inNext.y - inPt.y;
  18603. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18604. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18605. if (Math.abs(collinear0) > Number.EPSILON) {
  18606. // not collinear
  18607. // length of vectors for normalizing
  18608. var v_prev_len = Math.sqrt(v_prev_lensq);
  18609. 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
  18610. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18611. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18612. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18613. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18614. 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
  18615. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18616. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18617. // but prevent crazy spikes
  18618. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18619. if (v_trans_lensq <= 2) {
  18620. return new Vector2(v_trans_x, v_trans_y);
  18621. } else {
  18622. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18623. }
  18624. } else {
  18625. // handle special case of collinear edges
  18626. var direction_eq = false; // assumes: opposite
  18627. if (v_prev_x > Number.EPSILON) {
  18628. if (v_next_x > Number.EPSILON) {
  18629. direction_eq = true;
  18630. }
  18631. } else {
  18632. if (v_prev_x < -Number.EPSILON) {
  18633. if (v_next_x < -Number.EPSILON) {
  18634. direction_eq = true;
  18635. }
  18636. } else {
  18637. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18638. direction_eq = true;
  18639. }
  18640. }
  18641. }
  18642. if (direction_eq) {
  18643. // console.log("Warning: lines are a straight sequence");
  18644. v_trans_x = -v_prev_y;
  18645. v_trans_y = v_prev_x;
  18646. shrink_by = Math.sqrt(v_prev_lensq);
  18647. } else {
  18648. // console.log("Warning: lines are a straight spike");
  18649. v_trans_x = v_prev_x;
  18650. v_trans_y = v_prev_y;
  18651. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18652. }
  18653. }
  18654. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18655. }
  18656. var contourMovements = [];
  18657. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18658. if (j === il) j = 0;
  18659. if (k === il) k = 0; // (j)---(i)---(k)
  18660. // console.log('i,j,k', i, j , k)
  18661. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18662. }
  18663. var holesMovements = [];
  18664. var oneHoleMovements,
  18665. verticesMovements = contourMovements.concat();
  18666. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18667. var _ahole2 = holes[_h2];
  18668. oneHoleMovements = [];
  18669. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18670. if (_j === _il) _j = 0;
  18671. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18672. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18673. }
  18674. holesMovements.push(oneHoleMovements);
  18675. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18676. } // Loop bevelSegments, 1 for the front, 1 for the back
  18677. for (var b = 0; b < bevelSegments; b++) {
  18678. //for ( b = bevelSegments; b > 0; b -- ) {
  18679. var t = b / bevelSegments;
  18680. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18681. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18682. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18683. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18684. v(vert.x, vert.y, -z);
  18685. } // expand holes
  18686. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18687. var _ahole3 = holes[_h3];
  18688. oneHoleMovements = holesMovements[_h3];
  18689. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18690. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18691. v(_vert.x, _vert.y, -z);
  18692. }
  18693. }
  18694. }
  18695. var bs = bevelSize + bevelOffset; // Back facing vertices
  18696. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18697. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18698. if (!extrudeByPath) {
  18699. v(_vert2.x, _vert2.y, 0);
  18700. } else {
  18701. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18702. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18703. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18704. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18705. v(position2.x, position2.y, position2.z);
  18706. }
  18707. } // Add stepped vertices...
  18708. // Including front facing vertices
  18709. for (var s = 1; s <= steps; s++) {
  18710. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18711. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18712. if (!extrudeByPath) {
  18713. v(_vert3.x, _vert3.y, depth / steps * s);
  18714. } else {
  18715. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18716. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18717. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18718. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18719. v(position2.x, position2.y, position2.z);
  18720. }
  18721. }
  18722. } // Add bevel segments planes
  18723. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18724. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18725. var _t = _b / bevelSegments;
  18726. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18727. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18728. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18729. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18730. v(_vert4.x, _vert4.y, depth + _z);
  18731. } // expand holes
  18732. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18733. var _ahole4 = holes[_h4];
  18734. oneHoleMovements = holesMovements[_h4];
  18735. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18736. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18737. if (!extrudeByPath) {
  18738. v(_vert5.x, _vert5.y, depth + _z);
  18739. } else {
  18740. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18741. }
  18742. }
  18743. }
  18744. }
  18745. /* Faces */
  18746. // Top and bottom faces
  18747. buildLidFaces(); // Sides faces
  18748. buildSideFaces(); ///// Internal functions
  18749. function buildLidFaces() {
  18750. var start = verticesArray.length / 3;
  18751. if (bevelEnabled) {
  18752. var layer = 0; // steps + 1
  18753. var offset = vlen * layer; // Bottom faces
  18754. for (var _i9 = 0; _i9 < flen; _i9++) {
  18755. var face = faces[_i9];
  18756. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18757. }
  18758. layer = steps + bevelSegments * 2;
  18759. offset = vlen * layer; // Top faces
  18760. for (var _i10 = 0; _i10 < flen; _i10++) {
  18761. var _face = faces[_i10];
  18762. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18763. }
  18764. } else {
  18765. // Bottom faces
  18766. for (var _i11 = 0; _i11 < flen; _i11++) {
  18767. var _face2 = faces[_i11];
  18768. f3(_face2[2], _face2[1], _face2[0]);
  18769. } // Top faces
  18770. for (var _i12 = 0; _i12 < flen; _i12++) {
  18771. var _face3 = faces[_i12];
  18772. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18773. }
  18774. }
  18775. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18776. } // Create faces for the z-sides of the shape
  18777. function buildSideFaces() {
  18778. var start = verticesArray.length / 3;
  18779. var layeroffset = 0;
  18780. sidewalls(contour, layeroffset);
  18781. layeroffset += contour.length;
  18782. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18783. var _ahole5 = holes[_h5];
  18784. sidewalls(_ahole5, layeroffset); //, true
  18785. layeroffset += _ahole5.length;
  18786. }
  18787. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18788. }
  18789. function sidewalls(contour, layeroffset) {
  18790. var i = contour.length;
  18791. while (--i >= 0) {
  18792. var _j2 = i;
  18793. var _k2 = i - 1;
  18794. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18795. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18796. var slen1 = vlen * _s;
  18797. var slen2 = vlen * (_s + 1);
  18798. var a = layeroffset + _j2 + slen1,
  18799. _b2 = layeroffset + _k2 + slen1,
  18800. c = layeroffset + _k2 + slen2,
  18801. d = layeroffset + _j2 + slen2;
  18802. f4(a, _b2, c, d);
  18803. }
  18804. }
  18805. }
  18806. function v(x, y, z) {
  18807. placeholder.push(x);
  18808. placeholder.push(y);
  18809. placeholder.push(z);
  18810. }
  18811. function f3(a, b, c) {
  18812. addVertex(a);
  18813. addVertex(b);
  18814. addVertex(c);
  18815. var nextIndex = verticesArray.length / 3;
  18816. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18817. addUV(uvs[0]);
  18818. addUV(uvs[1]);
  18819. addUV(uvs[2]);
  18820. }
  18821. function f4(a, b, c, d) {
  18822. addVertex(a);
  18823. addVertex(b);
  18824. addVertex(d);
  18825. addVertex(b);
  18826. addVertex(c);
  18827. addVertex(d);
  18828. var nextIndex = verticesArray.length / 3;
  18829. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18830. addUV(uvs[0]);
  18831. addUV(uvs[1]);
  18832. addUV(uvs[3]);
  18833. addUV(uvs[1]);
  18834. addUV(uvs[2]);
  18835. addUV(uvs[3]);
  18836. }
  18837. function addVertex(index) {
  18838. verticesArray.push(placeholder[index * 3 + 0]);
  18839. verticesArray.push(placeholder[index * 3 + 1]);
  18840. verticesArray.push(placeholder[index * 3 + 2]);
  18841. }
  18842. function addUV(vector2) {
  18843. uvArray.push(vector2.x);
  18844. uvArray.push(vector2.y);
  18845. }
  18846. }
  18847. return _this;
  18848. }
  18849. var _proto = ExtrudeBufferGeometry.prototype;
  18850. _proto.toJSON = function toJSON() {
  18851. var data = BufferGeometry.prototype.toJSON.call(this);
  18852. var shapes = this.parameters.shapes;
  18853. var options = this.parameters.options;
  18854. return _toJSON(shapes, options, data);
  18855. };
  18856. return ExtrudeBufferGeometry;
  18857. }(BufferGeometry);
  18858. var WorldUVGenerator = {
  18859. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18860. var a_x = vertices[indexA * 3];
  18861. var a_y = vertices[indexA * 3 + 1];
  18862. var b_x = vertices[indexB * 3];
  18863. var b_y = vertices[indexB * 3 + 1];
  18864. var c_x = vertices[indexC * 3];
  18865. var c_y = vertices[indexC * 3 + 1];
  18866. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18867. },
  18868. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18869. var a_x = vertices[indexA * 3];
  18870. var a_y = vertices[indexA * 3 + 1];
  18871. var a_z = vertices[indexA * 3 + 2];
  18872. var b_x = vertices[indexB * 3];
  18873. var b_y = vertices[indexB * 3 + 1];
  18874. var b_z = vertices[indexB * 3 + 2];
  18875. var c_x = vertices[indexC * 3];
  18876. var c_y = vertices[indexC * 3 + 1];
  18877. var c_z = vertices[indexC * 3 + 2];
  18878. var d_x = vertices[indexD * 3];
  18879. var d_y = vertices[indexD * 3 + 1];
  18880. var d_z = vertices[indexD * 3 + 2];
  18881. if (Math.abs(a_y - b_y) < 0.01) {
  18882. 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)];
  18883. } else {
  18884. 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)];
  18885. }
  18886. }
  18887. };
  18888. function _toJSON(shapes, options, data) {
  18889. data.shapes = [];
  18890. if (Array.isArray(shapes)) {
  18891. for (var i = 0, l = shapes.length; i < l; i++) {
  18892. var shape = shapes[i];
  18893. data.shapes.push(shape.uuid);
  18894. }
  18895. } else {
  18896. data.shapes.push(shapes.uuid);
  18897. }
  18898. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18899. return data;
  18900. }
  18901. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18902. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18903. function ExtrudeGeometry(shapes, options) {
  18904. var _this;
  18905. _this = _Geometry.call(this) || this;
  18906. _this.type = 'ExtrudeGeometry';
  18907. _this.parameters = {
  18908. shapes: shapes,
  18909. options: options
  18910. };
  18911. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18912. _this.mergeVertices();
  18913. return _this;
  18914. }
  18915. var _proto = ExtrudeGeometry.prototype;
  18916. _proto.toJSON = function toJSON() {
  18917. var data = _Geometry.prototype.toJSON.call(this);
  18918. var shapes = this.parameters.shapes;
  18919. var options = this.parameters.options;
  18920. return _toJSON$1(shapes, options, data);
  18921. };
  18922. return ExtrudeGeometry;
  18923. }(Geometry);
  18924. function _toJSON$1(shapes, options, data) {
  18925. data.shapes = [];
  18926. if (Array.isArray(shapes)) {
  18927. for (var i = 0, l = shapes.length; i < l; i++) {
  18928. var shape = shapes[i];
  18929. data.shapes.push(shape.uuid);
  18930. }
  18931. } else {
  18932. data.shapes.push(shapes.uuid);
  18933. }
  18934. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18935. return data;
  18936. }
  18937. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18938. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18939. function IcosahedronBufferGeometry(radius, detail) {
  18940. var _this;
  18941. if (radius === void 0) {
  18942. radius = 1;
  18943. }
  18944. if (detail === void 0) {
  18945. detail = 0;
  18946. }
  18947. var t = (1 + Math.sqrt(5)) / 2;
  18948. 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];
  18949. 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];
  18950. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18951. _this.type = 'IcosahedronBufferGeometry';
  18952. _this.parameters = {
  18953. radius: radius,
  18954. detail: detail
  18955. };
  18956. return _this;
  18957. }
  18958. return IcosahedronBufferGeometry;
  18959. }(PolyhedronBufferGeometry);
  18960. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18961. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18962. function IcosahedronGeometry(radius, detail) {
  18963. var _this;
  18964. _this = _Geometry.call(this) || this;
  18965. _this.type = 'IcosahedronGeometry';
  18966. _this.parameters = {
  18967. radius: radius,
  18968. detail: detail
  18969. };
  18970. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18971. _this.mergeVertices();
  18972. return _this;
  18973. }
  18974. return IcosahedronGeometry;
  18975. }(Geometry);
  18976. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18977. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18978. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18979. var _this;
  18980. if (segments === void 0) {
  18981. segments = 12;
  18982. }
  18983. if (phiStart === void 0) {
  18984. phiStart = 0;
  18985. }
  18986. if (phiLength === void 0) {
  18987. phiLength = Math.PI * 2;
  18988. }
  18989. _this = _BufferGeometry.call(this) || this;
  18990. _this.type = 'LatheBufferGeometry';
  18991. _this.parameters = {
  18992. points: points,
  18993. segments: segments,
  18994. phiStart: phiStart,
  18995. phiLength: phiLength
  18996. };
  18997. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18998. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18999. var indices = [];
  19000. var vertices = [];
  19001. var uvs = []; // helper variables
  19002. var inverseSegments = 1.0 / segments;
  19003. var vertex = new Vector3();
  19004. var uv = new Vector2(); // generate vertices and uvs
  19005. for (var i = 0; i <= segments; i++) {
  19006. var phi = phiStart + i * inverseSegments * phiLength;
  19007. var sin = Math.sin(phi);
  19008. var cos = Math.cos(phi);
  19009. for (var j = 0; j <= points.length - 1; j++) {
  19010. // vertex
  19011. vertex.x = points[j].x * sin;
  19012. vertex.y = points[j].y;
  19013. vertex.z = points[j].x * cos;
  19014. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  19015. uv.x = i / segments;
  19016. uv.y = j / (points.length - 1);
  19017. uvs.push(uv.x, uv.y);
  19018. }
  19019. } // indices
  19020. for (var _i = 0; _i < segments; _i++) {
  19021. for (var _j = 0; _j < points.length - 1; _j++) {
  19022. var base = _j + _i * points.length;
  19023. var a = base;
  19024. var b = base + points.length;
  19025. var c = base + points.length + 1;
  19026. var d = base + 1; // faces
  19027. indices.push(a, b, d);
  19028. indices.push(b, c, d);
  19029. }
  19030. } // build geometry
  19031. _this.setIndex(indices);
  19032. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19033. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  19034. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  19035. // because the corresponding vertices are identical (but still have different UVs).
  19036. if (phiLength === Math.PI * 2) {
  19037. var normals = _this.attributes.normal.array;
  19038. var n1 = new Vector3();
  19039. var n2 = new Vector3();
  19040. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  19041. var _base = segments * points.length * 3;
  19042. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  19043. // select the normal of the vertex in the first line
  19044. n1.x = normals[_j2 + 0];
  19045. n1.y = normals[_j2 + 1];
  19046. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  19047. n2.x = normals[_base + _j2 + 0];
  19048. n2.y = normals[_base + _j2 + 1];
  19049. n2.z = normals[_base + _j2 + 2]; // average normals
  19050. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  19051. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  19052. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  19053. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  19054. }
  19055. }
  19056. return _this;
  19057. }
  19058. return LatheBufferGeometry;
  19059. }(BufferGeometry);
  19060. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  19061. _inheritsLoose(LatheGeometry, _Geometry);
  19062. function LatheGeometry(points, segments, phiStart, phiLength) {
  19063. var _this;
  19064. _this = _Geometry.call(this) || this;
  19065. _this.type = 'LatheGeometry';
  19066. _this.parameters = {
  19067. points: points,
  19068. segments: segments,
  19069. phiStart: phiStart,
  19070. phiLength: phiLength
  19071. };
  19072. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  19073. _this.mergeVertices();
  19074. return _this;
  19075. }
  19076. return LatheGeometry;
  19077. }(Geometry);
  19078. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19079. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  19080. function OctahedronBufferGeometry(radius, detail) {
  19081. var _this;
  19082. if (radius === void 0) {
  19083. radius = 1;
  19084. }
  19085. if (detail === void 0) {
  19086. detail = 0;
  19087. }
  19088. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  19089. 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];
  19090. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19091. _this.type = 'OctahedronBufferGeometry';
  19092. _this.parameters = {
  19093. radius: radius,
  19094. detail: detail
  19095. };
  19096. return _this;
  19097. }
  19098. return OctahedronBufferGeometry;
  19099. }(PolyhedronBufferGeometry);
  19100. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19101. _inheritsLoose(OctahedronGeometry, _Geometry);
  19102. function OctahedronGeometry(radius, detail) {
  19103. var _this;
  19104. _this = _Geometry.call(this) || this;
  19105. _this.type = 'OctahedronGeometry';
  19106. _this.parameters = {
  19107. radius: radius,
  19108. detail: detail
  19109. };
  19110. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  19111. _this.mergeVertices();
  19112. return _this;
  19113. }
  19114. return OctahedronGeometry;
  19115. }(Geometry);
  19116. /**
  19117. * Parametric Surfaces Geometry
  19118. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19119. */
  19120. function ParametricBufferGeometry(func, slices, stacks) {
  19121. BufferGeometry.call(this);
  19122. this.type = 'ParametricBufferGeometry';
  19123. this.parameters = {
  19124. func: func,
  19125. slices: slices,
  19126. stacks: stacks
  19127. }; // buffers
  19128. var indices = [];
  19129. var vertices = [];
  19130. var normals = [];
  19131. var uvs = [];
  19132. var EPS = 0.00001;
  19133. var normal = new Vector3();
  19134. var p0 = new Vector3(),
  19135. p1 = new Vector3();
  19136. var pu = new Vector3(),
  19137. pv = new Vector3();
  19138. if (func.length < 3) {
  19139. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  19140. } // generate vertices, normals and uvs
  19141. var sliceCount = slices + 1;
  19142. for (var i = 0; i <= stacks; i++) {
  19143. var v = i / stacks;
  19144. for (var j = 0; j <= slices; j++) {
  19145. var u = j / slices; // vertex
  19146. func(u, v, p0);
  19147. vertices.push(p0.x, p0.y, p0.z); // normal
  19148. // approximate tangent vectors via finite differences
  19149. if (u - EPS >= 0) {
  19150. func(u - EPS, v, p1);
  19151. pu.subVectors(p0, p1);
  19152. } else {
  19153. func(u + EPS, v, p1);
  19154. pu.subVectors(p1, p0);
  19155. }
  19156. if (v - EPS >= 0) {
  19157. func(u, v - EPS, p1);
  19158. pv.subVectors(p0, p1);
  19159. } else {
  19160. func(u, v + EPS, p1);
  19161. pv.subVectors(p1, p0);
  19162. } // cross product of tangent vectors returns surface normal
  19163. normal.crossVectors(pu, pv).normalize();
  19164. normals.push(normal.x, normal.y, normal.z); // uv
  19165. uvs.push(u, v);
  19166. }
  19167. } // generate indices
  19168. for (var _i = 0; _i < stacks; _i++) {
  19169. for (var _j = 0; _j < slices; _j++) {
  19170. var a = _i * sliceCount + _j;
  19171. var b = _i * sliceCount + _j + 1;
  19172. var c = (_i + 1) * sliceCount + _j + 1;
  19173. var d = (_i + 1) * sliceCount + _j; // faces one and two
  19174. indices.push(a, b, d);
  19175. indices.push(b, c, d);
  19176. }
  19177. } // build geometry
  19178. this.setIndex(indices);
  19179. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19180. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19181. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19182. }
  19183. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  19184. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  19185. /**
  19186. * Parametric Surfaces Geometry
  19187. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  19188. */
  19189. function ParametricGeometry(func, slices, stacks) {
  19190. Geometry.call(this);
  19191. this.type = 'ParametricGeometry';
  19192. this.parameters = {
  19193. func: func,
  19194. slices: slices,
  19195. stacks: stacks
  19196. };
  19197. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  19198. this.mergeVertices();
  19199. }
  19200. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  19201. ParametricGeometry.prototype.constructor = ParametricGeometry;
  19202. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  19203. _inheritsLoose(PlaneGeometry, _Geometry);
  19204. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  19205. var _this;
  19206. _this = _Geometry.call(this) || this;
  19207. _this.type = 'PlaneGeometry';
  19208. _this.parameters = {
  19209. width: width,
  19210. height: height,
  19211. widthSegments: widthSegments,
  19212. heightSegments: heightSegments
  19213. };
  19214. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  19215. _this.mergeVertices();
  19216. return _this;
  19217. }
  19218. return PlaneGeometry;
  19219. }(Geometry);
  19220. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  19221. _inheritsLoose(PolyhedronGeometry, _Geometry);
  19222. function PolyhedronGeometry(vertices, indices, radius, detail) {
  19223. var _this;
  19224. _this = _Geometry.call(this) || this;
  19225. _this.type = 'PolyhedronGeometry';
  19226. _this.parameters = {
  19227. vertices: vertices,
  19228. indices: indices,
  19229. radius: radius,
  19230. detail: detail
  19231. };
  19232. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  19233. _this.mergeVertices();
  19234. return _this;
  19235. }
  19236. return PolyhedronGeometry;
  19237. }(Geometry);
  19238. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19239. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  19240. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19241. var _this;
  19242. if (innerRadius === void 0) {
  19243. innerRadius = 0.5;
  19244. }
  19245. if (outerRadius === void 0) {
  19246. outerRadius = 1;
  19247. }
  19248. if (thetaSegments === void 0) {
  19249. thetaSegments = 8;
  19250. }
  19251. if (phiSegments === void 0) {
  19252. phiSegments = 1;
  19253. }
  19254. if (thetaStart === void 0) {
  19255. thetaStart = 0;
  19256. }
  19257. if (thetaLength === void 0) {
  19258. thetaLength = Math.PI * 2;
  19259. }
  19260. _this = _BufferGeometry.call(this) || this;
  19261. _this.type = 'RingBufferGeometry';
  19262. _this.parameters = {
  19263. innerRadius: innerRadius,
  19264. outerRadius: outerRadius,
  19265. thetaSegments: thetaSegments,
  19266. phiSegments: phiSegments,
  19267. thetaStart: thetaStart,
  19268. thetaLength: thetaLength
  19269. };
  19270. thetaSegments = Math.max(3, thetaSegments);
  19271. phiSegments = Math.max(1, phiSegments); // buffers
  19272. var indices = [];
  19273. var vertices = [];
  19274. var normals = [];
  19275. var uvs = []; // some helper variables
  19276. var radius = innerRadius;
  19277. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19278. var vertex = new Vector3();
  19279. var uv = new Vector2(); // generate vertices, normals and uvs
  19280. for (var j = 0; j <= phiSegments; j++) {
  19281. for (var i = 0; i <= thetaSegments; i++) {
  19282. // values are generate from the inside of the ring to the outside
  19283. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19284. vertex.x = radius * Math.cos(segment);
  19285. vertex.y = radius * Math.sin(segment);
  19286. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19287. normals.push(0, 0, 1); // uv
  19288. uv.x = (vertex.x / outerRadius + 1) / 2;
  19289. uv.y = (vertex.y / outerRadius + 1) / 2;
  19290. uvs.push(uv.x, uv.y);
  19291. } // increase the radius for next row of vertices
  19292. radius += radiusStep;
  19293. } // indices
  19294. for (var _j = 0; _j < phiSegments; _j++) {
  19295. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19296. for (var _i = 0; _i < thetaSegments; _i++) {
  19297. var _segment = _i + thetaSegmentLevel;
  19298. var a = _segment;
  19299. var b = _segment + thetaSegments + 1;
  19300. var c = _segment + thetaSegments + 2;
  19301. var d = _segment + 1; // faces
  19302. indices.push(a, b, d);
  19303. indices.push(b, c, d);
  19304. }
  19305. } // build geometry
  19306. _this.setIndex(indices);
  19307. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19308. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19309. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19310. return _this;
  19311. }
  19312. return RingBufferGeometry;
  19313. }(BufferGeometry);
  19314. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  19315. _inheritsLoose(RingGeometry, _Geometry);
  19316. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  19317. var _this;
  19318. _this = _Geometry.call(this) || this;
  19319. _this.type = 'RingGeometry';
  19320. _this.parameters = {
  19321. innerRadius: innerRadius,
  19322. outerRadius: outerRadius,
  19323. thetaSegments: thetaSegments,
  19324. phiSegments: phiSegments,
  19325. thetaStart: thetaStart,
  19326. thetaLength: thetaLength
  19327. };
  19328. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  19329. _this.mergeVertices();
  19330. return _this;
  19331. }
  19332. return RingGeometry;
  19333. }(Geometry);
  19334. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19335. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  19336. function ShapeBufferGeometry(shapes, curveSegments) {
  19337. var _this;
  19338. if (curveSegments === void 0) {
  19339. curveSegments = 12;
  19340. }
  19341. _this = _BufferGeometry.call(this) || this;
  19342. _this.type = 'ShapeBufferGeometry';
  19343. _this.parameters = {
  19344. shapes: shapes,
  19345. curveSegments: curveSegments
  19346. }; // buffers
  19347. var indices = [];
  19348. var vertices = [];
  19349. var normals = [];
  19350. var uvs = []; // helper variables
  19351. var groupStart = 0;
  19352. var groupCount = 0; // allow single and array values for "shapes" parameter
  19353. if (Array.isArray(shapes) === false) {
  19354. addShape(shapes);
  19355. } else {
  19356. for (var i = 0; i < shapes.length; i++) {
  19357. addShape(shapes[i]);
  19358. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19359. groupStart += groupCount;
  19360. groupCount = 0;
  19361. }
  19362. } // build geometry
  19363. _this.setIndex(indices);
  19364. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19365. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19366. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19367. function addShape(shape) {
  19368. var indexOffset = vertices.length / 3;
  19369. var points = shape.extractPoints(curveSegments);
  19370. var shapeVertices = points.shape;
  19371. var shapeHoles = points.holes; // check direction of vertices
  19372. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19373. shapeVertices = shapeVertices.reverse();
  19374. }
  19375. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19376. var shapeHole = shapeHoles[_i];
  19377. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19378. shapeHoles[_i] = shapeHole.reverse();
  19379. }
  19380. }
  19381. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19382. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19383. var _shapeHole = shapeHoles[_i2];
  19384. shapeVertices = shapeVertices.concat(_shapeHole);
  19385. } // vertices, normals, uvs
  19386. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19387. var vertex = shapeVertices[_i3];
  19388. vertices.push(vertex.x, vertex.y, 0);
  19389. normals.push(0, 0, 1);
  19390. uvs.push(vertex.x, vertex.y); // world uvs
  19391. } // incides
  19392. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19393. var face = faces[_i4];
  19394. var a = face[0] + indexOffset;
  19395. var b = face[1] + indexOffset;
  19396. var c = face[2] + indexOffset;
  19397. indices.push(a, b, c);
  19398. groupCount += 3;
  19399. }
  19400. }
  19401. return _this;
  19402. }
  19403. var _proto = ShapeBufferGeometry.prototype;
  19404. _proto.toJSON = function toJSON() {
  19405. var data = BufferGeometry.prototype.toJSON.call(this);
  19406. var shapes = this.parameters.shapes;
  19407. return _toJSON$2(shapes, data);
  19408. };
  19409. return ShapeBufferGeometry;
  19410. }(BufferGeometry);
  19411. function _toJSON$2(shapes, data) {
  19412. data.shapes = [];
  19413. if (Array.isArray(shapes)) {
  19414. for (var i = 0, l = shapes.length; i < l; i++) {
  19415. var shape = shapes[i];
  19416. data.shapes.push(shape.uuid);
  19417. }
  19418. } else {
  19419. data.shapes.push(shapes.uuid);
  19420. }
  19421. return data;
  19422. }
  19423. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19424. _inheritsLoose(ShapeGeometry, _Geometry);
  19425. function ShapeGeometry(shapes, curveSegments) {
  19426. var _this;
  19427. _this = _Geometry.call(this) || this;
  19428. _this.type = 'ShapeGeometry';
  19429. if (typeof curveSegments === 'object') {
  19430. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19431. curveSegments = curveSegments.curveSegments;
  19432. }
  19433. _this.parameters = {
  19434. shapes: shapes,
  19435. curveSegments: curveSegments
  19436. };
  19437. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19438. _this.mergeVertices();
  19439. return _this;
  19440. }
  19441. var _proto = ShapeGeometry.prototype;
  19442. _proto.toJSON = function toJSON() {
  19443. var data = Geometry.prototype.toJSON.call(this);
  19444. var shapes = this.parameters.shapes;
  19445. return _toJSON$3(shapes, data);
  19446. };
  19447. return ShapeGeometry;
  19448. }(Geometry);
  19449. function _toJSON$3(shapes, data) {
  19450. data.shapes = [];
  19451. if (Array.isArray(shapes)) {
  19452. for (var i = 0, l = shapes.length; i < l; i++) {
  19453. var shape = shapes[i];
  19454. data.shapes.push(shape.uuid);
  19455. }
  19456. } else {
  19457. data.shapes.push(shapes.uuid);
  19458. }
  19459. return data;
  19460. }
  19461. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19462. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19463. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19464. var _this;
  19465. if (radius === void 0) {
  19466. radius = 1;
  19467. }
  19468. if (widthSegments === void 0) {
  19469. widthSegments = 8;
  19470. }
  19471. if (heightSegments === void 0) {
  19472. heightSegments = 6;
  19473. }
  19474. if (phiStart === void 0) {
  19475. phiStart = 0;
  19476. }
  19477. if (phiLength === void 0) {
  19478. phiLength = Math.PI * 2;
  19479. }
  19480. if (thetaStart === void 0) {
  19481. thetaStart = 0;
  19482. }
  19483. if (thetaLength === void 0) {
  19484. thetaLength = Math.PI;
  19485. }
  19486. _this = _BufferGeometry.call(this) || this;
  19487. _this.type = 'SphereBufferGeometry';
  19488. _this.parameters = {
  19489. radius: radius,
  19490. widthSegments: widthSegments,
  19491. heightSegments: heightSegments,
  19492. phiStart: phiStart,
  19493. phiLength: phiLength,
  19494. thetaStart: thetaStart,
  19495. thetaLength: thetaLength
  19496. };
  19497. widthSegments = Math.max(3, Math.floor(widthSegments));
  19498. heightSegments = Math.max(2, Math.floor(heightSegments));
  19499. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19500. var index = 0;
  19501. var grid = [];
  19502. var vertex = new Vector3();
  19503. var normal = new Vector3(); // buffers
  19504. var indices = [];
  19505. var vertices = [];
  19506. var normals = [];
  19507. var uvs = []; // generate vertices, normals and uvs
  19508. for (var iy = 0; iy <= heightSegments; iy++) {
  19509. var verticesRow = [];
  19510. var v = iy / heightSegments; // special case for the poles
  19511. var uOffset = 0;
  19512. if (iy == 0 && thetaStart == 0) {
  19513. uOffset = 0.5 / widthSegments;
  19514. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19515. uOffset = -0.5 / widthSegments;
  19516. }
  19517. for (var ix = 0; ix <= widthSegments; ix++) {
  19518. var u = ix / widthSegments; // vertex
  19519. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19520. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19521. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19522. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19523. normal.copy(vertex).normalize();
  19524. normals.push(normal.x, normal.y, normal.z); // uv
  19525. uvs.push(u + uOffset, 1 - v);
  19526. verticesRow.push(index++);
  19527. }
  19528. grid.push(verticesRow);
  19529. } // indices
  19530. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19531. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19532. var a = grid[_iy][_ix + 1];
  19533. var b = grid[_iy][_ix];
  19534. var c = grid[_iy + 1][_ix];
  19535. var d = grid[_iy + 1][_ix + 1];
  19536. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19537. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19538. }
  19539. } // build geometry
  19540. _this.setIndex(indices);
  19541. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19542. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19543. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19544. return _this;
  19545. }
  19546. return SphereBufferGeometry;
  19547. }(BufferGeometry);
  19548. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19549. _inheritsLoose(SphereGeometry, _Geometry);
  19550. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19551. var _this;
  19552. _this = _Geometry.call(this) || this;
  19553. _this.type = 'SphereGeometry';
  19554. _this.parameters = {
  19555. radius: radius,
  19556. widthSegments: widthSegments,
  19557. heightSegments: heightSegments,
  19558. phiStart: phiStart,
  19559. phiLength: phiLength,
  19560. thetaStart: thetaStart,
  19561. thetaLength: thetaLength
  19562. };
  19563. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19564. _this.mergeVertices();
  19565. return _this;
  19566. }
  19567. return SphereGeometry;
  19568. }(Geometry);
  19569. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19570. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19571. function TetrahedronBufferGeometry(radius, detail) {
  19572. var _this;
  19573. if (radius === void 0) {
  19574. radius = 1;
  19575. }
  19576. if (detail === void 0) {
  19577. detail = 0;
  19578. }
  19579. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19580. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19581. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19582. _this.type = 'TetrahedronBufferGeometry';
  19583. _this.parameters = {
  19584. radius: radius,
  19585. detail: detail
  19586. };
  19587. return _this;
  19588. }
  19589. return TetrahedronBufferGeometry;
  19590. }(PolyhedronBufferGeometry);
  19591. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19592. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19593. function TetrahedronGeometry(radius, detail) {
  19594. var _this;
  19595. _this = _Geometry.call(this) || this;
  19596. _this.type = 'TetrahedronGeometry';
  19597. _this.parameters = {
  19598. radius: radius,
  19599. detail: detail
  19600. };
  19601. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19602. _this.mergeVertices();
  19603. return _this;
  19604. }
  19605. return TetrahedronGeometry;
  19606. }(Geometry);
  19607. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19608. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19609. function TextBufferGeometry(text, parameters) {
  19610. var _this;
  19611. if (parameters === void 0) {
  19612. parameters = {};
  19613. }
  19614. var font = parameters.font;
  19615. if (!(font && font.isFont)) {
  19616. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19617. return new BufferGeometry() || _assertThisInitialized(_this);
  19618. }
  19619. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19620. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19621. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19622. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19623. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19624. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19625. _this.type = 'TextBufferGeometry';
  19626. return _this;
  19627. }
  19628. return TextBufferGeometry;
  19629. }(ExtrudeBufferGeometry);
  19630. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19631. _inheritsLoose(TextGeometry, _Geometry);
  19632. function TextGeometry(text, parameters) {
  19633. var _this;
  19634. _this = _Geometry.call(this) || this;
  19635. _this.type = 'TextGeometry';
  19636. _this.parameters = {
  19637. text: text,
  19638. parameters: parameters
  19639. };
  19640. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19641. _this.mergeVertices();
  19642. return _this;
  19643. }
  19644. return TextGeometry;
  19645. }(Geometry);
  19646. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19647. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19648. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19649. var _this;
  19650. if (radius === void 0) {
  19651. radius = 1;
  19652. }
  19653. if (tube === void 0) {
  19654. tube = 0.4;
  19655. }
  19656. if (radialSegments === void 0) {
  19657. radialSegments = 8;
  19658. }
  19659. if (tubularSegments === void 0) {
  19660. tubularSegments = 6;
  19661. }
  19662. if (arc === void 0) {
  19663. arc = Math.PI * 2;
  19664. }
  19665. _this = _BufferGeometry.call(this) || this;
  19666. _this.type = 'TorusBufferGeometry';
  19667. _this.parameters = {
  19668. radius: radius,
  19669. tube: tube,
  19670. radialSegments: radialSegments,
  19671. tubularSegments: tubularSegments,
  19672. arc: arc
  19673. };
  19674. radialSegments = Math.floor(radialSegments);
  19675. tubularSegments = Math.floor(tubularSegments); // buffers
  19676. var indices = [];
  19677. var vertices = [];
  19678. var normals = [];
  19679. var uvs = []; // helper variables
  19680. var center = new Vector3();
  19681. var vertex = new Vector3();
  19682. var normal = new Vector3(); // generate vertices, normals and uvs
  19683. for (var j = 0; j <= radialSegments; j++) {
  19684. for (var i = 0; i <= tubularSegments; i++) {
  19685. var u = i / tubularSegments * arc;
  19686. var v = j / radialSegments * Math.PI * 2; // vertex
  19687. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19688. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19689. vertex.z = tube * Math.sin(v);
  19690. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19691. center.x = radius * Math.cos(u);
  19692. center.y = radius * Math.sin(u);
  19693. normal.subVectors(vertex, center).normalize();
  19694. normals.push(normal.x, normal.y, normal.z); // uv
  19695. uvs.push(i / tubularSegments);
  19696. uvs.push(j / radialSegments);
  19697. }
  19698. } // generate indices
  19699. for (var _j = 1; _j <= radialSegments; _j++) {
  19700. for (var _i = 1; _i <= tubularSegments; _i++) {
  19701. // indices
  19702. var a = (tubularSegments + 1) * _j + _i - 1;
  19703. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19704. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19705. var d = (tubularSegments + 1) * _j + _i; // faces
  19706. indices.push(a, b, d);
  19707. indices.push(b, c, d);
  19708. }
  19709. } // build geometry
  19710. _this.setIndex(indices);
  19711. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19712. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19713. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19714. return _this;
  19715. }
  19716. return TorusBufferGeometry;
  19717. }(BufferGeometry);
  19718. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19719. _inheritsLoose(TorusGeometry, _Geometry);
  19720. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19721. var _this;
  19722. _this = _Geometry.call(this) || this;
  19723. _this.type = 'TorusGeometry';
  19724. _this.parameters = {
  19725. radius: radius,
  19726. tube: tube,
  19727. radialSegments: radialSegments,
  19728. tubularSegments: tubularSegments,
  19729. arc: arc
  19730. };
  19731. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19732. _this.mergeVertices();
  19733. return _this;
  19734. }
  19735. return TorusGeometry;
  19736. }(Geometry);
  19737. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19738. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19739. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19740. var _this;
  19741. if (radius === void 0) {
  19742. radius = 1;
  19743. }
  19744. if (tube === void 0) {
  19745. tube = 0.4;
  19746. }
  19747. if (tubularSegments === void 0) {
  19748. tubularSegments = 64;
  19749. }
  19750. if (radialSegments === void 0) {
  19751. radialSegments = 8;
  19752. }
  19753. if (p === void 0) {
  19754. p = 2;
  19755. }
  19756. if (q === void 0) {
  19757. q = 3;
  19758. }
  19759. _this = _BufferGeometry.call(this) || this;
  19760. _this.type = 'TorusKnotBufferGeometry';
  19761. _this.parameters = {
  19762. radius: radius,
  19763. tube: tube,
  19764. tubularSegments: tubularSegments,
  19765. radialSegments: radialSegments,
  19766. p: p,
  19767. q: q
  19768. };
  19769. tubularSegments = Math.floor(tubularSegments);
  19770. radialSegments = Math.floor(radialSegments); // buffers
  19771. var indices = [];
  19772. var vertices = [];
  19773. var normals = [];
  19774. var uvs = []; // helper variables
  19775. var vertex = new Vector3();
  19776. var normal = new Vector3();
  19777. var P1 = new Vector3();
  19778. var P2 = new Vector3();
  19779. var B = new Vector3();
  19780. var T = new Vector3();
  19781. var N = new Vector3(); // generate vertices, normals and uvs
  19782. for (var i = 0; i <= tubularSegments; ++i) {
  19783. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19784. 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.
  19785. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19786. calculatePositionOnCurve(u, p, q, radius, P1);
  19787. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19788. T.subVectors(P2, P1);
  19789. N.addVectors(P2, P1);
  19790. B.crossVectors(T, N);
  19791. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19792. B.normalize();
  19793. N.normalize();
  19794. for (var j = 0; j <= radialSegments; ++j) {
  19795. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19796. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19797. var v = j / radialSegments * Math.PI * 2;
  19798. var cx = -tube * Math.cos(v);
  19799. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19800. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19801. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19802. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19803. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19804. 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)
  19805. normal.subVectors(vertex, P1).normalize();
  19806. normals.push(normal.x, normal.y, normal.z); // uv
  19807. uvs.push(i / tubularSegments);
  19808. uvs.push(j / radialSegments);
  19809. }
  19810. } // generate indices
  19811. for (var _j = 1; _j <= tubularSegments; _j++) {
  19812. for (var _i = 1; _i <= radialSegments; _i++) {
  19813. // indices
  19814. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19815. var b = (radialSegments + 1) * _j + (_i - 1);
  19816. var c = (radialSegments + 1) * _j + _i;
  19817. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19818. indices.push(a, b, d);
  19819. indices.push(b, c, d);
  19820. }
  19821. } // build geometry
  19822. _this.setIndex(indices);
  19823. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19824. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19825. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19826. function calculatePositionOnCurve(u, p, q, radius, position) {
  19827. var cu = Math.cos(u);
  19828. var su = Math.sin(u);
  19829. var quOverP = q / p * u;
  19830. var cs = Math.cos(quOverP);
  19831. position.x = radius * (2 + cs) * 0.5 * cu;
  19832. position.y = radius * (2 + cs) * su * 0.5;
  19833. position.z = radius * Math.sin(quOverP) * 0.5;
  19834. }
  19835. return _this;
  19836. }
  19837. return TorusKnotBufferGeometry;
  19838. }(BufferGeometry);
  19839. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19840. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19841. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19842. var _this;
  19843. _this = _Geometry.call(this) || this;
  19844. _this.type = 'TorusKnotGeometry';
  19845. _this.parameters = {
  19846. radius: radius,
  19847. tube: tube,
  19848. tubularSegments: tubularSegments,
  19849. radialSegments: radialSegments,
  19850. p: p,
  19851. q: q
  19852. };
  19853. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19854. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19855. _this.mergeVertices();
  19856. return _this;
  19857. }
  19858. return TorusKnotGeometry;
  19859. }(Geometry);
  19860. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19861. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19862. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19863. var _this;
  19864. if (tubularSegments === void 0) {
  19865. tubularSegments = 64;
  19866. }
  19867. if (radius === void 0) {
  19868. radius = 1;
  19869. }
  19870. if (radialSegments === void 0) {
  19871. radialSegments = 8;
  19872. }
  19873. if (closed === void 0) {
  19874. closed = false;
  19875. }
  19876. _this = _BufferGeometry.call(this) || this;
  19877. _this.type = 'TubeBufferGeometry';
  19878. _this.parameters = {
  19879. path: path,
  19880. tubularSegments: tubularSegments,
  19881. radius: radius,
  19882. radialSegments: radialSegments,
  19883. closed: closed
  19884. };
  19885. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19886. _this.tangents = frames.tangents;
  19887. _this.normals = frames.normals;
  19888. _this.binormals = frames.binormals; // helper variables
  19889. var vertex = new Vector3();
  19890. var normal = new Vector3();
  19891. var uv = new Vector2();
  19892. var P = new Vector3(); // buffer
  19893. var vertices = [];
  19894. var normals = [];
  19895. var uvs = [];
  19896. var indices = []; // create buffer data
  19897. generateBufferData(); // build geometry
  19898. _this.setIndex(indices);
  19899. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19900. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19901. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19902. function generateBufferData() {
  19903. for (var i = 0; i < tubularSegments; i++) {
  19904. generateSegment(i);
  19905. } // if the geometry is not closed, generate the last row of vertices and normals
  19906. // at the regular position on the given path
  19907. //
  19908. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19909. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19910. // this makes it easy compute correct values for closed geometries
  19911. generateUVs(); // finally create faces
  19912. generateIndices();
  19913. }
  19914. function generateSegment(i) {
  19915. // we use getPointAt to sample evenly distributed points from the given path
  19916. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19917. var N = frames.normals[i];
  19918. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19919. for (var j = 0; j <= radialSegments; j++) {
  19920. var v = j / radialSegments * Math.PI * 2;
  19921. var sin = Math.sin(v);
  19922. var cos = -Math.cos(v); // normal
  19923. normal.x = cos * N.x + sin * B.x;
  19924. normal.y = cos * N.y + sin * B.y;
  19925. normal.z = cos * N.z + sin * B.z;
  19926. normal.normalize();
  19927. normals.push(normal.x, normal.y, normal.z); // vertex
  19928. vertex.x = P.x + radius * normal.x;
  19929. vertex.y = P.y + radius * normal.y;
  19930. vertex.z = P.z + radius * normal.z;
  19931. vertices.push(vertex.x, vertex.y, vertex.z);
  19932. }
  19933. }
  19934. function generateIndices() {
  19935. for (var j = 1; j <= tubularSegments; j++) {
  19936. for (var i = 1; i <= radialSegments; i++) {
  19937. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19938. var b = (radialSegments + 1) * j + (i - 1);
  19939. var c = (radialSegments + 1) * j + i;
  19940. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19941. indices.push(a, b, d);
  19942. indices.push(b, c, d);
  19943. }
  19944. }
  19945. }
  19946. function generateUVs() {
  19947. for (var i = 0; i <= tubularSegments; i++) {
  19948. for (var j = 0; j <= radialSegments; j++) {
  19949. uv.x = i / tubularSegments;
  19950. uv.y = j / radialSegments;
  19951. uvs.push(uv.x, uv.y);
  19952. }
  19953. }
  19954. }
  19955. return _this;
  19956. }
  19957. var _proto = TubeBufferGeometry.prototype;
  19958. _proto.toJSON = function toJSON() {
  19959. var data = BufferGeometry.prototype.toJSON.call(this);
  19960. data.path = this.parameters.path.toJSON();
  19961. return data;
  19962. };
  19963. return TubeBufferGeometry;
  19964. }(BufferGeometry);
  19965. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19966. _inheritsLoose(TubeGeometry, _Geometry);
  19967. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19968. var _this;
  19969. _this = _Geometry.call(this) || this;
  19970. _this.type = 'TubeGeometry';
  19971. _this.parameters = {
  19972. path: path,
  19973. tubularSegments: tubularSegments,
  19974. radius: radius,
  19975. radialSegments: radialSegments,
  19976. closed: closed
  19977. };
  19978. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19979. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19980. _this.tangents = bufferGeometry.tangents;
  19981. _this.normals = bufferGeometry.normals;
  19982. _this.binormals = bufferGeometry.binormals; // create geometry
  19983. _this.fromBufferGeometry(bufferGeometry);
  19984. _this.mergeVertices();
  19985. return _this;
  19986. }
  19987. return TubeGeometry;
  19988. }(Geometry);
  19989. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19990. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19991. function WireframeGeometry(geometry) {
  19992. var _this;
  19993. _this = _BufferGeometry.call(this) || this;
  19994. _this.type = 'WireframeGeometry'; // buffer
  19995. var vertices = []; // helper variables
  19996. var edge = [0, 0],
  19997. edges = {};
  19998. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19999. if (geometry && geometry.isGeometry) {
  20000. // create a data structure that contains all edges without duplicates
  20001. var faces = geometry.faces;
  20002. for (var i = 0, l = faces.length; i < l; i++) {
  20003. var face = faces[i];
  20004. for (var j = 0; j < 3; j++) {
  20005. var edge1 = face[keys[j]];
  20006. var edge2 = face[keys[(j + 1) % 3]];
  20007. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  20008. edge[1] = Math.max(edge1, edge2);
  20009. var key = edge[0] + ',' + edge[1];
  20010. if (edges[key] === undefined) {
  20011. edges[key] = {
  20012. index1: edge[0],
  20013. index2: edge[1]
  20014. };
  20015. }
  20016. }
  20017. } // generate vertices
  20018. for (var _key in edges) {
  20019. var e = edges[_key];
  20020. var vertex = geometry.vertices[e.index1];
  20021. vertices.push(vertex.x, vertex.y, vertex.z);
  20022. vertex = geometry.vertices[e.index2];
  20023. vertices.push(vertex.x, vertex.y, vertex.z);
  20024. }
  20025. } else if (geometry && geometry.isBufferGeometry) {
  20026. var _vertex = new Vector3();
  20027. if (geometry.index !== null) {
  20028. // indexed BufferGeometry
  20029. var position = geometry.attributes.position;
  20030. var indices = geometry.index;
  20031. var groups = geometry.groups;
  20032. if (groups.length === 0) {
  20033. groups = [{
  20034. start: 0,
  20035. count: indices.count,
  20036. materialIndex: 0
  20037. }];
  20038. } // create a data structure that contains all eges without duplicates
  20039. for (var o = 0, ol = groups.length; o < ol; ++o) {
  20040. var group = groups[o];
  20041. var start = group.start;
  20042. var count = group.count;
  20043. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  20044. for (var _j = 0; _j < 3; _j++) {
  20045. var _edge = indices.getX(_i + _j);
  20046. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  20047. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  20048. edge[1] = Math.max(_edge, _edge2);
  20049. var _key2 = edge[0] + ',' + edge[1];
  20050. if (edges[_key2] === undefined) {
  20051. edges[_key2] = {
  20052. index1: edge[0],
  20053. index2: edge[1]
  20054. };
  20055. }
  20056. }
  20057. }
  20058. } // generate vertices
  20059. for (var _key3 in edges) {
  20060. var _e = edges[_key3];
  20061. _vertex.fromBufferAttribute(position, _e.index1);
  20062. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20063. _vertex.fromBufferAttribute(position, _e.index2);
  20064. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20065. }
  20066. } else {
  20067. // non-indexed BufferGeometry
  20068. var _position = geometry.attributes.position;
  20069. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  20070. for (var _j2 = 0; _j2 < 3; _j2++) {
  20071. // three edges per triangle, an edge is represented as (index1, index2)
  20072. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  20073. var index1 = 3 * _i2 + _j2;
  20074. _vertex.fromBufferAttribute(_position, index1);
  20075. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20076. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  20077. _vertex.fromBufferAttribute(_position, index2);
  20078. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  20079. }
  20080. }
  20081. }
  20082. } // build geometry
  20083. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  20084. return _this;
  20085. }
  20086. return WireframeGeometry;
  20087. }(BufferGeometry);
  20088. var Geometries = /*#__PURE__*/Object.freeze({
  20089. __proto__: null,
  20090. BoxGeometry: BoxGeometry,
  20091. BoxBufferGeometry: BoxBufferGeometry,
  20092. CircleGeometry: CircleGeometry,
  20093. CircleBufferGeometry: CircleBufferGeometry,
  20094. ConeGeometry: ConeGeometry,
  20095. ConeBufferGeometry: ConeBufferGeometry,
  20096. CylinderGeometry: CylinderGeometry,
  20097. CylinderBufferGeometry: CylinderBufferGeometry,
  20098. DodecahedronGeometry: DodecahedronGeometry,
  20099. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  20100. EdgesGeometry: EdgesGeometry,
  20101. ExtrudeGeometry: ExtrudeGeometry,
  20102. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  20103. IcosahedronGeometry: IcosahedronGeometry,
  20104. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  20105. LatheGeometry: LatheGeometry,
  20106. LatheBufferGeometry: LatheBufferGeometry,
  20107. OctahedronGeometry: OctahedronGeometry,
  20108. OctahedronBufferGeometry: OctahedronBufferGeometry,
  20109. ParametricGeometry: ParametricGeometry,
  20110. ParametricBufferGeometry: ParametricBufferGeometry,
  20111. PlaneGeometry: PlaneGeometry,
  20112. PlaneBufferGeometry: PlaneBufferGeometry,
  20113. PolyhedronGeometry: PolyhedronGeometry,
  20114. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  20115. RingGeometry: RingGeometry,
  20116. RingBufferGeometry: RingBufferGeometry,
  20117. ShapeGeometry: ShapeGeometry,
  20118. ShapeBufferGeometry: ShapeBufferGeometry,
  20119. SphereGeometry: SphereGeometry,
  20120. SphereBufferGeometry: SphereBufferGeometry,
  20121. TetrahedronGeometry: TetrahedronGeometry,
  20122. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  20123. TextGeometry: TextGeometry,
  20124. TextBufferGeometry: TextBufferGeometry,
  20125. TorusGeometry: TorusGeometry,
  20126. TorusBufferGeometry: TorusBufferGeometry,
  20127. TorusKnotGeometry: TorusKnotGeometry,
  20128. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  20129. TubeGeometry: TubeGeometry,
  20130. TubeBufferGeometry: TubeBufferGeometry,
  20131. WireframeGeometry: WireframeGeometry
  20132. });
  20133. /**
  20134. * parameters = {
  20135. * color: <THREE.Color>
  20136. * }
  20137. */
  20138. function ShadowMaterial(parameters) {
  20139. Material.call(this);
  20140. this.type = 'ShadowMaterial';
  20141. this.color = new Color(0x000000);
  20142. this.transparent = true;
  20143. this.setValues(parameters);
  20144. }
  20145. ShadowMaterial.prototype = Object.create(Material.prototype);
  20146. ShadowMaterial.prototype.constructor = ShadowMaterial;
  20147. ShadowMaterial.prototype.isShadowMaterial = true;
  20148. ShadowMaterial.prototype.copy = function (source) {
  20149. Material.prototype.copy.call(this, source);
  20150. this.color.copy(source.color);
  20151. return this;
  20152. };
  20153. function RawShaderMaterial(parameters) {
  20154. ShaderMaterial.call(this, parameters);
  20155. this.type = 'RawShaderMaterial';
  20156. }
  20157. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  20158. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  20159. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  20160. /**
  20161. * parameters = {
  20162. * color: <hex>,
  20163. * roughness: <float>,
  20164. * metalness: <float>,
  20165. * opacity: <float>,
  20166. *
  20167. * map: new THREE.Texture( <Image> ),
  20168. *
  20169. * lightMap: new THREE.Texture( <Image> ),
  20170. * lightMapIntensity: <float>
  20171. *
  20172. * aoMap: new THREE.Texture( <Image> ),
  20173. * aoMapIntensity: <float>
  20174. *
  20175. * emissive: <hex>,
  20176. * emissiveIntensity: <float>
  20177. * emissiveMap: new THREE.Texture( <Image> ),
  20178. *
  20179. * bumpMap: new THREE.Texture( <Image> ),
  20180. * bumpScale: <float>,
  20181. *
  20182. * normalMap: new THREE.Texture( <Image> ),
  20183. * normalMapType: THREE.TangentSpaceNormalMap,
  20184. * normalScale: <Vector2>,
  20185. *
  20186. * displacementMap: new THREE.Texture( <Image> ),
  20187. * displacementScale: <float>,
  20188. * displacementBias: <float>,
  20189. *
  20190. * roughnessMap: new THREE.Texture( <Image> ),
  20191. *
  20192. * metalnessMap: new THREE.Texture( <Image> ),
  20193. *
  20194. * alphaMap: new THREE.Texture( <Image> ),
  20195. *
  20196. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20197. * envMapIntensity: <float>
  20198. *
  20199. * refractionRatio: <float>,
  20200. *
  20201. * wireframe: <boolean>,
  20202. * wireframeLinewidth: <float>,
  20203. *
  20204. * skinning: <bool>,
  20205. * morphTargets: <bool>,
  20206. * morphNormals: <bool>
  20207. * }
  20208. */
  20209. function MeshStandardMaterial(parameters) {
  20210. Material.call(this);
  20211. this.defines = {
  20212. 'STANDARD': ''
  20213. };
  20214. this.type = 'MeshStandardMaterial';
  20215. this.color = new Color(0xffffff); // diffuse
  20216. this.roughness = 1.0;
  20217. this.metalness = 0.0;
  20218. this.map = null;
  20219. this.lightMap = null;
  20220. this.lightMapIntensity = 1.0;
  20221. this.aoMap = null;
  20222. this.aoMapIntensity = 1.0;
  20223. this.emissive = new Color(0x000000);
  20224. this.emissiveIntensity = 1.0;
  20225. this.emissiveMap = null;
  20226. this.bumpMap = null;
  20227. this.bumpScale = 1;
  20228. this.normalMap = null;
  20229. this.normalMapType = TangentSpaceNormalMap;
  20230. this.normalScale = new Vector2(1, 1);
  20231. this.displacementMap = null;
  20232. this.displacementScale = 1;
  20233. this.displacementBias = 0;
  20234. this.roughnessMap = null;
  20235. this.metalnessMap = null;
  20236. this.alphaMap = null;
  20237. this.envMap = null;
  20238. this.envMapIntensity = 1.0;
  20239. this.refractionRatio = 0.98;
  20240. this.wireframe = false;
  20241. this.wireframeLinewidth = 1;
  20242. this.wireframeLinecap = 'round';
  20243. this.wireframeLinejoin = 'round';
  20244. this.skinning = false;
  20245. this.morphTargets = false;
  20246. this.morphNormals = false;
  20247. this.vertexTangents = false;
  20248. this.setValues(parameters);
  20249. }
  20250. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  20251. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20252. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20253. MeshStandardMaterial.prototype.copy = function (source) {
  20254. Material.prototype.copy.call(this, source);
  20255. this.defines = {
  20256. 'STANDARD': ''
  20257. };
  20258. this.color.copy(source.color);
  20259. this.roughness = source.roughness;
  20260. this.metalness = source.metalness;
  20261. this.map = source.map;
  20262. this.lightMap = source.lightMap;
  20263. this.lightMapIntensity = source.lightMapIntensity;
  20264. this.aoMap = source.aoMap;
  20265. this.aoMapIntensity = source.aoMapIntensity;
  20266. this.emissive.copy(source.emissive);
  20267. this.emissiveMap = source.emissiveMap;
  20268. this.emissiveIntensity = source.emissiveIntensity;
  20269. this.bumpMap = source.bumpMap;
  20270. this.bumpScale = source.bumpScale;
  20271. this.normalMap = source.normalMap;
  20272. this.normalMapType = source.normalMapType;
  20273. this.normalScale.copy(source.normalScale);
  20274. this.displacementMap = source.displacementMap;
  20275. this.displacementScale = source.displacementScale;
  20276. this.displacementBias = source.displacementBias;
  20277. this.roughnessMap = source.roughnessMap;
  20278. this.metalnessMap = source.metalnessMap;
  20279. this.alphaMap = source.alphaMap;
  20280. this.envMap = source.envMap;
  20281. this.envMapIntensity = source.envMapIntensity;
  20282. this.refractionRatio = source.refractionRatio;
  20283. this.wireframe = source.wireframe;
  20284. this.wireframeLinewidth = source.wireframeLinewidth;
  20285. this.wireframeLinecap = source.wireframeLinecap;
  20286. this.wireframeLinejoin = source.wireframeLinejoin;
  20287. this.skinning = source.skinning;
  20288. this.morphTargets = source.morphTargets;
  20289. this.morphNormals = source.morphNormals;
  20290. this.vertexTangents = source.vertexTangents;
  20291. return this;
  20292. };
  20293. /**
  20294. * parameters = {
  20295. * clearcoat: <float>,
  20296. * clearcoatMap: new THREE.Texture( <Image> ),
  20297. * clearcoatRoughness: <float>,
  20298. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20299. * clearcoatNormalScale: <Vector2>,
  20300. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20301. *
  20302. * reflectivity: <float>,
  20303. * ior: <float>,
  20304. *
  20305. * sheen: <Color>,
  20306. *
  20307. * transmission: <float>,
  20308. * transmissionMap: new THREE.Texture( <Image> )
  20309. * }
  20310. */
  20311. function MeshPhysicalMaterial(parameters) {
  20312. MeshStandardMaterial.call(this);
  20313. this.defines = {
  20314. 'STANDARD': '',
  20315. 'PHYSICAL': ''
  20316. };
  20317. this.type = 'MeshPhysicalMaterial';
  20318. this.clearcoat = 0.0;
  20319. this.clearcoatMap = null;
  20320. this.clearcoatRoughness = 0.0;
  20321. this.clearcoatRoughnessMap = null;
  20322. this.clearcoatNormalScale = new Vector2(1, 1);
  20323. this.clearcoatNormalMap = null;
  20324. this.reflectivity = 0.5; // maps to F0 = 0.04
  20325. Object.defineProperty(this, 'ior', {
  20326. get: function get() {
  20327. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  20328. },
  20329. set: function set(ior) {
  20330. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  20331. }
  20332. });
  20333. this.sheen = null; // null will disable sheen bsdf
  20334. this.transmission = 0.0;
  20335. this.transmissionMap = null;
  20336. this.setValues(parameters);
  20337. }
  20338. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  20339. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20340. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20341. MeshPhysicalMaterial.prototype.copy = function (source) {
  20342. MeshStandardMaterial.prototype.copy.call(this, source);
  20343. this.defines = {
  20344. 'STANDARD': '',
  20345. 'PHYSICAL': ''
  20346. };
  20347. this.clearcoat = source.clearcoat;
  20348. this.clearcoatMap = source.clearcoatMap;
  20349. this.clearcoatRoughness = source.clearcoatRoughness;
  20350. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20351. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20352. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  20353. this.reflectivity = source.reflectivity;
  20354. if (source.sheen) {
  20355. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  20356. } else {
  20357. this.sheen = null;
  20358. }
  20359. this.transmission = source.transmission;
  20360. this.transmissionMap = source.transmissionMap;
  20361. return this;
  20362. };
  20363. /**
  20364. * parameters = {
  20365. * color: <hex>,
  20366. * specular: <hex>,
  20367. * shininess: <float>,
  20368. * opacity: <float>,
  20369. *
  20370. * map: new THREE.Texture( <Image> ),
  20371. *
  20372. * lightMap: new THREE.Texture( <Image> ),
  20373. * lightMapIntensity: <float>
  20374. *
  20375. * aoMap: new THREE.Texture( <Image> ),
  20376. * aoMapIntensity: <float>
  20377. *
  20378. * emissive: <hex>,
  20379. * emissiveIntensity: <float>
  20380. * emissiveMap: new THREE.Texture( <Image> ),
  20381. *
  20382. * bumpMap: new THREE.Texture( <Image> ),
  20383. * bumpScale: <float>,
  20384. *
  20385. * normalMap: new THREE.Texture( <Image> ),
  20386. * normalMapType: THREE.TangentSpaceNormalMap,
  20387. * normalScale: <Vector2>,
  20388. *
  20389. * displacementMap: new THREE.Texture( <Image> ),
  20390. * displacementScale: <float>,
  20391. * displacementBias: <float>,
  20392. *
  20393. * specularMap: new THREE.Texture( <Image> ),
  20394. *
  20395. * alphaMap: new THREE.Texture( <Image> ),
  20396. *
  20397. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20398. * combine: THREE.MultiplyOperation,
  20399. * reflectivity: <float>,
  20400. * refractionRatio: <float>,
  20401. *
  20402. * wireframe: <boolean>,
  20403. * wireframeLinewidth: <float>,
  20404. *
  20405. * skinning: <bool>,
  20406. * morphTargets: <bool>,
  20407. * morphNormals: <bool>
  20408. * }
  20409. */
  20410. function MeshPhongMaterial(parameters) {
  20411. Material.call(this);
  20412. this.type = 'MeshPhongMaterial';
  20413. this.color = new Color(0xffffff); // diffuse
  20414. this.specular = new Color(0x111111);
  20415. this.shininess = 30;
  20416. this.map = null;
  20417. this.lightMap = null;
  20418. this.lightMapIntensity = 1.0;
  20419. this.aoMap = null;
  20420. this.aoMapIntensity = 1.0;
  20421. this.emissive = new Color(0x000000);
  20422. this.emissiveIntensity = 1.0;
  20423. this.emissiveMap = null;
  20424. this.bumpMap = null;
  20425. this.bumpScale = 1;
  20426. this.normalMap = null;
  20427. this.normalMapType = TangentSpaceNormalMap;
  20428. this.normalScale = new Vector2(1, 1);
  20429. this.displacementMap = null;
  20430. this.displacementScale = 1;
  20431. this.displacementBias = 0;
  20432. this.specularMap = null;
  20433. this.alphaMap = null;
  20434. this.envMap = null;
  20435. this.combine = MultiplyOperation;
  20436. this.reflectivity = 1;
  20437. this.refractionRatio = 0.98;
  20438. this.wireframe = false;
  20439. this.wireframeLinewidth = 1;
  20440. this.wireframeLinecap = 'round';
  20441. this.wireframeLinejoin = 'round';
  20442. this.skinning = false;
  20443. this.morphTargets = false;
  20444. this.morphNormals = false;
  20445. this.setValues(parameters);
  20446. }
  20447. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20448. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20449. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20450. MeshPhongMaterial.prototype.copy = function (source) {
  20451. Material.prototype.copy.call(this, source);
  20452. this.color.copy(source.color);
  20453. this.specular.copy(source.specular);
  20454. this.shininess = source.shininess;
  20455. this.map = source.map;
  20456. this.lightMap = source.lightMap;
  20457. this.lightMapIntensity = source.lightMapIntensity;
  20458. this.aoMap = source.aoMap;
  20459. this.aoMapIntensity = source.aoMapIntensity;
  20460. this.emissive.copy(source.emissive);
  20461. this.emissiveMap = source.emissiveMap;
  20462. this.emissiveIntensity = source.emissiveIntensity;
  20463. this.bumpMap = source.bumpMap;
  20464. this.bumpScale = source.bumpScale;
  20465. this.normalMap = source.normalMap;
  20466. this.normalMapType = source.normalMapType;
  20467. this.normalScale.copy(source.normalScale);
  20468. this.displacementMap = source.displacementMap;
  20469. this.displacementScale = source.displacementScale;
  20470. this.displacementBias = source.displacementBias;
  20471. this.specularMap = source.specularMap;
  20472. this.alphaMap = source.alphaMap;
  20473. this.envMap = source.envMap;
  20474. this.combine = source.combine;
  20475. this.reflectivity = source.reflectivity;
  20476. this.refractionRatio = source.refractionRatio;
  20477. this.wireframe = source.wireframe;
  20478. this.wireframeLinewidth = source.wireframeLinewidth;
  20479. this.wireframeLinecap = source.wireframeLinecap;
  20480. this.wireframeLinejoin = source.wireframeLinejoin;
  20481. this.skinning = source.skinning;
  20482. this.morphTargets = source.morphTargets;
  20483. this.morphNormals = source.morphNormals;
  20484. return this;
  20485. };
  20486. /**
  20487. * parameters = {
  20488. * color: <hex>,
  20489. *
  20490. * map: new THREE.Texture( <Image> ),
  20491. * gradientMap: new THREE.Texture( <Image> ),
  20492. *
  20493. * lightMap: new THREE.Texture( <Image> ),
  20494. * lightMapIntensity: <float>
  20495. *
  20496. * aoMap: new THREE.Texture( <Image> ),
  20497. * aoMapIntensity: <float>
  20498. *
  20499. * emissive: <hex>,
  20500. * emissiveIntensity: <float>
  20501. * emissiveMap: new THREE.Texture( <Image> ),
  20502. *
  20503. * bumpMap: new THREE.Texture( <Image> ),
  20504. * bumpScale: <float>,
  20505. *
  20506. * normalMap: new THREE.Texture( <Image> ),
  20507. * normalMapType: THREE.TangentSpaceNormalMap,
  20508. * normalScale: <Vector2>,
  20509. *
  20510. * displacementMap: new THREE.Texture( <Image> ),
  20511. * displacementScale: <float>,
  20512. * displacementBias: <float>,
  20513. *
  20514. * alphaMap: new THREE.Texture( <Image> ),
  20515. *
  20516. * wireframe: <boolean>,
  20517. * wireframeLinewidth: <float>,
  20518. *
  20519. * skinning: <bool>,
  20520. * morphTargets: <bool>,
  20521. * morphNormals: <bool>
  20522. * }
  20523. */
  20524. function MeshToonMaterial(parameters) {
  20525. Material.call(this);
  20526. this.defines = {
  20527. 'TOON': ''
  20528. };
  20529. this.type = 'MeshToonMaterial';
  20530. this.color = new Color(0xffffff);
  20531. this.map = null;
  20532. this.gradientMap = null;
  20533. this.lightMap = null;
  20534. this.lightMapIntensity = 1.0;
  20535. this.aoMap = null;
  20536. this.aoMapIntensity = 1.0;
  20537. this.emissive = new Color(0x000000);
  20538. this.emissiveIntensity = 1.0;
  20539. this.emissiveMap = null;
  20540. this.bumpMap = null;
  20541. this.bumpScale = 1;
  20542. this.normalMap = null;
  20543. this.normalMapType = TangentSpaceNormalMap;
  20544. this.normalScale = new Vector2(1, 1);
  20545. this.displacementMap = null;
  20546. this.displacementScale = 1;
  20547. this.displacementBias = 0;
  20548. this.alphaMap = null;
  20549. this.wireframe = false;
  20550. this.wireframeLinewidth = 1;
  20551. this.wireframeLinecap = 'round';
  20552. this.wireframeLinejoin = 'round';
  20553. this.skinning = false;
  20554. this.morphTargets = false;
  20555. this.morphNormals = false;
  20556. this.setValues(parameters);
  20557. }
  20558. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20559. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20560. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20561. MeshToonMaterial.prototype.copy = function (source) {
  20562. Material.prototype.copy.call(this, source);
  20563. this.color.copy(source.color);
  20564. this.map = source.map;
  20565. this.gradientMap = source.gradientMap;
  20566. this.lightMap = source.lightMap;
  20567. this.lightMapIntensity = source.lightMapIntensity;
  20568. this.aoMap = source.aoMap;
  20569. this.aoMapIntensity = source.aoMapIntensity;
  20570. this.emissive.copy(source.emissive);
  20571. this.emissiveMap = source.emissiveMap;
  20572. this.emissiveIntensity = source.emissiveIntensity;
  20573. this.bumpMap = source.bumpMap;
  20574. this.bumpScale = source.bumpScale;
  20575. this.normalMap = source.normalMap;
  20576. this.normalMapType = source.normalMapType;
  20577. this.normalScale.copy(source.normalScale);
  20578. this.displacementMap = source.displacementMap;
  20579. this.displacementScale = source.displacementScale;
  20580. this.displacementBias = source.displacementBias;
  20581. this.alphaMap = source.alphaMap;
  20582. this.wireframe = source.wireframe;
  20583. this.wireframeLinewidth = source.wireframeLinewidth;
  20584. this.wireframeLinecap = source.wireframeLinecap;
  20585. this.wireframeLinejoin = source.wireframeLinejoin;
  20586. this.skinning = source.skinning;
  20587. this.morphTargets = source.morphTargets;
  20588. this.morphNormals = source.morphNormals;
  20589. return this;
  20590. };
  20591. /**
  20592. * parameters = {
  20593. * opacity: <float>,
  20594. *
  20595. * bumpMap: new THREE.Texture( <Image> ),
  20596. * bumpScale: <float>,
  20597. *
  20598. * normalMap: new THREE.Texture( <Image> ),
  20599. * normalMapType: THREE.TangentSpaceNormalMap,
  20600. * normalScale: <Vector2>,
  20601. *
  20602. * displacementMap: new THREE.Texture( <Image> ),
  20603. * displacementScale: <float>,
  20604. * displacementBias: <float>,
  20605. *
  20606. * wireframe: <boolean>,
  20607. * wireframeLinewidth: <float>
  20608. *
  20609. * skinning: <bool>,
  20610. * morphTargets: <bool>,
  20611. * morphNormals: <bool>
  20612. * }
  20613. */
  20614. function MeshNormalMaterial(parameters) {
  20615. Material.call(this);
  20616. this.type = 'MeshNormalMaterial';
  20617. this.bumpMap = null;
  20618. this.bumpScale = 1;
  20619. this.normalMap = null;
  20620. this.normalMapType = TangentSpaceNormalMap;
  20621. this.normalScale = new Vector2(1, 1);
  20622. this.displacementMap = null;
  20623. this.displacementScale = 1;
  20624. this.displacementBias = 0;
  20625. this.wireframe = false;
  20626. this.wireframeLinewidth = 1;
  20627. this.fog = false;
  20628. this.skinning = false;
  20629. this.morphTargets = false;
  20630. this.morphNormals = false;
  20631. this.setValues(parameters);
  20632. }
  20633. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20634. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20635. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20636. MeshNormalMaterial.prototype.copy = function (source) {
  20637. Material.prototype.copy.call(this, source);
  20638. this.bumpMap = source.bumpMap;
  20639. this.bumpScale = source.bumpScale;
  20640. this.normalMap = source.normalMap;
  20641. this.normalMapType = source.normalMapType;
  20642. this.normalScale.copy(source.normalScale);
  20643. this.displacementMap = source.displacementMap;
  20644. this.displacementScale = source.displacementScale;
  20645. this.displacementBias = source.displacementBias;
  20646. this.wireframe = source.wireframe;
  20647. this.wireframeLinewidth = source.wireframeLinewidth;
  20648. this.skinning = source.skinning;
  20649. this.morphTargets = source.morphTargets;
  20650. this.morphNormals = source.morphNormals;
  20651. return this;
  20652. };
  20653. /**
  20654. * parameters = {
  20655. * color: <hex>,
  20656. * opacity: <float>,
  20657. *
  20658. * map: new THREE.Texture( <Image> ),
  20659. *
  20660. * lightMap: new THREE.Texture( <Image> ),
  20661. * lightMapIntensity: <float>
  20662. *
  20663. * aoMap: new THREE.Texture( <Image> ),
  20664. * aoMapIntensity: <float>
  20665. *
  20666. * emissive: <hex>,
  20667. * emissiveIntensity: <float>
  20668. * emissiveMap: new THREE.Texture( <Image> ),
  20669. *
  20670. * specularMap: new THREE.Texture( <Image> ),
  20671. *
  20672. * alphaMap: new THREE.Texture( <Image> ),
  20673. *
  20674. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20675. * combine: THREE.Multiply,
  20676. * reflectivity: <float>,
  20677. * refractionRatio: <float>,
  20678. *
  20679. * wireframe: <boolean>,
  20680. * wireframeLinewidth: <float>,
  20681. *
  20682. * skinning: <bool>,
  20683. * morphTargets: <bool>,
  20684. * morphNormals: <bool>
  20685. * }
  20686. */
  20687. function MeshLambertMaterial(parameters) {
  20688. Material.call(this);
  20689. this.type = 'MeshLambertMaterial';
  20690. this.color = new Color(0xffffff); // diffuse
  20691. this.map = null;
  20692. this.lightMap = null;
  20693. this.lightMapIntensity = 1.0;
  20694. this.aoMap = null;
  20695. this.aoMapIntensity = 1.0;
  20696. this.emissive = new Color(0x000000);
  20697. this.emissiveIntensity = 1.0;
  20698. this.emissiveMap = null;
  20699. this.specularMap = null;
  20700. this.alphaMap = null;
  20701. this.envMap = null;
  20702. this.combine = MultiplyOperation;
  20703. this.reflectivity = 1;
  20704. this.refractionRatio = 0.98;
  20705. this.wireframe = false;
  20706. this.wireframeLinewidth = 1;
  20707. this.wireframeLinecap = 'round';
  20708. this.wireframeLinejoin = 'round';
  20709. this.skinning = false;
  20710. this.morphTargets = false;
  20711. this.morphNormals = false;
  20712. this.setValues(parameters);
  20713. }
  20714. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20715. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20716. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20717. MeshLambertMaterial.prototype.copy = function (source) {
  20718. Material.prototype.copy.call(this, source);
  20719. this.color.copy(source.color);
  20720. this.map = source.map;
  20721. this.lightMap = source.lightMap;
  20722. this.lightMapIntensity = source.lightMapIntensity;
  20723. this.aoMap = source.aoMap;
  20724. this.aoMapIntensity = source.aoMapIntensity;
  20725. this.emissive.copy(source.emissive);
  20726. this.emissiveMap = source.emissiveMap;
  20727. this.emissiveIntensity = source.emissiveIntensity;
  20728. this.specularMap = source.specularMap;
  20729. this.alphaMap = source.alphaMap;
  20730. this.envMap = source.envMap;
  20731. this.combine = source.combine;
  20732. this.reflectivity = source.reflectivity;
  20733. this.refractionRatio = source.refractionRatio;
  20734. this.wireframe = source.wireframe;
  20735. this.wireframeLinewidth = source.wireframeLinewidth;
  20736. this.wireframeLinecap = source.wireframeLinecap;
  20737. this.wireframeLinejoin = source.wireframeLinejoin;
  20738. this.skinning = source.skinning;
  20739. this.morphTargets = source.morphTargets;
  20740. this.morphNormals = source.morphNormals;
  20741. return this;
  20742. };
  20743. /**
  20744. * parameters = {
  20745. * color: <hex>,
  20746. * opacity: <float>,
  20747. *
  20748. * matcap: new THREE.Texture( <Image> ),
  20749. *
  20750. * map: new THREE.Texture( <Image> ),
  20751. *
  20752. * bumpMap: new THREE.Texture( <Image> ),
  20753. * bumpScale: <float>,
  20754. *
  20755. * normalMap: new THREE.Texture( <Image> ),
  20756. * normalMapType: THREE.TangentSpaceNormalMap,
  20757. * normalScale: <Vector2>,
  20758. *
  20759. * displacementMap: new THREE.Texture( <Image> ),
  20760. * displacementScale: <float>,
  20761. * displacementBias: <float>,
  20762. *
  20763. * alphaMap: new THREE.Texture( <Image> ),
  20764. *
  20765. * skinning: <bool>,
  20766. * morphTargets: <bool>,
  20767. * morphNormals: <bool>
  20768. * }
  20769. */
  20770. function MeshMatcapMaterial(parameters) {
  20771. Material.call(this);
  20772. this.defines = {
  20773. 'MATCAP': ''
  20774. };
  20775. this.type = 'MeshMatcapMaterial';
  20776. this.color = new Color(0xffffff); // diffuse
  20777. this.matcap = null;
  20778. this.map = null;
  20779. this.bumpMap = null;
  20780. this.bumpScale = 1;
  20781. this.normalMap = null;
  20782. this.normalMapType = TangentSpaceNormalMap;
  20783. this.normalScale = new Vector2(1, 1);
  20784. this.displacementMap = null;
  20785. this.displacementScale = 1;
  20786. this.displacementBias = 0;
  20787. this.alphaMap = null;
  20788. this.skinning = false;
  20789. this.morphTargets = false;
  20790. this.morphNormals = false;
  20791. this.setValues(parameters);
  20792. }
  20793. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20794. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20795. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20796. MeshMatcapMaterial.prototype.copy = function (source) {
  20797. Material.prototype.copy.call(this, source);
  20798. this.defines = {
  20799. 'MATCAP': ''
  20800. };
  20801. this.color.copy(source.color);
  20802. this.matcap = source.matcap;
  20803. this.map = source.map;
  20804. this.bumpMap = source.bumpMap;
  20805. this.bumpScale = source.bumpScale;
  20806. this.normalMap = source.normalMap;
  20807. this.normalMapType = source.normalMapType;
  20808. this.normalScale.copy(source.normalScale);
  20809. this.displacementMap = source.displacementMap;
  20810. this.displacementScale = source.displacementScale;
  20811. this.displacementBias = source.displacementBias;
  20812. this.alphaMap = source.alphaMap;
  20813. this.skinning = source.skinning;
  20814. this.morphTargets = source.morphTargets;
  20815. this.morphNormals = source.morphNormals;
  20816. return this;
  20817. };
  20818. /**
  20819. * parameters = {
  20820. * color: <hex>,
  20821. * opacity: <float>,
  20822. *
  20823. * linewidth: <float>,
  20824. *
  20825. * scale: <float>,
  20826. * dashSize: <float>,
  20827. * gapSize: <float>
  20828. * }
  20829. */
  20830. function LineDashedMaterial(parameters) {
  20831. LineBasicMaterial.call(this);
  20832. this.type = 'LineDashedMaterial';
  20833. this.scale = 1;
  20834. this.dashSize = 3;
  20835. this.gapSize = 1;
  20836. this.setValues(parameters);
  20837. }
  20838. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20839. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20840. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20841. LineDashedMaterial.prototype.copy = function (source) {
  20842. LineBasicMaterial.prototype.copy.call(this, source);
  20843. this.scale = source.scale;
  20844. this.dashSize = source.dashSize;
  20845. this.gapSize = source.gapSize;
  20846. return this;
  20847. };
  20848. var Materials = /*#__PURE__*/Object.freeze({
  20849. __proto__: null,
  20850. ShadowMaterial: ShadowMaterial,
  20851. SpriteMaterial: SpriteMaterial,
  20852. RawShaderMaterial: RawShaderMaterial,
  20853. ShaderMaterial: ShaderMaterial,
  20854. PointsMaterial: PointsMaterial,
  20855. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20856. MeshStandardMaterial: MeshStandardMaterial,
  20857. MeshPhongMaterial: MeshPhongMaterial,
  20858. MeshToonMaterial: MeshToonMaterial,
  20859. MeshNormalMaterial: MeshNormalMaterial,
  20860. MeshLambertMaterial: MeshLambertMaterial,
  20861. MeshDepthMaterial: MeshDepthMaterial,
  20862. MeshDistanceMaterial: MeshDistanceMaterial,
  20863. MeshBasicMaterial: MeshBasicMaterial,
  20864. MeshMatcapMaterial: MeshMatcapMaterial,
  20865. LineDashedMaterial: LineDashedMaterial,
  20866. LineBasicMaterial: LineBasicMaterial,
  20867. Material: Material
  20868. });
  20869. var AnimationUtils = {
  20870. // same as Array.prototype.slice, but also works on typed arrays
  20871. arraySlice: function arraySlice(array, from, to) {
  20872. if (AnimationUtils.isTypedArray(array)) {
  20873. // in ios9 array.subarray(from, undefined) will return empty array
  20874. // but array.subarray(from) or array.subarray(from, len) is correct
  20875. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20876. }
  20877. return array.slice(from, to);
  20878. },
  20879. // converts an array to a specific type
  20880. convertArray: function convertArray(array, type, forceClone) {
  20881. if (!array || // let 'undefined' and 'null' pass
  20882. !forceClone && array.constructor === type) return array;
  20883. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20884. return new type(array); // create typed array
  20885. }
  20886. return Array.prototype.slice.call(array); // create Array
  20887. },
  20888. isTypedArray: function isTypedArray(object) {
  20889. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20890. },
  20891. // returns an array by which times and values can be sorted
  20892. getKeyframeOrder: function getKeyframeOrder(times) {
  20893. function compareTime(i, j) {
  20894. return times[i] - times[j];
  20895. }
  20896. var n = times.length;
  20897. var result = new Array(n);
  20898. for (var i = 0; i !== n; ++i) {
  20899. result[i] = i;
  20900. }
  20901. result.sort(compareTime);
  20902. return result;
  20903. },
  20904. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20905. sortedArray: function sortedArray(values, stride, order) {
  20906. var nValues = values.length;
  20907. var result = new values.constructor(nValues);
  20908. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20909. var srcOffset = order[i] * stride;
  20910. for (var j = 0; j !== stride; ++j) {
  20911. result[dstOffset++] = values[srcOffset + j];
  20912. }
  20913. }
  20914. return result;
  20915. },
  20916. // function for parsing AOS keyframe formats
  20917. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20918. var i = 1,
  20919. key = jsonKeys[0];
  20920. while (key !== undefined && key[valuePropertyName] === undefined) {
  20921. key = jsonKeys[i++];
  20922. }
  20923. if (key === undefined) return; // no data
  20924. var value = key[valuePropertyName];
  20925. if (value === undefined) return; // no data
  20926. if (Array.isArray(value)) {
  20927. do {
  20928. value = key[valuePropertyName];
  20929. if (value !== undefined) {
  20930. times.push(key.time);
  20931. values.push.apply(values, value); // push all elements
  20932. }
  20933. key = jsonKeys[i++];
  20934. } while (key !== undefined);
  20935. } else if (value.toArray !== undefined) {
  20936. // ...assume THREE.Math-ish
  20937. do {
  20938. value = key[valuePropertyName];
  20939. if (value !== undefined) {
  20940. times.push(key.time);
  20941. value.toArray(values, values.length);
  20942. }
  20943. key = jsonKeys[i++];
  20944. } while (key !== undefined);
  20945. } else {
  20946. // otherwise push as-is
  20947. do {
  20948. value = key[valuePropertyName];
  20949. if (value !== undefined) {
  20950. times.push(key.time);
  20951. values.push(value);
  20952. }
  20953. key = jsonKeys[i++];
  20954. } while (key !== undefined);
  20955. }
  20956. },
  20957. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20958. if (fps === void 0) {
  20959. fps = 30;
  20960. }
  20961. var clip = sourceClip.clone();
  20962. clip.name = name;
  20963. var tracks = [];
  20964. for (var i = 0; i < clip.tracks.length; ++i) {
  20965. var track = clip.tracks[i];
  20966. var valueSize = track.getValueSize();
  20967. var times = [];
  20968. var values = [];
  20969. for (var j = 0; j < track.times.length; ++j) {
  20970. var frame = track.times[j] * fps;
  20971. if (frame < startFrame || frame >= endFrame) continue;
  20972. times.push(track.times[j]);
  20973. for (var k = 0; k < valueSize; ++k) {
  20974. values.push(track.values[j * valueSize + k]);
  20975. }
  20976. }
  20977. if (times.length === 0) continue;
  20978. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20979. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20980. tracks.push(track);
  20981. }
  20982. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20983. var minStartTime = Infinity;
  20984. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20985. if (minStartTime > clip.tracks[_i].times[0]) {
  20986. minStartTime = clip.tracks[_i].times[0];
  20987. }
  20988. } // shift all tracks such that clip begins at t=0
  20989. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20990. clip.tracks[_i2].shift(-1 * minStartTime);
  20991. }
  20992. clip.resetDuration();
  20993. return clip;
  20994. },
  20995. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20996. if (referenceFrame === void 0) {
  20997. referenceFrame = 0;
  20998. }
  20999. if (referenceClip === void 0) {
  21000. referenceClip = targetClip;
  21001. }
  21002. if (fps === void 0) {
  21003. fps = 30;
  21004. }
  21005. if (fps <= 0) fps = 30;
  21006. var numTracks = referenceClip.tracks.length;
  21007. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  21008. var _loop = function _loop(i) {
  21009. var referenceTrack = referenceClip.tracks[i];
  21010. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  21011. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  21012. var targetTrack = targetClip.tracks.find(function (track) {
  21013. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  21014. });
  21015. if (targetTrack === undefined) return "continue";
  21016. var referenceOffset = 0;
  21017. var referenceValueSize = referenceTrack.getValueSize();
  21018. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21019. referenceOffset = referenceValueSize / 3;
  21020. }
  21021. var targetOffset = 0;
  21022. var targetValueSize = targetTrack.getValueSize();
  21023. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  21024. targetOffset = targetValueSize / 3;
  21025. }
  21026. var lastIndex = referenceTrack.times.length - 1;
  21027. var referenceValue = void 0; // Find the value to subtract out of the track
  21028. if (referenceTime <= referenceTrack.times[0]) {
  21029. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  21030. var startIndex = referenceOffset;
  21031. var endIndex = referenceValueSize - referenceOffset;
  21032. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  21033. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  21034. // Reference frame is after the last keyframe, so just use the last keyframe
  21035. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  21036. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  21037. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  21038. } else {
  21039. // Interpolate to the reference value
  21040. var interpolant = referenceTrack.createInterpolant();
  21041. var _startIndex2 = referenceOffset;
  21042. var _endIndex2 = referenceValueSize - referenceOffset;
  21043. interpolant.evaluate(referenceTime);
  21044. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  21045. } // Conjugate the quaternion
  21046. if (referenceTrackType === 'quaternion') {
  21047. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  21048. referenceQuat.toArray(referenceValue);
  21049. } // Subtract the reference value from all of the track values
  21050. var numTimes = targetTrack.times.length;
  21051. for (var j = 0; j < numTimes; ++j) {
  21052. var valueStart = j * targetValueSize + targetOffset;
  21053. if (referenceTrackType === 'quaternion') {
  21054. // Multiply the conjugate for quaternion track types
  21055. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  21056. } else {
  21057. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  21058. for (var k = 0; k < valueEnd; ++k) {
  21059. targetTrack.values[valueStart + k] -= referenceValue[k];
  21060. }
  21061. }
  21062. }
  21063. };
  21064. for (var i = 0; i < numTracks; ++i) {
  21065. var _ret = _loop(i);
  21066. if (_ret === "continue") continue;
  21067. }
  21068. targetClip.blendMode = AdditiveAnimationBlendMode;
  21069. return targetClip;
  21070. }
  21071. };
  21072. /**
  21073. * Abstract base class of interpolants over parametric samples.
  21074. *
  21075. * The parameter domain is one dimensional, typically the time or a path
  21076. * along a curve defined by the data.
  21077. *
  21078. * The sample values can have any dimensionality and derived classes may
  21079. * apply special interpretations to the data.
  21080. *
  21081. * This class provides the interval seek in a Template Method, deferring
  21082. * the actual interpolation to derived classes.
  21083. *
  21084. * Time complexity is O(1) for linear access crossing at most two points
  21085. * and O(log N) for random access, where N is the number of positions.
  21086. *
  21087. * References:
  21088. *
  21089. * http://www.oodesign.com/template-method-pattern.html
  21090. *
  21091. */
  21092. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21093. this.parameterPositions = parameterPositions;
  21094. this._cachedIndex = 0;
  21095. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  21096. this.sampleValues = sampleValues;
  21097. this.valueSize = sampleSize;
  21098. }
  21099. Object.assign(Interpolant.prototype, {
  21100. evaluate: function evaluate(t) {
  21101. var pp = this.parameterPositions;
  21102. var i1 = this._cachedIndex,
  21103. t1 = pp[i1],
  21104. t0 = pp[i1 - 1];
  21105. validate_interval: {
  21106. seek: {
  21107. var right;
  21108. linear_scan: {
  21109. //- See http://jsperf.com/comparison-to-undefined/3
  21110. //- slower code:
  21111. //-
  21112. //- if ( t >= t1 || t1 === undefined ) {
  21113. forward_scan: if (!(t < t1)) {
  21114. for (var giveUpAt = i1 + 2;;) {
  21115. if (t1 === undefined) {
  21116. if (t < t0) break forward_scan; // after end
  21117. i1 = pp.length;
  21118. this._cachedIndex = i1;
  21119. return this.afterEnd_(i1 - 1, t, t0);
  21120. }
  21121. if (i1 === giveUpAt) break; // this loop
  21122. t0 = t1;
  21123. t1 = pp[++i1];
  21124. if (t < t1) {
  21125. // we have arrived at the sought interval
  21126. break seek;
  21127. }
  21128. } // prepare binary search on the right side of the index
  21129. right = pp.length;
  21130. break linear_scan;
  21131. } //- slower code:
  21132. //- if ( t < t0 || t0 === undefined ) {
  21133. if (!(t >= t0)) {
  21134. // looping?
  21135. var t1global = pp[1];
  21136. if (t < t1global) {
  21137. i1 = 2; // + 1, using the scan for the details
  21138. t0 = t1global;
  21139. } // linear reverse scan
  21140. for (var _giveUpAt = i1 - 2;;) {
  21141. if (t0 === undefined) {
  21142. // before start
  21143. this._cachedIndex = 0;
  21144. return this.beforeStart_(0, t, t1);
  21145. }
  21146. if (i1 === _giveUpAt) break; // this loop
  21147. t1 = t0;
  21148. t0 = pp[--i1 - 1];
  21149. if (t >= t0) {
  21150. // we have arrived at the sought interval
  21151. break seek;
  21152. }
  21153. } // prepare binary search on the left side of the index
  21154. right = i1;
  21155. i1 = 0;
  21156. break linear_scan;
  21157. } // the interval is valid
  21158. break validate_interval;
  21159. } // linear scan
  21160. // binary search
  21161. while (i1 < right) {
  21162. var mid = i1 + right >>> 1;
  21163. if (t < pp[mid]) {
  21164. right = mid;
  21165. } else {
  21166. i1 = mid + 1;
  21167. }
  21168. }
  21169. t1 = pp[i1];
  21170. t0 = pp[i1 - 1]; // check boundary cases, again
  21171. if (t0 === undefined) {
  21172. this._cachedIndex = 0;
  21173. return this.beforeStart_(0, t, t1);
  21174. }
  21175. if (t1 === undefined) {
  21176. i1 = pp.length;
  21177. this._cachedIndex = i1;
  21178. return this.afterEnd_(i1 - 1, t0, t);
  21179. }
  21180. } // seek
  21181. this._cachedIndex = i1;
  21182. this.intervalChanged_(i1, t0, t1);
  21183. } // validate_interval
  21184. return this.interpolate_(i1, t0, t, t1);
  21185. },
  21186. settings: null,
  21187. // optional, subclass-specific settings structure
  21188. // Note: The indirection allows central control of many interpolants.
  21189. // --- Protected interface
  21190. DefaultSettings_: {},
  21191. getSettings_: function getSettings_() {
  21192. return this.settings || this.DefaultSettings_;
  21193. },
  21194. copySampleValue_: function copySampleValue_(index) {
  21195. // copies a sample value to the result buffer
  21196. var result = this.resultBuffer,
  21197. values = this.sampleValues,
  21198. stride = this.valueSize,
  21199. offset = index * stride;
  21200. for (var i = 0; i !== stride; ++i) {
  21201. result[i] = values[offset + i];
  21202. }
  21203. return result;
  21204. },
  21205. // Template methods for derived classes:
  21206. interpolate_: function interpolate_()
  21207. /* i1, t0, t, t1 */
  21208. {
  21209. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  21210. },
  21211. intervalChanged_: function intervalChanged_()
  21212. /* i1, t0, t1 */
  21213. {// empty
  21214. }
  21215. }); // DECLARE ALIAS AFTER assign prototype
  21216. Object.assign(Interpolant.prototype, {
  21217. //( 0, t, t0 ), returns this.resultBuffer
  21218. beforeStart_: Interpolant.prototype.copySampleValue_,
  21219. //( N-1, tN-1, t ), returns this.resultBuffer
  21220. afterEnd_: Interpolant.prototype.copySampleValue_
  21221. });
  21222. /**
  21223. * Fast and simple cubic spline interpolant.
  21224. *
  21225. * It was derived from a Hermitian construction setting the first derivative
  21226. * at each sample position to the linear slope between neighboring positions
  21227. * over their parameter interval.
  21228. */
  21229. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21230. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21231. this._weightPrev = -0;
  21232. this._offsetPrev = -0;
  21233. this._weightNext = -0;
  21234. this._offsetNext = -0;
  21235. }
  21236. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21237. constructor: CubicInterpolant,
  21238. DefaultSettings_: {
  21239. endingStart: ZeroCurvatureEnding,
  21240. endingEnd: ZeroCurvatureEnding
  21241. },
  21242. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  21243. var pp = this.parameterPositions;
  21244. var iPrev = i1 - 2,
  21245. iNext = i1 + 1,
  21246. tPrev = pp[iPrev],
  21247. tNext = pp[iNext];
  21248. if (tPrev === undefined) {
  21249. switch (this.getSettings_().endingStart) {
  21250. case ZeroSlopeEnding:
  21251. // f'(t0) = 0
  21252. iPrev = i1;
  21253. tPrev = 2 * t0 - t1;
  21254. break;
  21255. case WrapAroundEnding:
  21256. // use the other end of the curve
  21257. iPrev = pp.length - 2;
  21258. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  21259. break;
  21260. default:
  21261. // ZeroCurvatureEnding
  21262. // f''(t0) = 0 a.k.a. Natural Spline
  21263. iPrev = i1;
  21264. tPrev = t1;
  21265. }
  21266. }
  21267. if (tNext === undefined) {
  21268. switch (this.getSettings_().endingEnd) {
  21269. case ZeroSlopeEnding:
  21270. // f'(tN) = 0
  21271. iNext = i1;
  21272. tNext = 2 * t1 - t0;
  21273. break;
  21274. case WrapAroundEnding:
  21275. // use the other end of the curve
  21276. iNext = 1;
  21277. tNext = t1 + pp[1] - pp[0];
  21278. break;
  21279. default:
  21280. // ZeroCurvatureEnding
  21281. // f''(tN) = 0, a.k.a. Natural Spline
  21282. iNext = i1 - 1;
  21283. tNext = t0;
  21284. }
  21285. }
  21286. var halfDt = (t1 - t0) * 0.5,
  21287. stride = this.valueSize;
  21288. this._weightPrev = halfDt / (t0 - tPrev);
  21289. this._weightNext = halfDt / (tNext - t1);
  21290. this._offsetPrev = iPrev * stride;
  21291. this._offsetNext = iNext * stride;
  21292. },
  21293. interpolate_: function interpolate_(i1, t0, t, t1) {
  21294. var result = this.resultBuffer,
  21295. values = this.sampleValues,
  21296. stride = this.valueSize,
  21297. o1 = i1 * stride,
  21298. o0 = o1 - stride,
  21299. oP = this._offsetPrev,
  21300. oN = this._offsetNext,
  21301. wP = this._weightPrev,
  21302. wN = this._weightNext,
  21303. p = (t - t0) / (t1 - t0),
  21304. pp = p * p,
  21305. ppp = pp * p; // evaluate polynomials
  21306. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  21307. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  21308. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  21309. var sN = wN * ppp - wN * pp; // combine data linearly
  21310. for (var i = 0; i !== stride; ++i) {
  21311. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  21312. }
  21313. return result;
  21314. }
  21315. });
  21316. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21317. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21318. }
  21319. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21320. constructor: LinearInterpolant,
  21321. interpolate_: function interpolate_(i1, t0, t, t1) {
  21322. var result = this.resultBuffer,
  21323. values = this.sampleValues,
  21324. stride = this.valueSize,
  21325. offset1 = i1 * stride,
  21326. offset0 = offset1 - stride,
  21327. weight1 = (t - t0) / (t1 - t0),
  21328. weight0 = 1 - weight1;
  21329. for (var i = 0; i !== stride; ++i) {
  21330. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  21331. }
  21332. return result;
  21333. }
  21334. });
  21335. /**
  21336. *
  21337. * Interpolant that evaluates to the sample value at the position preceeding
  21338. * the parameter.
  21339. */
  21340. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21341. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21342. }
  21343. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21344. constructor: DiscreteInterpolant,
  21345. interpolate_: function interpolate_(i1
  21346. /*, t0, t, t1 */
  21347. ) {
  21348. return this.copySampleValue_(i1 - 1);
  21349. }
  21350. });
  21351. function KeyframeTrack(name, times, values, interpolation) {
  21352. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  21353. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  21354. this.name = name;
  21355. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  21356. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  21357. this.setInterpolation(interpolation || this.DefaultInterpolation);
  21358. } // Static methods
  21359. Object.assign(KeyframeTrack, {
  21360. // Serialization (in static context, because of constructor invocation
  21361. // and automatic invocation of .toJSON):
  21362. toJSON: function toJSON(track) {
  21363. var trackType = track.constructor;
  21364. var json; // derived classes can define a static toJSON method
  21365. if (trackType.toJSON !== undefined) {
  21366. json = trackType.toJSON(track);
  21367. } else {
  21368. // by default, we assume the data can be serialized as-is
  21369. json = {
  21370. 'name': track.name,
  21371. 'times': AnimationUtils.convertArray(track.times, Array),
  21372. 'values': AnimationUtils.convertArray(track.values, Array)
  21373. };
  21374. var interpolation = track.getInterpolation();
  21375. if (interpolation !== track.DefaultInterpolation) {
  21376. json.interpolation = interpolation;
  21377. }
  21378. }
  21379. json.type = track.ValueTypeName; // mandatory
  21380. return json;
  21381. }
  21382. });
  21383. Object.assign(KeyframeTrack.prototype, {
  21384. constructor: KeyframeTrack,
  21385. TimeBufferType: Float32Array,
  21386. ValueBufferType: Float32Array,
  21387. DefaultInterpolation: InterpolateLinear,
  21388. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  21389. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  21390. },
  21391. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21392. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21393. },
  21394. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  21395. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  21396. },
  21397. setInterpolation: function setInterpolation(interpolation) {
  21398. var factoryMethod;
  21399. switch (interpolation) {
  21400. case InterpolateDiscrete:
  21401. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21402. break;
  21403. case InterpolateLinear:
  21404. factoryMethod = this.InterpolantFactoryMethodLinear;
  21405. break;
  21406. case InterpolateSmooth:
  21407. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21408. break;
  21409. }
  21410. if (factoryMethod === undefined) {
  21411. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  21412. if (this.createInterpolant === undefined) {
  21413. // fall back to default, unless the default itself is messed up
  21414. if (interpolation !== this.DefaultInterpolation) {
  21415. this.setInterpolation(this.DefaultInterpolation);
  21416. } else {
  21417. throw new Error(message); // fatal, in this case
  21418. }
  21419. }
  21420. console.warn('THREE.KeyframeTrack:', message);
  21421. return this;
  21422. }
  21423. this.createInterpolant = factoryMethod;
  21424. return this;
  21425. },
  21426. getInterpolation: function getInterpolation() {
  21427. switch (this.createInterpolant) {
  21428. case this.InterpolantFactoryMethodDiscrete:
  21429. return InterpolateDiscrete;
  21430. case this.InterpolantFactoryMethodLinear:
  21431. return InterpolateLinear;
  21432. case this.InterpolantFactoryMethodSmooth:
  21433. return InterpolateSmooth;
  21434. }
  21435. },
  21436. getValueSize: function getValueSize() {
  21437. return this.values.length / this.times.length;
  21438. },
  21439. // move all keyframes either forwards or backwards in time
  21440. shift: function shift(timeOffset) {
  21441. if (timeOffset !== 0.0) {
  21442. var times = this.times;
  21443. for (var i = 0, n = times.length; i !== n; ++i) {
  21444. times[i] += timeOffset;
  21445. }
  21446. }
  21447. return this;
  21448. },
  21449. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21450. scale: function scale(timeScale) {
  21451. if (timeScale !== 1.0) {
  21452. var times = this.times;
  21453. for (var i = 0, n = times.length; i !== n; ++i) {
  21454. times[i] *= timeScale;
  21455. }
  21456. }
  21457. return this;
  21458. },
  21459. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21460. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21461. trim: function trim(startTime, endTime) {
  21462. var times = this.times,
  21463. nKeys = times.length;
  21464. var from = 0,
  21465. to = nKeys - 1;
  21466. while (from !== nKeys && times[from] < startTime) {
  21467. ++from;
  21468. }
  21469. while (to !== -1 && times[to] > endTime) {
  21470. --to;
  21471. }
  21472. ++to; // inclusive -> exclusive bound
  21473. if (from !== 0 || to !== nKeys) {
  21474. // empty tracks are forbidden, so keep at least one keyframe
  21475. if (from >= to) {
  21476. to = Math.max(to, 1);
  21477. from = to - 1;
  21478. }
  21479. var stride = this.getValueSize();
  21480. this.times = AnimationUtils.arraySlice(times, from, to);
  21481. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21482. }
  21483. return this;
  21484. },
  21485. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21486. validate: function validate() {
  21487. var valid = true;
  21488. var valueSize = this.getValueSize();
  21489. if (valueSize - Math.floor(valueSize) !== 0) {
  21490. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21491. valid = false;
  21492. }
  21493. var times = this.times,
  21494. values = this.values,
  21495. nKeys = times.length;
  21496. if (nKeys === 0) {
  21497. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21498. valid = false;
  21499. }
  21500. var prevTime = null;
  21501. for (var i = 0; i !== nKeys; i++) {
  21502. var currTime = times[i];
  21503. if (typeof currTime === 'number' && isNaN(currTime)) {
  21504. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21505. valid = false;
  21506. break;
  21507. }
  21508. if (prevTime !== null && prevTime > currTime) {
  21509. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21510. valid = false;
  21511. break;
  21512. }
  21513. prevTime = currTime;
  21514. }
  21515. if (values !== undefined) {
  21516. if (AnimationUtils.isTypedArray(values)) {
  21517. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21518. var value = values[_i];
  21519. if (isNaN(value)) {
  21520. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21521. valid = false;
  21522. break;
  21523. }
  21524. }
  21525. }
  21526. }
  21527. return valid;
  21528. },
  21529. // removes equivalent sequential keys as common in morph target sequences
  21530. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21531. optimize: function optimize() {
  21532. // times or values may be shared with other tracks, so overwriting is unsafe
  21533. var times = AnimationUtils.arraySlice(this.times),
  21534. values = AnimationUtils.arraySlice(this.values),
  21535. stride = this.getValueSize(),
  21536. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21537. lastIndex = times.length - 1;
  21538. var writeIndex = 1;
  21539. for (var i = 1; i < lastIndex; ++i) {
  21540. var keep = false;
  21541. var time = times[i];
  21542. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21543. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21544. if (!smoothInterpolation) {
  21545. // remove unnecessary keyframes same as their neighbors
  21546. var offset = i * stride,
  21547. offsetP = offset - stride,
  21548. offsetN = offset + stride;
  21549. for (var j = 0; j !== stride; ++j) {
  21550. var value = values[offset + j];
  21551. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21552. keep = true;
  21553. break;
  21554. }
  21555. }
  21556. } else {
  21557. keep = true;
  21558. }
  21559. } // in-place compaction
  21560. if (keep) {
  21561. if (i !== writeIndex) {
  21562. times[writeIndex] = times[i];
  21563. var readOffset = i * stride,
  21564. writeOffset = writeIndex * stride;
  21565. for (var _j = 0; _j !== stride; ++_j) {
  21566. values[writeOffset + _j] = values[readOffset + _j];
  21567. }
  21568. }
  21569. ++writeIndex;
  21570. }
  21571. } // flush last keyframe (compaction looks ahead)
  21572. if (lastIndex > 0) {
  21573. times[writeIndex] = times[lastIndex];
  21574. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21575. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21576. }
  21577. ++writeIndex;
  21578. }
  21579. if (writeIndex !== times.length) {
  21580. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21581. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21582. } else {
  21583. this.times = times;
  21584. this.values = values;
  21585. }
  21586. return this;
  21587. },
  21588. clone: function clone() {
  21589. var times = AnimationUtils.arraySlice(this.times, 0);
  21590. var values = AnimationUtils.arraySlice(this.values, 0);
  21591. var TypedKeyframeTrack = this.constructor;
  21592. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21593. track.createInterpolant = this.createInterpolant;
  21594. return track;
  21595. }
  21596. });
  21597. /**
  21598. * A Track of Boolean keyframe values.
  21599. */
  21600. function BooleanKeyframeTrack(name, times, values) {
  21601. KeyframeTrack.call(this, name, times, values);
  21602. }
  21603. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21604. constructor: BooleanKeyframeTrack,
  21605. ValueTypeName: 'bool',
  21606. ValueBufferType: Array,
  21607. DefaultInterpolation: InterpolateDiscrete,
  21608. InterpolantFactoryMethodLinear: undefined,
  21609. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21610. // representation of a single value and a custom interpolant that
  21611. // computes "firstValue ^ isOdd( index )".
  21612. });
  21613. /**
  21614. * A Track of keyframe values that represent color.
  21615. */
  21616. function ColorKeyframeTrack(name, times, values, interpolation) {
  21617. KeyframeTrack.call(this, name, times, values, interpolation);
  21618. }
  21619. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21620. constructor: ColorKeyframeTrack,
  21621. ValueTypeName: 'color' // ValueBufferType is inherited
  21622. // DefaultInterpolation is inherited
  21623. // Note: Very basic implementation and nothing special yet.
  21624. // However, this is the place for color space parameterization.
  21625. });
  21626. /**
  21627. * A Track of numeric keyframe values.
  21628. */
  21629. function NumberKeyframeTrack(name, times, values, interpolation) {
  21630. KeyframeTrack.call(this, name, times, values, interpolation);
  21631. }
  21632. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21633. constructor: NumberKeyframeTrack,
  21634. ValueTypeName: 'number' // ValueBufferType is inherited
  21635. // DefaultInterpolation is inherited
  21636. });
  21637. /**
  21638. * Spherical linear unit quaternion interpolant.
  21639. */
  21640. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21641. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21642. }
  21643. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21644. constructor: QuaternionLinearInterpolant,
  21645. interpolate_: function interpolate_(i1, t0, t, t1) {
  21646. var result = this.resultBuffer,
  21647. values = this.sampleValues,
  21648. stride = this.valueSize,
  21649. alpha = (t - t0) / (t1 - t0);
  21650. var offset = i1 * stride;
  21651. for (var end = offset + stride; offset !== end; offset += 4) {
  21652. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21653. }
  21654. return result;
  21655. }
  21656. });
  21657. /**
  21658. * A Track of quaternion keyframe values.
  21659. */
  21660. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21661. KeyframeTrack.call(this, name, times, values, interpolation);
  21662. }
  21663. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21664. constructor: QuaternionKeyframeTrack,
  21665. ValueTypeName: 'quaternion',
  21666. // ValueBufferType is inherited
  21667. DefaultInterpolation: InterpolateLinear,
  21668. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21669. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21670. },
  21671. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21672. });
  21673. /**
  21674. * A Track that interpolates Strings
  21675. */
  21676. function StringKeyframeTrack(name, times, values, interpolation) {
  21677. KeyframeTrack.call(this, name, times, values, interpolation);
  21678. }
  21679. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21680. constructor: StringKeyframeTrack,
  21681. ValueTypeName: 'string',
  21682. ValueBufferType: Array,
  21683. DefaultInterpolation: InterpolateDiscrete,
  21684. InterpolantFactoryMethodLinear: undefined,
  21685. InterpolantFactoryMethodSmooth: undefined
  21686. });
  21687. /**
  21688. * A Track of vectored keyframe values.
  21689. */
  21690. function VectorKeyframeTrack(name, times, values, interpolation) {
  21691. KeyframeTrack.call(this, name, times, values, interpolation);
  21692. }
  21693. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21694. constructor: VectorKeyframeTrack,
  21695. ValueTypeName: 'vector' // ValueBufferType is inherited
  21696. // DefaultInterpolation is inherited
  21697. });
  21698. function AnimationClip(name, duration, tracks, blendMode) {
  21699. this.name = name;
  21700. this.tracks = tracks;
  21701. this.duration = duration !== undefined ? duration : -1;
  21702. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21703. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21704. if (this.duration < 0) {
  21705. this.resetDuration();
  21706. }
  21707. }
  21708. function getTrackTypeForValueTypeName(typeName) {
  21709. switch (typeName.toLowerCase()) {
  21710. case 'scalar':
  21711. case 'double':
  21712. case 'float':
  21713. case 'number':
  21714. case 'integer':
  21715. return NumberKeyframeTrack;
  21716. case 'vector':
  21717. case 'vector2':
  21718. case 'vector3':
  21719. case 'vector4':
  21720. return VectorKeyframeTrack;
  21721. case 'color':
  21722. return ColorKeyframeTrack;
  21723. case 'quaternion':
  21724. return QuaternionKeyframeTrack;
  21725. case 'bool':
  21726. case 'boolean':
  21727. return BooleanKeyframeTrack;
  21728. case 'string':
  21729. return StringKeyframeTrack;
  21730. }
  21731. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21732. }
  21733. function parseKeyframeTrack(json) {
  21734. if (json.type === undefined) {
  21735. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21736. }
  21737. var trackType = getTrackTypeForValueTypeName(json.type);
  21738. if (json.times === undefined) {
  21739. var times = [],
  21740. values = [];
  21741. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21742. json.times = times;
  21743. json.values = values;
  21744. } // derived classes can define a static parse method
  21745. if (trackType.parse !== undefined) {
  21746. return trackType.parse(json);
  21747. } else {
  21748. // by default, we assume a constructor compatible with the base
  21749. return new trackType(json.name, json.times, json.values, json.interpolation);
  21750. }
  21751. }
  21752. Object.assign(AnimationClip, {
  21753. parse: function parse(json) {
  21754. var tracks = [],
  21755. jsonTracks = json.tracks,
  21756. frameTime = 1.0 / (json.fps || 1.0);
  21757. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21758. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21759. }
  21760. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21761. clip.uuid = json.uuid;
  21762. return clip;
  21763. },
  21764. toJSON: function toJSON(clip) {
  21765. var tracks = [],
  21766. clipTracks = clip.tracks;
  21767. var json = {
  21768. 'name': clip.name,
  21769. 'duration': clip.duration,
  21770. 'tracks': tracks,
  21771. 'uuid': clip.uuid,
  21772. 'blendMode': clip.blendMode
  21773. };
  21774. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21775. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21776. }
  21777. return json;
  21778. },
  21779. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21780. var numMorphTargets = morphTargetSequence.length;
  21781. var tracks = [];
  21782. for (var i = 0; i < numMorphTargets; i++) {
  21783. var times = [];
  21784. var values = [];
  21785. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21786. values.push(0, 1, 0);
  21787. var order = AnimationUtils.getKeyframeOrder(times);
  21788. times = AnimationUtils.sortedArray(times, 1, order);
  21789. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21790. // last frame as well for perfect loop.
  21791. if (!noLoop && times[0] === 0) {
  21792. times.push(numMorphTargets);
  21793. values.push(values[0]);
  21794. }
  21795. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21796. }
  21797. return new AnimationClip(name, -1, tracks);
  21798. },
  21799. findByName: function findByName(objectOrClipArray, name) {
  21800. var clipArray = objectOrClipArray;
  21801. if (!Array.isArray(objectOrClipArray)) {
  21802. var o = objectOrClipArray;
  21803. clipArray = o.geometry && o.geometry.animations || o.animations;
  21804. }
  21805. for (var i = 0; i < clipArray.length; i++) {
  21806. if (clipArray[i].name === name) {
  21807. return clipArray[i];
  21808. }
  21809. }
  21810. return null;
  21811. },
  21812. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21813. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21814. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21815. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21816. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21817. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21818. var morphTarget = morphTargets[i];
  21819. var parts = morphTarget.name.match(pattern);
  21820. if (parts && parts.length > 1) {
  21821. var name = parts[1];
  21822. var animationMorphTargets = animationToMorphTargets[name];
  21823. if (!animationMorphTargets) {
  21824. animationToMorphTargets[name] = animationMorphTargets = [];
  21825. }
  21826. animationMorphTargets.push(morphTarget);
  21827. }
  21828. }
  21829. var clips = [];
  21830. for (var _name in animationToMorphTargets) {
  21831. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21832. }
  21833. return clips;
  21834. },
  21835. // parse the animation.hierarchy format
  21836. parseAnimation: function parseAnimation(animation, bones) {
  21837. if (!animation) {
  21838. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21839. return null;
  21840. }
  21841. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21842. // only return track if there are actually keys.
  21843. if (animationKeys.length !== 0) {
  21844. var times = [];
  21845. var values = [];
  21846. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21847. if (times.length !== 0) {
  21848. destTracks.push(new trackType(trackName, times, values));
  21849. }
  21850. }
  21851. };
  21852. var tracks = [];
  21853. var clipName = animation.name || 'default';
  21854. var fps = animation.fps || 30;
  21855. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21856. var duration = animation.length || -1;
  21857. var hierarchyTracks = animation.hierarchy || [];
  21858. for (var h = 0; h < hierarchyTracks.length; h++) {
  21859. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21860. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21861. if (animationKeys[0].morphTargets) {
  21862. // figure out all morph targets used in this track
  21863. var morphTargetNames = {};
  21864. var k = void 0;
  21865. for (k = 0; k < animationKeys.length; k++) {
  21866. if (animationKeys[k].morphTargets) {
  21867. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21868. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21869. }
  21870. }
  21871. } // create a track for each morph target with all zero
  21872. // morphTargetInfluences except for the keys in which
  21873. // the morphTarget is named.
  21874. for (var morphTargetName in morphTargetNames) {
  21875. var times = [];
  21876. var values = [];
  21877. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21878. var animationKey = animationKeys[k];
  21879. times.push(animationKey.time);
  21880. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21881. }
  21882. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21883. }
  21884. duration = morphTargetNames.length * (fps || 1.0);
  21885. } else {
  21886. // ...assume skeletal animation
  21887. var boneName = '.bones[' + bones[h].name + ']';
  21888. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21889. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21890. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21891. }
  21892. }
  21893. if (tracks.length === 0) {
  21894. return null;
  21895. }
  21896. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21897. return clip;
  21898. }
  21899. });
  21900. Object.assign(AnimationClip.prototype, {
  21901. resetDuration: function resetDuration() {
  21902. var tracks = this.tracks;
  21903. var duration = 0;
  21904. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21905. var track = this.tracks[i];
  21906. duration = Math.max(duration, track.times[track.times.length - 1]);
  21907. }
  21908. this.duration = duration;
  21909. return this;
  21910. },
  21911. trim: function trim() {
  21912. for (var i = 0; i < this.tracks.length; i++) {
  21913. this.tracks[i].trim(0, this.duration);
  21914. }
  21915. return this;
  21916. },
  21917. validate: function validate() {
  21918. var valid = true;
  21919. for (var i = 0; i < this.tracks.length; i++) {
  21920. valid = valid && this.tracks[i].validate();
  21921. }
  21922. return valid;
  21923. },
  21924. optimize: function optimize() {
  21925. for (var i = 0; i < this.tracks.length; i++) {
  21926. this.tracks[i].optimize();
  21927. }
  21928. return this;
  21929. },
  21930. clone: function clone() {
  21931. var tracks = [];
  21932. for (var i = 0; i < this.tracks.length; i++) {
  21933. tracks.push(this.tracks[i].clone());
  21934. }
  21935. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21936. },
  21937. toJSON: function toJSON() {
  21938. return AnimationClip.toJSON(this);
  21939. }
  21940. });
  21941. var Cache = {
  21942. enabled: false,
  21943. files: {},
  21944. add: function add(key, file) {
  21945. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21946. this.files[key] = file;
  21947. },
  21948. get: function get(key) {
  21949. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21950. return this.files[key];
  21951. },
  21952. remove: function remove(key) {
  21953. delete this.files[key];
  21954. },
  21955. clear: function clear() {
  21956. this.files = {};
  21957. }
  21958. };
  21959. function LoadingManager(onLoad, onProgress, onError) {
  21960. var scope = this;
  21961. var isLoading = false;
  21962. var itemsLoaded = 0;
  21963. var itemsTotal = 0;
  21964. var urlModifier = undefined;
  21965. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21966. // in the constructor
  21967. this.onStart = undefined;
  21968. this.onLoad = onLoad;
  21969. this.onProgress = onProgress;
  21970. this.onError = onError;
  21971. this.itemStart = function (url) {
  21972. itemsTotal++;
  21973. if (isLoading === false) {
  21974. if (scope.onStart !== undefined) {
  21975. scope.onStart(url, itemsLoaded, itemsTotal);
  21976. }
  21977. }
  21978. isLoading = true;
  21979. };
  21980. this.itemEnd = function (url) {
  21981. itemsLoaded++;
  21982. if (scope.onProgress !== undefined) {
  21983. scope.onProgress(url, itemsLoaded, itemsTotal);
  21984. }
  21985. if (itemsLoaded === itemsTotal) {
  21986. isLoading = false;
  21987. if (scope.onLoad !== undefined) {
  21988. scope.onLoad();
  21989. }
  21990. }
  21991. };
  21992. this.itemError = function (url) {
  21993. if (scope.onError !== undefined) {
  21994. scope.onError(url);
  21995. }
  21996. };
  21997. this.resolveURL = function (url) {
  21998. if (urlModifier) {
  21999. return urlModifier(url);
  22000. }
  22001. return url;
  22002. };
  22003. this.setURLModifier = function (transform) {
  22004. urlModifier = transform;
  22005. return this;
  22006. };
  22007. this.addHandler = function (regex, loader) {
  22008. handlers.push(regex, loader);
  22009. return this;
  22010. };
  22011. this.removeHandler = function (regex) {
  22012. var index = handlers.indexOf(regex);
  22013. if (index !== -1) {
  22014. handlers.splice(index, 2);
  22015. }
  22016. return this;
  22017. };
  22018. this.getHandler = function (file) {
  22019. for (var i = 0, l = handlers.length; i < l; i += 2) {
  22020. var regex = handlers[i];
  22021. var loader = handlers[i + 1];
  22022. if (regex.global) regex.lastIndex = 0; // see #17920
  22023. if (regex.test(file)) {
  22024. return loader;
  22025. }
  22026. }
  22027. return null;
  22028. };
  22029. }
  22030. var DefaultLoadingManager = new LoadingManager();
  22031. function Loader(manager) {
  22032. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22033. this.crossOrigin = 'anonymous';
  22034. this.withCredentials = false;
  22035. this.path = '';
  22036. this.resourcePath = '';
  22037. this.requestHeader = {};
  22038. }
  22039. Object.assign(Loader.prototype, {
  22040. load: function load()
  22041. /* url, onLoad, onProgress, onError */
  22042. {},
  22043. loadAsync: function loadAsync(url, onProgress) {
  22044. var scope = this;
  22045. return new Promise(function (resolve, reject) {
  22046. scope.load(url, resolve, onProgress, reject);
  22047. });
  22048. },
  22049. parse: function parse()
  22050. /* data */
  22051. {},
  22052. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  22053. this.crossOrigin = crossOrigin;
  22054. return this;
  22055. },
  22056. setWithCredentials: function setWithCredentials(value) {
  22057. this.withCredentials = value;
  22058. return this;
  22059. },
  22060. setPath: function setPath(path) {
  22061. this.path = path;
  22062. return this;
  22063. },
  22064. setResourcePath: function setResourcePath(resourcePath) {
  22065. this.resourcePath = resourcePath;
  22066. return this;
  22067. },
  22068. setRequestHeader: function setRequestHeader(requestHeader) {
  22069. this.requestHeader = requestHeader;
  22070. return this;
  22071. }
  22072. });
  22073. var loading = {};
  22074. function FileLoader(manager) {
  22075. Loader.call(this, manager);
  22076. }
  22077. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22078. constructor: FileLoader,
  22079. load: function load(url, onLoad, onProgress, onError) {
  22080. if (url === undefined) url = '';
  22081. if (this.path !== undefined) url = this.path + url;
  22082. url = this.manager.resolveURL(url);
  22083. var scope = this;
  22084. var cached = Cache.get(url);
  22085. if (cached !== undefined) {
  22086. scope.manager.itemStart(url);
  22087. setTimeout(function () {
  22088. if (onLoad) onLoad(cached);
  22089. scope.manager.itemEnd(url);
  22090. }, 0);
  22091. return cached;
  22092. } // Check if request is duplicate
  22093. if (loading[url] !== undefined) {
  22094. loading[url].push({
  22095. onLoad: onLoad,
  22096. onProgress: onProgress,
  22097. onError: onError
  22098. });
  22099. return;
  22100. } // Check for data: URI
  22101. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  22102. var dataUriRegexResult = url.match(dataUriRegex);
  22103. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  22104. if (dataUriRegexResult) {
  22105. var mimeType = dataUriRegexResult[1];
  22106. var isBase64 = !!dataUriRegexResult[2];
  22107. var data = dataUriRegexResult[3];
  22108. data = decodeURIComponent(data);
  22109. if (isBase64) data = atob(data);
  22110. try {
  22111. var response;
  22112. var responseType = (this.responseType || '').toLowerCase();
  22113. switch (responseType) {
  22114. case 'arraybuffer':
  22115. case 'blob':
  22116. var view = new Uint8Array(data.length);
  22117. for (var i = 0; i < data.length; i++) {
  22118. view[i] = data.charCodeAt(i);
  22119. }
  22120. if (responseType === 'blob') {
  22121. response = new Blob([view.buffer], {
  22122. type: mimeType
  22123. });
  22124. } else {
  22125. response = view.buffer;
  22126. }
  22127. break;
  22128. case 'document':
  22129. var parser = new DOMParser();
  22130. response = parser.parseFromString(data, mimeType);
  22131. break;
  22132. case 'json':
  22133. response = JSON.parse(data);
  22134. break;
  22135. default:
  22136. // 'text' or other
  22137. response = data;
  22138. break;
  22139. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22140. setTimeout(function () {
  22141. if (onLoad) onLoad(response);
  22142. scope.manager.itemEnd(url);
  22143. }, 0);
  22144. } catch (error) {
  22145. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22146. setTimeout(function () {
  22147. if (onError) onError(error);
  22148. scope.manager.itemError(url);
  22149. scope.manager.itemEnd(url);
  22150. }, 0);
  22151. }
  22152. } else {
  22153. // Initialise array for duplicate requests
  22154. loading[url] = [];
  22155. loading[url].push({
  22156. onLoad: onLoad,
  22157. onProgress: onProgress,
  22158. onError: onError
  22159. });
  22160. request = new XMLHttpRequest();
  22161. request.open('GET', url, true);
  22162. request.addEventListener('load', function (event) {
  22163. var response = this.response;
  22164. var callbacks = loading[url];
  22165. delete loading[url];
  22166. if (this.status === 200 || this.status === 0) {
  22167. // Some browsers return HTTP Status 0 when using non-http protocol
  22168. // e.g. 'file://' or 'data://'. Handle as success.
  22169. 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
  22170. // error response bodies as proper responses to requests.
  22171. Cache.add(url, response);
  22172. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  22173. var callback = callbacks[_i];
  22174. if (callback.onLoad) callback.onLoad(response);
  22175. }
  22176. scope.manager.itemEnd(url);
  22177. } else {
  22178. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  22179. var _callback = callbacks[_i2];
  22180. if (_callback.onError) _callback.onError(event);
  22181. }
  22182. scope.manager.itemError(url);
  22183. scope.manager.itemEnd(url);
  22184. }
  22185. }, false);
  22186. request.addEventListener('progress', function (event) {
  22187. var callbacks = loading[url];
  22188. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  22189. var callback = callbacks[_i3];
  22190. if (callback.onProgress) callback.onProgress(event);
  22191. }
  22192. }, false);
  22193. request.addEventListener('error', function (event) {
  22194. var callbacks = loading[url];
  22195. delete loading[url];
  22196. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  22197. var callback = callbacks[_i4];
  22198. if (callback.onError) callback.onError(event);
  22199. }
  22200. scope.manager.itemError(url);
  22201. scope.manager.itemEnd(url);
  22202. }, false);
  22203. request.addEventListener('abort', function (event) {
  22204. var callbacks = loading[url];
  22205. delete loading[url];
  22206. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  22207. var callback = callbacks[_i5];
  22208. if (callback.onError) callback.onError(event);
  22209. }
  22210. scope.manager.itemError(url);
  22211. scope.manager.itemEnd(url);
  22212. }, false);
  22213. if (this.responseType !== undefined) request.responseType = this.responseType;
  22214. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  22215. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  22216. for (var header in this.requestHeader) {
  22217. request.setRequestHeader(header, this.requestHeader[header]);
  22218. }
  22219. request.send(null);
  22220. }
  22221. scope.manager.itemStart(url);
  22222. return request;
  22223. },
  22224. setResponseType: function setResponseType(value) {
  22225. this.responseType = value;
  22226. return this;
  22227. },
  22228. setMimeType: function setMimeType(value) {
  22229. this.mimeType = value;
  22230. return this;
  22231. }
  22232. });
  22233. function AnimationLoader(manager) {
  22234. Loader.call(this, manager);
  22235. }
  22236. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22237. constructor: AnimationLoader,
  22238. load: function load(url, onLoad, onProgress, onError) {
  22239. var scope = this;
  22240. var loader = new FileLoader(scope.manager);
  22241. loader.setPath(scope.path);
  22242. loader.setRequestHeader(scope.requestHeader);
  22243. loader.setWithCredentials(scope.withCredentials);
  22244. loader.load(url, function (text) {
  22245. try {
  22246. onLoad(scope.parse(JSON.parse(text)));
  22247. } catch (e) {
  22248. if (onError) {
  22249. onError(e);
  22250. } else {
  22251. console.error(e);
  22252. }
  22253. scope.manager.itemError(url);
  22254. }
  22255. }, onProgress, onError);
  22256. },
  22257. parse: function parse(json) {
  22258. var animations = [];
  22259. for (var i = 0; i < json.length; i++) {
  22260. var clip = AnimationClip.parse(json[i]);
  22261. animations.push(clip);
  22262. }
  22263. return animations;
  22264. }
  22265. });
  22266. /**
  22267. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22268. *
  22269. * Sub classes have to implement the parse() method which will be used in load().
  22270. */
  22271. function CompressedTextureLoader(manager) {
  22272. Loader.call(this, manager);
  22273. }
  22274. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22275. constructor: CompressedTextureLoader,
  22276. load: function load(url, onLoad, onProgress, onError) {
  22277. var scope = this;
  22278. var images = [];
  22279. var texture = new CompressedTexture();
  22280. texture.image = images;
  22281. var loader = new FileLoader(this.manager);
  22282. loader.setPath(this.path);
  22283. loader.setResponseType('arraybuffer');
  22284. loader.setRequestHeader(this.requestHeader);
  22285. loader.setWithCredentials(scope.withCredentials);
  22286. var loaded = 0;
  22287. function loadTexture(i) {
  22288. loader.load(url[i], function (buffer) {
  22289. var texDatas = scope.parse(buffer, true);
  22290. images[i] = {
  22291. width: texDatas.width,
  22292. height: texDatas.height,
  22293. format: texDatas.format,
  22294. mipmaps: texDatas.mipmaps
  22295. };
  22296. loaded += 1;
  22297. if (loaded === 6) {
  22298. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  22299. texture.format = texDatas.format;
  22300. texture.needsUpdate = true;
  22301. if (onLoad) onLoad(texture);
  22302. }
  22303. }, onProgress, onError);
  22304. }
  22305. if (Array.isArray(url)) {
  22306. for (var i = 0, il = url.length; i < il; ++i) {
  22307. loadTexture(i);
  22308. }
  22309. } else {
  22310. // compressed cubemap texture stored in a single DDS file
  22311. loader.load(url, function (buffer) {
  22312. var texDatas = scope.parse(buffer, true);
  22313. if (texDatas.isCubemap) {
  22314. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22315. for (var f = 0; f < faces; f++) {
  22316. images[f] = {
  22317. mipmaps: []
  22318. };
  22319. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  22320. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  22321. images[f].format = texDatas.format;
  22322. images[f].width = texDatas.width;
  22323. images[f].height = texDatas.height;
  22324. }
  22325. }
  22326. } else {
  22327. texture.image.width = texDatas.width;
  22328. texture.image.height = texDatas.height;
  22329. texture.mipmaps = texDatas.mipmaps;
  22330. }
  22331. if (texDatas.mipmapCount === 1) {
  22332. texture.minFilter = LinearFilter;
  22333. }
  22334. texture.format = texDatas.format;
  22335. texture.needsUpdate = true;
  22336. if (onLoad) onLoad(texture);
  22337. }, onProgress, onError);
  22338. }
  22339. return texture;
  22340. }
  22341. });
  22342. function ImageLoader(manager) {
  22343. Loader.call(this, manager);
  22344. }
  22345. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22346. constructor: ImageLoader,
  22347. load: function load(url, onLoad, onProgress, onError) {
  22348. if (this.path !== undefined) url = this.path + url;
  22349. url = this.manager.resolveURL(url);
  22350. var scope = this;
  22351. var cached = Cache.get(url);
  22352. if (cached !== undefined) {
  22353. scope.manager.itemStart(url);
  22354. setTimeout(function () {
  22355. if (onLoad) onLoad(cached);
  22356. scope.manager.itemEnd(url);
  22357. }, 0);
  22358. return cached;
  22359. }
  22360. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  22361. function onImageLoad() {
  22362. image.removeEventListener('load', onImageLoad, false);
  22363. image.removeEventListener('error', onImageError, false);
  22364. Cache.add(url, this);
  22365. if (onLoad) onLoad(this);
  22366. scope.manager.itemEnd(url);
  22367. }
  22368. function onImageError(event) {
  22369. image.removeEventListener('load', onImageLoad, false);
  22370. image.removeEventListener('error', onImageError, false);
  22371. if (onError) onError(event);
  22372. scope.manager.itemError(url);
  22373. scope.manager.itemEnd(url);
  22374. }
  22375. image.addEventListener('load', onImageLoad, false);
  22376. image.addEventListener('error', onImageError, false);
  22377. if (url.substr(0, 5) !== 'data:') {
  22378. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  22379. }
  22380. scope.manager.itemStart(url);
  22381. image.src = url;
  22382. return image;
  22383. }
  22384. });
  22385. function CubeTextureLoader(manager) {
  22386. Loader.call(this, manager);
  22387. }
  22388. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22389. constructor: CubeTextureLoader,
  22390. load: function load(urls, onLoad, onProgress, onError) {
  22391. var texture = new CubeTexture();
  22392. var loader = new ImageLoader(this.manager);
  22393. loader.setCrossOrigin(this.crossOrigin);
  22394. loader.setPath(this.path);
  22395. var loaded = 0;
  22396. function loadTexture(i) {
  22397. loader.load(urls[i], function (image) {
  22398. texture.images[i] = image;
  22399. loaded++;
  22400. if (loaded === 6) {
  22401. texture.needsUpdate = true;
  22402. if (onLoad) onLoad(texture);
  22403. }
  22404. }, undefined, onError);
  22405. }
  22406. for (var i = 0; i < urls.length; ++i) {
  22407. loadTexture(i);
  22408. }
  22409. return texture;
  22410. }
  22411. });
  22412. /**
  22413. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22414. *
  22415. * Sub classes have to implement the parse() method which will be used in load().
  22416. */
  22417. function DataTextureLoader(manager) {
  22418. Loader.call(this, manager);
  22419. }
  22420. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22421. constructor: DataTextureLoader,
  22422. load: function load(url, onLoad, onProgress, onError) {
  22423. var scope = this;
  22424. var texture = new DataTexture();
  22425. var loader = new FileLoader(this.manager);
  22426. loader.setResponseType('arraybuffer');
  22427. loader.setRequestHeader(this.requestHeader);
  22428. loader.setPath(this.path);
  22429. loader.setWithCredentials(scope.withCredentials);
  22430. loader.load(url, function (buffer) {
  22431. var texData = scope.parse(buffer);
  22432. if (!texData) return;
  22433. if (texData.image !== undefined) {
  22434. texture.image = texData.image;
  22435. } else if (texData.data !== undefined) {
  22436. texture.image.width = texData.width;
  22437. texture.image.height = texData.height;
  22438. texture.image.data = texData.data;
  22439. }
  22440. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22441. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22442. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22443. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22444. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22445. if (texData.format !== undefined) {
  22446. texture.format = texData.format;
  22447. }
  22448. if (texData.type !== undefined) {
  22449. texture.type = texData.type;
  22450. }
  22451. if (texData.mipmaps !== undefined) {
  22452. texture.mipmaps = texData.mipmaps;
  22453. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22454. }
  22455. if (texData.mipmapCount === 1) {
  22456. texture.minFilter = LinearFilter;
  22457. }
  22458. texture.needsUpdate = true;
  22459. if (onLoad) onLoad(texture, texData);
  22460. }, onProgress, onError);
  22461. return texture;
  22462. }
  22463. });
  22464. function TextureLoader(manager) {
  22465. Loader.call(this, manager);
  22466. }
  22467. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22468. constructor: TextureLoader,
  22469. load: function load(url, onLoad, onProgress, onError) {
  22470. var texture = new Texture();
  22471. var loader = new ImageLoader(this.manager);
  22472. loader.setCrossOrigin(this.crossOrigin);
  22473. loader.setPath(this.path);
  22474. loader.load(url, function (image) {
  22475. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22476. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22477. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22478. texture.needsUpdate = true;
  22479. if (onLoad !== undefined) {
  22480. onLoad(texture);
  22481. }
  22482. }, onProgress, onError);
  22483. return texture;
  22484. }
  22485. });
  22486. /**
  22487. * Extensible curve object.
  22488. *
  22489. * Some common of curve methods:
  22490. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22491. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22492. * .getPoints(), .getSpacedPoints()
  22493. * .getLength()
  22494. * .updateArcLengths()
  22495. *
  22496. * This following curves inherit from THREE.Curve:
  22497. *
  22498. * -- 2D curves --
  22499. * THREE.ArcCurve
  22500. * THREE.CubicBezierCurve
  22501. * THREE.EllipseCurve
  22502. * THREE.LineCurve
  22503. * THREE.QuadraticBezierCurve
  22504. * THREE.SplineCurve
  22505. *
  22506. * -- 3D curves --
  22507. * THREE.CatmullRomCurve3
  22508. * THREE.CubicBezierCurve3
  22509. * THREE.LineCurve3
  22510. * THREE.QuadraticBezierCurve3
  22511. *
  22512. * A series of curves can be represented as a THREE.CurvePath.
  22513. *
  22514. **/
  22515. function Curve() {
  22516. this.type = 'Curve';
  22517. this.arcLengthDivisions = 200;
  22518. }
  22519. Object.assign(Curve.prototype, {
  22520. // Virtual base class method to overwrite and implement in subclasses
  22521. // - t [0 .. 1]
  22522. getPoint: function getPoint()
  22523. /* t, optionalTarget */
  22524. {
  22525. console.warn('THREE.Curve: .getPoint() not implemented.');
  22526. return null;
  22527. },
  22528. // Get point at relative position in curve according to arc length
  22529. // - u [0 .. 1]
  22530. getPointAt: function getPointAt(u, optionalTarget) {
  22531. var t = this.getUtoTmapping(u);
  22532. return this.getPoint(t, optionalTarget);
  22533. },
  22534. // Get sequence of points using getPoint( t )
  22535. getPoints: function getPoints(divisions) {
  22536. if (divisions === void 0) {
  22537. divisions = 5;
  22538. }
  22539. var points = [];
  22540. for (var d = 0; d <= divisions; d++) {
  22541. points.push(this.getPoint(d / divisions));
  22542. }
  22543. return points;
  22544. },
  22545. // Get sequence of points using getPointAt( u )
  22546. getSpacedPoints: function getSpacedPoints(divisions) {
  22547. if (divisions === void 0) {
  22548. divisions = 5;
  22549. }
  22550. var points = [];
  22551. for (var d = 0; d <= divisions; d++) {
  22552. points.push(this.getPointAt(d / divisions));
  22553. }
  22554. return points;
  22555. },
  22556. // Get total curve arc length
  22557. getLength: function getLength() {
  22558. var lengths = this.getLengths();
  22559. return lengths[lengths.length - 1];
  22560. },
  22561. // Get list of cumulative segment lengths
  22562. getLengths: function getLengths(divisions) {
  22563. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22564. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22565. return this.cacheArcLengths;
  22566. }
  22567. this.needsUpdate = false;
  22568. var cache = [];
  22569. var current,
  22570. last = this.getPoint(0);
  22571. var sum = 0;
  22572. cache.push(0);
  22573. for (var p = 1; p <= divisions; p++) {
  22574. current = this.getPoint(p / divisions);
  22575. sum += current.distanceTo(last);
  22576. cache.push(sum);
  22577. last = current;
  22578. }
  22579. this.cacheArcLengths = cache;
  22580. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22581. },
  22582. updateArcLengths: function updateArcLengths() {
  22583. this.needsUpdate = true;
  22584. this.getLengths();
  22585. },
  22586. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22587. getUtoTmapping: function getUtoTmapping(u, distance) {
  22588. var arcLengths = this.getLengths();
  22589. var i = 0;
  22590. var il = arcLengths.length;
  22591. var targetArcLength; // The targeted u distance value to get
  22592. if (distance) {
  22593. targetArcLength = distance;
  22594. } else {
  22595. targetArcLength = u * arcLengths[il - 1];
  22596. } // binary search for the index with largest value smaller than target u distance
  22597. var low = 0,
  22598. high = il - 1,
  22599. comparison;
  22600. while (low <= high) {
  22601. 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
  22602. comparison = arcLengths[i] - targetArcLength;
  22603. if (comparison < 0) {
  22604. low = i + 1;
  22605. } else if (comparison > 0) {
  22606. high = i - 1;
  22607. } else {
  22608. high = i;
  22609. break; // DONE
  22610. }
  22611. }
  22612. i = high;
  22613. if (arcLengths[i] === targetArcLength) {
  22614. return i / (il - 1);
  22615. } // we could get finer grain at lengths, or use simple interpolation between two points
  22616. var lengthBefore = arcLengths[i];
  22617. var lengthAfter = arcLengths[i + 1];
  22618. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22619. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22620. var t = (i + segmentFraction) / (il - 1);
  22621. return t;
  22622. },
  22623. // Returns a unit vector tangent at t
  22624. // In case any sub curve does not implement its tangent derivation,
  22625. // 2 points a small delta apart will be used to find its gradient
  22626. // which seems to give a reasonable approximation
  22627. getTangent: function getTangent(t, optionalTarget) {
  22628. var delta = 0.0001;
  22629. var t1 = t - delta;
  22630. var t2 = t + delta; // Capping in case of danger
  22631. if (t1 < 0) t1 = 0;
  22632. if (t2 > 1) t2 = 1;
  22633. var pt1 = this.getPoint(t1);
  22634. var pt2 = this.getPoint(t2);
  22635. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22636. tangent.copy(pt2).sub(pt1).normalize();
  22637. return tangent;
  22638. },
  22639. getTangentAt: function getTangentAt(u, optionalTarget) {
  22640. var t = this.getUtoTmapping(u);
  22641. return this.getTangent(t, optionalTarget);
  22642. },
  22643. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22644. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22645. var normal = new Vector3();
  22646. var tangents = [];
  22647. var normals = [];
  22648. var binormals = [];
  22649. var vec = new Vector3();
  22650. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22651. for (var i = 0; i <= segments; i++) {
  22652. var u = i / segments;
  22653. tangents[i] = this.getTangentAt(u, new Vector3());
  22654. tangents[i].normalize();
  22655. } // select an initial normal vector perpendicular to the first tangent vector,
  22656. // and in the direction of the minimum tangent xyz component
  22657. normals[0] = new Vector3();
  22658. binormals[0] = new Vector3();
  22659. var min = Number.MAX_VALUE;
  22660. var tx = Math.abs(tangents[0].x);
  22661. var ty = Math.abs(tangents[0].y);
  22662. var tz = Math.abs(tangents[0].z);
  22663. if (tx <= min) {
  22664. min = tx;
  22665. normal.set(1, 0, 0);
  22666. }
  22667. if (ty <= min) {
  22668. min = ty;
  22669. normal.set(0, 1, 0);
  22670. }
  22671. if (tz <= min) {
  22672. normal.set(0, 0, 1);
  22673. }
  22674. vec.crossVectors(tangents[0], normal).normalize();
  22675. normals[0].crossVectors(tangents[0], vec);
  22676. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22677. for (var _i = 1; _i <= segments; _i++) {
  22678. normals[_i] = normals[_i - 1].clone();
  22679. binormals[_i] = binormals[_i - 1].clone();
  22680. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22681. if (vec.length() > Number.EPSILON) {
  22682. vec.normalize();
  22683. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22684. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22685. }
  22686. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22687. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22688. if (closed === true) {
  22689. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22690. _theta /= segments;
  22691. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22692. _theta = -_theta;
  22693. }
  22694. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22695. // twist a little...
  22696. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22697. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22698. }
  22699. }
  22700. return {
  22701. tangents: tangents,
  22702. normals: normals,
  22703. binormals: binormals
  22704. };
  22705. },
  22706. clone: function clone() {
  22707. return new this.constructor().copy(this);
  22708. },
  22709. copy: function copy(source) {
  22710. this.arcLengthDivisions = source.arcLengthDivisions;
  22711. return this;
  22712. },
  22713. toJSON: function toJSON() {
  22714. var data = {
  22715. metadata: {
  22716. version: 4.5,
  22717. type: 'Curve',
  22718. generator: 'Curve.toJSON'
  22719. }
  22720. };
  22721. data.arcLengthDivisions = this.arcLengthDivisions;
  22722. data.type = this.type;
  22723. return data;
  22724. },
  22725. fromJSON: function fromJSON(json) {
  22726. this.arcLengthDivisions = json.arcLengthDivisions;
  22727. return this;
  22728. }
  22729. });
  22730. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22731. Curve.call(this);
  22732. this.type = 'EllipseCurve';
  22733. this.aX = aX || 0;
  22734. this.aY = aY || 0;
  22735. this.xRadius = xRadius || 1;
  22736. this.yRadius = yRadius || 1;
  22737. this.aStartAngle = aStartAngle || 0;
  22738. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22739. this.aClockwise = aClockwise || false;
  22740. this.aRotation = aRotation || 0;
  22741. }
  22742. EllipseCurve.prototype = Object.create(Curve.prototype);
  22743. EllipseCurve.prototype.constructor = EllipseCurve;
  22744. EllipseCurve.prototype.isEllipseCurve = true;
  22745. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22746. var point = optionalTarget || new Vector2();
  22747. var twoPi = Math.PI * 2;
  22748. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22749. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22750. while (deltaAngle < 0) {
  22751. deltaAngle += twoPi;
  22752. }
  22753. while (deltaAngle > twoPi) {
  22754. deltaAngle -= twoPi;
  22755. }
  22756. if (deltaAngle < Number.EPSILON) {
  22757. if (samePoints) {
  22758. deltaAngle = 0;
  22759. } else {
  22760. deltaAngle = twoPi;
  22761. }
  22762. }
  22763. if (this.aClockwise === true && !samePoints) {
  22764. if (deltaAngle === twoPi) {
  22765. deltaAngle = -twoPi;
  22766. } else {
  22767. deltaAngle = deltaAngle - twoPi;
  22768. }
  22769. }
  22770. var angle = this.aStartAngle + t * deltaAngle;
  22771. var x = this.aX + this.xRadius * Math.cos(angle);
  22772. var y = this.aY + this.yRadius * Math.sin(angle);
  22773. if (this.aRotation !== 0) {
  22774. var cos = Math.cos(this.aRotation);
  22775. var sin = Math.sin(this.aRotation);
  22776. var tx = x - this.aX;
  22777. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22778. x = tx * cos - ty * sin + this.aX;
  22779. y = tx * sin + ty * cos + this.aY;
  22780. }
  22781. return point.set(x, y);
  22782. };
  22783. EllipseCurve.prototype.copy = function (source) {
  22784. Curve.prototype.copy.call(this, source);
  22785. this.aX = source.aX;
  22786. this.aY = source.aY;
  22787. this.xRadius = source.xRadius;
  22788. this.yRadius = source.yRadius;
  22789. this.aStartAngle = source.aStartAngle;
  22790. this.aEndAngle = source.aEndAngle;
  22791. this.aClockwise = source.aClockwise;
  22792. this.aRotation = source.aRotation;
  22793. return this;
  22794. };
  22795. EllipseCurve.prototype.toJSON = function () {
  22796. var data = Curve.prototype.toJSON.call(this);
  22797. data.aX = this.aX;
  22798. data.aY = this.aY;
  22799. data.xRadius = this.xRadius;
  22800. data.yRadius = this.yRadius;
  22801. data.aStartAngle = this.aStartAngle;
  22802. data.aEndAngle = this.aEndAngle;
  22803. data.aClockwise = this.aClockwise;
  22804. data.aRotation = this.aRotation;
  22805. return data;
  22806. };
  22807. EllipseCurve.prototype.fromJSON = function (json) {
  22808. Curve.prototype.fromJSON.call(this, json);
  22809. this.aX = json.aX;
  22810. this.aY = json.aY;
  22811. this.xRadius = json.xRadius;
  22812. this.yRadius = json.yRadius;
  22813. this.aStartAngle = json.aStartAngle;
  22814. this.aEndAngle = json.aEndAngle;
  22815. this.aClockwise = json.aClockwise;
  22816. this.aRotation = json.aRotation;
  22817. return this;
  22818. };
  22819. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22820. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22821. this.type = 'ArcCurve';
  22822. }
  22823. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22824. ArcCurve.prototype.constructor = ArcCurve;
  22825. ArcCurve.prototype.isArcCurve = true;
  22826. /**
  22827. * Centripetal CatmullRom Curve - which is useful for avoiding
  22828. * cusps and self-intersections in non-uniform catmull rom curves.
  22829. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22830. *
  22831. * curve.type accepts centripetal(default), chordal and catmullrom
  22832. * curve.tension is used for catmullrom which defaults to 0.5
  22833. */
  22834. /*
  22835. Based on an optimized c++ solution in
  22836. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22837. - http://ideone.com/NoEbVM
  22838. This CubicPoly class could be used for reusing some variables and calculations,
  22839. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22840. which can be placed in CurveUtils.
  22841. */
  22842. function CubicPoly() {
  22843. var c0 = 0,
  22844. c1 = 0,
  22845. c2 = 0,
  22846. c3 = 0;
  22847. /*
  22848. * Compute coefficients for a cubic polynomial
  22849. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22850. * such that
  22851. * p(0) = x0, p(1) = x1
  22852. * and
  22853. * p'(0) = t0, p'(1) = t1.
  22854. */
  22855. function init(x0, x1, t0, t1) {
  22856. c0 = x0;
  22857. c1 = t0;
  22858. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22859. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22860. }
  22861. return {
  22862. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22863. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22864. },
  22865. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22866. // compute tangents when parameterized in [t1,t2]
  22867. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22868. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22869. t1 *= dt1;
  22870. t2 *= dt1;
  22871. init(x1, x2, t1, t2);
  22872. },
  22873. calc: function calc(t) {
  22874. var t2 = t * t;
  22875. var t3 = t2 * t;
  22876. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22877. }
  22878. };
  22879. } //
  22880. var tmp = new Vector3();
  22881. var px = new CubicPoly(),
  22882. py = new CubicPoly(),
  22883. pz = new CubicPoly();
  22884. function CatmullRomCurve3(points, closed, curveType, tension) {
  22885. if (points === void 0) {
  22886. points = [];
  22887. }
  22888. if (closed === void 0) {
  22889. closed = false;
  22890. }
  22891. if (curveType === void 0) {
  22892. curveType = 'centripetal';
  22893. }
  22894. if (tension === void 0) {
  22895. tension = 0.5;
  22896. }
  22897. Curve.call(this);
  22898. this.type = 'CatmullRomCurve3';
  22899. this.points = points;
  22900. this.closed = closed;
  22901. this.curveType = curveType;
  22902. this.tension = tension;
  22903. }
  22904. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22905. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22906. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22907. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22908. if (optionalTarget === void 0) {
  22909. optionalTarget = new Vector3();
  22910. }
  22911. var point = optionalTarget;
  22912. var points = this.points;
  22913. var l = points.length;
  22914. var p = (l - (this.closed ? 0 : 1)) * t;
  22915. var intPoint = Math.floor(p);
  22916. var weight = p - intPoint;
  22917. if (this.closed) {
  22918. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22919. } else if (weight === 0 && intPoint === l - 1) {
  22920. intPoint = l - 2;
  22921. weight = 1;
  22922. }
  22923. var p0, p3; // 4 points (p1 & p2 defined below)
  22924. if (this.closed || intPoint > 0) {
  22925. p0 = points[(intPoint - 1) % l];
  22926. } else {
  22927. // extrapolate first point
  22928. tmp.subVectors(points[0], points[1]).add(points[0]);
  22929. p0 = tmp;
  22930. }
  22931. var p1 = points[intPoint % l];
  22932. var p2 = points[(intPoint + 1) % l];
  22933. if (this.closed || intPoint + 2 < l) {
  22934. p3 = points[(intPoint + 2) % l];
  22935. } else {
  22936. // extrapolate last point
  22937. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22938. p3 = tmp;
  22939. }
  22940. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22941. // init Centripetal / Chordal Catmull-Rom
  22942. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22943. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22944. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22945. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22946. if (dt1 < 1e-4) dt1 = 1.0;
  22947. if (dt0 < 1e-4) dt0 = dt1;
  22948. if (dt2 < 1e-4) dt2 = dt1;
  22949. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22950. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22951. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22952. } else if (this.curveType === 'catmullrom') {
  22953. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22954. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22955. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22956. }
  22957. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22958. return point;
  22959. };
  22960. CatmullRomCurve3.prototype.copy = function (source) {
  22961. Curve.prototype.copy.call(this, source);
  22962. this.points = [];
  22963. for (var i = 0, l = source.points.length; i < l; i++) {
  22964. var point = source.points[i];
  22965. this.points.push(point.clone());
  22966. }
  22967. this.closed = source.closed;
  22968. this.curveType = source.curveType;
  22969. this.tension = source.tension;
  22970. return this;
  22971. };
  22972. CatmullRomCurve3.prototype.toJSON = function () {
  22973. var data = Curve.prototype.toJSON.call(this);
  22974. data.points = [];
  22975. for (var i = 0, l = this.points.length; i < l; i++) {
  22976. var point = this.points[i];
  22977. data.points.push(point.toArray());
  22978. }
  22979. data.closed = this.closed;
  22980. data.curveType = this.curveType;
  22981. data.tension = this.tension;
  22982. return data;
  22983. };
  22984. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22985. Curve.prototype.fromJSON.call(this, json);
  22986. this.points = [];
  22987. for (var i = 0, l = json.points.length; i < l; i++) {
  22988. var point = json.points[i];
  22989. this.points.push(new Vector3().fromArray(point));
  22990. }
  22991. this.closed = json.closed;
  22992. this.curveType = json.curveType;
  22993. this.tension = json.tension;
  22994. return this;
  22995. };
  22996. /**
  22997. * Bezier Curves formulas obtained from
  22998. * http://en.wikipedia.org/wiki/Bézier_curve
  22999. */
  23000. function CatmullRom(t, p0, p1, p2, p3) {
  23001. var v0 = (p2 - p0) * 0.5;
  23002. var v1 = (p3 - p1) * 0.5;
  23003. var t2 = t * t;
  23004. var t3 = t * t2;
  23005. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  23006. } //
  23007. function QuadraticBezierP0(t, p) {
  23008. var k = 1 - t;
  23009. return k * k * p;
  23010. }
  23011. function QuadraticBezierP1(t, p) {
  23012. return 2 * (1 - t) * t * p;
  23013. }
  23014. function QuadraticBezierP2(t, p) {
  23015. return t * t * p;
  23016. }
  23017. function QuadraticBezier(t, p0, p1, p2) {
  23018. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  23019. } //
  23020. function CubicBezierP0(t, p) {
  23021. var k = 1 - t;
  23022. return k * k * k * p;
  23023. }
  23024. function CubicBezierP1(t, p) {
  23025. var k = 1 - t;
  23026. return 3 * k * k * t * p;
  23027. }
  23028. function CubicBezierP2(t, p) {
  23029. return 3 * (1 - t) * t * t * p;
  23030. }
  23031. function CubicBezierP3(t, p) {
  23032. return t * t * t * p;
  23033. }
  23034. function CubicBezier(t, p0, p1, p2, p3) {
  23035. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  23036. }
  23037. function CubicBezierCurve(v0, v1, v2, v3) {
  23038. if (v0 === void 0) {
  23039. v0 = new Vector2();
  23040. }
  23041. if (v1 === void 0) {
  23042. v1 = new Vector2();
  23043. }
  23044. if (v2 === void 0) {
  23045. v2 = new Vector2();
  23046. }
  23047. if (v3 === void 0) {
  23048. v3 = new Vector2();
  23049. }
  23050. Curve.call(this);
  23051. this.type = 'CubicBezierCurve';
  23052. this.v0 = v0;
  23053. this.v1 = v1;
  23054. this.v2 = v2;
  23055. this.v3 = v3;
  23056. }
  23057. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  23058. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  23059. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  23060. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23061. if (optionalTarget === void 0) {
  23062. optionalTarget = new Vector2();
  23063. }
  23064. var point = optionalTarget;
  23065. var v0 = this.v0,
  23066. v1 = this.v1,
  23067. v2 = this.v2,
  23068. v3 = this.v3;
  23069. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  23070. return point;
  23071. };
  23072. CubicBezierCurve.prototype.copy = function (source) {
  23073. Curve.prototype.copy.call(this, source);
  23074. this.v0.copy(source.v0);
  23075. this.v1.copy(source.v1);
  23076. this.v2.copy(source.v2);
  23077. this.v3.copy(source.v3);
  23078. return this;
  23079. };
  23080. CubicBezierCurve.prototype.toJSON = function () {
  23081. var data = Curve.prototype.toJSON.call(this);
  23082. data.v0 = this.v0.toArray();
  23083. data.v1 = this.v1.toArray();
  23084. data.v2 = this.v2.toArray();
  23085. data.v3 = this.v3.toArray();
  23086. return data;
  23087. };
  23088. CubicBezierCurve.prototype.fromJSON = function (json) {
  23089. Curve.prototype.fromJSON.call(this, json);
  23090. this.v0.fromArray(json.v0);
  23091. this.v1.fromArray(json.v1);
  23092. this.v2.fromArray(json.v2);
  23093. this.v3.fromArray(json.v3);
  23094. return this;
  23095. };
  23096. function CubicBezierCurve3(v0, v1, v2, v3) {
  23097. if (v0 === void 0) {
  23098. v0 = new Vector3();
  23099. }
  23100. if (v1 === void 0) {
  23101. v1 = new Vector3();
  23102. }
  23103. if (v2 === void 0) {
  23104. v2 = new Vector3();
  23105. }
  23106. if (v3 === void 0) {
  23107. v3 = new Vector3();
  23108. }
  23109. Curve.call(this);
  23110. this.type = 'CubicBezierCurve3';
  23111. this.v0 = v0;
  23112. this.v1 = v1;
  23113. this.v2 = v2;
  23114. this.v3 = v3;
  23115. }
  23116. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  23117. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  23118. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  23119. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23120. if (optionalTarget === void 0) {
  23121. optionalTarget = new Vector3();
  23122. }
  23123. var point = optionalTarget;
  23124. var v0 = this.v0,
  23125. v1 = this.v1,
  23126. v2 = this.v2,
  23127. v3 = this.v3;
  23128. 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));
  23129. return point;
  23130. };
  23131. CubicBezierCurve3.prototype.copy = function (source) {
  23132. Curve.prototype.copy.call(this, source);
  23133. this.v0.copy(source.v0);
  23134. this.v1.copy(source.v1);
  23135. this.v2.copy(source.v2);
  23136. this.v3.copy(source.v3);
  23137. return this;
  23138. };
  23139. CubicBezierCurve3.prototype.toJSON = function () {
  23140. var data = Curve.prototype.toJSON.call(this);
  23141. data.v0 = this.v0.toArray();
  23142. data.v1 = this.v1.toArray();
  23143. data.v2 = this.v2.toArray();
  23144. data.v3 = this.v3.toArray();
  23145. return data;
  23146. };
  23147. CubicBezierCurve3.prototype.fromJSON = function (json) {
  23148. Curve.prototype.fromJSON.call(this, json);
  23149. this.v0.fromArray(json.v0);
  23150. this.v1.fromArray(json.v1);
  23151. this.v2.fromArray(json.v2);
  23152. this.v3.fromArray(json.v3);
  23153. return this;
  23154. };
  23155. function LineCurve(v1, v2) {
  23156. if (v1 === void 0) {
  23157. v1 = new Vector2();
  23158. }
  23159. if (v2 === void 0) {
  23160. v2 = new Vector2();
  23161. }
  23162. Curve.call(this);
  23163. this.type = 'LineCurve';
  23164. this.v1 = v1;
  23165. this.v2 = v2;
  23166. }
  23167. LineCurve.prototype = Object.create(Curve.prototype);
  23168. LineCurve.prototype.constructor = LineCurve;
  23169. LineCurve.prototype.isLineCurve = true;
  23170. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  23171. if (optionalTarget === void 0) {
  23172. optionalTarget = new Vector2();
  23173. }
  23174. var point = optionalTarget;
  23175. if (t === 1) {
  23176. point.copy(this.v2);
  23177. } else {
  23178. point.copy(this.v2).sub(this.v1);
  23179. point.multiplyScalar(t).add(this.v1);
  23180. }
  23181. return point;
  23182. }; // Line curve is linear, so we can overwrite default getPointAt
  23183. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  23184. return this.getPoint(u, optionalTarget);
  23185. };
  23186. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  23187. var tangent = optionalTarget || new Vector2();
  23188. tangent.copy(this.v2).sub(this.v1).normalize();
  23189. return tangent;
  23190. };
  23191. LineCurve.prototype.copy = function (source) {
  23192. Curve.prototype.copy.call(this, source);
  23193. this.v1.copy(source.v1);
  23194. this.v2.copy(source.v2);
  23195. return this;
  23196. };
  23197. LineCurve.prototype.toJSON = function () {
  23198. var data = Curve.prototype.toJSON.call(this);
  23199. data.v1 = this.v1.toArray();
  23200. data.v2 = this.v2.toArray();
  23201. return data;
  23202. };
  23203. LineCurve.prototype.fromJSON = function (json) {
  23204. Curve.prototype.fromJSON.call(this, json);
  23205. this.v1.fromArray(json.v1);
  23206. this.v2.fromArray(json.v2);
  23207. return this;
  23208. };
  23209. function LineCurve3(v1, v2) {
  23210. if (v1 === void 0) {
  23211. v1 = new Vector3();
  23212. }
  23213. if (v2 === void 0) {
  23214. v2 = new Vector3();
  23215. }
  23216. Curve.call(this);
  23217. this.type = 'LineCurve3';
  23218. this.v1 = v1;
  23219. this.v2 = v2;
  23220. }
  23221. LineCurve3.prototype = Object.create(Curve.prototype);
  23222. LineCurve3.prototype.constructor = LineCurve3;
  23223. LineCurve3.prototype.isLineCurve3 = true;
  23224. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  23225. if (optionalTarget === void 0) {
  23226. optionalTarget = new Vector3();
  23227. }
  23228. var point = optionalTarget;
  23229. if (t === 1) {
  23230. point.copy(this.v2);
  23231. } else {
  23232. point.copy(this.v2).sub(this.v1);
  23233. point.multiplyScalar(t).add(this.v1);
  23234. }
  23235. return point;
  23236. }; // Line curve is linear, so we can overwrite default getPointAt
  23237. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  23238. return this.getPoint(u, optionalTarget);
  23239. };
  23240. LineCurve3.prototype.copy = function (source) {
  23241. Curve.prototype.copy.call(this, source);
  23242. this.v1.copy(source.v1);
  23243. this.v2.copy(source.v2);
  23244. return this;
  23245. };
  23246. LineCurve3.prototype.toJSON = function () {
  23247. var data = Curve.prototype.toJSON.call(this);
  23248. data.v1 = this.v1.toArray();
  23249. data.v2 = this.v2.toArray();
  23250. return data;
  23251. };
  23252. LineCurve3.prototype.fromJSON = function (json) {
  23253. Curve.prototype.fromJSON.call(this, json);
  23254. this.v1.fromArray(json.v1);
  23255. this.v2.fromArray(json.v2);
  23256. return this;
  23257. };
  23258. function QuadraticBezierCurve(v0, v1, v2) {
  23259. if (v0 === void 0) {
  23260. v0 = new Vector2();
  23261. }
  23262. if (v1 === void 0) {
  23263. v1 = new Vector2();
  23264. }
  23265. if (v2 === void 0) {
  23266. v2 = new Vector2();
  23267. }
  23268. Curve.call(this);
  23269. this.type = 'QuadraticBezierCurve';
  23270. this.v0 = v0;
  23271. this.v1 = v1;
  23272. this.v2 = v2;
  23273. }
  23274. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  23275. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  23276. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23277. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  23278. if (optionalTarget === void 0) {
  23279. optionalTarget = new Vector2();
  23280. }
  23281. var point = optionalTarget;
  23282. var v0 = this.v0,
  23283. v1 = this.v1,
  23284. v2 = this.v2;
  23285. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  23286. return point;
  23287. };
  23288. QuadraticBezierCurve.prototype.copy = function (source) {
  23289. Curve.prototype.copy.call(this, source);
  23290. this.v0.copy(source.v0);
  23291. this.v1.copy(source.v1);
  23292. this.v2.copy(source.v2);
  23293. return this;
  23294. };
  23295. QuadraticBezierCurve.prototype.toJSON = function () {
  23296. var data = Curve.prototype.toJSON.call(this);
  23297. data.v0 = this.v0.toArray();
  23298. data.v1 = this.v1.toArray();
  23299. data.v2 = this.v2.toArray();
  23300. return data;
  23301. };
  23302. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  23303. Curve.prototype.fromJSON.call(this, json);
  23304. this.v0.fromArray(json.v0);
  23305. this.v1.fromArray(json.v1);
  23306. this.v2.fromArray(json.v2);
  23307. return this;
  23308. };
  23309. function QuadraticBezierCurve3(v0, v1, v2) {
  23310. if (v0 === void 0) {
  23311. v0 = new Vector3();
  23312. }
  23313. if (v1 === void 0) {
  23314. v1 = new Vector3();
  23315. }
  23316. if (v2 === void 0) {
  23317. v2 = new Vector3();
  23318. }
  23319. Curve.call(this);
  23320. this.type = 'QuadraticBezierCurve3';
  23321. this.v0 = v0;
  23322. this.v1 = v1;
  23323. this.v2 = v2;
  23324. }
  23325. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  23326. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  23327. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23328. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  23329. if (optionalTarget === void 0) {
  23330. optionalTarget = new Vector3();
  23331. }
  23332. var point = optionalTarget;
  23333. var v0 = this.v0,
  23334. v1 = this.v1,
  23335. v2 = this.v2;
  23336. 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));
  23337. return point;
  23338. };
  23339. QuadraticBezierCurve3.prototype.copy = function (source) {
  23340. Curve.prototype.copy.call(this, source);
  23341. this.v0.copy(source.v0);
  23342. this.v1.copy(source.v1);
  23343. this.v2.copy(source.v2);
  23344. return this;
  23345. };
  23346. QuadraticBezierCurve3.prototype.toJSON = function () {
  23347. var data = Curve.prototype.toJSON.call(this);
  23348. data.v0 = this.v0.toArray();
  23349. data.v1 = this.v1.toArray();
  23350. data.v2 = this.v2.toArray();
  23351. return data;
  23352. };
  23353. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  23354. Curve.prototype.fromJSON.call(this, json);
  23355. this.v0.fromArray(json.v0);
  23356. this.v1.fromArray(json.v1);
  23357. this.v2.fromArray(json.v2);
  23358. return this;
  23359. };
  23360. function SplineCurve(points) {
  23361. if (points === void 0) {
  23362. points = [];
  23363. }
  23364. Curve.call(this);
  23365. this.type = 'SplineCurve';
  23366. this.points = points;
  23367. }
  23368. SplineCurve.prototype = Object.create(Curve.prototype);
  23369. SplineCurve.prototype.constructor = SplineCurve;
  23370. SplineCurve.prototype.isSplineCurve = true;
  23371. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  23372. if (optionalTarget === void 0) {
  23373. optionalTarget = new Vector2();
  23374. }
  23375. var point = optionalTarget;
  23376. var points = this.points;
  23377. var p = (points.length - 1) * t;
  23378. var intPoint = Math.floor(p);
  23379. var weight = p - intPoint;
  23380. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23381. var p1 = points[intPoint];
  23382. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23383. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23384. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23385. return point;
  23386. };
  23387. SplineCurve.prototype.copy = function (source) {
  23388. Curve.prototype.copy.call(this, source);
  23389. this.points = [];
  23390. for (var i = 0, l = source.points.length; i < l; i++) {
  23391. var point = source.points[i];
  23392. this.points.push(point.clone());
  23393. }
  23394. return this;
  23395. };
  23396. SplineCurve.prototype.toJSON = function () {
  23397. var data = Curve.prototype.toJSON.call(this);
  23398. data.points = [];
  23399. for (var i = 0, l = this.points.length; i < l; i++) {
  23400. var point = this.points[i];
  23401. data.points.push(point.toArray());
  23402. }
  23403. return data;
  23404. };
  23405. SplineCurve.prototype.fromJSON = function (json) {
  23406. Curve.prototype.fromJSON.call(this, json);
  23407. this.points = [];
  23408. for (var i = 0, l = json.points.length; i < l; i++) {
  23409. var point = json.points[i];
  23410. this.points.push(new Vector2().fromArray(point));
  23411. }
  23412. return this;
  23413. };
  23414. var Curves = /*#__PURE__*/Object.freeze({
  23415. __proto__: null,
  23416. ArcCurve: ArcCurve,
  23417. CatmullRomCurve3: CatmullRomCurve3,
  23418. CubicBezierCurve: CubicBezierCurve,
  23419. CubicBezierCurve3: CubicBezierCurve3,
  23420. EllipseCurve: EllipseCurve,
  23421. LineCurve: LineCurve,
  23422. LineCurve3: LineCurve3,
  23423. QuadraticBezierCurve: QuadraticBezierCurve,
  23424. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23425. SplineCurve: SplineCurve
  23426. });
  23427. /**************************************************************
  23428. * Curved Path - a curve path is simply a array of connected
  23429. * curves, but retains the api of a curve
  23430. **************************************************************/
  23431. function CurvePath() {
  23432. Curve.call(this);
  23433. this.type = 'CurvePath';
  23434. this.curves = [];
  23435. this.autoClose = false; // Automatically closes the path
  23436. }
  23437. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  23438. constructor: CurvePath,
  23439. add: function add(curve) {
  23440. this.curves.push(curve);
  23441. },
  23442. closePath: function closePath() {
  23443. // Add a line curve if start and end of lines are not connected
  23444. var startPoint = this.curves[0].getPoint(0);
  23445. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23446. if (!startPoint.equals(endPoint)) {
  23447. this.curves.push(new LineCurve(endPoint, startPoint));
  23448. }
  23449. },
  23450. // To get accurate point with reference to
  23451. // entire path distance at time t,
  23452. // following has to be done:
  23453. // 1. Length of each sub path have to be known
  23454. // 2. Locate and identify type of curve
  23455. // 3. Get t for the curve
  23456. // 4. Return curve.getPointAt(t')
  23457. getPoint: function getPoint(t) {
  23458. var d = t * this.getLength();
  23459. var curveLengths = this.getCurveLengths();
  23460. var i = 0; // To think about boundaries points.
  23461. while (i < curveLengths.length) {
  23462. if (curveLengths[i] >= d) {
  23463. var diff = curveLengths[i] - d;
  23464. var curve = this.curves[i];
  23465. var segmentLength = curve.getLength();
  23466. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23467. return curve.getPointAt(u);
  23468. }
  23469. i++;
  23470. }
  23471. return null; // loop where sum != 0, sum > d , sum+1 <d
  23472. },
  23473. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23474. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23475. // getPoint() depends on getLength
  23476. getLength: function getLength() {
  23477. var lens = this.getCurveLengths();
  23478. return lens[lens.length - 1];
  23479. },
  23480. // cacheLengths must be recalculated.
  23481. updateArcLengths: function updateArcLengths() {
  23482. this.needsUpdate = true;
  23483. this.cacheLengths = null;
  23484. this.getCurveLengths();
  23485. },
  23486. // Compute lengths and cache them
  23487. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23488. getCurveLengths: function getCurveLengths() {
  23489. // We use cache values if curves and cache array are same length
  23490. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23491. return this.cacheLengths;
  23492. } // Get length of sub-curve
  23493. // Push sums into cached array
  23494. var lengths = [];
  23495. var sums = 0;
  23496. for (var i = 0, l = this.curves.length; i < l; i++) {
  23497. sums += this.curves[i].getLength();
  23498. lengths.push(sums);
  23499. }
  23500. this.cacheLengths = lengths;
  23501. return lengths;
  23502. },
  23503. getSpacedPoints: function getSpacedPoints(divisions) {
  23504. if (divisions === void 0) {
  23505. divisions = 40;
  23506. }
  23507. var points = [];
  23508. for (var i = 0; i <= divisions; i++) {
  23509. points.push(this.getPoint(i / divisions));
  23510. }
  23511. if (this.autoClose) {
  23512. points.push(points[0]);
  23513. }
  23514. return points;
  23515. },
  23516. getPoints: function getPoints(divisions) {
  23517. if (divisions === void 0) {
  23518. divisions = 12;
  23519. }
  23520. var points = [];
  23521. var last;
  23522. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23523. var curve = curves[i];
  23524. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23525. var pts = curve.getPoints(resolution);
  23526. for (var j = 0; j < pts.length; j++) {
  23527. var point = pts[j];
  23528. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23529. points.push(point);
  23530. last = point;
  23531. }
  23532. }
  23533. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23534. points.push(points[0]);
  23535. }
  23536. return points;
  23537. },
  23538. copy: function copy(source) {
  23539. Curve.prototype.copy.call(this, source);
  23540. this.curves = [];
  23541. for (var i = 0, l = source.curves.length; i < l; i++) {
  23542. var curve = source.curves[i];
  23543. this.curves.push(curve.clone());
  23544. }
  23545. this.autoClose = source.autoClose;
  23546. return this;
  23547. },
  23548. toJSON: function toJSON() {
  23549. var data = Curve.prototype.toJSON.call(this);
  23550. data.autoClose = this.autoClose;
  23551. data.curves = [];
  23552. for (var i = 0, l = this.curves.length; i < l; i++) {
  23553. var curve = this.curves[i];
  23554. data.curves.push(curve.toJSON());
  23555. }
  23556. return data;
  23557. },
  23558. fromJSON: function fromJSON(json) {
  23559. Curve.prototype.fromJSON.call(this, json);
  23560. this.autoClose = json.autoClose;
  23561. this.curves = [];
  23562. for (var i = 0, l = json.curves.length; i < l; i++) {
  23563. var curve = json.curves[i];
  23564. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23565. }
  23566. return this;
  23567. }
  23568. });
  23569. function Path(points) {
  23570. CurvePath.call(this);
  23571. this.type = 'Path';
  23572. this.currentPoint = new Vector2();
  23573. if (points) {
  23574. this.setFromPoints(points);
  23575. }
  23576. }
  23577. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23578. constructor: Path,
  23579. setFromPoints: function setFromPoints(points) {
  23580. this.moveTo(points[0].x, points[0].y);
  23581. for (var i = 1, l = points.length; i < l; i++) {
  23582. this.lineTo(points[i].x, points[i].y);
  23583. }
  23584. return this;
  23585. },
  23586. moveTo: function moveTo(x, y) {
  23587. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23588. return this;
  23589. },
  23590. lineTo: function lineTo(x, y) {
  23591. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23592. this.curves.push(curve);
  23593. this.currentPoint.set(x, y);
  23594. return this;
  23595. },
  23596. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23597. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23598. this.curves.push(curve);
  23599. this.currentPoint.set(aX, aY);
  23600. return this;
  23601. },
  23602. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23603. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23604. this.curves.push(curve);
  23605. this.currentPoint.set(aX, aY);
  23606. return this;
  23607. },
  23608. splineThru: function splineThru(pts
  23609. /*Array of Vector*/
  23610. ) {
  23611. var npts = [this.currentPoint.clone()].concat(pts);
  23612. var curve = new SplineCurve(npts);
  23613. this.curves.push(curve);
  23614. this.currentPoint.copy(pts[pts.length - 1]);
  23615. return this;
  23616. },
  23617. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23618. var x0 = this.currentPoint.x;
  23619. var y0 = this.currentPoint.y;
  23620. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23621. return this;
  23622. },
  23623. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23624. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23625. return this;
  23626. },
  23627. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23628. var x0 = this.currentPoint.x;
  23629. var y0 = this.currentPoint.y;
  23630. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23631. return this;
  23632. },
  23633. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23634. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23635. if (this.curves.length > 0) {
  23636. // if a previous curve is present, attempt to join
  23637. var firstPoint = curve.getPoint(0);
  23638. if (!firstPoint.equals(this.currentPoint)) {
  23639. this.lineTo(firstPoint.x, firstPoint.y);
  23640. }
  23641. }
  23642. this.curves.push(curve);
  23643. var lastPoint = curve.getPoint(1);
  23644. this.currentPoint.copy(lastPoint);
  23645. return this;
  23646. },
  23647. copy: function copy(source) {
  23648. CurvePath.prototype.copy.call(this, source);
  23649. this.currentPoint.copy(source.currentPoint);
  23650. return this;
  23651. },
  23652. toJSON: function toJSON() {
  23653. var data = CurvePath.prototype.toJSON.call(this);
  23654. data.currentPoint = this.currentPoint.toArray();
  23655. return data;
  23656. },
  23657. fromJSON: function fromJSON(json) {
  23658. CurvePath.prototype.fromJSON.call(this, json);
  23659. this.currentPoint.fromArray(json.currentPoint);
  23660. return this;
  23661. }
  23662. });
  23663. function Shape(points) {
  23664. Path.call(this, points);
  23665. this.uuid = MathUtils.generateUUID();
  23666. this.type = 'Shape';
  23667. this.holes = [];
  23668. }
  23669. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23670. constructor: Shape,
  23671. getPointsHoles: function getPointsHoles(divisions) {
  23672. var holesPts = [];
  23673. for (var i = 0, l = this.holes.length; i < l; i++) {
  23674. holesPts[i] = this.holes[i].getPoints(divisions);
  23675. }
  23676. return holesPts;
  23677. },
  23678. // get points of shape and holes (keypoints based on segments parameter)
  23679. extractPoints: function extractPoints(divisions) {
  23680. return {
  23681. shape: this.getPoints(divisions),
  23682. holes: this.getPointsHoles(divisions)
  23683. };
  23684. },
  23685. copy: function copy(source) {
  23686. Path.prototype.copy.call(this, source);
  23687. this.holes = [];
  23688. for (var i = 0, l = source.holes.length; i < l; i++) {
  23689. var hole = source.holes[i];
  23690. this.holes.push(hole.clone());
  23691. }
  23692. return this;
  23693. },
  23694. toJSON: function toJSON() {
  23695. var data = Path.prototype.toJSON.call(this);
  23696. data.uuid = this.uuid;
  23697. data.holes = [];
  23698. for (var i = 0, l = this.holes.length; i < l; i++) {
  23699. var hole = this.holes[i];
  23700. data.holes.push(hole.toJSON());
  23701. }
  23702. return data;
  23703. },
  23704. fromJSON: function fromJSON(json) {
  23705. Path.prototype.fromJSON.call(this, json);
  23706. this.uuid = json.uuid;
  23707. this.holes = [];
  23708. for (var i = 0, l = json.holes.length; i < l; i++) {
  23709. var hole = json.holes[i];
  23710. this.holes.push(new Path().fromJSON(hole));
  23711. }
  23712. return this;
  23713. }
  23714. });
  23715. function Light(color, intensity) {
  23716. if (intensity === void 0) {
  23717. intensity = 1;
  23718. }
  23719. Object3D.call(this);
  23720. this.type = 'Light';
  23721. this.color = new Color(color);
  23722. this.intensity = intensity;
  23723. }
  23724. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23725. constructor: Light,
  23726. isLight: true,
  23727. copy: function copy(source) {
  23728. Object3D.prototype.copy.call(this, source);
  23729. this.color.copy(source.color);
  23730. this.intensity = source.intensity;
  23731. return this;
  23732. },
  23733. toJSON: function toJSON(meta) {
  23734. var data = Object3D.prototype.toJSON.call(this, meta);
  23735. data.object.color = this.color.getHex();
  23736. data.object.intensity = this.intensity;
  23737. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23738. if (this.distance !== undefined) data.object.distance = this.distance;
  23739. if (this.angle !== undefined) data.object.angle = this.angle;
  23740. if (this.decay !== undefined) data.object.decay = this.decay;
  23741. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23742. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23743. return data;
  23744. }
  23745. });
  23746. function HemisphereLight(skyColor, groundColor, intensity) {
  23747. Light.call(this, skyColor, intensity);
  23748. this.type = 'HemisphereLight';
  23749. this.position.copy(Object3D.DefaultUp);
  23750. this.updateMatrix();
  23751. this.groundColor = new Color(groundColor);
  23752. }
  23753. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23754. constructor: HemisphereLight,
  23755. isHemisphereLight: true,
  23756. copy: function copy(source) {
  23757. Light.prototype.copy.call(this, source);
  23758. this.groundColor.copy(source.groundColor);
  23759. return this;
  23760. }
  23761. });
  23762. function LightShadow(camera) {
  23763. this.camera = camera;
  23764. this.bias = 0;
  23765. this.normalBias = 0;
  23766. this.radius = 1;
  23767. this.mapSize = new Vector2(512, 512);
  23768. this.map = null;
  23769. this.mapPass = null;
  23770. this.matrix = new Matrix4();
  23771. this.autoUpdate = true;
  23772. this.needsUpdate = false;
  23773. this._frustum = new Frustum();
  23774. this._frameExtents = new Vector2(1, 1);
  23775. this._viewportCount = 1;
  23776. this._viewports = [new Vector4(0, 0, 1, 1)];
  23777. }
  23778. Object.assign(LightShadow.prototype, {
  23779. _projScreenMatrix: new Matrix4(),
  23780. _lightPositionWorld: new Vector3(),
  23781. _lookTarget: new Vector3(),
  23782. getViewportCount: function getViewportCount() {
  23783. return this._viewportCount;
  23784. },
  23785. getFrustum: function getFrustum() {
  23786. return this._frustum;
  23787. },
  23788. updateMatrices: function updateMatrices(light) {
  23789. var shadowCamera = this.camera,
  23790. shadowMatrix = this.matrix,
  23791. projScreenMatrix = this._projScreenMatrix,
  23792. lookTarget = this._lookTarget,
  23793. lightPositionWorld = this._lightPositionWorld;
  23794. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23795. shadowCamera.position.copy(lightPositionWorld);
  23796. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23797. shadowCamera.lookAt(lookTarget);
  23798. shadowCamera.updateMatrixWorld();
  23799. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23800. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23801. 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);
  23802. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23803. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23804. },
  23805. getViewport: function getViewport(viewportIndex) {
  23806. return this._viewports[viewportIndex];
  23807. },
  23808. getFrameExtents: function getFrameExtents() {
  23809. return this._frameExtents;
  23810. },
  23811. copy: function copy(source) {
  23812. this.camera = source.camera.clone();
  23813. this.bias = source.bias;
  23814. this.radius = source.radius;
  23815. this.mapSize.copy(source.mapSize);
  23816. return this;
  23817. },
  23818. clone: function clone() {
  23819. return new this.constructor().copy(this);
  23820. },
  23821. toJSON: function toJSON() {
  23822. var object = {};
  23823. if (this.bias !== 0) object.bias = this.bias;
  23824. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23825. if (this.radius !== 1) object.radius = this.radius;
  23826. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23827. object.camera = this.camera.toJSON(false).object;
  23828. delete object.camera.matrix;
  23829. return object;
  23830. }
  23831. });
  23832. function SpotLightShadow() {
  23833. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23834. this.focus = 1;
  23835. }
  23836. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23837. constructor: SpotLightShadow,
  23838. isSpotLightShadow: true,
  23839. updateMatrices: function updateMatrices(light) {
  23840. var camera = this.camera;
  23841. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23842. var aspect = this.mapSize.width / this.mapSize.height;
  23843. var far = light.distance || camera.far;
  23844. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23845. camera.fov = fov;
  23846. camera.aspect = aspect;
  23847. camera.far = far;
  23848. camera.updateProjectionMatrix();
  23849. }
  23850. LightShadow.prototype.updateMatrices.call(this, light);
  23851. }
  23852. });
  23853. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23854. Light.call(this, color, intensity);
  23855. this.type = 'SpotLight';
  23856. this.position.copy(Object3D.DefaultUp);
  23857. this.updateMatrix();
  23858. this.target = new Object3D();
  23859. Object.defineProperty(this, 'power', {
  23860. get: function get() {
  23861. // intensity = power per solid angle.
  23862. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23863. return this.intensity * Math.PI;
  23864. },
  23865. set: function set(power) {
  23866. // intensity = power per solid angle.
  23867. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23868. this.intensity = power / Math.PI;
  23869. }
  23870. });
  23871. this.distance = distance !== undefined ? distance : 0;
  23872. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23873. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23874. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23875. this.shadow = new SpotLightShadow();
  23876. }
  23877. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23878. constructor: SpotLight,
  23879. isSpotLight: true,
  23880. copy: function copy(source) {
  23881. Light.prototype.copy.call(this, source);
  23882. this.distance = source.distance;
  23883. this.angle = source.angle;
  23884. this.penumbra = source.penumbra;
  23885. this.decay = source.decay;
  23886. this.target = source.target.clone();
  23887. this.shadow = source.shadow.clone();
  23888. return this;
  23889. }
  23890. });
  23891. function PointLightShadow() {
  23892. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23893. this._frameExtents = new Vector2(4, 2);
  23894. this._viewportCount = 6;
  23895. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23896. // following orientation:
  23897. //
  23898. // xzXZ
  23899. // y Y
  23900. //
  23901. // X - Positive x direction
  23902. // x - Negative x direction
  23903. // Y - Positive y direction
  23904. // y - Negative y direction
  23905. // Z - Positive z direction
  23906. // z - Negative z direction
  23907. // positive X
  23908. new Vector4(2, 1, 1, 1), // negative X
  23909. new Vector4(0, 1, 1, 1), // positive Z
  23910. new Vector4(3, 1, 1, 1), // negative Z
  23911. new Vector4(1, 1, 1, 1), // positive Y
  23912. new Vector4(3, 0, 1, 1), // negative Y
  23913. new Vector4(1, 0, 1, 1)];
  23914. 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)];
  23915. 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)];
  23916. }
  23917. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23918. constructor: PointLightShadow,
  23919. isPointLightShadow: true,
  23920. updateMatrices: function updateMatrices(light, viewportIndex) {
  23921. if (viewportIndex === void 0) {
  23922. viewportIndex = 0;
  23923. }
  23924. var camera = this.camera,
  23925. shadowMatrix = this.matrix,
  23926. lightPositionWorld = this._lightPositionWorld,
  23927. lookTarget = this._lookTarget,
  23928. projScreenMatrix = this._projScreenMatrix;
  23929. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23930. camera.position.copy(lightPositionWorld);
  23931. lookTarget.copy(camera.position);
  23932. lookTarget.add(this._cubeDirections[viewportIndex]);
  23933. camera.up.copy(this._cubeUps[viewportIndex]);
  23934. camera.lookAt(lookTarget);
  23935. camera.updateMatrixWorld();
  23936. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23937. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23938. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23939. }
  23940. });
  23941. function PointLight(color, intensity, distance, decay) {
  23942. Light.call(this, color, intensity);
  23943. this.type = 'PointLight';
  23944. Object.defineProperty(this, 'power', {
  23945. get: function get() {
  23946. // intensity = power per solid angle.
  23947. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23948. return this.intensity * 4 * Math.PI;
  23949. },
  23950. set: function set(power) {
  23951. // intensity = power per solid angle.
  23952. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23953. this.intensity = power / (4 * Math.PI);
  23954. }
  23955. });
  23956. this.distance = distance !== undefined ? distance : 0;
  23957. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23958. this.shadow = new PointLightShadow();
  23959. }
  23960. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23961. constructor: PointLight,
  23962. isPointLight: true,
  23963. copy: function copy(source) {
  23964. Light.prototype.copy.call(this, source);
  23965. this.distance = source.distance;
  23966. this.decay = source.decay;
  23967. this.shadow = source.shadow.clone();
  23968. return this;
  23969. }
  23970. });
  23971. function OrthographicCamera(left, right, top, bottom, near, far) {
  23972. Camera.call(this);
  23973. this.type = 'OrthographicCamera';
  23974. this.zoom = 1;
  23975. this.view = null;
  23976. this.left = left !== undefined ? left : -1;
  23977. this.right = right !== undefined ? right : 1;
  23978. this.top = top !== undefined ? top : 1;
  23979. this.bottom = bottom !== undefined ? bottom : -1;
  23980. this.near = near !== undefined ? near : 0.1;
  23981. this.far = far !== undefined ? far : 2000;
  23982. this.updateProjectionMatrix();
  23983. }
  23984. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23985. constructor: OrthographicCamera,
  23986. isOrthographicCamera: true,
  23987. copy: function copy(source, recursive) {
  23988. Camera.prototype.copy.call(this, source, recursive);
  23989. this.left = source.left;
  23990. this.right = source.right;
  23991. this.top = source.top;
  23992. this.bottom = source.bottom;
  23993. this.near = source.near;
  23994. this.far = source.far;
  23995. this.zoom = source.zoom;
  23996. this.view = source.view === null ? null : Object.assign({}, source.view);
  23997. return this;
  23998. },
  23999. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  24000. if (this.view === null) {
  24001. this.view = {
  24002. enabled: true,
  24003. fullWidth: 1,
  24004. fullHeight: 1,
  24005. offsetX: 0,
  24006. offsetY: 0,
  24007. width: 1,
  24008. height: 1
  24009. };
  24010. }
  24011. this.view.enabled = true;
  24012. this.view.fullWidth = fullWidth;
  24013. this.view.fullHeight = fullHeight;
  24014. this.view.offsetX = x;
  24015. this.view.offsetY = y;
  24016. this.view.width = width;
  24017. this.view.height = height;
  24018. this.updateProjectionMatrix();
  24019. },
  24020. clearViewOffset: function clearViewOffset() {
  24021. if (this.view !== null) {
  24022. this.view.enabled = false;
  24023. }
  24024. this.updateProjectionMatrix();
  24025. },
  24026. updateProjectionMatrix: function updateProjectionMatrix() {
  24027. var dx = (this.right - this.left) / (2 * this.zoom);
  24028. var dy = (this.top - this.bottom) / (2 * this.zoom);
  24029. var cx = (this.right + this.left) / 2;
  24030. var cy = (this.top + this.bottom) / 2;
  24031. var left = cx - dx;
  24032. var right = cx + dx;
  24033. var top = cy + dy;
  24034. var bottom = cy - dy;
  24035. if (this.view !== null && this.view.enabled) {
  24036. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  24037. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  24038. left += scaleW * this.view.offsetX;
  24039. right = left + scaleW * this.view.width;
  24040. top -= scaleH * this.view.offsetY;
  24041. bottom = top - scaleH * this.view.height;
  24042. }
  24043. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  24044. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  24045. },
  24046. toJSON: function toJSON(meta) {
  24047. var data = Object3D.prototype.toJSON.call(this, meta);
  24048. data.object.zoom = this.zoom;
  24049. data.object.left = this.left;
  24050. data.object.right = this.right;
  24051. data.object.top = this.top;
  24052. data.object.bottom = this.bottom;
  24053. data.object.near = this.near;
  24054. data.object.far = this.far;
  24055. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  24056. return data;
  24057. }
  24058. });
  24059. function DirectionalLightShadow() {
  24060. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  24061. }
  24062. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  24063. constructor: DirectionalLightShadow,
  24064. isDirectionalLightShadow: true,
  24065. updateMatrices: function updateMatrices(light) {
  24066. LightShadow.prototype.updateMatrices.call(this, light);
  24067. }
  24068. });
  24069. function DirectionalLight(color, intensity) {
  24070. Light.call(this, color, intensity);
  24071. this.type = 'DirectionalLight';
  24072. this.position.copy(Object3D.DefaultUp);
  24073. this.updateMatrix();
  24074. this.target = new Object3D();
  24075. this.shadow = new DirectionalLightShadow();
  24076. }
  24077. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  24078. constructor: DirectionalLight,
  24079. isDirectionalLight: true,
  24080. copy: function copy(source) {
  24081. Light.prototype.copy.call(this, source);
  24082. this.target = source.target.clone();
  24083. this.shadow = source.shadow.clone();
  24084. return this;
  24085. }
  24086. });
  24087. function AmbientLight(color, intensity) {
  24088. Light.call(this, color, intensity);
  24089. this.type = 'AmbientLight';
  24090. }
  24091. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  24092. constructor: AmbientLight,
  24093. isAmbientLight: true
  24094. });
  24095. function RectAreaLight(color, intensity, width, height) {
  24096. Light.call(this, color, intensity);
  24097. this.type = 'RectAreaLight';
  24098. this.width = width !== undefined ? width : 10;
  24099. this.height = height !== undefined ? height : 10;
  24100. }
  24101. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  24102. constructor: RectAreaLight,
  24103. isRectAreaLight: true,
  24104. copy: function copy(source) {
  24105. Light.prototype.copy.call(this, source);
  24106. this.width = source.width;
  24107. this.height = source.height;
  24108. return this;
  24109. },
  24110. toJSON: function toJSON(meta) {
  24111. var data = Light.prototype.toJSON.call(this, meta);
  24112. data.object.width = this.width;
  24113. data.object.height = this.height;
  24114. return data;
  24115. }
  24116. });
  24117. /**
  24118. * Primary reference:
  24119. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24120. *
  24121. * Secondary reference:
  24122. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24123. */
  24124. // 3-band SH defined by 9 coefficients
  24125. var SphericalHarmonics3 = /*#__PURE__*/function () {
  24126. function SphericalHarmonics3() {
  24127. Object.defineProperty(this, 'isSphericalHarmonics3', {
  24128. value: true
  24129. });
  24130. this.coefficients = [];
  24131. for (var i = 0; i < 9; i++) {
  24132. this.coefficients.push(new Vector3());
  24133. }
  24134. }
  24135. var _proto = SphericalHarmonics3.prototype;
  24136. _proto.set = function set(coefficients) {
  24137. for (var i = 0; i < 9; i++) {
  24138. this.coefficients[i].copy(coefficients[i]);
  24139. }
  24140. return this;
  24141. };
  24142. _proto.zero = function zero() {
  24143. for (var i = 0; i < 9; i++) {
  24144. this.coefficients[i].set(0, 0, 0);
  24145. }
  24146. return this;
  24147. } // get the radiance in the direction of the normal
  24148. // target is a Vector3
  24149. ;
  24150. _proto.getAt = function getAt(normal, target) {
  24151. // normal is assumed to be unit length
  24152. var x = normal.x,
  24153. y = normal.y,
  24154. z = normal.z;
  24155. var coeff = this.coefficients; // band 0
  24156. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  24157. target.addScaledVector(coeff[1], 0.488603 * y);
  24158. target.addScaledVector(coeff[2], 0.488603 * z);
  24159. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  24160. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  24161. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  24162. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  24163. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  24164. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  24165. return target;
  24166. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24167. // target is a Vector3
  24168. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24169. ;
  24170. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  24171. // normal is assumed to be unit length
  24172. var x = normal.x,
  24173. y = normal.y,
  24174. z = normal.z;
  24175. var coeff = this.coefficients; // band 0
  24176. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  24177. // band 1
  24178. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  24179. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  24180. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  24181. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  24182. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  24183. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  24184. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  24185. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  24186. return target;
  24187. };
  24188. _proto.add = function add(sh) {
  24189. for (var i = 0; i < 9; i++) {
  24190. this.coefficients[i].add(sh.coefficients[i]);
  24191. }
  24192. return this;
  24193. };
  24194. _proto.addScaledSH = function addScaledSH(sh, s) {
  24195. for (var i = 0; i < 9; i++) {
  24196. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  24197. }
  24198. return this;
  24199. };
  24200. _proto.scale = function scale(s) {
  24201. for (var i = 0; i < 9; i++) {
  24202. this.coefficients[i].multiplyScalar(s);
  24203. }
  24204. return this;
  24205. };
  24206. _proto.lerp = function lerp(sh, alpha) {
  24207. for (var i = 0; i < 9; i++) {
  24208. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  24209. }
  24210. return this;
  24211. };
  24212. _proto.equals = function equals(sh) {
  24213. for (var i = 0; i < 9; i++) {
  24214. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24215. return false;
  24216. }
  24217. }
  24218. return true;
  24219. };
  24220. _proto.copy = function copy(sh) {
  24221. return this.set(sh.coefficients);
  24222. };
  24223. _proto.clone = function clone() {
  24224. return new this.constructor().copy(this);
  24225. };
  24226. _proto.fromArray = function fromArray(array, offset) {
  24227. if (offset === void 0) {
  24228. offset = 0;
  24229. }
  24230. var coefficients = this.coefficients;
  24231. for (var i = 0; i < 9; i++) {
  24232. coefficients[i].fromArray(array, offset + i * 3);
  24233. }
  24234. return this;
  24235. };
  24236. _proto.toArray = function toArray(array, offset) {
  24237. if (array === void 0) {
  24238. array = [];
  24239. }
  24240. if (offset === void 0) {
  24241. offset = 0;
  24242. }
  24243. var coefficients = this.coefficients;
  24244. for (var i = 0; i < 9; i++) {
  24245. coefficients[i].toArray(array, offset + i * 3);
  24246. }
  24247. return array;
  24248. } // evaluate the basis functions
  24249. // shBasis is an Array[ 9 ]
  24250. ;
  24251. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24252. // normal is assumed to be unit length
  24253. var x = normal.x,
  24254. y = normal.y,
  24255. z = normal.z; // band 0
  24256. shBasis[0] = 0.282095; // band 1
  24257. shBasis[1] = 0.488603 * y;
  24258. shBasis[2] = 0.488603 * z;
  24259. shBasis[3] = 0.488603 * x; // band 2
  24260. shBasis[4] = 1.092548 * x * y;
  24261. shBasis[5] = 1.092548 * y * z;
  24262. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24263. shBasis[7] = 1.092548 * x * z;
  24264. shBasis[8] = 0.546274 * (x * x - y * y);
  24265. };
  24266. return SphericalHarmonics3;
  24267. }();
  24268. function LightProbe(sh, intensity) {
  24269. Light.call(this, undefined, intensity);
  24270. this.type = 'LightProbe';
  24271. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  24272. }
  24273. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  24274. constructor: LightProbe,
  24275. isLightProbe: true,
  24276. copy: function copy(source) {
  24277. Light.prototype.copy.call(this, source);
  24278. this.sh.copy(source.sh);
  24279. return this;
  24280. },
  24281. fromJSON: function fromJSON(json) {
  24282. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24283. this.sh.fromArray(json.sh);
  24284. return this;
  24285. },
  24286. toJSON: function toJSON(meta) {
  24287. var data = Light.prototype.toJSON.call(this, meta);
  24288. data.object.sh = this.sh.toArray();
  24289. return data;
  24290. }
  24291. });
  24292. function MaterialLoader(manager) {
  24293. Loader.call(this, manager);
  24294. this.textures = {};
  24295. }
  24296. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24297. constructor: MaterialLoader,
  24298. load: function load(url, onLoad, onProgress, onError) {
  24299. var scope = this;
  24300. var loader = new FileLoader(scope.manager);
  24301. loader.setPath(scope.path);
  24302. loader.setRequestHeader(scope.requestHeader);
  24303. loader.setWithCredentials(scope.withCredentials);
  24304. loader.load(url, function (text) {
  24305. try {
  24306. onLoad(scope.parse(JSON.parse(text)));
  24307. } catch (e) {
  24308. if (onError) {
  24309. onError(e);
  24310. } else {
  24311. console.error(e);
  24312. }
  24313. scope.manager.itemError(url);
  24314. }
  24315. }, onProgress, onError);
  24316. },
  24317. parse: function parse(json) {
  24318. var textures = this.textures;
  24319. function getTexture(name) {
  24320. if (textures[name] === undefined) {
  24321. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24322. }
  24323. return textures[name];
  24324. }
  24325. var material = new Materials[json.type]();
  24326. if (json.uuid !== undefined) material.uuid = json.uuid;
  24327. if (json.name !== undefined) material.name = json.name;
  24328. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24329. if (json.roughness !== undefined) material.roughness = json.roughness;
  24330. if (json.metalness !== undefined) material.metalness = json.metalness;
  24331. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24332. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24333. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24334. if (json.shininess !== undefined) material.shininess = json.shininess;
  24335. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24336. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24337. if (json.fog !== undefined) material.fog = json.fog;
  24338. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24339. if (json.blending !== undefined) material.blending = json.blending;
  24340. if (json.combine !== undefined) material.combine = json.combine;
  24341. if (json.side !== undefined) material.side = json.side;
  24342. if (json.opacity !== undefined) material.opacity = json.opacity;
  24343. if (json.transparent !== undefined) material.transparent = json.transparent;
  24344. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24345. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24346. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24347. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24348. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24349. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24350. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24351. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24352. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24353. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24354. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24355. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24356. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24357. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24358. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24359. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24360. if (json.rotation !== undefined) material.rotation = json.rotation;
  24361. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24362. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24363. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24364. if (json.scale !== undefined) material.scale = json.scale;
  24365. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24366. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24367. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24368. if (json.skinning !== undefined) material.skinning = json.skinning;
  24369. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24370. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24371. if (json.dithering !== undefined) material.dithering = json.dithering;
  24372. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24373. if (json.visible !== undefined) material.visible = json.visible;
  24374. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24375. if (json.userData !== undefined) material.userData = json.userData;
  24376. if (json.vertexColors !== undefined) {
  24377. if (typeof json.vertexColors === 'number') {
  24378. material.vertexColors = json.vertexColors > 0 ? true : false;
  24379. } else {
  24380. material.vertexColors = json.vertexColors;
  24381. }
  24382. } // Shader Material
  24383. if (json.uniforms !== undefined) {
  24384. for (var name in json.uniforms) {
  24385. var uniform = json.uniforms[name];
  24386. material.uniforms[name] = {};
  24387. switch (uniform.type) {
  24388. case 't':
  24389. material.uniforms[name].value = getTexture(uniform.value);
  24390. break;
  24391. case 'c':
  24392. material.uniforms[name].value = new Color().setHex(uniform.value);
  24393. break;
  24394. case 'v2':
  24395. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24396. break;
  24397. case 'v3':
  24398. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24399. break;
  24400. case 'v4':
  24401. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24402. break;
  24403. case 'm3':
  24404. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24405. break;
  24406. case 'm4':
  24407. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24408. break;
  24409. default:
  24410. material.uniforms[name].value = uniform.value;
  24411. }
  24412. }
  24413. }
  24414. if (json.defines !== undefined) material.defines = json.defines;
  24415. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24416. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24417. if (json.extensions !== undefined) {
  24418. for (var key in json.extensions) {
  24419. material.extensions[key] = json.extensions[key];
  24420. }
  24421. } // Deprecated
  24422. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24423. // for PointsMaterial
  24424. if (json.size !== undefined) material.size = json.size;
  24425. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24426. if (json.map !== undefined) material.map = getTexture(json.map);
  24427. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24428. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24429. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24430. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24431. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24432. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24433. if (json.normalScale !== undefined) {
  24434. var normalScale = json.normalScale;
  24435. if (Array.isArray(normalScale) === false) {
  24436. // Blender exporter used to export a scalar. See #7459
  24437. normalScale = [normalScale, normalScale];
  24438. }
  24439. material.normalScale = new Vector2().fromArray(normalScale);
  24440. }
  24441. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24442. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24443. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24444. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24445. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24446. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24447. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24448. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24449. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24450. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24451. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24452. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24453. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24454. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24455. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24456. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24457. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24458. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24459. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24460. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24461. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24462. if (json.transmission !== undefined) material.transmission = json.transmission;
  24463. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24464. return material;
  24465. },
  24466. setTextures: function setTextures(value) {
  24467. this.textures = value;
  24468. return this;
  24469. }
  24470. });
  24471. var LoaderUtils = {
  24472. decodeText: function decodeText(array) {
  24473. if (typeof TextDecoder !== 'undefined') {
  24474. return new TextDecoder().decode(array);
  24475. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24476. // throws a "maximum call stack size exceeded" error for large arrays.
  24477. var s = '';
  24478. for (var i = 0, il = array.length; i < il; i++) {
  24479. // Implicitly assumes little-endian.
  24480. s += String.fromCharCode(array[i]);
  24481. }
  24482. try {
  24483. // merges multi-byte utf-8 characters.
  24484. return decodeURIComponent(escape(s));
  24485. } catch (e) {
  24486. // see #16358
  24487. return s;
  24488. }
  24489. },
  24490. extractUrlBase: function extractUrlBase(url) {
  24491. var index = url.lastIndexOf('/');
  24492. if (index === -1) return './';
  24493. return url.substr(0, index + 1);
  24494. }
  24495. };
  24496. function InstancedBufferGeometry() {
  24497. BufferGeometry.call(this);
  24498. this.type = 'InstancedBufferGeometry';
  24499. this.instanceCount = Infinity;
  24500. }
  24501. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24502. constructor: InstancedBufferGeometry,
  24503. isInstancedBufferGeometry: true,
  24504. copy: function copy(source) {
  24505. BufferGeometry.prototype.copy.call(this, source);
  24506. this.instanceCount = source.instanceCount;
  24507. return this;
  24508. },
  24509. clone: function clone() {
  24510. return new this.constructor().copy(this);
  24511. },
  24512. toJSON: function toJSON() {
  24513. var data = BufferGeometry.prototype.toJSON.call(this);
  24514. data.instanceCount = this.instanceCount;
  24515. data.isInstancedBufferGeometry = true;
  24516. return data;
  24517. }
  24518. });
  24519. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24520. if (typeof normalized === 'number') {
  24521. meshPerAttribute = normalized;
  24522. normalized = false;
  24523. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24524. }
  24525. BufferAttribute.call(this, array, itemSize, normalized);
  24526. this.meshPerAttribute = meshPerAttribute || 1;
  24527. }
  24528. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24529. constructor: InstancedBufferAttribute,
  24530. isInstancedBufferAttribute: true,
  24531. copy: function copy(source) {
  24532. BufferAttribute.prototype.copy.call(this, source);
  24533. this.meshPerAttribute = source.meshPerAttribute;
  24534. return this;
  24535. },
  24536. toJSON: function toJSON() {
  24537. var data = BufferAttribute.prototype.toJSON.call(this);
  24538. data.meshPerAttribute = this.meshPerAttribute;
  24539. data.isInstancedBufferAttribute = true;
  24540. return data;
  24541. }
  24542. });
  24543. function BufferGeometryLoader(manager) {
  24544. Loader.call(this, manager);
  24545. }
  24546. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24547. constructor: BufferGeometryLoader,
  24548. load: function load(url, onLoad, onProgress, onError) {
  24549. var scope = this;
  24550. var loader = new FileLoader(scope.manager);
  24551. loader.setPath(scope.path);
  24552. loader.setRequestHeader(scope.requestHeader);
  24553. loader.setWithCredentials(scope.withCredentials);
  24554. loader.load(url, function (text) {
  24555. try {
  24556. onLoad(scope.parse(JSON.parse(text)));
  24557. } catch (e) {
  24558. if (onError) {
  24559. onError(e);
  24560. } else {
  24561. console.error(e);
  24562. }
  24563. scope.manager.itemError(url);
  24564. }
  24565. }, onProgress, onError);
  24566. },
  24567. parse: function parse(json) {
  24568. var interleavedBufferMap = {};
  24569. var arrayBufferMap = {};
  24570. function getInterleavedBuffer(json, uuid) {
  24571. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24572. var interleavedBuffers = json.interleavedBuffers;
  24573. var interleavedBuffer = interleavedBuffers[uuid];
  24574. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24575. var array = getTypedArray(interleavedBuffer.type, buffer);
  24576. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24577. ib.uuid = interleavedBuffer.uuid;
  24578. interleavedBufferMap[uuid] = ib;
  24579. return ib;
  24580. }
  24581. function getArrayBuffer(json, uuid) {
  24582. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24583. var arrayBuffers = json.arrayBuffers;
  24584. var arrayBuffer = arrayBuffers[uuid];
  24585. var ab = new Uint32Array(arrayBuffer).buffer;
  24586. arrayBufferMap[uuid] = ab;
  24587. return ab;
  24588. }
  24589. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24590. var index = json.data.index;
  24591. if (index !== undefined) {
  24592. var typedArray = getTypedArray(index.type, index.array);
  24593. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24594. }
  24595. var attributes = json.data.attributes;
  24596. for (var key in attributes) {
  24597. var attribute = attributes[key];
  24598. var bufferAttribute = void 0;
  24599. if (attribute.isInterleavedBufferAttribute) {
  24600. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24601. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24602. } else {
  24603. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24604. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24605. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24606. }
  24607. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24608. geometry.setAttribute(key, bufferAttribute);
  24609. }
  24610. var morphAttributes = json.data.morphAttributes;
  24611. if (morphAttributes) {
  24612. for (var _key in morphAttributes) {
  24613. var attributeArray = morphAttributes[_key];
  24614. var array = [];
  24615. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24616. var _attribute = attributeArray[i];
  24617. var _bufferAttribute = void 0;
  24618. if (_attribute.isInterleavedBufferAttribute) {
  24619. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24620. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24621. } else {
  24622. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24623. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24624. }
  24625. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24626. array.push(_bufferAttribute);
  24627. }
  24628. geometry.morphAttributes[_key] = array;
  24629. }
  24630. }
  24631. var morphTargetsRelative = json.data.morphTargetsRelative;
  24632. if (morphTargetsRelative) {
  24633. geometry.morphTargetsRelative = true;
  24634. }
  24635. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24636. if (groups !== undefined) {
  24637. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24638. var group = groups[_i];
  24639. geometry.addGroup(group.start, group.count, group.materialIndex);
  24640. }
  24641. }
  24642. var boundingSphere = json.data.boundingSphere;
  24643. if (boundingSphere !== undefined) {
  24644. var center = new Vector3();
  24645. if (boundingSphere.center !== undefined) {
  24646. center.fromArray(boundingSphere.center);
  24647. }
  24648. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24649. }
  24650. if (json.name) geometry.name = json.name;
  24651. if (json.userData) geometry.userData = json.userData;
  24652. return geometry;
  24653. }
  24654. });
  24655. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24656. _inheritsLoose(ObjectLoader, _Loader);
  24657. function ObjectLoader(manager) {
  24658. return _Loader.call(this, manager) || this;
  24659. }
  24660. var _proto = ObjectLoader.prototype;
  24661. _proto.load = function load(url, onLoad, onProgress, onError) {
  24662. var scope = this;
  24663. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24664. this.resourcePath = this.resourcePath || path;
  24665. var loader = new FileLoader(this.manager);
  24666. loader.setPath(this.path);
  24667. loader.setRequestHeader(this.requestHeader);
  24668. loader.setWithCredentials(this.withCredentials);
  24669. loader.load(url, function (text) {
  24670. var json = null;
  24671. try {
  24672. json = JSON.parse(text);
  24673. } catch (error) {
  24674. if (onError !== undefined) onError(error);
  24675. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24676. return;
  24677. }
  24678. var metadata = json.metadata;
  24679. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24680. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24681. return;
  24682. }
  24683. scope.parse(json, onLoad);
  24684. }, onProgress, onError);
  24685. };
  24686. _proto.parse = function parse(json, onLoad) {
  24687. var animations = this.parseAnimations(json.animations);
  24688. var shapes = this.parseShapes(json.shapes);
  24689. var geometries = this.parseGeometries(json.geometries, shapes);
  24690. var images = this.parseImages(json.images, function () {
  24691. if (onLoad !== undefined) onLoad(object);
  24692. });
  24693. var textures = this.parseTextures(json.textures, images);
  24694. var materials = this.parseMaterials(json.materials, textures);
  24695. var object = this.parseObject(json.object, geometries, materials, animations);
  24696. var skeletons = this.parseSkeletons(json.skeletons, object);
  24697. this.bindSkeletons(object, skeletons); //
  24698. if (onLoad !== undefined) {
  24699. var hasImages = false;
  24700. for (var uuid in images) {
  24701. if (images[uuid] instanceof HTMLImageElement) {
  24702. hasImages = true;
  24703. break;
  24704. }
  24705. }
  24706. if (hasImages === false) onLoad(object);
  24707. }
  24708. return object;
  24709. };
  24710. _proto.parseShapes = function parseShapes(json) {
  24711. var shapes = {};
  24712. if (json !== undefined) {
  24713. for (var i = 0, l = json.length; i < l; i++) {
  24714. var shape = new Shape().fromJSON(json[i]);
  24715. shapes[shape.uuid] = shape;
  24716. }
  24717. }
  24718. return shapes;
  24719. };
  24720. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24721. var skeletons = {};
  24722. var bones = {}; // generate bone lookup table
  24723. object.traverse(function (child) {
  24724. if (child.isBone) bones[child.uuid] = child;
  24725. }); // create skeletons
  24726. if (json !== undefined) {
  24727. for (var i = 0, l = json.length; i < l; i++) {
  24728. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24729. skeletons[skeleton.uuid] = skeleton;
  24730. }
  24731. }
  24732. return skeletons;
  24733. };
  24734. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24735. var geometries = {};
  24736. var geometryShapes;
  24737. if (json !== undefined) {
  24738. var bufferGeometryLoader = new BufferGeometryLoader();
  24739. for (var i = 0, l = json.length; i < l; i++) {
  24740. var geometry = void 0;
  24741. var data = json[i];
  24742. switch (data.type) {
  24743. case 'PlaneGeometry':
  24744. case 'PlaneBufferGeometry':
  24745. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24746. break;
  24747. case 'BoxGeometry':
  24748. case 'BoxBufferGeometry':
  24749. case 'CubeGeometry':
  24750. // backwards compatible
  24751. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24752. break;
  24753. case 'CircleGeometry':
  24754. case 'CircleBufferGeometry':
  24755. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24756. break;
  24757. case 'CylinderGeometry':
  24758. case 'CylinderBufferGeometry':
  24759. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24760. break;
  24761. case 'ConeGeometry':
  24762. case 'ConeBufferGeometry':
  24763. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24764. break;
  24765. case 'SphereGeometry':
  24766. case 'SphereBufferGeometry':
  24767. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24768. break;
  24769. case 'DodecahedronGeometry':
  24770. case 'DodecahedronBufferGeometry':
  24771. case 'IcosahedronGeometry':
  24772. case 'IcosahedronBufferGeometry':
  24773. case 'OctahedronGeometry':
  24774. case 'OctahedronBufferGeometry':
  24775. case 'TetrahedronGeometry':
  24776. case 'TetrahedronBufferGeometry':
  24777. geometry = new Geometries[data.type](data.radius, data.detail);
  24778. break;
  24779. case 'RingGeometry':
  24780. case 'RingBufferGeometry':
  24781. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24782. break;
  24783. case 'TorusGeometry':
  24784. case 'TorusBufferGeometry':
  24785. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24786. break;
  24787. case 'TorusKnotGeometry':
  24788. case 'TorusKnotBufferGeometry':
  24789. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24790. break;
  24791. case 'TubeGeometry':
  24792. case 'TubeBufferGeometry':
  24793. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24794. // User defined curves or instances of CurvePath will not be deserialized.
  24795. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24796. break;
  24797. case 'LatheGeometry':
  24798. case 'LatheBufferGeometry':
  24799. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24800. break;
  24801. case 'PolyhedronGeometry':
  24802. case 'PolyhedronBufferGeometry':
  24803. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24804. break;
  24805. case 'ShapeGeometry':
  24806. case 'ShapeBufferGeometry':
  24807. geometryShapes = [];
  24808. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24809. var shape = shapes[data.shapes[j]];
  24810. geometryShapes.push(shape);
  24811. }
  24812. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24813. break;
  24814. case 'ExtrudeGeometry':
  24815. case 'ExtrudeBufferGeometry':
  24816. geometryShapes = [];
  24817. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24818. var _shape = shapes[data.shapes[_j]];
  24819. geometryShapes.push(_shape);
  24820. }
  24821. var extrudePath = data.options.extrudePath;
  24822. if (extrudePath !== undefined) {
  24823. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24824. }
  24825. geometry = new Geometries[data.type](geometryShapes, data.options);
  24826. break;
  24827. case 'BufferGeometry':
  24828. case 'InstancedBufferGeometry':
  24829. geometry = bufferGeometryLoader.parse(data);
  24830. break;
  24831. case 'Geometry':
  24832. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24833. break;
  24834. default:
  24835. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24836. continue;
  24837. }
  24838. geometry.uuid = data.uuid;
  24839. if (data.name !== undefined) geometry.name = data.name;
  24840. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24841. geometries[data.uuid] = geometry;
  24842. }
  24843. }
  24844. return geometries;
  24845. };
  24846. _proto.parseMaterials = function parseMaterials(json, textures) {
  24847. var cache = {}; // MultiMaterial
  24848. var materials = {};
  24849. if (json !== undefined) {
  24850. var loader = new MaterialLoader();
  24851. loader.setTextures(textures);
  24852. for (var i = 0, l = json.length; i < l; i++) {
  24853. var data = json[i];
  24854. if (data.type === 'MultiMaterial') {
  24855. // Deprecated
  24856. var array = [];
  24857. for (var j = 0; j < data.materials.length; j++) {
  24858. var material = data.materials[j];
  24859. if (cache[material.uuid] === undefined) {
  24860. cache[material.uuid] = loader.parse(material);
  24861. }
  24862. array.push(cache[material.uuid]);
  24863. }
  24864. materials[data.uuid] = array;
  24865. } else {
  24866. if (cache[data.uuid] === undefined) {
  24867. cache[data.uuid] = loader.parse(data);
  24868. }
  24869. materials[data.uuid] = cache[data.uuid];
  24870. }
  24871. }
  24872. }
  24873. return materials;
  24874. };
  24875. _proto.parseAnimations = function parseAnimations(json) {
  24876. var animations = {};
  24877. if (json !== undefined) {
  24878. for (var i = 0; i < json.length; i++) {
  24879. var data = json[i];
  24880. var clip = AnimationClip.parse(data);
  24881. animations[clip.uuid] = clip;
  24882. }
  24883. }
  24884. return animations;
  24885. };
  24886. _proto.parseImages = function parseImages(json, onLoad) {
  24887. var scope = this;
  24888. var images = {};
  24889. var loader;
  24890. function loadImage(url) {
  24891. scope.manager.itemStart(url);
  24892. return loader.load(url, function () {
  24893. scope.manager.itemEnd(url);
  24894. }, undefined, function () {
  24895. scope.manager.itemError(url);
  24896. scope.manager.itemEnd(url);
  24897. });
  24898. }
  24899. function deserializeImage(image) {
  24900. if (typeof image === 'string') {
  24901. var url = image;
  24902. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24903. return loadImage(path);
  24904. } else {
  24905. if (image.data) {
  24906. return {
  24907. data: getTypedArray(image.type, image.data),
  24908. width: image.width,
  24909. height: image.height
  24910. };
  24911. } else {
  24912. return null;
  24913. }
  24914. }
  24915. }
  24916. if (json !== undefined && json.length > 0) {
  24917. var manager = new LoadingManager(onLoad);
  24918. loader = new ImageLoader(manager);
  24919. loader.setCrossOrigin(this.crossOrigin);
  24920. for (var i = 0, il = json.length; i < il; i++) {
  24921. var image = json[i];
  24922. var url = image.url;
  24923. if (Array.isArray(url)) {
  24924. // load array of images e.g CubeTexture
  24925. images[image.uuid] = [];
  24926. for (var j = 0, jl = url.length; j < jl; j++) {
  24927. var currentUrl = url[j];
  24928. var deserializedImage = deserializeImage(currentUrl);
  24929. if (deserializedImage !== null) {
  24930. if (deserializedImage instanceof HTMLImageElement) {
  24931. images[image.uuid].push(deserializedImage);
  24932. } else {
  24933. // special case: handle array of data textures for cube textures
  24934. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24935. }
  24936. }
  24937. }
  24938. } else {
  24939. // load single image
  24940. var _deserializedImage = deserializeImage(image.url);
  24941. if (_deserializedImage !== null) {
  24942. images[image.uuid] = _deserializedImage;
  24943. }
  24944. }
  24945. }
  24946. }
  24947. return images;
  24948. };
  24949. _proto.parseTextures = function parseTextures(json, images) {
  24950. function parseConstant(value, type) {
  24951. if (typeof value === 'number') return value;
  24952. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24953. return type[value];
  24954. }
  24955. var textures = {};
  24956. if (json !== undefined) {
  24957. for (var i = 0, l = json.length; i < l; i++) {
  24958. var data = json[i];
  24959. if (data.image === undefined) {
  24960. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24961. }
  24962. if (images[data.image] === undefined) {
  24963. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24964. }
  24965. var texture = void 0;
  24966. var image = images[data.image];
  24967. if (Array.isArray(image)) {
  24968. texture = new CubeTexture(image);
  24969. if (image.length === 6) texture.needsUpdate = true;
  24970. } else {
  24971. if (image && image.data) {
  24972. texture = new DataTexture(image.data, image.width, image.height);
  24973. } else {
  24974. texture = new Texture(image);
  24975. }
  24976. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24977. }
  24978. texture.uuid = data.uuid;
  24979. if (data.name !== undefined) texture.name = data.name;
  24980. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24981. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24982. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24983. if (data.center !== undefined) texture.center.fromArray(data.center);
  24984. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24985. if (data.wrap !== undefined) {
  24986. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24987. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24988. }
  24989. if (data.format !== undefined) texture.format = data.format;
  24990. if (data.type !== undefined) texture.type = data.type;
  24991. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24992. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24993. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24994. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24995. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24996. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24997. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24998. textures[data.uuid] = texture;
  24999. }
  25000. }
  25001. return textures;
  25002. };
  25003. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  25004. var object;
  25005. function getGeometry(name) {
  25006. if (geometries[name] === undefined) {
  25007. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  25008. }
  25009. return geometries[name];
  25010. }
  25011. function getMaterial(name) {
  25012. if (name === undefined) return undefined;
  25013. if (Array.isArray(name)) {
  25014. var array = [];
  25015. for (var i = 0, l = name.length; i < l; i++) {
  25016. var uuid = name[i];
  25017. if (materials[uuid] === undefined) {
  25018. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  25019. }
  25020. array.push(materials[uuid]);
  25021. }
  25022. return array;
  25023. }
  25024. if (materials[name] === undefined) {
  25025. console.warn('THREE.ObjectLoader: Undefined material', name);
  25026. }
  25027. return materials[name];
  25028. }
  25029. var geometry, material;
  25030. switch (data.type) {
  25031. case 'Scene':
  25032. object = new Scene();
  25033. if (data.background !== undefined) {
  25034. if (Number.isInteger(data.background)) {
  25035. object.background = new Color(data.background);
  25036. }
  25037. }
  25038. if (data.fog !== undefined) {
  25039. if (data.fog.type === 'Fog') {
  25040. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  25041. } else if (data.fog.type === 'FogExp2') {
  25042. object.fog = new FogExp2(data.fog.color, data.fog.density);
  25043. }
  25044. }
  25045. break;
  25046. case 'PerspectiveCamera':
  25047. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  25048. if (data.focus !== undefined) object.focus = data.focus;
  25049. if (data.zoom !== undefined) object.zoom = data.zoom;
  25050. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  25051. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  25052. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25053. break;
  25054. case 'OrthographicCamera':
  25055. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  25056. if (data.zoom !== undefined) object.zoom = data.zoom;
  25057. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  25058. break;
  25059. case 'AmbientLight':
  25060. object = new AmbientLight(data.color, data.intensity);
  25061. break;
  25062. case 'DirectionalLight':
  25063. object = new DirectionalLight(data.color, data.intensity);
  25064. break;
  25065. case 'PointLight':
  25066. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  25067. break;
  25068. case 'RectAreaLight':
  25069. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  25070. break;
  25071. case 'SpotLight':
  25072. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  25073. break;
  25074. case 'HemisphereLight':
  25075. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  25076. break;
  25077. case 'LightProbe':
  25078. object = new LightProbe().fromJSON(data);
  25079. break;
  25080. case 'SkinnedMesh':
  25081. geometry = getGeometry(data.geometry);
  25082. material = getMaterial(data.material);
  25083. object = new SkinnedMesh(geometry, material);
  25084. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  25085. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  25086. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  25087. break;
  25088. case 'Mesh':
  25089. geometry = getGeometry(data.geometry);
  25090. material = getMaterial(data.material);
  25091. object = new Mesh(geometry, material);
  25092. break;
  25093. case 'InstancedMesh':
  25094. geometry = getGeometry(data.geometry);
  25095. material = getMaterial(data.material);
  25096. var count = data.count;
  25097. var instanceMatrix = data.instanceMatrix;
  25098. object = new InstancedMesh(geometry, material, count);
  25099. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  25100. break;
  25101. case 'LOD':
  25102. object = new LOD();
  25103. break;
  25104. case 'Line':
  25105. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  25106. break;
  25107. case 'LineLoop':
  25108. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  25109. break;
  25110. case 'LineSegments':
  25111. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  25112. break;
  25113. case 'PointCloud':
  25114. case 'Points':
  25115. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  25116. break;
  25117. case 'Sprite':
  25118. object = new Sprite(getMaterial(data.material));
  25119. break;
  25120. case 'Group':
  25121. object = new Group();
  25122. break;
  25123. case 'Bone':
  25124. object = new Bone();
  25125. break;
  25126. default:
  25127. object = new Object3D();
  25128. }
  25129. object.uuid = data.uuid;
  25130. if (data.name !== undefined) object.name = data.name;
  25131. if (data.matrix !== undefined) {
  25132. object.matrix.fromArray(data.matrix);
  25133. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  25134. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  25135. } else {
  25136. if (data.position !== undefined) object.position.fromArray(data.position);
  25137. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  25138. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  25139. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  25140. }
  25141. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  25142. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  25143. if (data.shadow) {
  25144. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  25145. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  25146. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  25147. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  25148. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  25149. }
  25150. if (data.visible !== undefined) object.visible = data.visible;
  25151. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  25152. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  25153. if (data.userData !== undefined) object.userData = data.userData;
  25154. if (data.layers !== undefined) object.layers.mask = data.layers;
  25155. if (data.children !== undefined) {
  25156. var children = data.children;
  25157. for (var i = 0; i < children.length; i++) {
  25158. object.add(this.parseObject(children[i], geometries, materials, animations));
  25159. }
  25160. }
  25161. if (data.animations !== undefined) {
  25162. var objectAnimations = data.animations;
  25163. for (var _i = 0; _i < objectAnimations.length; _i++) {
  25164. var uuid = objectAnimations[_i];
  25165. object.animations.push(animations[uuid]);
  25166. }
  25167. }
  25168. if (data.type === 'LOD') {
  25169. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  25170. var levels = data.levels;
  25171. for (var l = 0; l < levels.length; l++) {
  25172. var level = levels[l];
  25173. var child = object.getObjectByProperty('uuid', level.object);
  25174. if (child !== undefined) {
  25175. object.addLevel(child, level.distance);
  25176. }
  25177. }
  25178. }
  25179. return object;
  25180. };
  25181. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  25182. if (Object.keys(skeletons).length === 0) return;
  25183. object.traverse(function (child) {
  25184. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  25185. var skeleton = skeletons[child.skeleton];
  25186. if (skeleton === undefined) {
  25187. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  25188. } else {
  25189. child.bind(skeleton, child.bindMatrix);
  25190. }
  25191. }
  25192. });
  25193. }
  25194. /* DEPRECATED */
  25195. ;
  25196. _proto.setTexturePath = function setTexturePath(value) {
  25197. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  25198. return this.setResourcePath(value);
  25199. };
  25200. return ObjectLoader;
  25201. }(Loader);
  25202. var TEXTURE_MAPPING = {
  25203. UVMapping: UVMapping,
  25204. CubeReflectionMapping: CubeReflectionMapping,
  25205. CubeRefractionMapping: CubeRefractionMapping,
  25206. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25207. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25208. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25209. CubeUVRefractionMapping: CubeUVRefractionMapping
  25210. };
  25211. var TEXTURE_WRAPPING = {
  25212. RepeatWrapping: RepeatWrapping,
  25213. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25214. MirroredRepeatWrapping: MirroredRepeatWrapping
  25215. };
  25216. var TEXTURE_FILTER = {
  25217. NearestFilter: NearestFilter,
  25218. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25219. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25220. LinearFilter: LinearFilter,
  25221. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25222. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25223. };
  25224. function ImageBitmapLoader(manager) {
  25225. if (typeof createImageBitmap === 'undefined') {
  25226. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25227. }
  25228. if (typeof fetch === 'undefined') {
  25229. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25230. }
  25231. Loader.call(this, manager);
  25232. this.options = {
  25233. premultiplyAlpha: 'none'
  25234. };
  25235. }
  25236. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25237. constructor: ImageBitmapLoader,
  25238. isImageBitmapLoader: true,
  25239. setOptions: function setOptions(options) {
  25240. this.options = options;
  25241. return this;
  25242. },
  25243. load: function load(url, onLoad, onProgress, onError) {
  25244. if (url === undefined) url = '';
  25245. if (this.path !== undefined) url = this.path + url;
  25246. url = this.manager.resolveURL(url);
  25247. var scope = this;
  25248. var cached = Cache.get(url);
  25249. if (cached !== undefined) {
  25250. scope.manager.itemStart(url);
  25251. setTimeout(function () {
  25252. if (onLoad) onLoad(cached);
  25253. scope.manager.itemEnd(url);
  25254. }, 0);
  25255. return cached;
  25256. }
  25257. var fetchOptions = {};
  25258. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25259. fetch(url, fetchOptions).then(function (res) {
  25260. return res.blob();
  25261. }).then(function (blob) {
  25262. return createImageBitmap(blob, scope.options);
  25263. }).then(function (imageBitmap) {
  25264. Cache.add(url, imageBitmap);
  25265. if (onLoad) onLoad(imageBitmap);
  25266. scope.manager.itemEnd(url);
  25267. }).catch(function (e) {
  25268. if (onError) onError(e);
  25269. scope.manager.itemError(url);
  25270. scope.manager.itemEnd(url);
  25271. });
  25272. scope.manager.itemStart(url);
  25273. }
  25274. });
  25275. function ShapePath() {
  25276. this.type = 'ShapePath';
  25277. this.color = new Color();
  25278. this.subPaths = [];
  25279. this.currentPath = null;
  25280. }
  25281. Object.assign(ShapePath.prototype, {
  25282. moveTo: function moveTo(x, y) {
  25283. this.currentPath = new Path();
  25284. this.subPaths.push(this.currentPath);
  25285. this.currentPath.moveTo(x, y);
  25286. return this;
  25287. },
  25288. lineTo: function lineTo(x, y) {
  25289. this.currentPath.lineTo(x, y);
  25290. return this;
  25291. },
  25292. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25293. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25294. return this;
  25295. },
  25296. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25297. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25298. return this;
  25299. },
  25300. splineThru: function splineThru(pts) {
  25301. this.currentPath.splineThru(pts);
  25302. return this;
  25303. },
  25304. toShapes: function toShapes(isCCW, noHoles) {
  25305. function toShapesNoHoles(inSubpaths) {
  25306. var shapes = [];
  25307. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25308. var _tmpPath = inSubpaths[i];
  25309. var _tmpShape = new Shape();
  25310. _tmpShape.curves = _tmpPath.curves;
  25311. shapes.push(_tmpShape);
  25312. }
  25313. return shapes;
  25314. }
  25315. function isPointInsidePolygon(inPt, inPolygon) {
  25316. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25317. // toggling of inside/outside at every single! intersection point of an edge
  25318. // with the horizontal line through inPt, left of inPt
  25319. // not counting lowerY endpoints of edges and whole edges on that line
  25320. var inside = false;
  25321. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25322. var edgeLowPt = inPolygon[p];
  25323. var edgeHighPt = inPolygon[q];
  25324. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25325. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25326. if (Math.abs(edgeDy) > Number.EPSILON) {
  25327. // not parallel
  25328. if (edgeDy < 0) {
  25329. edgeLowPt = inPolygon[q];
  25330. edgeDx = -edgeDx;
  25331. edgeHighPt = inPolygon[p];
  25332. edgeDy = -edgeDy;
  25333. }
  25334. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25335. if (inPt.y === edgeLowPt.y) {
  25336. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25337. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25338. } else {
  25339. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25340. if (perpEdge === 0) return true; // inPt is on contour ?
  25341. if (perpEdge < 0) continue;
  25342. inside = !inside; // true intersection left of inPt
  25343. }
  25344. } else {
  25345. // parallel or collinear
  25346. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25347. // edge lies on the same horizontal line as inPt
  25348. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25349. // continue;
  25350. }
  25351. }
  25352. return inside;
  25353. }
  25354. var isClockWise = ShapeUtils.isClockWise;
  25355. var subPaths = this.subPaths;
  25356. if (subPaths.length === 0) return [];
  25357. if (noHoles === true) return toShapesNoHoles(subPaths);
  25358. var solid, tmpPath, tmpShape;
  25359. var shapes = [];
  25360. if (subPaths.length === 1) {
  25361. tmpPath = subPaths[0];
  25362. tmpShape = new Shape();
  25363. tmpShape.curves = tmpPath.curves;
  25364. shapes.push(tmpShape);
  25365. return shapes;
  25366. }
  25367. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25368. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25369. var betterShapeHoles = [];
  25370. var newShapes = [];
  25371. var newShapeHoles = [];
  25372. var mainIdx = 0;
  25373. var tmpPoints;
  25374. newShapes[mainIdx] = undefined;
  25375. newShapeHoles[mainIdx] = [];
  25376. for (var i = 0, l = subPaths.length; i < l; i++) {
  25377. tmpPath = subPaths[i];
  25378. tmpPoints = tmpPath.getPoints();
  25379. solid = isClockWise(tmpPoints);
  25380. solid = isCCW ? !solid : solid;
  25381. if (solid) {
  25382. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25383. newShapes[mainIdx] = {
  25384. s: new Shape(),
  25385. p: tmpPoints
  25386. };
  25387. newShapes[mainIdx].s.curves = tmpPath.curves;
  25388. if (holesFirst) mainIdx++;
  25389. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25390. } else {
  25391. newShapeHoles[mainIdx].push({
  25392. h: tmpPath,
  25393. p: tmpPoints[0]
  25394. }); //console.log('ccw', i);
  25395. }
  25396. } // only Holes? -> probably all Shapes with wrong orientation
  25397. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25398. if (newShapes.length > 1) {
  25399. var ambiguous = false;
  25400. var toChange = [];
  25401. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25402. betterShapeHoles[sIdx] = [];
  25403. }
  25404. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25405. var sho = newShapeHoles[_sIdx];
  25406. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25407. var ho = sho[hIdx];
  25408. var hole_unassigned = true;
  25409. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25410. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25411. if (_sIdx !== s2Idx) toChange.push({
  25412. froms: _sIdx,
  25413. tos: s2Idx,
  25414. hole: hIdx
  25415. });
  25416. if (hole_unassigned) {
  25417. hole_unassigned = false;
  25418. betterShapeHoles[s2Idx].push(ho);
  25419. } else {
  25420. ambiguous = true;
  25421. }
  25422. }
  25423. }
  25424. if (hole_unassigned) {
  25425. betterShapeHoles[_sIdx].push(ho);
  25426. }
  25427. }
  25428. } // console.log("ambiguous: ", ambiguous);
  25429. if (toChange.length > 0) {
  25430. // console.log("to change: ", toChange);
  25431. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25432. }
  25433. }
  25434. var tmpHoles;
  25435. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25436. tmpShape = newShapes[_i].s;
  25437. shapes.push(tmpShape);
  25438. tmpHoles = newShapeHoles[_i];
  25439. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25440. tmpShape.holes.push(tmpHoles[j].h);
  25441. }
  25442. } //console.log("shape", shapes);
  25443. return shapes;
  25444. }
  25445. });
  25446. function Font(data) {
  25447. this.type = 'Font';
  25448. this.data = data;
  25449. }
  25450. Object.assign(Font.prototype, {
  25451. isFont: true,
  25452. generateShapes: function generateShapes(text, size) {
  25453. if (size === void 0) {
  25454. size = 100;
  25455. }
  25456. var shapes = [];
  25457. var paths = createPaths(text, size, this.data);
  25458. for (var p = 0, pl = paths.length; p < pl; p++) {
  25459. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25460. }
  25461. return shapes;
  25462. }
  25463. });
  25464. function createPaths(text, size, data) {
  25465. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25466. var scale = size / data.resolution;
  25467. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25468. var paths = [];
  25469. var offsetX = 0,
  25470. offsetY = 0;
  25471. for (var i = 0; i < chars.length; i++) {
  25472. var char = chars[i];
  25473. if (char === '\n') {
  25474. offsetX = 0;
  25475. offsetY -= line_height;
  25476. } else {
  25477. var ret = createPath(char, scale, offsetX, offsetY, data);
  25478. offsetX += ret.offsetX;
  25479. paths.push(ret.path);
  25480. }
  25481. }
  25482. return paths;
  25483. }
  25484. function createPath(char, scale, offsetX, offsetY, data) {
  25485. var glyph = data.glyphs[char] || data.glyphs['?'];
  25486. if (!glyph) {
  25487. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25488. return;
  25489. }
  25490. var path = new ShapePath();
  25491. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25492. if (glyph.o) {
  25493. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25494. for (var i = 0, l = outline.length; i < l;) {
  25495. var action = outline[i++];
  25496. switch (action) {
  25497. case 'm':
  25498. // moveTo
  25499. x = outline[i++] * scale + offsetX;
  25500. y = outline[i++] * scale + offsetY;
  25501. path.moveTo(x, y);
  25502. break;
  25503. case 'l':
  25504. // lineTo
  25505. x = outline[i++] * scale + offsetX;
  25506. y = outline[i++] * scale + offsetY;
  25507. path.lineTo(x, y);
  25508. break;
  25509. case 'q':
  25510. // quadraticCurveTo
  25511. cpx = outline[i++] * scale + offsetX;
  25512. cpy = outline[i++] * scale + offsetY;
  25513. cpx1 = outline[i++] * scale + offsetX;
  25514. cpy1 = outline[i++] * scale + offsetY;
  25515. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25516. break;
  25517. case 'b':
  25518. // bezierCurveTo
  25519. cpx = outline[i++] * scale + offsetX;
  25520. cpy = outline[i++] * scale + offsetY;
  25521. cpx1 = outline[i++] * scale + offsetX;
  25522. cpy1 = outline[i++] * scale + offsetY;
  25523. cpx2 = outline[i++] * scale + offsetX;
  25524. cpy2 = outline[i++] * scale + offsetY;
  25525. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25526. break;
  25527. }
  25528. }
  25529. }
  25530. return {
  25531. offsetX: glyph.ha * scale,
  25532. path: path
  25533. };
  25534. }
  25535. function FontLoader(manager) {
  25536. Loader.call(this, manager);
  25537. }
  25538. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25539. constructor: FontLoader,
  25540. load: function load(url, onLoad, onProgress, onError) {
  25541. var scope = this;
  25542. var loader = new FileLoader(this.manager);
  25543. loader.setPath(this.path);
  25544. loader.setRequestHeader(this.requestHeader);
  25545. loader.setWithCredentials(scope.withCredentials);
  25546. loader.load(url, function (text) {
  25547. var json;
  25548. try {
  25549. json = JSON.parse(text);
  25550. } catch (e) {
  25551. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25552. json = JSON.parse(text.substring(65, text.length - 2));
  25553. }
  25554. var font = scope.parse(json);
  25555. if (onLoad) onLoad(font);
  25556. }, onProgress, onError);
  25557. },
  25558. parse: function parse(json) {
  25559. return new Font(json);
  25560. }
  25561. });
  25562. var _context;
  25563. var AudioContext = {
  25564. getContext: function getContext() {
  25565. if (_context === undefined) {
  25566. _context = new (window.AudioContext || window.webkitAudioContext)();
  25567. }
  25568. return _context;
  25569. },
  25570. setContext: function setContext(value) {
  25571. _context = value;
  25572. }
  25573. };
  25574. function AudioLoader(manager) {
  25575. Loader.call(this, manager);
  25576. }
  25577. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25578. constructor: AudioLoader,
  25579. load: function load(url, onLoad, onProgress, onError) {
  25580. var scope = this;
  25581. var loader = new FileLoader(scope.manager);
  25582. loader.setResponseType('arraybuffer');
  25583. loader.setPath(scope.path);
  25584. loader.setRequestHeader(scope.requestHeader);
  25585. loader.setWithCredentials(scope.withCredentials);
  25586. loader.load(url, function (buffer) {
  25587. try {
  25588. // Create a copy of the buffer. The `decodeAudioData` method
  25589. // detaches the buffer when complete, preventing reuse.
  25590. var bufferCopy = buffer.slice(0);
  25591. var context = AudioContext.getContext();
  25592. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25593. onLoad(audioBuffer);
  25594. });
  25595. } catch (e) {
  25596. if (onError) {
  25597. onError(e);
  25598. } else {
  25599. console.error(e);
  25600. }
  25601. scope.manager.itemError(url);
  25602. }
  25603. }, onProgress, onError);
  25604. }
  25605. });
  25606. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25607. LightProbe.call(this, undefined, intensity);
  25608. var color1 = new Color().set(skyColor);
  25609. var color2 = new Color().set(groundColor);
  25610. var sky = new Vector3(color1.r, color1.g, color1.b);
  25611. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25612. var c0 = Math.sqrt(Math.PI);
  25613. var c1 = c0 * Math.sqrt(0.75);
  25614. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25615. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25616. }
  25617. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25618. constructor: HemisphereLightProbe,
  25619. isHemisphereLightProbe: true,
  25620. copy: function copy(source) {
  25621. // modifying colors not currently supported
  25622. LightProbe.prototype.copy.call(this, source);
  25623. return this;
  25624. },
  25625. toJSON: function toJSON(meta) {
  25626. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25627. return data;
  25628. }
  25629. });
  25630. function AmbientLightProbe(color, intensity) {
  25631. LightProbe.call(this, undefined, intensity);
  25632. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25633. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25634. }
  25635. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25636. constructor: AmbientLightProbe,
  25637. isAmbientLightProbe: true,
  25638. copy: function copy(source) {
  25639. // modifying color not currently supported
  25640. LightProbe.prototype.copy.call(this, source);
  25641. return this;
  25642. },
  25643. toJSON: function toJSON(meta) {
  25644. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25645. return data;
  25646. }
  25647. });
  25648. var _eyeRight = new Matrix4();
  25649. var _eyeLeft = new Matrix4();
  25650. function StereoCamera() {
  25651. this.type = 'StereoCamera';
  25652. this.aspect = 1;
  25653. this.eyeSep = 0.064;
  25654. this.cameraL = new PerspectiveCamera();
  25655. this.cameraL.layers.enable(1);
  25656. this.cameraL.matrixAutoUpdate = false;
  25657. this.cameraR = new PerspectiveCamera();
  25658. this.cameraR.layers.enable(2);
  25659. this.cameraR.matrixAutoUpdate = false;
  25660. this._cache = {
  25661. focus: null,
  25662. fov: null,
  25663. aspect: null,
  25664. near: null,
  25665. far: null,
  25666. zoom: null,
  25667. eyeSep: null
  25668. };
  25669. }
  25670. Object.assign(StereoCamera.prototype, {
  25671. update: function update(camera) {
  25672. var cache = this._cache;
  25673. 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;
  25674. if (needsUpdate) {
  25675. cache.focus = camera.focus;
  25676. cache.fov = camera.fov;
  25677. cache.aspect = camera.aspect * this.aspect;
  25678. cache.near = camera.near;
  25679. cache.far = camera.far;
  25680. cache.zoom = camera.zoom;
  25681. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25682. // http://paulbourke.net/stereographics/stereorender/
  25683. var projectionMatrix = camera.projectionMatrix.clone();
  25684. var eyeSepHalf = cache.eyeSep / 2;
  25685. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25686. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25687. var xmin, xmax; // translate xOffset
  25688. _eyeLeft.elements[12] = -eyeSepHalf;
  25689. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25690. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25691. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25692. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25693. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25694. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25695. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25696. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25697. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25698. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25699. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25700. }
  25701. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25702. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25703. }
  25704. });
  25705. var Clock = /*#__PURE__*/function () {
  25706. function Clock(autoStart) {
  25707. this.autoStart = autoStart !== undefined ? autoStart : true;
  25708. this.startTime = 0;
  25709. this.oldTime = 0;
  25710. this.elapsedTime = 0;
  25711. this.running = false;
  25712. }
  25713. var _proto = Clock.prototype;
  25714. _proto.start = function start() {
  25715. this.startTime = now();
  25716. this.oldTime = this.startTime;
  25717. this.elapsedTime = 0;
  25718. this.running = true;
  25719. };
  25720. _proto.stop = function stop() {
  25721. this.getElapsedTime();
  25722. this.running = false;
  25723. this.autoStart = false;
  25724. };
  25725. _proto.getElapsedTime = function getElapsedTime() {
  25726. this.getDelta();
  25727. return this.elapsedTime;
  25728. };
  25729. _proto.getDelta = function getDelta() {
  25730. var diff = 0;
  25731. if (this.autoStart && !this.running) {
  25732. this.start();
  25733. return 0;
  25734. }
  25735. if (this.running) {
  25736. var newTime = now();
  25737. diff = (newTime - this.oldTime) / 1000;
  25738. this.oldTime = newTime;
  25739. this.elapsedTime += diff;
  25740. }
  25741. return diff;
  25742. };
  25743. return Clock;
  25744. }();
  25745. function now() {
  25746. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25747. }
  25748. var _position$2 = /*@__PURE__*/new Vector3();
  25749. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25750. var _scale$1 = /*@__PURE__*/new Vector3();
  25751. var _orientation = /*@__PURE__*/new Vector3();
  25752. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25753. _inheritsLoose(AudioListener, _Object3D);
  25754. function AudioListener() {
  25755. var _this;
  25756. _this = _Object3D.call(this) || this;
  25757. _this.type = 'AudioListener';
  25758. _this.context = AudioContext.getContext();
  25759. _this.gain = _this.context.createGain();
  25760. _this.gain.connect(_this.context.destination);
  25761. _this.filter = null;
  25762. _this.timeDelta = 0; // private
  25763. _this._clock = new Clock();
  25764. return _this;
  25765. }
  25766. var _proto = AudioListener.prototype;
  25767. _proto.getInput = function getInput() {
  25768. return this.gain;
  25769. };
  25770. _proto.removeFilter = function removeFilter() {
  25771. if (this.filter !== null) {
  25772. this.gain.disconnect(this.filter);
  25773. this.filter.disconnect(this.context.destination);
  25774. this.gain.connect(this.context.destination);
  25775. this.filter = null;
  25776. }
  25777. return this;
  25778. };
  25779. _proto.getFilter = function getFilter() {
  25780. return this.filter;
  25781. };
  25782. _proto.setFilter = function setFilter(value) {
  25783. if (this.filter !== null) {
  25784. this.gain.disconnect(this.filter);
  25785. this.filter.disconnect(this.context.destination);
  25786. } else {
  25787. this.gain.disconnect(this.context.destination);
  25788. }
  25789. this.filter = value;
  25790. this.gain.connect(this.filter);
  25791. this.filter.connect(this.context.destination);
  25792. return this;
  25793. };
  25794. _proto.getMasterVolume = function getMasterVolume() {
  25795. return this.gain.gain.value;
  25796. };
  25797. _proto.setMasterVolume = function setMasterVolume(value) {
  25798. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25799. return this;
  25800. };
  25801. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25802. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25803. var listener = this.context.listener;
  25804. var up = this.up;
  25805. this.timeDelta = this._clock.getDelta();
  25806. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25807. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25808. if (listener.positionX) {
  25809. // code path for Chrome (see #14393)
  25810. var endTime = this.context.currentTime + this.timeDelta;
  25811. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25812. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25813. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25814. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25815. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25816. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25817. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25818. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25819. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25820. } else {
  25821. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25822. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25823. }
  25824. };
  25825. return AudioListener;
  25826. }(Object3D);
  25827. var Audio = /*#__PURE__*/function (_Object3D) {
  25828. _inheritsLoose(Audio, _Object3D);
  25829. function Audio(listener) {
  25830. var _this;
  25831. _this = _Object3D.call(this) || this;
  25832. _this.type = 'Audio';
  25833. _this.listener = listener;
  25834. _this.context = listener.context;
  25835. _this.gain = _this.context.createGain();
  25836. _this.gain.connect(listener.getInput());
  25837. _this.autoplay = false;
  25838. _this.buffer = null;
  25839. _this.detune = 0;
  25840. _this.loop = false;
  25841. _this.loopStart = 0;
  25842. _this.loopEnd = 0;
  25843. _this.offset = 0;
  25844. _this.duration = undefined;
  25845. _this.playbackRate = 1;
  25846. _this.isPlaying = false;
  25847. _this.hasPlaybackControl = true;
  25848. _this.source = null;
  25849. _this.sourceType = 'empty';
  25850. _this._startedAt = 0;
  25851. _this._progress = 0;
  25852. _this._connected = false;
  25853. _this.filters = [];
  25854. return _this;
  25855. }
  25856. var _proto = Audio.prototype;
  25857. _proto.getOutput = function getOutput() {
  25858. return this.gain;
  25859. };
  25860. _proto.setNodeSource = function setNodeSource(audioNode) {
  25861. this.hasPlaybackControl = false;
  25862. this.sourceType = 'audioNode';
  25863. this.source = audioNode;
  25864. this.connect();
  25865. return this;
  25866. };
  25867. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25868. this.hasPlaybackControl = false;
  25869. this.sourceType = 'mediaNode';
  25870. this.source = this.context.createMediaElementSource(mediaElement);
  25871. this.connect();
  25872. return this;
  25873. };
  25874. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25875. this.hasPlaybackControl = false;
  25876. this.sourceType = 'mediaStreamNode';
  25877. this.source = this.context.createMediaStreamSource(mediaStream);
  25878. this.connect();
  25879. return this;
  25880. };
  25881. _proto.setBuffer = function setBuffer(audioBuffer) {
  25882. this.buffer = audioBuffer;
  25883. this.sourceType = 'buffer';
  25884. if (this.autoplay) this.play();
  25885. return this;
  25886. };
  25887. _proto.play = function play(delay) {
  25888. if (delay === void 0) {
  25889. delay = 0;
  25890. }
  25891. if (this.isPlaying === true) {
  25892. console.warn('THREE.Audio: Audio is already playing.');
  25893. return;
  25894. }
  25895. if (this.hasPlaybackControl === false) {
  25896. console.warn('THREE.Audio: this Audio has no playback control.');
  25897. return;
  25898. }
  25899. this._startedAt = this.context.currentTime + delay;
  25900. var source = this.context.createBufferSource();
  25901. source.buffer = this.buffer;
  25902. source.loop = this.loop;
  25903. source.loopStart = this.loopStart;
  25904. source.loopEnd = this.loopEnd;
  25905. source.onended = this.onEnded.bind(this);
  25906. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25907. this.isPlaying = true;
  25908. this.source = source;
  25909. this.setDetune(this.detune);
  25910. this.setPlaybackRate(this.playbackRate);
  25911. return this.connect();
  25912. };
  25913. _proto.pause = function pause() {
  25914. if (this.hasPlaybackControl === false) {
  25915. console.warn('THREE.Audio: this Audio has no playback control.');
  25916. return;
  25917. }
  25918. if (this.isPlaying === true) {
  25919. // update current progress
  25920. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25921. if (this.loop === true) {
  25922. // ensure _progress does not exceed duration with looped audios
  25923. this._progress = this._progress % (this.duration || this.buffer.duration);
  25924. }
  25925. this.source.stop();
  25926. this.source.onended = null;
  25927. this.isPlaying = false;
  25928. }
  25929. return this;
  25930. };
  25931. _proto.stop = function stop() {
  25932. if (this.hasPlaybackControl === false) {
  25933. console.warn('THREE.Audio: this Audio has no playback control.');
  25934. return;
  25935. }
  25936. this._progress = 0;
  25937. this.source.stop();
  25938. this.source.onended = null;
  25939. this.isPlaying = false;
  25940. return this;
  25941. };
  25942. _proto.connect = function connect() {
  25943. if (this.filters.length > 0) {
  25944. this.source.connect(this.filters[0]);
  25945. for (var i = 1, l = this.filters.length; i < l; i++) {
  25946. this.filters[i - 1].connect(this.filters[i]);
  25947. }
  25948. this.filters[this.filters.length - 1].connect(this.getOutput());
  25949. } else {
  25950. this.source.connect(this.getOutput());
  25951. }
  25952. this._connected = true;
  25953. return this;
  25954. };
  25955. _proto.disconnect = function disconnect() {
  25956. if (this.filters.length > 0) {
  25957. this.source.disconnect(this.filters[0]);
  25958. for (var i = 1, l = this.filters.length; i < l; i++) {
  25959. this.filters[i - 1].disconnect(this.filters[i]);
  25960. }
  25961. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25962. } else {
  25963. this.source.disconnect(this.getOutput());
  25964. }
  25965. this._connected = false;
  25966. return this;
  25967. };
  25968. _proto.getFilters = function getFilters() {
  25969. return this.filters;
  25970. };
  25971. _proto.setFilters = function setFilters(value) {
  25972. if (!value) value = [];
  25973. if (this._connected === true) {
  25974. this.disconnect();
  25975. this.filters = value.slice();
  25976. this.connect();
  25977. } else {
  25978. this.filters = value.slice();
  25979. }
  25980. return this;
  25981. };
  25982. _proto.setDetune = function setDetune(value) {
  25983. this.detune = value;
  25984. if (this.source.detune === undefined) return; // only set detune when available
  25985. if (this.isPlaying === true) {
  25986. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25987. }
  25988. return this;
  25989. };
  25990. _proto.getDetune = function getDetune() {
  25991. return this.detune;
  25992. };
  25993. _proto.getFilter = function getFilter() {
  25994. return this.getFilters()[0];
  25995. };
  25996. _proto.setFilter = function setFilter(filter) {
  25997. return this.setFilters(filter ? [filter] : []);
  25998. };
  25999. _proto.setPlaybackRate = function setPlaybackRate(value) {
  26000. if (this.hasPlaybackControl === false) {
  26001. console.warn('THREE.Audio: this Audio has no playback control.');
  26002. return;
  26003. }
  26004. this.playbackRate = value;
  26005. if (this.isPlaying === true) {
  26006. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  26007. }
  26008. return this;
  26009. };
  26010. _proto.getPlaybackRate = function getPlaybackRate() {
  26011. return this.playbackRate;
  26012. };
  26013. _proto.onEnded = function onEnded() {
  26014. this.isPlaying = false;
  26015. };
  26016. _proto.getLoop = function getLoop() {
  26017. if (this.hasPlaybackControl === false) {
  26018. console.warn('THREE.Audio: this Audio has no playback control.');
  26019. return false;
  26020. }
  26021. return this.loop;
  26022. };
  26023. _proto.setLoop = function setLoop(value) {
  26024. if (this.hasPlaybackControl === false) {
  26025. console.warn('THREE.Audio: this Audio has no playback control.');
  26026. return;
  26027. }
  26028. this.loop = value;
  26029. if (this.isPlaying === true) {
  26030. this.source.loop = this.loop;
  26031. }
  26032. return this;
  26033. };
  26034. _proto.setLoopStart = function setLoopStart(value) {
  26035. this.loopStart = value;
  26036. return this;
  26037. };
  26038. _proto.setLoopEnd = function setLoopEnd(value) {
  26039. this.loopEnd = value;
  26040. return this;
  26041. };
  26042. _proto.getVolume = function getVolume() {
  26043. return this.gain.gain.value;
  26044. };
  26045. _proto.setVolume = function setVolume(value) {
  26046. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  26047. return this;
  26048. };
  26049. return Audio;
  26050. }(Object3D);
  26051. var _position$3 = /*@__PURE__*/new Vector3();
  26052. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  26053. var _scale$2 = /*@__PURE__*/new Vector3();
  26054. var _orientation$1 = /*@__PURE__*/new Vector3();
  26055. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  26056. _inheritsLoose(PositionalAudio, _Audio);
  26057. function PositionalAudio(listener) {
  26058. var _this;
  26059. _this = _Audio.call(this, listener) || this;
  26060. _this.panner = _this.context.createPanner();
  26061. _this.panner.panningModel = 'HRTF';
  26062. _this.panner.connect(_this.gain);
  26063. return _this;
  26064. }
  26065. var _proto = PositionalAudio.prototype;
  26066. _proto.getOutput = function getOutput() {
  26067. return this.panner;
  26068. };
  26069. _proto.getRefDistance = function getRefDistance() {
  26070. return this.panner.refDistance;
  26071. };
  26072. _proto.setRefDistance = function setRefDistance(value) {
  26073. this.panner.refDistance = value;
  26074. return this;
  26075. };
  26076. _proto.getRolloffFactor = function getRolloffFactor() {
  26077. return this.panner.rolloffFactor;
  26078. };
  26079. _proto.setRolloffFactor = function setRolloffFactor(value) {
  26080. this.panner.rolloffFactor = value;
  26081. return this;
  26082. };
  26083. _proto.getDistanceModel = function getDistanceModel() {
  26084. return this.panner.distanceModel;
  26085. };
  26086. _proto.setDistanceModel = function setDistanceModel(value) {
  26087. this.panner.distanceModel = value;
  26088. return this;
  26089. };
  26090. _proto.getMaxDistance = function getMaxDistance() {
  26091. return this.panner.maxDistance;
  26092. };
  26093. _proto.setMaxDistance = function setMaxDistance(value) {
  26094. this.panner.maxDistance = value;
  26095. return this;
  26096. };
  26097. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  26098. this.panner.coneInnerAngle = coneInnerAngle;
  26099. this.panner.coneOuterAngle = coneOuterAngle;
  26100. this.panner.coneOuterGain = coneOuterGain;
  26101. return this;
  26102. };
  26103. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  26104. _Audio.prototype.updateMatrixWorld.call(this, force);
  26105. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  26106. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  26107. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  26108. var panner = this.panner;
  26109. if (panner.positionX) {
  26110. // code path for Chrome and Firefox (see #14393)
  26111. var endTime = this.context.currentTime + this.listener.timeDelta;
  26112. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  26113. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  26114. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  26115. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  26116. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  26117. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  26118. } else {
  26119. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  26120. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  26121. }
  26122. };
  26123. return PositionalAudio;
  26124. }(Audio);
  26125. var AudioAnalyser = /*#__PURE__*/function () {
  26126. function AudioAnalyser(audio, fftSize) {
  26127. if (fftSize === void 0) {
  26128. fftSize = 2048;
  26129. }
  26130. this.analyser = audio.context.createAnalyser();
  26131. this.analyser.fftSize = fftSize;
  26132. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  26133. audio.getOutput().connect(this.analyser);
  26134. }
  26135. var _proto = AudioAnalyser.prototype;
  26136. _proto.getFrequencyData = function getFrequencyData() {
  26137. this.analyser.getByteFrequencyData(this.data);
  26138. return this.data;
  26139. };
  26140. _proto.getAverageFrequency = function getAverageFrequency() {
  26141. var value = 0;
  26142. var data = this.getFrequencyData();
  26143. for (var i = 0; i < data.length; i++) {
  26144. value += data[i];
  26145. }
  26146. return value / data.length;
  26147. };
  26148. return AudioAnalyser;
  26149. }();
  26150. function PropertyMixer(binding, typeName, valueSize) {
  26151. this.binding = binding;
  26152. this.valueSize = valueSize;
  26153. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  26154. //
  26155. // interpolators can use .buffer as their .result
  26156. // the data then goes to 'incoming'
  26157. //
  26158. // 'accu0' and 'accu1' are used frame-interleaved for
  26159. // the cumulative result and are compared to detect
  26160. // changes
  26161. //
  26162. // 'orig' stores the original state of the property
  26163. //
  26164. // 'add' is used for additive cumulative results
  26165. //
  26166. // 'work' is optional and is only present for quaternion types. It is used
  26167. // to store intermediate quaternion multiplication results
  26168. switch (typeName) {
  26169. case 'quaternion':
  26170. mixFunction = this._slerp;
  26171. mixFunctionAdditive = this._slerpAdditive;
  26172. setIdentity = this._setAdditiveIdentityQuaternion;
  26173. this.buffer = new Float64Array(valueSize * 6);
  26174. this._workIndex = 5;
  26175. break;
  26176. case 'string':
  26177. case 'bool':
  26178. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  26179. // additive is not relevant for non-numeric types
  26180. mixFunctionAdditive = this._select;
  26181. setIdentity = this._setAdditiveIdentityOther;
  26182. this.buffer = new Array(valueSize * 5);
  26183. break;
  26184. default:
  26185. mixFunction = this._lerp;
  26186. mixFunctionAdditive = this._lerpAdditive;
  26187. setIdentity = this._setAdditiveIdentityNumeric;
  26188. this.buffer = new Float64Array(valueSize * 5);
  26189. }
  26190. this._mixBufferRegion = mixFunction;
  26191. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26192. this._setIdentity = setIdentity;
  26193. this._origIndex = 3;
  26194. this._addIndex = 4;
  26195. this.cumulativeWeight = 0;
  26196. this.cumulativeWeightAdditive = 0;
  26197. this.useCount = 0;
  26198. this.referenceCount = 0;
  26199. }
  26200. Object.assign(PropertyMixer.prototype, {
  26201. // accumulate data in the 'incoming' region into 'accu<i>'
  26202. accumulate: function accumulate(accuIndex, weight) {
  26203. // note: happily accumulating nothing when weight = 0, the caller knows
  26204. // the weight and shouldn't have made the call in the first place
  26205. var buffer = this.buffer,
  26206. stride = this.valueSize,
  26207. offset = accuIndex * stride + stride;
  26208. var currentWeight = this.cumulativeWeight;
  26209. if (currentWeight === 0) {
  26210. // accuN := incoming * weight
  26211. for (var i = 0; i !== stride; ++i) {
  26212. buffer[offset + i] = buffer[i];
  26213. }
  26214. currentWeight = weight;
  26215. } else {
  26216. // accuN := accuN + incoming * weight
  26217. currentWeight += weight;
  26218. var mix = weight / currentWeight;
  26219. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26220. }
  26221. this.cumulativeWeight = currentWeight;
  26222. },
  26223. // accumulate data in the 'incoming' region into 'add'
  26224. accumulateAdditive: function accumulateAdditive(weight) {
  26225. var buffer = this.buffer,
  26226. stride = this.valueSize,
  26227. offset = stride * this._addIndex;
  26228. if (this.cumulativeWeightAdditive === 0) {
  26229. // add = identity
  26230. this._setIdentity();
  26231. } // add := add + incoming * weight
  26232. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26233. this.cumulativeWeightAdditive += weight;
  26234. },
  26235. // apply the state of 'accu<i>' to the binding when accus differ
  26236. apply: function apply(accuIndex) {
  26237. var stride = this.valueSize,
  26238. buffer = this.buffer,
  26239. offset = accuIndex * stride + stride,
  26240. weight = this.cumulativeWeight,
  26241. weightAdditive = this.cumulativeWeightAdditive,
  26242. binding = this.binding;
  26243. this.cumulativeWeight = 0;
  26244. this.cumulativeWeightAdditive = 0;
  26245. if (weight < 1) {
  26246. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26247. var originalValueOffset = stride * this._origIndex;
  26248. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26249. }
  26250. if (weightAdditive > 0) {
  26251. // accuN := accuN + additive accuN
  26252. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26253. }
  26254. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26255. if (buffer[i] !== buffer[i + stride]) {
  26256. // value has changed -> update scene graph
  26257. binding.setValue(buffer, offset);
  26258. break;
  26259. }
  26260. }
  26261. },
  26262. // remember the state of the bound property and copy it to both accus
  26263. saveOriginalState: function saveOriginalState() {
  26264. var binding = this.binding;
  26265. var buffer = this.buffer,
  26266. stride = this.valueSize,
  26267. originalValueOffset = stride * this._origIndex;
  26268. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26269. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26270. buffer[i] = buffer[originalValueOffset + i % stride];
  26271. } // Add to identity for additive
  26272. this._setIdentity();
  26273. this.cumulativeWeight = 0;
  26274. this.cumulativeWeightAdditive = 0;
  26275. },
  26276. // apply the state previously taken via 'saveOriginalState' to the binding
  26277. restoreOriginalState: function restoreOriginalState() {
  26278. var originalValueOffset = this.valueSize * 3;
  26279. this.binding.setValue(this.buffer, originalValueOffset);
  26280. },
  26281. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  26282. var startIndex = this._addIndex * this.valueSize;
  26283. var endIndex = startIndex + this.valueSize;
  26284. for (var i = startIndex; i < endIndex; i++) {
  26285. this.buffer[i] = 0;
  26286. }
  26287. },
  26288. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  26289. this._setAdditiveIdentityNumeric();
  26290. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26291. },
  26292. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  26293. var startIndex = this._origIndex * this.valueSize;
  26294. var targetIndex = this._addIndex * this.valueSize;
  26295. for (var i = 0; i < this.valueSize; i++) {
  26296. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26297. }
  26298. },
  26299. // mix functions
  26300. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  26301. if (t >= 0.5) {
  26302. for (var i = 0; i !== stride; ++i) {
  26303. buffer[dstOffset + i] = buffer[srcOffset + i];
  26304. }
  26305. }
  26306. },
  26307. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  26308. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26309. },
  26310. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26311. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26312. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26313. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26314. },
  26315. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26316. var s = 1 - t;
  26317. for (var i = 0; i !== stride; ++i) {
  26318. var j = dstOffset + i;
  26319. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26320. }
  26321. },
  26322. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26323. for (var i = 0; i !== stride; ++i) {
  26324. var j = dstOffset + i;
  26325. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26326. }
  26327. }
  26328. });
  26329. // Characters [].:/ are reserved for track binding syntax.
  26330. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26331. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26332. // only latin characters, and the unicode \p{L} is not yet supported. So
  26333. // instead, we exclude reserved characters and match everything else.
  26334. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26335. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26336. // be matched to parse the rest of the track name.
  26337. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26338. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26339. // characters. Accessor may contain any character except closing bracket.
  26340. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26341. // contain any non-bracket characters.
  26342. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26343. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26344. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26345. function Composite(targetGroup, path, optionalParsedPath) {
  26346. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26347. this._targetGroup = targetGroup;
  26348. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26349. }
  26350. Object.assign(Composite.prototype, {
  26351. getValue: function getValue(array, offset) {
  26352. this.bind(); // bind all binding
  26353. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26354. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26355. if (binding !== undefined) binding.getValue(array, offset);
  26356. },
  26357. setValue: function setValue(array, offset) {
  26358. var bindings = this._bindings;
  26359. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26360. bindings[i].setValue(array, offset);
  26361. }
  26362. },
  26363. bind: function bind() {
  26364. var bindings = this._bindings;
  26365. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26366. bindings[i].bind();
  26367. }
  26368. },
  26369. unbind: function unbind() {
  26370. var bindings = this._bindings;
  26371. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26372. bindings[i].unbind();
  26373. }
  26374. }
  26375. });
  26376. function PropertyBinding(rootNode, path, parsedPath) {
  26377. this.path = path;
  26378. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26379. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26380. this.rootNode = rootNode;
  26381. }
  26382. Object.assign(PropertyBinding, {
  26383. Composite: Composite,
  26384. create: function create(root, path, parsedPath) {
  26385. if (!(root && root.isAnimationObjectGroup)) {
  26386. return new PropertyBinding(root, path, parsedPath);
  26387. } else {
  26388. return new PropertyBinding.Composite(root, path, parsedPath);
  26389. }
  26390. },
  26391. /**
  26392. * Replaces spaces with underscores and removes unsupported characters from
  26393. * node names, to ensure compatibility with parseTrackName().
  26394. *
  26395. * @param {string} name Node name to be sanitized.
  26396. * @return {string}
  26397. */
  26398. sanitizeNodeName: function sanitizeNodeName(name) {
  26399. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26400. },
  26401. parseTrackName: function parseTrackName(trackName) {
  26402. var matches = _trackRe.exec(trackName);
  26403. if (!matches) {
  26404. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26405. }
  26406. var results = {
  26407. // directoryName: matches[ 1 ], // (tschw) currently unused
  26408. nodeName: matches[2],
  26409. objectName: matches[3],
  26410. objectIndex: matches[4],
  26411. propertyName: matches[5],
  26412. // required
  26413. propertyIndex: matches[6]
  26414. };
  26415. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26416. if (lastDot !== undefined && lastDot !== -1) {
  26417. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26418. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26419. // 'bar' could be the objectName, or part of a nodeName (which can
  26420. // include '.' characters).
  26421. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26422. results.nodeName = results.nodeName.substring(0, lastDot);
  26423. results.objectName = objectName;
  26424. }
  26425. }
  26426. if (results.propertyName === null || results.propertyName.length === 0) {
  26427. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26428. }
  26429. return results;
  26430. },
  26431. findNode: function findNode(root, nodeName) {
  26432. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26433. return root;
  26434. } // search into skeleton bones.
  26435. if (root.skeleton) {
  26436. var bone = root.skeleton.getBoneByName(nodeName);
  26437. if (bone !== undefined) {
  26438. return bone;
  26439. }
  26440. } // search into node subtree.
  26441. if (root.children) {
  26442. var searchNodeSubtree = function searchNodeSubtree(children) {
  26443. for (var i = 0; i < children.length; i++) {
  26444. var childNode = children[i];
  26445. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26446. return childNode;
  26447. }
  26448. var result = searchNodeSubtree(childNode.children);
  26449. if (result) return result;
  26450. }
  26451. return null;
  26452. };
  26453. var subTreeNode = searchNodeSubtree(root.children);
  26454. if (subTreeNode) {
  26455. return subTreeNode;
  26456. }
  26457. }
  26458. return null;
  26459. }
  26460. });
  26461. Object.assign(PropertyBinding.prototype, {
  26462. // prototype, continued
  26463. // these are used to "bind" a nonexistent property
  26464. _getValue_unavailable: function _getValue_unavailable() {},
  26465. _setValue_unavailable: function _setValue_unavailable() {},
  26466. BindingType: {
  26467. Direct: 0,
  26468. EntireArray: 1,
  26469. ArrayElement: 2,
  26470. HasFromToArray: 3
  26471. },
  26472. Versioning: {
  26473. None: 0,
  26474. NeedsUpdate: 1,
  26475. MatrixWorldNeedsUpdate: 2
  26476. },
  26477. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26478. buffer[offset] = this.node[this.propertyName];
  26479. }, function getValue_array(buffer, offset) {
  26480. var source = this.resolvedProperty;
  26481. for (var i = 0, n = source.length; i !== n; ++i) {
  26482. buffer[offset++] = source[i];
  26483. }
  26484. }, function getValue_arrayElement(buffer, offset) {
  26485. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26486. }, function getValue_toArray(buffer, offset) {
  26487. this.resolvedProperty.toArray(buffer, offset);
  26488. }],
  26489. SetterByBindingTypeAndVersioning: [[// Direct
  26490. function setValue_direct(buffer, offset) {
  26491. this.targetObject[this.propertyName] = buffer[offset];
  26492. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26493. this.targetObject[this.propertyName] = buffer[offset];
  26494. this.targetObject.needsUpdate = true;
  26495. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26496. this.targetObject[this.propertyName] = buffer[offset];
  26497. this.targetObject.matrixWorldNeedsUpdate = true;
  26498. }], [// EntireArray
  26499. function setValue_array(buffer, offset) {
  26500. var dest = this.resolvedProperty;
  26501. for (var i = 0, n = dest.length; i !== n; ++i) {
  26502. dest[i] = buffer[offset++];
  26503. }
  26504. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26505. var dest = this.resolvedProperty;
  26506. for (var i = 0, n = dest.length; i !== n; ++i) {
  26507. dest[i] = buffer[offset++];
  26508. }
  26509. this.targetObject.needsUpdate = true;
  26510. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26511. var dest = this.resolvedProperty;
  26512. for (var i = 0, n = dest.length; i !== n; ++i) {
  26513. dest[i] = buffer[offset++];
  26514. }
  26515. this.targetObject.matrixWorldNeedsUpdate = true;
  26516. }], [// ArrayElement
  26517. function setValue_arrayElement(buffer, offset) {
  26518. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26519. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26520. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26521. this.targetObject.needsUpdate = true;
  26522. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26523. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26524. this.targetObject.matrixWorldNeedsUpdate = true;
  26525. }], [// HasToFromArray
  26526. function setValue_fromArray(buffer, offset) {
  26527. this.resolvedProperty.fromArray(buffer, offset);
  26528. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26529. this.resolvedProperty.fromArray(buffer, offset);
  26530. this.targetObject.needsUpdate = true;
  26531. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26532. this.resolvedProperty.fromArray(buffer, offset);
  26533. this.targetObject.matrixWorldNeedsUpdate = true;
  26534. }]],
  26535. getValue: function getValue_unbound(targetArray, offset) {
  26536. this.bind();
  26537. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26538. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26539. // prototype version of these methods with one that represents
  26540. // the bound state. When the property is not found, the methods
  26541. // become no-ops.
  26542. },
  26543. setValue: function getValue_unbound(sourceArray, offset) {
  26544. this.bind();
  26545. this.setValue(sourceArray, offset);
  26546. },
  26547. // create getter / setter pair for a property in the scene graph
  26548. bind: function bind() {
  26549. var targetObject = this.node;
  26550. var parsedPath = this.parsedPath;
  26551. var objectName = parsedPath.objectName;
  26552. var propertyName = parsedPath.propertyName;
  26553. var propertyIndex = parsedPath.propertyIndex;
  26554. if (!targetObject) {
  26555. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26556. this.node = targetObject;
  26557. } // set fail state so we can just 'return' on error
  26558. this.getValue = this._getValue_unavailable;
  26559. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26560. if (!targetObject) {
  26561. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26562. return;
  26563. }
  26564. if (objectName) {
  26565. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26566. switch (objectName) {
  26567. case 'materials':
  26568. if (!targetObject.material) {
  26569. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26570. return;
  26571. }
  26572. if (!targetObject.material.materials) {
  26573. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26574. return;
  26575. }
  26576. targetObject = targetObject.material.materials;
  26577. break;
  26578. case 'bones':
  26579. if (!targetObject.skeleton) {
  26580. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26581. return;
  26582. } // potential future optimization: skip this if propertyIndex is already an integer
  26583. // and convert the integer string to a true integer.
  26584. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26585. for (var i = 0; i < targetObject.length; i++) {
  26586. if (targetObject[i].name === objectIndex) {
  26587. objectIndex = i;
  26588. break;
  26589. }
  26590. }
  26591. break;
  26592. default:
  26593. if (targetObject[objectName] === undefined) {
  26594. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26595. return;
  26596. }
  26597. targetObject = targetObject[objectName];
  26598. }
  26599. if (objectIndex !== undefined) {
  26600. if (targetObject[objectIndex] === undefined) {
  26601. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26602. return;
  26603. }
  26604. targetObject = targetObject[objectIndex];
  26605. }
  26606. } // resolve property
  26607. var nodeProperty = targetObject[propertyName];
  26608. if (nodeProperty === undefined) {
  26609. var nodeName = parsedPath.nodeName;
  26610. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26611. return;
  26612. } // determine versioning scheme
  26613. var versioning = this.Versioning.None;
  26614. this.targetObject = targetObject;
  26615. if (targetObject.needsUpdate !== undefined) {
  26616. // material
  26617. versioning = this.Versioning.NeedsUpdate;
  26618. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26619. // node transform
  26620. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26621. } // determine how the property gets bound
  26622. var bindingType = this.BindingType.Direct;
  26623. if (propertyIndex !== undefined) {
  26624. // access a sub element of the property array (only primitives are supported right now)
  26625. if (propertyName === "morphTargetInfluences") {
  26626. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26627. // support resolving morphTarget names into indices.
  26628. if (!targetObject.geometry) {
  26629. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26630. return;
  26631. }
  26632. if (targetObject.geometry.isBufferGeometry) {
  26633. if (!targetObject.geometry.morphAttributes) {
  26634. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26635. return;
  26636. }
  26637. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26638. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26639. }
  26640. } else {
  26641. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26642. return;
  26643. }
  26644. }
  26645. bindingType = this.BindingType.ArrayElement;
  26646. this.resolvedProperty = nodeProperty;
  26647. this.propertyIndex = propertyIndex;
  26648. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26649. // must use copy for Object3D.Euler/Quaternion
  26650. bindingType = this.BindingType.HasFromToArray;
  26651. this.resolvedProperty = nodeProperty;
  26652. } else if (Array.isArray(nodeProperty)) {
  26653. bindingType = this.BindingType.EntireArray;
  26654. this.resolvedProperty = nodeProperty;
  26655. } else {
  26656. this.propertyName = propertyName;
  26657. } // select getter / setter
  26658. this.getValue = this.GetterByBindingType[bindingType];
  26659. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26660. },
  26661. unbind: function unbind() {
  26662. this.node = null; // back to the prototype version of getValue / setValue
  26663. // note: avoiding to mutate the shape of 'this' via 'delete'
  26664. this.getValue = this._getValue_unbound;
  26665. this.setValue = this._setValue_unbound;
  26666. }
  26667. }); // DECLARE ALIAS AFTER assign prototype
  26668. Object.assign(PropertyBinding.prototype, {
  26669. // initial state of these methods that calls 'bind'
  26670. _getValue_unbound: PropertyBinding.prototype.getValue,
  26671. _setValue_unbound: PropertyBinding.prototype.setValue
  26672. });
  26673. /**
  26674. *
  26675. * A group of objects that receives a shared animation state.
  26676. *
  26677. * Usage:
  26678. *
  26679. * - Add objects you would otherwise pass as 'root' to the
  26680. * constructor or the .clipAction method of AnimationMixer.
  26681. *
  26682. * - Instead pass this object as 'root'.
  26683. *
  26684. * - You can also add and remove objects later when the mixer
  26685. * is running.
  26686. *
  26687. * Note:
  26688. *
  26689. * Objects of this class appear as one object to the mixer,
  26690. * so cache control of the individual objects must be done
  26691. * on the group.
  26692. *
  26693. * Limitation:
  26694. *
  26695. * - The animated properties must be compatible among the
  26696. * all objects in the group.
  26697. *
  26698. * - A single property can either be controlled through a
  26699. * target group or directly, but not both.
  26700. */
  26701. function AnimationObjectGroup() {
  26702. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26703. this._objects = Array.prototype.slice.call(arguments);
  26704. this.nCachedObjects_ = 0; // threshold
  26705. // note: read by PropertyBinding.Composite
  26706. var indices = {};
  26707. this._indicesByUUID = indices; // for bookkeeping
  26708. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26709. indices[arguments[i].uuid] = i;
  26710. }
  26711. this._paths = []; // inside: string
  26712. this._parsedPaths = []; // inside: { we don't care, here }
  26713. this._bindings = []; // inside: Array< PropertyBinding >
  26714. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26715. var scope = this;
  26716. this.stats = {
  26717. objects: {
  26718. get total() {
  26719. return scope._objects.length;
  26720. },
  26721. get inUse() {
  26722. return this.total - scope.nCachedObjects_;
  26723. }
  26724. },
  26725. get bindingsPerObject() {
  26726. return scope._bindings.length;
  26727. }
  26728. };
  26729. }
  26730. Object.assign(AnimationObjectGroup.prototype, {
  26731. isAnimationObjectGroup: true,
  26732. add: function add() {
  26733. var objects = this._objects,
  26734. indicesByUUID = this._indicesByUUID,
  26735. paths = this._paths,
  26736. parsedPaths = this._parsedPaths,
  26737. bindings = this._bindings,
  26738. nBindings = bindings.length;
  26739. var knownObject = undefined,
  26740. nObjects = objects.length,
  26741. nCachedObjects = this.nCachedObjects_;
  26742. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26743. var object = arguments[i],
  26744. uuid = object.uuid;
  26745. var index = indicesByUUID[uuid];
  26746. if (index === undefined) {
  26747. // unknown object -> add it to the ACTIVE region
  26748. index = nObjects++;
  26749. indicesByUUID[uuid] = index;
  26750. objects.push(object); // accounting is done, now do the same for all bindings
  26751. for (var j = 0, m = nBindings; j !== m; ++j) {
  26752. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26753. }
  26754. } else if (index < nCachedObjects) {
  26755. knownObject = objects[index]; // move existing object to the ACTIVE region
  26756. var firstActiveIndex = --nCachedObjects,
  26757. lastCachedObject = objects[firstActiveIndex];
  26758. indicesByUUID[lastCachedObject.uuid] = index;
  26759. objects[index] = lastCachedObject;
  26760. indicesByUUID[uuid] = firstActiveIndex;
  26761. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26762. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26763. var bindingsForPath = bindings[_j],
  26764. lastCached = bindingsForPath[firstActiveIndex];
  26765. var binding = bindingsForPath[index];
  26766. bindingsForPath[index] = lastCached;
  26767. if (binding === undefined) {
  26768. // since we do not bother to create new bindings
  26769. // for objects that are cached, the binding may
  26770. // or may not exist
  26771. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26772. }
  26773. bindingsForPath[firstActiveIndex] = binding;
  26774. }
  26775. } else if (objects[index] !== knownObject) {
  26776. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26777. } // else the object is already where we want it to be
  26778. } // for arguments
  26779. this.nCachedObjects_ = nCachedObjects;
  26780. },
  26781. remove: function remove() {
  26782. var objects = this._objects,
  26783. indicesByUUID = this._indicesByUUID,
  26784. bindings = this._bindings,
  26785. nBindings = bindings.length;
  26786. var nCachedObjects = this.nCachedObjects_;
  26787. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26788. var object = arguments[i],
  26789. uuid = object.uuid,
  26790. index = indicesByUUID[uuid];
  26791. if (index !== undefined && index >= nCachedObjects) {
  26792. // move existing object into the CACHED region
  26793. var lastCachedIndex = nCachedObjects++,
  26794. firstActiveObject = objects[lastCachedIndex];
  26795. indicesByUUID[firstActiveObject.uuid] = index;
  26796. objects[index] = firstActiveObject;
  26797. indicesByUUID[uuid] = lastCachedIndex;
  26798. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26799. for (var j = 0, m = nBindings; j !== m; ++j) {
  26800. var bindingsForPath = bindings[j],
  26801. firstActive = bindingsForPath[lastCachedIndex],
  26802. binding = bindingsForPath[index];
  26803. bindingsForPath[index] = firstActive;
  26804. bindingsForPath[lastCachedIndex] = binding;
  26805. }
  26806. }
  26807. } // for arguments
  26808. this.nCachedObjects_ = nCachedObjects;
  26809. },
  26810. // remove & forget
  26811. uncache: function uncache() {
  26812. var objects = this._objects,
  26813. indicesByUUID = this._indicesByUUID,
  26814. bindings = this._bindings,
  26815. nBindings = bindings.length;
  26816. var nCachedObjects = this.nCachedObjects_,
  26817. nObjects = objects.length;
  26818. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26819. var object = arguments[i],
  26820. uuid = object.uuid,
  26821. index = indicesByUUID[uuid];
  26822. if (index !== undefined) {
  26823. delete indicesByUUID[uuid];
  26824. if (index < nCachedObjects) {
  26825. // object is cached, shrink the CACHED region
  26826. var firstActiveIndex = --nCachedObjects,
  26827. lastCachedObject = objects[firstActiveIndex],
  26828. lastIndex = --nObjects,
  26829. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26830. indicesByUUID[lastCachedObject.uuid] = index;
  26831. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26832. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26833. objects[firstActiveIndex] = lastObject;
  26834. objects.pop(); // accounting is done, now do the same for all bindings
  26835. for (var j = 0, m = nBindings; j !== m; ++j) {
  26836. var bindingsForPath = bindings[j],
  26837. lastCached = bindingsForPath[firstActiveIndex],
  26838. last = bindingsForPath[lastIndex];
  26839. bindingsForPath[index] = lastCached;
  26840. bindingsForPath[firstActiveIndex] = last;
  26841. bindingsForPath.pop();
  26842. }
  26843. } else {
  26844. // object is active, just swap with the last and pop
  26845. var _lastIndex = --nObjects,
  26846. _lastObject = objects[_lastIndex];
  26847. if (_lastIndex > 0) {
  26848. indicesByUUID[_lastObject.uuid] = index;
  26849. }
  26850. objects[index] = _lastObject;
  26851. objects.pop(); // accounting is done, now do the same for all bindings
  26852. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26853. var _bindingsForPath = bindings[_j2];
  26854. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26855. _bindingsForPath.pop();
  26856. }
  26857. } // cached or active
  26858. } // if object is known
  26859. } // for arguments
  26860. this.nCachedObjects_ = nCachedObjects;
  26861. },
  26862. // Internal interface used by befriended PropertyBinding.Composite:
  26863. subscribe_: function subscribe_(path, parsedPath) {
  26864. // returns an array of bindings for the given path that is changed
  26865. // according to the contained objects in the group
  26866. var indicesByPath = this._bindingsIndicesByPath;
  26867. var index = indicesByPath[path];
  26868. var bindings = this._bindings;
  26869. if (index !== undefined) return bindings[index];
  26870. var paths = this._paths,
  26871. parsedPaths = this._parsedPaths,
  26872. objects = this._objects,
  26873. nObjects = objects.length,
  26874. nCachedObjects = this.nCachedObjects_,
  26875. bindingsForPath = new Array(nObjects);
  26876. index = bindings.length;
  26877. indicesByPath[path] = index;
  26878. paths.push(path);
  26879. parsedPaths.push(parsedPath);
  26880. bindings.push(bindingsForPath);
  26881. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26882. var object = objects[i];
  26883. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26884. }
  26885. return bindingsForPath;
  26886. },
  26887. unsubscribe_: function unsubscribe_(path) {
  26888. // tells the group to forget about a property path and no longer
  26889. // update the array previously obtained with 'subscribe_'
  26890. var indicesByPath = this._bindingsIndicesByPath,
  26891. index = indicesByPath[path];
  26892. if (index !== undefined) {
  26893. var paths = this._paths,
  26894. parsedPaths = this._parsedPaths,
  26895. bindings = this._bindings,
  26896. lastBindingsIndex = bindings.length - 1,
  26897. lastBindings = bindings[lastBindingsIndex],
  26898. lastBindingsPath = path[lastBindingsIndex];
  26899. indicesByPath[lastBindingsPath] = index;
  26900. bindings[index] = lastBindings;
  26901. bindings.pop();
  26902. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26903. parsedPaths.pop();
  26904. paths[index] = paths[lastBindingsIndex];
  26905. paths.pop();
  26906. }
  26907. }
  26908. });
  26909. var AnimationAction = /*#__PURE__*/function () {
  26910. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26911. if (localRoot === void 0) {
  26912. localRoot = null;
  26913. }
  26914. if (blendMode === void 0) {
  26915. blendMode = clip.blendMode;
  26916. }
  26917. this._mixer = mixer;
  26918. this._clip = clip;
  26919. this._localRoot = localRoot;
  26920. this.blendMode = blendMode;
  26921. var tracks = clip.tracks,
  26922. nTracks = tracks.length,
  26923. interpolants = new Array(nTracks);
  26924. var interpolantSettings = {
  26925. endingStart: ZeroCurvatureEnding,
  26926. endingEnd: ZeroCurvatureEnding
  26927. };
  26928. for (var i = 0; i !== nTracks; ++i) {
  26929. var interpolant = tracks[i].createInterpolant(null);
  26930. interpolants[i] = interpolant;
  26931. interpolant.settings = interpolantSettings;
  26932. }
  26933. this._interpolantSettings = interpolantSettings;
  26934. this._interpolants = interpolants; // bound by the mixer
  26935. // inside: PropertyMixer (managed by the mixer)
  26936. this._propertyBindings = new Array(nTracks);
  26937. this._cacheIndex = null; // for the memory manager
  26938. this._byClipCacheIndex = null; // for the memory manager
  26939. this._timeScaleInterpolant = null;
  26940. this._weightInterpolant = null;
  26941. this.loop = LoopRepeat;
  26942. this._loopCount = -1; // global mixer time when the action is to be started
  26943. // it's set back to 'null' upon start of the action
  26944. this._startTime = null; // scaled local time of the action
  26945. // gets clamped or wrapped to 0..clip.duration according to loop
  26946. this.time = 0;
  26947. this.timeScale = 1;
  26948. this._effectiveTimeScale = 1;
  26949. this.weight = 1;
  26950. this._effectiveWeight = 1;
  26951. this.repetitions = Infinity; // no. of repetitions when looping
  26952. this.paused = false; // true -> zero effective time scale
  26953. this.enabled = true; // false -> zero effective weight
  26954. this.clampWhenFinished = false; // keep feeding the last frame?
  26955. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26956. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26957. } // State & Scheduling
  26958. var _proto = AnimationAction.prototype;
  26959. _proto.play = function play() {
  26960. this._mixer._activateAction(this);
  26961. return this;
  26962. };
  26963. _proto.stop = function stop() {
  26964. this._mixer._deactivateAction(this);
  26965. return this.reset();
  26966. };
  26967. _proto.reset = function reset() {
  26968. this.paused = false;
  26969. this.enabled = true;
  26970. this.time = 0; // restart clip
  26971. this._loopCount = -1; // forget previous loops
  26972. this._startTime = null; // forget scheduling
  26973. return this.stopFading().stopWarping();
  26974. };
  26975. _proto.isRunning = function isRunning() {
  26976. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26977. } // return true when play has been called
  26978. ;
  26979. _proto.isScheduled = function isScheduled() {
  26980. return this._mixer._isActiveAction(this);
  26981. };
  26982. _proto.startAt = function startAt(time) {
  26983. this._startTime = time;
  26984. return this;
  26985. };
  26986. _proto.setLoop = function setLoop(mode, repetitions) {
  26987. this.loop = mode;
  26988. this.repetitions = repetitions;
  26989. return this;
  26990. } // Weight
  26991. // set the weight stopping any scheduled fading
  26992. // although .enabled = false yields an effective weight of zero, this
  26993. // method does *not* change .enabled, because it would be confusing
  26994. ;
  26995. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26996. this.weight = weight; // note: same logic as when updated at runtime
  26997. this._effectiveWeight = this.enabled ? weight : 0;
  26998. return this.stopFading();
  26999. } // return the weight considering fading and .enabled
  27000. ;
  27001. _proto.getEffectiveWeight = function getEffectiveWeight() {
  27002. return this._effectiveWeight;
  27003. };
  27004. _proto.fadeIn = function fadeIn(duration) {
  27005. return this._scheduleFading(duration, 0, 1);
  27006. };
  27007. _proto.fadeOut = function fadeOut(duration) {
  27008. return this._scheduleFading(duration, 1, 0);
  27009. };
  27010. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  27011. fadeOutAction.fadeOut(duration);
  27012. this.fadeIn(duration);
  27013. if (warp) {
  27014. var fadeInDuration = this._clip.duration,
  27015. fadeOutDuration = fadeOutAction._clip.duration,
  27016. startEndRatio = fadeOutDuration / fadeInDuration,
  27017. endStartRatio = fadeInDuration / fadeOutDuration;
  27018. fadeOutAction.warp(1.0, startEndRatio, duration);
  27019. this.warp(endStartRatio, 1.0, duration);
  27020. }
  27021. return this;
  27022. };
  27023. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  27024. return fadeInAction.crossFadeFrom(this, duration, warp);
  27025. };
  27026. _proto.stopFading = function stopFading() {
  27027. var weightInterpolant = this._weightInterpolant;
  27028. if (weightInterpolant !== null) {
  27029. this._weightInterpolant = null;
  27030. this._mixer._takeBackControlInterpolant(weightInterpolant);
  27031. }
  27032. return this;
  27033. } // Time Scale Control
  27034. // set the time scale stopping any scheduled warping
  27035. // although .paused = true yields an effective time scale of zero, this
  27036. // method does *not* change .paused, because it would be confusing
  27037. ;
  27038. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  27039. this.timeScale = timeScale;
  27040. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  27041. return this.stopWarping();
  27042. } // return the time scale considering warping and .paused
  27043. ;
  27044. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  27045. return this._effectiveTimeScale;
  27046. };
  27047. _proto.setDuration = function setDuration(duration) {
  27048. this.timeScale = this._clip.duration / duration;
  27049. return this.stopWarping();
  27050. };
  27051. _proto.syncWith = function syncWith(action) {
  27052. this.time = action.time;
  27053. this.timeScale = action.timeScale;
  27054. return this.stopWarping();
  27055. };
  27056. _proto.halt = function halt(duration) {
  27057. return this.warp(this._effectiveTimeScale, 0, duration);
  27058. };
  27059. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  27060. var mixer = this._mixer,
  27061. now = mixer.time,
  27062. timeScale = this.timeScale;
  27063. var interpolant = this._timeScaleInterpolant;
  27064. if (interpolant === null) {
  27065. interpolant = mixer._lendControlInterpolant();
  27066. this._timeScaleInterpolant = interpolant;
  27067. }
  27068. var times = interpolant.parameterPositions,
  27069. values = interpolant.sampleValues;
  27070. times[0] = now;
  27071. times[1] = now + duration;
  27072. values[0] = startTimeScale / timeScale;
  27073. values[1] = endTimeScale / timeScale;
  27074. return this;
  27075. };
  27076. _proto.stopWarping = function stopWarping() {
  27077. var timeScaleInterpolant = this._timeScaleInterpolant;
  27078. if (timeScaleInterpolant !== null) {
  27079. this._timeScaleInterpolant = null;
  27080. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  27081. }
  27082. return this;
  27083. } // Object Accessors
  27084. ;
  27085. _proto.getMixer = function getMixer() {
  27086. return this._mixer;
  27087. };
  27088. _proto.getClip = function getClip() {
  27089. return this._clip;
  27090. };
  27091. _proto.getRoot = function getRoot() {
  27092. return this._localRoot || this._mixer._root;
  27093. } // Interna
  27094. ;
  27095. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  27096. // called by the mixer
  27097. if (!this.enabled) {
  27098. // call ._updateWeight() to update ._effectiveWeight
  27099. this._updateWeight(time);
  27100. return;
  27101. }
  27102. var startTime = this._startTime;
  27103. if (startTime !== null) {
  27104. // check for scheduled start of action
  27105. var timeRunning = (time - startTime) * timeDirection;
  27106. if (timeRunning < 0 || timeDirection === 0) {
  27107. return; // yet to come / don't decide when delta = 0
  27108. } // start
  27109. this._startTime = null; // unschedule
  27110. deltaTime = timeDirection * timeRunning;
  27111. } // apply time scale and advance time
  27112. deltaTime *= this._updateTimeScale(time);
  27113. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  27114. // an effective weight of 0
  27115. var weight = this._updateWeight(time);
  27116. if (weight > 0) {
  27117. var _interpolants = this._interpolants;
  27118. var propertyMixers = this._propertyBindings;
  27119. switch (this.blendMode) {
  27120. case AdditiveAnimationBlendMode:
  27121. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  27122. _interpolants[j].evaluate(clipTime);
  27123. propertyMixers[j].accumulateAdditive(weight);
  27124. }
  27125. break;
  27126. case NormalAnimationBlendMode:
  27127. default:
  27128. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  27129. _interpolants[_j].evaluate(clipTime);
  27130. propertyMixers[_j].accumulate(accuIndex, weight);
  27131. }
  27132. }
  27133. }
  27134. };
  27135. _proto._updateWeight = function _updateWeight(time) {
  27136. var weight = 0;
  27137. if (this.enabled) {
  27138. weight = this.weight;
  27139. var interpolant = this._weightInterpolant;
  27140. if (interpolant !== null) {
  27141. var interpolantValue = interpolant.evaluate(time)[0];
  27142. weight *= interpolantValue;
  27143. if (time > interpolant.parameterPositions[1]) {
  27144. this.stopFading();
  27145. if (interpolantValue === 0) {
  27146. // faded out, disable
  27147. this.enabled = false;
  27148. }
  27149. }
  27150. }
  27151. }
  27152. this._effectiveWeight = weight;
  27153. return weight;
  27154. };
  27155. _proto._updateTimeScale = function _updateTimeScale(time) {
  27156. var timeScale = 0;
  27157. if (!this.paused) {
  27158. timeScale = this.timeScale;
  27159. var interpolant = this._timeScaleInterpolant;
  27160. if (interpolant !== null) {
  27161. var interpolantValue = interpolant.evaluate(time)[0];
  27162. timeScale *= interpolantValue;
  27163. if (time > interpolant.parameterPositions[1]) {
  27164. this.stopWarping();
  27165. if (timeScale === 0) {
  27166. // motion has halted, pause
  27167. this.paused = true;
  27168. } else {
  27169. // warp done - apply final time scale
  27170. this.timeScale = timeScale;
  27171. }
  27172. }
  27173. }
  27174. }
  27175. this._effectiveTimeScale = timeScale;
  27176. return timeScale;
  27177. };
  27178. _proto._updateTime = function _updateTime(deltaTime) {
  27179. var duration = this._clip.duration;
  27180. var loop = this.loop;
  27181. var time = this.time + deltaTime;
  27182. var loopCount = this._loopCount;
  27183. var pingPong = loop === LoopPingPong;
  27184. if (deltaTime === 0) {
  27185. if (loopCount === -1) return time;
  27186. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  27187. }
  27188. if (loop === LoopOnce) {
  27189. if (loopCount === -1) {
  27190. // just started
  27191. this._loopCount = 0;
  27192. this._setEndings(true, true, false);
  27193. }
  27194. handle_stop: {
  27195. if (time >= duration) {
  27196. time = duration;
  27197. } else if (time < 0) {
  27198. time = 0;
  27199. } else {
  27200. this.time = time;
  27201. break handle_stop;
  27202. }
  27203. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27204. this.time = time;
  27205. this._mixer.dispatchEvent({
  27206. type: 'finished',
  27207. action: this,
  27208. direction: deltaTime < 0 ? -1 : 1
  27209. });
  27210. }
  27211. } else {
  27212. // repetitive Repeat or PingPong
  27213. if (loopCount === -1) {
  27214. // just started
  27215. if (deltaTime >= 0) {
  27216. loopCount = 0;
  27217. this._setEndings(true, this.repetitions === 0, pingPong);
  27218. } else {
  27219. // when looping in reverse direction, the initial
  27220. // transition through zero counts as a repetition,
  27221. // so leave loopCount at -1
  27222. this._setEndings(this.repetitions === 0, true, pingPong);
  27223. }
  27224. }
  27225. if (time >= duration || time < 0) {
  27226. // wrap around
  27227. var loopDelta = Math.floor(time / duration); // signed
  27228. time -= duration * loopDelta;
  27229. loopCount += Math.abs(loopDelta);
  27230. var pending = this.repetitions - loopCount;
  27231. if (pending <= 0) {
  27232. // have to stop (switch state, clamp time, fire event)
  27233. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27234. time = deltaTime > 0 ? duration : 0;
  27235. this.time = time;
  27236. this._mixer.dispatchEvent({
  27237. type: 'finished',
  27238. action: this,
  27239. direction: deltaTime > 0 ? 1 : -1
  27240. });
  27241. } else {
  27242. // keep running
  27243. if (pending === 1) {
  27244. // entering the last round
  27245. var atStart = deltaTime < 0;
  27246. this._setEndings(atStart, !atStart, pingPong);
  27247. } else {
  27248. this._setEndings(false, false, pingPong);
  27249. }
  27250. this._loopCount = loopCount;
  27251. this.time = time;
  27252. this._mixer.dispatchEvent({
  27253. type: 'loop',
  27254. action: this,
  27255. loopDelta: loopDelta
  27256. });
  27257. }
  27258. } else {
  27259. this.time = time;
  27260. }
  27261. if (pingPong && (loopCount & 1) === 1) {
  27262. // invert time for the "pong round"
  27263. return duration - time;
  27264. }
  27265. }
  27266. return time;
  27267. };
  27268. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27269. var settings = this._interpolantSettings;
  27270. if (pingPong) {
  27271. settings.endingStart = ZeroSlopeEnding;
  27272. settings.endingEnd = ZeroSlopeEnding;
  27273. } else {
  27274. // assuming for LoopOnce atStart == atEnd == true
  27275. if (atStart) {
  27276. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27277. } else {
  27278. settings.endingStart = WrapAroundEnding;
  27279. }
  27280. if (atEnd) {
  27281. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27282. } else {
  27283. settings.endingEnd = WrapAroundEnding;
  27284. }
  27285. }
  27286. };
  27287. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27288. var mixer = this._mixer,
  27289. now = mixer.time;
  27290. var interpolant = this._weightInterpolant;
  27291. if (interpolant === null) {
  27292. interpolant = mixer._lendControlInterpolant();
  27293. this._weightInterpolant = interpolant;
  27294. }
  27295. var times = interpolant.parameterPositions,
  27296. values = interpolant.sampleValues;
  27297. times[0] = now;
  27298. values[0] = weightNow;
  27299. times[1] = now + duration;
  27300. values[1] = weightThen;
  27301. return this;
  27302. };
  27303. return AnimationAction;
  27304. }();
  27305. function AnimationMixer(root) {
  27306. this._root = root;
  27307. this._initMemoryManager();
  27308. this._accuIndex = 0;
  27309. this.time = 0;
  27310. this.timeScale = 1.0;
  27311. }
  27312. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  27313. constructor: AnimationMixer,
  27314. _bindAction: function _bindAction(action, prototypeAction) {
  27315. var root = action._localRoot || this._root,
  27316. tracks = action._clip.tracks,
  27317. nTracks = tracks.length,
  27318. bindings = action._propertyBindings,
  27319. interpolants = action._interpolants,
  27320. rootUuid = root.uuid,
  27321. bindingsByRoot = this._bindingsByRootAndName;
  27322. var bindingsByName = bindingsByRoot[rootUuid];
  27323. if (bindingsByName === undefined) {
  27324. bindingsByName = {};
  27325. bindingsByRoot[rootUuid] = bindingsByName;
  27326. }
  27327. for (var i = 0; i !== nTracks; ++i) {
  27328. var track = tracks[i],
  27329. trackName = track.name;
  27330. var binding = bindingsByName[trackName];
  27331. if (binding !== undefined) {
  27332. bindings[i] = binding;
  27333. } else {
  27334. binding = bindings[i];
  27335. if (binding !== undefined) {
  27336. // existing binding, make sure the cache knows
  27337. if (binding._cacheIndex === null) {
  27338. ++binding.referenceCount;
  27339. this._addInactiveBinding(binding, rootUuid, trackName);
  27340. }
  27341. continue;
  27342. }
  27343. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27344. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27345. ++binding.referenceCount;
  27346. this._addInactiveBinding(binding, rootUuid, trackName);
  27347. bindings[i] = binding;
  27348. }
  27349. interpolants[i].resultBuffer = binding.buffer;
  27350. }
  27351. },
  27352. _activateAction: function _activateAction(action) {
  27353. if (!this._isActiveAction(action)) {
  27354. if (action._cacheIndex === null) {
  27355. // this action has been forgotten by the cache, but the user
  27356. // appears to be still using it -> rebind
  27357. var rootUuid = (action._localRoot || this._root).uuid,
  27358. clipUuid = action._clip.uuid,
  27359. actionsForClip = this._actionsByClip[clipUuid];
  27360. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27361. this._addInactiveAction(action, clipUuid, rootUuid);
  27362. }
  27363. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27364. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27365. var binding = bindings[i];
  27366. if (binding.useCount++ === 0) {
  27367. this._lendBinding(binding);
  27368. binding.saveOriginalState();
  27369. }
  27370. }
  27371. this._lendAction(action);
  27372. }
  27373. },
  27374. _deactivateAction: function _deactivateAction(action) {
  27375. if (this._isActiveAction(action)) {
  27376. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27377. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27378. var binding = bindings[i];
  27379. if (--binding.useCount === 0) {
  27380. binding.restoreOriginalState();
  27381. this._takeBackBinding(binding);
  27382. }
  27383. }
  27384. this._takeBackAction(action);
  27385. }
  27386. },
  27387. // Memory manager
  27388. _initMemoryManager: function _initMemoryManager() {
  27389. this._actions = []; // 'nActiveActions' followed by inactive ones
  27390. this._nActiveActions = 0;
  27391. this._actionsByClip = {}; // inside:
  27392. // {
  27393. // knownActions: Array< AnimationAction > - used as prototypes
  27394. // actionByRoot: AnimationAction - lookup
  27395. // }
  27396. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27397. this._nActiveBindings = 0;
  27398. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27399. this._controlInterpolants = []; // same game as above
  27400. this._nActiveControlInterpolants = 0;
  27401. var scope = this;
  27402. this.stats = {
  27403. actions: {
  27404. get total() {
  27405. return scope._actions.length;
  27406. },
  27407. get inUse() {
  27408. return scope._nActiveActions;
  27409. }
  27410. },
  27411. bindings: {
  27412. get total() {
  27413. return scope._bindings.length;
  27414. },
  27415. get inUse() {
  27416. return scope._nActiveBindings;
  27417. }
  27418. },
  27419. controlInterpolants: {
  27420. get total() {
  27421. return scope._controlInterpolants.length;
  27422. },
  27423. get inUse() {
  27424. return scope._nActiveControlInterpolants;
  27425. }
  27426. }
  27427. };
  27428. },
  27429. // Memory management for AnimationAction objects
  27430. _isActiveAction: function _isActiveAction(action) {
  27431. var index = action._cacheIndex;
  27432. return index !== null && index < this._nActiveActions;
  27433. },
  27434. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  27435. var actions = this._actions,
  27436. actionsByClip = this._actionsByClip;
  27437. var actionsForClip = actionsByClip[clipUuid];
  27438. if (actionsForClip === undefined) {
  27439. actionsForClip = {
  27440. knownActions: [action],
  27441. actionByRoot: {}
  27442. };
  27443. action._byClipCacheIndex = 0;
  27444. actionsByClip[clipUuid] = actionsForClip;
  27445. } else {
  27446. var knownActions = actionsForClip.knownActions;
  27447. action._byClipCacheIndex = knownActions.length;
  27448. knownActions.push(action);
  27449. }
  27450. action._cacheIndex = actions.length;
  27451. actions.push(action);
  27452. actionsForClip.actionByRoot[rootUuid] = action;
  27453. },
  27454. _removeInactiveAction: function _removeInactiveAction(action) {
  27455. var actions = this._actions,
  27456. lastInactiveAction = actions[actions.length - 1],
  27457. cacheIndex = action._cacheIndex;
  27458. lastInactiveAction._cacheIndex = cacheIndex;
  27459. actions[cacheIndex] = lastInactiveAction;
  27460. actions.pop();
  27461. action._cacheIndex = null;
  27462. var clipUuid = action._clip.uuid,
  27463. actionsByClip = this._actionsByClip,
  27464. actionsForClip = actionsByClip[clipUuid],
  27465. knownActionsForClip = actionsForClip.knownActions,
  27466. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27467. byClipCacheIndex = action._byClipCacheIndex;
  27468. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27469. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27470. knownActionsForClip.pop();
  27471. action._byClipCacheIndex = null;
  27472. var actionByRoot = actionsForClip.actionByRoot,
  27473. rootUuid = (action._localRoot || this._root).uuid;
  27474. delete actionByRoot[rootUuid];
  27475. if (knownActionsForClip.length === 0) {
  27476. delete actionsByClip[clipUuid];
  27477. }
  27478. this._removeInactiveBindingsForAction(action);
  27479. },
  27480. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27481. var bindings = action._propertyBindings;
  27482. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27483. var binding = bindings[i];
  27484. if (--binding.referenceCount === 0) {
  27485. this._removeInactiveBinding(binding);
  27486. }
  27487. }
  27488. },
  27489. _lendAction: function _lendAction(action) {
  27490. // [ active actions | inactive actions ]
  27491. // [ active actions >| inactive actions ]
  27492. // s a
  27493. // <-swap->
  27494. // a s
  27495. var actions = this._actions,
  27496. prevIndex = action._cacheIndex,
  27497. lastActiveIndex = this._nActiveActions++,
  27498. firstInactiveAction = actions[lastActiveIndex];
  27499. action._cacheIndex = lastActiveIndex;
  27500. actions[lastActiveIndex] = action;
  27501. firstInactiveAction._cacheIndex = prevIndex;
  27502. actions[prevIndex] = firstInactiveAction;
  27503. },
  27504. _takeBackAction: function _takeBackAction(action) {
  27505. // [ active actions | inactive actions ]
  27506. // [ active actions |< inactive actions ]
  27507. // a s
  27508. // <-swap->
  27509. // s a
  27510. var actions = this._actions,
  27511. prevIndex = action._cacheIndex,
  27512. firstInactiveIndex = --this._nActiveActions,
  27513. lastActiveAction = actions[firstInactiveIndex];
  27514. action._cacheIndex = firstInactiveIndex;
  27515. actions[firstInactiveIndex] = action;
  27516. lastActiveAction._cacheIndex = prevIndex;
  27517. actions[prevIndex] = lastActiveAction;
  27518. },
  27519. // Memory management for PropertyMixer objects
  27520. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27521. var bindingsByRoot = this._bindingsByRootAndName,
  27522. bindings = this._bindings;
  27523. var bindingByName = bindingsByRoot[rootUuid];
  27524. if (bindingByName === undefined) {
  27525. bindingByName = {};
  27526. bindingsByRoot[rootUuid] = bindingByName;
  27527. }
  27528. bindingByName[trackName] = binding;
  27529. binding._cacheIndex = bindings.length;
  27530. bindings.push(binding);
  27531. },
  27532. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27533. var bindings = this._bindings,
  27534. propBinding = binding.binding,
  27535. rootUuid = propBinding.rootNode.uuid,
  27536. trackName = propBinding.path,
  27537. bindingsByRoot = this._bindingsByRootAndName,
  27538. bindingByName = bindingsByRoot[rootUuid],
  27539. lastInactiveBinding = bindings[bindings.length - 1],
  27540. cacheIndex = binding._cacheIndex;
  27541. lastInactiveBinding._cacheIndex = cacheIndex;
  27542. bindings[cacheIndex] = lastInactiveBinding;
  27543. bindings.pop();
  27544. delete bindingByName[trackName];
  27545. if (Object.keys(bindingByName).length === 0) {
  27546. delete bindingsByRoot[rootUuid];
  27547. }
  27548. },
  27549. _lendBinding: function _lendBinding(binding) {
  27550. var bindings = this._bindings,
  27551. prevIndex = binding._cacheIndex,
  27552. lastActiveIndex = this._nActiveBindings++,
  27553. firstInactiveBinding = bindings[lastActiveIndex];
  27554. binding._cacheIndex = lastActiveIndex;
  27555. bindings[lastActiveIndex] = binding;
  27556. firstInactiveBinding._cacheIndex = prevIndex;
  27557. bindings[prevIndex] = firstInactiveBinding;
  27558. },
  27559. _takeBackBinding: function _takeBackBinding(binding) {
  27560. var bindings = this._bindings,
  27561. prevIndex = binding._cacheIndex,
  27562. firstInactiveIndex = --this._nActiveBindings,
  27563. lastActiveBinding = bindings[firstInactiveIndex];
  27564. binding._cacheIndex = firstInactiveIndex;
  27565. bindings[firstInactiveIndex] = binding;
  27566. lastActiveBinding._cacheIndex = prevIndex;
  27567. bindings[prevIndex] = lastActiveBinding;
  27568. },
  27569. // Memory management of Interpolants for weight and time scale
  27570. _lendControlInterpolant: function _lendControlInterpolant() {
  27571. var interpolants = this._controlInterpolants,
  27572. lastActiveIndex = this._nActiveControlInterpolants++;
  27573. var interpolant = interpolants[lastActiveIndex];
  27574. if (interpolant === undefined) {
  27575. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27576. interpolant.__cacheIndex = lastActiveIndex;
  27577. interpolants[lastActiveIndex] = interpolant;
  27578. }
  27579. return interpolant;
  27580. },
  27581. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27582. var interpolants = this._controlInterpolants,
  27583. prevIndex = interpolant.__cacheIndex,
  27584. firstInactiveIndex = --this._nActiveControlInterpolants,
  27585. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27586. interpolant.__cacheIndex = firstInactiveIndex;
  27587. interpolants[firstInactiveIndex] = interpolant;
  27588. lastActiveInterpolant.__cacheIndex = prevIndex;
  27589. interpolants[prevIndex] = lastActiveInterpolant;
  27590. },
  27591. _controlInterpolantsResultBuffer: new Float32Array(1),
  27592. // return an action for a clip optionally using a custom root target
  27593. // object (this method allocates a lot of dynamic memory in case a
  27594. // previously unknown clip/root combination is specified)
  27595. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27596. var root = optionalRoot || this._root,
  27597. rootUuid = root.uuid;
  27598. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27599. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27600. var actionsForClip = this._actionsByClip[clipUuid];
  27601. var prototypeAction = null;
  27602. if (blendMode === undefined) {
  27603. if (clipObject !== null) {
  27604. blendMode = clipObject.blendMode;
  27605. } else {
  27606. blendMode = NormalAnimationBlendMode;
  27607. }
  27608. }
  27609. if (actionsForClip !== undefined) {
  27610. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27611. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27612. return existingAction;
  27613. } // we know the clip, so we don't have to parse all
  27614. // the bindings again but can just copy
  27615. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27616. if (clipObject === null) clipObject = prototypeAction._clip;
  27617. } // clip must be known when specified via string
  27618. if (clipObject === null) return null; // allocate all resources required to run it
  27619. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27620. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27621. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27622. return newAction;
  27623. },
  27624. // get an existing action
  27625. existingAction: function existingAction(clip, optionalRoot) {
  27626. var root = optionalRoot || this._root,
  27627. rootUuid = root.uuid,
  27628. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27629. clipUuid = clipObject ? clipObject.uuid : clip,
  27630. actionsForClip = this._actionsByClip[clipUuid];
  27631. if (actionsForClip !== undefined) {
  27632. return actionsForClip.actionByRoot[rootUuid] || null;
  27633. }
  27634. return null;
  27635. },
  27636. // deactivates all previously scheduled actions
  27637. stopAllAction: function stopAllAction() {
  27638. var actions = this._actions,
  27639. nActions = this._nActiveActions;
  27640. for (var i = nActions - 1; i >= 0; --i) {
  27641. actions[i].stop();
  27642. }
  27643. return this;
  27644. },
  27645. // advance the time and update apply the animation
  27646. update: function update(deltaTime) {
  27647. deltaTime *= this.timeScale;
  27648. var actions = this._actions,
  27649. nActions = this._nActiveActions,
  27650. time = this.time += deltaTime,
  27651. timeDirection = Math.sign(deltaTime),
  27652. accuIndex = this._accuIndex ^= 1; // run active actions
  27653. for (var i = 0; i !== nActions; ++i) {
  27654. var action = actions[i];
  27655. action._update(time, deltaTime, timeDirection, accuIndex);
  27656. } // update scene graph
  27657. var bindings = this._bindings,
  27658. nBindings = this._nActiveBindings;
  27659. for (var _i = 0; _i !== nBindings; ++_i) {
  27660. bindings[_i].apply(accuIndex);
  27661. }
  27662. return this;
  27663. },
  27664. // Allows you to seek to a specific time in an animation.
  27665. setTime: function setTime(timeInSeconds) {
  27666. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27667. for (var i = 0; i < this._actions.length; i++) {
  27668. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27669. }
  27670. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27671. },
  27672. // return this mixer's root target object
  27673. getRoot: function getRoot() {
  27674. return this._root;
  27675. },
  27676. // free all resources specific to a particular clip
  27677. uncacheClip: function uncacheClip(clip) {
  27678. var actions = this._actions,
  27679. clipUuid = clip.uuid,
  27680. actionsByClip = this._actionsByClip,
  27681. actionsForClip = actionsByClip[clipUuid];
  27682. if (actionsForClip !== undefined) {
  27683. // note: just calling _removeInactiveAction would mess up the
  27684. // iteration state and also require updating the state we can
  27685. // just throw away
  27686. var actionsToRemove = actionsForClip.knownActions;
  27687. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27688. var action = actionsToRemove[i];
  27689. this._deactivateAction(action);
  27690. var cacheIndex = action._cacheIndex,
  27691. lastInactiveAction = actions[actions.length - 1];
  27692. action._cacheIndex = null;
  27693. action._byClipCacheIndex = null;
  27694. lastInactiveAction._cacheIndex = cacheIndex;
  27695. actions[cacheIndex] = lastInactiveAction;
  27696. actions.pop();
  27697. this._removeInactiveBindingsForAction(action);
  27698. }
  27699. delete actionsByClip[clipUuid];
  27700. }
  27701. },
  27702. // free all resources specific to a particular root target object
  27703. uncacheRoot: function uncacheRoot(root) {
  27704. var rootUuid = root.uuid,
  27705. actionsByClip = this._actionsByClip;
  27706. for (var clipUuid in actionsByClip) {
  27707. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27708. action = actionByRoot[rootUuid];
  27709. if (action !== undefined) {
  27710. this._deactivateAction(action);
  27711. this._removeInactiveAction(action);
  27712. }
  27713. }
  27714. var bindingsByRoot = this._bindingsByRootAndName,
  27715. bindingByName = bindingsByRoot[rootUuid];
  27716. if (bindingByName !== undefined) {
  27717. for (var trackName in bindingByName) {
  27718. var binding = bindingByName[trackName];
  27719. binding.restoreOriginalState();
  27720. this._removeInactiveBinding(binding);
  27721. }
  27722. }
  27723. },
  27724. // remove a targeted clip from the cache
  27725. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27726. var action = this.existingAction(clip, optionalRoot);
  27727. if (action !== null) {
  27728. this._deactivateAction(action);
  27729. this._removeInactiveAction(action);
  27730. }
  27731. }
  27732. });
  27733. var Uniform = /*#__PURE__*/function () {
  27734. function Uniform(value) {
  27735. if (typeof value === 'string') {
  27736. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27737. value = arguments[1];
  27738. }
  27739. this.value = value;
  27740. }
  27741. var _proto = Uniform.prototype;
  27742. _proto.clone = function clone() {
  27743. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27744. };
  27745. return Uniform;
  27746. }();
  27747. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27748. InterleavedBuffer.call(this, array, stride);
  27749. this.meshPerAttribute = meshPerAttribute || 1;
  27750. }
  27751. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27752. constructor: InstancedInterleavedBuffer,
  27753. isInstancedInterleavedBuffer: true,
  27754. copy: function copy(source) {
  27755. InterleavedBuffer.prototype.copy.call(this, source);
  27756. this.meshPerAttribute = source.meshPerAttribute;
  27757. return this;
  27758. },
  27759. clone: function clone(data) {
  27760. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27761. ib.meshPerAttribute = this.meshPerAttribute;
  27762. return ib;
  27763. },
  27764. toJSON: function toJSON(data) {
  27765. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27766. json.isInstancedInterleavedBuffer = true;
  27767. json.meshPerAttribute = this.meshPerAttribute;
  27768. return json;
  27769. }
  27770. });
  27771. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27772. this.buffer = buffer;
  27773. this.type = type;
  27774. this.itemSize = itemSize;
  27775. this.elementSize = elementSize;
  27776. this.count = count;
  27777. this.version = 0;
  27778. }
  27779. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27780. set: function set(value) {
  27781. if (value === true) this.version++;
  27782. }
  27783. });
  27784. Object.assign(GLBufferAttribute.prototype, {
  27785. isGLBufferAttribute: true,
  27786. setBuffer: function setBuffer(buffer) {
  27787. this.buffer = buffer;
  27788. return this;
  27789. },
  27790. setType: function setType(type, elementSize) {
  27791. this.type = type;
  27792. this.elementSize = elementSize;
  27793. return this;
  27794. },
  27795. setItemSize: function setItemSize(itemSize) {
  27796. this.itemSize = itemSize;
  27797. return this;
  27798. },
  27799. setCount: function setCount(count) {
  27800. this.count = count;
  27801. return this;
  27802. }
  27803. });
  27804. function Raycaster(origin, direction, near, far) {
  27805. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27806. this.near = near || 0;
  27807. this.far = far || Infinity;
  27808. this.camera = null;
  27809. this.layers = new Layers();
  27810. this.params = {
  27811. Mesh: {},
  27812. Line: {
  27813. threshold: 1
  27814. },
  27815. LOD: {},
  27816. Points: {
  27817. threshold: 1
  27818. },
  27819. Sprite: {}
  27820. };
  27821. Object.defineProperties(this.params, {
  27822. PointCloud: {
  27823. get: function get() {
  27824. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27825. return this.Points;
  27826. }
  27827. }
  27828. });
  27829. }
  27830. function ascSort(a, b) {
  27831. return a.distance - b.distance;
  27832. }
  27833. function _intersectObject(object, raycaster, intersects, recursive) {
  27834. if (object.layers.test(raycaster.layers)) {
  27835. object.raycast(raycaster, intersects);
  27836. }
  27837. if (recursive === true) {
  27838. var children = object.children;
  27839. for (var i = 0, l = children.length; i < l; i++) {
  27840. _intersectObject(children[i], raycaster, intersects, true);
  27841. }
  27842. }
  27843. }
  27844. Object.assign(Raycaster.prototype, {
  27845. set: function set(origin, direction) {
  27846. // direction is assumed to be normalized (for accurate distance calculations)
  27847. this.ray.set(origin, direction);
  27848. },
  27849. setFromCamera: function setFromCamera(coords, camera) {
  27850. if (camera && camera.isPerspectiveCamera) {
  27851. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27852. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27853. this.camera = camera;
  27854. } else if (camera && camera.isOrthographicCamera) {
  27855. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27856. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27857. this.camera = camera;
  27858. } else {
  27859. console.error('THREE.Raycaster: Unsupported camera type.');
  27860. }
  27861. },
  27862. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27863. var intersects = optionalTarget || [];
  27864. _intersectObject(object, this, intersects, recursive);
  27865. intersects.sort(ascSort);
  27866. return intersects;
  27867. },
  27868. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27869. var intersects = optionalTarget || [];
  27870. if (Array.isArray(objects) === false) {
  27871. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27872. return intersects;
  27873. }
  27874. for (var i = 0, l = objects.length; i < l; i++) {
  27875. _intersectObject(objects[i], this, intersects, recursive);
  27876. }
  27877. intersects.sort(ascSort);
  27878. return intersects;
  27879. }
  27880. });
  27881. /**
  27882. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27883. *
  27884. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27885. * The azimuthal angle (theta) is measured from the positive z-axis.
  27886. */
  27887. var Spherical = /*#__PURE__*/function () {
  27888. function Spherical(radius, phi, theta) {
  27889. if (radius === void 0) {
  27890. radius = 1;
  27891. }
  27892. if (phi === void 0) {
  27893. phi = 0;
  27894. }
  27895. if (theta === void 0) {
  27896. theta = 0;
  27897. }
  27898. this.radius = radius;
  27899. this.phi = phi; // polar angle
  27900. this.theta = theta; // azimuthal angle
  27901. return this;
  27902. }
  27903. var _proto = Spherical.prototype;
  27904. _proto.set = function set(radius, phi, theta) {
  27905. this.radius = radius;
  27906. this.phi = phi;
  27907. this.theta = theta;
  27908. return this;
  27909. };
  27910. _proto.clone = function clone() {
  27911. return new this.constructor().copy(this);
  27912. };
  27913. _proto.copy = function copy(other) {
  27914. this.radius = other.radius;
  27915. this.phi = other.phi;
  27916. this.theta = other.theta;
  27917. return this;
  27918. } // restrict phi to be betwee EPS and PI-EPS
  27919. ;
  27920. _proto.makeSafe = function makeSafe() {
  27921. var EPS = 0.000001;
  27922. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27923. return this;
  27924. };
  27925. _proto.setFromVector3 = function setFromVector3(v) {
  27926. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27927. };
  27928. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27929. this.radius = Math.sqrt(x * x + y * y + z * z);
  27930. if (this.radius === 0) {
  27931. this.theta = 0;
  27932. this.phi = 0;
  27933. } else {
  27934. this.theta = Math.atan2(x, z);
  27935. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27936. }
  27937. return this;
  27938. };
  27939. return Spherical;
  27940. }();
  27941. /**
  27942. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27943. */
  27944. var Cylindrical = /*#__PURE__*/function () {
  27945. function Cylindrical(radius, theta, y) {
  27946. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27947. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27948. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27949. return this;
  27950. }
  27951. var _proto = Cylindrical.prototype;
  27952. _proto.set = function set(radius, theta, y) {
  27953. this.radius = radius;
  27954. this.theta = theta;
  27955. this.y = y;
  27956. return this;
  27957. };
  27958. _proto.clone = function clone() {
  27959. return new this.constructor().copy(this);
  27960. };
  27961. _proto.copy = function copy(other) {
  27962. this.radius = other.radius;
  27963. this.theta = other.theta;
  27964. this.y = other.y;
  27965. return this;
  27966. };
  27967. _proto.setFromVector3 = function setFromVector3(v) {
  27968. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27969. };
  27970. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27971. this.radius = Math.sqrt(x * x + z * z);
  27972. this.theta = Math.atan2(x, z);
  27973. this.y = y;
  27974. return this;
  27975. };
  27976. return Cylindrical;
  27977. }();
  27978. var _vector$7 = /*@__PURE__*/new Vector2();
  27979. var Box2 = /*#__PURE__*/function () {
  27980. function Box2(min, max) {
  27981. Object.defineProperty(this, 'isBox2', {
  27982. value: true
  27983. });
  27984. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27985. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27986. }
  27987. var _proto = Box2.prototype;
  27988. _proto.set = function set(min, max) {
  27989. this.min.copy(min);
  27990. this.max.copy(max);
  27991. return this;
  27992. };
  27993. _proto.setFromPoints = function setFromPoints(points) {
  27994. this.makeEmpty();
  27995. for (var i = 0, il = points.length; i < il; i++) {
  27996. this.expandByPoint(points[i]);
  27997. }
  27998. return this;
  27999. };
  28000. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  28001. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  28002. this.min.copy(center).sub(halfSize);
  28003. this.max.copy(center).add(halfSize);
  28004. return this;
  28005. };
  28006. _proto.clone = function clone() {
  28007. return new this.constructor().copy(this);
  28008. };
  28009. _proto.copy = function copy(box) {
  28010. this.min.copy(box.min);
  28011. this.max.copy(box.max);
  28012. return this;
  28013. };
  28014. _proto.makeEmpty = function makeEmpty() {
  28015. this.min.x = this.min.y = +Infinity;
  28016. this.max.x = this.max.y = -Infinity;
  28017. return this;
  28018. };
  28019. _proto.isEmpty = function isEmpty() {
  28020. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  28021. return this.max.x < this.min.x || this.max.y < this.min.y;
  28022. };
  28023. _proto.getCenter = function getCenter(target) {
  28024. if (target === undefined) {
  28025. console.warn('THREE.Box2: .getCenter() target is now required');
  28026. target = new Vector2();
  28027. }
  28028. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  28029. };
  28030. _proto.getSize = function getSize(target) {
  28031. if (target === undefined) {
  28032. console.warn('THREE.Box2: .getSize() target is now required');
  28033. target = new Vector2();
  28034. }
  28035. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  28036. };
  28037. _proto.expandByPoint = function expandByPoint(point) {
  28038. this.min.min(point);
  28039. this.max.max(point);
  28040. return this;
  28041. };
  28042. _proto.expandByVector = function expandByVector(vector) {
  28043. this.min.sub(vector);
  28044. this.max.add(vector);
  28045. return this;
  28046. };
  28047. _proto.expandByScalar = function expandByScalar(scalar) {
  28048. this.min.addScalar(-scalar);
  28049. this.max.addScalar(scalar);
  28050. return this;
  28051. };
  28052. _proto.containsPoint = function containsPoint(point) {
  28053. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  28054. };
  28055. _proto.containsBox = function containsBox(box) {
  28056. 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;
  28057. };
  28058. _proto.getParameter = function getParameter(point, target) {
  28059. // This can potentially have a divide by zero if the box
  28060. // has a size dimension of 0.
  28061. if (target === undefined) {
  28062. console.warn('THREE.Box2: .getParameter() target is now required');
  28063. target = new Vector2();
  28064. }
  28065. 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));
  28066. };
  28067. _proto.intersectsBox = function intersectsBox(box) {
  28068. // using 4 splitting planes to rule out intersections
  28069. 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;
  28070. };
  28071. _proto.clampPoint = function clampPoint(point, target) {
  28072. if (target === undefined) {
  28073. console.warn('THREE.Box2: .clampPoint() target is now required');
  28074. target = new Vector2();
  28075. }
  28076. return target.copy(point).clamp(this.min, this.max);
  28077. };
  28078. _proto.distanceToPoint = function distanceToPoint(point) {
  28079. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  28080. return clampedPoint.sub(point).length();
  28081. };
  28082. _proto.intersect = function intersect(box) {
  28083. this.min.max(box.min);
  28084. this.max.min(box.max);
  28085. return this;
  28086. };
  28087. _proto.union = function union(box) {
  28088. this.min.min(box.min);
  28089. this.max.max(box.max);
  28090. return this;
  28091. };
  28092. _proto.translate = function translate(offset) {
  28093. this.min.add(offset);
  28094. this.max.add(offset);
  28095. return this;
  28096. };
  28097. _proto.equals = function equals(box) {
  28098. return box.min.equals(this.min) && box.max.equals(this.max);
  28099. };
  28100. return Box2;
  28101. }();
  28102. var _startP = /*@__PURE__*/new Vector3();
  28103. var _startEnd = /*@__PURE__*/new Vector3();
  28104. var Line3 = /*#__PURE__*/function () {
  28105. function Line3(start, end) {
  28106. this.start = start !== undefined ? start : new Vector3();
  28107. this.end = end !== undefined ? end : new Vector3();
  28108. }
  28109. var _proto = Line3.prototype;
  28110. _proto.set = function set(start, end) {
  28111. this.start.copy(start);
  28112. this.end.copy(end);
  28113. return this;
  28114. };
  28115. _proto.clone = function clone() {
  28116. return new this.constructor().copy(this);
  28117. };
  28118. _proto.copy = function copy(line) {
  28119. this.start.copy(line.start);
  28120. this.end.copy(line.end);
  28121. return this;
  28122. };
  28123. _proto.getCenter = function getCenter(target) {
  28124. if (target === undefined) {
  28125. console.warn('THREE.Line3: .getCenter() target is now required');
  28126. target = new Vector3();
  28127. }
  28128. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  28129. };
  28130. _proto.delta = function delta(target) {
  28131. if (target === undefined) {
  28132. console.warn('THREE.Line3: .delta() target is now required');
  28133. target = new Vector3();
  28134. }
  28135. return target.subVectors(this.end, this.start);
  28136. };
  28137. _proto.distanceSq = function distanceSq() {
  28138. return this.start.distanceToSquared(this.end);
  28139. };
  28140. _proto.distance = function distance() {
  28141. return this.start.distanceTo(this.end);
  28142. };
  28143. _proto.at = function at(t, target) {
  28144. if (target === undefined) {
  28145. console.warn('THREE.Line3: .at() target is now required');
  28146. target = new Vector3();
  28147. }
  28148. return this.delta(target).multiplyScalar(t).add(this.start);
  28149. };
  28150. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  28151. _startP.subVectors(point, this.start);
  28152. _startEnd.subVectors(this.end, this.start);
  28153. var startEnd2 = _startEnd.dot(_startEnd);
  28154. var startEnd_startP = _startEnd.dot(_startP);
  28155. var t = startEnd_startP / startEnd2;
  28156. if (clampToLine) {
  28157. t = MathUtils.clamp(t, 0, 1);
  28158. }
  28159. return t;
  28160. };
  28161. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  28162. var t = this.closestPointToPointParameter(point, clampToLine);
  28163. if (target === undefined) {
  28164. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  28165. target = new Vector3();
  28166. }
  28167. return this.delta(target).multiplyScalar(t).add(this.start);
  28168. };
  28169. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  28170. this.start.applyMatrix4(matrix);
  28171. this.end.applyMatrix4(matrix);
  28172. return this;
  28173. };
  28174. _proto.equals = function equals(line) {
  28175. return line.start.equals(this.start) && line.end.equals(this.end);
  28176. };
  28177. return Line3;
  28178. }();
  28179. function ImmediateRenderObject(material) {
  28180. Object3D.call(this);
  28181. this.material = material;
  28182. this.render = function ()
  28183. /* renderCallback */
  28184. {};
  28185. this.hasPositions = false;
  28186. this.hasNormals = false;
  28187. this.hasColors = false;
  28188. this.hasUvs = false;
  28189. this.positionArray = null;
  28190. this.normalArray = null;
  28191. this.colorArray = null;
  28192. this.uvArray = null;
  28193. this.count = 0;
  28194. }
  28195. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28196. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28197. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28198. var _vector$8 = /*@__PURE__*/new Vector3();
  28199. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28200. _inheritsLoose(SpotLightHelper, _Object3D);
  28201. function SpotLightHelper(light, color) {
  28202. var _this;
  28203. _this = _Object3D.call(this) || this;
  28204. _this.light = light;
  28205. _this.light.updateMatrixWorld();
  28206. _this.matrix = light.matrixWorld;
  28207. _this.matrixAutoUpdate = false;
  28208. _this.color = color;
  28209. var geometry = new BufferGeometry();
  28210. 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];
  28211. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28212. var p1 = i / l * Math.PI * 2;
  28213. var p2 = j / l * Math.PI * 2;
  28214. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28215. }
  28216. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28217. var material = new LineBasicMaterial({
  28218. fog: false,
  28219. toneMapped: false
  28220. });
  28221. _this.cone = new LineSegments(geometry, material);
  28222. _this.add(_this.cone);
  28223. _this.update();
  28224. return _this;
  28225. }
  28226. var _proto = SpotLightHelper.prototype;
  28227. _proto.dispose = function dispose() {
  28228. this.cone.geometry.dispose();
  28229. this.cone.material.dispose();
  28230. };
  28231. _proto.update = function update() {
  28232. this.light.updateMatrixWorld();
  28233. var coneLength = this.light.distance ? this.light.distance : 1000;
  28234. var coneWidth = coneLength * Math.tan(this.light.angle);
  28235. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28236. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  28237. this.cone.lookAt(_vector$8);
  28238. if (this.color !== undefined) {
  28239. this.cone.material.color.set(this.color);
  28240. } else {
  28241. this.cone.material.color.copy(this.light.color);
  28242. }
  28243. };
  28244. return SpotLightHelper;
  28245. }(Object3D);
  28246. var _vector$9 = /*@__PURE__*/new Vector3();
  28247. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28248. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28249. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28250. _inheritsLoose(SkeletonHelper, _LineSegments);
  28251. function SkeletonHelper(object) {
  28252. var _this;
  28253. var bones = getBoneList(object);
  28254. var geometry = new BufferGeometry();
  28255. var vertices = [];
  28256. var colors = [];
  28257. var color1 = new Color(0, 0, 1);
  28258. var color2 = new Color(0, 1, 0);
  28259. for (var i = 0; i < bones.length; i++) {
  28260. var bone = bones[i];
  28261. if (bone.parent && bone.parent.isBone) {
  28262. vertices.push(0, 0, 0);
  28263. vertices.push(0, 0, 0);
  28264. colors.push(color1.r, color1.g, color1.b);
  28265. colors.push(color2.r, color2.g, color2.b);
  28266. }
  28267. }
  28268. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28269. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28270. var material = new LineBasicMaterial({
  28271. vertexColors: true,
  28272. depthTest: false,
  28273. depthWrite: false,
  28274. toneMapped: false,
  28275. transparent: true
  28276. });
  28277. _this = _LineSegments.call(this, geometry, material) || this;
  28278. _this.type = 'SkeletonHelper';
  28279. _this.isSkeletonHelper = true;
  28280. _this.root = object;
  28281. _this.bones = bones;
  28282. _this.matrix = object.matrixWorld;
  28283. _this.matrixAutoUpdate = false;
  28284. return _this;
  28285. }
  28286. var _proto = SkeletonHelper.prototype;
  28287. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28288. var bones = this.bones;
  28289. var geometry = this.geometry;
  28290. var position = geometry.getAttribute('position');
  28291. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28292. for (var i = 0, j = 0; i < bones.length; i++) {
  28293. var bone = bones[i];
  28294. if (bone.parent && bone.parent.isBone) {
  28295. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28296. _vector$9.setFromMatrixPosition(_boneMatrix);
  28297. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  28298. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28299. _vector$9.setFromMatrixPosition(_boneMatrix);
  28300. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  28301. j += 2;
  28302. }
  28303. }
  28304. geometry.getAttribute('position').needsUpdate = true;
  28305. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28306. };
  28307. return SkeletonHelper;
  28308. }(LineSegments);
  28309. function getBoneList(object) {
  28310. var boneList = [];
  28311. if (object && object.isBone) {
  28312. boneList.push(object);
  28313. }
  28314. for (var i = 0; i < object.children.length; i++) {
  28315. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28316. }
  28317. return boneList;
  28318. }
  28319. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28320. _inheritsLoose(PointLightHelper, _Mesh);
  28321. function PointLightHelper(light, sphereSize, color) {
  28322. var _this;
  28323. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  28324. var material = new MeshBasicMaterial({
  28325. wireframe: true,
  28326. fog: false,
  28327. toneMapped: false
  28328. });
  28329. _this = _Mesh.call(this, geometry, material) || this;
  28330. _this.light = light;
  28331. _this.light.updateMatrixWorld();
  28332. _this.color = color;
  28333. _this.type = 'PointLightHelper';
  28334. _this.matrix = _this.light.matrixWorld;
  28335. _this.matrixAutoUpdate = false;
  28336. _this.update();
  28337. /*
  28338. // TODO: delete this comment?
  28339. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28340. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28341. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28342. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28343. const d = light.distance;
  28344. if ( d === 0.0 ) {
  28345. this.lightDistance.visible = false;
  28346. } else {
  28347. this.lightDistance.scale.set( d, d, d );
  28348. }
  28349. this.add( this.lightDistance );
  28350. */
  28351. return _this;
  28352. }
  28353. var _proto = PointLightHelper.prototype;
  28354. _proto.dispose = function dispose() {
  28355. this.geometry.dispose();
  28356. this.material.dispose();
  28357. };
  28358. _proto.update = function update() {
  28359. if (this.color !== undefined) {
  28360. this.material.color.set(this.color);
  28361. } else {
  28362. this.material.color.copy(this.light.color);
  28363. }
  28364. /*
  28365. const d = this.light.distance;
  28366. if ( d === 0.0 ) {
  28367. this.lightDistance.visible = false;
  28368. } else {
  28369. this.lightDistance.visible = true;
  28370. this.lightDistance.scale.set( d, d, d );
  28371. }
  28372. */
  28373. };
  28374. return PointLightHelper;
  28375. }(Mesh);
  28376. var _vector$a = /*@__PURE__*/new Vector3();
  28377. var _color1 = /*@__PURE__*/new Color();
  28378. var _color2 = /*@__PURE__*/new Color();
  28379. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28380. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28381. function HemisphereLightHelper(light, size, color) {
  28382. var _this;
  28383. _this = _Object3D.call(this) || this;
  28384. _this.light = light;
  28385. _this.light.updateMatrixWorld();
  28386. _this.matrix = light.matrixWorld;
  28387. _this.matrixAutoUpdate = false;
  28388. _this.color = color;
  28389. var geometry = new OctahedronBufferGeometry(size);
  28390. geometry.rotateY(Math.PI * 0.5);
  28391. _this.material = new MeshBasicMaterial({
  28392. wireframe: true,
  28393. fog: false,
  28394. toneMapped: false
  28395. });
  28396. if (_this.color === undefined) _this.material.vertexColors = true;
  28397. var position = geometry.getAttribute('position');
  28398. var colors = new Float32Array(position.count * 3);
  28399. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28400. _this.add(new Mesh(geometry, _this.material));
  28401. _this.update();
  28402. return _this;
  28403. }
  28404. var _proto = HemisphereLightHelper.prototype;
  28405. _proto.dispose = function dispose() {
  28406. this.children[0].geometry.dispose();
  28407. this.children[0].material.dispose();
  28408. };
  28409. _proto.update = function update() {
  28410. var mesh = this.children[0];
  28411. if (this.color !== undefined) {
  28412. this.material.color.set(this.color);
  28413. } else {
  28414. var colors = mesh.geometry.getAttribute('color');
  28415. _color1.copy(this.light.color);
  28416. _color2.copy(this.light.groundColor);
  28417. for (var i = 0, l = colors.count; i < l; i++) {
  28418. var color = i < l / 2 ? _color1 : _color2;
  28419. colors.setXYZ(i, color.r, color.g, color.b);
  28420. }
  28421. colors.needsUpdate = true;
  28422. }
  28423. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  28424. };
  28425. return HemisphereLightHelper;
  28426. }(Object3D);
  28427. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28428. _inheritsLoose(GridHelper, _LineSegments);
  28429. function GridHelper(size, divisions, color1, color2) {
  28430. var _this;
  28431. if (size === void 0) {
  28432. size = 10;
  28433. }
  28434. if (divisions === void 0) {
  28435. divisions = 10;
  28436. }
  28437. if (color1 === void 0) {
  28438. color1 = 0x444444;
  28439. }
  28440. if (color2 === void 0) {
  28441. color2 = 0x888888;
  28442. }
  28443. color1 = new Color(color1);
  28444. color2 = new Color(color2);
  28445. var center = divisions / 2;
  28446. var step = size / divisions;
  28447. var halfSize = size / 2;
  28448. var vertices = [],
  28449. colors = [];
  28450. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28451. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28452. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28453. var color = i === center ? color1 : color2;
  28454. color.toArray(colors, j);
  28455. j += 3;
  28456. color.toArray(colors, j);
  28457. j += 3;
  28458. color.toArray(colors, j);
  28459. j += 3;
  28460. color.toArray(colors, j);
  28461. j += 3;
  28462. }
  28463. var geometry = new BufferGeometry();
  28464. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28465. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28466. var material = new LineBasicMaterial({
  28467. vertexColors: true,
  28468. toneMapped: false
  28469. });
  28470. _this = _LineSegments.call(this, geometry, material) || this;
  28471. _this.type = 'GridHelper';
  28472. return _this;
  28473. }
  28474. return GridHelper;
  28475. }(LineSegments);
  28476. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28477. _inheritsLoose(PolarGridHelper, _LineSegments);
  28478. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28479. var _this;
  28480. if (radius === void 0) {
  28481. radius = 10;
  28482. }
  28483. if (radials === void 0) {
  28484. radials = 16;
  28485. }
  28486. if (circles === void 0) {
  28487. circles = 8;
  28488. }
  28489. if (divisions === void 0) {
  28490. divisions = 64;
  28491. }
  28492. if (color1 === void 0) {
  28493. color1 = 0x444444;
  28494. }
  28495. if (color2 === void 0) {
  28496. color2 = 0x888888;
  28497. }
  28498. color1 = new Color(color1);
  28499. color2 = new Color(color2);
  28500. var vertices = [];
  28501. var colors = []; // create the radials
  28502. for (var i = 0; i <= radials; i++) {
  28503. var v = i / radials * (Math.PI * 2);
  28504. var x = Math.sin(v) * radius;
  28505. var z = Math.cos(v) * radius;
  28506. vertices.push(0, 0, 0);
  28507. vertices.push(x, 0, z);
  28508. var color = i & 1 ? color1 : color2;
  28509. colors.push(color.r, color.g, color.b);
  28510. colors.push(color.r, color.g, color.b);
  28511. } // create the circles
  28512. for (var _i = 0; _i <= circles; _i++) {
  28513. var _color = _i & 1 ? color1 : color2;
  28514. var r = radius - radius / circles * _i;
  28515. for (var j = 0; j < divisions; j++) {
  28516. // first vertex
  28517. var _v = j / divisions * (Math.PI * 2);
  28518. var _x = Math.sin(_v) * r;
  28519. var _z = Math.cos(_v) * r;
  28520. vertices.push(_x, 0, _z);
  28521. colors.push(_color.r, _color.g, _color.b); // second vertex
  28522. _v = (j + 1) / divisions * (Math.PI * 2);
  28523. _x = Math.sin(_v) * r;
  28524. _z = Math.cos(_v) * r;
  28525. vertices.push(_x, 0, _z);
  28526. colors.push(_color.r, _color.g, _color.b);
  28527. }
  28528. }
  28529. var geometry = new BufferGeometry();
  28530. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28531. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28532. var material = new LineBasicMaterial({
  28533. vertexColors: true,
  28534. toneMapped: false
  28535. });
  28536. _this = _LineSegments.call(this, geometry, material) || this;
  28537. _this.type = 'PolarGridHelper';
  28538. return _this;
  28539. }
  28540. return PolarGridHelper;
  28541. }(LineSegments);
  28542. var _v1$6 = /*@__PURE__*/new Vector3();
  28543. var _v2$3 = /*@__PURE__*/new Vector3();
  28544. var _v3$1 = /*@__PURE__*/new Vector3();
  28545. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28546. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28547. function DirectionalLightHelper(light, size, color) {
  28548. var _this;
  28549. _this = _Object3D.call(this) || this;
  28550. _this.light = light;
  28551. _this.light.updateMatrixWorld();
  28552. _this.matrix = light.matrixWorld;
  28553. _this.matrixAutoUpdate = false;
  28554. _this.color = color;
  28555. if (size === undefined) size = 1;
  28556. var geometry = new BufferGeometry();
  28557. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28558. var material = new LineBasicMaterial({
  28559. fog: false,
  28560. toneMapped: false
  28561. });
  28562. _this.lightPlane = new Line(geometry, material);
  28563. _this.add(_this.lightPlane);
  28564. geometry = new BufferGeometry();
  28565. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28566. _this.targetLine = new Line(geometry, material);
  28567. _this.add(_this.targetLine);
  28568. _this.update();
  28569. return _this;
  28570. }
  28571. var _proto = DirectionalLightHelper.prototype;
  28572. _proto.dispose = function dispose() {
  28573. this.lightPlane.geometry.dispose();
  28574. this.lightPlane.material.dispose();
  28575. this.targetLine.geometry.dispose();
  28576. this.targetLine.material.dispose();
  28577. };
  28578. _proto.update = function update() {
  28579. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28580. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28581. _v3$1.subVectors(_v2$3, _v1$6);
  28582. this.lightPlane.lookAt(_v2$3);
  28583. if (this.color !== undefined) {
  28584. this.lightPlane.material.color.set(this.color);
  28585. this.targetLine.material.color.set(this.color);
  28586. } else {
  28587. this.lightPlane.material.color.copy(this.light.color);
  28588. this.targetLine.material.color.copy(this.light.color);
  28589. }
  28590. this.targetLine.lookAt(_v2$3);
  28591. this.targetLine.scale.z = _v3$1.length();
  28592. };
  28593. return DirectionalLightHelper;
  28594. }(Object3D);
  28595. var _vector$b = /*@__PURE__*/new Vector3();
  28596. var _camera = /*@__PURE__*/new Camera();
  28597. /**
  28598. * - shows frustum, line of sight and up of the camera
  28599. * - suitable for fast updates
  28600. * - based on frustum visualization in lightgl.js shadowmap example
  28601. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28602. */
  28603. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28604. _inheritsLoose(CameraHelper, _LineSegments);
  28605. function CameraHelper(camera) {
  28606. var _this;
  28607. var geometry = new BufferGeometry();
  28608. var material = new LineBasicMaterial({
  28609. color: 0xffffff,
  28610. vertexColors: true,
  28611. toneMapped: false
  28612. });
  28613. var vertices = [];
  28614. var colors = [];
  28615. var pointMap = {}; // colors
  28616. var colorFrustum = new Color(0xffaa00);
  28617. var colorCone = new Color(0xff0000);
  28618. var colorUp = new Color(0x00aaff);
  28619. var colorTarget = new Color(0xffffff);
  28620. var colorCross = new Color(0x333333); // near
  28621. addLine('n1', 'n2', colorFrustum);
  28622. addLine('n2', 'n4', colorFrustum);
  28623. addLine('n4', 'n3', colorFrustum);
  28624. addLine('n3', 'n1', colorFrustum); // far
  28625. addLine('f1', 'f2', colorFrustum);
  28626. addLine('f2', 'f4', colorFrustum);
  28627. addLine('f4', 'f3', colorFrustum);
  28628. addLine('f3', 'f1', colorFrustum); // sides
  28629. addLine('n1', 'f1', colorFrustum);
  28630. addLine('n2', 'f2', colorFrustum);
  28631. addLine('n3', 'f3', colorFrustum);
  28632. addLine('n4', 'f4', colorFrustum); // cone
  28633. addLine('p', 'n1', colorCone);
  28634. addLine('p', 'n2', colorCone);
  28635. addLine('p', 'n3', colorCone);
  28636. addLine('p', 'n4', colorCone); // up
  28637. addLine('u1', 'u2', colorUp);
  28638. addLine('u2', 'u3', colorUp);
  28639. addLine('u3', 'u1', colorUp); // target
  28640. addLine('c', 't', colorTarget);
  28641. addLine('p', 'c', colorCross); // cross
  28642. addLine('cn1', 'cn2', colorCross);
  28643. addLine('cn3', 'cn4', colorCross);
  28644. addLine('cf1', 'cf2', colorCross);
  28645. addLine('cf3', 'cf4', colorCross);
  28646. function addLine(a, b, color) {
  28647. addPoint(a, color);
  28648. addPoint(b, color);
  28649. }
  28650. function addPoint(id, color) {
  28651. vertices.push(0, 0, 0);
  28652. colors.push(color.r, color.g, color.b);
  28653. if (pointMap[id] === undefined) {
  28654. pointMap[id] = [];
  28655. }
  28656. pointMap[id].push(vertices.length / 3 - 1);
  28657. }
  28658. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28659. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28660. _this = _LineSegments.call(this, geometry, material) || this;
  28661. _this.type = 'CameraHelper';
  28662. _this.camera = camera;
  28663. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28664. _this.matrix = camera.matrixWorld;
  28665. _this.matrixAutoUpdate = false;
  28666. _this.pointMap = pointMap;
  28667. _this.update();
  28668. return _this;
  28669. }
  28670. var _proto = CameraHelper.prototype;
  28671. _proto.update = function update() {
  28672. var geometry = this.geometry;
  28673. var pointMap = this.pointMap;
  28674. var w = 1,
  28675. h = 1; // we need just camera projection matrix inverse
  28676. // world matrix must be identity
  28677. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28678. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28679. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28680. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28681. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28682. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28683. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28684. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28685. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28686. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28687. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28688. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28689. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28690. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28691. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28692. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28693. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28694. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28695. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28696. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28697. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28698. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28699. geometry.getAttribute('position').needsUpdate = true;
  28700. };
  28701. return CameraHelper;
  28702. }(LineSegments);
  28703. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28704. _vector$b.set(x, y, z).unproject(camera);
  28705. var points = pointMap[point];
  28706. if (points !== undefined) {
  28707. var position = geometry.getAttribute('position');
  28708. for (var i = 0, l = points.length; i < l; i++) {
  28709. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  28710. }
  28711. }
  28712. }
  28713. var _box$3 = /*@__PURE__*/new Box3();
  28714. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28715. _inheritsLoose(BoxHelper, _LineSegments);
  28716. function BoxHelper(object, color) {
  28717. var _this;
  28718. if (color === void 0) {
  28719. color = 0xffff00;
  28720. }
  28721. 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]);
  28722. var positions = new Float32Array(8 * 3);
  28723. var geometry = new BufferGeometry();
  28724. geometry.setIndex(new BufferAttribute(indices, 1));
  28725. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28726. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28727. color: color,
  28728. toneMapped: false
  28729. })) || this;
  28730. _this.object = object;
  28731. _this.type = 'BoxHelper';
  28732. _this.matrixAutoUpdate = false;
  28733. _this.update();
  28734. return _this;
  28735. }
  28736. var _proto = BoxHelper.prototype;
  28737. _proto.update = function update(object) {
  28738. if (object !== undefined) {
  28739. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28740. }
  28741. if (this.object !== undefined) {
  28742. _box$3.setFromObject(this.object);
  28743. }
  28744. if (_box$3.isEmpty()) return;
  28745. var min = _box$3.min;
  28746. var max = _box$3.max;
  28747. /*
  28748. 5____4
  28749. 1/___0/|
  28750. | 6__|_7
  28751. 2/___3/
  28752. 0: max.x, max.y, max.z
  28753. 1: min.x, max.y, max.z
  28754. 2: min.x, min.y, max.z
  28755. 3: max.x, min.y, max.z
  28756. 4: max.x, max.y, min.z
  28757. 5: min.x, max.y, min.z
  28758. 6: min.x, min.y, min.z
  28759. 7: max.x, min.y, min.z
  28760. */
  28761. var position = this.geometry.attributes.position;
  28762. var array = position.array;
  28763. array[0] = max.x;
  28764. array[1] = max.y;
  28765. array[2] = max.z;
  28766. array[3] = min.x;
  28767. array[4] = max.y;
  28768. array[5] = max.z;
  28769. array[6] = min.x;
  28770. array[7] = min.y;
  28771. array[8] = max.z;
  28772. array[9] = max.x;
  28773. array[10] = min.y;
  28774. array[11] = max.z;
  28775. array[12] = max.x;
  28776. array[13] = max.y;
  28777. array[14] = min.z;
  28778. array[15] = min.x;
  28779. array[16] = max.y;
  28780. array[17] = min.z;
  28781. array[18] = min.x;
  28782. array[19] = min.y;
  28783. array[20] = min.z;
  28784. array[21] = max.x;
  28785. array[22] = min.y;
  28786. array[23] = min.z;
  28787. position.needsUpdate = true;
  28788. this.geometry.computeBoundingSphere();
  28789. };
  28790. _proto.setFromObject = function setFromObject(object) {
  28791. this.object = object;
  28792. this.update();
  28793. return this;
  28794. };
  28795. _proto.copy = function copy(source) {
  28796. LineSegments.prototype.copy.call(this, source);
  28797. this.object = source.object;
  28798. return this;
  28799. };
  28800. return BoxHelper;
  28801. }(LineSegments);
  28802. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28803. _inheritsLoose(Box3Helper, _LineSegments);
  28804. function Box3Helper(box, color) {
  28805. var _this;
  28806. if (color === void 0) {
  28807. color = 0xffff00;
  28808. }
  28809. 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]);
  28810. 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];
  28811. var geometry = new BufferGeometry();
  28812. geometry.setIndex(new BufferAttribute(indices, 1));
  28813. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28814. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28815. color: color,
  28816. toneMapped: false
  28817. })) || this;
  28818. _this.box = box;
  28819. _this.type = 'Box3Helper';
  28820. _this.geometry.computeBoundingSphere();
  28821. return _this;
  28822. }
  28823. var _proto = Box3Helper.prototype;
  28824. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28825. var box = this.box;
  28826. if (box.isEmpty()) return;
  28827. box.getCenter(this.position);
  28828. box.getSize(this.scale);
  28829. this.scale.multiplyScalar(0.5);
  28830. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28831. };
  28832. return Box3Helper;
  28833. }(LineSegments);
  28834. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28835. _inheritsLoose(PlaneHelper, _Line);
  28836. function PlaneHelper(plane, size, hex) {
  28837. var _this;
  28838. if (size === void 0) {
  28839. size = 1;
  28840. }
  28841. if (hex === void 0) {
  28842. hex = 0xffff00;
  28843. }
  28844. var color = hex;
  28845. 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];
  28846. var geometry = new BufferGeometry();
  28847. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28848. geometry.computeBoundingSphere();
  28849. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28850. color: color,
  28851. toneMapped: false
  28852. })) || this;
  28853. _this.type = 'PlaneHelper';
  28854. _this.plane = plane;
  28855. _this.size = size;
  28856. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28857. var geometry2 = new BufferGeometry();
  28858. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28859. geometry2.computeBoundingSphere();
  28860. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28861. color: color,
  28862. opacity: 0.2,
  28863. transparent: true,
  28864. depthWrite: false,
  28865. toneMapped: false
  28866. })));
  28867. return _this;
  28868. }
  28869. var _proto = PlaneHelper.prototype;
  28870. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28871. var scale = -this.plane.constant;
  28872. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28873. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28874. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28875. this.lookAt(this.plane.normal);
  28876. _Line.prototype.updateMatrixWorld.call(this, force);
  28877. };
  28878. return PlaneHelper;
  28879. }(Line);
  28880. var _axis = /*@__PURE__*/new Vector3();
  28881. var _lineGeometry, _coneGeometry;
  28882. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28883. _inheritsLoose(ArrowHelper, _Object3D);
  28884. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28885. var _this;
  28886. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28887. _this.type = 'ArrowHelper';
  28888. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28889. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28890. if (length === undefined) length = 1;
  28891. if (color === undefined) color = 0xffff00;
  28892. if (headLength === undefined) headLength = 0.2 * length;
  28893. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28894. if (_lineGeometry === undefined) {
  28895. _lineGeometry = new BufferGeometry();
  28896. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28897. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28898. _coneGeometry.translate(0, -0.5, 0);
  28899. }
  28900. _this.position.copy(origin);
  28901. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28902. color: color,
  28903. toneMapped: false
  28904. }));
  28905. _this.line.matrixAutoUpdate = false;
  28906. _this.add(_this.line);
  28907. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28908. color: color,
  28909. toneMapped: false
  28910. }));
  28911. _this.cone.matrixAutoUpdate = false;
  28912. _this.add(_this.cone);
  28913. _this.setDirection(dir);
  28914. _this.setLength(length, headLength, headWidth);
  28915. return _this;
  28916. }
  28917. var _proto = ArrowHelper.prototype;
  28918. _proto.setDirection = function setDirection(dir) {
  28919. // dir is assumed to be normalized
  28920. if (dir.y > 0.99999) {
  28921. this.quaternion.set(0, 0, 0, 1);
  28922. } else if (dir.y < -0.99999) {
  28923. this.quaternion.set(1, 0, 0, 0);
  28924. } else {
  28925. _axis.set(dir.z, 0, -dir.x).normalize();
  28926. var radians = Math.acos(dir.y);
  28927. this.quaternion.setFromAxisAngle(_axis, radians);
  28928. }
  28929. };
  28930. _proto.setLength = function setLength(length, headLength, headWidth) {
  28931. if (headLength === undefined) headLength = 0.2 * length;
  28932. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28933. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28934. this.line.updateMatrix();
  28935. this.cone.scale.set(headWidth, headLength, headWidth);
  28936. this.cone.position.y = length;
  28937. this.cone.updateMatrix();
  28938. };
  28939. _proto.setColor = function setColor(color) {
  28940. this.line.material.color.set(color);
  28941. this.cone.material.color.set(color);
  28942. };
  28943. _proto.copy = function copy(source) {
  28944. _Object3D.prototype.copy.call(this, source, false);
  28945. this.line.copy(source.line);
  28946. this.cone.copy(source.cone);
  28947. return this;
  28948. };
  28949. return ArrowHelper;
  28950. }(Object3D);
  28951. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28952. _inheritsLoose(AxesHelper, _LineSegments);
  28953. function AxesHelper(size) {
  28954. var _this;
  28955. if (size === void 0) {
  28956. size = 1;
  28957. }
  28958. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28959. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28960. var geometry = new BufferGeometry();
  28961. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28962. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28963. var material = new LineBasicMaterial({
  28964. vertexColors: true,
  28965. toneMapped: false
  28966. });
  28967. _this = _LineSegments.call(this, geometry, material) || this;
  28968. _this.type = 'AxesHelper';
  28969. return _this;
  28970. }
  28971. return AxesHelper;
  28972. }(LineSegments);
  28973. var _floatView = new Float32Array(1);
  28974. var _int32View = new Int32Array(_floatView.buffer);
  28975. var DataUtils = {
  28976. // Converts float32 to float16 (stored as uint16 value).
  28977. toHalfFloat: function toHalfFloat(val) {
  28978. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28979. /* This method is faster than the OpenEXR implementation (very often
  28980. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28981. * by James Tursa?s half-precision code. */
  28982. _floatView[0] = val;
  28983. var x = _int32View[0];
  28984. var bits = x >> 16 & 0x8000;
  28985. /* Get the sign */
  28986. var m = x >> 12 & 0x07ff;
  28987. /* Keep one extra bit for rounding */
  28988. var e = x >> 23 & 0xff;
  28989. /* Using int is faster here */
  28990. /* If zero, or denormal, or exponent underflows too much for a denormal
  28991. * half, return signed zero. */
  28992. if (e < 103) return bits;
  28993. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28994. if (e > 142) {
  28995. bits |= 0x7c00;
  28996. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28997. * not Inf, so make sure we set one mantissa bit too. */
  28998. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28999. return bits;
  29000. }
  29001. /* If exponent underflows but not too much, return a denormal */
  29002. if (e < 113) {
  29003. m |= 0x0800;
  29004. /* Extra rounding may overflow and set mantissa to 0 and exponent
  29005. * to 1, which is OK. */
  29006. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  29007. return bits;
  29008. }
  29009. bits |= e - 112 << 10 | m >> 1;
  29010. /* Extra rounding. An overflow will set mantissa to 0 and increment
  29011. * the exponent, which is OK. */
  29012. bits += m & 1;
  29013. return bits;
  29014. }
  29015. };
  29016. var _ENCODINGS;
  29017. var LOD_MIN = 4;
  29018. var LOD_MAX = 8;
  29019. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  29020. // chosen to approximate a Trowbridge-Reitz distribution function times the
  29021. // geometric shadowing function. These sigma values squared must match the
  29022. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  29023. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  29024. 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
  29025. // samples and exit early, but not recompile the shader.
  29026. var MAX_SAMPLES = 20;
  29027. 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);
  29028. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  29029. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  29030. _lodPlanes = _createPlanes2._lodPlanes,
  29031. _sizeLods = _createPlanes2._sizeLods,
  29032. _sigmas = _createPlanes2._sigmas;
  29033. var _oldTarget = null; // Golden Ratio
  29034. var PHI = (1 + Math.sqrt(5)) / 2;
  29035. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  29036. // same axis), used as axis directions evenly spread on a sphere.
  29037. 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)];
  29038. /**
  29039. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  29040. * (PMREM) from a cubeMap environment texture. This allows different levels of
  29041. * blur to be quickly accessed based on material roughness. It is packed into a
  29042. * special CubeUV format that allows us to perform custom interpolation so that
  29043. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  29044. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  29045. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  29046. * higher roughness levels. In this way we maintain resolution to smoothly
  29047. * interpolate diffuse lighting while limiting sampling computation.
  29048. */
  29049. var PMREMGenerator = /*#__PURE__*/function () {
  29050. function PMREMGenerator(renderer) {
  29051. this._renderer = renderer;
  29052. this._pingPongRenderTarget = null;
  29053. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  29054. this._equirectShader = null;
  29055. this._cubemapShader = null;
  29056. this._compileMaterial(this._blurMaterial);
  29057. }
  29058. /**
  29059. * Generates a PMREM from a supplied Scene, which can be faster than using an
  29060. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  29061. * in radians to be applied to the scene before PMREM generation. Optional near
  29062. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  29063. * is placed at the origin).
  29064. */
  29065. var _proto = PMREMGenerator.prototype;
  29066. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  29067. if (sigma === void 0) {
  29068. sigma = 0;
  29069. }
  29070. if (near === void 0) {
  29071. near = 0.1;
  29072. }
  29073. if (far === void 0) {
  29074. far = 100;
  29075. }
  29076. _oldTarget = this._renderer.getRenderTarget();
  29077. var cubeUVRenderTarget = this._allocateTargets();
  29078. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  29079. if (sigma > 0) {
  29080. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  29081. }
  29082. this._applyPMREM(cubeUVRenderTarget);
  29083. this._cleanup(cubeUVRenderTarget);
  29084. return cubeUVRenderTarget;
  29085. }
  29086. /**
  29087. * Generates a PMREM from an equirectangular texture, which can be either LDR
  29088. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  29089. * as this matches best with the 256 x 256 cubemap output.
  29090. */
  29091. ;
  29092. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  29093. return this._fromTexture(equirectangular);
  29094. }
  29095. /**
  29096. * Generates a PMREM from an cubemap texture, which can be either LDR
  29097. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  29098. * as this matches best with the 256 x 256 cubemap output.
  29099. */
  29100. ;
  29101. _proto.fromCubemap = function fromCubemap(cubemap) {
  29102. return this._fromTexture(cubemap);
  29103. }
  29104. /**
  29105. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  29106. * your texture's network fetch for increased concurrency.
  29107. */
  29108. ;
  29109. _proto.compileCubemapShader = function compileCubemapShader() {
  29110. if (this._cubemapShader === null) {
  29111. this._cubemapShader = _getCubemapShader();
  29112. this._compileMaterial(this._cubemapShader);
  29113. }
  29114. }
  29115. /**
  29116. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  29117. * your texture's network fetch for increased concurrency.
  29118. */
  29119. ;
  29120. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  29121. if (this._equirectShader === null) {
  29122. this._equirectShader = _getEquirectShader();
  29123. this._compileMaterial(this._equirectShader);
  29124. }
  29125. }
  29126. /**
  29127. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29128. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29129. * one of them will cause any others to also become unusable.
  29130. */
  29131. ;
  29132. _proto.dispose = function dispose() {
  29133. this._blurMaterial.dispose();
  29134. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  29135. if (this._equirectShader !== null) this._equirectShader.dispose();
  29136. for (var i = 0; i < _lodPlanes.length; i++) {
  29137. _lodPlanes[i].dispose();
  29138. }
  29139. } // private interface
  29140. ;
  29141. _proto._cleanup = function _cleanup(outputTarget) {
  29142. this._pingPongRenderTarget.dispose();
  29143. this._renderer.setRenderTarget(_oldTarget);
  29144. outputTarget.scissorTest = false;
  29145. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29146. };
  29147. _proto._fromTexture = function _fromTexture(texture) {
  29148. _oldTarget = this._renderer.getRenderTarget();
  29149. var cubeUVRenderTarget = this._allocateTargets(texture);
  29150. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29151. this._applyPMREM(cubeUVRenderTarget);
  29152. this._cleanup(cubeUVRenderTarget);
  29153. return cubeUVRenderTarget;
  29154. };
  29155. _proto._allocateTargets = function _allocateTargets(texture) {
  29156. // warning: null texture is valid
  29157. var params = {
  29158. magFilter: NearestFilter,
  29159. minFilter: NearestFilter,
  29160. generateMipmaps: false,
  29161. type: UnsignedByteType,
  29162. format: RGBEFormat,
  29163. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29164. depthBuffer: false
  29165. };
  29166. var cubeUVRenderTarget = _createRenderTarget(params);
  29167. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29168. this._pingPongRenderTarget = _createRenderTarget(params);
  29169. return cubeUVRenderTarget;
  29170. };
  29171. _proto._compileMaterial = function _compileMaterial(material) {
  29172. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29173. this._renderer.compile(tmpMesh, _flatCamera);
  29174. };
  29175. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29176. var fov = 90;
  29177. var aspect = 1;
  29178. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29179. var upSign = [1, -1, 1, 1, 1, 1];
  29180. var forwardSign = [1, 1, 1, -1, -1, -1];
  29181. var renderer = this._renderer;
  29182. var outputEncoding = renderer.outputEncoding;
  29183. var toneMapping = renderer.toneMapping;
  29184. var clearColor = renderer.getClearColor();
  29185. var clearAlpha = renderer.getClearAlpha();
  29186. renderer.toneMapping = NoToneMapping;
  29187. renderer.outputEncoding = LinearEncoding;
  29188. var background = scene.background;
  29189. if (background && background.isColor) {
  29190. background.convertSRGBToLinear(); // Convert linear to RGBE
  29191. var maxComponent = Math.max(background.r, background.g, background.b);
  29192. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  29193. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  29194. var alpha = (fExp + 128.0) / 255.0;
  29195. renderer.setClearColor(background, alpha);
  29196. scene.background = null;
  29197. }
  29198. for (var i = 0; i < 6; i++) {
  29199. var col = i % 3;
  29200. if (col == 0) {
  29201. cubeCamera.up.set(0, upSign[i], 0);
  29202. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29203. } else if (col == 1) {
  29204. cubeCamera.up.set(0, 0, upSign[i]);
  29205. cubeCamera.lookAt(0, forwardSign[i], 0);
  29206. } else {
  29207. cubeCamera.up.set(0, upSign[i], 0);
  29208. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29209. }
  29210. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29211. renderer.setRenderTarget(cubeUVRenderTarget);
  29212. renderer.render(scene, cubeCamera);
  29213. }
  29214. renderer.toneMapping = toneMapping;
  29215. renderer.outputEncoding = outputEncoding;
  29216. renderer.setClearColor(clearColor, clearAlpha);
  29217. };
  29218. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29219. var renderer = this._renderer;
  29220. if (texture.isCubeTexture) {
  29221. if (this._cubemapShader == null) {
  29222. this._cubemapShader = _getCubemapShader();
  29223. }
  29224. } else {
  29225. if (this._equirectShader == null) {
  29226. this._equirectShader = _getEquirectShader();
  29227. }
  29228. }
  29229. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29230. var mesh = new Mesh(_lodPlanes[0], material);
  29231. var uniforms = material.uniforms;
  29232. uniforms['envMap'].value = texture;
  29233. if (!texture.isCubeTexture) {
  29234. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29235. }
  29236. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29237. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29238. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29239. renderer.setRenderTarget(cubeUVRenderTarget);
  29240. renderer.render(mesh, _flatCamera);
  29241. };
  29242. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29243. var renderer = this._renderer;
  29244. var autoClear = renderer.autoClear;
  29245. renderer.autoClear = false;
  29246. for (var i = 1; i < TOTAL_LODS; i++) {
  29247. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29248. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29249. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29250. }
  29251. renderer.autoClear = autoClear;
  29252. }
  29253. /**
  29254. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29255. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29256. * the blur latitudinally (around the poles), and then longitudinally (towards
  29257. * the poles) to approximate the orthogonally-separable blur. It is least
  29258. * accurate at the poles, but still does a decent job.
  29259. */
  29260. ;
  29261. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29262. var pingPongRenderTarget = this._pingPongRenderTarget;
  29263. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29264. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29265. };
  29266. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29267. var renderer = this._renderer;
  29268. var blurMaterial = this._blurMaterial;
  29269. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29270. console.error('blur direction must be either latitudinal or longitudinal!');
  29271. } // Number of standard deviations at which to cut off the discrete approximation.
  29272. var STANDARD_DEVIATIONS = 3;
  29273. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29274. var blurUniforms = blurMaterial.uniforms;
  29275. var pixels = _sizeLods[lodIn] - 1;
  29276. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29277. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29278. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29279. if (samples > MAX_SAMPLES) {
  29280. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29281. }
  29282. var weights = [];
  29283. var sum = 0;
  29284. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29285. var _x = i / sigmaPixels;
  29286. var weight = Math.exp(-_x * _x / 2);
  29287. weights.push(weight);
  29288. if (i == 0) {
  29289. sum += weight;
  29290. } else if (i < samples) {
  29291. sum += 2 * weight;
  29292. }
  29293. }
  29294. for (var _i = 0; _i < weights.length; _i++) {
  29295. weights[_i] = weights[_i] / sum;
  29296. }
  29297. blurUniforms['envMap'].value = targetIn.texture;
  29298. blurUniforms['samples'].value = samples;
  29299. blurUniforms['weights'].value = weights;
  29300. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29301. if (poleAxis) {
  29302. blurUniforms['poleAxis'].value = poleAxis;
  29303. }
  29304. blurUniforms['dTheta'].value = radiansPerPixel;
  29305. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29306. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29307. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29308. var outputSize = _sizeLods[lodOut];
  29309. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29310. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29311. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29312. renderer.setRenderTarget(targetOut);
  29313. renderer.render(blurMesh, _flatCamera);
  29314. };
  29315. return PMREMGenerator;
  29316. }();
  29317. function _isLDR(texture) {
  29318. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29319. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29320. }
  29321. function _createPlanes() {
  29322. var _lodPlanes = [];
  29323. var _sizeLods = [];
  29324. var _sigmas = [];
  29325. var lod = LOD_MAX;
  29326. for (var i = 0; i < TOTAL_LODS; i++) {
  29327. var sizeLod = Math.pow(2, lod);
  29328. _sizeLods.push(sizeLod);
  29329. var sigma = 1.0 / sizeLod;
  29330. if (i > LOD_MAX - LOD_MIN) {
  29331. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29332. } else if (i == 0) {
  29333. sigma = 0;
  29334. }
  29335. _sigmas.push(sigma);
  29336. var texelSize = 1.0 / (sizeLod - 1);
  29337. var min = -texelSize / 2;
  29338. var max = 1 + texelSize / 2;
  29339. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29340. var cubeFaces = 6;
  29341. var vertices = 6;
  29342. var positionSize = 3;
  29343. var uvSize = 2;
  29344. var faceIndexSize = 1;
  29345. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29346. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29347. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29348. for (var face = 0; face < cubeFaces; face++) {
  29349. var x = face % 3 * 2 / 3 - 1;
  29350. var y = face > 2 ? 0 : -1;
  29351. 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];
  29352. position.set(coordinates, positionSize * vertices * face);
  29353. uv.set(uv1, uvSize * vertices * face);
  29354. var fill = [face, face, face, face, face, face];
  29355. faceIndex.set(fill, faceIndexSize * vertices * face);
  29356. }
  29357. var planes = new BufferGeometry();
  29358. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29359. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29360. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29361. _lodPlanes.push(planes);
  29362. if (lod > LOD_MIN) {
  29363. lod--;
  29364. }
  29365. }
  29366. return {
  29367. _lodPlanes: _lodPlanes,
  29368. _sizeLods: _sizeLods,
  29369. _sigmas: _sigmas
  29370. };
  29371. }
  29372. function _createRenderTarget(params) {
  29373. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29374. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29375. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29376. cubeUVRenderTarget.scissorTest = true;
  29377. return cubeUVRenderTarget;
  29378. }
  29379. function _setViewport(target, x, y, width, height) {
  29380. target.viewport.set(x, y, width, height);
  29381. target.scissor.set(x, y, width, height);
  29382. }
  29383. function _getBlurShader(maxSamples) {
  29384. var weights = new Float32Array(maxSamples);
  29385. var poleAxis = new Vector3(0, 1, 0);
  29386. var shaderMaterial = new RawShaderMaterial({
  29387. name: 'SphericalGaussianBlur',
  29388. defines: {
  29389. 'n': maxSamples
  29390. },
  29391. uniforms: {
  29392. 'envMap': {
  29393. value: null
  29394. },
  29395. 'samples': {
  29396. value: 1
  29397. },
  29398. 'weights': {
  29399. value: weights
  29400. },
  29401. 'latitudinal': {
  29402. value: false
  29403. },
  29404. 'dTheta': {
  29405. value: 0
  29406. },
  29407. 'mipInt': {
  29408. value: 0
  29409. },
  29410. 'poleAxis': {
  29411. value: poleAxis
  29412. },
  29413. 'inputEncoding': {
  29414. value: ENCODINGS[LinearEncoding]
  29415. },
  29416. 'outputEncoding': {
  29417. value: ENCODINGS[LinearEncoding]
  29418. }
  29419. },
  29420. vertexShader: _getCommonVertexShader(),
  29421. fragmentShader:
  29422. /* glsl */
  29423. "\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",
  29424. blending: NoBlending,
  29425. depthTest: false,
  29426. depthWrite: false
  29427. });
  29428. return shaderMaterial;
  29429. }
  29430. function _getEquirectShader() {
  29431. var texelSize = new Vector2(1, 1);
  29432. var shaderMaterial = new RawShaderMaterial({
  29433. name: 'EquirectangularToCubeUV',
  29434. uniforms: {
  29435. 'envMap': {
  29436. value: null
  29437. },
  29438. 'texelSize': {
  29439. value: texelSize
  29440. },
  29441. 'inputEncoding': {
  29442. value: ENCODINGS[LinearEncoding]
  29443. },
  29444. 'outputEncoding': {
  29445. value: ENCODINGS[LinearEncoding]
  29446. }
  29447. },
  29448. vertexShader: _getCommonVertexShader(),
  29449. fragmentShader:
  29450. /* glsl */
  29451. "\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",
  29452. blending: NoBlending,
  29453. depthTest: false,
  29454. depthWrite: false
  29455. });
  29456. return shaderMaterial;
  29457. }
  29458. function _getCubemapShader() {
  29459. var shaderMaterial = new RawShaderMaterial({
  29460. name: 'CubemapToCubeUV',
  29461. uniforms: {
  29462. 'envMap': {
  29463. value: null
  29464. },
  29465. 'inputEncoding': {
  29466. value: ENCODINGS[LinearEncoding]
  29467. },
  29468. 'outputEncoding': {
  29469. value: ENCODINGS[LinearEncoding]
  29470. }
  29471. },
  29472. vertexShader: _getCommonVertexShader(),
  29473. fragmentShader:
  29474. /* glsl */
  29475. "\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",
  29476. blending: NoBlending,
  29477. depthTest: false,
  29478. depthWrite: false
  29479. });
  29480. return shaderMaterial;
  29481. }
  29482. function _getCommonVertexShader() {
  29483. return (
  29484. /* glsl */
  29485. "\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"
  29486. );
  29487. }
  29488. function _getEncodings() {
  29489. return (
  29490. /* glsl */
  29491. "\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"
  29492. );
  29493. }
  29494. function Face4(a, b, c, d, normal, color, materialIndex) {
  29495. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  29496. return new Face3(a, b, c, normal, color, materialIndex);
  29497. }
  29498. var LineStrip = 0;
  29499. var LinePieces = 1;
  29500. var NoColors = 0;
  29501. var FaceColors = 1;
  29502. var VertexColors = 2;
  29503. function MeshFaceMaterial(materials) {
  29504. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29505. return materials;
  29506. }
  29507. function MultiMaterial(materials) {
  29508. if (materials === void 0) {
  29509. materials = [];
  29510. }
  29511. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29512. materials.isMultiMaterial = true;
  29513. materials.materials = materials;
  29514. materials.clone = function () {
  29515. return materials.slice();
  29516. };
  29517. return materials;
  29518. }
  29519. function PointCloud(geometry, material) {
  29520. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29521. return new Points(geometry, material);
  29522. }
  29523. function Particle(material) {
  29524. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29525. return new Sprite(material);
  29526. }
  29527. function ParticleSystem(geometry, material) {
  29528. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29529. return new Points(geometry, material);
  29530. }
  29531. function PointCloudMaterial(parameters) {
  29532. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29533. return new PointsMaterial(parameters);
  29534. }
  29535. function ParticleBasicMaterial(parameters) {
  29536. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29537. return new PointsMaterial(parameters);
  29538. }
  29539. function ParticleSystemMaterial(parameters) {
  29540. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29541. return new PointsMaterial(parameters);
  29542. }
  29543. function Vertex(x, y, z) {
  29544. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29545. return new Vector3(x, y, z);
  29546. } //
  29547. function DynamicBufferAttribute(array, itemSize) {
  29548. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29549. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29550. }
  29551. function Int8Attribute(array, itemSize) {
  29552. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29553. return new Int8BufferAttribute(array, itemSize);
  29554. }
  29555. function Uint8Attribute(array, itemSize) {
  29556. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29557. return new Uint8BufferAttribute(array, itemSize);
  29558. }
  29559. function Uint8ClampedAttribute(array, itemSize) {
  29560. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29561. return new Uint8ClampedBufferAttribute(array, itemSize);
  29562. }
  29563. function Int16Attribute(array, itemSize) {
  29564. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29565. return new Int16BufferAttribute(array, itemSize);
  29566. }
  29567. function Uint16Attribute(array, itemSize) {
  29568. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29569. return new Uint16BufferAttribute(array, itemSize);
  29570. }
  29571. function Int32Attribute(array, itemSize) {
  29572. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29573. return new Int32BufferAttribute(array, itemSize);
  29574. }
  29575. function Uint32Attribute(array, itemSize) {
  29576. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29577. return new Uint32BufferAttribute(array, itemSize);
  29578. }
  29579. function Float32Attribute(array, itemSize) {
  29580. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29581. return new Float32BufferAttribute(array, itemSize);
  29582. }
  29583. function Float64Attribute(array, itemSize) {
  29584. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29585. return new Float64BufferAttribute(array, itemSize);
  29586. } //
  29587. Curve.create = function (construct, getPoint) {
  29588. console.log('THREE.Curve.create() has been deprecated');
  29589. construct.prototype = Object.create(Curve.prototype);
  29590. construct.prototype.constructor = construct;
  29591. construct.prototype.getPoint = getPoint;
  29592. return construct;
  29593. }; //
  29594. Object.assign(CurvePath.prototype, {
  29595. createPointsGeometry: function createPointsGeometry(divisions) {
  29596. 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)
  29597. var pts = this.getPoints(divisions);
  29598. return this.createGeometry(pts);
  29599. },
  29600. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  29601. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  29602. var pts = this.getSpacedPoints(divisions);
  29603. return this.createGeometry(pts);
  29604. },
  29605. createGeometry: function createGeometry(points) {
  29606. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  29607. var geometry = new Geometry();
  29608. for (var i = 0, l = points.length; i < l; i++) {
  29609. var point = points[i];
  29610. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  29611. }
  29612. return geometry;
  29613. }
  29614. }); //
  29615. Object.assign(Path.prototype, {
  29616. fromPoints: function fromPoints(points) {
  29617. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29618. return this.setFromPoints(points);
  29619. }
  29620. }); //
  29621. function ClosedSplineCurve3(points) {
  29622. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29623. CatmullRomCurve3.call(this, points);
  29624. this.type = 'catmullrom';
  29625. this.closed = true;
  29626. }
  29627. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29628. function SplineCurve3(points) {
  29629. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29630. CatmullRomCurve3.call(this, points);
  29631. this.type = 'catmullrom';
  29632. }
  29633. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29634. function Spline(points) {
  29635. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29636. CatmullRomCurve3.call(this, points);
  29637. this.type = 'catmullrom';
  29638. }
  29639. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29640. Object.assign(Spline.prototype, {
  29641. initFromArray: function initFromArray()
  29642. /* a */
  29643. {
  29644. console.error('THREE.Spline: .initFromArray() has been removed.');
  29645. },
  29646. getControlPointsArray: function getControlPointsArray()
  29647. /* optionalTarget */
  29648. {
  29649. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29650. },
  29651. reparametrizeByArcLength: function reparametrizeByArcLength()
  29652. /* samplingCoef */
  29653. {
  29654. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29655. }
  29656. }); //
  29657. function AxisHelper(size) {
  29658. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29659. return new AxesHelper(size);
  29660. }
  29661. function BoundingBoxHelper(object, color) {
  29662. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29663. return new BoxHelper(object, color);
  29664. }
  29665. function EdgesHelper(object, hex) {
  29666. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29667. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29668. color: hex !== undefined ? hex : 0xffffff
  29669. }));
  29670. }
  29671. GridHelper.prototype.setColors = function () {
  29672. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29673. };
  29674. SkeletonHelper.prototype.update = function () {
  29675. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29676. };
  29677. function WireframeHelper(object, hex) {
  29678. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29679. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29680. color: hex !== undefined ? hex : 0xffffff
  29681. }));
  29682. } //
  29683. Object.assign(Loader.prototype, {
  29684. extractUrlBase: function extractUrlBase(url) {
  29685. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29686. return LoaderUtils.extractUrlBase(url);
  29687. }
  29688. });
  29689. Loader.Handlers = {
  29690. add: function add()
  29691. /* regex, loader */
  29692. {
  29693. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29694. },
  29695. get: function get()
  29696. /* file */
  29697. {
  29698. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29699. }
  29700. };
  29701. function XHRLoader(manager) {
  29702. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29703. return new FileLoader(manager);
  29704. }
  29705. function BinaryTextureLoader(manager) {
  29706. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29707. return new DataTextureLoader(manager);
  29708. } //
  29709. Object.assign(Box2.prototype, {
  29710. center: function center(optionalTarget) {
  29711. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29712. return this.getCenter(optionalTarget);
  29713. },
  29714. empty: function empty() {
  29715. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29716. return this.isEmpty();
  29717. },
  29718. isIntersectionBox: function isIntersectionBox(box) {
  29719. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29720. return this.intersectsBox(box);
  29721. },
  29722. size: function size(optionalTarget) {
  29723. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29724. return this.getSize(optionalTarget);
  29725. }
  29726. });
  29727. Object.assign(Box3.prototype, {
  29728. center: function center(optionalTarget) {
  29729. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29730. return this.getCenter(optionalTarget);
  29731. },
  29732. empty: function empty() {
  29733. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29734. return this.isEmpty();
  29735. },
  29736. isIntersectionBox: function isIntersectionBox(box) {
  29737. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29738. return this.intersectsBox(box);
  29739. },
  29740. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29741. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29742. return this.intersectsSphere(sphere);
  29743. },
  29744. size: function size(optionalTarget) {
  29745. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29746. return this.getSize(optionalTarget);
  29747. }
  29748. });
  29749. Object.assign(Sphere.prototype, {
  29750. empty: function empty() {
  29751. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29752. return this.isEmpty();
  29753. }
  29754. });
  29755. Frustum.prototype.setFromMatrix = function (m) {
  29756. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29757. return this.setFromProjectionMatrix(m);
  29758. };
  29759. Line3.prototype.center = function (optionalTarget) {
  29760. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29761. return this.getCenter(optionalTarget);
  29762. };
  29763. Object.assign(MathUtils, {
  29764. random16: function random16() {
  29765. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29766. return Math.random();
  29767. },
  29768. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29769. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29770. return MathUtils.floorPowerOfTwo(value);
  29771. },
  29772. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29773. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29774. return MathUtils.ceilPowerOfTwo(value);
  29775. }
  29776. });
  29777. Object.assign(Matrix3.prototype, {
  29778. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29779. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29780. return this.toArray(array, offset);
  29781. },
  29782. multiplyVector3: function multiplyVector3(vector) {
  29783. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29784. return vector.applyMatrix3(this);
  29785. },
  29786. multiplyVector3Array: function multiplyVector3Array()
  29787. /* a */
  29788. {
  29789. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29790. },
  29791. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29792. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29793. return attribute.applyMatrix3(this);
  29794. },
  29795. applyToVector3Array: function applyToVector3Array()
  29796. /* array, offset, length */
  29797. {
  29798. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29799. },
  29800. getInverse: function getInverse(matrix) {
  29801. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29802. return this.copy(matrix).invert();
  29803. }
  29804. });
  29805. Object.assign(Matrix4.prototype, {
  29806. extractPosition: function extractPosition(m) {
  29807. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29808. return this.copyPosition(m);
  29809. },
  29810. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29811. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29812. return this.toArray(array, offset);
  29813. },
  29814. getPosition: function getPosition() {
  29815. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29816. return new Vector3().setFromMatrixColumn(this, 3);
  29817. },
  29818. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29819. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29820. return this.makeRotationFromQuaternion(q);
  29821. },
  29822. multiplyToArray: function multiplyToArray() {
  29823. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29824. },
  29825. multiplyVector3: function multiplyVector3(vector) {
  29826. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29827. return vector.applyMatrix4(this);
  29828. },
  29829. multiplyVector4: function multiplyVector4(vector) {
  29830. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29831. return vector.applyMatrix4(this);
  29832. },
  29833. multiplyVector3Array: function multiplyVector3Array()
  29834. /* a */
  29835. {
  29836. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29837. },
  29838. rotateAxis: function rotateAxis(v) {
  29839. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29840. v.transformDirection(this);
  29841. },
  29842. crossVector: function crossVector(vector) {
  29843. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29844. return vector.applyMatrix4(this);
  29845. },
  29846. translate: function translate() {
  29847. console.error('THREE.Matrix4: .translate() has been removed.');
  29848. },
  29849. rotateX: function rotateX() {
  29850. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29851. },
  29852. rotateY: function rotateY() {
  29853. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29854. },
  29855. rotateZ: function rotateZ() {
  29856. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29857. },
  29858. rotateByAxis: function rotateByAxis() {
  29859. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29860. },
  29861. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29862. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29863. return attribute.applyMatrix4(this);
  29864. },
  29865. applyToVector3Array: function applyToVector3Array()
  29866. /* array, offset, length */
  29867. {
  29868. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29869. },
  29870. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29871. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29872. return this.makePerspective(left, right, top, bottom, near, far);
  29873. },
  29874. getInverse: function getInverse(matrix) {
  29875. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29876. return this.copy(matrix).invert();
  29877. }
  29878. });
  29879. Plane.prototype.isIntersectionLine = function (line) {
  29880. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29881. return this.intersectsLine(line);
  29882. };
  29883. Object.assign(Quaternion.prototype, {
  29884. multiplyVector3: function multiplyVector3(vector) {
  29885. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29886. return vector.applyQuaternion(this);
  29887. },
  29888. inverse: function inverse() {
  29889. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29890. return this.invert();
  29891. }
  29892. });
  29893. Object.assign(Ray.prototype, {
  29894. isIntersectionBox: function isIntersectionBox(box) {
  29895. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29896. return this.intersectsBox(box);
  29897. },
  29898. isIntersectionPlane: function isIntersectionPlane(plane) {
  29899. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29900. return this.intersectsPlane(plane);
  29901. },
  29902. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29903. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29904. return this.intersectsSphere(sphere);
  29905. }
  29906. });
  29907. Object.assign(Triangle.prototype, {
  29908. area: function area() {
  29909. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29910. return this.getArea();
  29911. },
  29912. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29913. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29914. return this.getBarycoord(point, target);
  29915. },
  29916. midpoint: function midpoint(target) {
  29917. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29918. return this.getMidpoint(target);
  29919. },
  29920. normal: function normal(target) {
  29921. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29922. return this.getNormal(target);
  29923. },
  29924. plane: function plane(target) {
  29925. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29926. return this.getPlane(target);
  29927. }
  29928. });
  29929. Object.assign(Triangle, {
  29930. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29931. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29932. return Triangle.getBarycoord(point, a, b, c, target);
  29933. },
  29934. normal: function normal(a, b, c, target) {
  29935. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29936. return Triangle.getNormal(a, b, c, target);
  29937. }
  29938. });
  29939. Object.assign(Shape.prototype, {
  29940. extractAllPoints: function extractAllPoints(divisions) {
  29941. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29942. return this.extractPoints(divisions);
  29943. },
  29944. extrude: function extrude(options) {
  29945. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29946. return new ExtrudeGeometry(this, options);
  29947. },
  29948. makeGeometry: function makeGeometry(options) {
  29949. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29950. return new ShapeGeometry(this, options);
  29951. }
  29952. });
  29953. Object.assign(Vector2.prototype, {
  29954. fromAttribute: function fromAttribute(attribute, index, offset) {
  29955. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29956. return this.fromBufferAttribute(attribute, index, offset);
  29957. },
  29958. distanceToManhattan: function distanceToManhattan(v) {
  29959. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29960. return this.manhattanDistanceTo(v);
  29961. },
  29962. lengthManhattan: function lengthManhattan() {
  29963. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29964. return this.manhattanLength();
  29965. }
  29966. });
  29967. Object.assign(Vector3.prototype, {
  29968. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29969. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29970. },
  29971. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29972. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29973. },
  29974. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29975. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29976. return this.setFromMatrixPosition(m);
  29977. },
  29978. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29979. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29980. return this.setFromMatrixScale(m);
  29981. },
  29982. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29983. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29984. return this.setFromMatrixColumn(matrix, index);
  29985. },
  29986. applyProjection: function applyProjection(m) {
  29987. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29988. return this.applyMatrix4(m);
  29989. },
  29990. fromAttribute: function fromAttribute(attribute, index, offset) {
  29991. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29992. return this.fromBufferAttribute(attribute, index, offset);
  29993. },
  29994. distanceToManhattan: function distanceToManhattan(v) {
  29995. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29996. return this.manhattanDistanceTo(v);
  29997. },
  29998. lengthManhattan: function lengthManhattan() {
  29999. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  30000. return this.manhattanLength();
  30001. }
  30002. });
  30003. Object.assign(Vector4.prototype, {
  30004. fromAttribute: function fromAttribute(attribute, index, offset) {
  30005. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  30006. return this.fromBufferAttribute(attribute, index, offset);
  30007. },
  30008. lengthManhattan: function lengthManhattan() {
  30009. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  30010. return this.manhattanLength();
  30011. }
  30012. }); //
  30013. Object.assign(Geometry.prototype, {
  30014. computeTangents: function computeTangents() {
  30015. console.error('THREE.Geometry: .computeTangents() has been removed.');
  30016. },
  30017. computeLineDistances: function computeLineDistances() {
  30018. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  30019. },
  30020. applyMatrix: function applyMatrix(matrix) {
  30021. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30022. return this.applyMatrix4(matrix);
  30023. }
  30024. });
  30025. Object.assign(Object3D.prototype, {
  30026. getChildByName: function getChildByName(name) {
  30027. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  30028. return this.getObjectByName(name);
  30029. },
  30030. renderDepth: function renderDepth() {
  30031. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  30032. },
  30033. translate: function translate(distance, axis) {
  30034. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  30035. return this.translateOnAxis(axis, distance);
  30036. },
  30037. getWorldRotation: function getWorldRotation() {
  30038. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  30039. },
  30040. applyMatrix: function applyMatrix(matrix) {
  30041. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  30042. return this.applyMatrix4(matrix);
  30043. }
  30044. });
  30045. Object.defineProperties(Object3D.prototype, {
  30046. eulerOrder: {
  30047. get: function get() {
  30048. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30049. return this.rotation.order;
  30050. },
  30051. set: function set(value) {
  30052. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  30053. this.rotation.order = value;
  30054. }
  30055. },
  30056. useQuaternion: {
  30057. get: function get() {
  30058. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30059. },
  30060. set: function set() {
  30061. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  30062. }
  30063. }
  30064. });
  30065. Object.assign(Mesh.prototype, {
  30066. setDrawMode: function setDrawMode() {
  30067. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30068. }
  30069. });
  30070. Object.defineProperties(Mesh.prototype, {
  30071. drawMode: {
  30072. get: function get() {
  30073. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  30074. return TrianglesDrawMode;
  30075. },
  30076. set: function set() {
  30077. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  30078. }
  30079. }
  30080. });
  30081. Object.defineProperties(LOD.prototype, {
  30082. objects: {
  30083. get: function get() {
  30084. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  30085. return this.levels;
  30086. }
  30087. }
  30088. });
  30089. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  30090. get: function get() {
  30091. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30092. },
  30093. set: function set() {
  30094. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  30095. }
  30096. });
  30097. SkinnedMesh.prototype.initBones = function () {
  30098. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  30099. };
  30100. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  30101. get: function get() {
  30102. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30103. return this.arcLengthDivisions;
  30104. },
  30105. set: function set(value) {
  30106. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  30107. this.arcLengthDivisions = value;
  30108. }
  30109. }); //
  30110. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  30111. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  30112. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  30113. this.setFocalLength(focalLength);
  30114. }; //
  30115. Object.defineProperties(Light.prototype, {
  30116. onlyShadow: {
  30117. set: function set() {
  30118. console.warn('THREE.Light: .onlyShadow has been removed.');
  30119. }
  30120. },
  30121. shadowCameraFov: {
  30122. set: function set(value) {
  30123. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  30124. this.shadow.camera.fov = value;
  30125. }
  30126. },
  30127. shadowCameraLeft: {
  30128. set: function set(value) {
  30129. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  30130. this.shadow.camera.left = value;
  30131. }
  30132. },
  30133. shadowCameraRight: {
  30134. set: function set(value) {
  30135. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  30136. this.shadow.camera.right = value;
  30137. }
  30138. },
  30139. shadowCameraTop: {
  30140. set: function set(value) {
  30141. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  30142. this.shadow.camera.top = value;
  30143. }
  30144. },
  30145. shadowCameraBottom: {
  30146. set: function set(value) {
  30147. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  30148. this.shadow.camera.bottom = value;
  30149. }
  30150. },
  30151. shadowCameraNear: {
  30152. set: function set(value) {
  30153. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  30154. this.shadow.camera.near = value;
  30155. }
  30156. },
  30157. shadowCameraFar: {
  30158. set: function set(value) {
  30159. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  30160. this.shadow.camera.far = value;
  30161. }
  30162. },
  30163. shadowCameraVisible: {
  30164. set: function set() {
  30165. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  30166. }
  30167. },
  30168. shadowBias: {
  30169. set: function set(value) {
  30170. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  30171. this.shadow.bias = value;
  30172. }
  30173. },
  30174. shadowDarkness: {
  30175. set: function set() {
  30176. console.warn('THREE.Light: .shadowDarkness has been removed.');
  30177. }
  30178. },
  30179. shadowMapWidth: {
  30180. set: function set(value) {
  30181. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  30182. this.shadow.mapSize.width = value;
  30183. }
  30184. },
  30185. shadowMapHeight: {
  30186. set: function set(value) {
  30187. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  30188. this.shadow.mapSize.height = value;
  30189. }
  30190. }
  30191. }); //
  30192. Object.defineProperties(BufferAttribute.prototype, {
  30193. length: {
  30194. get: function get() {
  30195. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  30196. return this.array.length;
  30197. }
  30198. },
  30199. dynamic: {
  30200. get: function get() {
  30201. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30202. return this.usage === DynamicDrawUsage;
  30203. },
  30204. set: function set()
  30205. /* value */
  30206. {
  30207. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  30208. this.setUsage(DynamicDrawUsage);
  30209. }
  30210. }
  30211. });
  30212. Object.assign(BufferAttribute.prototype, {
  30213. setDynamic: function setDynamic(value) {
  30214. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30215. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30216. return this;
  30217. },
  30218. copyIndicesArray: function copyIndicesArray()
  30219. /* indices */
  30220. {
  30221. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30222. },
  30223. setArray: function setArray()
  30224. /* array */
  30225. {
  30226. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30227. }
  30228. });
  30229. Object.assign(BufferGeometry.prototype, {
  30230. addIndex: function addIndex(index) {
  30231. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30232. this.setIndex(index);
  30233. },
  30234. addAttribute: function addAttribute(name, attribute) {
  30235. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30236. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30237. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30238. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30239. }
  30240. if (name === 'index') {
  30241. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30242. this.setIndex(attribute);
  30243. return this;
  30244. }
  30245. return this.setAttribute(name, attribute);
  30246. },
  30247. addDrawCall: function addDrawCall(start, count, indexOffset) {
  30248. if (indexOffset !== undefined) {
  30249. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30250. }
  30251. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30252. this.addGroup(start, count);
  30253. },
  30254. clearDrawCalls: function clearDrawCalls() {
  30255. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30256. this.clearGroups();
  30257. },
  30258. computeTangents: function computeTangents() {
  30259. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  30260. },
  30261. computeOffsets: function computeOffsets() {
  30262. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30263. },
  30264. removeAttribute: function removeAttribute(name) {
  30265. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30266. return this.deleteAttribute(name);
  30267. },
  30268. applyMatrix: function applyMatrix(matrix) {
  30269. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30270. return this.applyMatrix4(matrix);
  30271. }
  30272. });
  30273. Object.defineProperties(BufferGeometry.prototype, {
  30274. drawcalls: {
  30275. get: function get() {
  30276. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30277. return this.groups;
  30278. }
  30279. },
  30280. offsets: {
  30281. get: function get() {
  30282. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30283. return this.groups;
  30284. }
  30285. }
  30286. });
  30287. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30288. maxInstancedCount: {
  30289. get: function get() {
  30290. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30291. return this.instanceCount;
  30292. },
  30293. set: function set(value) {
  30294. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30295. this.instanceCount = value;
  30296. }
  30297. }
  30298. });
  30299. Object.defineProperties(Raycaster.prototype, {
  30300. linePrecision: {
  30301. get: function get() {
  30302. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30303. return this.params.Line.threshold;
  30304. },
  30305. set: function set(value) {
  30306. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30307. this.params.Line.threshold = value;
  30308. }
  30309. }
  30310. });
  30311. Object.defineProperties(InterleavedBuffer.prototype, {
  30312. dynamic: {
  30313. get: function get() {
  30314. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30315. return this.usage === DynamicDrawUsage;
  30316. },
  30317. set: function set(value) {
  30318. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30319. this.setUsage(value);
  30320. }
  30321. }
  30322. });
  30323. Object.assign(InterleavedBuffer.prototype, {
  30324. setDynamic: function setDynamic(value) {
  30325. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30326. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30327. return this;
  30328. },
  30329. setArray: function setArray()
  30330. /* array */
  30331. {
  30332. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30333. }
  30334. }); //
  30335. Object.assign(ExtrudeBufferGeometry.prototype, {
  30336. getArrays: function getArrays() {
  30337. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  30338. },
  30339. addShapeList: function addShapeList() {
  30340. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  30341. },
  30342. addShape: function addShape() {
  30343. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  30344. }
  30345. }); //
  30346. Object.assign(Scene.prototype, {
  30347. dispose: function dispose() {
  30348. console.error('THREE.Scene: .dispose() has been removed.');
  30349. }
  30350. }); //
  30351. Object.defineProperties(Uniform.prototype, {
  30352. dynamic: {
  30353. set: function set() {
  30354. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30355. }
  30356. },
  30357. onUpdate: {
  30358. value: function value() {
  30359. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30360. return this;
  30361. }
  30362. }
  30363. }); //
  30364. Object.defineProperties(Material.prototype, {
  30365. wrapAround: {
  30366. get: function get() {
  30367. console.warn('THREE.Material: .wrapAround has been removed.');
  30368. },
  30369. set: function set() {
  30370. console.warn('THREE.Material: .wrapAround has been removed.');
  30371. }
  30372. },
  30373. overdraw: {
  30374. get: function get() {
  30375. console.warn('THREE.Material: .overdraw has been removed.');
  30376. },
  30377. set: function set() {
  30378. console.warn('THREE.Material: .overdraw has been removed.');
  30379. }
  30380. },
  30381. wrapRGB: {
  30382. get: function get() {
  30383. console.warn('THREE.Material: .wrapRGB has been removed.');
  30384. return new Color();
  30385. }
  30386. },
  30387. shading: {
  30388. get: function get() {
  30389. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30390. },
  30391. set: function set(value) {
  30392. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30393. this.flatShading = value === FlatShading;
  30394. }
  30395. },
  30396. stencilMask: {
  30397. get: function get() {
  30398. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30399. return this.stencilFuncMask;
  30400. },
  30401. set: function set(value) {
  30402. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30403. this.stencilFuncMask = value;
  30404. }
  30405. }
  30406. });
  30407. Object.defineProperties(MeshPhongMaterial.prototype, {
  30408. metal: {
  30409. get: function get() {
  30410. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30411. return false;
  30412. },
  30413. set: function set() {
  30414. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30415. }
  30416. }
  30417. });
  30418. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30419. transparency: {
  30420. get: function get() {
  30421. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30422. return this.transmission;
  30423. },
  30424. set: function set(value) {
  30425. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30426. this.transmission = value;
  30427. }
  30428. }
  30429. });
  30430. Object.defineProperties(ShaderMaterial.prototype, {
  30431. derivatives: {
  30432. get: function get() {
  30433. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30434. return this.extensions.derivatives;
  30435. },
  30436. set: function set(value) {
  30437. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30438. this.extensions.derivatives = value;
  30439. }
  30440. }
  30441. }); //
  30442. Object.assign(WebGLRenderer.prototype, {
  30443. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  30444. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30445. this.setRenderTarget(renderTarget);
  30446. this.clear(color, depth, stencil);
  30447. },
  30448. animate: function animate(callback) {
  30449. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30450. this.setAnimationLoop(callback);
  30451. },
  30452. getCurrentRenderTarget: function getCurrentRenderTarget() {
  30453. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30454. return this.getRenderTarget();
  30455. },
  30456. getMaxAnisotropy: function getMaxAnisotropy() {
  30457. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30458. return this.capabilities.getMaxAnisotropy();
  30459. },
  30460. getPrecision: function getPrecision() {
  30461. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30462. return this.capabilities.precision;
  30463. },
  30464. resetGLState: function resetGLState() {
  30465. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30466. return this.state.reset();
  30467. },
  30468. supportsFloatTextures: function supportsFloatTextures() {
  30469. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30470. return this.extensions.get('OES_texture_float');
  30471. },
  30472. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30473. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30474. return this.extensions.get('OES_texture_half_float');
  30475. },
  30476. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30477. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30478. return this.extensions.get('OES_standard_derivatives');
  30479. },
  30480. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30481. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30482. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30483. },
  30484. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30485. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30486. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30487. },
  30488. supportsBlendMinMax: function supportsBlendMinMax() {
  30489. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30490. return this.extensions.get('EXT_blend_minmax');
  30491. },
  30492. supportsVertexTextures: function supportsVertexTextures() {
  30493. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30494. return this.capabilities.vertexTextures;
  30495. },
  30496. supportsInstancedArrays: function supportsInstancedArrays() {
  30497. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30498. return this.extensions.get('ANGLE_instanced_arrays');
  30499. },
  30500. enableScissorTest: function enableScissorTest(boolean) {
  30501. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30502. this.setScissorTest(boolean);
  30503. },
  30504. initMaterial: function initMaterial() {
  30505. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30506. },
  30507. addPrePlugin: function addPrePlugin() {
  30508. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30509. },
  30510. addPostPlugin: function addPostPlugin() {
  30511. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30512. },
  30513. updateShadowMap: function updateShadowMap() {
  30514. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30515. },
  30516. setFaceCulling: function setFaceCulling() {
  30517. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30518. },
  30519. allocTextureUnit: function allocTextureUnit() {
  30520. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30521. },
  30522. setTexture: function setTexture() {
  30523. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30524. },
  30525. setTexture2D: function setTexture2D() {
  30526. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30527. },
  30528. setTextureCube: function setTextureCube() {
  30529. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30530. },
  30531. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30532. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30533. return this.getActiveMipmapLevel();
  30534. }
  30535. });
  30536. Object.defineProperties(WebGLRenderer.prototype, {
  30537. shadowMapEnabled: {
  30538. get: function get() {
  30539. return this.shadowMap.enabled;
  30540. },
  30541. set: function set(value) {
  30542. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30543. this.shadowMap.enabled = value;
  30544. }
  30545. },
  30546. shadowMapType: {
  30547. get: function get() {
  30548. return this.shadowMap.type;
  30549. },
  30550. set: function set(value) {
  30551. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30552. this.shadowMap.type = value;
  30553. }
  30554. },
  30555. shadowMapCullFace: {
  30556. get: function get() {
  30557. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30558. return undefined;
  30559. },
  30560. set: function set()
  30561. /* value */
  30562. {
  30563. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30564. }
  30565. },
  30566. context: {
  30567. get: function get() {
  30568. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30569. return this.getContext();
  30570. }
  30571. },
  30572. vr: {
  30573. get: function get() {
  30574. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30575. return this.xr;
  30576. }
  30577. },
  30578. gammaInput: {
  30579. get: function get() {
  30580. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30581. return false;
  30582. },
  30583. set: function set() {
  30584. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30585. }
  30586. },
  30587. gammaOutput: {
  30588. get: function get() {
  30589. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30590. return false;
  30591. },
  30592. set: function set(value) {
  30593. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30594. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30595. }
  30596. },
  30597. toneMappingWhitePoint: {
  30598. get: function get() {
  30599. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30600. return 1.0;
  30601. },
  30602. set: function set() {
  30603. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30604. }
  30605. }
  30606. });
  30607. Object.defineProperties(WebGLShadowMap.prototype, {
  30608. cullFace: {
  30609. get: function get() {
  30610. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30611. return undefined;
  30612. },
  30613. set: function set()
  30614. /* cullFace */
  30615. {
  30616. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30617. }
  30618. },
  30619. renderReverseSided: {
  30620. get: function get() {
  30621. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30622. return undefined;
  30623. },
  30624. set: function set() {
  30625. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30626. }
  30627. },
  30628. renderSingleSided: {
  30629. get: function get() {
  30630. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30631. return undefined;
  30632. },
  30633. set: function set() {
  30634. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30635. }
  30636. }
  30637. });
  30638. function WebGLRenderTargetCube(width, height, options) {
  30639. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30640. return new WebGLCubeRenderTarget(width, options);
  30641. } //
  30642. Object.defineProperties(WebGLRenderTarget.prototype, {
  30643. wrapS: {
  30644. get: function get() {
  30645. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30646. return this.texture.wrapS;
  30647. },
  30648. set: function set(value) {
  30649. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30650. this.texture.wrapS = value;
  30651. }
  30652. },
  30653. wrapT: {
  30654. get: function get() {
  30655. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30656. return this.texture.wrapT;
  30657. },
  30658. set: function set(value) {
  30659. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30660. this.texture.wrapT = value;
  30661. }
  30662. },
  30663. magFilter: {
  30664. get: function get() {
  30665. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30666. return this.texture.magFilter;
  30667. },
  30668. set: function set(value) {
  30669. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30670. this.texture.magFilter = value;
  30671. }
  30672. },
  30673. minFilter: {
  30674. get: function get() {
  30675. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30676. return this.texture.minFilter;
  30677. },
  30678. set: function set(value) {
  30679. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30680. this.texture.minFilter = value;
  30681. }
  30682. },
  30683. anisotropy: {
  30684. get: function get() {
  30685. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30686. return this.texture.anisotropy;
  30687. },
  30688. set: function set(value) {
  30689. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30690. this.texture.anisotropy = value;
  30691. }
  30692. },
  30693. offset: {
  30694. get: function get() {
  30695. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30696. return this.texture.offset;
  30697. },
  30698. set: function set(value) {
  30699. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30700. this.texture.offset = value;
  30701. }
  30702. },
  30703. repeat: {
  30704. get: function get() {
  30705. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30706. return this.texture.repeat;
  30707. },
  30708. set: function set(value) {
  30709. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30710. this.texture.repeat = value;
  30711. }
  30712. },
  30713. format: {
  30714. get: function get() {
  30715. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30716. return this.texture.format;
  30717. },
  30718. set: function set(value) {
  30719. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30720. this.texture.format = value;
  30721. }
  30722. },
  30723. type: {
  30724. get: function get() {
  30725. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30726. return this.texture.type;
  30727. },
  30728. set: function set(value) {
  30729. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30730. this.texture.type = value;
  30731. }
  30732. },
  30733. generateMipmaps: {
  30734. get: function get() {
  30735. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30736. return this.texture.generateMipmaps;
  30737. },
  30738. set: function set(value) {
  30739. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30740. this.texture.generateMipmaps = value;
  30741. }
  30742. }
  30743. }); //
  30744. Object.defineProperties(Audio.prototype, {
  30745. load: {
  30746. value: function value(file) {
  30747. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30748. var scope = this;
  30749. var audioLoader = new AudioLoader();
  30750. audioLoader.load(file, function (buffer) {
  30751. scope.setBuffer(buffer);
  30752. });
  30753. return this;
  30754. }
  30755. },
  30756. startTime: {
  30757. set: function set() {
  30758. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30759. }
  30760. }
  30761. });
  30762. AudioAnalyser.prototype.getData = function () {
  30763. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30764. return this.getFrequencyData();
  30765. }; //
  30766. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30767. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30768. return this.update(renderer, scene);
  30769. };
  30770. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30771. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30772. return this.renderTarget.clear(renderer, color, depth, stencil);
  30773. }; //
  30774. var GeometryUtils = {
  30775. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30776. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30777. var matrix;
  30778. if (geometry2.isMesh) {
  30779. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30780. matrix = geometry2.matrix;
  30781. geometry2 = geometry2.geometry;
  30782. }
  30783. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30784. },
  30785. center: function center(geometry) {
  30786. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30787. return geometry.center();
  30788. }
  30789. };
  30790. ImageUtils.crossOrigin = undefined;
  30791. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30792. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30793. var loader = new TextureLoader();
  30794. loader.setCrossOrigin(this.crossOrigin);
  30795. var texture = loader.load(url, onLoad, undefined, onError);
  30796. if (mapping) texture.mapping = mapping;
  30797. return texture;
  30798. };
  30799. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30800. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30801. var loader = new CubeTextureLoader();
  30802. loader.setCrossOrigin(this.crossOrigin);
  30803. var texture = loader.load(urls, onLoad, undefined, onError);
  30804. if (mapping) texture.mapping = mapping;
  30805. return texture;
  30806. };
  30807. ImageUtils.loadCompressedTexture = function () {
  30808. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30809. };
  30810. ImageUtils.loadCompressedTextureCube = function () {
  30811. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30812. }; //
  30813. function CanvasRenderer() {
  30814. console.error('THREE.CanvasRenderer has been removed');
  30815. } //
  30816. function JSONLoader() {
  30817. console.error('THREE.JSONLoader has been removed.');
  30818. } //
  30819. var SceneUtils = {
  30820. createMultiMaterialObject: function createMultiMaterialObject()
  30821. /* geometry, materials */
  30822. {
  30823. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30824. },
  30825. detach: function detach()
  30826. /* child, parent, scene */
  30827. {
  30828. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30829. },
  30830. attach: function attach()
  30831. /* child, scene, parent */
  30832. {
  30833. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30834. }
  30835. }; //
  30836. function LensFlare() {
  30837. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30838. }
  30839. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30840. /* eslint-disable no-undef */
  30841. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30842. detail: {
  30843. revision: REVISION
  30844. }
  30845. }));
  30846. /* eslint-enable no-undef */
  30847. }
  30848. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30849. exports.AddEquation = AddEquation;
  30850. exports.AddOperation = AddOperation;
  30851. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30852. exports.AdditiveBlending = AdditiveBlending;
  30853. exports.AlphaFormat = AlphaFormat;
  30854. exports.AlwaysDepth = AlwaysDepth;
  30855. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30856. exports.AmbientLight = AmbientLight;
  30857. exports.AmbientLightProbe = AmbientLightProbe;
  30858. exports.AnimationClip = AnimationClip;
  30859. exports.AnimationLoader = AnimationLoader;
  30860. exports.AnimationMixer = AnimationMixer;
  30861. exports.AnimationObjectGroup = AnimationObjectGroup;
  30862. exports.AnimationUtils = AnimationUtils;
  30863. exports.ArcCurve = ArcCurve;
  30864. exports.ArrayCamera = ArrayCamera;
  30865. exports.ArrowHelper = ArrowHelper;
  30866. exports.Audio = Audio;
  30867. exports.AudioAnalyser = AudioAnalyser;
  30868. exports.AudioContext = AudioContext;
  30869. exports.AudioListener = AudioListener;
  30870. exports.AudioLoader = AudioLoader;
  30871. exports.AxesHelper = AxesHelper;
  30872. exports.AxisHelper = AxisHelper;
  30873. exports.BackSide = BackSide;
  30874. exports.BasicDepthPacking = BasicDepthPacking;
  30875. exports.BasicShadowMap = BasicShadowMap;
  30876. exports.BinaryTextureLoader = BinaryTextureLoader;
  30877. exports.Bone = Bone;
  30878. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30879. exports.BoundingBoxHelper = BoundingBoxHelper;
  30880. exports.Box2 = Box2;
  30881. exports.Box3 = Box3;
  30882. exports.Box3Helper = Box3Helper;
  30883. exports.BoxBufferGeometry = BoxBufferGeometry;
  30884. exports.BoxGeometry = BoxGeometry;
  30885. exports.BoxHelper = BoxHelper;
  30886. exports.BufferAttribute = BufferAttribute;
  30887. exports.BufferGeometry = BufferGeometry;
  30888. exports.BufferGeometryLoader = BufferGeometryLoader;
  30889. exports.ByteType = ByteType;
  30890. exports.Cache = Cache;
  30891. exports.Camera = Camera;
  30892. exports.CameraHelper = CameraHelper;
  30893. exports.CanvasRenderer = CanvasRenderer;
  30894. exports.CanvasTexture = CanvasTexture;
  30895. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30896. exports.CineonToneMapping = CineonToneMapping;
  30897. exports.CircleBufferGeometry = CircleBufferGeometry;
  30898. exports.CircleGeometry = CircleGeometry;
  30899. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30900. exports.Clock = Clock;
  30901. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30902. exports.Color = Color;
  30903. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30904. exports.CompressedTexture = CompressedTexture;
  30905. exports.CompressedTextureLoader = CompressedTextureLoader;
  30906. exports.ConeBufferGeometry = ConeBufferGeometry;
  30907. exports.ConeGeometry = ConeGeometry;
  30908. exports.CubeCamera = CubeCamera;
  30909. exports.CubeGeometry = BoxGeometry;
  30910. exports.CubeReflectionMapping = CubeReflectionMapping;
  30911. exports.CubeRefractionMapping = CubeRefractionMapping;
  30912. exports.CubeTexture = CubeTexture;
  30913. exports.CubeTextureLoader = CubeTextureLoader;
  30914. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30915. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30916. exports.CubicBezierCurve = CubicBezierCurve;
  30917. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30918. exports.CubicInterpolant = CubicInterpolant;
  30919. exports.CullFaceBack = CullFaceBack;
  30920. exports.CullFaceFront = CullFaceFront;
  30921. exports.CullFaceFrontBack = CullFaceFrontBack;
  30922. exports.CullFaceNone = CullFaceNone;
  30923. exports.Curve = Curve;
  30924. exports.CurvePath = CurvePath;
  30925. exports.CustomBlending = CustomBlending;
  30926. exports.CustomToneMapping = CustomToneMapping;
  30927. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30928. exports.CylinderGeometry = CylinderGeometry;
  30929. exports.Cylindrical = Cylindrical;
  30930. exports.DataTexture = DataTexture;
  30931. exports.DataTexture2DArray = DataTexture2DArray;
  30932. exports.DataTexture3D = DataTexture3D;
  30933. exports.DataTextureLoader = DataTextureLoader;
  30934. exports.DataUtils = DataUtils;
  30935. exports.DecrementStencilOp = DecrementStencilOp;
  30936. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30937. exports.DefaultLoadingManager = DefaultLoadingManager;
  30938. exports.DepthFormat = DepthFormat;
  30939. exports.DepthStencilFormat = DepthStencilFormat;
  30940. exports.DepthTexture = DepthTexture;
  30941. exports.DirectionalLight = DirectionalLight;
  30942. exports.DirectionalLightHelper = DirectionalLightHelper;
  30943. exports.DiscreteInterpolant = DiscreteInterpolant;
  30944. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30945. exports.DodecahedronGeometry = DodecahedronGeometry;
  30946. exports.DoubleSide = DoubleSide;
  30947. exports.DstAlphaFactor = DstAlphaFactor;
  30948. exports.DstColorFactor = DstColorFactor;
  30949. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30950. exports.DynamicCopyUsage = DynamicCopyUsage;
  30951. exports.DynamicDrawUsage = DynamicDrawUsage;
  30952. exports.DynamicReadUsage = DynamicReadUsage;
  30953. exports.EdgesGeometry = EdgesGeometry;
  30954. exports.EdgesHelper = EdgesHelper;
  30955. exports.EllipseCurve = EllipseCurve;
  30956. exports.EqualDepth = EqualDepth;
  30957. exports.EqualStencilFunc = EqualStencilFunc;
  30958. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30959. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30960. exports.Euler = Euler;
  30961. exports.EventDispatcher = EventDispatcher;
  30962. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30963. exports.ExtrudeGeometry = ExtrudeGeometry;
  30964. exports.Face3 = Face3;
  30965. exports.Face4 = Face4;
  30966. exports.FaceColors = FaceColors;
  30967. exports.FileLoader = FileLoader;
  30968. exports.FlatShading = FlatShading;
  30969. exports.Float16BufferAttribute = Float16BufferAttribute;
  30970. exports.Float32Attribute = Float32Attribute;
  30971. exports.Float32BufferAttribute = Float32BufferAttribute;
  30972. exports.Float64Attribute = Float64Attribute;
  30973. exports.Float64BufferAttribute = Float64BufferAttribute;
  30974. exports.FloatType = FloatType;
  30975. exports.Fog = Fog;
  30976. exports.FogExp2 = FogExp2;
  30977. exports.Font = Font;
  30978. exports.FontLoader = FontLoader;
  30979. exports.FrontSide = FrontSide;
  30980. exports.Frustum = Frustum;
  30981. exports.GLBufferAttribute = GLBufferAttribute;
  30982. exports.GLSL1 = GLSL1;
  30983. exports.GLSL3 = GLSL3;
  30984. exports.GammaEncoding = GammaEncoding;
  30985. exports.Geometry = Geometry;
  30986. exports.GeometryUtils = GeometryUtils;
  30987. exports.GreaterDepth = GreaterDepth;
  30988. exports.GreaterEqualDepth = GreaterEqualDepth;
  30989. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30990. exports.GreaterStencilFunc = GreaterStencilFunc;
  30991. exports.GridHelper = GridHelper;
  30992. exports.Group = Group;
  30993. exports.HalfFloatType = HalfFloatType;
  30994. exports.HemisphereLight = HemisphereLight;
  30995. exports.HemisphereLightHelper = HemisphereLightHelper;
  30996. exports.HemisphereLightProbe = HemisphereLightProbe;
  30997. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30998. exports.IcosahedronGeometry = IcosahedronGeometry;
  30999. exports.ImageBitmapLoader = ImageBitmapLoader;
  31000. exports.ImageLoader = ImageLoader;
  31001. exports.ImageUtils = ImageUtils;
  31002. exports.ImmediateRenderObject = ImmediateRenderObject;
  31003. exports.IncrementStencilOp = IncrementStencilOp;
  31004. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  31005. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  31006. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  31007. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  31008. exports.InstancedMesh = InstancedMesh;
  31009. exports.Int16Attribute = Int16Attribute;
  31010. exports.Int16BufferAttribute = Int16BufferAttribute;
  31011. exports.Int32Attribute = Int32Attribute;
  31012. exports.Int32BufferAttribute = Int32BufferAttribute;
  31013. exports.Int8Attribute = Int8Attribute;
  31014. exports.Int8BufferAttribute = Int8BufferAttribute;
  31015. exports.IntType = IntType;
  31016. exports.InterleavedBuffer = InterleavedBuffer;
  31017. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  31018. exports.Interpolant = Interpolant;
  31019. exports.InterpolateDiscrete = InterpolateDiscrete;
  31020. exports.InterpolateLinear = InterpolateLinear;
  31021. exports.InterpolateSmooth = InterpolateSmooth;
  31022. exports.InvertStencilOp = InvertStencilOp;
  31023. exports.JSONLoader = JSONLoader;
  31024. exports.KeepStencilOp = KeepStencilOp;
  31025. exports.KeyframeTrack = KeyframeTrack;
  31026. exports.LOD = LOD;
  31027. exports.LatheBufferGeometry = LatheBufferGeometry;
  31028. exports.LatheGeometry = LatheGeometry;
  31029. exports.Layers = Layers;
  31030. exports.LensFlare = LensFlare;
  31031. exports.LessDepth = LessDepth;
  31032. exports.LessEqualDepth = LessEqualDepth;
  31033. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  31034. exports.LessStencilFunc = LessStencilFunc;
  31035. exports.Light = Light;
  31036. exports.LightProbe = LightProbe;
  31037. exports.Line = Line;
  31038. exports.Line3 = Line3;
  31039. exports.LineBasicMaterial = LineBasicMaterial;
  31040. exports.LineCurve = LineCurve;
  31041. exports.LineCurve3 = LineCurve3;
  31042. exports.LineDashedMaterial = LineDashedMaterial;
  31043. exports.LineLoop = LineLoop;
  31044. exports.LinePieces = LinePieces;
  31045. exports.LineSegments = LineSegments;
  31046. exports.LineStrip = LineStrip;
  31047. exports.LinearEncoding = LinearEncoding;
  31048. exports.LinearFilter = LinearFilter;
  31049. exports.LinearInterpolant = LinearInterpolant;
  31050. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  31051. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  31052. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  31053. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  31054. exports.LinearToneMapping = LinearToneMapping;
  31055. exports.Loader = Loader;
  31056. exports.LoaderUtils = LoaderUtils;
  31057. exports.LoadingManager = LoadingManager;
  31058. exports.LogLuvEncoding = LogLuvEncoding;
  31059. exports.LoopOnce = LoopOnce;
  31060. exports.LoopPingPong = LoopPingPong;
  31061. exports.LoopRepeat = LoopRepeat;
  31062. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  31063. exports.LuminanceFormat = LuminanceFormat;
  31064. exports.MOUSE = MOUSE;
  31065. exports.Material = Material;
  31066. exports.MaterialLoader = MaterialLoader;
  31067. exports.Math = MathUtils;
  31068. exports.MathUtils = MathUtils;
  31069. exports.Matrix3 = Matrix3;
  31070. exports.Matrix4 = Matrix4;
  31071. exports.MaxEquation = MaxEquation;
  31072. exports.Mesh = Mesh;
  31073. exports.MeshBasicMaterial = MeshBasicMaterial;
  31074. exports.MeshDepthMaterial = MeshDepthMaterial;
  31075. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  31076. exports.MeshFaceMaterial = MeshFaceMaterial;
  31077. exports.MeshLambertMaterial = MeshLambertMaterial;
  31078. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  31079. exports.MeshNormalMaterial = MeshNormalMaterial;
  31080. exports.MeshPhongMaterial = MeshPhongMaterial;
  31081. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  31082. exports.MeshStandardMaterial = MeshStandardMaterial;
  31083. exports.MeshToonMaterial = MeshToonMaterial;
  31084. exports.MinEquation = MinEquation;
  31085. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  31086. exports.MixOperation = MixOperation;
  31087. exports.MultiMaterial = MultiMaterial;
  31088. exports.MultiplyBlending = MultiplyBlending;
  31089. exports.MultiplyOperation = MultiplyOperation;
  31090. exports.NearestFilter = NearestFilter;
  31091. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  31092. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  31093. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  31094. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  31095. exports.NeverDepth = NeverDepth;
  31096. exports.NeverStencilFunc = NeverStencilFunc;
  31097. exports.NoBlending = NoBlending;
  31098. exports.NoColors = NoColors;
  31099. exports.NoToneMapping = NoToneMapping;
  31100. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  31101. exports.NormalBlending = NormalBlending;
  31102. exports.NotEqualDepth = NotEqualDepth;
  31103. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  31104. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  31105. exports.Object3D = Object3D;
  31106. exports.ObjectLoader = ObjectLoader;
  31107. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  31108. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  31109. exports.OctahedronGeometry = OctahedronGeometry;
  31110. exports.OneFactor = OneFactor;
  31111. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  31112. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  31113. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  31114. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  31115. exports.OrthographicCamera = OrthographicCamera;
  31116. exports.PCFShadowMap = PCFShadowMap;
  31117. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  31118. exports.PMREMGenerator = PMREMGenerator;
  31119. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  31120. exports.ParametricGeometry = ParametricGeometry;
  31121. exports.Particle = Particle;
  31122. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  31123. exports.ParticleSystem = ParticleSystem;
  31124. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  31125. exports.Path = Path;
  31126. exports.PerspectiveCamera = PerspectiveCamera;
  31127. exports.Plane = Plane;
  31128. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  31129. exports.PlaneGeometry = PlaneGeometry;
  31130. exports.PlaneHelper = PlaneHelper;
  31131. exports.PointCloud = PointCloud;
  31132. exports.PointCloudMaterial = PointCloudMaterial;
  31133. exports.PointLight = PointLight;
  31134. exports.PointLightHelper = PointLightHelper;
  31135. exports.Points = Points;
  31136. exports.PointsMaterial = PointsMaterial;
  31137. exports.PolarGridHelper = PolarGridHelper;
  31138. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  31139. exports.PolyhedronGeometry = PolyhedronGeometry;
  31140. exports.PositionalAudio = PositionalAudio;
  31141. exports.PropertyBinding = PropertyBinding;
  31142. exports.PropertyMixer = PropertyMixer;
  31143. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  31144. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  31145. exports.Quaternion = Quaternion;
  31146. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  31147. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  31148. exports.REVISION = REVISION;
  31149. exports.RGBADepthPacking = RGBADepthPacking;
  31150. exports.RGBAFormat = RGBAFormat;
  31151. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  31152. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  31153. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  31154. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  31155. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  31156. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  31157. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  31158. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  31159. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  31160. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  31161. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  31162. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  31163. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  31164. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  31165. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  31166. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  31167. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  31168. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  31169. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  31170. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  31171. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  31172. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  31173. exports.RGBDEncoding = RGBDEncoding;
  31174. exports.RGBEEncoding = RGBEEncoding;
  31175. exports.RGBEFormat = RGBEFormat;
  31176. exports.RGBFormat = RGBFormat;
  31177. exports.RGBIntegerFormat = RGBIntegerFormat;
  31178. exports.RGBM16Encoding = RGBM16Encoding;
  31179. exports.RGBM7Encoding = RGBM7Encoding;
  31180. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  31181. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  31182. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  31183. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  31184. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  31185. exports.RGFormat = RGFormat;
  31186. exports.RGIntegerFormat = RGIntegerFormat;
  31187. exports.RawShaderMaterial = RawShaderMaterial;
  31188. exports.Ray = Ray;
  31189. exports.Raycaster = Raycaster;
  31190. exports.RectAreaLight = RectAreaLight;
  31191. exports.RedFormat = RedFormat;
  31192. exports.RedIntegerFormat = RedIntegerFormat;
  31193. exports.ReinhardToneMapping = ReinhardToneMapping;
  31194. exports.RepeatWrapping = RepeatWrapping;
  31195. exports.ReplaceStencilOp = ReplaceStencilOp;
  31196. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  31197. exports.RingBufferGeometry = RingBufferGeometry;
  31198. exports.RingGeometry = RingGeometry;
  31199. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  31200. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  31201. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  31202. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  31203. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  31204. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  31205. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  31206. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  31207. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  31208. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  31209. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  31210. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  31211. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  31212. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  31213. exports.Scene = Scene;
  31214. exports.SceneUtils = SceneUtils;
  31215. exports.ShaderChunk = ShaderChunk;
  31216. exports.ShaderLib = ShaderLib;
  31217. exports.ShaderMaterial = ShaderMaterial;
  31218. exports.ShadowMaterial = ShadowMaterial;
  31219. exports.Shape = Shape;
  31220. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  31221. exports.ShapeGeometry = ShapeGeometry;
  31222. exports.ShapePath = ShapePath;
  31223. exports.ShapeUtils = ShapeUtils;
  31224. exports.ShortType = ShortType;
  31225. exports.Skeleton = Skeleton;
  31226. exports.SkeletonHelper = SkeletonHelper;
  31227. exports.SkinnedMesh = SkinnedMesh;
  31228. exports.SmoothShading = SmoothShading;
  31229. exports.Sphere = Sphere;
  31230. exports.SphereBufferGeometry = SphereBufferGeometry;
  31231. exports.SphereGeometry = SphereGeometry;
  31232. exports.Spherical = Spherical;
  31233. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31234. exports.Spline = Spline;
  31235. exports.SplineCurve = SplineCurve;
  31236. exports.SplineCurve3 = SplineCurve3;
  31237. exports.SpotLight = SpotLight;
  31238. exports.SpotLightHelper = SpotLightHelper;
  31239. exports.Sprite = Sprite;
  31240. exports.SpriteMaterial = SpriteMaterial;
  31241. exports.SrcAlphaFactor = SrcAlphaFactor;
  31242. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31243. exports.SrcColorFactor = SrcColorFactor;
  31244. exports.StaticCopyUsage = StaticCopyUsage;
  31245. exports.StaticDrawUsage = StaticDrawUsage;
  31246. exports.StaticReadUsage = StaticReadUsage;
  31247. exports.StereoCamera = StereoCamera;
  31248. exports.StreamCopyUsage = StreamCopyUsage;
  31249. exports.StreamDrawUsage = StreamDrawUsage;
  31250. exports.StreamReadUsage = StreamReadUsage;
  31251. exports.StringKeyframeTrack = StringKeyframeTrack;
  31252. exports.SubtractEquation = SubtractEquation;
  31253. exports.SubtractiveBlending = SubtractiveBlending;
  31254. exports.TOUCH = TOUCH;
  31255. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31256. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  31257. exports.TetrahedronGeometry = TetrahedronGeometry;
  31258. exports.TextBufferGeometry = TextBufferGeometry;
  31259. exports.TextGeometry = TextGeometry;
  31260. exports.Texture = Texture;
  31261. exports.TextureLoader = TextureLoader;
  31262. exports.TorusBufferGeometry = TorusBufferGeometry;
  31263. exports.TorusGeometry = TorusGeometry;
  31264. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  31265. exports.TorusKnotGeometry = TorusKnotGeometry;
  31266. exports.Triangle = Triangle;
  31267. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31268. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31269. exports.TrianglesDrawMode = TrianglesDrawMode;
  31270. exports.TubeBufferGeometry = TubeBufferGeometry;
  31271. exports.TubeGeometry = TubeGeometry;
  31272. exports.UVMapping = UVMapping;
  31273. exports.Uint16Attribute = Uint16Attribute;
  31274. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31275. exports.Uint32Attribute = Uint32Attribute;
  31276. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31277. exports.Uint8Attribute = Uint8Attribute;
  31278. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31279. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31280. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31281. exports.Uniform = Uniform;
  31282. exports.UniformsLib = UniformsLib;
  31283. exports.UniformsUtils = UniformsUtils;
  31284. exports.UnsignedByteType = UnsignedByteType;
  31285. exports.UnsignedInt248Type = UnsignedInt248Type;
  31286. exports.UnsignedIntType = UnsignedIntType;
  31287. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31288. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31289. exports.UnsignedShort565Type = UnsignedShort565Type;
  31290. exports.UnsignedShortType = UnsignedShortType;
  31291. exports.VSMShadowMap = VSMShadowMap;
  31292. exports.Vector2 = Vector2;
  31293. exports.Vector3 = Vector3;
  31294. exports.Vector4 = Vector4;
  31295. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31296. exports.Vertex = Vertex;
  31297. exports.VertexColors = VertexColors;
  31298. exports.VideoTexture = VideoTexture;
  31299. exports.WebGL1Renderer = WebGL1Renderer;
  31300. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31301. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31302. exports.WebGLRenderTarget = WebGLRenderTarget;
  31303. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31304. exports.WebGLRenderer = WebGLRenderer;
  31305. exports.WebGLUtils = WebGLUtils;
  31306. exports.WireframeGeometry = WireframeGeometry;
  31307. exports.WireframeHelper = WireframeHelper;
  31308. exports.WrapAroundEnding = WrapAroundEnding;
  31309. exports.XHRLoader = XHRLoader;
  31310. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31311. exports.ZeroFactor = ZeroFactor;
  31312. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31313. exports.ZeroStencilOp = ZeroStencilOp;
  31314. exports.sRGBEncoding = sRGBEncoding;
  31315. Object.defineProperty(exports, '__esModule', { value: true });
  31316. })));