three.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287
  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 = '122';
  55. var MOUSE = {
  56. LEFT: 0,
  57. MIDDLE: 1,
  58. RIGHT: 2,
  59. ROTATE: 0,
  60. DOLLY: 1,
  61. PAN: 2
  62. };
  63. var TOUCH = {
  64. ROTATE: 0,
  65. PAN: 1,
  66. DOLLY_PAN: 2,
  67. DOLLY_ROTATE: 3
  68. };
  69. var CullFaceNone = 0;
  70. var CullFaceBack = 1;
  71. var CullFaceFront = 2;
  72. var CullFaceFrontBack = 3;
  73. var BasicShadowMap = 0;
  74. var PCFShadowMap = 1;
  75. var PCFSoftShadowMap = 2;
  76. var VSMShadowMap = 3;
  77. var FrontSide = 0;
  78. var BackSide = 1;
  79. var DoubleSide = 2;
  80. var FlatShading = 1;
  81. var SmoothShading = 2;
  82. var NoBlending = 0;
  83. var NormalBlending = 1;
  84. var AdditiveBlending = 2;
  85. var SubtractiveBlending = 3;
  86. var MultiplyBlending = 4;
  87. var CustomBlending = 5;
  88. var AddEquation = 100;
  89. var SubtractEquation = 101;
  90. var ReverseSubtractEquation = 102;
  91. var MinEquation = 103;
  92. var MaxEquation = 104;
  93. var ZeroFactor = 200;
  94. var OneFactor = 201;
  95. var SrcColorFactor = 202;
  96. var OneMinusSrcColorFactor = 203;
  97. var SrcAlphaFactor = 204;
  98. var OneMinusSrcAlphaFactor = 205;
  99. var DstAlphaFactor = 206;
  100. var OneMinusDstAlphaFactor = 207;
  101. var DstColorFactor = 208;
  102. var OneMinusDstColorFactor = 209;
  103. var SrcAlphaSaturateFactor = 210;
  104. var NeverDepth = 0;
  105. var AlwaysDepth = 1;
  106. var LessDepth = 2;
  107. var LessEqualDepth = 3;
  108. var EqualDepth = 4;
  109. var GreaterEqualDepth = 5;
  110. var GreaterDepth = 6;
  111. var NotEqualDepth = 7;
  112. var MultiplyOperation = 0;
  113. var MixOperation = 1;
  114. var AddOperation = 2;
  115. var NoToneMapping = 0;
  116. var LinearToneMapping = 1;
  117. var ReinhardToneMapping = 2;
  118. var CineonToneMapping = 3;
  119. var ACESFilmicToneMapping = 4;
  120. var CustomToneMapping = 5;
  121. var UVMapping = 300;
  122. var CubeReflectionMapping = 301;
  123. var CubeRefractionMapping = 302;
  124. var EquirectangularReflectionMapping = 303;
  125. var EquirectangularRefractionMapping = 304;
  126. var CubeUVReflectionMapping = 306;
  127. var CubeUVRefractionMapping = 307;
  128. var RepeatWrapping = 1000;
  129. var ClampToEdgeWrapping = 1001;
  130. var MirroredRepeatWrapping = 1002;
  131. var NearestFilter = 1003;
  132. var NearestMipmapNearestFilter = 1004;
  133. var NearestMipMapNearestFilter = 1004;
  134. var NearestMipmapLinearFilter = 1005;
  135. var NearestMipMapLinearFilter = 1005;
  136. var LinearFilter = 1006;
  137. var LinearMipmapNearestFilter = 1007;
  138. var LinearMipMapNearestFilter = 1007;
  139. var LinearMipmapLinearFilter = 1008;
  140. var LinearMipMapLinearFilter = 1008;
  141. var UnsignedByteType = 1009;
  142. var ByteType = 1010;
  143. var ShortType = 1011;
  144. var UnsignedShortType = 1012;
  145. var IntType = 1013;
  146. var UnsignedIntType = 1014;
  147. var FloatType = 1015;
  148. var HalfFloatType = 1016;
  149. var UnsignedShort4444Type = 1017;
  150. var UnsignedShort5551Type = 1018;
  151. var UnsignedShort565Type = 1019;
  152. var UnsignedInt248Type = 1020;
  153. var AlphaFormat = 1021;
  154. var RGBFormat = 1022;
  155. var RGBAFormat = 1023;
  156. var LuminanceFormat = 1024;
  157. var LuminanceAlphaFormat = 1025;
  158. var RGBEFormat = RGBAFormat;
  159. var DepthFormat = 1026;
  160. var DepthStencilFormat = 1027;
  161. var RedFormat = 1028;
  162. var RedIntegerFormat = 1029;
  163. var RGFormat = 1030;
  164. var RGIntegerFormat = 1031;
  165. var RGBIntegerFormat = 1032;
  166. var RGBAIntegerFormat = 1033;
  167. var RGB_S3TC_DXT1_Format = 33776;
  168. var RGBA_S3TC_DXT1_Format = 33777;
  169. var RGBA_S3TC_DXT3_Format = 33778;
  170. var RGBA_S3TC_DXT5_Format = 33779;
  171. var RGB_PVRTC_4BPPV1_Format = 35840;
  172. var RGB_PVRTC_2BPPV1_Format = 35841;
  173. var RGBA_PVRTC_4BPPV1_Format = 35842;
  174. var RGBA_PVRTC_2BPPV1_Format = 35843;
  175. var RGB_ETC1_Format = 36196;
  176. var RGB_ETC2_Format = 37492;
  177. var RGBA_ETC2_EAC_Format = 37496;
  178. var RGBA_ASTC_4x4_Format = 37808;
  179. var RGBA_ASTC_5x4_Format = 37809;
  180. var RGBA_ASTC_5x5_Format = 37810;
  181. var RGBA_ASTC_6x5_Format = 37811;
  182. var RGBA_ASTC_6x6_Format = 37812;
  183. var RGBA_ASTC_8x5_Format = 37813;
  184. var RGBA_ASTC_8x6_Format = 37814;
  185. var RGBA_ASTC_8x8_Format = 37815;
  186. var RGBA_ASTC_10x5_Format = 37816;
  187. var RGBA_ASTC_10x6_Format = 37817;
  188. var RGBA_ASTC_10x8_Format = 37818;
  189. var RGBA_ASTC_10x10_Format = 37819;
  190. var RGBA_ASTC_12x10_Format = 37820;
  191. var RGBA_ASTC_12x12_Format = 37821;
  192. var RGBA_BPTC_Format = 36492;
  193. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  194. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  195. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  196. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  197. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  198. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  199. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  200. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  201. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  202. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  203. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  204. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  205. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  206. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  207. var LoopOnce = 2200;
  208. var LoopRepeat = 2201;
  209. var LoopPingPong = 2202;
  210. var InterpolateDiscrete = 2300;
  211. var InterpolateLinear = 2301;
  212. var InterpolateSmooth = 2302;
  213. var ZeroCurvatureEnding = 2400;
  214. var ZeroSlopeEnding = 2401;
  215. var WrapAroundEnding = 2402;
  216. var NormalAnimationBlendMode = 2500;
  217. var AdditiveAnimationBlendMode = 2501;
  218. var TrianglesDrawMode = 0;
  219. var TriangleStripDrawMode = 1;
  220. var TriangleFanDrawMode = 2;
  221. var LinearEncoding = 3000;
  222. var sRGBEncoding = 3001;
  223. var GammaEncoding = 3007;
  224. var RGBEEncoding = 3002;
  225. var LogLuvEncoding = 3003;
  226. var RGBM7Encoding = 3004;
  227. var RGBM16Encoding = 3005;
  228. var RGBDEncoding = 3006;
  229. var BasicDepthPacking = 3200;
  230. var RGBADepthPacking = 3201;
  231. var TangentSpaceNormalMap = 0;
  232. var ObjectSpaceNormalMap = 1;
  233. var ZeroStencilOp = 0;
  234. var KeepStencilOp = 7680;
  235. var ReplaceStencilOp = 7681;
  236. var IncrementStencilOp = 7682;
  237. var DecrementStencilOp = 7683;
  238. var IncrementWrapStencilOp = 34055;
  239. var DecrementWrapStencilOp = 34056;
  240. var InvertStencilOp = 5386;
  241. var NeverStencilFunc = 512;
  242. var LessStencilFunc = 513;
  243. var EqualStencilFunc = 514;
  244. var LessEqualStencilFunc = 515;
  245. var GreaterStencilFunc = 516;
  246. var NotEqualStencilFunc = 517;
  247. var GreaterEqualStencilFunc = 518;
  248. var AlwaysStencilFunc = 519;
  249. var StaticDrawUsage = 35044;
  250. var DynamicDrawUsage = 35048;
  251. var StreamDrawUsage = 35040;
  252. var StaticReadUsage = 35045;
  253. var DynamicReadUsage = 35049;
  254. var StreamReadUsage = 35041;
  255. var StaticCopyUsage = 35046;
  256. var DynamicCopyUsage = 35050;
  257. var StreamCopyUsage = 35042;
  258. var GLSL1 = "100";
  259. var GLSL3 = "300 es";
  260. /**
  261. * https://github.com/mrdoob/eventdispatcher.js/
  262. */
  263. function EventDispatcher() {}
  264. Object.assign(EventDispatcher.prototype, {
  265. addEventListener: function addEventListener(type, listener) {
  266. if (this._listeners === undefined) this._listeners = {};
  267. var listeners = this._listeners;
  268. if (listeners[type] === undefined) {
  269. listeners[type] = [];
  270. }
  271. if (listeners[type].indexOf(listener) === -1) {
  272. listeners[type].push(listener);
  273. }
  274. },
  275. hasEventListener: function hasEventListener(type, listener) {
  276. if (this._listeners === undefined) return false;
  277. var listeners = this._listeners;
  278. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  279. },
  280. removeEventListener: function removeEventListener(type, listener) {
  281. if (this._listeners === undefined) return;
  282. var listeners = this._listeners;
  283. var listenerArray = listeners[type];
  284. if (listenerArray !== undefined) {
  285. var index = listenerArray.indexOf(listener);
  286. if (index !== -1) {
  287. listenerArray.splice(index, 1);
  288. }
  289. }
  290. },
  291. dispatchEvent: function dispatchEvent(event) {
  292. if (this._listeners === undefined) return;
  293. var listeners = this._listeners;
  294. var listenerArray = listeners[event.type];
  295. if (listenerArray !== undefined) {
  296. event.target = this; // Make a copy, in case listeners are removed while iterating.
  297. var array = listenerArray.slice(0);
  298. for (var i = 0, l = array.length; i < l; i++) {
  299. array[i].call(this, event);
  300. }
  301. }
  302. }
  303. });
  304. var _lut = [];
  305. for (var i = 0; i < 256; i++) {
  306. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  307. }
  308. var _seed = 1234567;
  309. var MathUtils = {
  310. DEG2RAD: Math.PI / 180,
  311. RAD2DEG: 180 / Math.PI,
  312. generateUUID: function generateUUID() {
  313. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  314. var d0 = Math.random() * 0xffffffff | 0;
  315. var d1 = Math.random() * 0xffffffff | 0;
  316. var d2 = Math.random() * 0xffffffff | 0;
  317. var d3 = Math.random() * 0xffffffff | 0;
  318. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  319. return uuid.toUpperCase();
  320. },
  321. clamp: function clamp(value, min, max) {
  322. return Math.max(min, Math.min(max, value));
  323. },
  324. // compute euclidian modulo of m % n
  325. // https://en.wikipedia.org/wiki/Modulo_operation
  326. euclideanModulo: function euclideanModulo(n, m) {
  327. return (n % m + m) % m;
  328. },
  329. // Linear mapping from range <a1, a2> to range <b1, b2>
  330. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  331. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  332. },
  333. // https://en.wikipedia.org/wiki/Linear_interpolation
  334. lerp: function lerp(x, y, t) {
  335. return (1 - t) * x + t * y;
  336. },
  337. // http://en.wikipedia.org/wiki/Smoothstep
  338. smoothstep: function smoothstep(x, min, max) {
  339. if (x <= min) return 0;
  340. if (x >= max) return 1;
  341. x = (x - min) / (max - min);
  342. return x * x * (3 - 2 * x);
  343. },
  344. smootherstep: function smootherstep(x, min, max) {
  345. if (x <= min) return 0;
  346. if (x >= max) return 1;
  347. x = (x - min) / (max - min);
  348. return x * x * x * (x * (x * 6 - 15) + 10);
  349. },
  350. // Random integer from <low, high> interval
  351. randInt: function randInt(low, high) {
  352. return low + Math.floor(Math.random() * (high - low + 1));
  353. },
  354. // Random float from <low, high> interval
  355. randFloat: function randFloat(low, high) {
  356. return low + Math.random() * (high - low);
  357. },
  358. // Random float from <-range/2, range/2> interval
  359. randFloatSpread: function randFloatSpread(range) {
  360. return range * (0.5 - Math.random());
  361. },
  362. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  363. seededRandom: function seededRandom(s) {
  364. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  365. _seed = _seed * 16807 % 2147483647;
  366. return (_seed - 1) / 2147483646;
  367. },
  368. degToRad: function degToRad(degrees) {
  369. return degrees * MathUtils.DEG2RAD;
  370. },
  371. radToDeg: function radToDeg(radians) {
  372. return radians * MathUtils.RAD2DEG;
  373. },
  374. isPowerOfTwo: function isPowerOfTwo(value) {
  375. return (value & value - 1) === 0 && value !== 0;
  376. },
  377. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  378. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  379. },
  380. floorPowerOfTwo: function floorPowerOfTwo(value) {
  381. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  382. },
  383. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  384. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  385. // rotations are applied to the axes in the order specified by 'order'
  386. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  387. // angles are in radians
  388. var cos = Math.cos;
  389. var sin = Math.sin;
  390. var c2 = cos(b / 2);
  391. var s2 = sin(b / 2);
  392. var c13 = cos((a + c) / 2);
  393. var s13 = sin((a + c) / 2);
  394. var c1_3 = cos((a - c) / 2);
  395. var s1_3 = sin((a - c) / 2);
  396. var c3_1 = cos((c - a) / 2);
  397. var s3_1 = sin((c - a) / 2);
  398. switch (order) {
  399. case 'XYX':
  400. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  401. break;
  402. case 'YZY':
  403. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  404. break;
  405. case 'ZXZ':
  406. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  407. break;
  408. case 'XZX':
  409. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  410. break;
  411. case 'YXY':
  412. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  413. break;
  414. case 'ZYZ':
  415. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  416. break;
  417. default:
  418. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  419. }
  420. }
  421. };
  422. function _defineProperties(target, props) {
  423. for (var i = 0; i < props.length; i++) {
  424. var descriptor = props[i];
  425. descriptor.enumerable = descriptor.enumerable || false;
  426. descriptor.configurable = true;
  427. if ("value" in descriptor) descriptor.writable = true;
  428. Object.defineProperty(target, descriptor.key, descriptor);
  429. }
  430. }
  431. function _createClass(Constructor, protoProps, staticProps) {
  432. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  433. if (staticProps) _defineProperties(Constructor, staticProps);
  434. return Constructor;
  435. }
  436. function _inheritsLoose(subClass, superClass) {
  437. subClass.prototype = Object.create(superClass.prototype);
  438. subClass.prototype.constructor = subClass;
  439. subClass.__proto__ = superClass;
  440. }
  441. function _assertThisInitialized(self) {
  442. if (self === void 0) {
  443. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  444. }
  445. return self;
  446. }
  447. var Vector2 = /*#__PURE__*/function () {
  448. function Vector2(x, y) {
  449. if (x === void 0) {
  450. x = 0;
  451. }
  452. if (y === void 0) {
  453. y = 0;
  454. }
  455. Object.defineProperty(this, 'isVector2', {
  456. value: true
  457. });
  458. this.x = x;
  459. this.y = y;
  460. }
  461. var _proto = Vector2.prototype;
  462. _proto.set = function set(x, y) {
  463. this.x = x;
  464. this.y = y;
  465. return this;
  466. };
  467. _proto.setScalar = function setScalar(scalar) {
  468. this.x = scalar;
  469. this.y = scalar;
  470. return this;
  471. };
  472. _proto.setX = function setX(x) {
  473. this.x = x;
  474. return this;
  475. };
  476. _proto.setY = function setY(y) {
  477. this.y = y;
  478. return this;
  479. };
  480. _proto.setComponent = function setComponent(index, value) {
  481. switch (index) {
  482. case 0:
  483. this.x = value;
  484. break;
  485. case 1:
  486. this.y = value;
  487. break;
  488. default:
  489. throw new Error('index is out of range: ' + index);
  490. }
  491. return this;
  492. };
  493. _proto.getComponent = function getComponent(index) {
  494. switch (index) {
  495. case 0:
  496. return this.x;
  497. case 1:
  498. return this.y;
  499. default:
  500. throw new Error('index is out of range: ' + index);
  501. }
  502. };
  503. _proto.clone = function clone() {
  504. return new this.constructor(this.x, this.y);
  505. };
  506. _proto.copy = function copy(v) {
  507. this.x = v.x;
  508. this.y = v.y;
  509. return this;
  510. };
  511. _proto.add = function add(v, w) {
  512. if (w !== undefined) {
  513. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  514. return this.addVectors(v, w);
  515. }
  516. this.x += v.x;
  517. this.y += v.y;
  518. return this;
  519. };
  520. _proto.addScalar = function addScalar(s) {
  521. this.x += s;
  522. this.y += s;
  523. return this;
  524. };
  525. _proto.addVectors = function addVectors(a, b) {
  526. this.x = a.x + b.x;
  527. this.y = a.y + b.y;
  528. return this;
  529. };
  530. _proto.addScaledVector = function addScaledVector(v, s) {
  531. this.x += v.x * s;
  532. this.y += v.y * s;
  533. return this;
  534. };
  535. _proto.sub = function sub(v, w) {
  536. if (w !== undefined) {
  537. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  538. return this.subVectors(v, w);
  539. }
  540. this.x -= v.x;
  541. this.y -= v.y;
  542. return this;
  543. };
  544. _proto.subScalar = function subScalar(s) {
  545. this.x -= s;
  546. this.y -= s;
  547. return this;
  548. };
  549. _proto.subVectors = function subVectors(a, b) {
  550. this.x = a.x - b.x;
  551. this.y = a.y - b.y;
  552. return this;
  553. };
  554. _proto.multiply = function multiply(v) {
  555. this.x *= v.x;
  556. this.y *= v.y;
  557. return this;
  558. };
  559. _proto.multiplyScalar = function multiplyScalar(scalar) {
  560. this.x *= scalar;
  561. this.y *= scalar;
  562. return this;
  563. };
  564. _proto.divide = function divide(v) {
  565. this.x /= v.x;
  566. this.y /= v.y;
  567. return this;
  568. };
  569. _proto.divideScalar = function divideScalar(scalar) {
  570. return this.multiplyScalar(1 / scalar);
  571. };
  572. _proto.applyMatrix3 = function applyMatrix3(m) {
  573. var x = this.x,
  574. y = this.y;
  575. var e = m.elements;
  576. this.x = e[0] * x + e[3] * y + e[6];
  577. this.y = e[1] * x + e[4] * y + e[7];
  578. return this;
  579. };
  580. _proto.min = function min(v) {
  581. this.x = Math.min(this.x, v.x);
  582. this.y = Math.min(this.y, v.y);
  583. return this;
  584. };
  585. _proto.max = function max(v) {
  586. this.x = Math.max(this.x, v.x);
  587. this.y = Math.max(this.y, v.y);
  588. return this;
  589. };
  590. _proto.clamp = function clamp(min, max) {
  591. // assumes min < max, componentwise
  592. this.x = Math.max(min.x, Math.min(max.x, this.x));
  593. this.y = Math.max(min.y, Math.min(max.y, this.y));
  594. return this;
  595. };
  596. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  597. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  598. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  599. return this;
  600. };
  601. _proto.clampLength = function clampLength(min, max) {
  602. var length = this.length();
  603. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  604. };
  605. _proto.floor = function floor() {
  606. this.x = Math.floor(this.x);
  607. this.y = Math.floor(this.y);
  608. return this;
  609. };
  610. _proto.ceil = function ceil() {
  611. this.x = Math.ceil(this.x);
  612. this.y = Math.ceil(this.y);
  613. return this;
  614. };
  615. _proto.round = function round() {
  616. this.x = Math.round(this.x);
  617. this.y = Math.round(this.y);
  618. return this;
  619. };
  620. _proto.roundToZero = function roundToZero() {
  621. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  622. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  623. return this;
  624. };
  625. _proto.negate = function negate() {
  626. this.x = -this.x;
  627. this.y = -this.y;
  628. return this;
  629. };
  630. _proto.dot = function dot(v) {
  631. return this.x * v.x + this.y * v.y;
  632. };
  633. _proto.cross = function cross(v) {
  634. return this.x * v.y - this.y * v.x;
  635. };
  636. _proto.lengthSq = function lengthSq() {
  637. return this.x * this.x + this.y * this.y;
  638. };
  639. _proto.length = function length() {
  640. return Math.sqrt(this.x * this.x + this.y * this.y);
  641. };
  642. _proto.manhattanLength = function manhattanLength() {
  643. return Math.abs(this.x) + Math.abs(this.y);
  644. };
  645. _proto.normalize = function normalize() {
  646. return this.divideScalar(this.length() || 1);
  647. };
  648. _proto.angle = function angle() {
  649. // computes the angle in radians with respect to the positive x-axis
  650. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  651. return angle;
  652. };
  653. _proto.distanceTo = function distanceTo(v) {
  654. return Math.sqrt(this.distanceToSquared(v));
  655. };
  656. _proto.distanceToSquared = function distanceToSquared(v) {
  657. var dx = this.x - v.x,
  658. dy = this.y - v.y;
  659. return dx * dx + dy * dy;
  660. };
  661. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  662. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  663. };
  664. _proto.setLength = function setLength(length) {
  665. return this.normalize().multiplyScalar(length);
  666. };
  667. _proto.lerp = function lerp(v, alpha) {
  668. this.x += (v.x - this.x) * alpha;
  669. this.y += (v.y - this.y) * alpha;
  670. return this;
  671. };
  672. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  673. this.x = v1.x + (v2.x - v1.x) * alpha;
  674. this.y = v1.y + (v2.y - v1.y) * alpha;
  675. return this;
  676. };
  677. _proto.equals = function equals(v) {
  678. return v.x === this.x && v.y === this.y;
  679. };
  680. _proto.fromArray = function fromArray(array, offset) {
  681. if (offset === void 0) {
  682. offset = 0;
  683. }
  684. this.x = array[offset];
  685. this.y = array[offset + 1];
  686. return this;
  687. };
  688. _proto.toArray = function toArray(array, offset) {
  689. if (array === void 0) {
  690. array = [];
  691. }
  692. if (offset === void 0) {
  693. offset = 0;
  694. }
  695. array[offset] = this.x;
  696. array[offset + 1] = this.y;
  697. return array;
  698. };
  699. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  700. if (offset !== undefined) {
  701. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  702. }
  703. this.x = attribute.getX(index);
  704. this.y = attribute.getY(index);
  705. return this;
  706. };
  707. _proto.rotateAround = function rotateAround(center, angle) {
  708. var c = Math.cos(angle),
  709. s = Math.sin(angle);
  710. var x = this.x - center.x;
  711. var y = this.y - center.y;
  712. this.x = x * c - y * s + center.x;
  713. this.y = x * s + y * c + center.y;
  714. return this;
  715. };
  716. _proto.random = function random() {
  717. this.x = Math.random();
  718. this.y = Math.random();
  719. return this;
  720. };
  721. _createClass(Vector2, [{
  722. key: "width",
  723. get: function get() {
  724. return this.x;
  725. },
  726. set: function set(value) {
  727. this.x = value;
  728. }
  729. }, {
  730. key: "height",
  731. get: function get() {
  732. return this.y;
  733. },
  734. set: function set(value) {
  735. this.y = value;
  736. }
  737. }]);
  738. return Vector2;
  739. }();
  740. var Matrix3 = /*#__PURE__*/function () {
  741. function Matrix3() {
  742. Object.defineProperty(this, 'isMatrix3', {
  743. value: true
  744. });
  745. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  746. if (arguments.length > 0) {
  747. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  748. }
  749. }
  750. var _proto = Matrix3.prototype;
  751. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  752. var te = this.elements;
  753. te[0] = n11;
  754. te[1] = n21;
  755. te[2] = n31;
  756. te[3] = n12;
  757. te[4] = n22;
  758. te[5] = n32;
  759. te[6] = n13;
  760. te[7] = n23;
  761. te[8] = n33;
  762. return this;
  763. };
  764. _proto.identity = function identity() {
  765. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  766. return this;
  767. };
  768. _proto.clone = function clone() {
  769. return new this.constructor().fromArray(this.elements);
  770. };
  771. _proto.copy = function copy(m) {
  772. var te = this.elements;
  773. var me = m.elements;
  774. te[0] = me[0];
  775. te[1] = me[1];
  776. te[2] = me[2];
  777. te[3] = me[3];
  778. te[4] = me[4];
  779. te[5] = me[5];
  780. te[6] = me[6];
  781. te[7] = me[7];
  782. te[8] = me[8];
  783. return this;
  784. };
  785. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  786. xAxis.setFromMatrix3Column(this, 0);
  787. yAxis.setFromMatrix3Column(this, 1);
  788. zAxis.setFromMatrix3Column(this, 2);
  789. return this;
  790. };
  791. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  792. var me = m.elements;
  793. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  794. return this;
  795. };
  796. _proto.multiply = function multiply(m) {
  797. return this.multiplyMatrices(this, m);
  798. };
  799. _proto.premultiply = function premultiply(m) {
  800. return this.multiplyMatrices(m, this);
  801. };
  802. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  803. var ae = a.elements;
  804. var be = b.elements;
  805. var te = this.elements;
  806. var a11 = ae[0],
  807. a12 = ae[3],
  808. a13 = ae[6];
  809. var a21 = ae[1],
  810. a22 = ae[4],
  811. a23 = ae[7];
  812. var a31 = ae[2],
  813. a32 = ae[5],
  814. a33 = ae[8];
  815. var b11 = be[0],
  816. b12 = be[3],
  817. b13 = be[6];
  818. var b21 = be[1],
  819. b22 = be[4],
  820. b23 = be[7];
  821. var b31 = be[2],
  822. b32 = be[5],
  823. b33 = be[8];
  824. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  825. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  826. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  827. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  828. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  829. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  830. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  831. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  832. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  833. return this;
  834. };
  835. _proto.multiplyScalar = function multiplyScalar(s) {
  836. var te = this.elements;
  837. te[0] *= s;
  838. te[3] *= s;
  839. te[6] *= s;
  840. te[1] *= s;
  841. te[4] *= s;
  842. te[7] *= s;
  843. te[2] *= s;
  844. te[5] *= s;
  845. te[8] *= s;
  846. return this;
  847. };
  848. _proto.determinant = function determinant() {
  849. var te = this.elements;
  850. var a = te[0],
  851. b = te[1],
  852. c = te[2],
  853. d = te[3],
  854. e = te[4],
  855. f = te[5],
  856. g = te[6],
  857. h = te[7],
  858. i = te[8];
  859. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  860. };
  861. _proto.getInverse = function getInverse(matrix, throwOnDegenerate) {
  862. if (throwOnDegenerate !== undefined) {
  863. console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");
  864. }
  865. var me = matrix.elements,
  866. te = this.elements,
  867. n11 = me[0],
  868. n21 = me[1],
  869. n31 = me[2],
  870. n12 = me[3],
  871. n22 = me[4],
  872. n32 = me[5],
  873. n13 = me[6],
  874. n23 = me[7],
  875. n33 = me[8],
  876. t11 = n33 * n22 - n32 * n23,
  877. t12 = n32 * n13 - n33 * n12,
  878. t13 = n23 * n12 - n22 * n13,
  879. det = n11 * t11 + n21 * t12 + n31 * t13;
  880. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  881. var detInv = 1 / det;
  882. te[0] = t11 * detInv;
  883. te[1] = (n31 * n23 - n33 * n21) * detInv;
  884. te[2] = (n32 * n21 - n31 * n22) * detInv;
  885. te[3] = t12 * detInv;
  886. te[4] = (n33 * n11 - n31 * n13) * detInv;
  887. te[5] = (n31 * n12 - n32 * n11) * detInv;
  888. te[6] = t13 * detInv;
  889. te[7] = (n21 * n13 - n23 * n11) * detInv;
  890. te[8] = (n22 * n11 - n21 * n12) * detInv;
  891. return this;
  892. };
  893. _proto.transpose = function transpose() {
  894. var tmp;
  895. var m = this.elements;
  896. tmp = m[1];
  897. m[1] = m[3];
  898. m[3] = tmp;
  899. tmp = m[2];
  900. m[2] = m[6];
  901. m[6] = tmp;
  902. tmp = m[5];
  903. m[5] = m[7];
  904. m[7] = tmp;
  905. return this;
  906. };
  907. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  908. return this.setFromMatrix4(matrix4).getInverse(this).transpose();
  909. };
  910. _proto.transposeIntoArray = function transposeIntoArray(r) {
  911. var m = this.elements;
  912. r[0] = m[0];
  913. r[1] = m[3];
  914. r[2] = m[6];
  915. r[3] = m[1];
  916. r[4] = m[4];
  917. r[5] = m[7];
  918. r[6] = m[2];
  919. r[7] = m[5];
  920. r[8] = m[8];
  921. return this;
  922. };
  923. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  924. var c = Math.cos(rotation);
  925. var s = Math.sin(rotation);
  926. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  927. };
  928. _proto.scale = function scale(sx, sy) {
  929. var te = this.elements;
  930. te[0] *= sx;
  931. te[3] *= sx;
  932. te[6] *= sx;
  933. te[1] *= sy;
  934. te[4] *= sy;
  935. te[7] *= sy;
  936. return this;
  937. };
  938. _proto.rotate = function rotate(theta) {
  939. var c = Math.cos(theta);
  940. var s = Math.sin(theta);
  941. var te = this.elements;
  942. var a11 = te[0],
  943. a12 = te[3],
  944. a13 = te[6];
  945. var a21 = te[1],
  946. a22 = te[4],
  947. a23 = te[7];
  948. te[0] = c * a11 + s * a21;
  949. te[3] = c * a12 + s * a22;
  950. te[6] = c * a13 + s * a23;
  951. te[1] = -s * a11 + c * a21;
  952. te[4] = -s * a12 + c * a22;
  953. te[7] = -s * a13 + c * a23;
  954. return this;
  955. };
  956. _proto.translate = function translate(tx, ty) {
  957. var te = this.elements;
  958. te[0] += tx * te[2];
  959. te[3] += tx * te[5];
  960. te[6] += tx * te[8];
  961. te[1] += ty * te[2];
  962. te[4] += ty * te[5];
  963. te[7] += ty * te[8];
  964. return this;
  965. };
  966. _proto.equals = function equals(matrix) {
  967. var te = this.elements;
  968. var me = matrix.elements;
  969. for (var i = 0; i < 9; i++) {
  970. if (te[i] !== me[i]) return false;
  971. }
  972. return true;
  973. };
  974. _proto.fromArray = function fromArray(array, offset) {
  975. if (offset === void 0) {
  976. offset = 0;
  977. }
  978. for (var i = 0; i < 9; i++) {
  979. this.elements[i] = array[i + offset];
  980. }
  981. return this;
  982. };
  983. _proto.toArray = function toArray(array, offset) {
  984. if (array === void 0) {
  985. array = [];
  986. }
  987. if (offset === void 0) {
  988. offset = 0;
  989. }
  990. var te = this.elements;
  991. array[offset] = te[0];
  992. array[offset + 1] = te[1];
  993. array[offset + 2] = te[2];
  994. array[offset + 3] = te[3];
  995. array[offset + 4] = te[4];
  996. array[offset + 5] = te[5];
  997. array[offset + 6] = te[6];
  998. array[offset + 7] = te[7];
  999. array[offset + 8] = te[8];
  1000. return array;
  1001. };
  1002. return Matrix3;
  1003. }();
  1004. var _canvas;
  1005. var ImageUtils = {
  1006. getDataURL: function getDataURL(image) {
  1007. if (/^data:/i.test(image.src)) {
  1008. return image.src;
  1009. }
  1010. if (typeof HTMLCanvasElement == 'undefined') {
  1011. return image.src;
  1012. }
  1013. var canvas;
  1014. if (image instanceof HTMLCanvasElement) {
  1015. canvas = image;
  1016. } else {
  1017. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1018. _canvas.width = image.width;
  1019. _canvas.height = image.height;
  1020. var context = _canvas.getContext('2d');
  1021. if (image instanceof ImageData) {
  1022. context.putImageData(image, 0, 0);
  1023. } else {
  1024. context.drawImage(image, 0, 0, image.width, image.height);
  1025. }
  1026. canvas = _canvas;
  1027. }
  1028. if (canvas.width > 2048 || canvas.height > 2048) {
  1029. return canvas.toDataURL('image/jpeg', 0.6);
  1030. } else {
  1031. return canvas.toDataURL('image/png');
  1032. }
  1033. }
  1034. };
  1035. var textureId = 0;
  1036. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1037. Object.defineProperty(this, 'id', {
  1038. value: textureId++
  1039. });
  1040. this.uuid = MathUtils.generateUUID();
  1041. this.name = '';
  1042. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1043. this.mipmaps = [];
  1044. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1045. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1046. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1047. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1048. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1049. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1050. this.format = format !== undefined ? format : RGBAFormat;
  1051. this.internalFormat = null;
  1052. this.type = type !== undefined ? type : UnsignedByteType;
  1053. this.offset = new Vector2(0, 0);
  1054. this.repeat = new Vector2(1, 1);
  1055. this.center = new Vector2(0, 0);
  1056. this.rotation = 0;
  1057. this.matrixAutoUpdate = true;
  1058. this.matrix = new Matrix3();
  1059. this.generateMipmaps = true;
  1060. this.premultiplyAlpha = false;
  1061. this.flipY = true;
  1062. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1063. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1064. //
  1065. // Also changing the encoding after already used by a Material will not automatically make the Material
  1066. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1067. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1068. this.version = 0;
  1069. this.onUpdate = null;
  1070. }
  1071. Texture.DEFAULT_IMAGE = undefined;
  1072. Texture.DEFAULT_MAPPING = UVMapping;
  1073. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1074. constructor: Texture,
  1075. isTexture: true,
  1076. updateMatrix: function updateMatrix() {
  1077. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1078. },
  1079. clone: function clone() {
  1080. return new this.constructor().copy(this);
  1081. },
  1082. copy: function copy(source) {
  1083. this.name = source.name;
  1084. this.image = source.image;
  1085. this.mipmaps = source.mipmaps.slice(0);
  1086. this.mapping = source.mapping;
  1087. this.wrapS = source.wrapS;
  1088. this.wrapT = source.wrapT;
  1089. this.magFilter = source.magFilter;
  1090. this.minFilter = source.minFilter;
  1091. this.anisotropy = source.anisotropy;
  1092. this.format = source.format;
  1093. this.internalFormat = source.internalFormat;
  1094. this.type = source.type;
  1095. this.offset.copy(source.offset);
  1096. this.repeat.copy(source.repeat);
  1097. this.center.copy(source.center);
  1098. this.rotation = source.rotation;
  1099. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1100. this.matrix.copy(source.matrix);
  1101. this.generateMipmaps = source.generateMipmaps;
  1102. this.premultiplyAlpha = source.premultiplyAlpha;
  1103. this.flipY = source.flipY;
  1104. this.unpackAlignment = source.unpackAlignment;
  1105. this.encoding = source.encoding;
  1106. return this;
  1107. },
  1108. toJSON: function toJSON(meta) {
  1109. var isRootObject = meta === undefined || typeof meta === 'string';
  1110. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1111. return meta.textures[this.uuid];
  1112. }
  1113. var output = {
  1114. metadata: {
  1115. version: 4.5,
  1116. type: 'Texture',
  1117. generator: 'Texture.toJSON'
  1118. },
  1119. uuid: this.uuid,
  1120. name: this.name,
  1121. mapping: this.mapping,
  1122. repeat: [this.repeat.x, this.repeat.y],
  1123. offset: [this.offset.x, this.offset.y],
  1124. center: [this.center.x, this.center.y],
  1125. rotation: this.rotation,
  1126. wrap: [this.wrapS, this.wrapT],
  1127. format: this.format,
  1128. type: this.type,
  1129. encoding: this.encoding,
  1130. minFilter: this.minFilter,
  1131. magFilter: this.magFilter,
  1132. anisotropy: this.anisotropy,
  1133. flipY: this.flipY,
  1134. premultiplyAlpha: this.premultiplyAlpha,
  1135. unpackAlignment: this.unpackAlignment
  1136. };
  1137. if (this.image !== undefined) {
  1138. // TODO: Move to THREE.Image
  1139. var image = this.image;
  1140. if (image.uuid === undefined) {
  1141. image.uuid = MathUtils.generateUUID(); // UGH
  1142. }
  1143. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1144. var url;
  1145. if (Array.isArray(image)) {
  1146. // process array of images e.g. CubeTexture
  1147. url = [];
  1148. for (var i = 0, l = image.length; i < l; i++) {
  1149. url.push(ImageUtils.getDataURL(image[i]));
  1150. }
  1151. } else {
  1152. // process single image
  1153. url = ImageUtils.getDataURL(image);
  1154. }
  1155. meta.images[image.uuid] = {
  1156. uuid: image.uuid,
  1157. url: url
  1158. };
  1159. }
  1160. output.image = image.uuid;
  1161. }
  1162. if (!isRootObject) {
  1163. meta.textures[this.uuid] = output;
  1164. }
  1165. return output;
  1166. },
  1167. dispose: function dispose() {
  1168. this.dispatchEvent({
  1169. type: 'dispose'
  1170. });
  1171. },
  1172. transformUv: function transformUv(uv) {
  1173. if (this.mapping !== UVMapping) return uv;
  1174. uv.applyMatrix3(this.matrix);
  1175. if (uv.x < 0 || uv.x > 1) {
  1176. switch (this.wrapS) {
  1177. case RepeatWrapping:
  1178. uv.x = uv.x - Math.floor(uv.x);
  1179. break;
  1180. case ClampToEdgeWrapping:
  1181. uv.x = uv.x < 0 ? 0 : 1;
  1182. break;
  1183. case MirroredRepeatWrapping:
  1184. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1185. uv.x = Math.ceil(uv.x) - uv.x;
  1186. } else {
  1187. uv.x = uv.x - Math.floor(uv.x);
  1188. }
  1189. break;
  1190. }
  1191. }
  1192. if (uv.y < 0 || uv.y > 1) {
  1193. switch (this.wrapT) {
  1194. case RepeatWrapping:
  1195. uv.y = uv.y - Math.floor(uv.y);
  1196. break;
  1197. case ClampToEdgeWrapping:
  1198. uv.y = uv.y < 0 ? 0 : 1;
  1199. break;
  1200. case MirroredRepeatWrapping:
  1201. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1202. uv.y = Math.ceil(uv.y) - uv.y;
  1203. } else {
  1204. uv.y = uv.y - Math.floor(uv.y);
  1205. }
  1206. break;
  1207. }
  1208. }
  1209. if (this.flipY) {
  1210. uv.y = 1 - uv.y;
  1211. }
  1212. return uv;
  1213. }
  1214. });
  1215. Object.defineProperty(Texture.prototype, "needsUpdate", {
  1216. set: function set(value) {
  1217. if (value === true) this.version++;
  1218. }
  1219. });
  1220. var Vector4 = /*#__PURE__*/function () {
  1221. function Vector4(x, y, z, w) {
  1222. if (x === void 0) {
  1223. x = 0;
  1224. }
  1225. if (y === void 0) {
  1226. y = 0;
  1227. }
  1228. if (z === void 0) {
  1229. z = 0;
  1230. }
  1231. if (w === void 0) {
  1232. w = 1;
  1233. }
  1234. Object.defineProperty(this, 'isVector4', {
  1235. value: true
  1236. });
  1237. this.x = x;
  1238. this.y = y;
  1239. this.z = z;
  1240. this.w = w;
  1241. }
  1242. var _proto = Vector4.prototype;
  1243. _proto.set = function set(x, y, z, w) {
  1244. this.x = x;
  1245. this.y = y;
  1246. this.z = z;
  1247. this.w = w;
  1248. return this;
  1249. };
  1250. _proto.setScalar = function setScalar(scalar) {
  1251. this.x = scalar;
  1252. this.y = scalar;
  1253. this.z = scalar;
  1254. this.w = scalar;
  1255. return this;
  1256. };
  1257. _proto.setX = function setX(x) {
  1258. this.x = x;
  1259. return this;
  1260. };
  1261. _proto.setY = function setY(y) {
  1262. this.y = y;
  1263. return this;
  1264. };
  1265. _proto.setZ = function setZ(z) {
  1266. this.z = z;
  1267. return this;
  1268. };
  1269. _proto.setW = function setW(w) {
  1270. this.w = w;
  1271. return this;
  1272. };
  1273. _proto.setComponent = function setComponent(index, value) {
  1274. switch (index) {
  1275. case 0:
  1276. this.x = value;
  1277. break;
  1278. case 1:
  1279. this.y = value;
  1280. break;
  1281. case 2:
  1282. this.z = value;
  1283. break;
  1284. case 3:
  1285. this.w = value;
  1286. break;
  1287. default:
  1288. throw new Error('index is out of range: ' + index);
  1289. }
  1290. return this;
  1291. };
  1292. _proto.getComponent = function getComponent(index) {
  1293. switch (index) {
  1294. case 0:
  1295. return this.x;
  1296. case 1:
  1297. return this.y;
  1298. case 2:
  1299. return this.z;
  1300. case 3:
  1301. return this.w;
  1302. default:
  1303. throw new Error('index is out of range: ' + index);
  1304. }
  1305. };
  1306. _proto.clone = function clone() {
  1307. return new this.constructor(this.x, this.y, this.z, this.w);
  1308. };
  1309. _proto.copy = function copy(v) {
  1310. this.x = v.x;
  1311. this.y = v.y;
  1312. this.z = v.z;
  1313. this.w = v.w !== undefined ? v.w : 1;
  1314. return this;
  1315. };
  1316. _proto.add = function add(v, w) {
  1317. if (w !== undefined) {
  1318. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1319. return this.addVectors(v, w);
  1320. }
  1321. this.x += v.x;
  1322. this.y += v.y;
  1323. this.z += v.z;
  1324. this.w += v.w;
  1325. return this;
  1326. };
  1327. _proto.addScalar = function addScalar(s) {
  1328. this.x += s;
  1329. this.y += s;
  1330. this.z += s;
  1331. this.w += s;
  1332. return this;
  1333. };
  1334. _proto.addVectors = function addVectors(a, b) {
  1335. this.x = a.x + b.x;
  1336. this.y = a.y + b.y;
  1337. this.z = a.z + b.z;
  1338. this.w = a.w + b.w;
  1339. return this;
  1340. };
  1341. _proto.addScaledVector = function addScaledVector(v, s) {
  1342. this.x += v.x * s;
  1343. this.y += v.y * s;
  1344. this.z += v.z * s;
  1345. this.w += v.w * s;
  1346. return this;
  1347. };
  1348. _proto.sub = function sub(v, w) {
  1349. if (w !== undefined) {
  1350. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1351. return this.subVectors(v, w);
  1352. }
  1353. this.x -= v.x;
  1354. this.y -= v.y;
  1355. this.z -= v.z;
  1356. this.w -= v.w;
  1357. return this;
  1358. };
  1359. _proto.subScalar = function subScalar(s) {
  1360. this.x -= s;
  1361. this.y -= s;
  1362. this.z -= s;
  1363. this.w -= s;
  1364. return this;
  1365. };
  1366. _proto.subVectors = function subVectors(a, b) {
  1367. this.x = a.x - b.x;
  1368. this.y = a.y - b.y;
  1369. this.z = a.z - b.z;
  1370. this.w = a.w - b.w;
  1371. return this;
  1372. };
  1373. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1374. this.x *= scalar;
  1375. this.y *= scalar;
  1376. this.z *= scalar;
  1377. this.w *= scalar;
  1378. return this;
  1379. };
  1380. _proto.applyMatrix4 = function applyMatrix4(m) {
  1381. var x = this.x,
  1382. y = this.y,
  1383. z = this.z,
  1384. w = this.w;
  1385. var e = m.elements;
  1386. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  1387. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  1388. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  1389. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  1390. return this;
  1391. };
  1392. _proto.divideScalar = function divideScalar(scalar) {
  1393. return this.multiplyScalar(1 / scalar);
  1394. };
  1395. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  1396. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1397. // q is assumed to be normalized
  1398. this.w = 2 * Math.acos(q.w);
  1399. var s = Math.sqrt(1 - q.w * q.w);
  1400. if (s < 0.0001) {
  1401. this.x = 1;
  1402. this.y = 0;
  1403. this.z = 0;
  1404. } else {
  1405. this.x = q.x / s;
  1406. this.y = q.y / s;
  1407. this.z = q.z / s;
  1408. }
  1409. return this;
  1410. };
  1411. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  1412. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1413. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1414. var angle, x, y, z; // variables for result
  1415. var epsilon = 0.01,
  1416. // margin to allow for rounding errors
  1417. epsilon2 = 0.1,
  1418. // margin to distinguish between 0 and 180 degrees
  1419. te = m.elements,
  1420. m11 = te[0],
  1421. m12 = te[4],
  1422. m13 = te[8],
  1423. m21 = te[1],
  1424. m22 = te[5],
  1425. m23 = te[9],
  1426. m31 = te[2],
  1427. m32 = te[6],
  1428. m33 = te[10];
  1429. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  1430. // singularity found
  1431. // first check for identity matrix which must have +1 for all terms
  1432. // in leading diagonal and zero in other terms
  1433. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  1434. // this singularity is identity matrix so angle = 0
  1435. this.set(1, 0, 0, 0);
  1436. return this; // zero angle, arbitrary axis
  1437. } // otherwise this singularity is angle = 180
  1438. angle = Math.PI;
  1439. var xx = (m11 + 1) / 2;
  1440. var yy = (m22 + 1) / 2;
  1441. var zz = (m33 + 1) / 2;
  1442. var xy = (m12 + m21) / 4;
  1443. var xz = (m13 + m31) / 4;
  1444. var yz = (m23 + m32) / 4;
  1445. if (xx > yy && xx > zz) {
  1446. // m11 is the largest diagonal term
  1447. if (xx < epsilon) {
  1448. x = 0;
  1449. y = 0.707106781;
  1450. z = 0.707106781;
  1451. } else {
  1452. x = Math.sqrt(xx);
  1453. y = xy / x;
  1454. z = xz / x;
  1455. }
  1456. } else if (yy > zz) {
  1457. // m22 is the largest diagonal term
  1458. if (yy < epsilon) {
  1459. x = 0.707106781;
  1460. y = 0;
  1461. z = 0.707106781;
  1462. } else {
  1463. y = Math.sqrt(yy);
  1464. x = xy / y;
  1465. z = yz / y;
  1466. }
  1467. } else {
  1468. // m33 is the largest diagonal term so base result on this
  1469. if (zz < epsilon) {
  1470. x = 0.707106781;
  1471. y = 0.707106781;
  1472. z = 0;
  1473. } else {
  1474. z = Math.sqrt(zz);
  1475. x = xz / z;
  1476. y = yz / z;
  1477. }
  1478. }
  1479. this.set(x, y, z, angle);
  1480. return this; // return 180 deg rotation
  1481. } // as we have reached here there are no singularities so we can handle normally
  1482. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  1483. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1484. // caught by singularity test above, but I've left it in just in case
  1485. this.x = (m32 - m23) / s;
  1486. this.y = (m13 - m31) / s;
  1487. this.z = (m21 - m12) / s;
  1488. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  1489. return this;
  1490. };
  1491. _proto.min = function min(v) {
  1492. this.x = Math.min(this.x, v.x);
  1493. this.y = Math.min(this.y, v.y);
  1494. this.z = Math.min(this.z, v.z);
  1495. this.w = Math.min(this.w, v.w);
  1496. return this;
  1497. };
  1498. _proto.max = function max(v) {
  1499. this.x = Math.max(this.x, v.x);
  1500. this.y = Math.max(this.y, v.y);
  1501. this.z = Math.max(this.z, v.z);
  1502. this.w = Math.max(this.w, v.w);
  1503. return this;
  1504. };
  1505. _proto.clamp = function clamp(min, max) {
  1506. // assumes min < max, componentwise
  1507. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1508. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1509. this.z = Math.max(min.z, Math.min(max.z, this.z));
  1510. this.w = Math.max(min.w, Math.min(max.w, this.w));
  1511. return this;
  1512. };
  1513. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1514. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1515. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1516. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  1517. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  1518. return this;
  1519. };
  1520. _proto.clampLength = function clampLength(min, max) {
  1521. var length = this.length();
  1522. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1523. };
  1524. _proto.floor = function floor() {
  1525. this.x = Math.floor(this.x);
  1526. this.y = Math.floor(this.y);
  1527. this.z = Math.floor(this.z);
  1528. this.w = Math.floor(this.w);
  1529. return this;
  1530. };
  1531. _proto.ceil = function ceil() {
  1532. this.x = Math.ceil(this.x);
  1533. this.y = Math.ceil(this.y);
  1534. this.z = Math.ceil(this.z);
  1535. this.w = Math.ceil(this.w);
  1536. return this;
  1537. };
  1538. _proto.round = function round() {
  1539. this.x = Math.round(this.x);
  1540. this.y = Math.round(this.y);
  1541. this.z = Math.round(this.z);
  1542. this.w = Math.round(this.w);
  1543. return this;
  1544. };
  1545. _proto.roundToZero = function roundToZero() {
  1546. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1547. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1548. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  1549. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  1550. return this;
  1551. };
  1552. _proto.negate = function negate() {
  1553. this.x = -this.x;
  1554. this.y = -this.y;
  1555. this.z = -this.z;
  1556. this.w = -this.w;
  1557. return this;
  1558. };
  1559. _proto.dot = function dot(v) {
  1560. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1561. };
  1562. _proto.lengthSq = function lengthSq() {
  1563. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1564. };
  1565. _proto.length = function length() {
  1566. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1567. };
  1568. _proto.manhattanLength = function manhattanLength() {
  1569. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  1570. };
  1571. _proto.normalize = function normalize() {
  1572. return this.divideScalar(this.length() || 1);
  1573. };
  1574. _proto.setLength = function setLength(length) {
  1575. return this.normalize().multiplyScalar(length);
  1576. };
  1577. _proto.lerp = function lerp(v, alpha) {
  1578. this.x += (v.x - this.x) * alpha;
  1579. this.y += (v.y - this.y) * alpha;
  1580. this.z += (v.z - this.z) * alpha;
  1581. this.w += (v.w - this.w) * alpha;
  1582. return this;
  1583. };
  1584. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1585. this.x = v1.x + (v2.x - v1.x) * alpha;
  1586. this.y = v1.y + (v2.y - v1.y) * alpha;
  1587. this.z = v1.z + (v2.z - v1.z) * alpha;
  1588. this.w = v1.w + (v2.w - v1.w) * alpha;
  1589. return this;
  1590. };
  1591. _proto.equals = function equals(v) {
  1592. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  1593. };
  1594. _proto.fromArray = function fromArray(array, offset) {
  1595. if (offset === void 0) {
  1596. offset = 0;
  1597. }
  1598. this.x = array[offset];
  1599. this.y = array[offset + 1];
  1600. this.z = array[offset + 2];
  1601. this.w = array[offset + 3];
  1602. return this;
  1603. };
  1604. _proto.toArray = function toArray(array, offset) {
  1605. if (array === void 0) {
  1606. array = [];
  1607. }
  1608. if (offset === void 0) {
  1609. offset = 0;
  1610. }
  1611. array[offset] = this.x;
  1612. array[offset + 1] = this.y;
  1613. array[offset + 2] = this.z;
  1614. array[offset + 3] = this.w;
  1615. return array;
  1616. };
  1617. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1618. if (offset !== undefined) {
  1619. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  1620. }
  1621. this.x = attribute.getX(index);
  1622. this.y = attribute.getY(index);
  1623. this.z = attribute.getZ(index);
  1624. this.w = attribute.getW(index);
  1625. return this;
  1626. };
  1627. _proto.random = function random() {
  1628. this.x = Math.random();
  1629. this.y = Math.random();
  1630. this.z = Math.random();
  1631. this.w = Math.random();
  1632. return this;
  1633. };
  1634. _createClass(Vector4, [{
  1635. key: "width",
  1636. get: function get() {
  1637. return this.z;
  1638. },
  1639. set: function set(value) {
  1640. this.z = value;
  1641. }
  1642. }, {
  1643. key: "height",
  1644. get: function get() {
  1645. return this.w;
  1646. },
  1647. set: function set(value) {
  1648. this.w = value;
  1649. }
  1650. }]);
  1651. return Vector4;
  1652. }();
  1653. /*
  1654. In options, we can specify:
  1655. * Texture parameters for an auto-generated target texture
  1656. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1657. */
  1658. function WebGLRenderTarget(width, height, options) {
  1659. this.width = width;
  1660. this.height = height;
  1661. this.scissor = new Vector4(0, 0, width, height);
  1662. this.scissorTest = false;
  1663. this.viewport = new Vector4(0, 0, width, height);
  1664. options = options || {};
  1665. this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  1666. this.texture.image = {};
  1667. this.texture.image.width = width;
  1668. this.texture.image.height = height;
  1669. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1670. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1671. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1672. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1673. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1674. }
  1675. WebGLRenderTarget.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1676. constructor: WebGLRenderTarget,
  1677. isWebGLRenderTarget: true,
  1678. setSize: function setSize(width, height) {
  1679. if (this.width !== width || this.height !== height) {
  1680. this.width = width;
  1681. this.height = height;
  1682. this.texture.image.width = width;
  1683. this.texture.image.height = height;
  1684. this.dispose();
  1685. }
  1686. this.viewport.set(0, 0, width, height);
  1687. this.scissor.set(0, 0, width, height);
  1688. },
  1689. clone: function clone() {
  1690. return new this.constructor().copy(this);
  1691. },
  1692. copy: function copy(source) {
  1693. this.width = source.width;
  1694. this.height = source.height;
  1695. this.viewport.copy(source.viewport);
  1696. this.texture = source.texture.clone();
  1697. this.depthBuffer = source.depthBuffer;
  1698. this.stencilBuffer = source.stencilBuffer;
  1699. this.depthTexture = source.depthTexture;
  1700. return this;
  1701. },
  1702. dispose: function dispose() {
  1703. this.dispatchEvent({
  1704. type: 'dispose'
  1705. });
  1706. }
  1707. });
  1708. function WebGLMultisampleRenderTarget(width, height, options) {
  1709. WebGLRenderTarget.call(this, width, height, options);
  1710. this.samples = 4;
  1711. }
  1712. WebGLMultisampleRenderTarget.prototype = Object.assign(Object.create(WebGLRenderTarget.prototype), {
  1713. constructor: WebGLMultisampleRenderTarget,
  1714. isWebGLMultisampleRenderTarget: true,
  1715. copy: function copy(source) {
  1716. WebGLRenderTarget.prototype.copy.call(this, source);
  1717. this.samples = source.samples;
  1718. return this;
  1719. }
  1720. });
  1721. var Quaternion = /*#__PURE__*/function () {
  1722. function Quaternion(x, y, z, w) {
  1723. if (x === void 0) {
  1724. x = 0;
  1725. }
  1726. if (y === void 0) {
  1727. y = 0;
  1728. }
  1729. if (z === void 0) {
  1730. z = 0;
  1731. }
  1732. if (w === void 0) {
  1733. w = 1;
  1734. }
  1735. Object.defineProperty(this, 'isQuaternion', {
  1736. value: true
  1737. });
  1738. this._x = x;
  1739. this._y = y;
  1740. this._z = z;
  1741. this._w = w;
  1742. }
  1743. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  1744. return qm.copy(qa).slerp(qb, t);
  1745. };
  1746. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  1747. // fuzz-free, array-based Quaternion SLERP operation
  1748. var x0 = src0[srcOffset0 + 0],
  1749. y0 = src0[srcOffset0 + 1],
  1750. z0 = src0[srcOffset0 + 2],
  1751. w0 = src0[srcOffset0 + 3];
  1752. var x1 = src1[srcOffset1 + 0],
  1753. y1 = src1[srcOffset1 + 1],
  1754. z1 = src1[srcOffset1 + 2],
  1755. w1 = src1[srcOffset1 + 3];
  1756. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  1757. var s = 1 - t;
  1758. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1759. dir = cos >= 0 ? 1 : -1,
  1760. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  1761. if (sqrSin > Number.EPSILON) {
  1762. var sin = Math.sqrt(sqrSin),
  1763. len = Math.atan2(sin, cos * dir);
  1764. s = Math.sin(s * len) / sin;
  1765. t = Math.sin(t * len) / sin;
  1766. }
  1767. var tDir = t * dir;
  1768. x0 = x0 * s + x1 * tDir;
  1769. y0 = y0 * s + y1 * tDir;
  1770. z0 = z0 * s + z1 * tDir;
  1771. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  1772. if (s === 1 - t) {
  1773. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  1774. x0 *= f;
  1775. y0 *= f;
  1776. z0 *= f;
  1777. w0 *= f;
  1778. }
  1779. }
  1780. dst[dstOffset] = x0;
  1781. dst[dstOffset + 1] = y0;
  1782. dst[dstOffset + 2] = z0;
  1783. dst[dstOffset + 3] = w0;
  1784. };
  1785. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  1786. var x0 = src0[srcOffset0];
  1787. var y0 = src0[srcOffset0 + 1];
  1788. var z0 = src0[srcOffset0 + 2];
  1789. var w0 = src0[srcOffset0 + 3];
  1790. var x1 = src1[srcOffset1];
  1791. var y1 = src1[srcOffset1 + 1];
  1792. var z1 = src1[srcOffset1 + 2];
  1793. var w1 = src1[srcOffset1 + 3];
  1794. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1795. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1796. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1797. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1798. return dst;
  1799. };
  1800. var _proto = Quaternion.prototype;
  1801. _proto.set = function set(x, y, z, w) {
  1802. this._x = x;
  1803. this._y = y;
  1804. this._z = z;
  1805. this._w = w;
  1806. this._onChangeCallback();
  1807. return this;
  1808. };
  1809. _proto.clone = function clone() {
  1810. return new this.constructor(this._x, this._y, this._z, this._w);
  1811. };
  1812. _proto.copy = function copy(quaternion) {
  1813. this._x = quaternion.x;
  1814. this._y = quaternion.y;
  1815. this._z = quaternion.z;
  1816. this._w = quaternion.w;
  1817. this._onChangeCallback();
  1818. return this;
  1819. };
  1820. _proto.setFromEuler = function setFromEuler(euler, update) {
  1821. if (!(euler && euler.isEuler)) {
  1822. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  1823. }
  1824. var x = euler._x,
  1825. y = euler._y,
  1826. z = euler._z,
  1827. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  1828. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1829. // content/SpinCalc.m
  1830. var cos = Math.cos;
  1831. var sin = Math.sin;
  1832. var c1 = cos(x / 2);
  1833. var c2 = cos(y / 2);
  1834. var c3 = cos(z / 2);
  1835. var s1 = sin(x / 2);
  1836. var s2 = sin(y / 2);
  1837. var s3 = sin(z / 2);
  1838. switch (order) {
  1839. case 'XYZ':
  1840. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1841. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1842. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1843. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1844. break;
  1845. case 'YXZ':
  1846. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1847. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1848. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1849. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1850. break;
  1851. case 'ZXY':
  1852. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1853. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1854. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1855. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1856. break;
  1857. case 'ZYX':
  1858. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1859. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1860. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1861. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1862. break;
  1863. case 'YZX':
  1864. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1865. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1866. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1867. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1868. break;
  1869. case 'XZY':
  1870. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1871. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1872. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1873. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1874. break;
  1875. default:
  1876. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  1877. }
  1878. if (update !== false) this._onChangeCallback();
  1879. return this;
  1880. };
  1881. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  1882. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1883. // assumes axis is normalized
  1884. var halfAngle = angle / 2,
  1885. s = Math.sin(halfAngle);
  1886. this._x = axis.x * s;
  1887. this._y = axis.y * s;
  1888. this._z = axis.z * s;
  1889. this._w = Math.cos(halfAngle);
  1890. this._onChangeCallback();
  1891. return this;
  1892. };
  1893. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  1894. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1895. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1896. var te = m.elements,
  1897. m11 = te[0],
  1898. m12 = te[4],
  1899. m13 = te[8],
  1900. m21 = te[1],
  1901. m22 = te[5],
  1902. m23 = te[9],
  1903. m31 = te[2],
  1904. m32 = te[6],
  1905. m33 = te[10],
  1906. trace = m11 + m22 + m33;
  1907. if (trace > 0) {
  1908. var s = 0.5 / Math.sqrt(trace + 1.0);
  1909. this._w = 0.25 / s;
  1910. this._x = (m32 - m23) * s;
  1911. this._y = (m13 - m31) * s;
  1912. this._z = (m21 - m12) * s;
  1913. } else if (m11 > m22 && m11 > m33) {
  1914. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  1915. this._w = (m32 - m23) / _s;
  1916. this._x = 0.25 * _s;
  1917. this._y = (m12 + m21) / _s;
  1918. this._z = (m13 + m31) / _s;
  1919. } else if (m22 > m33) {
  1920. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  1921. this._w = (m13 - m31) / _s2;
  1922. this._x = (m12 + m21) / _s2;
  1923. this._y = 0.25 * _s2;
  1924. this._z = (m23 + m32) / _s2;
  1925. } else {
  1926. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  1927. this._w = (m21 - m12) / _s3;
  1928. this._x = (m13 + m31) / _s3;
  1929. this._y = (m23 + m32) / _s3;
  1930. this._z = 0.25 * _s3;
  1931. }
  1932. this._onChangeCallback();
  1933. return this;
  1934. };
  1935. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  1936. // assumes direction vectors vFrom and vTo are normalized
  1937. var EPS = 0.000001;
  1938. var r = vFrom.dot(vTo) + 1;
  1939. if (r < EPS) {
  1940. r = 0;
  1941. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  1942. this._x = -vFrom.y;
  1943. this._y = vFrom.x;
  1944. this._z = 0;
  1945. this._w = r;
  1946. } else {
  1947. this._x = 0;
  1948. this._y = -vFrom.z;
  1949. this._z = vFrom.y;
  1950. this._w = r;
  1951. }
  1952. } else {
  1953. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1954. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1955. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1956. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1957. this._w = r;
  1958. }
  1959. return this.normalize();
  1960. };
  1961. _proto.angleTo = function angleTo(q) {
  1962. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  1963. };
  1964. _proto.rotateTowards = function rotateTowards(q, step) {
  1965. var angle = this.angleTo(q);
  1966. if (angle === 0) return this;
  1967. var t = Math.min(1, step / angle);
  1968. this.slerp(q, t);
  1969. return this;
  1970. };
  1971. _proto.identity = function identity() {
  1972. return this.set(0, 0, 0, 1);
  1973. };
  1974. _proto.inverse = function inverse() {
  1975. // quaternion is assumed to have unit length
  1976. return this.conjugate();
  1977. };
  1978. _proto.conjugate = function conjugate() {
  1979. this._x *= -1;
  1980. this._y *= -1;
  1981. this._z *= -1;
  1982. this._onChangeCallback();
  1983. return this;
  1984. };
  1985. _proto.dot = function dot(v) {
  1986. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1987. };
  1988. _proto.lengthSq = function lengthSq() {
  1989. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1990. };
  1991. _proto.length = function length() {
  1992. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  1993. };
  1994. _proto.normalize = function normalize() {
  1995. var l = this.length();
  1996. if (l === 0) {
  1997. this._x = 0;
  1998. this._y = 0;
  1999. this._z = 0;
  2000. this._w = 1;
  2001. } else {
  2002. l = 1 / l;
  2003. this._x = this._x * l;
  2004. this._y = this._y * l;
  2005. this._z = this._z * l;
  2006. this._w = this._w * l;
  2007. }
  2008. this._onChangeCallback();
  2009. return this;
  2010. };
  2011. _proto.multiply = function multiply(q, p) {
  2012. if (p !== undefined) {
  2013. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2014. return this.multiplyQuaternions(q, p);
  2015. }
  2016. return this.multiplyQuaternions(this, q);
  2017. };
  2018. _proto.premultiply = function premultiply(q) {
  2019. return this.multiplyQuaternions(q, this);
  2020. };
  2021. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2022. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2023. var qax = a._x,
  2024. qay = a._y,
  2025. qaz = a._z,
  2026. qaw = a._w;
  2027. var qbx = b._x,
  2028. qby = b._y,
  2029. qbz = b._z,
  2030. qbw = b._w;
  2031. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2032. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2033. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2034. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2035. this._onChangeCallback();
  2036. return this;
  2037. };
  2038. _proto.slerp = function slerp(qb, t) {
  2039. if (t === 0) return this;
  2040. if (t === 1) return this.copy(qb);
  2041. var x = this._x,
  2042. y = this._y,
  2043. z = this._z,
  2044. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2045. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2046. if (cosHalfTheta < 0) {
  2047. this._w = -qb._w;
  2048. this._x = -qb._x;
  2049. this._y = -qb._y;
  2050. this._z = -qb._z;
  2051. cosHalfTheta = -cosHalfTheta;
  2052. } else {
  2053. this.copy(qb);
  2054. }
  2055. if (cosHalfTheta >= 1.0) {
  2056. this._w = w;
  2057. this._x = x;
  2058. this._y = y;
  2059. this._z = z;
  2060. return this;
  2061. }
  2062. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2063. if (sqrSinHalfTheta <= Number.EPSILON) {
  2064. var s = 1 - t;
  2065. this._w = s * w + t * this._w;
  2066. this._x = s * x + t * this._x;
  2067. this._y = s * y + t * this._y;
  2068. this._z = s * z + t * this._z;
  2069. this.normalize();
  2070. this._onChangeCallback();
  2071. return this;
  2072. }
  2073. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2074. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2075. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2076. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2077. this._w = w * ratioA + this._w * ratioB;
  2078. this._x = x * ratioA + this._x * ratioB;
  2079. this._y = y * ratioA + this._y * ratioB;
  2080. this._z = z * ratioA + this._z * ratioB;
  2081. this._onChangeCallback();
  2082. return this;
  2083. };
  2084. _proto.equals = function equals(quaternion) {
  2085. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2086. };
  2087. _proto.fromArray = function fromArray(array, offset) {
  2088. if (offset === void 0) {
  2089. offset = 0;
  2090. }
  2091. this._x = array[offset];
  2092. this._y = array[offset + 1];
  2093. this._z = array[offset + 2];
  2094. this._w = array[offset + 3];
  2095. this._onChangeCallback();
  2096. return this;
  2097. };
  2098. _proto.toArray = function toArray(array, offset) {
  2099. if (array === void 0) {
  2100. array = [];
  2101. }
  2102. if (offset === void 0) {
  2103. offset = 0;
  2104. }
  2105. array[offset] = this._x;
  2106. array[offset + 1] = this._y;
  2107. array[offset + 2] = this._z;
  2108. array[offset + 3] = this._w;
  2109. return array;
  2110. };
  2111. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2112. this._x = attribute.getX(index);
  2113. this._y = attribute.getY(index);
  2114. this._z = attribute.getZ(index);
  2115. this._w = attribute.getW(index);
  2116. return this;
  2117. };
  2118. _proto._onChange = function _onChange(callback) {
  2119. this._onChangeCallback = callback;
  2120. return this;
  2121. };
  2122. _proto._onChangeCallback = function _onChangeCallback() {};
  2123. _createClass(Quaternion, [{
  2124. key: "x",
  2125. get: function get() {
  2126. return this._x;
  2127. },
  2128. set: function set(value) {
  2129. this._x = value;
  2130. this._onChangeCallback();
  2131. }
  2132. }, {
  2133. key: "y",
  2134. get: function get() {
  2135. return this._y;
  2136. },
  2137. set: function set(value) {
  2138. this._y = value;
  2139. this._onChangeCallback();
  2140. }
  2141. }, {
  2142. key: "z",
  2143. get: function get() {
  2144. return this._z;
  2145. },
  2146. set: function set(value) {
  2147. this._z = value;
  2148. this._onChangeCallback();
  2149. }
  2150. }, {
  2151. key: "w",
  2152. get: function get() {
  2153. return this._w;
  2154. },
  2155. set: function set(value) {
  2156. this._w = value;
  2157. this._onChangeCallback();
  2158. }
  2159. }]);
  2160. return Quaternion;
  2161. }();
  2162. var Vector3 = /*#__PURE__*/function () {
  2163. function Vector3(x, y, z) {
  2164. if (x === void 0) {
  2165. x = 0;
  2166. }
  2167. if (y === void 0) {
  2168. y = 0;
  2169. }
  2170. if (z === void 0) {
  2171. z = 0;
  2172. }
  2173. Object.defineProperty(this, 'isVector3', {
  2174. value: true
  2175. });
  2176. this.x = x;
  2177. this.y = y;
  2178. this.z = z;
  2179. }
  2180. var _proto = Vector3.prototype;
  2181. _proto.set = function set(x, y, z) {
  2182. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2183. this.x = x;
  2184. this.y = y;
  2185. this.z = z;
  2186. return this;
  2187. };
  2188. _proto.setScalar = function setScalar(scalar) {
  2189. this.x = scalar;
  2190. this.y = scalar;
  2191. this.z = scalar;
  2192. return this;
  2193. };
  2194. _proto.setX = function setX(x) {
  2195. this.x = x;
  2196. return this;
  2197. };
  2198. _proto.setY = function setY(y) {
  2199. this.y = y;
  2200. return this;
  2201. };
  2202. _proto.setZ = function setZ(z) {
  2203. this.z = z;
  2204. return this;
  2205. };
  2206. _proto.setComponent = function setComponent(index, value) {
  2207. switch (index) {
  2208. case 0:
  2209. this.x = value;
  2210. break;
  2211. case 1:
  2212. this.y = value;
  2213. break;
  2214. case 2:
  2215. this.z = value;
  2216. break;
  2217. default:
  2218. throw new Error('index is out of range: ' + index);
  2219. }
  2220. return this;
  2221. };
  2222. _proto.getComponent = function getComponent(index) {
  2223. switch (index) {
  2224. case 0:
  2225. return this.x;
  2226. case 1:
  2227. return this.y;
  2228. case 2:
  2229. return this.z;
  2230. default:
  2231. throw new Error('index is out of range: ' + index);
  2232. }
  2233. };
  2234. _proto.clone = function clone() {
  2235. return new this.constructor(this.x, this.y, this.z);
  2236. };
  2237. _proto.copy = function copy(v) {
  2238. this.x = v.x;
  2239. this.y = v.y;
  2240. this.z = v.z;
  2241. return this;
  2242. };
  2243. _proto.add = function add(v, w) {
  2244. if (w !== undefined) {
  2245. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2246. return this.addVectors(v, w);
  2247. }
  2248. this.x += v.x;
  2249. this.y += v.y;
  2250. this.z += v.z;
  2251. return this;
  2252. };
  2253. _proto.addScalar = function addScalar(s) {
  2254. this.x += s;
  2255. this.y += s;
  2256. this.z += s;
  2257. return this;
  2258. };
  2259. _proto.addVectors = function addVectors(a, b) {
  2260. this.x = a.x + b.x;
  2261. this.y = a.y + b.y;
  2262. this.z = a.z + b.z;
  2263. return this;
  2264. };
  2265. _proto.addScaledVector = function addScaledVector(v, s) {
  2266. this.x += v.x * s;
  2267. this.y += v.y * s;
  2268. this.z += v.z * s;
  2269. return this;
  2270. };
  2271. _proto.sub = function sub(v, w) {
  2272. if (w !== undefined) {
  2273. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2274. return this.subVectors(v, w);
  2275. }
  2276. this.x -= v.x;
  2277. this.y -= v.y;
  2278. this.z -= v.z;
  2279. return this;
  2280. };
  2281. _proto.subScalar = function subScalar(s) {
  2282. this.x -= s;
  2283. this.y -= s;
  2284. this.z -= s;
  2285. return this;
  2286. };
  2287. _proto.subVectors = function subVectors(a, b) {
  2288. this.x = a.x - b.x;
  2289. this.y = a.y - b.y;
  2290. this.z = a.z - b.z;
  2291. return this;
  2292. };
  2293. _proto.multiply = function multiply(v, w) {
  2294. if (w !== undefined) {
  2295. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  2296. return this.multiplyVectors(v, w);
  2297. }
  2298. this.x *= v.x;
  2299. this.y *= v.y;
  2300. this.z *= v.z;
  2301. return this;
  2302. };
  2303. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2304. this.x *= scalar;
  2305. this.y *= scalar;
  2306. this.z *= scalar;
  2307. return this;
  2308. };
  2309. _proto.multiplyVectors = function multiplyVectors(a, b) {
  2310. this.x = a.x * b.x;
  2311. this.y = a.y * b.y;
  2312. this.z = a.z * b.z;
  2313. return this;
  2314. };
  2315. _proto.applyEuler = function applyEuler(euler) {
  2316. if (!(euler && euler.isEuler)) {
  2317. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2318. }
  2319. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  2320. };
  2321. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  2322. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  2323. };
  2324. _proto.applyMatrix3 = function applyMatrix3(m) {
  2325. var x = this.x,
  2326. y = this.y,
  2327. z = this.z;
  2328. var e = m.elements;
  2329. this.x = e[0] * x + e[3] * y + e[6] * z;
  2330. this.y = e[1] * x + e[4] * y + e[7] * z;
  2331. this.z = e[2] * x + e[5] * y + e[8] * z;
  2332. return this;
  2333. };
  2334. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  2335. return this.applyMatrix3(m).normalize();
  2336. };
  2337. _proto.applyMatrix4 = function applyMatrix4(m) {
  2338. var x = this.x,
  2339. y = this.y,
  2340. z = this.z;
  2341. var e = m.elements;
  2342. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  2343. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  2344. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  2345. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  2346. return this;
  2347. };
  2348. _proto.applyQuaternion = function applyQuaternion(q) {
  2349. var x = this.x,
  2350. y = this.y,
  2351. z = this.z;
  2352. var qx = q.x,
  2353. qy = q.y,
  2354. qz = q.z,
  2355. qw = q.w; // calculate quat * vector
  2356. var ix = qw * x + qy * z - qz * y;
  2357. var iy = qw * y + qz * x - qx * z;
  2358. var iz = qw * z + qx * y - qy * x;
  2359. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  2360. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2361. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2362. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2363. return this;
  2364. };
  2365. _proto.project = function project(camera) {
  2366. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  2367. };
  2368. _proto.unproject = function unproject(camera) {
  2369. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  2370. };
  2371. _proto.transformDirection = function transformDirection(m) {
  2372. // input: THREE.Matrix4 affine matrix
  2373. // vector interpreted as a direction
  2374. var x = this.x,
  2375. y = this.y,
  2376. z = this.z;
  2377. var e = m.elements;
  2378. this.x = e[0] * x + e[4] * y + e[8] * z;
  2379. this.y = e[1] * x + e[5] * y + e[9] * z;
  2380. this.z = e[2] * x + e[6] * y + e[10] * z;
  2381. return this.normalize();
  2382. };
  2383. _proto.divide = function divide(v) {
  2384. this.x /= v.x;
  2385. this.y /= v.y;
  2386. this.z /= v.z;
  2387. return this;
  2388. };
  2389. _proto.divideScalar = function divideScalar(scalar) {
  2390. return this.multiplyScalar(1 / scalar);
  2391. };
  2392. _proto.min = function min(v) {
  2393. this.x = Math.min(this.x, v.x);
  2394. this.y = Math.min(this.y, v.y);
  2395. this.z = Math.min(this.z, v.z);
  2396. return this;
  2397. };
  2398. _proto.max = function max(v) {
  2399. this.x = Math.max(this.x, v.x);
  2400. this.y = Math.max(this.y, v.y);
  2401. this.z = Math.max(this.z, v.z);
  2402. return this;
  2403. };
  2404. _proto.clamp = function clamp(min, max) {
  2405. // assumes min < max, componentwise
  2406. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2407. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2408. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2409. return this;
  2410. };
  2411. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2412. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2413. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2414. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2415. return this;
  2416. };
  2417. _proto.clampLength = function clampLength(min, max) {
  2418. var length = this.length();
  2419. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2420. };
  2421. _proto.floor = function floor() {
  2422. this.x = Math.floor(this.x);
  2423. this.y = Math.floor(this.y);
  2424. this.z = Math.floor(this.z);
  2425. return this;
  2426. };
  2427. _proto.ceil = function ceil() {
  2428. this.x = Math.ceil(this.x);
  2429. this.y = Math.ceil(this.y);
  2430. this.z = Math.ceil(this.z);
  2431. return this;
  2432. };
  2433. _proto.round = function round() {
  2434. this.x = Math.round(this.x);
  2435. this.y = Math.round(this.y);
  2436. this.z = Math.round(this.z);
  2437. return this;
  2438. };
  2439. _proto.roundToZero = function roundToZero() {
  2440. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2441. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2442. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2443. return this;
  2444. };
  2445. _proto.negate = function negate() {
  2446. this.x = -this.x;
  2447. this.y = -this.y;
  2448. this.z = -this.z;
  2449. return this;
  2450. };
  2451. _proto.dot = function dot(v) {
  2452. return this.x * v.x + this.y * v.y + this.z * v.z;
  2453. } // TODO lengthSquared?
  2454. ;
  2455. _proto.lengthSq = function lengthSq() {
  2456. return this.x * this.x + this.y * this.y + this.z * this.z;
  2457. };
  2458. _proto.length = function length() {
  2459. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  2460. };
  2461. _proto.manhattanLength = function manhattanLength() {
  2462. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  2463. };
  2464. _proto.normalize = function normalize() {
  2465. return this.divideScalar(this.length() || 1);
  2466. };
  2467. _proto.setLength = function setLength(length) {
  2468. return this.normalize().multiplyScalar(length);
  2469. };
  2470. _proto.lerp = function lerp(v, alpha) {
  2471. this.x += (v.x - this.x) * alpha;
  2472. this.y += (v.y - this.y) * alpha;
  2473. this.z += (v.z - this.z) * alpha;
  2474. return this;
  2475. };
  2476. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2477. this.x = v1.x + (v2.x - v1.x) * alpha;
  2478. this.y = v1.y + (v2.y - v1.y) * alpha;
  2479. this.z = v1.z + (v2.z - v1.z) * alpha;
  2480. return this;
  2481. };
  2482. _proto.cross = function cross(v, w) {
  2483. if (w !== undefined) {
  2484. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  2485. return this.crossVectors(v, w);
  2486. }
  2487. return this.crossVectors(this, v);
  2488. };
  2489. _proto.crossVectors = function crossVectors(a, b) {
  2490. var ax = a.x,
  2491. ay = a.y,
  2492. az = a.z;
  2493. var bx = b.x,
  2494. by = b.y,
  2495. bz = b.z;
  2496. this.x = ay * bz - az * by;
  2497. this.y = az * bx - ax * bz;
  2498. this.z = ax * by - ay * bx;
  2499. return this;
  2500. };
  2501. _proto.projectOnVector = function projectOnVector(v) {
  2502. var denominator = v.lengthSq();
  2503. if (denominator === 0) return this.set(0, 0, 0);
  2504. var scalar = v.dot(this) / denominator;
  2505. return this.copy(v).multiplyScalar(scalar);
  2506. };
  2507. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  2508. _vector.copy(this).projectOnVector(planeNormal);
  2509. return this.sub(_vector);
  2510. };
  2511. _proto.reflect = function reflect(normal) {
  2512. // reflect incident vector off plane orthogonal to normal
  2513. // normal is assumed to have unit length
  2514. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  2515. };
  2516. _proto.angleTo = function angleTo(v) {
  2517. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  2518. if (denominator === 0) return Math.PI / 2;
  2519. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  2520. return Math.acos(MathUtils.clamp(theta, -1, 1));
  2521. };
  2522. _proto.distanceTo = function distanceTo(v) {
  2523. return Math.sqrt(this.distanceToSquared(v));
  2524. };
  2525. _proto.distanceToSquared = function distanceToSquared(v) {
  2526. var dx = this.x - v.x,
  2527. dy = this.y - v.y,
  2528. dz = this.z - v.z;
  2529. return dx * dx + dy * dy + dz * dz;
  2530. };
  2531. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  2532. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  2533. };
  2534. _proto.setFromSpherical = function setFromSpherical(s) {
  2535. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  2536. };
  2537. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  2538. var sinPhiRadius = Math.sin(phi) * radius;
  2539. this.x = sinPhiRadius * Math.sin(theta);
  2540. this.y = Math.cos(phi) * radius;
  2541. this.z = sinPhiRadius * Math.cos(theta);
  2542. return this;
  2543. };
  2544. _proto.setFromCylindrical = function setFromCylindrical(c) {
  2545. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  2546. };
  2547. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  2548. this.x = radius * Math.sin(theta);
  2549. this.y = y;
  2550. this.z = radius * Math.cos(theta);
  2551. return this;
  2552. };
  2553. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  2554. var e = m.elements;
  2555. this.x = e[12];
  2556. this.y = e[13];
  2557. this.z = e[14];
  2558. return this;
  2559. };
  2560. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  2561. var sx = this.setFromMatrixColumn(m, 0).length();
  2562. var sy = this.setFromMatrixColumn(m, 1).length();
  2563. var sz = this.setFromMatrixColumn(m, 2).length();
  2564. this.x = sx;
  2565. this.y = sy;
  2566. this.z = sz;
  2567. return this;
  2568. };
  2569. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  2570. return this.fromArray(m.elements, index * 4);
  2571. };
  2572. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  2573. return this.fromArray(m.elements, index * 3);
  2574. };
  2575. _proto.equals = function equals(v) {
  2576. return v.x === this.x && v.y === this.y && v.z === this.z;
  2577. };
  2578. _proto.fromArray = function fromArray(array, offset) {
  2579. if (offset === void 0) {
  2580. offset = 0;
  2581. }
  2582. this.x = array[offset];
  2583. this.y = array[offset + 1];
  2584. this.z = array[offset + 2];
  2585. return this;
  2586. };
  2587. _proto.toArray = function toArray(array, offset) {
  2588. if (array === void 0) {
  2589. array = [];
  2590. }
  2591. if (offset === void 0) {
  2592. offset = 0;
  2593. }
  2594. array[offset] = this.x;
  2595. array[offset + 1] = this.y;
  2596. array[offset + 2] = this.z;
  2597. return array;
  2598. };
  2599. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2600. if (offset !== undefined) {
  2601. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  2602. }
  2603. this.x = attribute.getX(index);
  2604. this.y = attribute.getY(index);
  2605. this.z = attribute.getZ(index);
  2606. return this;
  2607. };
  2608. _proto.random = function random() {
  2609. this.x = Math.random();
  2610. this.y = Math.random();
  2611. this.z = Math.random();
  2612. return this;
  2613. };
  2614. return Vector3;
  2615. }();
  2616. var _vector = /*@__PURE__*/new Vector3();
  2617. var _quaternion = /*@__PURE__*/new Quaternion();
  2618. var Box3 = /*#__PURE__*/function () {
  2619. function Box3(min, max) {
  2620. Object.defineProperty(this, 'isBox3', {
  2621. value: true
  2622. });
  2623. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  2624. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  2625. }
  2626. var _proto = Box3.prototype;
  2627. _proto.set = function set(min, max) {
  2628. this.min.copy(min);
  2629. this.max.copy(max);
  2630. return this;
  2631. };
  2632. _proto.setFromArray = function setFromArray(array) {
  2633. var minX = +Infinity;
  2634. var minY = +Infinity;
  2635. var minZ = +Infinity;
  2636. var maxX = -Infinity;
  2637. var maxY = -Infinity;
  2638. var maxZ = -Infinity;
  2639. for (var i = 0, l = array.length; i < l; i += 3) {
  2640. var x = array[i];
  2641. var y = array[i + 1];
  2642. var z = array[i + 2];
  2643. if (x < minX) minX = x;
  2644. if (y < minY) minY = y;
  2645. if (z < minZ) minZ = z;
  2646. if (x > maxX) maxX = x;
  2647. if (y > maxY) maxY = y;
  2648. if (z > maxZ) maxZ = z;
  2649. }
  2650. this.min.set(minX, minY, minZ);
  2651. this.max.set(maxX, maxY, maxZ);
  2652. return this;
  2653. };
  2654. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  2655. var minX = +Infinity;
  2656. var minY = +Infinity;
  2657. var minZ = +Infinity;
  2658. var maxX = -Infinity;
  2659. var maxY = -Infinity;
  2660. var maxZ = -Infinity;
  2661. for (var i = 0, l = attribute.count; i < l; i++) {
  2662. var x = attribute.getX(i);
  2663. var y = attribute.getY(i);
  2664. var z = attribute.getZ(i);
  2665. if (x < minX) minX = x;
  2666. if (y < minY) minY = y;
  2667. if (z < minZ) minZ = z;
  2668. if (x > maxX) maxX = x;
  2669. if (y > maxY) maxY = y;
  2670. if (z > maxZ) maxZ = z;
  2671. }
  2672. this.min.set(minX, minY, minZ);
  2673. this.max.set(maxX, maxY, maxZ);
  2674. return this;
  2675. };
  2676. _proto.setFromPoints = function setFromPoints(points) {
  2677. this.makeEmpty();
  2678. for (var i = 0, il = points.length; i < il; i++) {
  2679. this.expandByPoint(points[i]);
  2680. }
  2681. return this;
  2682. };
  2683. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  2684. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  2685. this.min.copy(center).sub(halfSize);
  2686. this.max.copy(center).add(halfSize);
  2687. return this;
  2688. };
  2689. _proto.setFromObject = function setFromObject(object) {
  2690. this.makeEmpty();
  2691. return this.expandByObject(object);
  2692. };
  2693. _proto.clone = function clone() {
  2694. return new this.constructor().copy(this);
  2695. };
  2696. _proto.copy = function copy(box) {
  2697. this.min.copy(box.min);
  2698. this.max.copy(box.max);
  2699. return this;
  2700. };
  2701. _proto.makeEmpty = function makeEmpty() {
  2702. this.min.x = this.min.y = this.min.z = +Infinity;
  2703. this.max.x = this.max.y = this.max.z = -Infinity;
  2704. return this;
  2705. };
  2706. _proto.isEmpty = function isEmpty() {
  2707. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2708. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  2709. };
  2710. _proto.getCenter = function getCenter(target) {
  2711. if (target === undefined) {
  2712. console.warn('THREE.Box3: .getCenter() target is now required');
  2713. target = new Vector3();
  2714. }
  2715. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  2716. };
  2717. _proto.getSize = function getSize(target) {
  2718. if (target === undefined) {
  2719. console.warn('THREE.Box3: .getSize() target is now required');
  2720. target = new Vector3();
  2721. }
  2722. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  2723. };
  2724. _proto.expandByPoint = function expandByPoint(point) {
  2725. this.min.min(point);
  2726. this.max.max(point);
  2727. return this;
  2728. };
  2729. _proto.expandByVector = function expandByVector(vector) {
  2730. this.min.sub(vector);
  2731. this.max.add(vector);
  2732. return this;
  2733. };
  2734. _proto.expandByScalar = function expandByScalar(scalar) {
  2735. this.min.addScalar(-scalar);
  2736. this.max.addScalar(scalar);
  2737. return this;
  2738. };
  2739. _proto.expandByObject = function expandByObject(object) {
  2740. // Computes the world-axis-aligned bounding box of an object (including its children),
  2741. // accounting for both the object's, and children's, world transforms
  2742. object.updateWorldMatrix(false, false);
  2743. var geometry = object.geometry;
  2744. if (geometry !== undefined) {
  2745. if (geometry.boundingBox === null) {
  2746. geometry.computeBoundingBox();
  2747. }
  2748. _box.copy(geometry.boundingBox);
  2749. _box.applyMatrix4(object.matrixWorld);
  2750. this.union(_box);
  2751. }
  2752. var children = object.children;
  2753. for (var i = 0, l = children.length; i < l; i++) {
  2754. this.expandByObject(children[i]);
  2755. }
  2756. return this;
  2757. };
  2758. _proto.containsPoint = function containsPoint(point) {
  2759. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  2760. };
  2761. _proto.containsBox = function containsBox(box) {
  2762. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  2763. };
  2764. _proto.getParameter = function getParameter(point, target) {
  2765. // This can potentially have a divide by zero if the box
  2766. // has a size dimension of 0.
  2767. if (target === undefined) {
  2768. console.warn('THREE.Box3: .getParameter() target is now required');
  2769. target = new Vector3();
  2770. }
  2771. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  2772. };
  2773. _proto.intersectsBox = function intersectsBox(box) {
  2774. // using 6 splitting planes to rule out intersections.
  2775. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2776. };
  2777. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2778. // Find the point on the AABB closest to the sphere center.
  2779. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  2780. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  2781. };
  2782. _proto.intersectsPlane = function intersectsPlane(plane) {
  2783. // We compute the minimum and maximum dot product values. If those values
  2784. // are on the same side (back or front) of the plane, then there is no intersection.
  2785. var min, max;
  2786. if (plane.normal.x > 0) {
  2787. min = plane.normal.x * this.min.x;
  2788. max = plane.normal.x * this.max.x;
  2789. } else {
  2790. min = plane.normal.x * this.max.x;
  2791. max = plane.normal.x * this.min.x;
  2792. }
  2793. if (plane.normal.y > 0) {
  2794. min += plane.normal.y * this.min.y;
  2795. max += plane.normal.y * this.max.y;
  2796. } else {
  2797. min += plane.normal.y * this.max.y;
  2798. max += plane.normal.y * this.min.y;
  2799. }
  2800. if (plane.normal.z > 0) {
  2801. min += plane.normal.z * this.min.z;
  2802. max += plane.normal.z * this.max.z;
  2803. } else {
  2804. min += plane.normal.z * this.max.z;
  2805. max += plane.normal.z * this.min.z;
  2806. }
  2807. return min <= -plane.constant && max >= -plane.constant;
  2808. };
  2809. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  2810. if (this.isEmpty()) {
  2811. return false;
  2812. } // compute box center and extents
  2813. this.getCenter(_center);
  2814. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  2815. _v0.subVectors(triangle.a, _center);
  2816. _v1.subVectors(triangle.b, _center);
  2817. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  2818. _f0.subVectors(_v1, _v0);
  2819. _f1.subVectors(_v2, _v1);
  2820. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2821. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  2822. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2823. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  2824. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2825. return false;
  2826. } // test 3 face normals from the aabb
  2827. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  2828. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  2829. return false;
  2830. } // finally testing the face normal of the triangle
  2831. // use already existing triangle edge vectors here
  2832. _triangleNormal.crossVectors(_f0, _f1);
  2833. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  2834. return satForAxes(axes, _v0, _v1, _v2, _extents);
  2835. };
  2836. _proto.clampPoint = function clampPoint(point, target) {
  2837. if (target === undefined) {
  2838. console.warn('THREE.Box3: .clampPoint() target is now required');
  2839. target = new Vector3();
  2840. }
  2841. return target.copy(point).clamp(this.min, this.max);
  2842. };
  2843. _proto.distanceToPoint = function distanceToPoint(point) {
  2844. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  2845. return clampedPoint.sub(point).length();
  2846. };
  2847. _proto.getBoundingSphere = function getBoundingSphere(target) {
  2848. if (target === undefined) {
  2849. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  2850. }
  2851. this.getCenter(target.center);
  2852. target.radius = this.getSize(_vector$1).length() * 0.5;
  2853. return target;
  2854. };
  2855. _proto.intersect = function intersect(box) {
  2856. this.min.max(box.min);
  2857. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  2858. if (this.isEmpty()) this.makeEmpty();
  2859. return this;
  2860. };
  2861. _proto.union = function union(box) {
  2862. this.min.min(box.min);
  2863. this.max.max(box.max);
  2864. return this;
  2865. };
  2866. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  2867. // transform of empty box is an empty box.
  2868. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2869. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  2870. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  2871. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  2872. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  2873. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  2874. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  2875. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  2876. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  2877. this.setFromPoints(_points);
  2878. return this;
  2879. };
  2880. _proto.translate = function translate(offset) {
  2881. this.min.add(offset);
  2882. this.max.add(offset);
  2883. return this;
  2884. };
  2885. _proto.equals = function equals(box) {
  2886. return box.min.equals(this.min) && box.max.equals(this.max);
  2887. };
  2888. return Box3;
  2889. }();
  2890. function satForAxes(axes, v0, v1, v2, extents) {
  2891. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  2892. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  2893. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  2894. var p0 = v0.dot(_testAxis);
  2895. var p1 = v1.dot(_testAxis);
  2896. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  2897. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  2898. // points of the projected triangle are outside the projected half-length of the aabb
  2899. // the axis is seperating and we can exit
  2900. return false;
  2901. }
  2902. }
  2903. return true;
  2904. }
  2905. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  2906. var _vector$1 = /*@__PURE__*/new Vector3();
  2907. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  2908. var _v0 = /*@__PURE__*/new Vector3();
  2909. var _v1 = /*@__PURE__*/new Vector3();
  2910. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  2911. var _f0 = /*@__PURE__*/new Vector3();
  2912. var _f1 = /*@__PURE__*/new Vector3();
  2913. var _f2 = /*@__PURE__*/new Vector3();
  2914. var _center = /*@__PURE__*/new Vector3();
  2915. var _extents = /*@__PURE__*/new Vector3();
  2916. var _triangleNormal = /*@__PURE__*/new Vector3();
  2917. var _testAxis = /*@__PURE__*/new Vector3();
  2918. var _box$1 = /*@__PURE__*/new Box3();
  2919. var Sphere = /*#__PURE__*/function () {
  2920. function Sphere(center, radius) {
  2921. this.center = center !== undefined ? center : new Vector3();
  2922. this.radius = radius !== undefined ? radius : -1;
  2923. }
  2924. var _proto = Sphere.prototype;
  2925. _proto.set = function set(center, radius) {
  2926. this.center.copy(center);
  2927. this.radius = radius;
  2928. return this;
  2929. };
  2930. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  2931. var center = this.center;
  2932. if (optionalCenter !== undefined) {
  2933. center.copy(optionalCenter);
  2934. } else {
  2935. _box$1.setFromPoints(points).getCenter(center);
  2936. }
  2937. var maxRadiusSq = 0;
  2938. for (var i = 0, il = points.length; i < il; i++) {
  2939. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  2940. }
  2941. this.radius = Math.sqrt(maxRadiusSq);
  2942. return this;
  2943. };
  2944. _proto.clone = function clone() {
  2945. return new this.constructor().copy(this);
  2946. };
  2947. _proto.copy = function copy(sphere) {
  2948. this.center.copy(sphere.center);
  2949. this.radius = sphere.radius;
  2950. return this;
  2951. };
  2952. _proto.isEmpty = function isEmpty() {
  2953. return this.radius < 0;
  2954. };
  2955. _proto.makeEmpty = function makeEmpty() {
  2956. this.center.set(0, 0, 0);
  2957. this.radius = -1;
  2958. return this;
  2959. };
  2960. _proto.containsPoint = function containsPoint(point) {
  2961. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  2962. };
  2963. _proto.distanceToPoint = function distanceToPoint(point) {
  2964. return point.distanceTo(this.center) - this.radius;
  2965. };
  2966. _proto.intersectsSphere = function intersectsSphere(sphere) {
  2967. var radiusSum = this.radius + sphere.radius;
  2968. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  2969. };
  2970. _proto.intersectsBox = function intersectsBox(box) {
  2971. return box.intersectsSphere(this);
  2972. };
  2973. _proto.intersectsPlane = function intersectsPlane(plane) {
  2974. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  2975. };
  2976. _proto.clampPoint = function clampPoint(point, target) {
  2977. var deltaLengthSq = this.center.distanceToSquared(point);
  2978. if (target === undefined) {
  2979. console.warn('THREE.Sphere: .clampPoint() target is now required');
  2980. target = new Vector3();
  2981. }
  2982. target.copy(point);
  2983. if (deltaLengthSq > this.radius * this.radius) {
  2984. target.sub(this.center).normalize();
  2985. target.multiplyScalar(this.radius).add(this.center);
  2986. }
  2987. return target;
  2988. };
  2989. _proto.getBoundingBox = function getBoundingBox(target) {
  2990. if (target === undefined) {
  2991. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  2992. target = new Box3();
  2993. }
  2994. if (this.isEmpty()) {
  2995. // Empty sphere produces empty bounding box
  2996. target.makeEmpty();
  2997. return target;
  2998. }
  2999. target.set(this.center, this.center);
  3000. target.expandByScalar(this.radius);
  3001. return target;
  3002. };
  3003. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3004. this.center.applyMatrix4(matrix);
  3005. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3006. return this;
  3007. };
  3008. _proto.translate = function translate(offset) {
  3009. this.center.add(offset);
  3010. return this;
  3011. };
  3012. _proto.equals = function equals(sphere) {
  3013. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3014. };
  3015. return Sphere;
  3016. }();
  3017. var _vector$2 = /*@__PURE__*/new Vector3();
  3018. var _segCenter = /*@__PURE__*/new Vector3();
  3019. var _segDir = /*@__PURE__*/new Vector3();
  3020. var _diff = /*@__PURE__*/new Vector3();
  3021. var _edge1 = /*@__PURE__*/new Vector3();
  3022. var _edge2 = /*@__PURE__*/new Vector3();
  3023. var _normal = /*@__PURE__*/new Vector3();
  3024. var Ray = /*#__PURE__*/function () {
  3025. function Ray(origin, direction) {
  3026. this.origin = origin !== undefined ? origin : new Vector3();
  3027. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3028. }
  3029. var _proto = Ray.prototype;
  3030. _proto.set = function set(origin, direction) {
  3031. this.origin.copy(origin);
  3032. this.direction.copy(direction);
  3033. return this;
  3034. };
  3035. _proto.clone = function clone() {
  3036. return new this.constructor().copy(this);
  3037. };
  3038. _proto.copy = function copy(ray) {
  3039. this.origin.copy(ray.origin);
  3040. this.direction.copy(ray.direction);
  3041. return this;
  3042. };
  3043. _proto.at = function at(t, target) {
  3044. if (target === undefined) {
  3045. console.warn('THREE.Ray: .at() target is now required');
  3046. target = new Vector3();
  3047. }
  3048. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3049. };
  3050. _proto.lookAt = function lookAt(v) {
  3051. this.direction.copy(v).sub(this.origin).normalize();
  3052. return this;
  3053. };
  3054. _proto.recast = function recast(t) {
  3055. this.origin.copy(this.at(t, _vector$2));
  3056. return this;
  3057. };
  3058. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3059. if (target === undefined) {
  3060. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3061. target = new Vector3();
  3062. }
  3063. target.subVectors(point, this.origin);
  3064. var directionDistance = target.dot(this.direction);
  3065. if (directionDistance < 0) {
  3066. return target.copy(this.origin);
  3067. }
  3068. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3069. };
  3070. _proto.distanceToPoint = function distanceToPoint(point) {
  3071. return Math.sqrt(this.distanceSqToPoint(point));
  3072. };
  3073. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3074. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3075. if (directionDistance < 0) {
  3076. return this.origin.distanceToSquared(point);
  3077. }
  3078. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3079. return _vector$2.distanceToSquared(point);
  3080. };
  3081. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3082. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3083. // It returns the min distance between the ray and the segment
  3084. // defined by v0 and v1
  3085. // It can also set two optional targets :
  3086. // - The closest point on the ray
  3087. // - The closest point on the segment
  3088. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3089. _segDir.copy(v1).sub(v0).normalize();
  3090. _diff.copy(this.origin).sub(_segCenter);
  3091. var segExtent = v0.distanceTo(v1) * 0.5;
  3092. var a01 = -this.direction.dot(_segDir);
  3093. var b0 = _diff.dot(this.direction);
  3094. var b1 = -_diff.dot(_segDir);
  3095. var c = _diff.lengthSq();
  3096. var det = Math.abs(1 - a01 * a01);
  3097. var s0, s1, sqrDist, extDet;
  3098. if (det > 0) {
  3099. // The ray and segment are not parallel.
  3100. s0 = a01 * b1 - b0;
  3101. s1 = a01 * b0 - b1;
  3102. extDet = segExtent * det;
  3103. if (s0 >= 0) {
  3104. if (s1 >= -extDet) {
  3105. if (s1 <= extDet) {
  3106. // region 0
  3107. // Minimum at interior points of ray and segment.
  3108. var invDet = 1 / det;
  3109. s0 *= invDet;
  3110. s1 *= invDet;
  3111. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3112. } else {
  3113. // region 1
  3114. s1 = segExtent;
  3115. s0 = Math.max(0, -(a01 * s1 + b0));
  3116. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3117. }
  3118. } else {
  3119. // region 5
  3120. s1 = -segExtent;
  3121. s0 = Math.max(0, -(a01 * s1 + b0));
  3122. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3123. }
  3124. } else {
  3125. if (s1 <= -extDet) {
  3126. // region 4
  3127. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3128. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3129. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3130. } else if (s1 <= extDet) {
  3131. // region 3
  3132. s0 = 0;
  3133. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3134. sqrDist = s1 * (s1 + 2 * b1) + c;
  3135. } else {
  3136. // region 2
  3137. s0 = Math.max(0, -(a01 * segExtent + b0));
  3138. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3139. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3140. }
  3141. }
  3142. } else {
  3143. // Ray and segment are parallel.
  3144. s1 = a01 > 0 ? -segExtent : segExtent;
  3145. s0 = Math.max(0, -(a01 * s1 + b0));
  3146. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3147. }
  3148. if (optionalPointOnRay) {
  3149. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3150. }
  3151. if (optionalPointOnSegment) {
  3152. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3153. }
  3154. return sqrDist;
  3155. };
  3156. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3157. _vector$2.subVectors(sphere.center, this.origin);
  3158. var tca = _vector$2.dot(this.direction);
  3159. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3160. var radius2 = sphere.radius * sphere.radius;
  3161. if (d2 > radius2) return null;
  3162. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3163. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3164. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3165. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3166. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3167. // in order to always return an intersect point that is in front of the ray.
  3168. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3169. return this.at(t0, target);
  3170. };
  3171. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3172. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3173. };
  3174. _proto.distanceToPlane = function distanceToPlane(plane) {
  3175. var denominator = plane.normal.dot(this.direction);
  3176. if (denominator === 0) {
  3177. // line is coplanar, return origin
  3178. if (plane.distanceToPoint(this.origin) === 0) {
  3179. return 0;
  3180. } // Null is preferable to undefined since undefined means.... it is undefined
  3181. return null;
  3182. }
  3183. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3184. return t >= 0 ? t : null;
  3185. };
  3186. _proto.intersectPlane = function intersectPlane(plane, target) {
  3187. var t = this.distanceToPlane(plane);
  3188. if (t === null) {
  3189. return null;
  3190. }
  3191. return this.at(t, target);
  3192. };
  3193. _proto.intersectsPlane = function intersectsPlane(plane) {
  3194. // check if the ray lies on the plane first
  3195. var distToPoint = plane.distanceToPoint(this.origin);
  3196. if (distToPoint === 0) {
  3197. return true;
  3198. }
  3199. var denominator = plane.normal.dot(this.direction);
  3200. if (denominator * distToPoint < 0) {
  3201. return true;
  3202. } // ray origin is behind the plane (and is pointing behind it)
  3203. return false;
  3204. };
  3205. _proto.intersectBox = function intersectBox(box, target) {
  3206. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3207. var invdirx = 1 / this.direction.x,
  3208. invdiry = 1 / this.direction.y,
  3209. invdirz = 1 / this.direction.z;
  3210. var origin = this.origin;
  3211. if (invdirx >= 0) {
  3212. tmin = (box.min.x - origin.x) * invdirx;
  3213. tmax = (box.max.x - origin.x) * invdirx;
  3214. } else {
  3215. tmin = (box.max.x - origin.x) * invdirx;
  3216. tmax = (box.min.x - origin.x) * invdirx;
  3217. }
  3218. if (invdiry >= 0) {
  3219. tymin = (box.min.y - origin.y) * invdiry;
  3220. tymax = (box.max.y - origin.y) * invdiry;
  3221. } else {
  3222. tymin = (box.max.y - origin.y) * invdiry;
  3223. tymax = (box.min.y - origin.y) * invdiry;
  3224. }
  3225. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3226. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3227. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3228. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3229. if (invdirz >= 0) {
  3230. tzmin = (box.min.z - origin.z) * invdirz;
  3231. tzmax = (box.max.z - origin.z) * invdirz;
  3232. } else {
  3233. tzmin = (box.max.z - origin.z) * invdirz;
  3234. tzmax = (box.min.z - origin.z) * invdirz;
  3235. }
  3236. if (tmin > tzmax || tzmin > tmax) return null;
  3237. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3238. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3239. if (tmax < 0) return null;
  3240. return this.at(tmin >= 0 ? tmin : tmax, target);
  3241. };
  3242. _proto.intersectsBox = function intersectsBox(box) {
  3243. return this.intersectBox(box, _vector$2) !== null;
  3244. };
  3245. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3246. // Compute the offset origin, edges, and normal.
  3247. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3248. _edge1.subVectors(b, a);
  3249. _edge2.subVectors(c, a);
  3250. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3251. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3252. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3253. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3254. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3255. var DdN = this.direction.dot(_normal);
  3256. var sign;
  3257. if (DdN > 0) {
  3258. if (backfaceCulling) return null;
  3259. sign = 1;
  3260. } else if (DdN < 0) {
  3261. sign = -1;
  3262. DdN = -DdN;
  3263. } else {
  3264. return null;
  3265. }
  3266. _diff.subVectors(this.origin, a);
  3267. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  3268. if (DdQxE2 < 0) {
  3269. return null;
  3270. }
  3271. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  3272. if (DdE1xQ < 0) {
  3273. return null;
  3274. } // b1+b2 > 1, no intersection
  3275. if (DdQxE2 + DdE1xQ > DdN) {
  3276. return null;
  3277. } // Line intersects triangle, check if ray does.
  3278. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  3279. if (QdN < 0) {
  3280. return null;
  3281. } // Ray intersects triangle.
  3282. return this.at(QdN / DdN, target);
  3283. };
  3284. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  3285. this.origin.applyMatrix4(matrix4);
  3286. this.direction.transformDirection(matrix4);
  3287. return this;
  3288. };
  3289. _proto.equals = function equals(ray) {
  3290. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  3291. };
  3292. return Ray;
  3293. }();
  3294. var Matrix4 = /*#__PURE__*/function () {
  3295. function Matrix4() {
  3296. Object.defineProperty(this, 'isMatrix4', {
  3297. value: true
  3298. });
  3299. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3300. if (arguments.length > 0) {
  3301. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  3302. }
  3303. }
  3304. var _proto = Matrix4.prototype;
  3305. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  3306. var te = this.elements;
  3307. te[0] = n11;
  3308. te[4] = n12;
  3309. te[8] = n13;
  3310. te[12] = n14;
  3311. te[1] = n21;
  3312. te[5] = n22;
  3313. te[9] = n23;
  3314. te[13] = n24;
  3315. te[2] = n31;
  3316. te[6] = n32;
  3317. te[10] = n33;
  3318. te[14] = n34;
  3319. te[3] = n41;
  3320. te[7] = n42;
  3321. te[11] = n43;
  3322. te[15] = n44;
  3323. return this;
  3324. };
  3325. _proto.identity = function identity() {
  3326. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3327. return this;
  3328. };
  3329. _proto.clone = function clone() {
  3330. return new Matrix4().fromArray(this.elements);
  3331. };
  3332. _proto.copy = function copy(m) {
  3333. var te = this.elements;
  3334. var me = m.elements;
  3335. te[0] = me[0];
  3336. te[1] = me[1];
  3337. te[2] = me[2];
  3338. te[3] = me[3];
  3339. te[4] = me[4];
  3340. te[5] = me[5];
  3341. te[6] = me[6];
  3342. te[7] = me[7];
  3343. te[8] = me[8];
  3344. te[9] = me[9];
  3345. te[10] = me[10];
  3346. te[11] = me[11];
  3347. te[12] = me[12];
  3348. te[13] = me[13];
  3349. te[14] = me[14];
  3350. te[15] = me[15];
  3351. return this;
  3352. };
  3353. _proto.copyPosition = function copyPosition(m) {
  3354. var te = this.elements,
  3355. me = m.elements;
  3356. te[12] = me[12];
  3357. te[13] = me[13];
  3358. te[14] = me[14];
  3359. return this;
  3360. };
  3361. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  3362. xAxis.setFromMatrixColumn(this, 0);
  3363. yAxis.setFromMatrixColumn(this, 1);
  3364. zAxis.setFromMatrixColumn(this, 2);
  3365. return this;
  3366. };
  3367. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  3368. this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
  3369. return this;
  3370. };
  3371. _proto.extractRotation = function extractRotation(m) {
  3372. // this method does not support reflection matrices
  3373. var te = this.elements;
  3374. var me = m.elements;
  3375. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  3376. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  3377. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  3378. te[0] = me[0] * scaleX;
  3379. te[1] = me[1] * scaleX;
  3380. te[2] = me[2] * scaleX;
  3381. te[3] = 0;
  3382. te[4] = me[4] * scaleY;
  3383. te[5] = me[5] * scaleY;
  3384. te[6] = me[6] * scaleY;
  3385. te[7] = 0;
  3386. te[8] = me[8] * scaleZ;
  3387. te[9] = me[9] * scaleZ;
  3388. te[10] = me[10] * scaleZ;
  3389. te[11] = 0;
  3390. te[12] = 0;
  3391. te[13] = 0;
  3392. te[14] = 0;
  3393. te[15] = 1;
  3394. return this;
  3395. };
  3396. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  3397. if (!(euler && euler.isEuler)) {
  3398. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  3399. }
  3400. var te = this.elements;
  3401. var x = euler.x,
  3402. y = euler.y,
  3403. z = euler.z;
  3404. var a = Math.cos(x),
  3405. b = Math.sin(x);
  3406. var c = Math.cos(y),
  3407. d = Math.sin(y);
  3408. var e = Math.cos(z),
  3409. f = Math.sin(z);
  3410. if (euler.order === 'XYZ') {
  3411. var ae = a * e,
  3412. af = a * f,
  3413. be = b * e,
  3414. bf = b * f;
  3415. te[0] = c * e;
  3416. te[4] = -c * f;
  3417. te[8] = d;
  3418. te[1] = af + be * d;
  3419. te[5] = ae - bf * d;
  3420. te[9] = -b * c;
  3421. te[2] = bf - ae * d;
  3422. te[6] = be + af * d;
  3423. te[10] = a * c;
  3424. } else if (euler.order === 'YXZ') {
  3425. var ce = c * e,
  3426. cf = c * f,
  3427. de = d * e,
  3428. df = d * f;
  3429. te[0] = ce + df * b;
  3430. te[4] = de * b - cf;
  3431. te[8] = a * d;
  3432. te[1] = a * f;
  3433. te[5] = a * e;
  3434. te[9] = -b;
  3435. te[2] = cf * b - de;
  3436. te[6] = df + ce * b;
  3437. te[10] = a * c;
  3438. } else if (euler.order === 'ZXY') {
  3439. var _ce = c * e,
  3440. _cf = c * f,
  3441. _de = d * e,
  3442. _df = d * f;
  3443. te[0] = _ce - _df * b;
  3444. te[4] = -a * f;
  3445. te[8] = _de + _cf * b;
  3446. te[1] = _cf + _de * b;
  3447. te[5] = a * e;
  3448. te[9] = _df - _ce * b;
  3449. te[2] = -a * d;
  3450. te[6] = b;
  3451. te[10] = a * c;
  3452. } else if (euler.order === 'ZYX') {
  3453. var _ae = a * e,
  3454. _af = a * f,
  3455. _be = b * e,
  3456. _bf = b * f;
  3457. te[0] = c * e;
  3458. te[4] = _be * d - _af;
  3459. te[8] = _ae * d + _bf;
  3460. te[1] = c * f;
  3461. te[5] = _bf * d + _ae;
  3462. te[9] = _af * d - _be;
  3463. te[2] = -d;
  3464. te[6] = b * c;
  3465. te[10] = a * c;
  3466. } else if (euler.order === 'YZX') {
  3467. var ac = a * c,
  3468. ad = a * d,
  3469. bc = b * c,
  3470. bd = b * d;
  3471. te[0] = c * e;
  3472. te[4] = bd - ac * f;
  3473. te[8] = bc * f + ad;
  3474. te[1] = f;
  3475. te[5] = a * e;
  3476. te[9] = -b * e;
  3477. te[2] = -d * e;
  3478. te[6] = ad * f + bc;
  3479. te[10] = ac - bd * f;
  3480. } else if (euler.order === 'XZY') {
  3481. var _ac = a * c,
  3482. _ad = a * d,
  3483. _bc = b * c,
  3484. _bd = b * d;
  3485. te[0] = c * e;
  3486. te[4] = -f;
  3487. te[8] = d * e;
  3488. te[1] = _ac * f + _bd;
  3489. te[5] = a * e;
  3490. te[9] = _ad * f - _bc;
  3491. te[2] = _bc * f - _ad;
  3492. te[6] = b * e;
  3493. te[10] = _bd * f + _ac;
  3494. } // bottom row
  3495. te[3] = 0;
  3496. te[7] = 0;
  3497. te[11] = 0; // last column
  3498. te[12] = 0;
  3499. te[13] = 0;
  3500. te[14] = 0;
  3501. te[15] = 1;
  3502. return this;
  3503. };
  3504. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  3505. return this.compose(_zero, q, _one);
  3506. };
  3507. _proto.lookAt = function lookAt(eye, target, up) {
  3508. var te = this.elements;
  3509. _z.subVectors(eye, target);
  3510. if (_z.lengthSq() === 0) {
  3511. // eye and target are in the same position
  3512. _z.z = 1;
  3513. }
  3514. _z.normalize();
  3515. _x.crossVectors(up, _z);
  3516. if (_x.lengthSq() === 0) {
  3517. // up and z are parallel
  3518. if (Math.abs(up.z) === 1) {
  3519. _z.x += 0.0001;
  3520. } else {
  3521. _z.z += 0.0001;
  3522. }
  3523. _z.normalize();
  3524. _x.crossVectors(up, _z);
  3525. }
  3526. _x.normalize();
  3527. _y.crossVectors(_z, _x);
  3528. te[0] = _x.x;
  3529. te[4] = _y.x;
  3530. te[8] = _z.x;
  3531. te[1] = _x.y;
  3532. te[5] = _y.y;
  3533. te[9] = _z.y;
  3534. te[2] = _x.z;
  3535. te[6] = _y.z;
  3536. te[10] = _z.z;
  3537. return this;
  3538. };
  3539. _proto.multiply = function multiply(m, n) {
  3540. if (n !== undefined) {
  3541. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  3542. return this.multiplyMatrices(m, n);
  3543. }
  3544. return this.multiplyMatrices(this, m);
  3545. };
  3546. _proto.premultiply = function premultiply(m) {
  3547. return this.multiplyMatrices(m, this);
  3548. };
  3549. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  3550. var ae = a.elements;
  3551. var be = b.elements;
  3552. var te = this.elements;
  3553. var a11 = ae[0],
  3554. a12 = ae[4],
  3555. a13 = ae[8],
  3556. a14 = ae[12];
  3557. var a21 = ae[1],
  3558. a22 = ae[5],
  3559. a23 = ae[9],
  3560. a24 = ae[13];
  3561. var a31 = ae[2],
  3562. a32 = ae[6],
  3563. a33 = ae[10],
  3564. a34 = ae[14];
  3565. var a41 = ae[3],
  3566. a42 = ae[7],
  3567. a43 = ae[11],
  3568. a44 = ae[15];
  3569. var b11 = be[0],
  3570. b12 = be[4],
  3571. b13 = be[8],
  3572. b14 = be[12];
  3573. var b21 = be[1],
  3574. b22 = be[5],
  3575. b23 = be[9],
  3576. b24 = be[13];
  3577. var b31 = be[2],
  3578. b32 = be[6],
  3579. b33 = be[10],
  3580. b34 = be[14];
  3581. var b41 = be[3],
  3582. b42 = be[7],
  3583. b43 = be[11],
  3584. b44 = be[15];
  3585. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3586. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3587. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3588. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3589. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3590. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3591. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3592. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3593. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3594. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3595. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3596. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3597. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3598. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3599. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3600. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3601. return this;
  3602. };
  3603. _proto.multiplyScalar = function multiplyScalar(s) {
  3604. var te = this.elements;
  3605. te[0] *= s;
  3606. te[4] *= s;
  3607. te[8] *= s;
  3608. te[12] *= s;
  3609. te[1] *= s;
  3610. te[5] *= s;
  3611. te[9] *= s;
  3612. te[13] *= s;
  3613. te[2] *= s;
  3614. te[6] *= s;
  3615. te[10] *= s;
  3616. te[14] *= s;
  3617. te[3] *= s;
  3618. te[7] *= s;
  3619. te[11] *= s;
  3620. te[15] *= s;
  3621. return this;
  3622. };
  3623. _proto.determinant = function determinant() {
  3624. var te = this.elements;
  3625. var n11 = te[0],
  3626. n12 = te[4],
  3627. n13 = te[8],
  3628. n14 = te[12];
  3629. var n21 = te[1],
  3630. n22 = te[5],
  3631. n23 = te[9],
  3632. n24 = te[13];
  3633. var n31 = te[2],
  3634. n32 = te[6],
  3635. n33 = te[10],
  3636. n34 = te[14];
  3637. var n41 = te[3],
  3638. n42 = te[7],
  3639. n43 = te[11],
  3640. n44 = te[15]; //TODO: make this more efficient
  3641. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3642. return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
  3643. };
  3644. _proto.transpose = function transpose() {
  3645. var te = this.elements;
  3646. var tmp;
  3647. tmp = te[1];
  3648. te[1] = te[4];
  3649. te[4] = tmp;
  3650. tmp = te[2];
  3651. te[2] = te[8];
  3652. te[8] = tmp;
  3653. tmp = te[6];
  3654. te[6] = te[9];
  3655. te[9] = tmp;
  3656. tmp = te[3];
  3657. te[3] = te[12];
  3658. te[12] = tmp;
  3659. tmp = te[7];
  3660. te[7] = te[13];
  3661. te[13] = tmp;
  3662. tmp = te[11];
  3663. te[11] = te[14];
  3664. te[14] = tmp;
  3665. return this;
  3666. };
  3667. _proto.setPosition = function setPosition(x, y, z) {
  3668. var te = this.elements;
  3669. if (x.isVector3) {
  3670. te[12] = x.x;
  3671. te[13] = x.y;
  3672. te[14] = x.z;
  3673. } else {
  3674. te[12] = x;
  3675. te[13] = y;
  3676. te[14] = z;
  3677. }
  3678. return this;
  3679. };
  3680. _proto.getInverse = function getInverse(m, throwOnDegenerate) {
  3681. if (throwOnDegenerate !== undefined) {
  3682. console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");
  3683. } // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3684. var te = this.elements,
  3685. me = m.elements,
  3686. n11 = me[0],
  3687. n21 = me[1],
  3688. n31 = me[2],
  3689. n41 = me[3],
  3690. n12 = me[4],
  3691. n22 = me[5],
  3692. n32 = me[6],
  3693. n42 = me[7],
  3694. n13 = me[8],
  3695. n23 = me[9],
  3696. n33 = me[10],
  3697. n43 = me[11],
  3698. n14 = me[12],
  3699. n24 = me[13],
  3700. n34 = me[14],
  3701. n44 = me[15],
  3702. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3703. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3704. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3705. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3706. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3707. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3708. var detInv = 1 / det;
  3709. te[0] = t11 * detInv;
  3710. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  3711. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  3712. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  3713. te[4] = t12 * detInv;
  3714. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  3715. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  3716. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  3717. te[8] = t13 * detInv;
  3718. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  3719. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  3720. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  3721. te[12] = t14 * detInv;
  3722. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  3723. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  3724. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  3725. return this;
  3726. };
  3727. _proto.scale = function scale(v) {
  3728. var te = this.elements;
  3729. var x = v.x,
  3730. y = v.y,
  3731. z = v.z;
  3732. te[0] *= x;
  3733. te[4] *= y;
  3734. te[8] *= z;
  3735. te[1] *= x;
  3736. te[5] *= y;
  3737. te[9] *= z;
  3738. te[2] *= x;
  3739. te[6] *= y;
  3740. te[10] *= z;
  3741. te[3] *= x;
  3742. te[7] *= y;
  3743. te[11] *= z;
  3744. return this;
  3745. };
  3746. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  3747. var te = this.elements;
  3748. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  3749. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  3750. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  3751. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  3752. };
  3753. _proto.makeTranslation = function makeTranslation(x, y, z) {
  3754. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  3755. return this;
  3756. };
  3757. _proto.makeRotationX = function makeRotationX(theta) {
  3758. var c = Math.cos(theta),
  3759. s = Math.sin(theta);
  3760. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  3761. return this;
  3762. };
  3763. _proto.makeRotationY = function makeRotationY(theta) {
  3764. var c = Math.cos(theta),
  3765. s = Math.sin(theta);
  3766. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  3767. return this;
  3768. };
  3769. _proto.makeRotationZ = function makeRotationZ(theta) {
  3770. var c = Math.cos(theta),
  3771. s = Math.sin(theta);
  3772. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  3773. return this;
  3774. };
  3775. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  3776. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3777. var c = Math.cos(angle);
  3778. var s = Math.sin(angle);
  3779. var t = 1 - c;
  3780. var x = axis.x,
  3781. y = axis.y,
  3782. z = axis.z;
  3783. var tx = t * x,
  3784. ty = t * y;
  3785. this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
  3786. return this;
  3787. };
  3788. _proto.makeScale = function makeScale(x, y, z) {
  3789. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  3790. return this;
  3791. };
  3792. _proto.makeShear = function makeShear(x, y, z) {
  3793. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  3794. return this;
  3795. };
  3796. _proto.compose = function compose(position, quaternion, scale) {
  3797. var te = this.elements;
  3798. var x = quaternion._x,
  3799. y = quaternion._y,
  3800. z = quaternion._z,
  3801. w = quaternion._w;
  3802. var x2 = x + x,
  3803. y2 = y + y,
  3804. z2 = z + z;
  3805. var xx = x * x2,
  3806. xy = x * y2,
  3807. xz = x * z2;
  3808. var yy = y * y2,
  3809. yz = y * z2,
  3810. zz = z * z2;
  3811. var wx = w * x2,
  3812. wy = w * y2,
  3813. wz = w * z2;
  3814. var sx = scale.x,
  3815. sy = scale.y,
  3816. sz = scale.z;
  3817. te[0] = (1 - (yy + zz)) * sx;
  3818. te[1] = (xy + wz) * sx;
  3819. te[2] = (xz - wy) * sx;
  3820. te[3] = 0;
  3821. te[4] = (xy - wz) * sy;
  3822. te[5] = (1 - (xx + zz)) * sy;
  3823. te[6] = (yz + wx) * sy;
  3824. te[7] = 0;
  3825. te[8] = (xz + wy) * sz;
  3826. te[9] = (yz - wx) * sz;
  3827. te[10] = (1 - (xx + yy)) * sz;
  3828. te[11] = 0;
  3829. te[12] = position.x;
  3830. te[13] = position.y;
  3831. te[14] = position.z;
  3832. te[15] = 1;
  3833. return this;
  3834. };
  3835. _proto.decompose = function decompose(position, quaternion, scale) {
  3836. var te = this.elements;
  3837. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  3838. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  3839. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  3840. var det = this.determinant();
  3841. if (det < 0) sx = -sx;
  3842. position.x = te[12];
  3843. position.y = te[13];
  3844. position.z = te[14]; // scale the rotation part
  3845. _m1.copy(this);
  3846. var invSX = 1 / sx;
  3847. var invSY = 1 / sy;
  3848. var invSZ = 1 / sz;
  3849. _m1.elements[0] *= invSX;
  3850. _m1.elements[1] *= invSX;
  3851. _m1.elements[2] *= invSX;
  3852. _m1.elements[4] *= invSY;
  3853. _m1.elements[5] *= invSY;
  3854. _m1.elements[6] *= invSY;
  3855. _m1.elements[8] *= invSZ;
  3856. _m1.elements[9] *= invSZ;
  3857. _m1.elements[10] *= invSZ;
  3858. quaternion.setFromRotationMatrix(_m1);
  3859. scale.x = sx;
  3860. scale.y = sy;
  3861. scale.z = sz;
  3862. return this;
  3863. };
  3864. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  3865. if (far === undefined) {
  3866. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  3867. }
  3868. var te = this.elements;
  3869. var x = 2 * near / (right - left);
  3870. var y = 2 * near / (top - bottom);
  3871. var a = (right + left) / (right - left);
  3872. var b = (top + bottom) / (top - bottom);
  3873. var c = -(far + near) / (far - near);
  3874. var d = -2 * far * near / (far - near);
  3875. te[0] = x;
  3876. te[4] = 0;
  3877. te[8] = a;
  3878. te[12] = 0;
  3879. te[1] = 0;
  3880. te[5] = y;
  3881. te[9] = b;
  3882. te[13] = 0;
  3883. te[2] = 0;
  3884. te[6] = 0;
  3885. te[10] = c;
  3886. te[14] = d;
  3887. te[3] = 0;
  3888. te[7] = 0;
  3889. te[11] = -1;
  3890. te[15] = 0;
  3891. return this;
  3892. };
  3893. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  3894. var te = this.elements;
  3895. var w = 1.0 / (right - left);
  3896. var h = 1.0 / (top - bottom);
  3897. var p = 1.0 / (far - near);
  3898. var x = (right + left) * w;
  3899. var y = (top + bottom) * h;
  3900. var z = (far + near) * p;
  3901. te[0] = 2 * w;
  3902. te[4] = 0;
  3903. te[8] = 0;
  3904. te[12] = -x;
  3905. te[1] = 0;
  3906. te[5] = 2 * h;
  3907. te[9] = 0;
  3908. te[13] = -y;
  3909. te[2] = 0;
  3910. te[6] = 0;
  3911. te[10] = -2 * p;
  3912. te[14] = -z;
  3913. te[3] = 0;
  3914. te[7] = 0;
  3915. te[11] = 0;
  3916. te[15] = 1;
  3917. return this;
  3918. };
  3919. _proto.equals = function equals(matrix) {
  3920. var te = this.elements;
  3921. var me = matrix.elements;
  3922. for (var i = 0; i < 16; i++) {
  3923. if (te[i] !== me[i]) return false;
  3924. }
  3925. return true;
  3926. };
  3927. _proto.fromArray = function fromArray(array, offset) {
  3928. if (offset === void 0) {
  3929. offset = 0;
  3930. }
  3931. for (var i = 0; i < 16; i++) {
  3932. this.elements[i] = array[i + offset];
  3933. }
  3934. return this;
  3935. };
  3936. _proto.toArray = function toArray(array, offset) {
  3937. if (array === void 0) {
  3938. array = [];
  3939. }
  3940. if (offset === void 0) {
  3941. offset = 0;
  3942. }
  3943. var te = this.elements;
  3944. array[offset] = te[0];
  3945. array[offset + 1] = te[1];
  3946. array[offset + 2] = te[2];
  3947. array[offset + 3] = te[3];
  3948. array[offset + 4] = te[4];
  3949. array[offset + 5] = te[5];
  3950. array[offset + 6] = te[6];
  3951. array[offset + 7] = te[7];
  3952. array[offset + 8] = te[8];
  3953. array[offset + 9] = te[9];
  3954. array[offset + 10] = te[10];
  3955. array[offset + 11] = te[11];
  3956. array[offset + 12] = te[12];
  3957. array[offset + 13] = te[13];
  3958. array[offset + 14] = te[14];
  3959. array[offset + 15] = te[15];
  3960. return array;
  3961. };
  3962. return Matrix4;
  3963. }();
  3964. var _v1$1 = /*@__PURE__*/new Vector3();
  3965. var _m1 = /*@__PURE__*/new Matrix4();
  3966. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  3967. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  3968. var _x = /*@__PURE__*/new Vector3();
  3969. var _y = /*@__PURE__*/new Vector3();
  3970. var _z = /*@__PURE__*/new Vector3();
  3971. var Euler = /*#__PURE__*/function () {
  3972. function Euler(x, y, z, order) {
  3973. if (x === void 0) {
  3974. x = 0;
  3975. }
  3976. if (y === void 0) {
  3977. y = 0;
  3978. }
  3979. if (z === void 0) {
  3980. z = 0;
  3981. }
  3982. if (order === void 0) {
  3983. order = Euler.DefaultOrder;
  3984. }
  3985. Object.defineProperty(this, 'isEuler', {
  3986. value: true
  3987. });
  3988. this._x = x;
  3989. this._y = y;
  3990. this._z = z;
  3991. this._order = order;
  3992. }
  3993. var _proto = Euler.prototype;
  3994. _proto.set = function set(x, y, z, order) {
  3995. this._x = x;
  3996. this._y = y;
  3997. this._z = z;
  3998. this._order = order || this._order;
  3999. this._onChangeCallback();
  4000. return this;
  4001. };
  4002. _proto.clone = function clone() {
  4003. return new this.constructor(this._x, this._y, this._z, this._order);
  4004. };
  4005. _proto.copy = function copy(euler) {
  4006. this._x = euler._x;
  4007. this._y = euler._y;
  4008. this._z = euler._z;
  4009. this._order = euler._order;
  4010. this._onChangeCallback();
  4011. return this;
  4012. };
  4013. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4014. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4015. var te = m.elements;
  4016. var m11 = te[0],
  4017. m12 = te[4],
  4018. m13 = te[8];
  4019. var m21 = te[1],
  4020. m22 = te[5],
  4021. m23 = te[9];
  4022. var m31 = te[2],
  4023. m32 = te[6],
  4024. m33 = te[10];
  4025. order = order || this._order;
  4026. switch (order) {
  4027. case 'XYZ':
  4028. this._y = Math.asin(clamp(m13, -1, 1));
  4029. if (Math.abs(m13) < 0.9999999) {
  4030. this._x = Math.atan2(-m23, m33);
  4031. this._z = Math.atan2(-m12, m11);
  4032. } else {
  4033. this._x = Math.atan2(m32, m22);
  4034. this._z = 0;
  4035. }
  4036. break;
  4037. case 'YXZ':
  4038. this._x = Math.asin(-clamp(m23, -1, 1));
  4039. if (Math.abs(m23) < 0.9999999) {
  4040. this._y = Math.atan2(m13, m33);
  4041. this._z = Math.atan2(m21, m22);
  4042. } else {
  4043. this._y = Math.atan2(-m31, m11);
  4044. this._z = 0;
  4045. }
  4046. break;
  4047. case 'ZXY':
  4048. this._x = Math.asin(clamp(m32, -1, 1));
  4049. if (Math.abs(m32) < 0.9999999) {
  4050. this._y = Math.atan2(-m31, m33);
  4051. this._z = Math.atan2(-m12, m22);
  4052. } else {
  4053. this._y = 0;
  4054. this._z = Math.atan2(m21, m11);
  4055. }
  4056. break;
  4057. case 'ZYX':
  4058. this._y = Math.asin(-clamp(m31, -1, 1));
  4059. if (Math.abs(m31) < 0.9999999) {
  4060. this._x = Math.atan2(m32, m33);
  4061. this._z = Math.atan2(m21, m11);
  4062. } else {
  4063. this._x = 0;
  4064. this._z = Math.atan2(-m12, m22);
  4065. }
  4066. break;
  4067. case 'YZX':
  4068. this._z = Math.asin(clamp(m21, -1, 1));
  4069. if (Math.abs(m21) < 0.9999999) {
  4070. this._x = Math.atan2(-m23, m22);
  4071. this._y = Math.atan2(-m31, m11);
  4072. } else {
  4073. this._x = 0;
  4074. this._y = Math.atan2(m13, m33);
  4075. }
  4076. break;
  4077. case 'XZY':
  4078. this._z = Math.asin(-clamp(m12, -1, 1));
  4079. if (Math.abs(m12) < 0.9999999) {
  4080. this._x = Math.atan2(m32, m22);
  4081. this._y = Math.atan2(m13, m11);
  4082. } else {
  4083. this._x = Math.atan2(-m23, m33);
  4084. this._y = 0;
  4085. }
  4086. break;
  4087. default:
  4088. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4089. }
  4090. this._order = order;
  4091. if (update !== false) this._onChangeCallback();
  4092. return this;
  4093. };
  4094. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4095. _matrix.makeRotationFromQuaternion(q);
  4096. return this.setFromRotationMatrix(_matrix, order, update);
  4097. };
  4098. _proto.setFromVector3 = function setFromVector3(v, order) {
  4099. return this.set(v.x, v.y, v.z, order || this._order);
  4100. };
  4101. _proto.reorder = function reorder(newOrder) {
  4102. // WARNING: this discards revolution information -bhouston
  4103. _quaternion$1.setFromEuler(this);
  4104. return this.setFromQuaternion(_quaternion$1, newOrder);
  4105. };
  4106. _proto.equals = function equals(euler) {
  4107. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4108. };
  4109. _proto.fromArray = function fromArray(array) {
  4110. this._x = array[0];
  4111. this._y = array[1];
  4112. this._z = array[2];
  4113. if (array[3] !== undefined) this._order = array[3];
  4114. this._onChangeCallback();
  4115. return this;
  4116. };
  4117. _proto.toArray = function toArray(array, offset) {
  4118. if (array === void 0) {
  4119. array = [];
  4120. }
  4121. if (offset === void 0) {
  4122. offset = 0;
  4123. }
  4124. array[offset] = this._x;
  4125. array[offset + 1] = this._y;
  4126. array[offset + 2] = this._z;
  4127. array[offset + 3] = this._order;
  4128. return array;
  4129. };
  4130. _proto.toVector3 = function toVector3(optionalResult) {
  4131. if (optionalResult) {
  4132. return optionalResult.set(this._x, this._y, this._z);
  4133. } else {
  4134. return new Vector3(this._x, this._y, this._z);
  4135. }
  4136. };
  4137. _proto._onChange = function _onChange(callback) {
  4138. this._onChangeCallback = callback;
  4139. return this;
  4140. };
  4141. _proto._onChangeCallback = function _onChangeCallback() {};
  4142. _createClass(Euler, [{
  4143. key: "x",
  4144. get: function get() {
  4145. return this._x;
  4146. },
  4147. set: function set(value) {
  4148. this._x = value;
  4149. this._onChangeCallback();
  4150. }
  4151. }, {
  4152. key: "y",
  4153. get: function get() {
  4154. return this._y;
  4155. },
  4156. set: function set(value) {
  4157. this._y = value;
  4158. this._onChangeCallback();
  4159. }
  4160. }, {
  4161. key: "z",
  4162. get: function get() {
  4163. return this._z;
  4164. },
  4165. set: function set(value) {
  4166. this._z = value;
  4167. this._onChangeCallback();
  4168. }
  4169. }, {
  4170. key: "order",
  4171. get: function get() {
  4172. return this._order;
  4173. },
  4174. set: function set(value) {
  4175. this._order = value;
  4176. this._onChangeCallback();
  4177. }
  4178. }]);
  4179. return Euler;
  4180. }();
  4181. Euler.DefaultOrder = 'XYZ';
  4182. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4183. var _matrix = /*@__PURE__*/new Matrix4();
  4184. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4185. var Layers = /*#__PURE__*/function () {
  4186. function Layers() {
  4187. this.mask = 1 | 0;
  4188. }
  4189. var _proto = Layers.prototype;
  4190. _proto.set = function set(channel) {
  4191. this.mask = 1 << channel | 0;
  4192. };
  4193. _proto.enable = function enable(channel) {
  4194. this.mask |= 1 << channel | 0;
  4195. };
  4196. _proto.enableAll = function enableAll() {
  4197. this.mask = 0xffffffff | 0;
  4198. };
  4199. _proto.toggle = function toggle(channel) {
  4200. this.mask ^= 1 << channel | 0;
  4201. };
  4202. _proto.disable = function disable(channel) {
  4203. this.mask &= ~(1 << channel | 0);
  4204. };
  4205. _proto.disableAll = function disableAll() {
  4206. this.mask = 0;
  4207. };
  4208. _proto.test = function test(layers) {
  4209. return (this.mask & layers.mask) !== 0;
  4210. };
  4211. return Layers;
  4212. }();
  4213. var _object3DId = 0;
  4214. var _v1$2 = new Vector3();
  4215. var _q1 = new Quaternion();
  4216. var _m1$1 = new Matrix4();
  4217. var _target = new Vector3();
  4218. var _position = new Vector3();
  4219. var _scale = new Vector3();
  4220. var _quaternion$2 = new Quaternion();
  4221. var _xAxis = new Vector3(1, 0, 0);
  4222. var _yAxis = new Vector3(0, 1, 0);
  4223. var _zAxis = new Vector3(0, 0, 1);
  4224. var _addedEvent = {
  4225. type: 'added'
  4226. };
  4227. var _removedEvent = {
  4228. type: 'removed'
  4229. };
  4230. function Object3D() {
  4231. Object.defineProperty(this, 'id', {
  4232. value: _object3DId++
  4233. });
  4234. this.uuid = MathUtils.generateUUID();
  4235. this.name = '';
  4236. this.type = 'Object3D';
  4237. this.parent = null;
  4238. this.children = [];
  4239. this.up = Object3D.DefaultUp.clone();
  4240. var position = new Vector3();
  4241. var rotation = new Euler();
  4242. var quaternion = new Quaternion();
  4243. var scale = new Vector3(1, 1, 1);
  4244. function onRotationChange() {
  4245. quaternion.setFromEuler(rotation, false);
  4246. }
  4247. function onQuaternionChange() {
  4248. rotation.setFromQuaternion(quaternion, undefined, false);
  4249. }
  4250. rotation._onChange(onRotationChange);
  4251. quaternion._onChange(onQuaternionChange);
  4252. Object.defineProperties(this, {
  4253. position: {
  4254. configurable: true,
  4255. enumerable: true,
  4256. value: position
  4257. },
  4258. rotation: {
  4259. configurable: true,
  4260. enumerable: true,
  4261. value: rotation
  4262. },
  4263. quaternion: {
  4264. configurable: true,
  4265. enumerable: true,
  4266. value: quaternion
  4267. },
  4268. scale: {
  4269. configurable: true,
  4270. enumerable: true,
  4271. value: scale
  4272. },
  4273. modelViewMatrix: {
  4274. value: new Matrix4()
  4275. },
  4276. normalMatrix: {
  4277. value: new Matrix3()
  4278. }
  4279. });
  4280. this.matrix = new Matrix4();
  4281. this.matrixWorld = new Matrix4();
  4282. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4283. this.matrixWorldNeedsUpdate = false;
  4284. this.layers = new Layers();
  4285. this.visible = true;
  4286. this.castShadow = false;
  4287. this.receiveShadow = false;
  4288. this.frustumCulled = true;
  4289. this.renderOrder = 0;
  4290. this.userData = {};
  4291. }
  4292. Object3D.DefaultUp = new Vector3(0, 1, 0);
  4293. Object3D.DefaultMatrixAutoUpdate = true;
  4294. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  4295. constructor: Object3D,
  4296. isObject3D: true,
  4297. onBeforeRender: function onBeforeRender() {},
  4298. onAfterRender: function onAfterRender() {},
  4299. applyMatrix4: function applyMatrix4(matrix) {
  4300. if (this.matrixAutoUpdate) this.updateMatrix();
  4301. this.matrix.premultiply(matrix);
  4302. this.matrix.decompose(this.position, this.quaternion, this.scale);
  4303. },
  4304. applyQuaternion: function applyQuaternion(q) {
  4305. this.quaternion.premultiply(q);
  4306. return this;
  4307. },
  4308. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  4309. // assumes axis is normalized
  4310. this.quaternion.setFromAxisAngle(axis, angle);
  4311. },
  4312. setRotationFromEuler: function setRotationFromEuler(euler) {
  4313. this.quaternion.setFromEuler(euler, true);
  4314. },
  4315. setRotationFromMatrix: function setRotationFromMatrix(m) {
  4316. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4317. this.quaternion.setFromRotationMatrix(m);
  4318. },
  4319. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  4320. // assumes q is normalized
  4321. this.quaternion.copy(q);
  4322. },
  4323. rotateOnAxis: function rotateOnAxis(axis, angle) {
  4324. // rotate object on axis in object space
  4325. // axis is assumed to be normalized
  4326. _q1.setFromAxisAngle(axis, angle);
  4327. this.quaternion.multiply(_q1);
  4328. return this;
  4329. },
  4330. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  4331. // rotate object on axis in world space
  4332. // axis is assumed to be normalized
  4333. // method assumes no rotated parent
  4334. _q1.setFromAxisAngle(axis, angle);
  4335. this.quaternion.premultiply(_q1);
  4336. return this;
  4337. },
  4338. rotateX: function rotateX(angle) {
  4339. return this.rotateOnAxis(_xAxis, angle);
  4340. },
  4341. rotateY: function rotateY(angle) {
  4342. return this.rotateOnAxis(_yAxis, angle);
  4343. },
  4344. rotateZ: function rotateZ(angle) {
  4345. return this.rotateOnAxis(_zAxis, angle);
  4346. },
  4347. translateOnAxis: function translateOnAxis(axis, distance) {
  4348. // translate object by distance along axis in object space
  4349. // axis is assumed to be normalized
  4350. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  4351. this.position.add(_v1$2.multiplyScalar(distance));
  4352. return this;
  4353. },
  4354. translateX: function translateX(distance) {
  4355. return this.translateOnAxis(_xAxis, distance);
  4356. },
  4357. translateY: function translateY(distance) {
  4358. return this.translateOnAxis(_yAxis, distance);
  4359. },
  4360. translateZ: function translateZ(distance) {
  4361. return this.translateOnAxis(_zAxis, distance);
  4362. },
  4363. localToWorld: function localToWorld(vector) {
  4364. return vector.applyMatrix4(this.matrixWorld);
  4365. },
  4366. worldToLocal: function worldToLocal(vector) {
  4367. return vector.applyMatrix4(_m1$1.getInverse(this.matrixWorld));
  4368. },
  4369. lookAt: function lookAt(x, y, z) {
  4370. // This method does not support objects having non-uniformly-scaled parent(s)
  4371. if (x.isVector3) {
  4372. _target.copy(x);
  4373. } else {
  4374. _target.set(x, y, z);
  4375. }
  4376. var parent = this.parent;
  4377. this.updateWorldMatrix(true, false);
  4378. _position.setFromMatrixPosition(this.matrixWorld);
  4379. if (this.isCamera || this.isLight) {
  4380. _m1$1.lookAt(_position, _target, this.up);
  4381. } else {
  4382. _m1$1.lookAt(_target, _position, this.up);
  4383. }
  4384. this.quaternion.setFromRotationMatrix(_m1$1);
  4385. if (parent) {
  4386. _m1$1.extractRotation(parent.matrixWorld);
  4387. _q1.setFromRotationMatrix(_m1$1);
  4388. this.quaternion.premultiply(_q1.inverse());
  4389. }
  4390. },
  4391. add: function add(object) {
  4392. if (arguments.length > 1) {
  4393. for (var i = 0; i < arguments.length; i++) {
  4394. this.add(arguments[i]);
  4395. }
  4396. return this;
  4397. }
  4398. if (object === this) {
  4399. console.error("THREE.Object3D.add: object can't be added as a child of itself.", object);
  4400. return this;
  4401. }
  4402. if (object && object.isObject3D) {
  4403. if (object.parent !== null) {
  4404. object.parent.remove(object);
  4405. }
  4406. object.parent = this;
  4407. this.children.push(object);
  4408. object.dispatchEvent(_addedEvent);
  4409. } else {
  4410. console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object);
  4411. }
  4412. return this;
  4413. },
  4414. remove: function remove(object) {
  4415. if (arguments.length > 1) {
  4416. for (var i = 0; i < arguments.length; i++) {
  4417. this.remove(arguments[i]);
  4418. }
  4419. return this;
  4420. }
  4421. var index = this.children.indexOf(object);
  4422. if (index !== -1) {
  4423. object.parent = null;
  4424. this.children.splice(index, 1);
  4425. object.dispatchEvent(_removedEvent);
  4426. }
  4427. return this;
  4428. },
  4429. clear: function clear() {
  4430. for (var i = 0; i < this.children.length; i++) {
  4431. var object = this.children[i];
  4432. object.parent = null;
  4433. object.dispatchEvent(_removedEvent);
  4434. }
  4435. this.children.length = 0;
  4436. return this;
  4437. },
  4438. attach: function attach(object) {
  4439. // adds object as a child of this, while maintaining the object's world transform
  4440. this.updateWorldMatrix(true, false);
  4441. _m1$1.getInverse(this.matrixWorld);
  4442. if (object.parent !== null) {
  4443. object.parent.updateWorldMatrix(true, false);
  4444. _m1$1.multiply(object.parent.matrixWorld);
  4445. }
  4446. object.applyMatrix4(_m1$1);
  4447. object.updateWorldMatrix(false, false);
  4448. this.add(object);
  4449. return this;
  4450. },
  4451. getObjectById: function getObjectById(id) {
  4452. return this.getObjectByProperty('id', id);
  4453. },
  4454. getObjectByName: function getObjectByName(name) {
  4455. return this.getObjectByProperty('name', name);
  4456. },
  4457. getObjectByProperty: function getObjectByProperty(name, value) {
  4458. if (this[name] === value) return this;
  4459. for (var i = 0, l = this.children.length; i < l; i++) {
  4460. var child = this.children[i];
  4461. var object = child.getObjectByProperty(name, value);
  4462. if (object !== undefined) {
  4463. return object;
  4464. }
  4465. }
  4466. return undefined;
  4467. },
  4468. getWorldPosition: function getWorldPosition(target) {
  4469. if (target === undefined) {
  4470. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  4471. target = new Vector3();
  4472. }
  4473. this.updateWorldMatrix(true, false);
  4474. return target.setFromMatrixPosition(this.matrixWorld);
  4475. },
  4476. getWorldQuaternion: function getWorldQuaternion(target) {
  4477. if (target === undefined) {
  4478. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  4479. target = new Quaternion();
  4480. }
  4481. this.updateWorldMatrix(true, false);
  4482. this.matrixWorld.decompose(_position, target, _scale);
  4483. return target;
  4484. },
  4485. getWorldScale: function getWorldScale(target) {
  4486. if (target === undefined) {
  4487. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  4488. target = new Vector3();
  4489. }
  4490. this.updateWorldMatrix(true, false);
  4491. this.matrixWorld.decompose(_position, _quaternion$2, target);
  4492. return target;
  4493. },
  4494. getWorldDirection: function getWorldDirection(target) {
  4495. if (target === undefined) {
  4496. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  4497. target = new Vector3();
  4498. }
  4499. this.updateWorldMatrix(true, false);
  4500. var e = this.matrixWorld.elements;
  4501. return target.set(e[8], e[9], e[10]).normalize();
  4502. },
  4503. raycast: function raycast() {},
  4504. traverse: function traverse(callback) {
  4505. callback(this);
  4506. var children = this.children;
  4507. for (var i = 0, l = children.length; i < l; i++) {
  4508. children[i].traverse(callback);
  4509. }
  4510. },
  4511. traverseVisible: function traverseVisible(callback) {
  4512. if (this.visible === false) return;
  4513. callback(this);
  4514. var children = this.children;
  4515. for (var i = 0, l = children.length; i < l; i++) {
  4516. children[i].traverseVisible(callback);
  4517. }
  4518. },
  4519. traverseAncestors: function traverseAncestors(callback) {
  4520. var parent = this.parent;
  4521. if (parent !== null) {
  4522. callback(parent);
  4523. parent.traverseAncestors(callback);
  4524. }
  4525. },
  4526. updateMatrix: function updateMatrix() {
  4527. this.matrix.compose(this.position, this.quaternion, this.scale);
  4528. this.matrixWorldNeedsUpdate = true;
  4529. },
  4530. updateMatrixWorld: function updateMatrixWorld(force) {
  4531. if (this.matrixAutoUpdate) this.updateMatrix();
  4532. if (this.matrixWorldNeedsUpdate || force) {
  4533. if (this.parent === null) {
  4534. this.matrixWorld.copy(this.matrix);
  4535. } else {
  4536. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4537. }
  4538. this.matrixWorldNeedsUpdate = false;
  4539. force = true;
  4540. } // update children
  4541. var children = this.children;
  4542. for (var i = 0, l = children.length; i < l; i++) {
  4543. children[i].updateMatrixWorld(force);
  4544. }
  4545. },
  4546. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  4547. var parent = this.parent;
  4548. if (updateParents === true && parent !== null) {
  4549. parent.updateWorldMatrix(true, false);
  4550. }
  4551. if (this.matrixAutoUpdate) this.updateMatrix();
  4552. if (this.parent === null) {
  4553. this.matrixWorld.copy(this.matrix);
  4554. } else {
  4555. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  4556. } // update children
  4557. if (updateChildren === true) {
  4558. var children = this.children;
  4559. for (var i = 0, l = children.length; i < l; i++) {
  4560. children[i].updateWorldMatrix(false, true);
  4561. }
  4562. }
  4563. },
  4564. toJSON: function toJSON(meta) {
  4565. // meta is a string when called from JSON.stringify
  4566. var isRootObject = meta === undefined || typeof meta === 'string';
  4567. var output = {}; // meta is a hash used to collect geometries, materials.
  4568. // not providing it implies that this is the root object
  4569. // being serialized.
  4570. if (isRootObject) {
  4571. // initialize meta obj
  4572. meta = {
  4573. geometries: {},
  4574. materials: {},
  4575. textures: {},
  4576. images: {},
  4577. shapes: {}
  4578. };
  4579. output.metadata = {
  4580. version: 4.5,
  4581. type: 'Object',
  4582. generator: 'Object3D.toJSON'
  4583. };
  4584. } // standard Object3D serialization
  4585. var object = {};
  4586. object.uuid = this.uuid;
  4587. object.type = this.type;
  4588. if (this.name !== '') object.name = this.name;
  4589. if (this.castShadow === true) object.castShadow = true;
  4590. if (this.receiveShadow === true) object.receiveShadow = true;
  4591. if (this.visible === false) object.visible = false;
  4592. if (this.frustumCulled === false) object.frustumCulled = false;
  4593. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  4594. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  4595. object.layers = this.layers.mask;
  4596. object.matrix = this.matrix.toArray();
  4597. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  4598. if (this.isInstancedMesh) {
  4599. object.type = 'InstancedMesh';
  4600. object.count = this.count;
  4601. object.instanceMatrix = this.instanceMatrix.toJSON();
  4602. } //
  4603. function serialize(library, element) {
  4604. if (library[element.uuid] === undefined) {
  4605. library[element.uuid] = element.toJSON(meta);
  4606. }
  4607. return element.uuid;
  4608. }
  4609. if (this.isMesh || this.isLine || this.isPoints) {
  4610. object.geometry = serialize(meta.geometries, this.geometry);
  4611. var parameters = this.geometry.parameters;
  4612. if (parameters !== undefined && parameters.shapes !== undefined) {
  4613. var shapes = parameters.shapes;
  4614. if (Array.isArray(shapes)) {
  4615. for (var i = 0, l = shapes.length; i < l; i++) {
  4616. var shape = shapes[i];
  4617. serialize(meta.shapes, shape);
  4618. }
  4619. } else {
  4620. serialize(meta.shapes, shapes);
  4621. }
  4622. }
  4623. }
  4624. if (this.material !== undefined) {
  4625. if (Array.isArray(this.material)) {
  4626. var uuids = [];
  4627. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  4628. uuids.push(serialize(meta.materials, this.material[_i]));
  4629. }
  4630. object.material = uuids;
  4631. } else {
  4632. object.material = serialize(meta.materials, this.material);
  4633. }
  4634. } //
  4635. if (this.children.length > 0) {
  4636. object.children = [];
  4637. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  4638. object.children.push(this.children[_i2].toJSON(meta).object);
  4639. }
  4640. }
  4641. if (isRootObject) {
  4642. var geometries = extractFromCache(meta.geometries);
  4643. var materials = extractFromCache(meta.materials);
  4644. var textures = extractFromCache(meta.textures);
  4645. var images = extractFromCache(meta.images);
  4646. var _shapes = extractFromCache(meta.shapes);
  4647. if (geometries.length > 0) output.geometries = geometries;
  4648. if (materials.length > 0) output.materials = materials;
  4649. if (textures.length > 0) output.textures = textures;
  4650. if (images.length > 0) output.images = images;
  4651. if (_shapes.length > 0) output.shapes = _shapes;
  4652. }
  4653. output.object = object;
  4654. return output; // extract data from the cache hash
  4655. // remove metadata on each item
  4656. // and return as array
  4657. function extractFromCache(cache) {
  4658. var values = [];
  4659. for (var key in cache) {
  4660. var data = cache[key];
  4661. delete data.metadata;
  4662. values.push(data);
  4663. }
  4664. return values;
  4665. }
  4666. },
  4667. clone: function clone(recursive) {
  4668. return new this.constructor().copy(this, recursive);
  4669. },
  4670. copy: function copy(source, recursive) {
  4671. if (recursive === undefined) recursive = true;
  4672. this.name = source.name;
  4673. this.up.copy(source.up);
  4674. this.position.copy(source.position);
  4675. this.rotation.order = source.rotation.order;
  4676. this.quaternion.copy(source.quaternion);
  4677. this.scale.copy(source.scale);
  4678. this.matrix.copy(source.matrix);
  4679. this.matrixWorld.copy(source.matrixWorld);
  4680. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4681. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4682. this.layers.mask = source.layers.mask;
  4683. this.visible = source.visible;
  4684. this.castShadow = source.castShadow;
  4685. this.receiveShadow = source.receiveShadow;
  4686. this.frustumCulled = source.frustumCulled;
  4687. this.renderOrder = source.renderOrder;
  4688. this.userData = JSON.parse(JSON.stringify(source.userData));
  4689. if (recursive === true) {
  4690. for (var i = 0; i < source.children.length; i++) {
  4691. var child = source.children[i];
  4692. this.add(child.clone());
  4693. }
  4694. }
  4695. return this;
  4696. }
  4697. });
  4698. var _vector1 = /*@__PURE__*/new Vector3();
  4699. var _vector2 = /*@__PURE__*/new Vector3();
  4700. var _normalMatrix = /*@__PURE__*/new Matrix3();
  4701. var Plane = /*#__PURE__*/function () {
  4702. function Plane(normal, constant) {
  4703. Object.defineProperty(this, 'isPlane', {
  4704. value: true
  4705. }); // normal is assumed to be normalized
  4706. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  4707. this.constant = constant !== undefined ? constant : 0;
  4708. }
  4709. var _proto = Plane.prototype;
  4710. _proto.set = function set(normal, constant) {
  4711. this.normal.copy(normal);
  4712. this.constant = constant;
  4713. return this;
  4714. };
  4715. _proto.setComponents = function setComponents(x, y, z, w) {
  4716. this.normal.set(x, y, z);
  4717. this.constant = w;
  4718. return this;
  4719. };
  4720. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  4721. this.normal.copy(normal);
  4722. this.constant = -point.dot(this.normal);
  4723. return this;
  4724. };
  4725. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  4726. var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4727. this.setFromNormalAndCoplanarPoint(normal, a);
  4728. return this;
  4729. };
  4730. _proto.clone = function clone() {
  4731. return new this.constructor().copy(this);
  4732. };
  4733. _proto.copy = function copy(plane) {
  4734. this.normal.copy(plane.normal);
  4735. this.constant = plane.constant;
  4736. return this;
  4737. };
  4738. _proto.normalize = function normalize() {
  4739. // Note: will lead to a divide by zero if the plane is invalid.
  4740. var inverseNormalLength = 1.0 / this.normal.length();
  4741. this.normal.multiplyScalar(inverseNormalLength);
  4742. this.constant *= inverseNormalLength;
  4743. return this;
  4744. };
  4745. _proto.negate = function negate() {
  4746. this.constant *= -1;
  4747. this.normal.negate();
  4748. return this;
  4749. };
  4750. _proto.distanceToPoint = function distanceToPoint(point) {
  4751. return this.normal.dot(point) + this.constant;
  4752. };
  4753. _proto.distanceToSphere = function distanceToSphere(sphere) {
  4754. return this.distanceToPoint(sphere.center) - sphere.radius;
  4755. };
  4756. _proto.projectPoint = function projectPoint(point, target) {
  4757. if (target === undefined) {
  4758. console.warn('THREE.Plane: .projectPoint() target is now required');
  4759. target = new Vector3();
  4760. }
  4761. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  4762. };
  4763. _proto.intersectLine = function intersectLine(line, target) {
  4764. if (target === undefined) {
  4765. console.warn('THREE.Plane: .intersectLine() target is now required');
  4766. target = new Vector3();
  4767. }
  4768. var direction = line.delta(_vector1);
  4769. var denominator = this.normal.dot(direction);
  4770. if (denominator === 0) {
  4771. // line is coplanar, return origin
  4772. if (this.distanceToPoint(line.start) === 0) {
  4773. return target.copy(line.start);
  4774. } // Unsure if this is the correct method to handle this case.
  4775. return undefined;
  4776. }
  4777. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  4778. if (t < 0 || t > 1) {
  4779. return undefined;
  4780. }
  4781. return target.copy(direction).multiplyScalar(t).add(line.start);
  4782. };
  4783. _proto.intersectsLine = function intersectsLine(line) {
  4784. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4785. var startSign = this.distanceToPoint(line.start);
  4786. var endSign = this.distanceToPoint(line.end);
  4787. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  4788. };
  4789. _proto.intersectsBox = function intersectsBox(box) {
  4790. return box.intersectsPlane(this);
  4791. };
  4792. _proto.intersectsSphere = function intersectsSphere(sphere) {
  4793. return sphere.intersectsPlane(this);
  4794. };
  4795. _proto.coplanarPoint = function coplanarPoint(target) {
  4796. if (target === undefined) {
  4797. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  4798. target = new Vector3();
  4799. }
  4800. return target.copy(this.normal).multiplyScalar(-this.constant);
  4801. };
  4802. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  4803. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  4804. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  4805. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  4806. this.constant = -referencePoint.dot(normal);
  4807. return this;
  4808. };
  4809. _proto.translate = function translate(offset) {
  4810. this.constant -= offset.dot(this.normal);
  4811. return this;
  4812. };
  4813. _proto.equals = function equals(plane) {
  4814. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  4815. };
  4816. return Plane;
  4817. }();
  4818. var _v0$1 = /*@__PURE__*/new Vector3();
  4819. var _v1$3 = /*@__PURE__*/new Vector3();
  4820. var _v2$1 = /*@__PURE__*/new Vector3();
  4821. var _v3 = /*@__PURE__*/new Vector3();
  4822. var _vab = /*@__PURE__*/new Vector3();
  4823. var _vac = /*@__PURE__*/new Vector3();
  4824. var _vbc = /*@__PURE__*/new Vector3();
  4825. var _vap = /*@__PURE__*/new Vector3();
  4826. var _vbp = /*@__PURE__*/new Vector3();
  4827. var _vcp = /*@__PURE__*/new Vector3();
  4828. var Triangle = /*#__PURE__*/function () {
  4829. function Triangle(a, b, c) {
  4830. this.a = a !== undefined ? a : new Vector3();
  4831. this.b = b !== undefined ? b : new Vector3();
  4832. this.c = c !== undefined ? c : new Vector3();
  4833. }
  4834. Triangle.getNormal = function getNormal(a, b, c, target) {
  4835. if (target === undefined) {
  4836. console.warn('THREE.Triangle: .getNormal() target is now required');
  4837. target = new Vector3();
  4838. }
  4839. target.subVectors(c, b);
  4840. _v0$1.subVectors(a, b);
  4841. target.cross(_v0$1);
  4842. var targetLengthSq = target.lengthSq();
  4843. if (targetLengthSq > 0) {
  4844. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  4845. }
  4846. return target.set(0, 0, 0);
  4847. } // static/instance method to calculate barycentric coordinates
  4848. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4849. ;
  4850. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  4851. _v0$1.subVectors(c, a);
  4852. _v1$3.subVectors(b, a);
  4853. _v2$1.subVectors(point, a);
  4854. var dot00 = _v0$1.dot(_v0$1);
  4855. var dot01 = _v0$1.dot(_v1$3);
  4856. var dot02 = _v0$1.dot(_v2$1);
  4857. var dot11 = _v1$3.dot(_v1$3);
  4858. var dot12 = _v1$3.dot(_v2$1);
  4859. var denom = dot00 * dot11 - dot01 * dot01;
  4860. if (target === undefined) {
  4861. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  4862. target = new Vector3();
  4863. } // collinear or singular triangle
  4864. if (denom === 0) {
  4865. // arbitrary location outside of triangle?
  4866. // not sure if this is the best idea, maybe should be returning undefined
  4867. return target.set(-2, -1, -1);
  4868. }
  4869. var invDenom = 1 / denom;
  4870. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  4871. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  4872. return target.set(1 - u - v, v, u);
  4873. };
  4874. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  4875. this.getBarycoord(point, a, b, c, _v3);
  4876. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  4877. };
  4878. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  4879. this.getBarycoord(point, p1, p2, p3, _v3);
  4880. target.set(0, 0);
  4881. target.addScaledVector(uv1, _v3.x);
  4882. target.addScaledVector(uv2, _v3.y);
  4883. target.addScaledVector(uv3, _v3.z);
  4884. return target;
  4885. };
  4886. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  4887. _v0$1.subVectors(c, b);
  4888. _v1$3.subVectors(a, b); // strictly front facing
  4889. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  4890. };
  4891. var _proto = Triangle.prototype;
  4892. _proto.set = function set(a, b, c) {
  4893. this.a.copy(a);
  4894. this.b.copy(b);
  4895. this.c.copy(c);
  4896. return this;
  4897. };
  4898. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  4899. this.a.copy(points[i0]);
  4900. this.b.copy(points[i1]);
  4901. this.c.copy(points[i2]);
  4902. return this;
  4903. };
  4904. _proto.clone = function clone() {
  4905. return new this.constructor().copy(this);
  4906. };
  4907. _proto.copy = function copy(triangle) {
  4908. this.a.copy(triangle.a);
  4909. this.b.copy(triangle.b);
  4910. this.c.copy(triangle.c);
  4911. return this;
  4912. };
  4913. _proto.getArea = function getArea() {
  4914. _v0$1.subVectors(this.c, this.b);
  4915. _v1$3.subVectors(this.a, this.b);
  4916. return _v0$1.cross(_v1$3).length() * 0.5;
  4917. };
  4918. _proto.getMidpoint = function getMidpoint(target) {
  4919. if (target === undefined) {
  4920. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  4921. target = new Vector3();
  4922. }
  4923. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  4924. };
  4925. _proto.getNormal = function getNormal(target) {
  4926. return Triangle.getNormal(this.a, this.b, this.c, target);
  4927. };
  4928. _proto.getPlane = function getPlane(target) {
  4929. if (target === undefined) {
  4930. console.warn('THREE.Triangle: .getPlane() target is now required');
  4931. target = new Plane();
  4932. }
  4933. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  4934. };
  4935. _proto.getBarycoord = function getBarycoord(point, target) {
  4936. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  4937. };
  4938. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  4939. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  4940. };
  4941. _proto.containsPoint = function containsPoint(point) {
  4942. return Triangle.containsPoint(point, this.a, this.b, this.c);
  4943. };
  4944. _proto.isFrontFacing = function isFrontFacing(direction) {
  4945. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  4946. };
  4947. _proto.intersectsBox = function intersectsBox(box) {
  4948. return box.intersectsTriangle(this);
  4949. };
  4950. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  4951. if (target === undefined) {
  4952. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  4953. target = new Vector3();
  4954. }
  4955. var a = this.a,
  4956. b = this.b,
  4957. c = this.c;
  4958. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4959. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4960. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4961. // basically, we're distinguishing which of the voronoi regions of the triangle
  4962. // the point lies in with the minimum amount of redundant computation.
  4963. _vab.subVectors(b, a);
  4964. _vac.subVectors(c, a);
  4965. _vap.subVectors(p, a);
  4966. var d1 = _vab.dot(_vap);
  4967. var d2 = _vac.dot(_vap);
  4968. if (d1 <= 0 && d2 <= 0) {
  4969. // vertex region of A; barycentric coords (1, 0, 0)
  4970. return target.copy(a);
  4971. }
  4972. _vbp.subVectors(p, b);
  4973. var d3 = _vab.dot(_vbp);
  4974. var d4 = _vac.dot(_vbp);
  4975. if (d3 >= 0 && d4 <= d3) {
  4976. // vertex region of B; barycentric coords (0, 1, 0)
  4977. return target.copy(b);
  4978. }
  4979. var vc = d1 * d4 - d3 * d2;
  4980. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  4981. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  4982. return target.copy(a).addScaledVector(_vab, v);
  4983. }
  4984. _vcp.subVectors(p, c);
  4985. var d5 = _vab.dot(_vcp);
  4986. var d6 = _vac.dot(_vcp);
  4987. if (d6 >= 0 && d5 <= d6) {
  4988. // vertex region of C; barycentric coords (0, 0, 1)
  4989. return target.copy(c);
  4990. }
  4991. var vb = d5 * d2 - d1 * d6;
  4992. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  4993. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  4994. return target.copy(a).addScaledVector(_vac, w);
  4995. }
  4996. var va = d3 * d6 - d5 * d4;
  4997. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  4998. _vbc.subVectors(c, b);
  4999. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5000. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5001. } // face region
  5002. var denom = 1 / (va + vb + vc); // u = va * denom
  5003. v = vb * denom;
  5004. w = vc * denom;
  5005. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5006. };
  5007. _proto.equals = function equals(triangle) {
  5008. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5009. };
  5010. return Triangle;
  5011. }();
  5012. var _colorKeywords = {
  5013. 'aliceblue': 0xF0F8FF,
  5014. 'antiquewhite': 0xFAEBD7,
  5015. 'aqua': 0x00FFFF,
  5016. 'aquamarine': 0x7FFFD4,
  5017. 'azure': 0xF0FFFF,
  5018. 'beige': 0xF5F5DC,
  5019. 'bisque': 0xFFE4C4,
  5020. 'black': 0x000000,
  5021. 'blanchedalmond': 0xFFEBCD,
  5022. 'blue': 0x0000FF,
  5023. 'blueviolet': 0x8A2BE2,
  5024. 'brown': 0xA52A2A,
  5025. 'burlywood': 0xDEB887,
  5026. 'cadetblue': 0x5F9EA0,
  5027. 'chartreuse': 0x7FFF00,
  5028. 'chocolate': 0xD2691E,
  5029. 'coral': 0xFF7F50,
  5030. 'cornflowerblue': 0x6495ED,
  5031. 'cornsilk': 0xFFF8DC,
  5032. 'crimson': 0xDC143C,
  5033. 'cyan': 0x00FFFF,
  5034. 'darkblue': 0x00008B,
  5035. 'darkcyan': 0x008B8B,
  5036. 'darkgoldenrod': 0xB8860B,
  5037. 'darkgray': 0xA9A9A9,
  5038. 'darkgreen': 0x006400,
  5039. 'darkgrey': 0xA9A9A9,
  5040. 'darkkhaki': 0xBDB76B,
  5041. 'darkmagenta': 0x8B008B,
  5042. 'darkolivegreen': 0x556B2F,
  5043. 'darkorange': 0xFF8C00,
  5044. 'darkorchid': 0x9932CC,
  5045. 'darkred': 0x8B0000,
  5046. 'darksalmon': 0xE9967A,
  5047. 'darkseagreen': 0x8FBC8F,
  5048. 'darkslateblue': 0x483D8B,
  5049. 'darkslategray': 0x2F4F4F,
  5050. 'darkslategrey': 0x2F4F4F,
  5051. 'darkturquoise': 0x00CED1,
  5052. 'darkviolet': 0x9400D3,
  5053. 'deeppink': 0xFF1493,
  5054. 'deepskyblue': 0x00BFFF,
  5055. 'dimgray': 0x696969,
  5056. 'dimgrey': 0x696969,
  5057. 'dodgerblue': 0x1E90FF,
  5058. 'firebrick': 0xB22222,
  5059. 'floralwhite': 0xFFFAF0,
  5060. 'forestgreen': 0x228B22,
  5061. 'fuchsia': 0xFF00FF,
  5062. 'gainsboro': 0xDCDCDC,
  5063. 'ghostwhite': 0xF8F8FF,
  5064. 'gold': 0xFFD700,
  5065. 'goldenrod': 0xDAA520,
  5066. 'gray': 0x808080,
  5067. 'green': 0x008000,
  5068. 'greenyellow': 0xADFF2F,
  5069. 'grey': 0x808080,
  5070. 'honeydew': 0xF0FFF0,
  5071. 'hotpink': 0xFF69B4,
  5072. 'indianred': 0xCD5C5C,
  5073. 'indigo': 0x4B0082,
  5074. 'ivory': 0xFFFFF0,
  5075. 'khaki': 0xF0E68C,
  5076. 'lavender': 0xE6E6FA,
  5077. 'lavenderblush': 0xFFF0F5,
  5078. 'lawngreen': 0x7CFC00,
  5079. 'lemonchiffon': 0xFFFACD,
  5080. 'lightblue': 0xADD8E6,
  5081. 'lightcoral': 0xF08080,
  5082. 'lightcyan': 0xE0FFFF,
  5083. 'lightgoldenrodyellow': 0xFAFAD2,
  5084. 'lightgray': 0xD3D3D3,
  5085. 'lightgreen': 0x90EE90,
  5086. 'lightgrey': 0xD3D3D3,
  5087. 'lightpink': 0xFFB6C1,
  5088. 'lightsalmon': 0xFFA07A,
  5089. 'lightseagreen': 0x20B2AA,
  5090. 'lightskyblue': 0x87CEFA,
  5091. 'lightslategray': 0x778899,
  5092. 'lightslategrey': 0x778899,
  5093. 'lightsteelblue': 0xB0C4DE,
  5094. 'lightyellow': 0xFFFFE0,
  5095. 'lime': 0x00FF00,
  5096. 'limegreen': 0x32CD32,
  5097. 'linen': 0xFAF0E6,
  5098. 'magenta': 0xFF00FF,
  5099. 'maroon': 0x800000,
  5100. 'mediumaquamarine': 0x66CDAA,
  5101. 'mediumblue': 0x0000CD,
  5102. 'mediumorchid': 0xBA55D3,
  5103. 'mediumpurple': 0x9370DB,
  5104. 'mediumseagreen': 0x3CB371,
  5105. 'mediumslateblue': 0x7B68EE,
  5106. 'mediumspringgreen': 0x00FA9A,
  5107. 'mediumturquoise': 0x48D1CC,
  5108. 'mediumvioletred': 0xC71585,
  5109. 'midnightblue': 0x191970,
  5110. 'mintcream': 0xF5FFFA,
  5111. 'mistyrose': 0xFFE4E1,
  5112. 'moccasin': 0xFFE4B5,
  5113. 'navajowhite': 0xFFDEAD,
  5114. 'navy': 0x000080,
  5115. 'oldlace': 0xFDF5E6,
  5116. 'olive': 0x808000,
  5117. 'olivedrab': 0x6B8E23,
  5118. 'orange': 0xFFA500,
  5119. 'orangered': 0xFF4500,
  5120. 'orchid': 0xDA70D6,
  5121. 'palegoldenrod': 0xEEE8AA,
  5122. 'palegreen': 0x98FB98,
  5123. 'paleturquoise': 0xAFEEEE,
  5124. 'palevioletred': 0xDB7093,
  5125. 'papayawhip': 0xFFEFD5,
  5126. 'peachpuff': 0xFFDAB9,
  5127. 'peru': 0xCD853F,
  5128. 'pink': 0xFFC0CB,
  5129. 'plum': 0xDDA0DD,
  5130. 'powderblue': 0xB0E0E6,
  5131. 'purple': 0x800080,
  5132. 'rebeccapurple': 0x663399,
  5133. 'red': 0xFF0000,
  5134. 'rosybrown': 0xBC8F8F,
  5135. 'royalblue': 0x4169E1,
  5136. 'saddlebrown': 0x8B4513,
  5137. 'salmon': 0xFA8072,
  5138. 'sandybrown': 0xF4A460,
  5139. 'seagreen': 0x2E8B57,
  5140. 'seashell': 0xFFF5EE,
  5141. 'sienna': 0xA0522D,
  5142. 'silver': 0xC0C0C0,
  5143. 'skyblue': 0x87CEEB,
  5144. 'slateblue': 0x6A5ACD,
  5145. 'slategray': 0x708090,
  5146. 'slategrey': 0x708090,
  5147. 'snow': 0xFFFAFA,
  5148. 'springgreen': 0x00FF7F,
  5149. 'steelblue': 0x4682B4,
  5150. 'tan': 0xD2B48C,
  5151. 'teal': 0x008080,
  5152. 'thistle': 0xD8BFD8,
  5153. 'tomato': 0xFF6347,
  5154. 'turquoise': 0x40E0D0,
  5155. 'violet': 0xEE82EE,
  5156. 'wheat': 0xF5DEB3,
  5157. 'white': 0xFFFFFF,
  5158. 'whitesmoke': 0xF5F5F5,
  5159. 'yellow': 0xFFFF00,
  5160. 'yellowgreen': 0x9ACD32
  5161. };
  5162. var _hslA = {
  5163. h: 0,
  5164. s: 0,
  5165. l: 0
  5166. };
  5167. var _hslB = {
  5168. h: 0,
  5169. s: 0,
  5170. l: 0
  5171. };
  5172. function hue2rgb(p, q, t) {
  5173. if (t < 0) t += 1;
  5174. if (t > 1) t -= 1;
  5175. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5176. if (t < 1 / 2) return q;
  5177. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5178. return p;
  5179. }
  5180. function SRGBToLinear(c) {
  5181. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5182. }
  5183. function LinearToSRGB(c) {
  5184. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5185. }
  5186. var Color = /*#__PURE__*/function () {
  5187. function Color(r, g, b) {
  5188. Object.defineProperty(this, 'isColor', {
  5189. value: true
  5190. });
  5191. if (g === undefined && b === undefined) {
  5192. // r is THREE.Color, hex or string
  5193. return this.set(r);
  5194. }
  5195. return this.setRGB(r, g, b);
  5196. }
  5197. var _proto = Color.prototype;
  5198. _proto.set = function set(value) {
  5199. if (value && value.isColor) {
  5200. this.copy(value);
  5201. } else if (typeof value === 'number') {
  5202. this.setHex(value);
  5203. } else if (typeof value === 'string') {
  5204. this.setStyle(value);
  5205. }
  5206. return this;
  5207. };
  5208. _proto.setScalar = function setScalar(scalar) {
  5209. this.r = scalar;
  5210. this.g = scalar;
  5211. this.b = scalar;
  5212. return this;
  5213. };
  5214. _proto.setHex = function setHex(hex) {
  5215. hex = Math.floor(hex);
  5216. this.r = (hex >> 16 & 255) / 255;
  5217. this.g = (hex >> 8 & 255) / 255;
  5218. this.b = (hex & 255) / 255;
  5219. return this;
  5220. };
  5221. _proto.setRGB = function setRGB(r, g, b) {
  5222. this.r = r;
  5223. this.g = g;
  5224. this.b = b;
  5225. return this;
  5226. };
  5227. _proto.setHSL = function setHSL(h, s, l) {
  5228. // h,s,l ranges are in 0.0 - 1.0
  5229. h = MathUtils.euclideanModulo(h, 1);
  5230. s = MathUtils.clamp(s, 0, 1);
  5231. l = MathUtils.clamp(l, 0, 1);
  5232. if (s === 0) {
  5233. this.r = this.g = this.b = l;
  5234. } else {
  5235. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5236. var q = 2 * l - p;
  5237. this.r = hue2rgb(q, p, h + 1 / 3);
  5238. this.g = hue2rgb(q, p, h);
  5239. this.b = hue2rgb(q, p, h - 1 / 3);
  5240. }
  5241. return this;
  5242. };
  5243. _proto.setStyle = function setStyle(style) {
  5244. function handleAlpha(string) {
  5245. if (string === undefined) return;
  5246. if (parseFloat(string) < 1) {
  5247. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  5248. }
  5249. }
  5250. var m;
  5251. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  5252. // rgb / hsl
  5253. var color;
  5254. var name = m[1];
  5255. var components = m[2];
  5256. switch (name) {
  5257. case 'rgb':
  5258. case 'rgba':
  5259. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5260. // rgb(255,0,0) rgba(255,0,0,0.5)
  5261. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  5262. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  5263. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  5264. handleAlpha(color[5]);
  5265. return this;
  5266. }
  5267. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5268. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5269. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  5270. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  5271. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  5272. handleAlpha(color[5]);
  5273. return this;
  5274. }
  5275. break;
  5276. case 'hsl':
  5277. case 'hsla':
  5278. if (color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)) {
  5279. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5280. var h = parseFloat(color[1]) / 360;
  5281. var s = parseInt(color[2], 10) / 100;
  5282. var l = parseInt(color[3], 10) / 100;
  5283. handleAlpha(color[5]);
  5284. return this.setHSL(h, s, l);
  5285. }
  5286. break;
  5287. }
  5288. } else if (m = /^\#([A-Fa-f0-9]+)$/.exec(style)) {
  5289. // hex color
  5290. var hex = m[1];
  5291. var size = hex.length;
  5292. if (size === 3) {
  5293. // #ff0
  5294. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  5295. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  5296. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  5297. return this;
  5298. } else if (size === 6) {
  5299. // #ff0000
  5300. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  5301. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  5302. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  5303. return this;
  5304. }
  5305. }
  5306. if (style && style.length > 0) {
  5307. return this.setColorName(style);
  5308. }
  5309. return this;
  5310. };
  5311. _proto.setColorName = function setColorName(style) {
  5312. // color keywords
  5313. var hex = _colorKeywords[style];
  5314. if (hex !== undefined) {
  5315. // red
  5316. this.setHex(hex);
  5317. } else {
  5318. // unknown color
  5319. console.warn('THREE.Color: Unknown color ' + style);
  5320. }
  5321. return this;
  5322. };
  5323. _proto.clone = function clone() {
  5324. return new this.constructor(this.r, this.g, this.b);
  5325. };
  5326. _proto.copy = function copy(color) {
  5327. this.r = color.r;
  5328. this.g = color.g;
  5329. this.b = color.b;
  5330. return this;
  5331. };
  5332. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  5333. if (gammaFactor === undefined) gammaFactor = 2.0;
  5334. this.r = Math.pow(color.r, gammaFactor);
  5335. this.g = Math.pow(color.g, gammaFactor);
  5336. this.b = Math.pow(color.b, gammaFactor);
  5337. return this;
  5338. };
  5339. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  5340. if (gammaFactor === undefined) gammaFactor = 2.0;
  5341. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  5342. this.r = Math.pow(color.r, safeInverse);
  5343. this.g = Math.pow(color.g, safeInverse);
  5344. this.b = Math.pow(color.b, safeInverse);
  5345. return this;
  5346. };
  5347. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  5348. this.copyGammaToLinear(this, gammaFactor);
  5349. return this;
  5350. };
  5351. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  5352. this.copyLinearToGamma(this, gammaFactor);
  5353. return this;
  5354. };
  5355. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  5356. this.r = SRGBToLinear(color.r);
  5357. this.g = SRGBToLinear(color.g);
  5358. this.b = SRGBToLinear(color.b);
  5359. return this;
  5360. };
  5361. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  5362. this.r = LinearToSRGB(color.r);
  5363. this.g = LinearToSRGB(color.g);
  5364. this.b = LinearToSRGB(color.b);
  5365. return this;
  5366. };
  5367. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  5368. this.copySRGBToLinear(this);
  5369. return this;
  5370. };
  5371. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  5372. this.copyLinearToSRGB(this);
  5373. return this;
  5374. };
  5375. _proto.getHex = function getHex() {
  5376. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  5377. };
  5378. _proto.getHexString = function getHexString() {
  5379. return ('000000' + this.getHex().toString(16)).slice(-6);
  5380. };
  5381. _proto.getHSL = function getHSL(target) {
  5382. // h,s,l ranges are in 0.0 - 1.0
  5383. if (target === undefined) {
  5384. console.warn('THREE.Color: .getHSL() target is now required');
  5385. target = {
  5386. h: 0,
  5387. s: 0,
  5388. l: 0
  5389. };
  5390. }
  5391. var r = this.r,
  5392. g = this.g,
  5393. b = this.b;
  5394. var max = Math.max(r, g, b);
  5395. var min = Math.min(r, g, b);
  5396. var hue, saturation;
  5397. var lightness = (min + max) / 2.0;
  5398. if (min === max) {
  5399. hue = 0;
  5400. saturation = 0;
  5401. } else {
  5402. var delta = max - min;
  5403. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  5404. switch (max) {
  5405. case r:
  5406. hue = (g - b) / delta + (g < b ? 6 : 0);
  5407. break;
  5408. case g:
  5409. hue = (b - r) / delta + 2;
  5410. break;
  5411. case b:
  5412. hue = (r - g) / delta + 4;
  5413. break;
  5414. }
  5415. hue /= 6;
  5416. }
  5417. target.h = hue;
  5418. target.s = saturation;
  5419. target.l = lightness;
  5420. return target;
  5421. };
  5422. _proto.getStyle = function getStyle() {
  5423. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  5424. };
  5425. _proto.offsetHSL = function offsetHSL(h, s, l) {
  5426. this.getHSL(_hslA);
  5427. _hslA.h += h;
  5428. _hslA.s += s;
  5429. _hslA.l += l;
  5430. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  5431. return this;
  5432. };
  5433. _proto.add = function add(color) {
  5434. this.r += color.r;
  5435. this.g += color.g;
  5436. this.b += color.b;
  5437. return this;
  5438. };
  5439. _proto.addColors = function addColors(color1, color2) {
  5440. this.r = color1.r + color2.r;
  5441. this.g = color1.g + color2.g;
  5442. this.b = color1.b + color2.b;
  5443. return this;
  5444. };
  5445. _proto.addScalar = function addScalar(s) {
  5446. this.r += s;
  5447. this.g += s;
  5448. this.b += s;
  5449. return this;
  5450. };
  5451. _proto.sub = function sub(color) {
  5452. this.r = Math.max(0, this.r - color.r);
  5453. this.g = Math.max(0, this.g - color.g);
  5454. this.b = Math.max(0, this.b - color.b);
  5455. return this;
  5456. };
  5457. _proto.multiply = function multiply(color) {
  5458. this.r *= color.r;
  5459. this.g *= color.g;
  5460. this.b *= color.b;
  5461. return this;
  5462. };
  5463. _proto.multiplyScalar = function multiplyScalar(s) {
  5464. this.r *= s;
  5465. this.g *= s;
  5466. this.b *= s;
  5467. return this;
  5468. };
  5469. _proto.lerp = function lerp(color, alpha) {
  5470. this.r += (color.r - this.r) * alpha;
  5471. this.g += (color.g - this.g) * alpha;
  5472. this.b += (color.b - this.b) * alpha;
  5473. return this;
  5474. };
  5475. _proto.lerpHSL = function lerpHSL(color, alpha) {
  5476. this.getHSL(_hslA);
  5477. color.getHSL(_hslB);
  5478. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  5479. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  5480. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  5481. this.setHSL(h, s, l);
  5482. return this;
  5483. };
  5484. _proto.equals = function equals(c) {
  5485. return c.r === this.r && c.g === this.g && c.b === this.b;
  5486. };
  5487. _proto.fromArray = function fromArray(array, offset) {
  5488. if (offset === void 0) {
  5489. offset = 0;
  5490. }
  5491. this.r = array[offset];
  5492. this.g = array[offset + 1];
  5493. this.b = array[offset + 2];
  5494. return this;
  5495. };
  5496. _proto.toArray = function toArray(array, offset) {
  5497. if (array === void 0) {
  5498. array = [];
  5499. }
  5500. if (offset === void 0) {
  5501. offset = 0;
  5502. }
  5503. array[offset] = this.r;
  5504. array[offset + 1] = this.g;
  5505. array[offset + 2] = this.b;
  5506. return array;
  5507. };
  5508. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  5509. this.r = attribute.getX(index);
  5510. this.g = attribute.getY(index);
  5511. this.b = attribute.getZ(index);
  5512. if (attribute.normalized === true) {
  5513. // assuming Uint8Array
  5514. this.r /= 255;
  5515. this.g /= 255;
  5516. this.b /= 255;
  5517. }
  5518. return this;
  5519. };
  5520. _proto.toJSON = function toJSON() {
  5521. return this.getHex();
  5522. };
  5523. return Color;
  5524. }();
  5525. Color.NAMES = _colorKeywords;
  5526. Color.prototype.r = 1;
  5527. Color.prototype.g = 1;
  5528. Color.prototype.b = 1;
  5529. var Face3 = /*#__PURE__*/function () {
  5530. function Face3(a, b, c, normal, color, materialIndex) {
  5531. this.a = a;
  5532. this.b = b;
  5533. this.c = c;
  5534. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  5535. this.vertexNormals = Array.isArray(normal) ? normal : [];
  5536. this.color = color && color.isColor ? color : new Color();
  5537. this.vertexColors = Array.isArray(color) ? color : [];
  5538. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5539. }
  5540. var _proto = Face3.prototype;
  5541. _proto.clone = function clone() {
  5542. return new this.constructor().copy(this);
  5543. };
  5544. _proto.copy = function copy(source) {
  5545. this.a = source.a;
  5546. this.b = source.b;
  5547. this.c = source.c;
  5548. this.normal.copy(source.normal);
  5549. this.color.copy(source.color);
  5550. this.materialIndex = source.materialIndex;
  5551. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  5552. this.vertexNormals[i] = source.vertexNormals[i].clone();
  5553. }
  5554. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  5555. this.vertexColors[_i] = source.vertexColors[_i].clone();
  5556. }
  5557. return this;
  5558. };
  5559. return Face3;
  5560. }();
  5561. var materialId = 0;
  5562. function Material() {
  5563. Object.defineProperty(this, 'id', {
  5564. value: materialId++
  5565. });
  5566. this.uuid = MathUtils.generateUUID();
  5567. this.name = '';
  5568. this.type = 'Material';
  5569. this.fog = true;
  5570. this.blending = NormalBlending;
  5571. this.side = FrontSide;
  5572. this.flatShading = false;
  5573. this.vertexColors = false;
  5574. this.opacity = 1;
  5575. this.transparent = false;
  5576. this.blendSrc = SrcAlphaFactor;
  5577. this.blendDst = OneMinusSrcAlphaFactor;
  5578. this.blendEquation = AddEquation;
  5579. this.blendSrcAlpha = null;
  5580. this.blendDstAlpha = null;
  5581. this.blendEquationAlpha = null;
  5582. this.depthFunc = LessEqualDepth;
  5583. this.depthTest = true;
  5584. this.depthWrite = true;
  5585. this.stencilWriteMask = 0xff;
  5586. this.stencilFunc = AlwaysStencilFunc;
  5587. this.stencilRef = 0;
  5588. this.stencilFuncMask = 0xff;
  5589. this.stencilFail = KeepStencilOp;
  5590. this.stencilZFail = KeepStencilOp;
  5591. this.stencilZPass = KeepStencilOp;
  5592. this.stencilWrite = false;
  5593. this.clippingPlanes = null;
  5594. this.clipIntersection = false;
  5595. this.clipShadows = false;
  5596. this.shadowSide = null;
  5597. this.colorWrite = true;
  5598. this.precision = null; // override the renderer's default precision for this material
  5599. this.polygonOffset = false;
  5600. this.polygonOffsetFactor = 0;
  5601. this.polygonOffsetUnits = 0;
  5602. this.dithering = false;
  5603. this.alphaTest = 0;
  5604. this.premultipliedAlpha = false;
  5605. this.visible = true;
  5606. this.toneMapped = true;
  5607. this.userData = {};
  5608. this.version = 0;
  5609. }
  5610. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5611. constructor: Material,
  5612. isMaterial: true,
  5613. onBeforeCompile: function onBeforeCompile()
  5614. /* shaderobject, renderer */
  5615. {},
  5616. customProgramCacheKey: function customProgramCacheKey() {
  5617. return this.onBeforeCompile.toString();
  5618. },
  5619. setValues: function setValues(values) {
  5620. if (values === undefined) return;
  5621. for (var key in values) {
  5622. var newValue = values[key];
  5623. if (newValue === undefined) {
  5624. console.warn("THREE.Material: '" + key + "' parameter is undefined.");
  5625. continue;
  5626. } // for backward compatability if shading is set in the constructor
  5627. if (key === 'shading') {
  5628. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5629. this.flatShading = newValue === FlatShading ? true : false;
  5630. continue;
  5631. }
  5632. var currentValue = this[key];
  5633. if (currentValue === undefined) {
  5634. console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material.");
  5635. continue;
  5636. }
  5637. if (currentValue && currentValue.isColor) {
  5638. currentValue.set(newValue);
  5639. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5640. currentValue.copy(newValue);
  5641. } else {
  5642. this[key] = newValue;
  5643. }
  5644. }
  5645. },
  5646. toJSON: function toJSON(meta) {
  5647. var isRoot = meta === undefined || typeof meta === 'string';
  5648. if (isRoot) {
  5649. meta = {
  5650. textures: {},
  5651. images: {}
  5652. };
  5653. }
  5654. var data = {
  5655. metadata: {
  5656. version: 4.5,
  5657. type: 'Material',
  5658. generator: 'Material.toJSON'
  5659. }
  5660. }; // standard Material serialization
  5661. data.uuid = this.uuid;
  5662. data.type = this.type;
  5663. if (this.name !== '') data.name = this.name;
  5664. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5665. if (this.roughness !== undefined) data.roughness = this.roughness;
  5666. if (this.metalness !== undefined) data.metalness = this.metalness;
  5667. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5668. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5669. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5670. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5671. if (this.shininess !== undefined) data.shininess = this.shininess;
  5672. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5673. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5674. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5675. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5676. }
  5677. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5678. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5679. }
  5680. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5681. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5682. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5683. }
  5684. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5685. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5686. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5687. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  5688. if (this.aoMap && this.aoMap.isTexture) {
  5689. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5690. data.aoMapIntensity = this.aoMapIntensity;
  5691. }
  5692. if (this.bumpMap && this.bumpMap.isTexture) {
  5693. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5694. data.bumpScale = this.bumpScale;
  5695. }
  5696. if (this.normalMap && this.normalMap.isTexture) {
  5697. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5698. data.normalMapType = this.normalMapType;
  5699. data.normalScale = this.normalScale.toArray();
  5700. }
  5701. if (this.displacementMap && this.displacementMap.isTexture) {
  5702. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5703. data.displacementScale = this.displacementScale;
  5704. data.displacementBias = this.displacementBias;
  5705. }
  5706. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5707. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5708. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5709. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5710. if (this.envMap && this.envMap.isTexture) {
  5711. data.envMap = this.envMap.toJSON(meta).uuid;
  5712. data.reflectivity = this.reflectivity; // Scale behind envMap
  5713. data.refractionRatio = this.refractionRatio;
  5714. if (this.combine !== undefined) data.combine = this.combine;
  5715. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5716. }
  5717. if (this.gradientMap && this.gradientMap.isTexture) {
  5718. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5719. }
  5720. if (this.size !== undefined) data.size = this.size;
  5721. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5722. if (this.blending !== NormalBlending) data.blending = this.blending;
  5723. if (this.flatShading === true) data.flatShading = this.flatShading;
  5724. if (this.side !== FrontSide) data.side = this.side;
  5725. if (this.vertexColors) data.vertexColors = true;
  5726. if (this.opacity < 1) data.opacity = this.opacity;
  5727. if (this.transparent === true) data.transparent = this.transparent;
  5728. data.depthFunc = this.depthFunc;
  5729. data.depthTest = this.depthTest;
  5730. data.depthWrite = this.depthWrite;
  5731. data.stencilWrite = this.stencilWrite;
  5732. data.stencilWriteMask = this.stencilWriteMask;
  5733. data.stencilFunc = this.stencilFunc;
  5734. data.stencilRef = this.stencilRef;
  5735. data.stencilFuncMask = this.stencilFuncMask;
  5736. data.stencilFail = this.stencilFail;
  5737. data.stencilZFail = this.stencilZFail;
  5738. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5739. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5740. if (this.polygonOffset === true) data.polygonOffset = true;
  5741. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5742. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5743. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5744. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5745. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5746. if (this.scale !== undefined) data.scale = this.scale;
  5747. if (this.dithering === true) data.dithering = true;
  5748. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5749. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5750. if (this.wireframe === true) data.wireframe = this.wireframe;
  5751. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5752. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5753. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5754. if (this.morphTargets === true) data.morphTargets = true;
  5755. if (this.morphNormals === true) data.morphNormals = true;
  5756. if (this.skinning === true) data.skinning = true;
  5757. if (this.visible === false) data.visible = false;
  5758. if (this.toneMapped === false) data.toneMapped = false;
  5759. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5760. function extractFromCache(cache) {
  5761. var values = [];
  5762. for (var key in cache) {
  5763. var _data = cache[key];
  5764. delete _data.metadata;
  5765. values.push(_data);
  5766. }
  5767. return values;
  5768. }
  5769. if (isRoot) {
  5770. var textures = extractFromCache(meta.textures);
  5771. var images = extractFromCache(meta.images);
  5772. if (textures.length > 0) data.textures = textures;
  5773. if (images.length > 0) data.images = images;
  5774. }
  5775. return data;
  5776. },
  5777. clone: function clone() {
  5778. return new this.constructor().copy(this);
  5779. },
  5780. copy: function copy(source) {
  5781. this.name = source.name;
  5782. this.fog = source.fog;
  5783. this.blending = source.blending;
  5784. this.side = source.side;
  5785. this.flatShading = source.flatShading;
  5786. this.vertexColors = source.vertexColors;
  5787. this.opacity = source.opacity;
  5788. this.transparent = source.transparent;
  5789. this.blendSrc = source.blendSrc;
  5790. this.blendDst = source.blendDst;
  5791. this.blendEquation = source.blendEquation;
  5792. this.blendSrcAlpha = source.blendSrcAlpha;
  5793. this.blendDstAlpha = source.blendDstAlpha;
  5794. this.blendEquationAlpha = source.blendEquationAlpha;
  5795. this.depthFunc = source.depthFunc;
  5796. this.depthTest = source.depthTest;
  5797. this.depthWrite = source.depthWrite;
  5798. this.stencilWriteMask = source.stencilWriteMask;
  5799. this.stencilFunc = source.stencilFunc;
  5800. this.stencilRef = source.stencilRef;
  5801. this.stencilFuncMask = source.stencilFuncMask;
  5802. this.stencilFail = source.stencilFail;
  5803. this.stencilZFail = source.stencilZFail;
  5804. this.stencilZPass = source.stencilZPass;
  5805. this.stencilWrite = source.stencilWrite;
  5806. var srcPlanes = source.clippingPlanes;
  5807. var dstPlanes = null;
  5808. if (srcPlanes !== null) {
  5809. var n = srcPlanes.length;
  5810. dstPlanes = new Array(n);
  5811. for (var i = 0; i !== n; ++i) {
  5812. dstPlanes[i] = srcPlanes[i].clone();
  5813. }
  5814. }
  5815. this.clippingPlanes = dstPlanes;
  5816. this.clipIntersection = source.clipIntersection;
  5817. this.clipShadows = source.clipShadows;
  5818. this.shadowSide = source.shadowSide;
  5819. this.colorWrite = source.colorWrite;
  5820. this.precision = source.precision;
  5821. this.polygonOffset = source.polygonOffset;
  5822. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5823. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5824. this.dithering = source.dithering;
  5825. this.alphaTest = source.alphaTest;
  5826. this.premultipliedAlpha = source.premultipliedAlpha;
  5827. this.visible = source.visible;
  5828. this.toneMapped = source.toneMapped;
  5829. this.userData = JSON.parse(JSON.stringify(source.userData));
  5830. return this;
  5831. },
  5832. dispose: function dispose() {
  5833. this.dispatchEvent({
  5834. type: 'dispose'
  5835. });
  5836. }
  5837. });
  5838. Object.defineProperty(Material.prototype, 'needsUpdate', {
  5839. set: function set(value) {
  5840. if (value === true) this.version++;
  5841. }
  5842. });
  5843. /**
  5844. * parameters = {
  5845. * color: <hex>,
  5846. * opacity: <float>,
  5847. * map: new THREE.Texture( <Image> ),
  5848. *
  5849. * lightMap: new THREE.Texture( <Image> ),
  5850. * lightMapIntensity: <float>
  5851. *
  5852. * aoMap: new THREE.Texture( <Image> ),
  5853. * aoMapIntensity: <float>
  5854. *
  5855. * specularMap: new THREE.Texture( <Image> ),
  5856. *
  5857. * alphaMap: new THREE.Texture( <Image> ),
  5858. *
  5859. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5860. * combine: THREE.Multiply,
  5861. * reflectivity: <float>,
  5862. * refractionRatio: <float>,
  5863. *
  5864. * depthTest: <bool>,
  5865. * depthWrite: <bool>,
  5866. *
  5867. * wireframe: <boolean>,
  5868. * wireframeLinewidth: <float>,
  5869. *
  5870. * skinning: <bool>,
  5871. * morphTargets: <bool>
  5872. * }
  5873. */
  5874. function MeshBasicMaterial(parameters) {
  5875. Material.call(this);
  5876. this.type = 'MeshBasicMaterial';
  5877. this.color = new Color(0xffffff); // emissive
  5878. this.map = null;
  5879. this.lightMap = null;
  5880. this.lightMapIntensity = 1.0;
  5881. this.aoMap = null;
  5882. this.aoMapIntensity = 1.0;
  5883. this.specularMap = null;
  5884. this.alphaMap = null;
  5885. this.envMap = null;
  5886. this.combine = MultiplyOperation;
  5887. this.reflectivity = 1;
  5888. this.refractionRatio = 0.98;
  5889. this.wireframe = false;
  5890. this.wireframeLinewidth = 1;
  5891. this.wireframeLinecap = 'round';
  5892. this.wireframeLinejoin = 'round';
  5893. this.skinning = false;
  5894. this.morphTargets = false;
  5895. this.setValues(parameters);
  5896. }
  5897. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  5898. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5899. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5900. MeshBasicMaterial.prototype.copy = function (source) {
  5901. Material.prototype.copy.call(this, source);
  5902. this.color.copy(source.color);
  5903. this.map = source.map;
  5904. this.lightMap = source.lightMap;
  5905. this.lightMapIntensity = source.lightMapIntensity;
  5906. this.aoMap = source.aoMap;
  5907. this.aoMapIntensity = source.aoMapIntensity;
  5908. this.specularMap = source.specularMap;
  5909. this.alphaMap = source.alphaMap;
  5910. this.envMap = source.envMap;
  5911. this.combine = source.combine;
  5912. this.reflectivity = source.reflectivity;
  5913. this.refractionRatio = source.refractionRatio;
  5914. this.wireframe = source.wireframe;
  5915. this.wireframeLinewidth = source.wireframeLinewidth;
  5916. this.wireframeLinecap = source.wireframeLinecap;
  5917. this.wireframeLinejoin = source.wireframeLinejoin;
  5918. this.skinning = source.skinning;
  5919. this.morphTargets = source.morphTargets;
  5920. return this;
  5921. };
  5922. var _vector$3 = new Vector3();
  5923. var _vector2$1 = new Vector2();
  5924. function BufferAttribute(array, itemSize, normalized) {
  5925. if (Array.isArray(array)) {
  5926. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  5927. }
  5928. this.name = '';
  5929. this.array = array;
  5930. this.itemSize = itemSize;
  5931. this.count = array !== undefined ? array.length / itemSize : 0;
  5932. this.normalized = normalized === true;
  5933. this.usage = StaticDrawUsage;
  5934. this.updateRange = {
  5935. offset: 0,
  5936. count: -1
  5937. };
  5938. this.version = 0;
  5939. }
  5940. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  5941. set: function set(value) {
  5942. if (value === true) this.version++;
  5943. }
  5944. });
  5945. Object.assign(BufferAttribute.prototype, {
  5946. isBufferAttribute: true,
  5947. onUploadCallback: function onUploadCallback() {},
  5948. setUsage: function setUsage(value) {
  5949. this.usage = value;
  5950. return this;
  5951. },
  5952. copy: function copy(source) {
  5953. this.name = source.name;
  5954. this.array = new source.array.constructor(source.array);
  5955. this.itemSize = source.itemSize;
  5956. this.count = source.count;
  5957. this.normalized = source.normalized;
  5958. this.usage = source.usage;
  5959. return this;
  5960. },
  5961. copyAt: function copyAt(index1, attribute, index2) {
  5962. index1 *= this.itemSize;
  5963. index2 *= attribute.itemSize;
  5964. for (var i = 0, l = this.itemSize; i < l; i++) {
  5965. this.array[index1 + i] = attribute.array[index2 + i];
  5966. }
  5967. return this;
  5968. },
  5969. copyArray: function copyArray(array) {
  5970. this.array.set(array);
  5971. return this;
  5972. },
  5973. copyColorsArray: function copyColorsArray(colors) {
  5974. var array = this.array;
  5975. var offset = 0;
  5976. for (var i = 0, l = colors.length; i < l; i++) {
  5977. var color = colors[i];
  5978. if (color === undefined) {
  5979. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  5980. color = new Color();
  5981. }
  5982. array[offset++] = color.r;
  5983. array[offset++] = color.g;
  5984. array[offset++] = color.b;
  5985. }
  5986. return this;
  5987. },
  5988. copyVector2sArray: function copyVector2sArray(vectors) {
  5989. var array = this.array;
  5990. var offset = 0;
  5991. for (var i = 0, l = vectors.length; i < l; i++) {
  5992. var vector = vectors[i];
  5993. if (vector === undefined) {
  5994. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  5995. vector = new Vector2();
  5996. }
  5997. array[offset++] = vector.x;
  5998. array[offset++] = vector.y;
  5999. }
  6000. return this;
  6001. },
  6002. copyVector3sArray: function copyVector3sArray(vectors) {
  6003. var array = this.array;
  6004. var offset = 0;
  6005. for (var i = 0, l = vectors.length; i < l; i++) {
  6006. var vector = vectors[i];
  6007. if (vector === undefined) {
  6008. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6009. vector = new Vector3();
  6010. }
  6011. array[offset++] = vector.x;
  6012. array[offset++] = vector.y;
  6013. array[offset++] = vector.z;
  6014. }
  6015. return this;
  6016. },
  6017. copyVector4sArray: function copyVector4sArray(vectors) {
  6018. var array = this.array;
  6019. var offset = 0;
  6020. for (var i = 0, l = vectors.length; i < l; i++) {
  6021. var vector = vectors[i];
  6022. if (vector === undefined) {
  6023. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6024. vector = new Vector4();
  6025. }
  6026. array[offset++] = vector.x;
  6027. array[offset++] = vector.y;
  6028. array[offset++] = vector.z;
  6029. array[offset++] = vector.w;
  6030. }
  6031. return this;
  6032. },
  6033. applyMatrix3: function applyMatrix3(m) {
  6034. if (this.itemSize === 2) {
  6035. for (var i = 0, l = this.count; i < l; i++) {
  6036. _vector2$1.fromBufferAttribute(this, i);
  6037. _vector2$1.applyMatrix3(m);
  6038. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6039. }
  6040. } else if (this.itemSize === 3) {
  6041. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6042. _vector$3.fromBufferAttribute(this, _i);
  6043. _vector$3.applyMatrix3(m);
  6044. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6045. }
  6046. }
  6047. return this;
  6048. },
  6049. applyMatrix4: function applyMatrix4(m) {
  6050. for (var i = 0, l = this.count; i < l; i++) {
  6051. _vector$3.x = this.getX(i);
  6052. _vector$3.y = this.getY(i);
  6053. _vector$3.z = this.getZ(i);
  6054. _vector$3.applyMatrix4(m);
  6055. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6056. }
  6057. return this;
  6058. },
  6059. applyNormalMatrix: function applyNormalMatrix(m) {
  6060. for (var i = 0, l = this.count; i < l; i++) {
  6061. _vector$3.x = this.getX(i);
  6062. _vector$3.y = this.getY(i);
  6063. _vector$3.z = this.getZ(i);
  6064. _vector$3.applyNormalMatrix(m);
  6065. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6066. }
  6067. return this;
  6068. },
  6069. transformDirection: function transformDirection(m) {
  6070. for (var i = 0, l = this.count; i < l; i++) {
  6071. _vector$3.x = this.getX(i);
  6072. _vector$3.y = this.getY(i);
  6073. _vector$3.z = this.getZ(i);
  6074. _vector$3.transformDirection(m);
  6075. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6076. }
  6077. return this;
  6078. },
  6079. set: function set(value, offset) {
  6080. if (offset === undefined) offset = 0;
  6081. this.array.set(value, offset);
  6082. return this;
  6083. },
  6084. getX: function getX(index) {
  6085. return this.array[index * this.itemSize];
  6086. },
  6087. setX: function setX(index, x) {
  6088. this.array[index * this.itemSize] = x;
  6089. return this;
  6090. },
  6091. getY: function getY(index) {
  6092. return this.array[index * this.itemSize + 1];
  6093. },
  6094. setY: function setY(index, y) {
  6095. this.array[index * this.itemSize + 1] = y;
  6096. return this;
  6097. },
  6098. getZ: function getZ(index) {
  6099. return this.array[index * this.itemSize + 2];
  6100. },
  6101. setZ: function setZ(index, z) {
  6102. this.array[index * this.itemSize + 2] = z;
  6103. return this;
  6104. },
  6105. getW: function getW(index) {
  6106. return this.array[index * this.itemSize + 3];
  6107. },
  6108. setW: function setW(index, w) {
  6109. this.array[index * this.itemSize + 3] = w;
  6110. return this;
  6111. },
  6112. setXY: function setXY(index, x, y) {
  6113. index *= this.itemSize;
  6114. this.array[index + 0] = x;
  6115. this.array[index + 1] = y;
  6116. return this;
  6117. },
  6118. setXYZ: function setXYZ(index, x, y, z) {
  6119. index *= this.itemSize;
  6120. this.array[index + 0] = x;
  6121. this.array[index + 1] = y;
  6122. this.array[index + 2] = z;
  6123. return this;
  6124. },
  6125. setXYZW: function setXYZW(index, x, y, z, w) {
  6126. index *= this.itemSize;
  6127. this.array[index + 0] = x;
  6128. this.array[index + 1] = y;
  6129. this.array[index + 2] = z;
  6130. this.array[index + 3] = w;
  6131. return this;
  6132. },
  6133. onUpload: function onUpload(callback) {
  6134. this.onUploadCallback = callback;
  6135. return this;
  6136. },
  6137. clone: function clone() {
  6138. return new this.constructor(this.array, this.itemSize).copy(this);
  6139. },
  6140. toJSON: function toJSON() {
  6141. return {
  6142. itemSize: this.itemSize,
  6143. type: this.array.constructor.name,
  6144. array: Array.prototype.slice.call(this.array),
  6145. normalized: this.normalized
  6146. };
  6147. }
  6148. }); //
  6149. function Int8BufferAttribute(array, itemSize, normalized) {
  6150. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6151. }
  6152. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6153. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6154. function Uint8BufferAttribute(array, itemSize, normalized) {
  6155. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6156. }
  6157. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6158. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6159. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6160. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6161. }
  6162. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6163. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6164. function Int16BufferAttribute(array, itemSize, normalized) {
  6165. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6166. }
  6167. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6168. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6169. function Uint16BufferAttribute(array, itemSize, normalized) {
  6170. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6171. }
  6172. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6173. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6174. function Int32BufferAttribute(array, itemSize, normalized) {
  6175. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6176. }
  6177. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6178. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6179. function Uint32BufferAttribute(array, itemSize, normalized) {
  6180. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6181. }
  6182. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6183. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6184. function Float32BufferAttribute(array, itemSize, normalized) {
  6185. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6186. }
  6187. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6188. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6189. function Float64BufferAttribute(array, itemSize, normalized) {
  6190. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6191. }
  6192. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6193. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6194. var DirectGeometry = /*#__PURE__*/function () {
  6195. function DirectGeometry() {
  6196. this.vertices = [];
  6197. this.normals = [];
  6198. this.colors = [];
  6199. this.uvs = [];
  6200. this.uvs2 = [];
  6201. this.groups = [];
  6202. this.morphTargets = {};
  6203. this.skinWeights = [];
  6204. this.skinIndices = []; // this.lineDistances = [];
  6205. this.boundingBox = null;
  6206. this.boundingSphere = null; // update flags
  6207. this.verticesNeedUpdate = false;
  6208. this.normalsNeedUpdate = false;
  6209. this.colorsNeedUpdate = false;
  6210. this.uvsNeedUpdate = false;
  6211. this.groupsNeedUpdate = false;
  6212. }
  6213. var _proto = DirectGeometry.prototype;
  6214. _proto.computeGroups = function computeGroups(geometry) {
  6215. var groups = [];
  6216. var group, i;
  6217. var materialIndex = undefined;
  6218. var faces = geometry.faces;
  6219. for (i = 0; i < faces.length; i++) {
  6220. var face = faces[i]; // materials
  6221. if (face.materialIndex !== materialIndex) {
  6222. materialIndex = face.materialIndex;
  6223. if (group !== undefined) {
  6224. group.count = i * 3 - group.start;
  6225. groups.push(group);
  6226. }
  6227. group = {
  6228. start: i * 3,
  6229. materialIndex: materialIndex
  6230. };
  6231. }
  6232. }
  6233. if (group !== undefined) {
  6234. group.count = i * 3 - group.start;
  6235. groups.push(group);
  6236. }
  6237. this.groups = groups;
  6238. };
  6239. _proto.fromGeometry = function fromGeometry(geometry) {
  6240. var faces = geometry.faces;
  6241. var vertices = geometry.vertices;
  6242. var faceVertexUvs = geometry.faceVertexUvs;
  6243. var hasFaceVertexUv = faceVertexUvs[0] && faceVertexUvs[0].length > 0;
  6244. var hasFaceVertexUv2 = faceVertexUvs[1] && faceVertexUvs[1].length > 0; // morphs
  6245. var morphTargets = geometry.morphTargets;
  6246. var morphTargetsLength = morphTargets.length;
  6247. var morphTargetsPosition;
  6248. if (morphTargetsLength > 0) {
  6249. morphTargetsPosition = [];
  6250. for (var i = 0; i < morphTargetsLength; i++) {
  6251. morphTargetsPosition[i] = {
  6252. name: morphTargets[i].name,
  6253. data: []
  6254. };
  6255. }
  6256. this.morphTargets.position = morphTargetsPosition;
  6257. }
  6258. var morphNormals = geometry.morphNormals;
  6259. var morphNormalsLength = morphNormals.length;
  6260. var morphTargetsNormal;
  6261. if (morphNormalsLength > 0) {
  6262. morphTargetsNormal = [];
  6263. for (var _i = 0; _i < morphNormalsLength; _i++) {
  6264. morphTargetsNormal[_i] = {
  6265. name: morphNormals[_i].name,
  6266. data: []
  6267. };
  6268. }
  6269. this.morphTargets.normal = morphTargetsNormal;
  6270. } // skins
  6271. var skinIndices = geometry.skinIndices;
  6272. var skinWeights = geometry.skinWeights;
  6273. var hasSkinIndices = skinIndices.length === vertices.length;
  6274. var hasSkinWeights = skinWeights.length === vertices.length; //
  6275. if (vertices.length > 0 && faces.length === 0) {
  6276. console.error('THREE.DirectGeometry: Faceless geometries are not supported.');
  6277. }
  6278. for (var _i2 = 0; _i2 < faces.length; _i2++) {
  6279. var face = faces[_i2];
  6280. this.vertices.push(vertices[face.a], vertices[face.b], vertices[face.c]);
  6281. var vertexNormals = face.vertexNormals;
  6282. if (vertexNormals.length === 3) {
  6283. this.normals.push(vertexNormals[0], vertexNormals[1], vertexNormals[2]);
  6284. } else {
  6285. var normal = face.normal;
  6286. this.normals.push(normal, normal, normal);
  6287. }
  6288. var vertexColors = face.vertexColors;
  6289. if (vertexColors.length === 3) {
  6290. this.colors.push(vertexColors[0], vertexColors[1], vertexColors[2]);
  6291. } else {
  6292. var color = face.color;
  6293. this.colors.push(color, color, color);
  6294. }
  6295. if (hasFaceVertexUv === true) {
  6296. var vertexUvs = faceVertexUvs[0][_i2];
  6297. if (vertexUvs !== undefined) {
  6298. this.uvs.push(vertexUvs[0], vertexUvs[1], vertexUvs[2]);
  6299. } else {
  6300. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', _i2);
  6301. this.uvs.push(new Vector2(), new Vector2(), new Vector2());
  6302. }
  6303. }
  6304. if (hasFaceVertexUv2 === true) {
  6305. var _vertexUvs = faceVertexUvs[1][_i2];
  6306. if (_vertexUvs !== undefined) {
  6307. this.uvs2.push(_vertexUvs[0], _vertexUvs[1], _vertexUvs[2]);
  6308. } else {
  6309. console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', _i2);
  6310. this.uvs2.push(new Vector2(), new Vector2(), new Vector2());
  6311. }
  6312. } // morphs
  6313. for (var j = 0; j < morphTargetsLength; j++) {
  6314. var morphTarget = morphTargets[j].vertices;
  6315. morphTargetsPosition[j].data.push(morphTarget[face.a], morphTarget[face.b], morphTarget[face.c]);
  6316. }
  6317. for (var _j = 0; _j < morphNormalsLength; _j++) {
  6318. var morphNormal = morphNormals[_j].vertexNormals[_i2];
  6319. morphTargetsNormal[_j].data.push(morphNormal.a, morphNormal.b, morphNormal.c);
  6320. } // skins
  6321. if (hasSkinIndices) {
  6322. this.skinIndices.push(skinIndices[face.a], skinIndices[face.b], skinIndices[face.c]);
  6323. }
  6324. if (hasSkinWeights) {
  6325. this.skinWeights.push(skinWeights[face.a], skinWeights[face.b], skinWeights[face.c]);
  6326. }
  6327. }
  6328. this.computeGroups(geometry);
  6329. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6330. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6331. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6332. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6333. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6334. if (geometry.boundingSphere !== null) {
  6335. this.boundingSphere = geometry.boundingSphere.clone();
  6336. }
  6337. if (geometry.boundingBox !== null) {
  6338. this.boundingBox = geometry.boundingBox.clone();
  6339. }
  6340. return this;
  6341. };
  6342. return DirectGeometry;
  6343. }();
  6344. function arrayMax(array) {
  6345. if (array.length === 0) return -Infinity;
  6346. var max = array[0];
  6347. for (var i = 1, l = array.length; i < l; ++i) {
  6348. if (array[i] > max) max = array[i];
  6349. }
  6350. return max;
  6351. }
  6352. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6353. var _m1$2 = new Matrix4();
  6354. var _obj = new Object3D();
  6355. var _offset = new Vector3();
  6356. var _box$2 = new Box3();
  6357. var _boxMorphTargets = new Box3();
  6358. var _vector$4 = new Vector3();
  6359. function BufferGeometry() {
  6360. Object.defineProperty(this, 'id', {
  6361. value: _bufferGeometryId += 2
  6362. });
  6363. this.uuid = MathUtils.generateUUID();
  6364. this.name = '';
  6365. this.type = 'BufferGeometry';
  6366. this.index = null;
  6367. this.attributes = {};
  6368. this.morphAttributes = {};
  6369. this.morphTargetsRelative = false;
  6370. this.groups = [];
  6371. this.boundingBox = null;
  6372. this.boundingSphere = null;
  6373. this.drawRange = {
  6374. start: 0,
  6375. count: Infinity
  6376. };
  6377. this.userData = {};
  6378. }
  6379. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6380. constructor: BufferGeometry,
  6381. isBufferGeometry: true,
  6382. getIndex: function getIndex() {
  6383. return this.index;
  6384. },
  6385. setIndex: function setIndex(index) {
  6386. if (Array.isArray(index)) {
  6387. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  6388. } else {
  6389. this.index = index;
  6390. }
  6391. return this;
  6392. },
  6393. getAttribute: function getAttribute(name) {
  6394. return this.attributes[name];
  6395. },
  6396. setAttribute: function setAttribute(name, attribute) {
  6397. this.attributes[name] = attribute;
  6398. return this;
  6399. },
  6400. deleteAttribute: function deleteAttribute(name) {
  6401. delete this.attributes[name];
  6402. return this;
  6403. },
  6404. addGroup: function addGroup(start, count, materialIndex) {
  6405. this.groups.push({
  6406. start: start,
  6407. count: count,
  6408. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6409. });
  6410. },
  6411. clearGroups: function clearGroups() {
  6412. this.groups = [];
  6413. },
  6414. setDrawRange: function setDrawRange(start, count) {
  6415. this.drawRange.start = start;
  6416. this.drawRange.count = count;
  6417. },
  6418. applyMatrix4: function applyMatrix4(matrix) {
  6419. var position = this.attributes.position;
  6420. if (position !== undefined) {
  6421. position.applyMatrix4(matrix);
  6422. position.needsUpdate = true;
  6423. }
  6424. var normal = this.attributes.normal;
  6425. if (normal !== undefined) {
  6426. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  6427. normal.applyNormalMatrix(normalMatrix);
  6428. normal.needsUpdate = true;
  6429. }
  6430. var tangent = this.attributes.tangent;
  6431. if (tangent !== undefined) {
  6432. tangent.transformDirection(matrix);
  6433. tangent.needsUpdate = true;
  6434. }
  6435. if (this.boundingBox !== null) {
  6436. this.computeBoundingBox();
  6437. }
  6438. if (this.boundingSphere !== null) {
  6439. this.computeBoundingSphere();
  6440. }
  6441. return this;
  6442. },
  6443. rotateX: function rotateX(angle) {
  6444. // rotate geometry around world x-axis
  6445. _m1$2.makeRotationX(angle);
  6446. this.applyMatrix4(_m1$2);
  6447. return this;
  6448. },
  6449. rotateY: function rotateY(angle) {
  6450. // rotate geometry around world y-axis
  6451. _m1$2.makeRotationY(angle);
  6452. this.applyMatrix4(_m1$2);
  6453. return this;
  6454. },
  6455. rotateZ: function rotateZ(angle) {
  6456. // rotate geometry around world z-axis
  6457. _m1$2.makeRotationZ(angle);
  6458. this.applyMatrix4(_m1$2);
  6459. return this;
  6460. },
  6461. translate: function translate(x, y, z) {
  6462. // translate geometry
  6463. _m1$2.makeTranslation(x, y, z);
  6464. this.applyMatrix4(_m1$2);
  6465. return this;
  6466. },
  6467. scale: function scale(x, y, z) {
  6468. // scale geometry
  6469. _m1$2.makeScale(x, y, z);
  6470. this.applyMatrix4(_m1$2);
  6471. return this;
  6472. },
  6473. lookAt: function lookAt(vector) {
  6474. _obj.lookAt(vector);
  6475. _obj.updateMatrix();
  6476. this.applyMatrix4(_obj.matrix);
  6477. return this;
  6478. },
  6479. center: function center() {
  6480. this.computeBoundingBox();
  6481. this.boundingBox.getCenter(_offset).negate();
  6482. this.translate(_offset.x, _offset.y, _offset.z);
  6483. return this;
  6484. },
  6485. setFromObject: function setFromObject(object) {
  6486. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6487. var geometry = object.geometry;
  6488. if (object.isPoints || object.isLine) {
  6489. var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
  6490. var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
  6491. this.setAttribute('position', positions.copyVector3sArray(geometry.vertices));
  6492. this.setAttribute('color', colors.copyColorsArray(geometry.colors));
  6493. if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
  6494. var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
  6495. this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
  6496. }
  6497. if (geometry.boundingSphere !== null) {
  6498. this.boundingSphere = geometry.boundingSphere.clone();
  6499. }
  6500. if (geometry.boundingBox !== null) {
  6501. this.boundingBox = geometry.boundingBox.clone();
  6502. }
  6503. } else if (object.isMesh) {
  6504. if (geometry && geometry.isGeometry) {
  6505. this.fromGeometry(geometry);
  6506. }
  6507. }
  6508. return this;
  6509. },
  6510. setFromPoints: function setFromPoints(points) {
  6511. var position = [];
  6512. for (var i = 0, l = points.length; i < l; i++) {
  6513. var point = points[i];
  6514. position.push(point.x, point.y, point.z || 0);
  6515. }
  6516. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  6517. return this;
  6518. },
  6519. updateFromObject: function updateFromObject(object) {
  6520. var geometry = object.geometry;
  6521. if (object.isMesh) {
  6522. var direct = geometry.__directGeometry;
  6523. if (geometry.elementsNeedUpdate === true) {
  6524. direct = undefined;
  6525. geometry.elementsNeedUpdate = false;
  6526. }
  6527. if (direct === undefined) {
  6528. return this.fromGeometry(geometry);
  6529. }
  6530. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6531. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6532. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6533. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6534. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6535. geometry.verticesNeedUpdate = false;
  6536. geometry.normalsNeedUpdate = false;
  6537. geometry.colorsNeedUpdate = false;
  6538. geometry.uvsNeedUpdate = false;
  6539. geometry.groupsNeedUpdate = false;
  6540. geometry = direct;
  6541. }
  6542. if (geometry.verticesNeedUpdate === true) {
  6543. var attribute = this.attributes.position;
  6544. if (attribute !== undefined) {
  6545. attribute.copyVector3sArray(geometry.vertices);
  6546. attribute.needsUpdate = true;
  6547. }
  6548. geometry.verticesNeedUpdate = false;
  6549. }
  6550. if (geometry.normalsNeedUpdate === true) {
  6551. var _attribute = this.attributes.normal;
  6552. if (_attribute !== undefined) {
  6553. _attribute.copyVector3sArray(geometry.normals);
  6554. _attribute.needsUpdate = true;
  6555. }
  6556. geometry.normalsNeedUpdate = false;
  6557. }
  6558. if (geometry.colorsNeedUpdate === true) {
  6559. var _attribute2 = this.attributes.color;
  6560. if (_attribute2 !== undefined) {
  6561. _attribute2.copyColorsArray(geometry.colors);
  6562. _attribute2.needsUpdate = true;
  6563. }
  6564. geometry.colorsNeedUpdate = false;
  6565. }
  6566. if (geometry.uvsNeedUpdate) {
  6567. var _attribute3 = this.attributes.uv;
  6568. if (_attribute3 !== undefined) {
  6569. _attribute3.copyVector2sArray(geometry.uvs);
  6570. _attribute3.needsUpdate = true;
  6571. }
  6572. geometry.uvsNeedUpdate = false;
  6573. }
  6574. if (geometry.lineDistancesNeedUpdate) {
  6575. var _attribute4 = this.attributes.lineDistance;
  6576. if (_attribute4 !== undefined) {
  6577. _attribute4.copyArray(geometry.lineDistances);
  6578. _attribute4.needsUpdate = true;
  6579. }
  6580. geometry.lineDistancesNeedUpdate = false;
  6581. }
  6582. if (geometry.groupsNeedUpdate) {
  6583. geometry.computeGroups(object.geometry);
  6584. this.groups = geometry.groups;
  6585. geometry.groupsNeedUpdate = false;
  6586. }
  6587. return this;
  6588. },
  6589. fromGeometry: function fromGeometry(geometry) {
  6590. geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
  6591. return this.fromDirectGeometry(geometry.__directGeometry);
  6592. },
  6593. fromDirectGeometry: function fromDirectGeometry(geometry) {
  6594. var positions = new Float32Array(geometry.vertices.length * 3);
  6595. this.setAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(geometry.vertices));
  6596. if (geometry.normals.length > 0) {
  6597. var normals = new Float32Array(geometry.normals.length * 3);
  6598. this.setAttribute('normal', new BufferAttribute(normals, 3).copyVector3sArray(geometry.normals));
  6599. }
  6600. if (geometry.colors.length > 0) {
  6601. var colors = new Float32Array(geometry.colors.length * 3);
  6602. this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
  6603. }
  6604. if (geometry.uvs.length > 0) {
  6605. var uvs = new Float32Array(geometry.uvs.length * 2);
  6606. this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVector2sArray(geometry.uvs));
  6607. }
  6608. if (geometry.uvs2.length > 0) {
  6609. var uvs2 = new Float32Array(geometry.uvs2.length * 2);
  6610. this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVector2sArray(geometry.uvs2));
  6611. } // groups
  6612. this.groups = geometry.groups; // morphs
  6613. for (var name in geometry.morphTargets) {
  6614. var array = [];
  6615. var morphTargets = geometry.morphTargets[name];
  6616. for (var i = 0, l = morphTargets.length; i < l; i++) {
  6617. var morphTarget = morphTargets[i];
  6618. var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
  6619. attribute.name = morphTarget.name;
  6620. array.push(attribute.copyVector3sArray(morphTarget.data));
  6621. }
  6622. this.morphAttributes[name] = array;
  6623. } // skinning
  6624. if (geometry.skinIndices.length > 0) {
  6625. var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
  6626. this.setAttribute('skinIndex', skinIndices.copyVector4sArray(geometry.skinIndices));
  6627. }
  6628. if (geometry.skinWeights.length > 0) {
  6629. var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
  6630. this.setAttribute('skinWeight', skinWeights.copyVector4sArray(geometry.skinWeights));
  6631. } //
  6632. if (geometry.boundingSphere !== null) {
  6633. this.boundingSphere = geometry.boundingSphere.clone();
  6634. }
  6635. if (geometry.boundingBox !== null) {
  6636. this.boundingBox = geometry.boundingBox.clone();
  6637. }
  6638. return this;
  6639. },
  6640. computeBoundingBox: function computeBoundingBox() {
  6641. if (this.boundingBox === null) {
  6642. this.boundingBox = new Box3();
  6643. }
  6644. var position = this.attributes.position;
  6645. var morphAttributesPosition = this.morphAttributes.position;
  6646. if (position && position.isGLBufferAttribute) {
  6647. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  6648. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  6649. return;
  6650. }
  6651. if (position !== undefined) {
  6652. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  6653. if (morphAttributesPosition) {
  6654. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6655. var morphAttribute = morphAttributesPosition[i];
  6656. _box$2.setFromBufferAttribute(morphAttribute);
  6657. if (this.morphTargetsRelative) {
  6658. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  6659. this.boundingBox.expandByPoint(_vector$4);
  6660. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  6661. this.boundingBox.expandByPoint(_vector$4);
  6662. } else {
  6663. this.boundingBox.expandByPoint(_box$2.min);
  6664. this.boundingBox.expandByPoint(_box$2.max);
  6665. }
  6666. }
  6667. }
  6668. } else {
  6669. this.boundingBox.makeEmpty();
  6670. }
  6671. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  6672. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  6673. }
  6674. },
  6675. computeBoundingSphere: function computeBoundingSphere() {
  6676. if (this.boundingSphere === null) {
  6677. this.boundingSphere = new Sphere();
  6678. }
  6679. var position = this.attributes.position;
  6680. var morphAttributesPosition = this.morphAttributes.position;
  6681. if (position && position.isGLBufferAttribute) {
  6682. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  6683. this.boundingSphere.set(new Vector3(), Infinity);
  6684. return;
  6685. }
  6686. if (position) {
  6687. // first, find the center of the bounding sphere
  6688. var center = this.boundingSphere.center;
  6689. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  6690. if (morphAttributesPosition) {
  6691. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  6692. var morphAttribute = morphAttributesPosition[i];
  6693. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  6694. if (this.morphTargetsRelative) {
  6695. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  6696. _box$2.expandByPoint(_vector$4);
  6697. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  6698. _box$2.expandByPoint(_vector$4);
  6699. } else {
  6700. _box$2.expandByPoint(_boxMorphTargets.min);
  6701. _box$2.expandByPoint(_boxMorphTargets.max);
  6702. }
  6703. }
  6704. }
  6705. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  6706. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6707. var maxRadiusSq = 0;
  6708. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  6709. _vector$4.fromBufferAttribute(position, _i);
  6710. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6711. } // process morph attributes if present
  6712. if (morphAttributesPosition) {
  6713. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  6714. var _morphAttribute = morphAttributesPosition[_i2];
  6715. var morphTargetsRelative = this.morphTargetsRelative;
  6716. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  6717. _vector$4.fromBufferAttribute(_morphAttribute, j);
  6718. if (morphTargetsRelative) {
  6719. _offset.fromBufferAttribute(position, j);
  6720. _vector$4.add(_offset);
  6721. }
  6722. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  6723. }
  6724. }
  6725. }
  6726. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  6727. if (isNaN(this.boundingSphere.radius)) {
  6728. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  6729. }
  6730. }
  6731. },
  6732. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  6733. },
  6734. computeVertexNormals: function computeVertexNormals() {
  6735. var index = this.index;
  6736. var positionAttribute = this.getAttribute('position');
  6737. if (positionAttribute !== undefined) {
  6738. var normalAttribute = this.getAttribute('normal');
  6739. if (normalAttribute === undefined) {
  6740. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  6741. this.setAttribute('normal', normalAttribute);
  6742. } else {
  6743. // reset existing normals to zero
  6744. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  6745. normalAttribute.setXYZ(i, 0, 0, 0);
  6746. }
  6747. }
  6748. var pA = new Vector3(),
  6749. pB = new Vector3(),
  6750. pC = new Vector3();
  6751. var nA = new Vector3(),
  6752. nB = new Vector3(),
  6753. nC = new Vector3();
  6754. var cb = new Vector3(),
  6755. ab = new Vector3(); // indexed elements
  6756. if (index) {
  6757. for (var _i3 = 0, _il3 = index.count; _i3 < _il3; _i3 += 3) {
  6758. var vA = index.getX(_i3 + 0);
  6759. var vB = index.getX(_i3 + 1);
  6760. var vC = index.getX(_i3 + 2);
  6761. pA.fromBufferAttribute(positionAttribute, vA);
  6762. pB.fromBufferAttribute(positionAttribute, vB);
  6763. pC.fromBufferAttribute(positionAttribute, vC);
  6764. cb.subVectors(pC, pB);
  6765. ab.subVectors(pA, pB);
  6766. cb.cross(ab);
  6767. nA.fromBufferAttribute(normalAttribute, vA);
  6768. nB.fromBufferAttribute(normalAttribute, vB);
  6769. nC.fromBufferAttribute(normalAttribute, vC);
  6770. nA.add(cb);
  6771. nB.add(cb);
  6772. nC.add(cb);
  6773. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  6774. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  6775. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  6776. }
  6777. } else {
  6778. // non-indexed elements (unconnected triangle soup)
  6779. for (var _i4 = 0, _il4 = positionAttribute.count; _i4 < _il4; _i4 += 3) {
  6780. pA.fromBufferAttribute(positionAttribute, _i4 + 0);
  6781. pB.fromBufferAttribute(positionAttribute, _i4 + 1);
  6782. pC.fromBufferAttribute(positionAttribute, _i4 + 2);
  6783. cb.subVectors(pC, pB);
  6784. ab.subVectors(pA, pB);
  6785. cb.cross(ab);
  6786. normalAttribute.setXYZ(_i4 + 0, cb.x, cb.y, cb.z);
  6787. normalAttribute.setXYZ(_i4 + 1, cb.x, cb.y, cb.z);
  6788. normalAttribute.setXYZ(_i4 + 2, cb.x, cb.y, cb.z);
  6789. }
  6790. }
  6791. this.normalizeNormals();
  6792. normalAttribute.needsUpdate = true;
  6793. }
  6794. },
  6795. merge: function merge(geometry, offset) {
  6796. if (!(geometry && geometry.isBufferGeometry)) {
  6797. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  6798. return;
  6799. }
  6800. if (offset === undefined) {
  6801. offset = 0;
  6802. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  6803. }
  6804. var attributes = this.attributes;
  6805. for (var key in attributes) {
  6806. if (geometry.attributes[key] === undefined) continue;
  6807. var attribute1 = attributes[key];
  6808. var attributeArray1 = attribute1.array;
  6809. var attribute2 = geometry.attributes[key];
  6810. var attributeArray2 = attribute2.array;
  6811. var attributeOffset = attribute2.itemSize * offset;
  6812. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  6813. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  6814. attributeArray1[j] = attributeArray2[i];
  6815. }
  6816. }
  6817. return this;
  6818. },
  6819. normalizeNormals: function normalizeNormals() {
  6820. var normals = this.attributes.normal;
  6821. for (var i = 0, il = normals.count; i < il; i++) {
  6822. _vector$4.fromBufferAttribute(normals, i);
  6823. _vector$4.normalize();
  6824. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  6825. }
  6826. },
  6827. toNonIndexed: function toNonIndexed() {
  6828. function convertBufferAttribute(attribute, indices) {
  6829. var array = attribute.array;
  6830. var itemSize = attribute.itemSize;
  6831. var normalized = attribute.normalized;
  6832. var array2 = new array.constructor(indices.length * itemSize);
  6833. var index = 0,
  6834. index2 = 0;
  6835. for (var i = 0, l = indices.length; i < l; i++) {
  6836. index = indices[i] * itemSize;
  6837. for (var j = 0; j < itemSize; j++) {
  6838. array2[index2++] = array[index++];
  6839. }
  6840. }
  6841. return new BufferAttribute(array2, itemSize, normalized);
  6842. } //
  6843. if (this.index === null) {
  6844. console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
  6845. return this;
  6846. }
  6847. var geometry2 = new BufferGeometry();
  6848. var indices = this.index.array;
  6849. var attributes = this.attributes; // attributes
  6850. for (var name in attributes) {
  6851. var attribute = attributes[name];
  6852. var newAttribute = convertBufferAttribute(attribute, indices);
  6853. geometry2.setAttribute(name, newAttribute);
  6854. } // morph attributes
  6855. var morphAttributes = this.morphAttributes;
  6856. for (var _name in morphAttributes) {
  6857. var morphArray = [];
  6858. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  6859. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  6860. var _attribute5 = morphAttribute[i];
  6861. var _newAttribute = convertBufferAttribute(_attribute5, indices);
  6862. morphArray.push(_newAttribute);
  6863. }
  6864. geometry2.morphAttributes[_name] = morphArray;
  6865. }
  6866. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  6867. var groups = this.groups;
  6868. for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
  6869. var group = groups[_i5];
  6870. geometry2.addGroup(group.start, group.count, group.materialIndex);
  6871. }
  6872. return geometry2;
  6873. },
  6874. toJSON: function toJSON() {
  6875. var data = {
  6876. metadata: {
  6877. version: 4.5,
  6878. type: 'BufferGeometry',
  6879. generator: 'BufferGeometry.toJSON'
  6880. }
  6881. }; // standard BufferGeometry serialization
  6882. data.uuid = this.uuid;
  6883. data.type = this.type;
  6884. if (this.name !== '') data.name = this.name;
  6885. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  6886. if (this.parameters !== undefined) {
  6887. var parameters = this.parameters;
  6888. for (var key in parameters) {
  6889. if (parameters[key] !== undefined) data[key] = parameters[key];
  6890. }
  6891. return data;
  6892. }
  6893. data.data = {
  6894. attributes: {}
  6895. };
  6896. var index = this.index;
  6897. if (index !== null) {
  6898. data.data.index = {
  6899. type: index.array.constructor.name,
  6900. array: Array.prototype.slice.call(index.array)
  6901. };
  6902. }
  6903. var attributes = this.attributes;
  6904. for (var _key in attributes) {
  6905. var attribute = attributes[_key];
  6906. var attributeData = attribute.toJSON(data.data);
  6907. if (attribute.name !== '') attributeData.name = attribute.name;
  6908. data.data.attributes[_key] = attributeData;
  6909. }
  6910. var morphAttributes = {};
  6911. var hasMorphAttributes = false;
  6912. for (var _key2 in this.morphAttributes) {
  6913. var attributeArray = this.morphAttributes[_key2];
  6914. var array = [];
  6915. for (var i = 0, il = attributeArray.length; i < il; i++) {
  6916. var _attribute6 = attributeArray[i];
  6917. var _attributeData = _attribute6.toJSON(data.data);
  6918. if (_attribute6.name !== '') _attributeData.name = _attribute6.name;
  6919. array.push(_attributeData);
  6920. }
  6921. if (array.length > 0) {
  6922. morphAttributes[_key2] = array;
  6923. hasMorphAttributes = true;
  6924. }
  6925. }
  6926. if (hasMorphAttributes) {
  6927. data.data.morphAttributes = morphAttributes;
  6928. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6929. }
  6930. var groups = this.groups;
  6931. if (groups.length > 0) {
  6932. data.data.groups = JSON.parse(JSON.stringify(groups));
  6933. }
  6934. var boundingSphere = this.boundingSphere;
  6935. if (boundingSphere !== null) {
  6936. data.data.boundingSphere = {
  6937. center: boundingSphere.center.toArray(),
  6938. radius: boundingSphere.radius
  6939. };
  6940. }
  6941. return data;
  6942. },
  6943. clone: function clone() {
  6944. /*
  6945. // Handle primitives
  6946. const parameters = this.parameters;
  6947. if ( parameters !== undefined ) {
  6948. const values = [];
  6949. for ( const key in parameters ) {
  6950. values.push( parameters[ key ] );
  6951. }
  6952. const geometry = Object.create( this.constructor.prototype );
  6953. this.constructor.apply( geometry, values );
  6954. return geometry;
  6955. }
  6956. return new this.constructor().copy( this );
  6957. */
  6958. return new BufferGeometry().copy(this);
  6959. },
  6960. copy: function copy(source) {
  6961. // reset
  6962. this.index = null;
  6963. this.attributes = {};
  6964. this.morphAttributes = {};
  6965. this.groups = [];
  6966. this.boundingBox = null;
  6967. this.boundingSphere = null; // used for storing cloned, shared data
  6968. var data = {}; // name
  6969. this.name = source.name; // index
  6970. var index = source.index;
  6971. if (index !== null) {
  6972. this.setIndex(index.clone(data));
  6973. } // attributes
  6974. var attributes = source.attributes;
  6975. for (var name in attributes) {
  6976. var attribute = attributes[name];
  6977. this.setAttribute(name, attribute.clone(data));
  6978. } // morph attributes
  6979. var morphAttributes = source.morphAttributes;
  6980. for (var _name2 in morphAttributes) {
  6981. var array = [];
  6982. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  6983. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  6984. array.push(morphAttribute[i].clone(data));
  6985. }
  6986. this.morphAttributes[_name2] = array;
  6987. }
  6988. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  6989. var groups = source.groups;
  6990. for (var _i6 = 0, _l = groups.length; _i6 < _l; _i6++) {
  6991. var group = groups[_i6];
  6992. this.addGroup(group.start, group.count, group.materialIndex);
  6993. } // bounding box
  6994. var boundingBox = source.boundingBox;
  6995. if (boundingBox !== null) {
  6996. this.boundingBox = boundingBox.clone();
  6997. } // bounding sphere
  6998. var boundingSphere = source.boundingSphere;
  6999. if (boundingSphere !== null) {
  7000. this.boundingSphere = boundingSphere.clone();
  7001. } // draw range
  7002. this.drawRange.start = source.drawRange.start;
  7003. this.drawRange.count = source.drawRange.count; // user data
  7004. this.userData = source.userData;
  7005. return this;
  7006. },
  7007. dispose: function dispose() {
  7008. this.dispatchEvent({
  7009. type: 'dispose'
  7010. });
  7011. }
  7012. });
  7013. var _inverseMatrix = new Matrix4();
  7014. var _ray = new Ray();
  7015. var _sphere = new Sphere();
  7016. var _vA = new Vector3();
  7017. var _vB = new Vector3();
  7018. var _vC = new Vector3();
  7019. var _tempA = new Vector3();
  7020. var _tempB = new Vector3();
  7021. var _tempC = new Vector3();
  7022. var _morphA = new Vector3();
  7023. var _morphB = new Vector3();
  7024. var _morphC = new Vector3();
  7025. var _uvA = new Vector2();
  7026. var _uvB = new Vector2();
  7027. var _uvC = new Vector2();
  7028. var _intersectionPoint = new Vector3();
  7029. var _intersectionPointWorld = new Vector3();
  7030. function Mesh(geometry, material) {
  7031. Object3D.call(this);
  7032. this.type = 'Mesh';
  7033. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  7034. this.material = material !== undefined ? material : new MeshBasicMaterial();
  7035. this.updateMorphTargets();
  7036. }
  7037. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7038. constructor: Mesh,
  7039. isMesh: true,
  7040. copy: function copy(source) {
  7041. Object3D.prototype.copy.call(this, source);
  7042. if (source.morphTargetInfluences !== undefined) {
  7043. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7044. }
  7045. if (source.morphTargetDictionary !== undefined) {
  7046. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7047. }
  7048. this.material = source.material;
  7049. this.geometry = source.geometry;
  7050. return this;
  7051. },
  7052. updateMorphTargets: function updateMorphTargets() {
  7053. var geometry = this.geometry;
  7054. if (geometry.isBufferGeometry) {
  7055. var morphAttributes = geometry.morphAttributes;
  7056. var keys = Object.keys(morphAttributes);
  7057. if (keys.length > 0) {
  7058. var morphAttribute = morphAttributes[keys[0]];
  7059. if (morphAttribute !== undefined) {
  7060. this.morphTargetInfluences = [];
  7061. this.morphTargetDictionary = {};
  7062. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7063. var name = morphAttribute[m].name || String(m);
  7064. this.morphTargetInfluences.push(0);
  7065. this.morphTargetDictionary[name] = m;
  7066. }
  7067. }
  7068. }
  7069. } else {
  7070. var morphTargets = geometry.morphTargets;
  7071. if (morphTargets !== undefined && morphTargets.length > 0) {
  7072. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7073. }
  7074. }
  7075. },
  7076. raycast: function raycast(raycaster, intersects) {
  7077. var geometry = this.geometry;
  7078. var material = this.material;
  7079. var matrixWorld = this.matrixWorld;
  7080. if (material === undefined) return; // Checking boundingSphere distance to ray
  7081. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7082. _sphere.copy(geometry.boundingSphere);
  7083. _sphere.applyMatrix4(matrixWorld);
  7084. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7085. _inverseMatrix.getInverse(matrixWorld);
  7086. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7087. if (geometry.boundingBox !== null) {
  7088. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7089. }
  7090. var intersection;
  7091. if (geometry.isBufferGeometry) {
  7092. var index = geometry.index;
  7093. var position = geometry.attributes.position;
  7094. var morphPosition = geometry.morphAttributes.position;
  7095. var morphTargetsRelative = geometry.morphTargetsRelative;
  7096. var uv = geometry.attributes.uv;
  7097. var uv2 = geometry.attributes.uv2;
  7098. var groups = geometry.groups;
  7099. var drawRange = geometry.drawRange;
  7100. if (index !== null) {
  7101. // indexed buffer geometry
  7102. if (Array.isArray(material)) {
  7103. for (var i = 0, il = groups.length; i < il; i++) {
  7104. var group = groups[i];
  7105. var groupMaterial = material[group.materialIndex];
  7106. var start = Math.max(group.start, drawRange.start);
  7107. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7108. for (var j = start, jl = end; j < jl; j += 3) {
  7109. var a = index.getX(j);
  7110. var b = index.getX(j + 1);
  7111. var c = index.getX(j + 2);
  7112. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7113. if (intersection) {
  7114. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7115. intersection.face.materialIndex = group.materialIndex;
  7116. intersects.push(intersection);
  7117. }
  7118. }
  7119. }
  7120. } else {
  7121. var _start = Math.max(0, drawRange.start);
  7122. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7123. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7124. var _a = index.getX(_i);
  7125. var _b = index.getX(_i + 1);
  7126. var _c = index.getX(_i + 2);
  7127. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7128. if (intersection) {
  7129. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7130. intersects.push(intersection);
  7131. }
  7132. }
  7133. }
  7134. } else if (position !== undefined) {
  7135. // non-indexed buffer geometry
  7136. if (Array.isArray(material)) {
  7137. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7138. var _group = groups[_i2];
  7139. var _groupMaterial = material[_group.materialIndex];
  7140. var _start2 = Math.max(_group.start, drawRange.start);
  7141. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7142. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7143. var _a2 = _j;
  7144. var _b2 = _j + 1;
  7145. var _c2 = _j + 2;
  7146. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7147. if (intersection) {
  7148. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7149. intersection.face.materialIndex = _group.materialIndex;
  7150. intersects.push(intersection);
  7151. }
  7152. }
  7153. }
  7154. } else {
  7155. var _start3 = Math.max(0, drawRange.start);
  7156. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7157. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7158. var _a3 = _i3;
  7159. var _b3 = _i3 + 1;
  7160. var _c3 = _i3 + 2;
  7161. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7162. if (intersection) {
  7163. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7164. intersects.push(intersection);
  7165. }
  7166. }
  7167. }
  7168. }
  7169. } else if (geometry.isGeometry) {
  7170. var isMultiMaterial = Array.isArray(material);
  7171. var vertices = geometry.vertices;
  7172. var faces = geometry.faces;
  7173. var uvs;
  7174. var faceVertexUvs = geometry.faceVertexUvs[0];
  7175. if (faceVertexUvs.length > 0) uvs = faceVertexUvs;
  7176. for (var f = 0, fl = faces.length; f < fl; f++) {
  7177. var face = faces[f];
  7178. var faceMaterial = isMultiMaterial ? material[face.materialIndex] : material;
  7179. if (faceMaterial === undefined) continue;
  7180. var fvA = vertices[face.a];
  7181. var fvB = vertices[face.b];
  7182. var fvC = vertices[face.c];
  7183. intersection = checkIntersection(this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint);
  7184. if (intersection) {
  7185. if (uvs && uvs[f]) {
  7186. var uvs_f = uvs[f];
  7187. _uvA.copy(uvs_f[0]);
  7188. _uvB.copy(uvs_f[1]);
  7189. _uvC.copy(uvs_f[2]);
  7190. intersection.uv = Triangle.getUV(_intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2());
  7191. }
  7192. intersection.face = face;
  7193. intersection.faceIndex = f;
  7194. intersects.push(intersection);
  7195. }
  7196. }
  7197. }
  7198. }
  7199. });
  7200. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7201. var intersect;
  7202. if (material.side === BackSide) {
  7203. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7204. } else {
  7205. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7206. }
  7207. if (intersect === null) return null;
  7208. _intersectionPointWorld.copy(point);
  7209. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7210. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7211. if (distance < raycaster.near || distance > raycaster.far) return null;
  7212. return {
  7213. distance: distance,
  7214. point: _intersectionPointWorld.clone(),
  7215. object: object
  7216. };
  7217. }
  7218. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7219. _vA.fromBufferAttribute(position, a);
  7220. _vB.fromBufferAttribute(position, b);
  7221. _vC.fromBufferAttribute(position, c);
  7222. var morphInfluences = object.morphTargetInfluences;
  7223. if (material.morphTargets && morphPosition && morphInfluences) {
  7224. _morphA.set(0, 0, 0);
  7225. _morphB.set(0, 0, 0);
  7226. _morphC.set(0, 0, 0);
  7227. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7228. var influence = morphInfluences[i];
  7229. var morphAttribute = morphPosition[i];
  7230. if (influence === 0) continue;
  7231. _tempA.fromBufferAttribute(morphAttribute, a);
  7232. _tempB.fromBufferAttribute(morphAttribute, b);
  7233. _tempC.fromBufferAttribute(morphAttribute, c);
  7234. if (morphTargetsRelative) {
  7235. _morphA.addScaledVector(_tempA, influence);
  7236. _morphB.addScaledVector(_tempB, influence);
  7237. _morphC.addScaledVector(_tempC, influence);
  7238. } else {
  7239. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7240. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7241. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7242. }
  7243. }
  7244. _vA.add(_morphA);
  7245. _vB.add(_morphB);
  7246. _vC.add(_morphC);
  7247. }
  7248. if (object.isSkinnedMesh) {
  7249. object.boneTransform(a, _vA);
  7250. object.boneTransform(b, _vB);
  7251. object.boneTransform(c, _vC);
  7252. }
  7253. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7254. if (intersection) {
  7255. if (uv) {
  7256. _uvA.fromBufferAttribute(uv, a);
  7257. _uvB.fromBufferAttribute(uv, b);
  7258. _uvC.fromBufferAttribute(uv, c);
  7259. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7260. }
  7261. if (uv2) {
  7262. _uvA.fromBufferAttribute(uv2, a);
  7263. _uvB.fromBufferAttribute(uv2, b);
  7264. _uvC.fromBufferAttribute(uv2, c);
  7265. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7266. }
  7267. var face = new Face3(a, b, c);
  7268. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7269. intersection.face = face;
  7270. }
  7271. return intersection;
  7272. }
  7273. var BoxBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7274. _inheritsLoose(BoxBufferGeometry, _BufferGeometry);
  7275. function BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7276. var _this;
  7277. if (width === void 0) {
  7278. width = 1;
  7279. }
  7280. if (height === void 0) {
  7281. height = 1;
  7282. }
  7283. if (depth === void 0) {
  7284. depth = 1;
  7285. }
  7286. if (widthSegments === void 0) {
  7287. widthSegments = 1;
  7288. }
  7289. if (heightSegments === void 0) {
  7290. heightSegments = 1;
  7291. }
  7292. if (depthSegments === void 0) {
  7293. depthSegments = 1;
  7294. }
  7295. _this = _BufferGeometry.call(this) || this;
  7296. _this.type = 'BoxBufferGeometry';
  7297. _this.parameters = {
  7298. width: width,
  7299. height: height,
  7300. depth: depth,
  7301. widthSegments: widthSegments,
  7302. heightSegments: heightSegments,
  7303. depthSegments: depthSegments
  7304. };
  7305. var scope = _assertThisInitialized(_this); // segments
  7306. widthSegments = Math.floor(widthSegments);
  7307. heightSegments = Math.floor(heightSegments);
  7308. depthSegments = Math.floor(depthSegments); // buffers
  7309. var indices = [];
  7310. var vertices = [];
  7311. var normals = [];
  7312. var uvs = []; // helper variables
  7313. var numberOfVertices = 0;
  7314. var groupStart = 0; // build each side of the box geometry
  7315. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7316. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7317. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7318. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7319. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7320. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7321. // build geometry
  7322. _this.setIndex(indices);
  7323. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7324. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7325. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7326. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7327. var segmentWidth = width / gridX;
  7328. var segmentHeight = height / gridY;
  7329. var widthHalf = width / 2;
  7330. var heightHalf = height / 2;
  7331. var depthHalf = depth / 2;
  7332. var gridX1 = gridX + 1;
  7333. var gridY1 = gridY + 1;
  7334. var vertexCounter = 0;
  7335. var groupCount = 0;
  7336. var vector = new Vector3(); // generate vertices, normals and uvs
  7337. for (var iy = 0; iy < gridY1; iy++) {
  7338. var y = iy * segmentHeight - heightHalf;
  7339. for (var ix = 0; ix < gridX1; ix++) {
  7340. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7341. vector[u] = x * udir;
  7342. vector[v] = y * vdir;
  7343. vector[w] = depthHalf; // now apply vector to vertex buffer
  7344. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7345. vector[u] = 0;
  7346. vector[v] = 0;
  7347. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7348. normals.push(vector.x, vector.y, vector.z); // uvs
  7349. uvs.push(ix / gridX);
  7350. uvs.push(1 - iy / gridY); // counters
  7351. vertexCounter += 1;
  7352. }
  7353. } // indices
  7354. // 1. you need three indices to draw a single face
  7355. // 2. a single segment consists of two faces
  7356. // 3. so we need to generate six (2*3) indices per segment
  7357. for (var _iy = 0; _iy < gridY; _iy++) {
  7358. for (var _ix = 0; _ix < gridX; _ix++) {
  7359. var a = numberOfVertices + _ix + gridX1 * _iy;
  7360. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7361. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7362. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7363. indices.push(a, b, d);
  7364. indices.push(b, c, d); // increase counter
  7365. groupCount += 6;
  7366. }
  7367. } // add a group to the geometry. this will ensure multi material support
  7368. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7369. groupStart += groupCount; // update total number of vertices
  7370. numberOfVertices += vertexCounter;
  7371. }
  7372. return _this;
  7373. }
  7374. return BoxBufferGeometry;
  7375. }(BufferGeometry);
  7376. /**
  7377. * Uniform Utilities
  7378. */
  7379. function cloneUniforms(src) {
  7380. var dst = {};
  7381. for (var u in src) {
  7382. dst[u] = {};
  7383. for (var p in src[u]) {
  7384. var property = src[u][p];
  7385. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7386. dst[u][p] = property.clone();
  7387. } else if (Array.isArray(property)) {
  7388. dst[u][p] = property.slice();
  7389. } else {
  7390. dst[u][p] = property;
  7391. }
  7392. }
  7393. }
  7394. return dst;
  7395. }
  7396. function mergeUniforms(uniforms) {
  7397. var merged = {};
  7398. for (var u = 0; u < uniforms.length; u++) {
  7399. var tmp = cloneUniforms(uniforms[u]);
  7400. for (var p in tmp) {
  7401. merged[p] = tmp[p];
  7402. }
  7403. }
  7404. return merged;
  7405. } // Legacy
  7406. var UniformsUtils = {
  7407. clone: cloneUniforms,
  7408. merge: mergeUniforms
  7409. };
  7410. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7411. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7412. /**
  7413. * parameters = {
  7414. * defines: { "label" : "value" },
  7415. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7416. *
  7417. * fragmentShader: <string>,
  7418. * vertexShader: <string>,
  7419. *
  7420. * wireframe: <boolean>,
  7421. * wireframeLinewidth: <float>,
  7422. *
  7423. * lights: <bool>,
  7424. *
  7425. * skinning: <bool>,
  7426. * morphTargets: <bool>,
  7427. * morphNormals: <bool>
  7428. * }
  7429. */
  7430. function ShaderMaterial(parameters) {
  7431. Material.call(this);
  7432. this.type = 'ShaderMaterial';
  7433. this.defines = {};
  7434. this.uniforms = {};
  7435. this.vertexShader = default_vertex;
  7436. this.fragmentShader = default_fragment;
  7437. this.linewidth = 1;
  7438. this.wireframe = false;
  7439. this.wireframeLinewidth = 1;
  7440. this.fog = false; // set to use scene fog
  7441. this.lights = false; // set to use scene lights
  7442. this.clipping = false; // set to use user-defined clipping planes
  7443. this.skinning = false; // set to use skinning attribute streams
  7444. this.morphTargets = false; // set to use morph targets
  7445. this.morphNormals = false; // set to use morph normals
  7446. this.extensions = {
  7447. derivatives: false,
  7448. // set to use derivatives
  7449. fragDepth: false,
  7450. // set to use fragment depth values
  7451. drawBuffers: false,
  7452. // set to use draw buffers
  7453. shaderTextureLOD: false // set to use shader texture LOD
  7454. }; // When rendered geometry doesn't include these attributes but the material does,
  7455. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7456. this.defaultAttributeValues = {
  7457. 'color': [1, 1, 1],
  7458. 'uv': [0, 0],
  7459. 'uv2': [0, 0]
  7460. };
  7461. this.index0AttributeName = undefined;
  7462. this.uniformsNeedUpdate = false;
  7463. this.glslVersion = null;
  7464. if (parameters !== undefined) {
  7465. if (parameters.attributes !== undefined) {
  7466. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  7467. }
  7468. this.setValues(parameters);
  7469. }
  7470. }
  7471. ShaderMaterial.prototype = Object.create(Material.prototype);
  7472. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7473. ShaderMaterial.prototype.isShaderMaterial = true;
  7474. ShaderMaterial.prototype.copy = function (source) {
  7475. Material.prototype.copy.call(this, source);
  7476. this.fragmentShader = source.fragmentShader;
  7477. this.vertexShader = source.vertexShader;
  7478. this.uniforms = cloneUniforms(source.uniforms);
  7479. this.defines = Object.assign({}, source.defines);
  7480. this.wireframe = source.wireframe;
  7481. this.wireframeLinewidth = source.wireframeLinewidth;
  7482. this.lights = source.lights;
  7483. this.clipping = source.clipping;
  7484. this.skinning = source.skinning;
  7485. this.morphTargets = source.morphTargets;
  7486. this.morphNormals = source.morphNormals;
  7487. this.extensions = Object.assign({}, source.extensions);
  7488. this.glslVersion = source.glslVersion;
  7489. return this;
  7490. };
  7491. ShaderMaterial.prototype.toJSON = function (meta) {
  7492. var data = Material.prototype.toJSON.call(this, meta);
  7493. data.glslVersion = this.glslVersion;
  7494. data.uniforms = {};
  7495. for (var name in this.uniforms) {
  7496. var uniform = this.uniforms[name];
  7497. var value = uniform.value;
  7498. if (value && value.isTexture) {
  7499. data.uniforms[name] = {
  7500. type: 't',
  7501. value: value.toJSON(meta).uuid
  7502. };
  7503. } else if (value && value.isColor) {
  7504. data.uniforms[name] = {
  7505. type: 'c',
  7506. value: value.getHex()
  7507. };
  7508. } else if (value && value.isVector2) {
  7509. data.uniforms[name] = {
  7510. type: 'v2',
  7511. value: value.toArray()
  7512. };
  7513. } else if (value && value.isVector3) {
  7514. data.uniforms[name] = {
  7515. type: 'v3',
  7516. value: value.toArray()
  7517. };
  7518. } else if (value && value.isVector4) {
  7519. data.uniforms[name] = {
  7520. type: 'v4',
  7521. value: value.toArray()
  7522. };
  7523. } else if (value && value.isMatrix3) {
  7524. data.uniforms[name] = {
  7525. type: 'm3',
  7526. value: value.toArray()
  7527. };
  7528. } else if (value && value.isMatrix4) {
  7529. data.uniforms[name] = {
  7530. type: 'm4',
  7531. value: value.toArray()
  7532. };
  7533. } else {
  7534. data.uniforms[name] = {
  7535. value: value
  7536. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7537. }
  7538. }
  7539. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  7540. data.vertexShader = this.vertexShader;
  7541. data.fragmentShader = this.fragmentShader;
  7542. var extensions = {};
  7543. for (var key in this.extensions) {
  7544. if (this.extensions[key] === true) extensions[key] = true;
  7545. }
  7546. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  7547. return data;
  7548. };
  7549. function Camera() {
  7550. Object3D.call(this);
  7551. this.type = 'Camera';
  7552. this.matrixWorldInverse = new Matrix4();
  7553. this.projectionMatrix = new Matrix4();
  7554. this.projectionMatrixInverse = new Matrix4();
  7555. }
  7556. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  7557. constructor: Camera,
  7558. isCamera: true,
  7559. copy: function copy(source, recursive) {
  7560. Object3D.prototype.copy.call(this, source, recursive);
  7561. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  7562. this.projectionMatrix.copy(source.projectionMatrix);
  7563. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  7564. return this;
  7565. },
  7566. getWorldDirection: function getWorldDirection(target) {
  7567. if (target === undefined) {
  7568. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  7569. target = new Vector3();
  7570. }
  7571. this.updateWorldMatrix(true, false);
  7572. var e = this.matrixWorld.elements;
  7573. return target.set(-e[8], -e[9], -e[10]).normalize();
  7574. },
  7575. updateMatrixWorld: function updateMatrixWorld(force) {
  7576. Object3D.prototype.updateMatrixWorld.call(this, force);
  7577. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7578. },
  7579. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  7580. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  7581. this.matrixWorldInverse.getInverse(this.matrixWorld);
  7582. },
  7583. clone: function clone() {
  7584. return new this.constructor().copy(this);
  7585. }
  7586. });
  7587. function PerspectiveCamera(fov, aspect, near, far) {
  7588. Camera.call(this);
  7589. this.type = 'PerspectiveCamera';
  7590. this.fov = fov !== undefined ? fov : 50;
  7591. this.zoom = 1;
  7592. this.near = near !== undefined ? near : 0.1;
  7593. this.far = far !== undefined ? far : 2000;
  7594. this.focus = 10;
  7595. this.aspect = aspect !== undefined ? aspect : 1;
  7596. this.view = null;
  7597. this.filmGauge = 35; // width of the film (default in millimeters)
  7598. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7599. this.updateProjectionMatrix();
  7600. }
  7601. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  7602. constructor: PerspectiveCamera,
  7603. isPerspectiveCamera: true,
  7604. copy: function copy(source, recursive) {
  7605. Camera.prototype.copy.call(this, source, recursive);
  7606. this.fov = source.fov;
  7607. this.zoom = source.zoom;
  7608. this.near = source.near;
  7609. this.far = source.far;
  7610. this.focus = source.focus;
  7611. this.aspect = source.aspect;
  7612. this.view = source.view === null ? null : Object.assign({}, source.view);
  7613. this.filmGauge = source.filmGauge;
  7614. this.filmOffset = source.filmOffset;
  7615. return this;
  7616. },
  7617. /**
  7618. * Sets the FOV by focal length in respect to the current .filmGauge.
  7619. *
  7620. * The default film gauge is 35, so that the focal length can be specified for
  7621. * a 35mm (full frame) camera.
  7622. *
  7623. * Values for focal length and film gauge must have the same unit.
  7624. */
  7625. setFocalLength: function setFocalLength(focalLength) {
  7626. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7627. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7628. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  7629. this.updateProjectionMatrix();
  7630. },
  7631. /**
  7632. * Calculates the focal length from the current .fov and .filmGauge.
  7633. */
  7634. getFocalLength: function getFocalLength() {
  7635. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  7636. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7637. },
  7638. getEffectiveFOV: function getEffectiveFOV() {
  7639. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  7640. },
  7641. getFilmWidth: function getFilmWidth() {
  7642. // film not completely covered in portrait format (aspect < 1)
  7643. return this.filmGauge * Math.min(this.aspect, 1);
  7644. },
  7645. getFilmHeight: function getFilmHeight() {
  7646. // film not completely covered in landscape format (aspect > 1)
  7647. return this.filmGauge / Math.max(this.aspect, 1);
  7648. },
  7649. /**
  7650. * Sets an offset in a larger frustum. This is useful for multi-window or
  7651. * multi-monitor/multi-machine setups.
  7652. *
  7653. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7654. * the monitors are in grid like this
  7655. *
  7656. * +---+---+---+
  7657. * | A | B | C |
  7658. * +---+---+---+
  7659. * | D | E | F |
  7660. * +---+---+---+
  7661. *
  7662. * then for each monitor you would call it like this
  7663. *
  7664. * const w = 1920;
  7665. * const h = 1080;
  7666. * const fullWidth = w * 3;
  7667. * const fullHeight = h * 2;
  7668. *
  7669. * --A--
  7670. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7671. * --B--
  7672. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7673. * --C--
  7674. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7675. * --D--
  7676. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7677. * --E--
  7678. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7679. * --F--
  7680. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7681. *
  7682. * Note there is no reason monitors have to be the same size or in a grid.
  7683. */
  7684. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  7685. this.aspect = fullWidth / fullHeight;
  7686. if (this.view === null) {
  7687. this.view = {
  7688. enabled: true,
  7689. fullWidth: 1,
  7690. fullHeight: 1,
  7691. offsetX: 0,
  7692. offsetY: 0,
  7693. width: 1,
  7694. height: 1
  7695. };
  7696. }
  7697. this.view.enabled = true;
  7698. this.view.fullWidth = fullWidth;
  7699. this.view.fullHeight = fullHeight;
  7700. this.view.offsetX = x;
  7701. this.view.offsetY = y;
  7702. this.view.width = width;
  7703. this.view.height = height;
  7704. this.updateProjectionMatrix();
  7705. },
  7706. clearViewOffset: function clearViewOffset() {
  7707. if (this.view !== null) {
  7708. this.view.enabled = false;
  7709. }
  7710. this.updateProjectionMatrix();
  7711. },
  7712. updateProjectionMatrix: function updateProjectionMatrix() {
  7713. var near = this.near;
  7714. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  7715. var height = 2 * top;
  7716. var width = this.aspect * height;
  7717. var left = -0.5 * width;
  7718. var view = this.view;
  7719. if (this.view !== null && this.view.enabled) {
  7720. var fullWidth = view.fullWidth,
  7721. fullHeight = view.fullHeight;
  7722. left += view.offsetX * width / fullWidth;
  7723. top -= view.offsetY * height / fullHeight;
  7724. width *= view.width / fullWidth;
  7725. height *= view.height / fullHeight;
  7726. }
  7727. var skew = this.filmOffset;
  7728. if (skew !== 0) left += near * skew / this.getFilmWidth();
  7729. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  7730. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  7731. },
  7732. toJSON: function toJSON(meta) {
  7733. var data = Object3D.prototype.toJSON.call(this, meta);
  7734. data.object.fov = this.fov;
  7735. data.object.zoom = this.zoom;
  7736. data.object.near = this.near;
  7737. data.object.far = this.far;
  7738. data.object.focus = this.focus;
  7739. data.object.aspect = this.aspect;
  7740. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  7741. data.object.filmGauge = this.filmGauge;
  7742. data.object.filmOffset = this.filmOffset;
  7743. return data;
  7744. }
  7745. });
  7746. var fov = 90,
  7747. aspect = 1;
  7748. function CubeCamera(near, far, renderTarget) {
  7749. Object3D.call(this);
  7750. this.type = 'CubeCamera';
  7751. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  7752. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  7753. return;
  7754. }
  7755. this.renderTarget = renderTarget;
  7756. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  7757. cameraPX.layers = this.layers;
  7758. cameraPX.up.set(0, -1, 0);
  7759. cameraPX.lookAt(new Vector3(1, 0, 0));
  7760. this.add(cameraPX);
  7761. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  7762. cameraNX.layers = this.layers;
  7763. cameraNX.up.set(0, -1, 0);
  7764. cameraNX.lookAt(new Vector3(-1, 0, 0));
  7765. this.add(cameraNX);
  7766. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  7767. cameraPY.layers = this.layers;
  7768. cameraPY.up.set(0, 0, 1);
  7769. cameraPY.lookAt(new Vector3(0, 1, 0));
  7770. this.add(cameraPY);
  7771. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  7772. cameraNY.layers = this.layers;
  7773. cameraNY.up.set(0, 0, -1);
  7774. cameraNY.lookAt(new Vector3(0, -1, 0));
  7775. this.add(cameraNY);
  7776. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  7777. cameraPZ.layers = this.layers;
  7778. cameraPZ.up.set(0, -1, 0);
  7779. cameraPZ.lookAt(new Vector3(0, 0, 1));
  7780. this.add(cameraPZ);
  7781. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  7782. cameraNZ.layers = this.layers;
  7783. cameraNZ.up.set(0, -1, 0);
  7784. cameraNZ.lookAt(new Vector3(0, 0, -1));
  7785. this.add(cameraNZ);
  7786. this.update = function (renderer, scene) {
  7787. if (this.parent === null) this.updateMatrixWorld();
  7788. var currentXrEnabled = renderer.xr.enabled;
  7789. var currentRenderTarget = renderer.getRenderTarget();
  7790. renderer.xr.enabled = false;
  7791. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7792. renderTarget.texture.generateMipmaps = false;
  7793. renderer.setRenderTarget(renderTarget, 0);
  7794. renderer.render(scene, cameraPX);
  7795. renderer.setRenderTarget(renderTarget, 1);
  7796. renderer.render(scene, cameraNX);
  7797. renderer.setRenderTarget(renderTarget, 2);
  7798. renderer.render(scene, cameraPY);
  7799. renderer.setRenderTarget(renderTarget, 3);
  7800. renderer.render(scene, cameraNY);
  7801. renderer.setRenderTarget(renderTarget, 4);
  7802. renderer.render(scene, cameraPZ);
  7803. renderTarget.texture.generateMipmaps = generateMipmaps;
  7804. renderer.setRenderTarget(renderTarget, 5);
  7805. renderer.render(scene, cameraNZ);
  7806. renderer.setRenderTarget(currentRenderTarget);
  7807. renderer.xr.enabled = currentXrEnabled;
  7808. };
  7809. }
  7810. CubeCamera.prototype = Object.create(Object3D.prototype);
  7811. CubeCamera.prototype.constructor = CubeCamera;
  7812. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  7813. images = images !== undefined ? images : [];
  7814. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7815. format = format !== undefined ? format : RGBFormat;
  7816. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7817. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  7818. //
  7819. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7820. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7821. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7822. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7823. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7824. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7825. this._needsFlipEnvMap = true;
  7826. }
  7827. CubeTexture.prototype = Object.create(Texture.prototype);
  7828. CubeTexture.prototype.constructor = CubeTexture;
  7829. CubeTexture.prototype.isCubeTexture = true;
  7830. Object.defineProperty(CubeTexture.prototype, 'images', {
  7831. get: function get() {
  7832. return this.image;
  7833. },
  7834. set: function set(value) {
  7835. this.image = value;
  7836. }
  7837. });
  7838. function WebGLCubeRenderTarget(size, options, dummy) {
  7839. if (Number.isInteger(options)) {
  7840. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  7841. options = dummy;
  7842. }
  7843. WebGLRenderTarget.call(this, size, size, options);
  7844. options = options || {};
  7845. this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  7846. this.texture._needsFlipEnvMap = false;
  7847. }
  7848. WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
  7849. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7850. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7851. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function (renderer, texture) {
  7852. this.texture.type = texture.type;
  7853. this.texture.format = RGBAFormat; // see #18859
  7854. this.texture.encoding = texture.encoding;
  7855. this.texture.generateMipmaps = texture.generateMipmaps;
  7856. this.texture.minFilter = texture.minFilter;
  7857. this.texture.magFilter = texture.magFilter;
  7858. var shader = {
  7859. uniforms: {
  7860. tEquirect: {
  7861. value: null
  7862. }
  7863. },
  7864. vertexShader:
  7865. /* glsl */
  7866. "\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",
  7867. fragmentShader:
  7868. /* glsl */
  7869. "\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"
  7870. };
  7871. var geometry = new BoxBufferGeometry(5, 5, 5);
  7872. var material = new ShaderMaterial({
  7873. name: 'CubemapFromEquirect',
  7874. uniforms: cloneUniforms(shader.uniforms),
  7875. vertexShader: shader.vertexShader,
  7876. fragmentShader: shader.fragmentShader,
  7877. side: BackSide,
  7878. blending: NoBlending
  7879. });
  7880. material.uniforms.tEquirect.value = texture;
  7881. var mesh = new Mesh(geometry, material);
  7882. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  7883. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  7884. var camera = new CubeCamera(1, 10, this);
  7885. camera.update(renderer, mesh);
  7886. texture.minFilter = currentMinFilter;
  7887. mesh.geometry.dispose();
  7888. mesh.material.dispose();
  7889. return this;
  7890. };
  7891. WebGLCubeRenderTarget.prototype.clear = function (renderer, color, depth, stencil) {
  7892. var currentRenderTarget = renderer.getRenderTarget();
  7893. for (var i = 0; i < 6; i++) {
  7894. renderer.setRenderTarget(this, i);
  7895. renderer.clear(color, depth, stencil);
  7896. }
  7897. renderer.setRenderTarget(currentRenderTarget);
  7898. };
  7899. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  7900. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  7901. this.image = {
  7902. data: data || null,
  7903. width: width || 1,
  7904. height: height || 1
  7905. };
  7906. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7907. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7908. this.generateMipmaps = false;
  7909. this.flipY = false;
  7910. this.unpackAlignment = 1;
  7911. this.needsUpdate = true;
  7912. }
  7913. DataTexture.prototype = Object.create(Texture.prototype);
  7914. DataTexture.prototype.constructor = DataTexture;
  7915. DataTexture.prototype.isDataTexture = true;
  7916. var _sphere$1 = /*@__PURE__*/new Sphere();
  7917. var _vector$5 = /*@__PURE__*/new Vector3();
  7918. var Frustum = /*#__PURE__*/function () {
  7919. function Frustum(p0, p1, p2, p3, p4, p5) {
  7920. 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()];
  7921. }
  7922. var _proto = Frustum.prototype;
  7923. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  7924. var planes = this.planes;
  7925. planes[0].copy(p0);
  7926. planes[1].copy(p1);
  7927. planes[2].copy(p2);
  7928. planes[3].copy(p3);
  7929. planes[4].copy(p4);
  7930. planes[5].copy(p5);
  7931. return this;
  7932. };
  7933. _proto.clone = function clone() {
  7934. return new this.constructor().copy(this);
  7935. };
  7936. _proto.copy = function copy(frustum) {
  7937. var planes = this.planes;
  7938. for (var i = 0; i < 6; i++) {
  7939. planes[i].copy(frustum.planes[i]);
  7940. }
  7941. return this;
  7942. };
  7943. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  7944. var planes = this.planes;
  7945. var me = m.elements;
  7946. var me0 = me[0],
  7947. me1 = me[1],
  7948. me2 = me[2],
  7949. me3 = me[3];
  7950. var me4 = me[4],
  7951. me5 = me[5],
  7952. me6 = me[6],
  7953. me7 = me[7];
  7954. var me8 = me[8],
  7955. me9 = me[9],
  7956. me10 = me[10],
  7957. me11 = me[11];
  7958. var me12 = me[12],
  7959. me13 = me[13],
  7960. me14 = me[14],
  7961. me15 = me[15];
  7962. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  7963. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  7964. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  7965. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  7966. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  7967. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  7968. return this;
  7969. };
  7970. _proto.intersectsObject = function intersectsObject(object) {
  7971. var geometry = object.geometry;
  7972. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7973. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  7974. return this.intersectsSphere(_sphere$1);
  7975. };
  7976. _proto.intersectsSprite = function intersectsSprite(sprite) {
  7977. _sphere$1.center.set(0, 0, 0);
  7978. _sphere$1.radius = 0.7071067811865476;
  7979. _sphere$1.applyMatrix4(sprite.matrixWorld);
  7980. return this.intersectsSphere(_sphere$1);
  7981. };
  7982. _proto.intersectsSphere = function intersectsSphere(sphere) {
  7983. var planes = this.planes;
  7984. var center = sphere.center;
  7985. var negRadius = -sphere.radius;
  7986. for (var i = 0; i < 6; i++) {
  7987. var distance = planes[i].distanceToPoint(center);
  7988. if (distance < negRadius) {
  7989. return false;
  7990. }
  7991. }
  7992. return true;
  7993. };
  7994. _proto.intersectsBox = function intersectsBox(box) {
  7995. var planes = this.planes;
  7996. for (var i = 0; i < 6; i++) {
  7997. var plane = planes[i]; // corner at max distance
  7998. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7999. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8000. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8001. if (plane.distanceToPoint(_vector$5) < 0) {
  8002. return false;
  8003. }
  8004. }
  8005. return true;
  8006. };
  8007. _proto.containsPoint = function containsPoint(point) {
  8008. var planes = this.planes;
  8009. for (var i = 0; i < 6; i++) {
  8010. if (planes[i].distanceToPoint(point) < 0) {
  8011. return false;
  8012. }
  8013. }
  8014. return true;
  8015. };
  8016. return Frustum;
  8017. }();
  8018. function WebGLAnimation() {
  8019. var context = null;
  8020. var isAnimating = false;
  8021. var animationLoop = null;
  8022. var requestId = null;
  8023. function onAnimationFrame(time, frame) {
  8024. animationLoop(time, frame);
  8025. requestId = context.requestAnimationFrame(onAnimationFrame);
  8026. }
  8027. return {
  8028. start: function start() {
  8029. if (isAnimating === true) return;
  8030. if (animationLoop === null) return;
  8031. requestId = context.requestAnimationFrame(onAnimationFrame);
  8032. isAnimating = true;
  8033. },
  8034. stop: function stop() {
  8035. context.cancelAnimationFrame(requestId);
  8036. isAnimating = false;
  8037. },
  8038. setAnimationLoop: function setAnimationLoop(callback) {
  8039. animationLoop = callback;
  8040. },
  8041. setContext: function setContext(value) {
  8042. context = value;
  8043. }
  8044. };
  8045. }
  8046. function WebGLAttributes(gl, capabilities) {
  8047. var isWebGL2 = capabilities.isWebGL2;
  8048. var buffers = new WeakMap();
  8049. function createBuffer(attribute, bufferType) {
  8050. var array = attribute.array;
  8051. var usage = attribute.usage;
  8052. var buffer = gl.createBuffer();
  8053. gl.bindBuffer(bufferType, buffer);
  8054. gl.bufferData(bufferType, array, usage);
  8055. attribute.onUploadCallback();
  8056. var type = 5126;
  8057. if (array instanceof Float32Array) {
  8058. type = 5126;
  8059. } else if (array instanceof Float64Array) {
  8060. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8061. } else if (array instanceof Uint16Array) {
  8062. type = 5123;
  8063. } else if (array instanceof Int16Array) {
  8064. type = 5122;
  8065. } else if (array instanceof Uint32Array) {
  8066. type = 5125;
  8067. } else if (array instanceof Int32Array) {
  8068. type = 5124;
  8069. } else if (array instanceof Int8Array) {
  8070. type = 5120;
  8071. } else if (array instanceof Uint8Array) {
  8072. type = 5121;
  8073. }
  8074. return {
  8075. buffer: buffer,
  8076. type: type,
  8077. bytesPerElement: array.BYTES_PER_ELEMENT,
  8078. version: attribute.version
  8079. };
  8080. }
  8081. function updateBuffer(buffer, attribute, bufferType) {
  8082. var array = attribute.array;
  8083. var updateRange = attribute.updateRange;
  8084. gl.bindBuffer(bufferType, buffer);
  8085. if (updateRange.count === -1) {
  8086. // Not using update ranges
  8087. gl.bufferSubData(bufferType, 0, array);
  8088. } else {
  8089. if (isWebGL2) {
  8090. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8091. } else {
  8092. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8093. }
  8094. updateRange.count = -1; // reset range
  8095. }
  8096. } //
  8097. function get(attribute) {
  8098. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8099. return buffers.get(attribute);
  8100. }
  8101. function remove(attribute) {
  8102. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8103. var data = buffers.get(attribute);
  8104. if (data) {
  8105. gl.deleteBuffer(data.buffer);
  8106. buffers.delete(attribute);
  8107. }
  8108. }
  8109. function update(attribute, bufferType) {
  8110. if (attribute.isGLBufferAttribute) {
  8111. var cached = buffers.get(attribute);
  8112. if (!cached || cached.version < attribute.version) {
  8113. buffers.set(attribute, {
  8114. buffer: attribute.buffer,
  8115. type: attribute.type,
  8116. bytesPerElement: attribute.elementSize,
  8117. version: attribute.version
  8118. });
  8119. }
  8120. return;
  8121. }
  8122. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8123. var data = buffers.get(attribute);
  8124. if (data === undefined) {
  8125. buffers.set(attribute, createBuffer(attribute, bufferType));
  8126. } else if (data.version < attribute.version) {
  8127. updateBuffer(data.buffer, attribute, bufferType);
  8128. data.version = attribute.version;
  8129. }
  8130. }
  8131. return {
  8132. get: get,
  8133. remove: remove,
  8134. update: update
  8135. };
  8136. }
  8137. var PlaneBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8138. _inheritsLoose(PlaneBufferGeometry, _BufferGeometry);
  8139. function PlaneBufferGeometry(width, height, widthSegments, heightSegments) {
  8140. var _this;
  8141. _this = _BufferGeometry.call(this) || this;
  8142. _this.type = 'PlaneBufferGeometry';
  8143. _this.parameters = {
  8144. width: width,
  8145. height: height,
  8146. widthSegments: widthSegments,
  8147. heightSegments: heightSegments
  8148. };
  8149. width = width || 1;
  8150. height = height || 1;
  8151. var width_half = width / 2;
  8152. var height_half = height / 2;
  8153. var gridX = Math.floor(widthSegments) || 1;
  8154. var gridY = Math.floor(heightSegments) || 1;
  8155. var gridX1 = gridX + 1;
  8156. var gridY1 = gridY + 1;
  8157. var segment_width = width / gridX;
  8158. var segment_height = height / gridY; // buffers
  8159. var indices = [];
  8160. var vertices = [];
  8161. var normals = [];
  8162. var uvs = []; // generate vertices, normals and uvs
  8163. for (var iy = 0; iy < gridY1; iy++) {
  8164. var y = iy * segment_height - height_half;
  8165. for (var ix = 0; ix < gridX1; ix++) {
  8166. var x = ix * segment_width - width_half;
  8167. vertices.push(x, -y, 0);
  8168. normals.push(0, 0, 1);
  8169. uvs.push(ix / gridX);
  8170. uvs.push(1 - iy / gridY);
  8171. }
  8172. } // indices
  8173. for (var _iy = 0; _iy < gridY; _iy++) {
  8174. for (var _ix = 0; _ix < gridX; _ix++) {
  8175. var a = _ix + gridX1 * _iy;
  8176. var b = _ix + gridX1 * (_iy + 1);
  8177. var c = _ix + 1 + gridX1 * (_iy + 1);
  8178. var d = _ix + 1 + gridX1 * _iy; // faces
  8179. indices.push(a, b, d);
  8180. indices.push(b, c, d);
  8181. }
  8182. } // build geometry
  8183. _this.setIndex(indices);
  8184. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8185. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8186. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8187. return _this;
  8188. }
  8189. return PlaneBufferGeometry;
  8190. }(BufferGeometry);
  8191. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8192. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8193. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8194. 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";
  8195. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8196. var begin_vertex = "vec3 transformed = vec3( position );";
  8197. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8198. 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";
  8199. 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";
  8200. 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";
  8201. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8202. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8203. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8204. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8205. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8206. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8207. 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";
  8208. 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}";
  8209. 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";
  8210. 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";
  8211. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8212. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8213. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8214. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8215. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8216. 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}";
  8217. 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";
  8218. 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";
  8219. 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";
  8220. 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";
  8221. 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";
  8222. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8223. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8224. 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";
  8225. 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";
  8226. 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}";
  8227. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8228. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8229. 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";
  8230. 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";
  8231. 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";
  8232. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8233. 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)";
  8234. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8235. 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)";
  8236. 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";
  8237. 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}";
  8238. 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";
  8239. 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";
  8240. 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";
  8241. 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";
  8242. 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";
  8243. 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";
  8244. 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";
  8245. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8246. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8247. 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";
  8248. 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";
  8249. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8250. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8251. 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";
  8252. 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";
  8253. 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";
  8254. 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;";
  8255. 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";
  8256. 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";
  8257. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8258. 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";
  8259. 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";
  8260. 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}";
  8261. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8262. 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;";
  8263. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8264. 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";
  8265. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8266. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8267. 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";
  8268. 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";
  8269. 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";
  8270. 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}";
  8271. 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";
  8272. 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";
  8273. 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";
  8274. 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";
  8275. 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";
  8276. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8277. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8278. 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; }";
  8279. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8280. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8281. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8282. 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";
  8283. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8284. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8285. 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";
  8286. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8287. 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";
  8288. 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}";
  8289. 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}";
  8290. 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}";
  8291. 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}";
  8292. 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}";
  8293. 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}";
  8294. 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}";
  8295. 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}";
  8296. 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}";
  8297. 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}";
  8298. 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}";
  8299. 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}";
  8300. 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}";
  8301. 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}";
  8302. 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}";
  8303. 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}";
  8304. 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}";
  8305. 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}";
  8306. 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}";
  8307. 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}";
  8308. 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}";
  8309. 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}";
  8310. 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}";
  8311. 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}";
  8312. 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}";
  8313. 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}";
  8314. 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}";
  8315. 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}";
  8316. 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}";
  8317. 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}";
  8318. 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}";
  8319. 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}";
  8320. var ShaderChunk = {
  8321. alphamap_fragment: alphamap_fragment,
  8322. alphamap_pars_fragment: alphamap_pars_fragment,
  8323. alphatest_fragment: alphatest_fragment,
  8324. aomap_fragment: aomap_fragment,
  8325. aomap_pars_fragment: aomap_pars_fragment,
  8326. begin_vertex: begin_vertex,
  8327. beginnormal_vertex: beginnormal_vertex,
  8328. bsdfs: bsdfs,
  8329. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8330. clipping_planes_fragment: clipping_planes_fragment,
  8331. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8332. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8333. clipping_planes_vertex: clipping_planes_vertex,
  8334. color_fragment: color_fragment,
  8335. color_pars_fragment: color_pars_fragment,
  8336. color_pars_vertex: color_pars_vertex,
  8337. color_vertex: color_vertex,
  8338. common: common,
  8339. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8340. defaultnormal_vertex: defaultnormal_vertex,
  8341. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8342. displacementmap_vertex: displacementmap_vertex,
  8343. emissivemap_fragment: emissivemap_fragment,
  8344. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8345. encodings_fragment: encodings_fragment,
  8346. encodings_pars_fragment: encodings_pars_fragment,
  8347. envmap_fragment: envmap_fragment,
  8348. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8349. envmap_pars_fragment: envmap_pars_fragment,
  8350. envmap_pars_vertex: envmap_pars_vertex,
  8351. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8352. envmap_vertex: envmap_vertex,
  8353. fog_vertex: fog_vertex,
  8354. fog_pars_vertex: fog_pars_vertex,
  8355. fog_fragment: fog_fragment,
  8356. fog_pars_fragment: fog_pars_fragment,
  8357. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8358. lightmap_fragment: lightmap_fragment,
  8359. lightmap_pars_fragment: lightmap_pars_fragment,
  8360. lights_lambert_vertex: lights_lambert_vertex,
  8361. lights_pars_begin: lights_pars_begin,
  8362. lights_toon_fragment: lights_toon_fragment,
  8363. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8364. lights_phong_fragment: lights_phong_fragment,
  8365. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8366. lights_physical_fragment: lights_physical_fragment,
  8367. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8368. lights_fragment_begin: lights_fragment_begin,
  8369. lights_fragment_maps: lights_fragment_maps,
  8370. lights_fragment_end: lights_fragment_end,
  8371. logdepthbuf_fragment: logdepthbuf_fragment,
  8372. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8373. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8374. logdepthbuf_vertex: logdepthbuf_vertex,
  8375. map_fragment: map_fragment,
  8376. map_pars_fragment: map_pars_fragment,
  8377. map_particle_fragment: map_particle_fragment,
  8378. map_particle_pars_fragment: map_particle_pars_fragment,
  8379. metalnessmap_fragment: metalnessmap_fragment,
  8380. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8381. morphnormal_vertex: morphnormal_vertex,
  8382. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8383. morphtarget_vertex: morphtarget_vertex,
  8384. normal_fragment_begin: normal_fragment_begin,
  8385. normal_fragment_maps: normal_fragment_maps,
  8386. normalmap_pars_fragment: normalmap_pars_fragment,
  8387. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8388. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8389. clearcoat_pars_fragment: clearcoat_pars_fragment,
  8390. packing: packing,
  8391. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8392. project_vertex: project_vertex,
  8393. dithering_fragment: dithering_fragment,
  8394. dithering_pars_fragment: dithering_pars_fragment,
  8395. roughnessmap_fragment: roughnessmap_fragment,
  8396. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8397. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8398. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8399. shadowmap_vertex: shadowmap_vertex,
  8400. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8401. skinbase_vertex: skinbase_vertex,
  8402. skinning_pars_vertex: skinning_pars_vertex,
  8403. skinning_vertex: skinning_vertex,
  8404. skinnormal_vertex: skinnormal_vertex,
  8405. specularmap_fragment: specularmap_fragment,
  8406. specularmap_pars_fragment: specularmap_pars_fragment,
  8407. tonemapping_fragment: tonemapping_fragment,
  8408. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8409. transmissionmap_fragment: transmissionmap_fragment,
  8410. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  8411. uv_pars_fragment: uv_pars_fragment,
  8412. uv_pars_vertex: uv_pars_vertex,
  8413. uv_vertex: uv_vertex,
  8414. uv2_pars_fragment: uv2_pars_fragment,
  8415. uv2_pars_vertex: uv2_pars_vertex,
  8416. uv2_vertex: uv2_vertex,
  8417. worldpos_vertex: worldpos_vertex,
  8418. background_frag: background_frag,
  8419. background_vert: background_vert,
  8420. cube_frag: cube_frag,
  8421. cube_vert: cube_vert,
  8422. depth_frag: depth_frag,
  8423. depth_vert: depth_vert,
  8424. distanceRGBA_frag: distanceRGBA_frag,
  8425. distanceRGBA_vert: distanceRGBA_vert,
  8426. equirect_frag: equirect_frag,
  8427. equirect_vert: equirect_vert,
  8428. linedashed_frag: linedashed_frag,
  8429. linedashed_vert: linedashed_vert,
  8430. meshbasic_frag: meshbasic_frag,
  8431. meshbasic_vert: meshbasic_vert,
  8432. meshlambert_frag: meshlambert_frag,
  8433. meshlambert_vert: meshlambert_vert,
  8434. meshmatcap_frag: meshmatcap_frag,
  8435. meshmatcap_vert: meshmatcap_vert,
  8436. meshtoon_frag: meshtoon_frag,
  8437. meshtoon_vert: meshtoon_vert,
  8438. meshphong_frag: meshphong_frag,
  8439. meshphong_vert: meshphong_vert,
  8440. meshphysical_frag: meshphysical_frag,
  8441. meshphysical_vert: meshphysical_vert,
  8442. normal_frag: normal_frag,
  8443. normal_vert: normal_vert,
  8444. points_frag: points_frag,
  8445. points_vert: points_vert,
  8446. shadow_frag: shadow_frag,
  8447. shadow_vert: shadow_vert,
  8448. sprite_frag: sprite_frag,
  8449. sprite_vert: sprite_vert
  8450. };
  8451. /**
  8452. * Uniforms library for shared webgl shaders
  8453. */
  8454. var UniformsLib = {
  8455. common: {
  8456. diffuse: {
  8457. value: new Color(0xeeeeee)
  8458. },
  8459. opacity: {
  8460. value: 1.0
  8461. },
  8462. map: {
  8463. value: null
  8464. },
  8465. uvTransform: {
  8466. value: new Matrix3()
  8467. },
  8468. uv2Transform: {
  8469. value: new Matrix3()
  8470. },
  8471. alphaMap: {
  8472. value: null
  8473. }
  8474. },
  8475. specularmap: {
  8476. specularMap: {
  8477. value: null
  8478. }
  8479. },
  8480. envmap: {
  8481. envMap: {
  8482. value: null
  8483. },
  8484. flipEnvMap: {
  8485. value: -1
  8486. },
  8487. reflectivity: {
  8488. value: 1.0
  8489. },
  8490. refractionRatio: {
  8491. value: 0.98
  8492. },
  8493. maxMipLevel: {
  8494. value: 0
  8495. }
  8496. },
  8497. aomap: {
  8498. aoMap: {
  8499. value: null
  8500. },
  8501. aoMapIntensity: {
  8502. value: 1
  8503. }
  8504. },
  8505. lightmap: {
  8506. lightMap: {
  8507. value: null
  8508. },
  8509. lightMapIntensity: {
  8510. value: 1
  8511. }
  8512. },
  8513. emissivemap: {
  8514. emissiveMap: {
  8515. value: null
  8516. }
  8517. },
  8518. bumpmap: {
  8519. bumpMap: {
  8520. value: null
  8521. },
  8522. bumpScale: {
  8523. value: 1
  8524. }
  8525. },
  8526. normalmap: {
  8527. normalMap: {
  8528. value: null
  8529. },
  8530. normalScale: {
  8531. value: new Vector2(1, 1)
  8532. }
  8533. },
  8534. displacementmap: {
  8535. displacementMap: {
  8536. value: null
  8537. },
  8538. displacementScale: {
  8539. value: 1
  8540. },
  8541. displacementBias: {
  8542. value: 0
  8543. }
  8544. },
  8545. roughnessmap: {
  8546. roughnessMap: {
  8547. value: null
  8548. }
  8549. },
  8550. metalnessmap: {
  8551. metalnessMap: {
  8552. value: null
  8553. }
  8554. },
  8555. gradientmap: {
  8556. gradientMap: {
  8557. value: null
  8558. }
  8559. },
  8560. fog: {
  8561. fogDensity: {
  8562. value: 0.00025
  8563. },
  8564. fogNear: {
  8565. value: 1
  8566. },
  8567. fogFar: {
  8568. value: 2000
  8569. },
  8570. fogColor: {
  8571. value: new Color(0xffffff)
  8572. }
  8573. },
  8574. lights: {
  8575. ambientLightColor: {
  8576. value: []
  8577. },
  8578. lightProbe: {
  8579. value: []
  8580. },
  8581. directionalLights: {
  8582. value: [],
  8583. properties: {
  8584. direction: {},
  8585. color: {}
  8586. }
  8587. },
  8588. directionalLightShadows: {
  8589. value: [],
  8590. properties: {
  8591. shadowBias: {},
  8592. shadowNormalBias: {},
  8593. shadowRadius: {},
  8594. shadowMapSize: {}
  8595. }
  8596. },
  8597. directionalShadowMap: {
  8598. value: []
  8599. },
  8600. directionalShadowMatrix: {
  8601. value: []
  8602. },
  8603. spotLights: {
  8604. value: [],
  8605. properties: {
  8606. color: {},
  8607. position: {},
  8608. direction: {},
  8609. distance: {},
  8610. coneCos: {},
  8611. penumbraCos: {},
  8612. decay: {}
  8613. }
  8614. },
  8615. spotLightShadows: {
  8616. value: [],
  8617. properties: {
  8618. shadowBias: {},
  8619. shadowNormalBias: {},
  8620. shadowRadius: {},
  8621. shadowMapSize: {}
  8622. }
  8623. },
  8624. spotShadowMap: {
  8625. value: []
  8626. },
  8627. spotShadowMatrix: {
  8628. value: []
  8629. },
  8630. pointLights: {
  8631. value: [],
  8632. properties: {
  8633. color: {},
  8634. position: {},
  8635. decay: {},
  8636. distance: {}
  8637. }
  8638. },
  8639. pointLightShadows: {
  8640. value: [],
  8641. properties: {
  8642. shadowBias: {},
  8643. shadowNormalBias: {},
  8644. shadowRadius: {},
  8645. shadowMapSize: {},
  8646. shadowCameraNear: {},
  8647. shadowCameraFar: {}
  8648. }
  8649. },
  8650. pointShadowMap: {
  8651. value: []
  8652. },
  8653. pointShadowMatrix: {
  8654. value: []
  8655. },
  8656. hemisphereLights: {
  8657. value: [],
  8658. properties: {
  8659. direction: {},
  8660. skyColor: {},
  8661. groundColor: {}
  8662. }
  8663. },
  8664. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8665. rectAreaLights: {
  8666. value: [],
  8667. properties: {
  8668. color: {},
  8669. position: {},
  8670. width: {},
  8671. height: {}
  8672. }
  8673. },
  8674. ltc_1: {
  8675. value: null
  8676. },
  8677. ltc_2: {
  8678. value: null
  8679. }
  8680. },
  8681. points: {
  8682. diffuse: {
  8683. value: new Color(0xeeeeee)
  8684. },
  8685. opacity: {
  8686. value: 1.0
  8687. },
  8688. size: {
  8689. value: 1.0
  8690. },
  8691. scale: {
  8692. value: 1.0
  8693. },
  8694. map: {
  8695. value: null
  8696. },
  8697. alphaMap: {
  8698. value: null
  8699. },
  8700. uvTransform: {
  8701. value: new Matrix3()
  8702. }
  8703. },
  8704. sprite: {
  8705. diffuse: {
  8706. value: new Color(0xeeeeee)
  8707. },
  8708. opacity: {
  8709. value: 1.0
  8710. },
  8711. center: {
  8712. value: new Vector2(0.5, 0.5)
  8713. },
  8714. rotation: {
  8715. value: 0.0
  8716. },
  8717. map: {
  8718. value: null
  8719. },
  8720. alphaMap: {
  8721. value: null
  8722. },
  8723. uvTransform: {
  8724. value: new Matrix3()
  8725. }
  8726. }
  8727. };
  8728. var ShaderLib = {
  8729. basic: {
  8730. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  8731. vertexShader: ShaderChunk.meshbasic_vert,
  8732. fragmentShader: ShaderChunk.meshbasic_frag
  8733. },
  8734. lambert: {
  8735. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  8736. emissive: {
  8737. value: new Color(0x000000)
  8738. }
  8739. }]),
  8740. vertexShader: ShaderChunk.meshlambert_vert,
  8741. fragmentShader: ShaderChunk.meshlambert_frag
  8742. },
  8743. phong: {
  8744. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  8745. emissive: {
  8746. value: new Color(0x000000)
  8747. },
  8748. specular: {
  8749. value: new Color(0x111111)
  8750. },
  8751. shininess: {
  8752. value: 30
  8753. }
  8754. }]),
  8755. vertexShader: ShaderChunk.meshphong_vert,
  8756. fragmentShader: ShaderChunk.meshphong_frag
  8757. },
  8758. standard: {
  8759. 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, {
  8760. emissive: {
  8761. value: new Color(0x000000)
  8762. },
  8763. roughness: {
  8764. value: 1.0
  8765. },
  8766. metalness: {
  8767. value: 0.0
  8768. },
  8769. envMapIntensity: {
  8770. value: 1
  8771. } // temporary
  8772. }]),
  8773. vertexShader: ShaderChunk.meshphysical_vert,
  8774. fragmentShader: ShaderChunk.meshphysical_frag
  8775. },
  8776. toon: {
  8777. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  8778. emissive: {
  8779. value: new Color(0x000000)
  8780. }
  8781. }]),
  8782. vertexShader: ShaderChunk.meshtoon_vert,
  8783. fragmentShader: ShaderChunk.meshtoon_frag
  8784. },
  8785. matcap: {
  8786. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  8787. matcap: {
  8788. value: null
  8789. }
  8790. }]),
  8791. vertexShader: ShaderChunk.meshmatcap_vert,
  8792. fragmentShader: ShaderChunk.meshmatcap_frag
  8793. },
  8794. points: {
  8795. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  8796. vertexShader: ShaderChunk.points_vert,
  8797. fragmentShader: ShaderChunk.points_frag
  8798. },
  8799. dashed: {
  8800. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  8801. scale: {
  8802. value: 1
  8803. },
  8804. dashSize: {
  8805. value: 1
  8806. },
  8807. totalSize: {
  8808. value: 2
  8809. }
  8810. }]),
  8811. vertexShader: ShaderChunk.linedashed_vert,
  8812. fragmentShader: ShaderChunk.linedashed_frag
  8813. },
  8814. depth: {
  8815. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  8816. vertexShader: ShaderChunk.depth_vert,
  8817. fragmentShader: ShaderChunk.depth_frag
  8818. },
  8819. normal: {
  8820. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  8821. opacity: {
  8822. value: 1.0
  8823. }
  8824. }]),
  8825. vertexShader: ShaderChunk.normal_vert,
  8826. fragmentShader: ShaderChunk.normal_frag
  8827. },
  8828. sprite: {
  8829. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  8830. vertexShader: ShaderChunk.sprite_vert,
  8831. fragmentShader: ShaderChunk.sprite_frag
  8832. },
  8833. background: {
  8834. uniforms: {
  8835. uvTransform: {
  8836. value: new Matrix3()
  8837. },
  8838. t2D: {
  8839. value: null
  8840. }
  8841. },
  8842. vertexShader: ShaderChunk.background_vert,
  8843. fragmentShader: ShaderChunk.background_frag
  8844. },
  8845. /* -------------------------------------------------------------------------
  8846. // Cube map shader
  8847. ------------------------------------------------------------------------- */
  8848. cube: {
  8849. uniforms: mergeUniforms([UniformsLib.envmap, {
  8850. opacity: {
  8851. value: 1.0
  8852. }
  8853. }]),
  8854. vertexShader: ShaderChunk.cube_vert,
  8855. fragmentShader: ShaderChunk.cube_frag
  8856. },
  8857. equirect: {
  8858. uniforms: {
  8859. tEquirect: {
  8860. value: null
  8861. }
  8862. },
  8863. vertexShader: ShaderChunk.equirect_vert,
  8864. fragmentShader: ShaderChunk.equirect_frag
  8865. },
  8866. distanceRGBA: {
  8867. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  8868. referencePosition: {
  8869. value: new Vector3()
  8870. },
  8871. nearDistance: {
  8872. value: 1
  8873. },
  8874. farDistance: {
  8875. value: 1000
  8876. }
  8877. }]),
  8878. vertexShader: ShaderChunk.distanceRGBA_vert,
  8879. fragmentShader: ShaderChunk.distanceRGBA_frag
  8880. },
  8881. shadow: {
  8882. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  8883. color: {
  8884. value: new Color(0x00000)
  8885. },
  8886. opacity: {
  8887. value: 1.0
  8888. }
  8889. }]),
  8890. vertexShader: ShaderChunk.shadow_vert,
  8891. fragmentShader: ShaderChunk.shadow_frag
  8892. }
  8893. };
  8894. ShaderLib.physical = {
  8895. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  8896. clearcoat: {
  8897. value: 0
  8898. },
  8899. clearcoatMap: {
  8900. value: null
  8901. },
  8902. clearcoatRoughness: {
  8903. value: 0
  8904. },
  8905. clearcoatRoughnessMap: {
  8906. value: null
  8907. },
  8908. clearcoatNormalScale: {
  8909. value: new Vector2(1, 1)
  8910. },
  8911. clearcoatNormalMap: {
  8912. value: null
  8913. },
  8914. sheen: {
  8915. value: new Color(0x000000)
  8916. },
  8917. transmission: {
  8918. value: 0
  8919. },
  8920. transmissionMap: {
  8921. value: null
  8922. }
  8923. }]),
  8924. vertexShader: ShaderChunk.meshphysical_vert,
  8925. fragmentShader: ShaderChunk.meshphysical_frag
  8926. };
  8927. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  8928. var clearColor = new Color(0x000000);
  8929. var clearAlpha = 0;
  8930. var planeMesh;
  8931. var boxMesh;
  8932. var currentBackground = null;
  8933. var currentBackgroundVersion = 0;
  8934. var currentTonemapping = null;
  8935. function render(renderList, scene, camera, forceClear) {
  8936. var background = scene.isScene === true ? scene.background : null;
  8937. if (background && background.isTexture) {
  8938. background = cubemaps.get(background);
  8939. } // Ignore background in AR
  8940. // TODO: Reconsider this.
  8941. var xr = renderer.xr;
  8942. var session = xr.getSession && xr.getSession();
  8943. if (session && session.environmentBlendMode === 'additive') {
  8944. background = null;
  8945. }
  8946. if (background === null) {
  8947. setClear(clearColor, clearAlpha);
  8948. } else if (background && background.isColor) {
  8949. setClear(background, 1);
  8950. forceClear = true;
  8951. }
  8952. if (renderer.autoClear || forceClear) {
  8953. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  8954. }
  8955. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  8956. if (boxMesh === undefined) {
  8957. boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
  8958. name: 'BackgroundCubeMaterial',
  8959. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  8960. vertexShader: ShaderLib.cube.vertexShader,
  8961. fragmentShader: ShaderLib.cube.fragmentShader,
  8962. side: BackSide,
  8963. depthTest: false,
  8964. depthWrite: false,
  8965. fog: false
  8966. }));
  8967. boxMesh.geometry.deleteAttribute('normal');
  8968. boxMesh.geometry.deleteAttribute('uv');
  8969. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  8970. this.matrixWorld.copyPosition(camera.matrixWorld);
  8971. }; // enable code injection for non-built-in material
  8972. Object.defineProperty(boxMesh.material, 'envMap', {
  8973. get: function get() {
  8974. return this.uniforms.envMap.value;
  8975. }
  8976. });
  8977. objects.update(boxMesh);
  8978. }
  8979. if (background.isWebGLCubeRenderTarget) {
  8980. // TODO Deprecate
  8981. background = background.texture;
  8982. }
  8983. boxMesh.material.uniforms.envMap.value = background;
  8984. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  8985. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  8986. boxMesh.material.needsUpdate = true;
  8987. currentBackground = background;
  8988. currentBackgroundVersion = background.version;
  8989. currentTonemapping = renderer.toneMapping;
  8990. } // push to the pre-sorted opaque render list
  8991. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  8992. } else if (background && background.isTexture) {
  8993. if (planeMesh === undefined) {
  8994. planeMesh = new Mesh(new PlaneBufferGeometry(2, 2), new ShaderMaterial({
  8995. name: 'BackgroundMaterial',
  8996. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  8997. vertexShader: ShaderLib.background.vertexShader,
  8998. fragmentShader: ShaderLib.background.fragmentShader,
  8999. side: FrontSide,
  9000. depthTest: false,
  9001. depthWrite: false,
  9002. fog: false
  9003. }));
  9004. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9005. Object.defineProperty(planeMesh.material, 'map', {
  9006. get: function get() {
  9007. return this.uniforms.t2D.value;
  9008. }
  9009. });
  9010. objects.update(planeMesh);
  9011. }
  9012. planeMesh.material.uniforms.t2D.value = background;
  9013. if (background.matrixAutoUpdate === true) {
  9014. background.updateMatrix();
  9015. }
  9016. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9017. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9018. planeMesh.material.needsUpdate = true;
  9019. currentBackground = background;
  9020. currentBackgroundVersion = background.version;
  9021. currentTonemapping = renderer.toneMapping;
  9022. } // push to the pre-sorted opaque render list
  9023. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9024. }
  9025. }
  9026. function setClear(color, alpha) {
  9027. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9028. }
  9029. return {
  9030. getClearColor: function getClearColor() {
  9031. return clearColor;
  9032. },
  9033. setClearColor: function setClearColor(color, alpha) {
  9034. clearColor.set(color);
  9035. clearAlpha = alpha !== undefined ? alpha : 1;
  9036. setClear(clearColor, clearAlpha);
  9037. },
  9038. getClearAlpha: function getClearAlpha() {
  9039. return clearAlpha;
  9040. },
  9041. setClearAlpha: function setClearAlpha(alpha) {
  9042. clearAlpha = alpha;
  9043. setClear(clearColor, clearAlpha);
  9044. },
  9045. render: render
  9046. };
  9047. }
  9048. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9049. var maxVertexAttributes = gl.getParameter(34921);
  9050. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9051. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9052. var bindingStates = {};
  9053. var defaultState = createBindingState(null);
  9054. var currentState = defaultState;
  9055. function setup(object, material, program, geometry, index) {
  9056. var updateBuffers = false;
  9057. if (vaoAvailable) {
  9058. var state = getBindingState(geometry, program, material);
  9059. if (currentState !== state) {
  9060. currentState = state;
  9061. bindVertexArrayObject(currentState.object);
  9062. }
  9063. updateBuffers = needsUpdate(geometry, index);
  9064. if (updateBuffers) saveCache(geometry, index);
  9065. } else {
  9066. var wireframe = material.wireframe === true;
  9067. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9068. currentState.geometry = geometry.id;
  9069. currentState.program = program.id;
  9070. currentState.wireframe = wireframe;
  9071. updateBuffers = true;
  9072. }
  9073. }
  9074. if (object.isInstancedMesh === true) {
  9075. updateBuffers = true;
  9076. }
  9077. if (index !== null) {
  9078. attributes.update(index, 34963);
  9079. }
  9080. if (updateBuffers) {
  9081. setupVertexAttributes(object, material, program, geometry);
  9082. if (index !== null) {
  9083. gl.bindBuffer(34963, attributes.get(index).buffer);
  9084. }
  9085. }
  9086. }
  9087. function createVertexArrayObject() {
  9088. if (capabilities.isWebGL2) return gl.createVertexArray();
  9089. return extension.createVertexArrayOES();
  9090. }
  9091. function bindVertexArrayObject(vao) {
  9092. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9093. return extension.bindVertexArrayOES(vao);
  9094. }
  9095. function deleteVertexArrayObject(vao) {
  9096. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9097. return extension.deleteVertexArrayOES(vao);
  9098. }
  9099. function getBindingState(geometry, program, material) {
  9100. var wireframe = material.wireframe === true;
  9101. var programMap = bindingStates[geometry.id];
  9102. if (programMap === undefined) {
  9103. programMap = {};
  9104. bindingStates[geometry.id] = programMap;
  9105. }
  9106. var stateMap = programMap[program.id];
  9107. if (stateMap === undefined) {
  9108. stateMap = {};
  9109. programMap[program.id] = stateMap;
  9110. }
  9111. var state = stateMap[wireframe];
  9112. if (state === undefined) {
  9113. state = createBindingState(createVertexArrayObject());
  9114. stateMap[wireframe] = state;
  9115. }
  9116. return state;
  9117. }
  9118. function createBindingState(vao) {
  9119. var newAttributes = [];
  9120. var enabledAttributes = [];
  9121. var attributeDivisors = [];
  9122. for (var i = 0; i < maxVertexAttributes; i++) {
  9123. newAttributes[i] = 0;
  9124. enabledAttributes[i] = 0;
  9125. attributeDivisors[i] = 0;
  9126. }
  9127. return {
  9128. // for backward compatibility on non-VAO support browser
  9129. geometry: null,
  9130. program: null,
  9131. wireframe: false,
  9132. newAttributes: newAttributes,
  9133. enabledAttributes: enabledAttributes,
  9134. attributeDivisors: attributeDivisors,
  9135. object: vao,
  9136. attributes: {},
  9137. index: null
  9138. };
  9139. }
  9140. function needsUpdate(geometry, index) {
  9141. var cachedAttributes = currentState.attributes;
  9142. var geometryAttributes = geometry.attributes;
  9143. if (Object.keys(cachedAttributes).length !== Object.keys(geometryAttributes).length) return true;
  9144. for (var key in geometryAttributes) {
  9145. var cachedAttribute = cachedAttributes[key];
  9146. var geometryAttribute = geometryAttributes[key];
  9147. if (cachedAttribute === undefined) return true;
  9148. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9149. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9150. }
  9151. if (currentState.index !== index) return true;
  9152. return false;
  9153. }
  9154. function saveCache(geometry, index) {
  9155. var cache = {};
  9156. var attributes = geometry.attributes;
  9157. for (var key in attributes) {
  9158. var attribute = attributes[key];
  9159. var data = {};
  9160. data.attribute = attribute;
  9161. if (attribute.data) {
  9162. data.data = attribute.data;
  9163. }
  9164. cache[key] = data;
  9165. }
  9166. currentState.attributes = cache;
  9167. currentState.index = index;
  9168. }
  9169. function initAttributes() {
  9170. var newAttributes = currentState.newAttributes;
  9171. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9172. newAttributes[i] = 0;
  9173. }
  9174. }
  9175. function enableAttribute(attribute) {
  9176. enableAttributeAndDivisor(attribute, 0);
  9177. }
  9178. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9179. var newAttributes = currentState.newAttributes;
  9180. var enabledAttributes = currentState.enabledAttributes;
  9181. var attributeDivisors = currentState.attributeDivisors;
  9182. newAttributes[attribute] = 1;
  9183. if (enabledAttributes[attribute] === 0) {
  9184. gl.enableVertexAttribArray(attribute);
  9185. enabledAttributes[attribute] = 1;
  9186. }
  9187. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9188. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9189. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9190. attributeDivisors[attribute] = meshPerAttribute;
  9191. }
  9192. }
  9193. function disableUnusedAttributes() {
  9194. var newAttributes = currentState.newAttributes;
  9195. var enabledAttributes = currentState.enabledAttributes;
  9196. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9197. if (enabledAttributes[i] !== newAttributes[i]) {
  9198. gl.disableVertexAttribArray(i);
  9199. enabledAttributes[i] = 0;
  9200. }
  9201. }
  9202. }
  9203. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9204. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9205. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9206. } else {
  9207. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9208. }
  9209. }
  9210. function setupVertexAttributes(object, material, program, geometry) {
  9211. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9212. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9213. }
  9214. initAttributes();
  9215. var geometryAttributes = geometry.attributes;
  9216. var programAttributes = program.getAttributes();
  9217. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9218. for (var name in programAttributes) {
  9219. var programAttribute = programAttributes[name];
  9220. if (programAttribute >= 0) {
  9221. var geometryAttribute = geometryAttributes[name];
  9222. if (geometryAttribute !== undefined) {
  9223. var normalized = geometryAttribute.normalized;
  9224. var size = geometryAttribute.itemSize;
  9225. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9226. if (attribute === undefined) continue;
  9227. var buffer = attribute.buffer;
  9228. var type = attribute.type;
  9229. var bytesPerElement = attribute.bytesPerElement;
  9230. if (geometryAttribute.isInterleavedBufferAttribute) {
  9231. var data = geometryAttribute.data;
  9232. var stride = data.stride;
  9233. var offset = geometryAttribute.offset;
  9234. if (data && data.isInstancedInterleavedBuffer) {
  9235. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9236. if (geometry._maxInstanceCount === undefined) {
  9237. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9238. }
  9239. } else {
  9240. enableAttribute(programAttribute);
  9241. }
  9242. gl.bindBuffer(34962, buffer);
  9243. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9244. } else {
  9245. if (geometryAttribute.isInstancedBufferAttribute) {
  9246. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9247. if (geometry._maxInstanceCount === undefined) {
  9248. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9249. }
  9250. } else {
  9251. enableAttribute(programAttribute);
  9252. }
  9253. gl.bindBuffer(34962, buffer);
  9254. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9255. }
  9256. } else if (name === 'instanceMatrix') {
  9257. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9258. if (_attribute === undefined) continue;
  9259. var _buffer = _attribute.buffer;
  9260. var _type = _attribute.type;
  9261. enableAttributeAndDivisor(programAttribute + 0, 1);
  9262. enableAttributeAndDivisor(programAttribute + 1, 1);
  9263. enableAttributeAndDivisor(programAttribute + 2, 1);
  9264. enableAttributeAndDivisor(programAttribute + 3, 1);
  9265. gl.bindBuffer(34962, _buffer);
  9266. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9267. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9268. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9269. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9270. } else if (name === 'instanceColor') {
  9271. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9272. if (_attribute2 === undefined) continue;
  9273. var _buffer2 = _attribute2.buffer;
  9274. var _type2 = _attribute2.type;
  9275. enableAttributeAndDivisor(programAttribute, 1);
  9276. gl.bindBuffer(34962, _buffer2);
  9277. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9278. } else if (materialDefaultAttributeValues !== undefined) {
  9279. var value = materialDefaultAttributeValues[name];
  9280. if (value !== undefined) {
  9281. switch (value.length) {
  9282. case 2:
  9283. gl.vertexAttrib2fv(programAttribute, value);
  9284. break;
  9285. case 3:
  9286. gl.vertexAttrib3fv(programAttribute, value);
  9287. break;
  9288. case 4:
  9289. gl.vertexAttrib4fv(programAttribute, value);
  9290. break;
  9291. default:
  9292. gl.vertexAttrib1fv(programAttribute, value);
  9293. }
  9294. }
  9295. }
  9296. }
  9297. }
  9298. disableUnusedAttributes();
  9299. }
  9300. function dispose() {
  9301. reset();
  9302. for (var geometryId in bindingStates) {
  9303. var programMap = bindingStates[geometryId];
  9304. for (var programId in programMap) {
  9305. var stateMap = programMap[programId];
  9306. for (var wireframe in stateMap) {
  9307. deleteVertexArrayObject(stateMap[wireframe].object);
  9308. delete stateMap[wireframe];
  9309. }
  9310. delete programMap[programId];
  9311. }
  9312. delete bindingStates[geometryId];
  9313. }
  9314. }
  9315. function releaseStatesOfGeometry(geometry) {
  9316. if (bindingStates[geometry.id] === undefined) return;
  9317. var programMap = bindingStates[geometry.id];
  9318. for (var programId in programMap) {
  9319. var stateMap = programMap[programId];
  9320. for (var wireframe in stateMap) {
  9321. deleteVertexArrayObject(stateMap[wireframe].object);
  9322. delete stateMap[wireframe];
  9323. }
  9324. delete programMap[programId];
  9325. }
  9326. delete bindingStates[geometry.id];
  9327. }
  9328. function releaseStatesOfProgram(program) {
  9329. for (var geometryId in bindingStates) {
  9330. var programMap = bindingStates[geometryId];
  9331. if (programMap[program.id] === undefined) continue;
  9332. var stateMap = programMap[program.id];
  9333. for (var wireframe in stateMap) {
  9334. deleteVertexArrayObject(stateMap[wireframe].object);
  9335. delete stateMap[wireframe];
  9336. }
  9337. delete programMap[program.id];
  9338. }
  9339. }
  9340. function reset() {
  9341. resetDefaultState();
  9342. if (currentState === defaultState) return;
  9343. currentState = defaultState;
  9344. bindVertexArrayObject(currentState.object);
  9345. } // for backward-compatilibity
  9346. function resetDefaultState() {
  9347. defaultState.geometry = null;
  9348. defaultState.program = null;
  9349. defaultState.wireframe = false;
  9350. }
  9351. return {
  9352. setup: setup,
  9353. reset: reset,
  9354. resetDefaultState: resetDefaultState,
  9355. dispose: dispose,
  9356. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9357. releaseStatesOfProgram: releaseStatesOfProgram,
  9358. initAttributes: initAttributes,
  9359. enableAttribute: enableAttribute,
  9360. disableUnusedAttributes: disableUnusedAttributes
  9361. };
  9362. }
  9363. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9364. var isWebGL2 = capabilities.isWebGL2;
  9365. var mode;
  9366. function setMode(value) {
  9367. mode = value;
  9368. }
  9369. function render(start, count) {
  9370. gl.drawArrays(mode, start, count);
  9371. info.update(count, mode, 1);
  9372. }
  9373. function renderInstances(start, count, primcount) {
  9374. if (primcount === 0) return;
  9375. var extension, methodName;
  9376. if (isWebGL2) {
  9377. extension = gl;
  9378. methodName = 'drawArraysInstanced';
  9379. } else {
  9380. extension = extensions.get('ANGLE_instanced_arrays');
  9381. methodName = 'drawArraysInstancedANGLE';
  9382. if (extension === null) {
  9383. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9384. return;
  9385. }
  9386. }
  9387. extension[methodName](mode, start, count, primcount);
  9388. info.update(count, mode, primcount);
  9389. } //
  9390. this.setMode = setMode;
  9391. this.render = render;
  9392. this.renderInstances = renderInstances;
  9393. }
  9394. function WebGLCapabilities(gl, extensions, parameters) {
  9395. var maxAnisotropy;
  9396. function getMaxAnisotropy() {
  9397. if (maxAnisotropy !== undefined) return maxAnisotropy;
  9398. var extension = extensions.get('EXT_texture_filter_anisotropic');
  9399. if (extension !== null) {
  9400. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  9401. } else {
  9402. maxAnisotropy = 0;
  9403. }
  9404. return maxAnisotropy;
  9405. }
  9406. function getMaxPrecision(precision) {
  9407. if (precision === 'highp') {
  9408. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  9409. return 'highp';
  9410. }
  9411. precision = 'mediump';
  9412. }
  9413. if (precision === 'mediump') {
  9414. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  9415. return 'mediump';
  9416. }
  9417. }
  9418. return 'lowp';
  9419. }
  9420. /* eslint-disable no-undef */
  9421. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  9422. /* eslint-enable no-undef */
  9423. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9424. var maxPrecision = getMaxPrecision(precision);
  9425. if (maxPrecision !== precision) {
  9426. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  9427. precision = maxPrecision;
  9428. }
  9429. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9430. var maxTextures = gl.getParameter(34930);
  9431. var maxVertexTextures = gl.getParameter(35660);
  9432. var maxTextureSize = gl.getParameter(3379);
  9433. var maxCubemapSize = gl.getParameter(34076);
  9434. var maxAttributes = gl.getParameter(34921);
  9435. var maxVertexUniforms = gl.getParameter(36347);
  9436. var maxVaryings = gl.getParameter(36348);
  9437. var maxFragmentUniforms = gl.getParameter(36349);
  9438. var vertexTextures = maxVertexTextures > 0;
  9439. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  9440. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9441. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  9442. return {
  9443. isWebGL2: isWebGL2,
  9444. getMaxAnisotropy: getMaxAnisotropy,
  9445. getMaxPrecision: getMaxPrecision,
  9446. precision: precision,
  9447. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9448. maxTextures: maxTextures,
  9449. maxVertexTextures: maxVertexTextures,
  9450. maxTextureSize: maxTextureSize,
  9451. maxCubemapSize: maxCubemapSize,
  9452. maxAttributes: maxAttributes,
  9453. maxVertexUniforms: maxVertexUniforms,
  9454. maxVaryings: maxVaryings,
  9455. maxFragmentUniforms: maxFragmentUniforms,
  9456. vertexTextures: vertexTextures,
  9457. floatFragmentTextures: floatFragmentTextures,
  9458. floatVertexTextures: floatVertexTextures,
  9459. maxSamples: maxSamples
  9460. };
  9461. }
  9462. function WebGLClipping(properties) {
  9463. var scope = this;
  9464. var globalState = null,
  9465. numGlobalPlanes = 0,
  9466. localClippingEnabled = false,
  9467. renderingShadows = false;
  9468. var plane = new Plane(),
  9469. viewNormalMatrix = new Matrix3(),
  9470. uniform = {
  9471. value: null,
  9472. needsUpdate: false
  9473. };
  9474. this.uniform = uniform;
  9475. this.numPlanes = 0;
  9476. this.numIntersection = 0;
  9477. this.init = function (planes, enableLocalClipping, camera) {
  9478. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  9479. // run another frame in order to reset the state:
  9480. numGlobalPlanes !== 0 || localClippingEnabled;
  9481. localClippingEnabled = enableLocalClipping;
  9482. globalState = projectPlanes(planes, camera, 0);
  9483. numGlobalPlanes = planes.length;
  9484. return enabled;
  9485. };
  9486. this.beginShadows = function () {
  9487. renderingShadows = true;
  9488. projectPlanes(null);
  9489. };
  9490. this.endShadows = function () {
  9491. renderingShadows = false;
  9492. resetGlobalState();
  9493. };
  9494. this.setState = function (material, camera, useCache) {
  9495. var planes = material.clippingPlanes,
  9496. clipIntersection = material.clipIntersection,
  9497. clipShadows = material.clipShadows;
  9498. var materialProperties = properties.get(material);
  9499. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  9500. // there's no local clipping
  9501. if (renderingShadows) {
  9502. // there's no global clipping
  9503. projectPlanes(null);
  9504. } else {
  9505. resetGlobalState();
  9506. }
  9507. } else {
  9508. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9509. lGlobal = nGlobal * 4;
  9510. var dstArray = materialProperties.clippingState || null;
  9511. uniform.value = dstArray; // ensure unique state
  9512. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  9513. for (var i = 0; i !== lGlobal; ++i) {
  9514. dstArray[i] = globalState[i];
  9515. }
  9516. materialProperties.clippingState = dstArray;
  9517. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9518. this.numPlanes += nGlobal;
  9519. }
  9520. };
  9521. function resetGlobalState() {
  9522. if (uniform.value !== globalState) {
  9523. uniform.value = globalState;
  9524. uniform.needsUpdate = numGlobalPlanes > 0;
  9525. }
  9526. scope.numPlanes = numGlobalPlanes;
  9527. scope.numIntersection = 0;
  9528. }
  9529. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  9530. var nPlanes = planes !== null ? planes.length : 0;
  9531. var dstArray = null;
  9532. if (nPlanes !== 0) {
  9533. dstArray = uniform.value;
  9534. if (skipTransform !== true || dstArray === null) {
  9535. var flatSize = dstOffset + nPlanes * 4,
  9536. viewMatrix = camera.matrixWorldInverse;
  9537. viewNormalMatrix.getNormalMatrix(viewMatrix);
  9538. if (dstArray === null || dstArray.length < flatSize) {
  9539. dstArray = new Float32Array(flatSize);
  9540. }
  9541. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  9542. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  9543. plane.normal.toArray(dstArray, i4);
  9544. dstArray[i4 + 3] = plane.constant;
  9545. }
  9546. }
  9547. uniform.value = dstArray;
  9548. uniform.needsUpdate = true;
  9549. }
  9550. scope.numPlanes = nPlanes;
  9551. scope.numIntersection = 0;
  9552. return dstArray;
  9553. }
  9554. }
  9555. function WebGLCubeMaps(renderer) {
  9556. var cubemaps = new WeakMap();
  9557. function mapTextureMapping(texture, mapping) {
  9558. if (mapping === EquirectangularReflectionMapping) {
  9559. texture.mapping = CubeReflectionMapping;
  9560. } else if (mapping === EquirectangularRefractionMapping) {
  9561. texture.mapping = CubeRefractionMapping;
  9562. }
  9563. return texture;
  9564. }
  9565. function get(texture) {
  9566. if (texture && texture.isTexture) {
  9567. var mapping = texture.mapping;
  9568. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  9569. if (cubemaps.has(texture)) {
  9570. var cubemap = cubemaps.get(texture).texture;
  9571. return mapTextureMapping(cubemap, texture.mapping);
  9572. } else {
  9573. var image = texture.image;
  9574. if (image && image.height > 0) {
  9575. var currentRenderList = renderer.getRenderList();
  9576. var currentRenderTarget = renderer.getRenderTarget();
  9577. var currentRenderState = renderer.getRenderState();
  9578. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  9579. renderTarget.fromEquirectangularTexture(renderer, texture);
  9580. cubemaps.set(texture, renderTarget);
  9581. renderer.setRenderTarget(currentRenderTarget);
  9582. renderer.setRenderList(currentRenderList);
  9583. renderer.setRenderState(currentRenderState);
  9584. texture.addEventListener('dispose', onTextureDispose);
  9585. return mapTextureMapping(renderTarget.texture, texture.mapping);
  9586. } else {
  9587. // image not yet ready. try the conversion next frame
  9588. return null;
  9589. }
  9590. }
  9591. }
  9592. }
  9593. return texture;
  9594. }
  9595. function onTextureDispose(event) {
  9596. var texture = event.target;
  9597. texture.removeEventListener('dispose', onTextureDispose);
  9598. var cubemap = cubemaps.get(texture);
  9599. if (cubemap !== undefined) {
  9600. cubemaps.delete(texture);
  9601. cubemap.dispose();
  9602. }
  9603. }
  9604. function dispose() {
  9605. cubemaps = new WeakMap();
  9606. }
  9607. return {
  9608. get: get,
  9609. dispose: dispose
  9610. };
  9611. }
  9612. function WebGLExtensions(gl) {
  9613. var extensions = {};
  9614. return {
  9615. has: function has(name) {
  9616. if (extensions[name] !== undefined) {
  9617. return extensions[name] !== null;
  9618. }
  9619. var extension;
  9620. switch (name) {
  9621. case 'WEBGL_depth_texture':
  9622. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  9623. break;
  9624. case 'EXT_texture_filter_anisotropic':
  9625. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  9626. break;
  9627. case 'WEBGL_compressed_texture_s3tc':
  9628. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  9629. break;
  9630. case 'WEBGL_compressed_texture_pvrtc':
  9631. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  9632. break;
  9633. default:
  9634. extension = gl.getExtension(name);
  9635. }
  9636. extensions[name] = extension;
  9637. return extension !== null;
  9638. },
  9639. get: function get(name) {
  9640. if (!this.has(name)) {
  9641. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  9642. }
  9643. return extensions[name];
  9644. }
  9645. };
  9646. }
  9647. function WebGLGeometries(gl, attributes, info, bindingStates) {
  9648. var geometries = new WeakMap();
  9649. var wireframeAttributes = new WeakMap();
  9650. function onGeometryDispose(event) {
  9651. var geometry = event.target;
  9652. var buffergeometry = geometries.get(geometry);
  9653. if (buffergeometry.index !== null) {
  9654. attributes.remove(buffergeometry.index);
  9655. }
  9656. for (var name in buffergeometry.attributes) {
  9657. attributes.remove(buffergeometry.attributes[name]);
  9658. }
  9659. geometry.removeEventListener('dispose', onGeometryDispose);
  9660. geometries.delete(geometry);
  9661. var attribute = wireframeAttributes.get(buffergeometry);
  9662. if (attribute) {
  9663. attributes.remove(attribute);
  9664. wireframeAttributes.delete(buffergeometry);
  9665. }
  9666. bindingStates.releaseStatesOfGeometry(buffergeometry);
  9667. if (geometry.isInstancedBufferGeometry === true) {
  9668. delete geometry._maxInstanceCount;
  9669. } //
  9670. info.memory.geometries--;
  9671. }
  9672. function get(object, geometry) {
  9673. var buffergeometry = geometries.get(geometry);
  9674. if (buffergeometry) return buffergeometry;
  9675. geometry.addEventListener('dispose', onGeometryDispose);
  9676. if (geometry.isBufferGeometry) {
  9677. buffergeometry = geometry;
  9678. } else if (geometry.isGeometry) {
  9679. if (geometry._bufferGeometry === undefined) {
  9680. geometry._bufferGeometry = new BufferGeometry().setFromObject(object);
  9681. }
  9682. buffergeometry = geometry._bufferGeometry;
  9683. }
  9684. geometries.set(geometry, buffergeometry);
  9685. info.memory.geometries++;
  9686. return buffergeometry;
  9687. }
  9688. function update(geometry) {
  9689. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  9690. for (var name in geometryAttributes) {
  9691. attributes.update(geometryAttributes[name], 34962);
  9692. } // morph targets
  9693. var morphAttributes = geometry.morphAttributes;
  9694. for (var _name in morphAttributes) {
  9695. var array = morphAttributes[_name];
  9696. for (var i = 0, l = array.length; i < l; i++) {
  9697. attributes.update(array[i], 34962);
  9698. }
  9699. }
  9700. }
  9701. function updateWireframeAttribute(geometry) {
  9702. var indices = [];
  9703. var geometryIndex = geometry.index;
  9704. var geometryPosition = geometry.attributes.position;
  9705. var version = 0;
  9706. if (geometryIndex !== null) {
  9707. var array = geometryIndex.array;
  9708. version = geometryIndex.version;
  9709. for (var i = 0, l = array.length; i < l; i += 3) {
  9710. var a = array[i + 0];
  9711. var b = array[i + 1];
  9712. var c = array[i + 2];
  9713. indices.push(a, b, b, c, c, a);
  9714. }
  9715. } else {
  9716. var _array = geometryPosition.array;
  9717. version = geometryPosition.version;
  9718. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  9719. var _a = _i + 0;
  9720. var _b = _i + 1;
  9721. var _c = _i + 2;
  9722. indices.push(_a, _b, _b, _c, _c, _a);
  9723. }
  9724. }
  9725. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  9726. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  9727. //
  9728. var previousAttribute = wireframeAttributes.get(geometry);
  9729. if (previousAttribute) attributes.remove(previousAttribute); //
  9730. wireframeAttributes.set(geometry, attribute);
  9731. }
  9732. function getWireframeAttribute(geometry) {
  9733. var currentAttribute = wireframeAttributes.get(geometry);
  9734. if (currentAttribute) {
  9735. var geometryIndex = geometry.index;
  9736. if (geometryIndex !== null) {
  9737. // if the attribute is obsolete, create a new one
  9738. if (currentAttribute.version < geometryIndex.version) {
  9739. updateWireframeAttribute(geometry);
  9740. }
  9741. }
  9742. } else {
  9743. updateWireframeAttribute(geometry);
  9744. }
  9745. return wireframeAttributes.get(geometry);
  9746. }
  9747. return {
  9748. get: get,
  9749. update: update,
  9750. getWireframeAttribute: getWireframeAttribute
  9751. };
  9752. }
  9753. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  9754. var isWebGL2 = capabilities.isWebGL2;
  9755. var mode;
  9756. function setMode(value) {
  9757. mode = value;
  9758. }
  9759. var type, bytesPerElement;
  9760. function setIndex(value) {
  9761. type = value.type;
  9762. bytesPerElement = value.bytesPerElement;
  9763. }
  9764. function render(start, count) {
  9765. gl.drawElements(mode, count, type, start * bytesPerElement);
  9766. info.update(count, mode, 1);
  9767. }
  9768. function renderInstances(start, count, primcount) {
  9769. if (primcount === 0) return;
  9770. var extension, methodName;
  9771. if (isWebGL2) {
  9772. extension = gl;
  9773. methodName = 'drawElementsInstanced';
  9774. } else {
  9775. extension = extensions.get('ANGLE_instanced_arrays');
  9776. methodName = 'drawElementsInstancedANGLE';
  9777. if (extension === null) {
  9778. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  9779. return;
  9780. }
  9781. }
  9782. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  9783. info.update(count, mode, primcount);
  9784. } //
  9785. this.setMode = setMode;
  9786. this.setIndex = setIndex;
  9787. this.render = render;
  9788. this.renderInstances = renderInstances;
  9789. }
  9790. function WebGLInfo(gl) {
  9791. var memory = {
  9792. geometries: 0,
  9793. textures: 0
  9794. };
  9795. var render = {
  9796. frame: 0,
  9797. calls: 0,
  9798. triangles: 0,
  9799. points: 0,
  9800. lines: 0
  9801. };
  9802. function update(count, mode, instanceCount) {
  9803. render.calls++;
  9804. switch (mode) {
  9805. case 4:
  9806. render.triangles += instanceCount * (count / 3);
  9807. break;
  9808. case 1:
  9809. render.lines += instanceCount * (count / 2);
  9810. break;
  9811. case 3:
  9812. render.lines += instanceCount * (count - 1);
  9813. break;
  9814. case 2:
  9815. render.lines += instanceCount * count;
  9816. break;
  9817. case 0:
  9818. render.points += instanceCount * count;
  9819. break;
  9820. default:
  9821. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  9822. break;
  9823. }
  9824. }
  9825. function reset() {
  9826. render.frame++;
  9827. render.calls = 0;
  9828. render.triangles = 0;
  9829. render.points = 0;
  9830. render.lines = 0;
  9831. }
  9832. return {
  9833. memory: memory,
  9834. render: render,
  9835. programs: null,
  9836. autoReset: true,
  9837. reset: reset,
  9838. update: update
  9839. };
  9840. }
  9841. function numericalSort(a, b) {
  9842. return a[0] - b[0];
  9843. }
  9844. function absNumericalSort(a, b) {
  9845. return Math.abs(b[1]) - Math.abs(a[1]);
  9846. }
  9847. function WebGLMorphtargets(gl) {
  9848. var influencesList = {};
  9849. var morphInfluences = new Float32Array(8);
  9850. var workInfluences = [];
  9851. for (var i = 0; i < 8; i++) {
  9852. workInfluences[i] = [i, 0];
  9853. }
  9854. function update(object, geometry, material, program) {
  9855. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9856. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9857. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9858. var influences = influencesList[geometry.id];
  9859. if (influences === undefined) {
  9860. // initialise list
  9861. influences = [];
  9862. for (var _i = 0; _i < length; _i++) {
  9863. influences[_i] = [_i, 0];
  9864. }
  9865. influencesList[geometry.id] = influences;
  9866. } // Collect influences
  9867. for (var _i2 = 0; _i2 < length; _i2++) {
  9868. var influence = influences[_i2];
  9869. influence[0] = _i2;
  9870. influence[1] = objectInfluences[_i2];
  9871. }
  9872. influences.sort(absNumericalSort);
  9873. for (var _i3 = 0; _i3 < 8; _i3++) {
  9874. if (_i3 < length && influences[_i3][1]) {
  9875. workInfluences[_i3][0] = influences[_i3][0];
  9876. workInfluences[_i3][1] = influences[_i3][1];
  9877. } else {
  9878. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  9879. workInfluences[_i3][1] = 0;
  9880. }
  9881. }
  9882. workInfluences.sort(numericalSort);
  9883. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9884. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9885. var morphInfluencesSum = 0;
  9886. for (var _i4 = 0; _i4 < 8; _i4++) {
  9887. var _influence = workInfluences[_i4];
  9888. var index = _influence[0];
  9889. var value = _influence[1];
  9890. if (index !== Number.MAX_SAFE_INTEGER && value) {
  9891. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  9892. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  9893. }
  9894. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  9895. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  9896. }
  9897. morphInfluences[_i4] = value;
  9898. morphInfluencesSum += value;
  9899. } else {
  9900. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== undefined) {
  9901. geometry.deleteAttribute('morphTarget' + _i4);
  9902. }
  9903. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== undefined) {
  9904. geometry.deleteAttribute('morphNormal' + _i4);
  9905. }
  9906. morphInfluences[_i4] = 0;
  9907. }
  9908. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9909. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9910. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9911. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9912. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  9913. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  9914. }
  9915. return {
  9916. update: update
  9917. };
  9918. }
  9919. function WebGLObjects(gl, geometries, attributes, info) {
  9920. var updateMap = new WeakMap();
  9921. function update(object) {
  9922. var frame = info.render.frame;
  9923. var geometry = object.geometry;
  9924. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  9925. if (updateMap.get(buffergeometry) !== frame) {
  9926. if (geometry.isGeometry) {
  9927. buffergeometry.updateFromObject(object);
  9928. }
  9929. geometries.update(buffergeometry);
  9930. updateMap.set(buffergeometry, frame);
  9931. }
  9932. if (object.isInstancedMesh) {
  9933. attributes.update(object.instanceMatrix, 34962);
  9934. if (object.instanceColor !== null) {
  9935. attributes.update(object.instanceColor, 34962);
  9936. }
  9937. }
  9938. return buffergeometry;
  9939. }
  9940. function dispose() {
  9941. updateMap = new WeakMap();
  9942. }
  9943. return {
  9944. update: update,
  9945. dispose: dispose
  9946. };
  9947. }
  9948. function DataTexture2DArray(data, width, height, depth) {
  9949. Texture.call(this, null);
  9950. this.image = {
  9951. data: data || null,
  9952. width: width || 1,
  9953. height: height || 1,
  9954. depth: depth || 1
  9955. };
  9956. this.magFilter = NearestFilter;
  9957. this.minFilter = NearestFilter;
  9958. this.wrapR = ClampToEdgeWrapping;
  9959. this.generateMipmaps = false;
  9960. this.flipY = false;
  9961. this.needsUpdate = true;
  9962. }
  9963. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  9964. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9965. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9966. function DataTexture3D(data, width, height, depth) {
  9967. // We're going to add .setXXX() methods for setting properties later.
  9968. // Users can still set in DataTexture3D directly.
  9969. //
  9970. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9971. // texture.anisotropy = 16;
  9972. //
  9973. // See #14839
  9974. Texture.call(this, null);
  9975. this.image = {
  9976. data: data || null,
  9977. width: width || 1,
  9978. height: height || 1,
  9979. depth: depth || 1
  9980. };
  9981. this.magFilter = NearestFilter;
  9982. this.minFilter = NearestFilter;
  9983. this.wrapR = ClampToEdgeWrapping;
  9984. this.generateMipmaps = false;
  9985. this.flipY = false;
  9986. this.needsUpdate = true;
  9987. }
  9988. DataTexture3D.prototype = Object.create(Texture.prototype);
  9989. DataTexture3D.prototype.constructor = DataTexture3D;
  9990. DataTexture3D.prototype.isDataTexture3D = true;
  9991. /**
  9992. * Uniforms of a program.
  9993. * Those form a tree structure with a special top-level container for the root,
  9994. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9995. *
  9996. *
  9997. * Properties of inner nodes including the top-level container:
  9998. *
  9999. * .seq - array of nested uniforms
  10000. * .map - nested uniforms by name
  10001. *
  10002. *
  10003. * Methods of all nodes except the top-level container:
  10004. *
  10005. * .setValue( gl, value, [textures] )
  10006. *
  10007. * uploads a uniform value(s)
  10008. * the 'textures' parameter is needed for sampler uniforms
  10009. *
  10010. *
  10011. * Static methods of the top-level container (textures factorizations):
  10012. *
  10013. * .upload( gl, seq, values, textures )
  10014. *
  10015. * sets uniforms in 'seq' to 'values[id].value'
  10016. *
  10017. * .seqWithValue( seq, values ) : filteredSeq
  10018. *
  10019. * filters 'seq' entries with corresponding entry in values
  10020. *
  10021. *
  10022. * Methods of the top-level container (textures factorizations):
  10023. *
  10024. * .setValue( gl, name, value, textures )
  10025. *
  10026. * sets uniform with name 'name' to 'value'
  10027. *
  10028. * .setOptional( gl, obj, prop )
  10029. *
  10030. * like .set for an optional property of the object
  10031. *
  10032. */
  10033. var emptyTexture = new Texture();
  10034. var emptyTexture2dArray = new DataTexture2DArray();
  10035. var emptyTexture3d = new DataTexture3D();
  10036. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10037. // Array Caches (provide typed arrays for temporary by size)
  10038. var arrayCacheF32 = [];
  10039. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10040. var mat4array = new Float32Array(16);
  10041. var mat3array = new Float32Array(9);
  10042. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10043. function flatten(array, nBlocks, blockSize) {
  10044. var firstElem = array[0];
  10045. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10046. // see http://jacksondunstan.com/articles/983
  10047. var n = nBlocks * blockSize;
  10048. var r = arrayCacheF32[n];
  10049. if (r === undefined) {
  10050. r = new Float32Array(n);
  10051. arrayCacheF32[n] = r;
  10052. }
  10053. if (nBlocks !== 0) {
  10054. firstElem.toArray(r, 0);
  10055. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10056. offset += blockSize;
  10057. array[i].toArray(r, offset);
  10058. }
  10059. }
  10060. return r;
  10061. }
  10062. function arraysEqual(a, b) {
  10063. if (a.length !== b.length) return false;
  10064. for (var i = 0, l = a.length; i < l; i++) {
  10065. if (a[i] !== b[i]) return false;
  10066. }
  10067. return true;
  10068. }
  10069. function copyArray(a, b) {
  10070. for (var i = 0, l = b.length; i < l; i++) {
  10071. a[i] = b[i];
  10072. }
  10073. } // Texture unit allocation
  10074. function allocTexUnits(textures, n) {
  10075. var r = arrayCacheI32[n];
  10076. if (r === undefined) {
  10077. r = new Int32Array(n);
  10078. arrayCacheI32[n] = r;
  10079. }
  10080. for (var i = 0; i !== n; ++i) {
  10081. r[i] = textures.allocateTextureUnit();
  10082. }
  10083. return r;
  10084. } // --- Setters ---
  10085. // Note: Defining these methods externally, because they come in a bunch
  10086. // and this way their names minify.
  10087. // Single scalar
  10088. function setValueV1f(gl, v) {
  10089. var cache = this.cache;
  10090. if (cache[0] === v) return;
  10091. gl.uniform1f(this.addr, v);
  10092. cache[0] = v;
  10093. } // Single float vector (from flat array or THREE.VectorN)
  10094. function setValueV2f(gl, v) {
  10095. var cache = this.cache;
  10096. if (v.x !== undefined) {
  10097. if (cache[0] !== v.x || cache[1] !== v.y) {
  10098. gl.uniform2f(this.addr, v.x, v.y);
  10099. cache[0] = v.x;
  10100. cache[1] = v.y;
  10101. }
  10102. } else {
  10103. if (arraysEqual(cache, v)) return;
  10104. gl.uniform2fv(this.addr, v);
  10105. copyArray(cache, v);
  10106. }
  10107. }
  10108. function setValueV3f(gl, v) {
  10109. var cache = this.cache;
  10110. if (v.x !== undefined) {
  10111. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10112. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10113. cache[0] = v.x;
  10114. cache[1] = v.y;
  10115. cache[2] = v.z;
  10116. }
  10117. } else if (v.r !== undefined) {
  10118. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10119. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10120. cache[0] = v.r;
  10121. cache[1] = v.g;
  10122. cache[2] = v.b;
  10123. }
  10124. } else {
  10125. if (arraysEqual(cache, v)) return;
  10126. gl.uniform3fv(this.addr, v);
  10127. copyArray(cache, v);
  10128. }
  10129. }
  10130. function setValueV4f(gl, v) {
  10131. var cache = this.cache;
  10132. if (v.x !== undefined) {
  10133. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10134. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10135. cache[0] = v.x;
  10136. cache[1] = v.y;
  10137. cache[2] = v.z;
  10138. cache[3] = v.w;
  10139. }
  10140. } else {
  10141. if (arraysEqual(cache, v)) return;
  10142. gl.uniform4fv(this.addr, v);
  10143. copyArray(cache, v);
  10144. }
  10145. } // Single matrix (from flat array or MatrixN)
  10146. function setValueM2(gl, v) {
  10147. var cache = this.cache;
  10148. var elements = v.elements;
  10149. if (elements === undefined) {
  10150. if (arraysEqual(cache, v)) return;
  10151. gl.uniformMatrix2fv(this.addr, false, v);
  10152. copyArray(cache, v);
  10153. } else {
  10154. if (arraysEqual(cache, elements)) return;
  10155. mat2array.set(elements);
  10156. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10157. copyArray(cache, elements);
  10158. }
  10159. }
  10160. function setValueM3(gl, v) {
  10161. var cache = this.cache;
  10162. var elements = v.elements;
  10163. if (elements === undefined) {
  10164. if (arraysEqual(cache, v)) return;
  10165. gl.uniformMatrix3fv(this.addr, false, v);
  10166. copyArray(cache, v);
  10167. } else {
  10168. if (arraysEqual(cache, elements)) return;
  10169. mat3array.set(elements);
  10170. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10171. copyArray(cache, elements);
  10172. }
  10173. }
  10174. function setValueM4(gl, v) {
  10175. var cache = this.cache;
  10176. var elements = v.elements;
  10177. if (elements === undefined) {
  10178. if (arraysEqual(cache, v)) return;
  10179. gl.uniformMatrix4fv(this.addr, false, v);
  10180. copyArray(cache, v);
  10181. } else {
  10182. if (arraysEqual(cache, elements)) return;
  10183. mat4array.set(elements);
  10184. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10185. copyArray(cache, elements);
  10186. }
  10187. } // Single texture (2D / Cube)
  10188. function setValueT1(gl, v, textures) {
  10189. var cache = this.cache;
  10190. var unit = textures.allocateTextureUnit();
  10191. if (cache[0] !== unit) {
  10192. gl.uniform1i(this.addr, unit);
  10193. cache[0] = unit;
  10194. }
  10195. textures.safeSetTexture2D(v || emptyTexture, unit);
  10196. }
  10197. function setValueT2DArray1(gl, v, textures) {
  10198. var cache = this.cache;
  10199. var unit = textures.allocateTextureUnit();
  10200. if (cache[0] !== unit) {
  10201. gl.uniform1i(this.addr, unit);
  10202. cache[0] = unit;
  10203. }
  10204. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10205. }
  10206. function setValueT3D1(gl, v, textures) {
  10207. var cache = this.cache;
  10208. var unit = textures.allocateTextureUnit();
  10209. if (cache[0] !== unit) {
  10210. gl.uniform1i(this.addr, unit);
  10211. cache[0] = unit;
  10212. }
  10213. textures.setTexture3D(v || emptyTexture3d, unit);
  10214. }
  10215. function setValueT6(gl, v, textures) {
  10216. var cache = this.cache;
  10217. var unit = textures.allocateTextureUnit();
  10218. if (cache[0] !== unit) {
  10219. gl.uniform1i(this.addr, unit);
  10220. cache[0] = unit;
  10221. }
  10222. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10223. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10224. function setValueV1i(gl, v) {
  10225. var cache = this.cache;
  10226. if (cache[0] === v) return;
  10227. gl.uniform1i(this.addr, v);
  10228. cache[0] = v;
  10229. }
  10230. function setValueV2i(gl, v) {
  10231. var cache = this.cache;
  10232. if (arraysEqual(cache, v)) return;
  10233. gl.uniform2iv(this.addr, v);
  10234. copyArray(cache, v);
  10235. }
  10236. function setValueV3i(gl, v) {
  10237. var cache = this.cache;
  10238. if (arraysEqual(cache, v)) return;
  10239. gl.uniform3iv(this.addr, v);
  10240. copyArray(cache, v);
  10241. }
  10242. function setValueV4i(gl, v) {
  10243. var cache = this.cache;
  10244. if (arraysEqual(cache, v)) return;
  10245. gl.uniform4iv(this.addr, v);
  10246. copyArray(cache, v);
  10247. } // uint
  10248. function setValueV1ui(gl, v) {
  10249. var cache = this.cache;
  10250. if (cache[0] === v) return;
  10251. gl.uniform1ui(this.addr, v);
  10252. cache[0] = v;
  10253. } // Helper to pick the right setter for the singular case
  10254. function getSingularSetter(type) {
  10255. switch (type) {
  10256. case 0x1406:
  10257. return setValueV1f;
  10258. // FLOAT
  10259. case 0x8b50:
  10260. return setValueV2f;
  10261. // _VEC2
  10262. case 0x8b51:
  10263. return setValueV3f;
  10264. // _VEC3
  10265. case 0x8b52:
  10266. return setValueV4f;
  10267. // _VEC4
  10268. case 0x8b5a:
  10269. return setValueM2;
  10270. // _MAT2
  10271. case 0x8b5b:
  10272. return setValueM3;
  10273. // _MAT3
  10274. case 0x8b5c:
  10275. return setValueM4;
  10276. // _MAT4
  10277. case 0x1404:
  10278. case 0x8b56:
  10279. return setValueV1i;
  10280. // INT, BOOL
  10281. case 0x8b53:
  10282. case 0x8b57:
  10283. return setValueV2i;
  10284. // _VEC2
  10285. case 0x8b54:
  10286. case 0x8b58:
  10287. return setValueV3i;
  10288. // _VEC3
  10289. case 0x8b55:
  10290. case 0x8b59:
  10291. return setValueV4i;
  10292. // _VEC4
  10293. case 0x1405:
  10294. return setValueV1ui;
  10295. // UINT
  10296. case 0x8b5e: // SAMPLER_2D
  10297. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10298. case 0x8dca: // INT_SAMPLER_2D
  10299. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10300. case 0x8b62:
  10301. // SAMPLER_2D_SHADOW
  10302. return setValueT1;
  10303. case 0x8b5f: // SAMPLER_3D
  10304. case 0x8dcb: // INT_SAMPLER_3D
  10305. case 0x8dd3:
  10306. // UNSIGNED_INT_SAMPLER_3D
  10307. return setValueT3D1;
  10308. case 0x8b60: // SAMPLER_CUBE
  10309. case 0x8dcc: // INT_SAMPLER_CUBE
  10310. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10311. case 0x8dc5:
  10312. // SAMPLER_CUBE_SHADOW
  10313. return setValueT6;
  10314. case 0x8dc1: // SAMPLER_2D_ARRAY
  10315. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10316. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10317. case 0x8dc4:
  10318. // SAMPLER_2D_ARRAY_SHADOW
  10319. return setValueT2DArray1;
  10320. }
  10321. } // Array of scalars
  10322. function setValueV1fArray(gl, v) {
  10323. gl.uniform1fv(this.addr, v);
  10324. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10325. function setValueV1iArray(gl, v) {
  10326. gl.uniform1iv(this.addr, v);
  10327. }
  10328. function setValueV2iArray(gl, v) {
  10329. gl.uniform2iv(this.addr, v);
  10330. }
  10331. function setValueV3iArray(gl, v) {
  10332. gl.uniform3iv(this.addr, v);
  10333. }
  10334. function setValueV4iArray(gl, v) {
  10335. gl.uniform4iv(this.addr, v);
  10336. } // Array of vectors (flat or from THREE classes)
  10337. function setValueV2fArray(gl, v) {
  10338. var data = flatten(v, this.size, 2);
  10339. gl.uniform2fv(this.addr, data);
  10340. }
  10341. function setValueV3fArray(gl, v) {
  10342. var data = flatten(v, this.size, 3);
  10343. gl.uniform3fv(this.addr, data);
  10344. }
  10345. function setValueV4fArray(gl, v) {
  10346. var data = flatten(v, this.size, 4);
  10347. gl.uniform4fv(this.addr, data);
  10348. } // Array of matrices (flat or from THREE clases)
  10349. function setValueM2Array(gl, v) {
  10350. var data = flatten(v, this.size, 4);
  10351. gl.uniformMatrix2fv(this.addr, false, data);
  10352. }
  10353. function setValueM3Array(gl, v) {
  10354. var data = flatten(v, this.size, 9);
  10355. gl.uniformMatrix3fv(this.addr, false, data);
  10356. }
  10357. function setValueM4Array(gl, v) {
  10358. var data = flatten(v, this.size, 16);
  10359. gl.uniformMatrix4fv(this.addr, false, data);
  10360. } // Array of textures (2D / Cube)
  10361. function setValueT1Array(gl, v, textures) {
  10362. var n = v.length;
  10363. var units = allocTexUnits(textures, n);
  10364. gl.uniform1iv(this.addr, units);
  10365. for (var i = 0; i !== n; ++i) {
  10366. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  10367. }
  10368. }
  10369. function setValueT6Array(gl, v, textures) {
  10370. var n = v.length;
  10371. var units = allocTexUnits(textures, n);
  10372. gl.uniform1iv(this.addr, units);
  10373. for (var i = 0; i !== n; ++i) {
  10374. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  10375. }
  10376. } // Helper to pick the right setter for a pure (bottom-level) array
  10377. function getPureArraySetter(type) {
  10378. switch (type) {
  10379. case 0x1406:
  10380. return setValueV1fArray;
  10381. // FLOAT
  10382. case 0x8b50:
  10383. return setValueV2fArray;
  10384. // _VEC2
  10385. case 0x8b51:
  10386. return setValueV3fArray;
  10387. // _VEC3
  10388. case 0x8b52:
  10389. return setValueV4fArray;
  10390. // _VEC4
  10391. case 0x8b5a:
  10392. return setValueM2Array;
  10393. // _MAT2
  10394. case 0x8b5b:
  10395. return setValueM3Array;
  10396. // _MAT3
  10397. case 0x8b5c:
  10398. return setValueM4Array;
  10399. // _MAT4
  10400. case 0x1404:
  10401. case 0x8b56:
  10402. return setValueV1iArray;
  10403. // INT, BOOL
  10404. case 0x8b53:
  10405. case 0x8b57:
  10406. return setValueV2iArray;
  10407. // _VEC2
  10408. case 0x8b54:
  10409. case 0x8b58:
  10410. return setValueV3iArray;
  10411. // _VEC3
  10412. case 0x8b55:
  10413. case 0x8b59:
  10414. return setValueV4iArray;
  10415. // _VEC4
  10416. case 0x8b5e: // SAMPLER_2D
  10417. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10418. case 0x8dca: // INT_SAMPLER_2D
  10419. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10420. case 0x8b62:
  10421. // SAMPLER_2D_SHADOW
  10422. return setValueT1Array;
  10423. case 0x8b60: // SAMPLER_CUBE
  10424. case 0x8dcc: // INT_SAMPLER_CUBE
  10425. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10426. case 0x8dc5:
  10427. // SAMPLER_CUBE_SHADOW
  10428. return setValueT6Array;
  10429. }
  10430. } // --- Uniform Classes ---
  10431. function SingleUniform(id, activeInfo, addr) {
  10432. this.id = id;
  10433. this.addr = addr;
  10434. this.cache = [];
  10435. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10436. }
  10437. function PureArrayUniform(id, activeInfo, addr) {
  10438. this.id = id;
  10439. this.addr = addr;
  10440. this.cache = [];
  10441. this.size = activeInfo.size;
  10442. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  10443. }
  10444. PureArrayUniform.prototype.updateCache = function (data) {
  10445. var cache = this.cache;
  10446. if (data instanceof Float32Array && cache.length !== data.length) {
  10447. this.cache = new Float32Array(data.length);
  10448. }
  10449. copyArray(cache, data);
  10450. };
  10451. function StructuredUniform(id) {
  10452. this.id = id;
  10453. this.seq = [];
  10454. this.map = {};
  10455. }
  10456. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  10457. var seq = this.seq;
  10458. for (var i = 0, n = seq.length; i !== n; ++i) {
  10459. var u = seq[i];
  10460. u.setValue(gl, value[u.id], textures);
  10461. }
  10462. }; // --- Top-level ---
  10463. // Parser - builds up the property tree from the path strings
  10464. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; // extracts
  10465. // - the identifier (member name or array index)
  10466. // - followed by an optional right bracket (found when array index)
  10467. // - followed by an optional left bracket or dot (type of subscript)
  10468. //
  10469. // Note: These portions can be read in a non-overlapping fashion and
  10470. // allow straightforward parsing of the hierarchy that WebGL encodes
  10471. // in the uniform names.
  10472. function addUniform(container, uniformObject) {
  10473. container.seq.push(uniformObject);
  10474. container.map[uniformObject.id] = uniformObject;
  10475. }
  10476. function parseUniform(activeInfo, addr, container) {
  10477. var path = activeInfo.name,
  10478. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  10479. RePathPart.lastIndex = 0;
  10480. while (true) {
  10481. var match = RePathPart.exec(path),
  10482. matchEnd = RePathPart.lastIndex;
  10483. var id = match[1];
  10484. var idIsIndex = match[2] === ']',
  10485. subscript = match[3];
  10486. if (idIsIndex) id = id | 0; // convert to integer
  10487. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  10488. // bare name or "pure" bottom-level array "[0]" suffix
  10489. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  10490. break;
  10491. } else {
  10492. // step into inner node / create it in case it doesn't exist
  10493. var map = container.map;
  10494. var next = map[id];
  10495. if (next === undefined) {
  10496. next = new StructuredUniform(id);
  10497. addUniform(container, next);
  10498. }
  10499. container = next;
  10500. }
  10501. }
  10502. } // Root Container
  10503. function WebGLUniforms(gl, program) {
  10504. this.seq = [];
  10505. this.map = {};
  10506. var n = gl.getProgramParameter(program, 35718);
  10507. for (var i = 0; i < n; ++i) {
  10508. var info = gl.getActiveUniform(program, i),
  10509. addr = gl.getUniformLocation(program, info.name);
  10510. parseUniform(info, addr, this);
  10511. }
  10512. }
  10513. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  10514. var u = this.map[name];
  10515. if (u !== undefined) u.setValue(gl, value, textures);
  10516. };
  10517. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  10518. var v = object[name];
  10519. if (v !== undefined) this.setValue(gl, name, v);
  10520. }; // Static interface
  10521. WebGLUniforms.upload = function (gl, seq, values, textures) {
  10522. for (var i = 0, n = seq.length; i !== n; ++i) {
  10523. var u = seq[i],
  10524. v = values[u.id];
  10525. if (v.needsUpdate !== false) {
  10526. // note: always updating when .needsUpdate is undefined
  10527. u.setValue(gl, v.value, textures);
  10528. }
  10529. }
  10530. };
  10531. WebGLUniforms.seqWithValue = function (seq, values) {
  10532. var r = [];
  10533. for (var i = 0, n = seq.length; i !== n; ++i) {
  10534. var u = seq[i];
  10535. if (u.id in values) r.push(u);
  10536. }
  10537. return r;
  10538. };
  10539. function WebGLShader(gl, type, string) {
  10540. var shader = gl.createShader(type);
  10541. gl.shaderSource(shader, string);
  10542. gl.compileShader(shader);
  10543. return shader;
  10544. }
  10545. var programIdCount = 0;
  10546. function addLineNumbers(string) {
  10547. var lines = string.split('\n');
  10548. for (var i = 0; i < lines.length; i++) {
  10549. lines[i] = i + 1 + ': ' + lines[i];
  10550. }
  10551. return lines.join('\n');
  10552. }
  10553. function getEncodingComponents(encoding) {
  10554. switch (encoding) {
  10555. case LinearEncoding:
  10556. return ['Linear', '( value )'];
  10557. case sRGBEncoding:
  10558. return ['sRGB', '( value )'];
  10559. case RGBEEncoding:
  10560. return ['RGBE', '( value )'];
  10561. case RGBM7Encoding:
  10562. return ['RGBM', '( value, 7.0 )'];
  10563. case RGBM16Encoding:
  10564. return ['RGBM', '( value, 16.0 )'];
  10565. case RGBDEncoding:
  10566. return ['RGBD', '( value, 256.0 )'];
  10567. case GammaEncoding:
  10568. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  10569. case LogLuvEncoding:
  10570. return ['LogLuv', '( value )'];
  10571. default:
  10572. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  10573. return ['Linear', '( value )'];
  10574. }
  10575. }
  10576. function getShaderErrors(gl, shader, type) {
  10577. var status = gl.getShaderParameter(shader, 35713);
  10578. var log = gl.getShaderInfoLog(shader).trim();
  10579. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  10580. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10581. var source = gl.getShaderSource(shader);
  10582. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  10583. }
  10584. function getTexelDecodingFunction(functionName, encoding) {
  10585. var components = getEncodingComponents(encoding);
  10586. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  10587. }
  10588. function getTexelEncodingFunction(functionName, encoding) {
  10589. var components = getEncodingComponents(encoding);
  10590. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  10591. }
  10592. function getToneMappingFunction(functionName, toneMapping) {
  10593. var toneMappingName;
  10594. switch (toneMapping) {
  10595. case LinearToneMapping:
  10596. toneMappingName = 'Linear';
  10597. break;
  10598. case ReinhardToneMapping:
  10599. toneMappingName = 'Reinhard';
  10600. break;
  10601. case CineonToneMapping:
  10602. toneMappingName = 'OptimizedCineon';
  10603. break;
  10604. case ACESFilmicToneMapping:
  10605. toneMappingName = 'ACESFilmic';
  10606. break;
  10607. case CustomToneMapping:
  10608. toneMappingName = 'Custom';
  10609. break;
  10610. default:
  10611. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  10612. toneMappingName = 'Linear';
  10613. }
  10614. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10615. }
  10616. function generateExtensions(parameters) {
  10617. 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' : ''];
  10618. return chunks.filter(filterEmptyLine).join('\n');
  10619. }
  10620. function generateDefines(defines) {
  10621. var chunks = [];
  10622. for (var name in defines) {
  10623. var value = defines[name];
  10624. if (value === false) continue;
  10625. chunks.push('#define ' + name + ' ' + value);
  10626. }
  10627. return chunks.join('\n');
  10628. }
  10629. function fetchAttributeLocations(gl, program) {
  10630. var attributes = {};
  10631. var n = gl.getProgramParameter(program, 35721);
  10632. for (var i = 0; i < n; i++) {
  10633. var info = gl.getActiveAttrib(program, i);
  10634. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10635. attributes[name] = gl.getAttribLocation(program, name);
  10636. }
  10637. return attributes;
  10638. }
  10639. function filterEmptyLine(string) {
  10640. return string !== '';
  10641. }
  10642. function replaceLightNums(string, parameters) {
  10643. 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);
  10644. }
  10645. function replaceClippingPlaneNums(string, parameters) {
  10646. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  10647. } // Resolve Includes
  10648. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10649. function resolveIncludes(string) {
  10650. return string.replace(includePattern, includeReplacer);
  10651. }
  10652. function includeReplacer(match, include) {
  10653. var string = ShaderChunk[include];
  10654. if (string === undefined) {
  10655. throw new Error('Can not resolve #include <' + include + '>');
  10656. }
  10657. return resolveIncludes(string);
  10658. } // Unroll Loops
  10659. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10660. 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;
  10661. function unrollLoops(string) {
  10662. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  10663. }
  10664. function deprecatedLoopReplacer(match, start, end, snippet) {
  10665. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  10666. return loopReplacer(match, start, end, snippet);
  10667. }
  10668. function loopReplacer(match, start, end, snippet) {
  10669. var string = '';
  10670. for (var i = parseInt(start); i < parseInt(end); i++) {
  10671. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  10672. }
  10673. return string;
  10674. } //
  10675. function generatePrecision(parameters) {
  10676. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10677. if (parameters.precision === "highp") {
  10678. precisionstring += "\n#define HIGH_PRECISION";
  10679. } else if (parameters.precision === "mediump") {
  10680. precisionstring += "\n#define MEDIUM_PRECISION";
  10681. } else if (parameters.precision === "lowp") {
  10682. precisionstring += "\n#define LOW_PRECISION";
  10683. }
  10684. return precisionstring;
  10685. }
  10686. function generateShadowMapTypeDefine(parameters) {
  10687. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10688. if (parameters.shadowMapType === PCFShadowMap) {
  10689. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10690. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  10691. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10692. } else if (parameters.shadowMapType === VSMShadowMap) {
  10693. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10694. }
  10695. return shadowMapTypeDefine;
  10696. }
  10697. function generateEnvMapTypeDefine(parameters) {
  10698. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10699. if (parameters.envMap) {
  10700. switch (parameters.envMapMode) {
  10701. case CubeReflectionMapping:
  10702. case CubeRefractionMapping:
  10703. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10704. break;
  10705. case CubeUVReflectionMapping:
  10706. case CubeUVRefractionMapping:
  10707. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10708. break;
  10709. }
  10710. }
  10711. return envMapTypeDefine;
  10712. }
  10713. function generateEnvMapModeDefine(parameters) {
  10714. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10715. if (parameters.envMap) {
  10716. switch (parameters.envMapMode) {
  10717. case CubeRefractionMapping:
  10718. case CubeUVRefractionMapping:
  10719. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10720. break;
  10721. }
  10722. }
  10723. return envMapModeDefine;
  10724. }
  10725. function generateEnvMapBlendingDefine(parameters) {
  10726. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10727. if (parameters.envMap) {
  10728. switch (parameters.combine) {
  10729. case MultiplyOperation:
  10730. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10731. break;
  10732. case MixOperation:
  10733. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10734. break;
  10735. case AddOperation:
  10736. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10737. break;
  10738. }
  10739. }
  10740. return envMapBlendingDefine;
  10741. }
  10742. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  10743. var gl = renderer.getContext();
  10744. var defines = parameters.defines;
  10745. var vertexShader = parameters.vertexShader;
  10746. var fragmentShader = parameters.fragmentShader;
  10747. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  10748. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  10749. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  10750. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  10751. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  10752. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  10753. var customDefines = generateDefines(defines);
  10754. var program = gl.createProgram();
  10755. var prefixVertex, prefixFragment;
  10756. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + "\n" : '';
  10757. if (parameters.isRawShaderMaterial) {
  10758. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  10759. if (prefixVertex.length > 0) {
  10760. prefixVertex += '\n';
  10761. }
  10762. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  10763. if (prefixFragment.length > 0) {
  10764. prefixFragment += '\n';
  10765. }
  10766. } else {
  10767. 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');
  10768. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  10769. '#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
  10770. 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
  10771. 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');
  10772. }
  10773. vertexShader = resolveIncludes(vertexShader);
  10774. vertexShader = replaceLightNums(vertexShader, parameters);
  10775. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  10776. fragmentShader = resolveIncludes(fragmentShader);
  10777. fragmentShader = replaceLightNums(fragmentShader, parameters);
  10778. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  10779. vertexShader = unrollLoops(vertexShader);
  10780. fragmentShader = unrollLoops(fragmentShader);
  10781. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  10782. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10783. versionString = '#version 300 es\n';
  10784. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  10785. 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;
  10786. }
  10787. var vertexGlsl = versionString + prefixVertex + vertexShader;
  10788. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  10789. // console.log( '*FRAGMENT*', fragmentGlsl );
  10790. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  10791. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  10792. gl.attachShader(program, glVertexShader);
  10793. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  10794. if (parameters.index0AttributeName !== undefined) {
  10795. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  10796. } else if (parameters.morphTargets === true) {
  10797. // programs with morphTargets displace position out of attribute 0
  10798. gl.bindAttribLocation(program, 0, 'position');
  10799. }
  10800. gl.linkProgram(program); // check for link errors
  10801. if (renderer.debug.checkShaderErrors) {
  10802. var programLog = gl.getProgramInfoLog(program).trim();
  10803. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  10804. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  10805. var runnable = true;
  10806. var haveDiagnostics = true;
  10807. if (gl.getProgramParameter(program, 35714) === false) {
  10808. runnable = false;
  10809. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  10810. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  10811. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  10812. } else if (programLog !== '') {
  10813. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  10814. } else if (vertexLog === '' || fragmentLog === '') {
  10815. haveDiagnostics = false;
  10816. }
  10817. if (haveDiagnostics) {
  10818. this.diagnostics = {
  10819. runnable: runnable,
  10820. programLog: programLog,
  10821. vertexShader: {
  10822. log: vertexLog,
  10823. prefix: prefixVertex
  10824. },
  10825. fragmentShader: {
  10826. log: fragmentLog,
  10827. prefix: prefixFragment
  10828. }
  10829. };
  10830. }
  10831. } // Clean up
  10832. // Crashes in iOS9 and iOS10. #18402
  10833. // gl.detachShader( program, glVertexShader );
  10834. // gl.detachShader( program, glFragmentShader );
  10835. gl.deleteShader(glVertexShader);
  10836. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  10837. var cachedUniforms;
  10838. this.getUniforms = function () {
  10839. if (cachedUniforms === undefined) {
  10840. cachedUniforms = new WebGLUniforms(gl, program);
  10841. }
  10842. return cachedUniforms;
  10843. }; // set up caching for attribute locations
  10844. var cachedAttributes;
  10845. this.getAttributes = function () {
  10846. if (cachedAttributes === undefined) {
  10847. cachedAttributes = fetchAttributeLocations(gl, program);
  10848. }
  10849. return cachedAttributes;
  10850. }; // free resource
  10851. this.destroy = function () {
  10852. bindingStates.releaseStatesOfProgram(this);
  10853. gl.deleteProgram(program);
  10854. this.program = undefined;
  10855. }; //
  10856. this.name = parameters.shaderName;
  10857. this.id = programIdCount++;
  10858. this.cacheKey = cacheKey;
  10859. this.usedTimes = 1;
  10860. this.program = program;
  10861. this.vertexShader = glVertexShader;
  10862. this.fragmentShader = glFragmentShader;
  10863. return this;
  10864. }
  10865. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  10866. var programs = [];
  10867. var isWebGL2 = capabilities.isWebGL2;
  10868. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10869. var floatVertexTextures = capabilities.floatVertexTextures;
  10870. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10871. var vertexTextures = capabilities.vertexTextures;
  10872. var precision = capabilities.precision;
  10873. var shaderIDs = {
  10874. MeshDepthMaterial: 'depth',
  10875. MeshDistanceMaterial: 'distanceRGBA',
  10876. MeshNormalMaterial: 'normal',
  10877. MeshBasicMaterial: 'basic',
  10878. MeshLambertMaterial: 'lambert',
  10879. MeshPhongMaterial: 'phong',
  10880. MeshToonMaterial: 'toon',
  10881. MeshStandardMaterial: 'physical',
  10882. MeshPhysicalMaterial: 'physical',
  10883. MeshMatcapMaterial: 'matcap',
  10884. LineBasicMaterial: 'basic',
  10885. LineDashedMaterial: 'dashed',
  10886. PointsMaterial: 'points',
  10887. ShadowMaterial: 'shadow',
  10888. SpriteMaterial: 'sprite'
  10889. };
  10890. 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"];
  10891. function getMaxBones(object) {
  10892. var skeleton = object.skeleton;
  10893. var bones = skeleton.bones;
  10894. if (floatVertexTextures) {
  10895. return 1024;
  10896. } else {
  10897. // default for when object is not specified
  10898. // ( for example when prebuilding shader to be used with multiple objects )
  10899. //
  10900. // - leave some extra space for other uniforms
  10901. // - limit here is ANGLE's 254 max uniform vectors
  10902. // (up to 54 should be safe)
  10903. var nVertexUniforms = maxVertexUniforms;
  10904. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  10905. var maxBones = Math.min(nVertexMatrices, bones.length);
  10906. if (maxBones < bones.length) {
  10907. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  10908. return 0;
  10909. }
  10910. return maxBones;
  10911. }
  10912. }
  10913. function getTextureEncodingFromMap(map) {
  10914. var encoding;
  10915. if (!map) {
  10916. encoding = LinearEncoding;
  10917. } else if (map.isTexture) {
  10918. encoding = map.encoding;
  10919. } else if (map.isWebGLRenderTarget) {
  10920. console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
  10921. encoding = map.texture.encoding;
  10922. }
  10923. return encoding;
  10924. }
  10925. function getParameters(material, lights, shadows, scene, object) {
  10926. var fog = scene.fog;
  10927. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  10928. var envMap = cubemaps.get(material.envMap || environment);
  10929. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  10930. // (not to blow over maxLights budget)
  10931. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  10932. if (material.precision !== null) {
  10933. precision = capabilities.getMaxPrecision(material.precision);
  10934. if (precision !== material.precision) {
  10935. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  10936. }
  10937. }
  10938. var vertexShader, fragmentShader;
  10939. if (shaderID) {
  10940. var shader = ShaderLib[shaderID];
  10941. vertexShader = shader.vertexShader;
  10942. fragmentShader = shader.fragmentShader;
  10943. } else {
  10944. vertexShader = material.vertexShader;
  10945. fragmentShader = material.fragmentShader;
  10946. }
  10947. var currentRenderTarget = renderer.getRenderTarget();
  10948. var parameters = {
  10949. isWebGL2: isWebGL2,
  10950. shaderID: shaderID,
  10951. shaderName: material.type,
  10952. vertexShader: vertexShader,
  10953. fragmentShader: fragmentShader,
  10954. defines: material.defines,
  10955. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10956. glslVersion: material.glslVersion,
  10957. precision: precision,
  10958. instancing: object.isInstancedMesh === true,
  10959. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10960. supportsVertexTextures: vertexTextures,
  10961. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  10962. map: !!material.map,
  10963. mapEncoding: getTextureEncodingFromMap(material.map),
  10964. matcap: !!material.matcap,
  10965. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  10966. envMap: !!envMap,
  10967. envMapMode: envMap && envMap.mapping,
  10968. envMapEncoding: getTextureEncodingFromMap(envMap),
  10969. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  10970. lightMap: !!material.lightMap,
  10971. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  10972. aoMap: !!material.aoMap,
  10973. emissiveMap: !!material.emissiveMap,
  10974. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  10975. bumpMap: !!material.bumpMap,
  10976. normalMap: !!material.normalMap,
  10977. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10978. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10979. clearcoatMap: !!material.clearcoatMap,
  10980. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  10981. clearcoatNormalMap: !!material.clearcoatNormalMap,
  10982. displacementMap: !!material.displacementMap,
  10983. roughnessMap: !!material.roughnessMap,
  10984. metalnessMap: !!material.metalnessMap,
  10985. specularMap: !!material.specularMap,
  10986. alphaMap: !!material.alphaMap,
  10987. gradientMap: !!material.gradientMap,
  10988. sheen: !!material.sheen,
  10989. transmissionMap: !!material.transmissionMap,
  10990. combine: material.combine,
  10991. vertexTangents: material.normalMap && material.vertexTangents,
  10992. vertexColors: material.vertexColors,
  10993. 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,
  10994. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  10995. fog: !!fog,
  10996. useFog: material.fog,
  10997. fogExp2: fog && fog.isFogExp2,
  10998. flatShading: material.flatShading,
  10999. sizeAttenuation: material.sizeAttenuation,
  11000. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11001. skinning: material.skinning && maxBones > 0,
  11002. maxBones: maxBones,
  11003. useVertexTexture: floatVertexTextures,
  11004. morphTargets: material.morphTargets,
  11005. morphNormals: material.morphNormals,
  11006. maxMorphTargets: renderer.maxMorphTargets,
  11007. maxMorphNormals: renderer.maxMorphNormals,
  11008. numDirLights: lights.directional.length,
  11009. numPointLights: lights.point.length,
  11010. numSpotLights: lights.spot.length,
  11011. numRectAreaLights: lights.rectArea.length,
  11012. numHemiLights: lights.hemi.length,
  11013. numDirLightShadows: lights.directionalShadowMap.length,
  11014. numPointLightShadows: lights.pointShadowMap.length,
  11015. numSpotLightShadows: lights.spotShadowMap.length,
  11016. numClippingPlanes: clipping.numPlanes,
  11017. numClipIntersection: clipping.numIntersection,
  11018. dithering: material.dithering,
  11019. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11020. shadowMapType: renderer.shadowMap.type,
  11021. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11022. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11023. premultipliedAlpha: material.premultipliedAlpha,
  11024. alphaTest: material.alphaTest,
  11025. doubleSided: material.side === DoubleSide,
  11026. flipSided: material.side === BackSide,
  11027. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11028. index0AttributeName: material.index0AttributeName,
  11029. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11030. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11031. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11032. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11033. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11034. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11035. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11036. customProgramCacheKey: material.customProgramCacheKey()
  11037. };
  11038. return parameters;
  11039. }
  11040. function getProgramCacheKey(parameters) {
  11041. var array = [];
  11042. if (parameters.shaderID) {
  11043. array.push(parameters.shaderID);
  11044. } else {
  11045. array.push(parameters.fragmentShader);
  11046. array.push(parameters.vertexShader);
  11047. }
  11048. if (parameters.defines !== undefined) {
  11049. for (var name in parameters.defines) {
  11050. array.push(name);
  11051. array.push(parameters.defines[name]);
  11052. }
  11053. }
  11054. if (parameters.isRawShaderMaterial === false) {
  11055. for (var i = 0; i < parameterNames.length; i++) {
  11056. array.push(parameters[parameterNames[i]]);
  11057. }
  11058. array.push(renderer.outputEncoding);
  11059. array.push(renderer.gammaFactor);
  11060. }
  11061. array.push(parameters.customProgramCacheKey);
  11062. return array.join();
  11063. }
  11064. function getUniforms(material) {
  11065. var shaderID = shaderIDs[material.type];
  11066. var uniforms;
  11067. if (shaderID) {
  11068. var shader = ShaderLib[shaderID];
  11069. uniforms = UniformsUtils.clone(shader.uniforms);
  11070. } else {
  11071. uniforms = material.uniforms;
  11072. }
  11073. return uniforms;
  11074. }
  11075. function acquireProgram(parameters, cacheKey) {
  11076. var program; // Check if code has been already compiled
  11077. for (var p = 0, pl = programs.length; p < pl; p++) {
  11078. var preexistingProgram = programs[p];
  11079. if (preexistingProgram.cacheKey === cacheKey) {
  11080. program = preexistingProgram;
  11081. ++program.usedTimes;
  11082. break;
  11083. }
  11084. }
  11085. if (program === undefined) {
  11086. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11087. programs.push(program);
  11088. }
  11089. return program;
  11090. }
  11091. function releaseProgram(program) {
  11092. if (--program.usedTimes === 0) {
  11093. // Remove from unordered set
  11094. var i = programs.indexOf(program);
  11095. programs[i] = programs[programs.length - 1];
  11096. programs.pop(); // Free WebGL resources
  11097. program.destroy();
  11098. }
  11099. }
  11100. return {
  11101. getParameters: getParameters,
  11102. getProgramCacheKey: getProgramCacheKey,
  11103. getUniforms: getUniforms,
  11104. acquireProgram: acquireProgram,
  11105. releaseProgram: releaseProgram,
  11106. // Exposed for resource monitoring & error feedback via renderer.info:
  11107. programs: programs
  11108. };
  11109. }
  11110. function WebGLProperties() {
  11111. var properties = new WeakMap();
  11112. function get(object) {
  11113. var map = properties.get(object);
  11114. if (map === undefined) {
  11115. map = {};
  11116. properties.set(object, map);
  11117. }
  11118. return map;
  11119. }
  11120. function remove(object) {
  11121. properties.delete(object);
  11122. }
  11123. function update(object, key, value) {
  11124. properties.get(object)[key] = value;
  11125. }
  11126. function dispose() {
  11127. properties = new WeakMap();
  11128. }
  11129. return {
  11130. get: get,
  11131. remove: remove,
  11132. update: update,
  11133. dispose: dispose
  11134. };
  11135. }
  11136. function painterSortStable(a, b) {
  11137. if (a.groupOrder !== b.groupOrder) {
  11138. return a.groupOrder - b.groupOrder;
  11139. } else if (a.renderOrder !== b.renderOrder) {
  11140. return a.renderOrder - b.renderOrder;
  11141. } else if (a.program !== b.program) {
  11142. return a.program.id - b.program.id;
  11143. } else if (a.material.id !== b.material.id) {
  11144. return a.material.id - b.material.id;
  11145. } else if (a.z !== b.z) {
  11146. return a.z - b.z;
  11147. } else {
  11148. return a.id - b.id;
  11149. }
  11150. }
  11151. function reversePainterSortStable(a, b) {
  11152. if (a.groupOrder !== b.groupOrder) {
  11153. return a.groupOrder - b.groupOrder;
  11154. } else if (a.renderOrder !== b.renderOrder) {
  11155. return a.renderOrder - b.renderOrder;
  11156. } else if (a.z !== b.z) {
  11157. return b.z - a.z;
  11158. } else {
  11159. return a.id - b.id;
  11160. }
  11161. }
  11162. function WebGLRenderList(properties) {
  11163. var renderItems = [];
  11164. var renderItemsIndex = 0;
  11165. var opaque = [];
  11166. var transparent = [];
  11167. var defaultProgram = {
  11168. id: -1
  11169. };
  11170. function init() {
  11171. renderItemsIndex = 0;
  11172. opaque.length = 0;
  11173. transparent.length = 0;
  11174. }
  11175. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11176. var renderItem = renderItems[renderItemsIndex];
  11177. var materialProperties = properties.get(material);
  11178. if (renderItem === undefined) {
  11179. renderItem = {
  11180. id: object.id,
  11181. object: object,
  11182. geometry: geometry,
  11183. material: material,
  11184. program: materialProperties.program || defaultProgram,
  11185. groupOrder: groupOrder,
  11186. renderOrder: object.renderOrder,
  11187. z: z,
  11188. group: group
  11189. };
  11190. renderItems[renderItemsIndex] = renderItem;
  11191. } else {
  11192. renderItem.id = object.id;
  11193. renderItem.object = object;
  11194. renderItem.geometry = geometry;
  11195. renderItem.material = material;
  11196. renderItem.program = materialProperties.program || defaultProgram;
  11197. renderItem.groupOrder = groupOrder;
  11198. renderItem.renderOrder = object.renderOrder;
  11199. renderItem.z = z;
  11200. renderItem.group = group;
  11201. }
  11202. renderItemsIndex++;
  11203. return renderItem;
  11204. }
  11205. function push(object, geometry, material, groupOrder, z, group) {
  11206. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11207. (material.transparent === true ? transparent : opaque).push(renderItem);
  11208. }
  11209. function unshift(object, geometry, material, groupOrder, z, group) {
  11210. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11211. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11212. }
  11213. function sort(customOpaqueSort, customTransparentSort) {
  11214. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11215. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11216. }
  11217. function finish() {
  11218. // Clear references from inactive renderItems in the list
  11219. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11220. var renderItem = renderItems[i];
  11221. if (renderItem.id === null) break;
  11222. renderItem.id = null;
  11223. renderItem.object = null;
  11224. renderItem.geometry = null;
  11225. renderItem.material = null;
  11226. renderItem.program = null;
  11227. renderItem.group = null;
  11228. }
  11229. }
  11230. return {
  11231. opaque: opaque,
  11232. transparent: transparent,
  11233. init: init,
  11234. push: push,
  11235. unshift: unshift,
  11236. finish: finish,
  11237. sort: sort
  11238. };
  11239. }
  11240. function WebGLRenderLists(properties) {
  11241. var lists = new WeakMap();
  11242. function get(scene, camera) {
  11243. var cameras = lists.get(scene);
  11244. var list;
  11245. if (cameras === undefined) {
  11246. list = new WebGLRenderList(properties);
  11247. lists.set(scene, new WeakMap());
  11248. lists.get(scene).set(camera, list);
  11249. } else {
  11250. list = cameras.get(camera);
  11251. if (list === undefined) {
  11252. list = new WebGLRenderList(properties);
  11253. cameras.set(camera, list);
  11254. }
  11255. }
  11256. return list;
  11257. }
  11258. function dispose() {
  11259. lists = new WeakMap();
  11260. }
  11261. return {
  11262. get: get,
  11263. dispose: dispose
  11264. };
  11265. }
  11266. function UniformsCache() {
  11267. var lights = {};
  11268. return {
  11269. get: function get(light) {
  11270. if (lights[light.id] !== undefined) {
  11271. return lights[light.id];
  11272. }
  11273. var uniforms;
  11274. switch (light.type) {
  11275. case 'DirectionalLight':
  11276. uniforms = {
  11277. direction: new Vector3(),
  11278. color: new Color()
  11279. };
  11280. break;
  11281. case 'SpotLight':
  11282. uniforms = {
  11283. position: new Vector3(),
  11284. direction: new Vector3(),
  11285. color: new Color(),
  11286. distance: 0,
  11287. coneCos: 0,
  11288. penumbraCos: 0,
  11289. decay: 0
  11290. };
  11291. break;
  11292. case 'PointLight':
  11293. uniforms = {
  11294. position: new Vector3(),
  11295. color: new Color(),
  11296. distance: 0,
  11297. decay: 0
  11298. };
  11299. break;
  11300. case 'HemisphereLight':
  11301. uniforms = {
  11302. direction: new Vector3(),
  11303. skyColor: new Color(),
  11304. groundColor: new Color()
  11305. };
  11306. break;
  11307. case 'RectAreaLight':
  11308. uniforms = {
  11309. color: new Color(),
  11310. position: new Vector3(),
  11311. halfWidth: new Vector3(),
  11312. halfHeight: new Vector3()
  11313. };
  11314. break;
  11315. }
  11316. lights[light.id] = uniforms;
  11317. return uniforms;
  11318. }
  11319. };
  11320. }
  11321. function ShadowUniformsCache() {
  11322. var lights = {};
  11323. return {
  11324. get: function get(light) {
  11325. if (lights[light.id] !== undefined) {
  11326. return lights[light.id];
  11327. }
  11328. var uniforms;
  11329. switch (light.type) {
  11330. case 'DirectionalLight':
  11331. uniforms = {
  11332. shadowBias: 0,
  11333. shadowNormalBias: 0,
  11334. shadowRadius: 1,
  11335. shadowMapSize: new Vector2()
  11336. };
  11337. break;
  11338. case 'SpotLight':
  11339. uniforms = {
  11340. shadowBias: 0,
  11341. shadowNormalBias: 0,
  11342. shadowRadius: 1,
  11343. shadowMapSize: new Vector2()
  11344. };
  11345. break;
  11346. case 'PointLight':
  11347. uniforms = {
  11348. shadowBias: 0,
  11349. shadowNormalBias: 0,
  11350. shadowRadius: 1,
  11351. shadowMapSize: new Vector2(),
  11352. shadowCameraNear: 1,
  11353. shadowCameraFar: 1000
  11354. };
  11355. break;
  11356. // TODO (abelnation): set RectAreaLight shadow uniforms
  11357. }
  11358. lights[light.id] = uniforms;
  11359. return uniforms;
  11360. }
  11361. };
  11362. }
  11363. var nextVersion = 0;
  11364. function shadowCastingLightsFirst(lightA, lightB) {
  11365. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  11366. }
  11367. function WebGLLights(extensions, capabilities) {
  11368. var cache = new UniformsCache();
  11369. var shadowCache = ShadowUniformsCache();
  11370. var state = {
  11371. version: 0,
  11372. hash: {
  11373. directionalLength: -1,
  11374. pointLength: -1,
  11375. spotLength: -1,
  11376. rectAreaLength: -1,
  11377. hemiLength: -1,
  11378. numDirectionalShadows: -1,
  11379. numPointShadows: -1,
  11380. numSpotShadows: -1
  11381. },
  11382. ambient: [0, 0, 0],
  11383. probe: [],
  11384. directional: [],
  11385. directionalShadow: [],
  11386. directionalShadowMap: [],
  11387. directionalShadowMatrix: [],
  11388. spot: [],
  11389. spotShadow: [],
  11390. spotShadowMap: [],
  11391. spotShadowMatrix: [],
  11392. rectArea: [],
  11393. rectAreaLTC1: null,
  11394. rectAreaLTC2: null,
  11395. point: [],
  11396. pointShadow: [],
  11397. pointShadowMap: [],
  11398. pointShadowMatrix: [],
  11399. hemi: []
  11400. };
  11401. for (var i = 0; i < 9; i++) {
  11402. state.probe.push(new Vector3());
  11403. }
  11404. var vector3 = new Vector3();
  11405. var matrix4 = new Matrix4();
  11406. var matrix42 = new Matrix4();
  11407. function setup(lights, shadows, camera) {
  11408. var r = 0,
  11409. g = 0,
  11410. b = 0;
  11411. for (var _i = 0; _i < 9; _i++) {
  11412. state.probe[_i].set(0, 0, 0);
  11413. }
  11414. var directionalLength = 0;
  11415. var pointLength = 0;
  11416. var spotLength = 0;
  11417. var rectAreaLength = 0;
  11418. var hemiLength = 0;
  11419. var numDirectionalShadows = 0;
  11420. var numPointShadows = 0;
  11421. var numSpotShadows = 0;
  11422. var viewMatrix = camera.matrixWorldInverse;
  11423. lights.sort(shadowCastingLightsFirst);
  11424. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  11425. var light = lights[_i2];
  11426. var color = light.color;
  11427. var intensity = light.intensity;
  11428. var distance = light.distance;
  11429. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  11430. if (light.isAmbientLight) {
  11431. r += color.r * intensity;
  11432. g += color.g * intensity;
  11433. b += color.b * intensity;
  11434. } else if (light.isLightProbe) {
  11435. for (var j = 0; j < 9; j++) {
  11436. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  11437. }
  11438. } else if (light.isDirectionalLight) {
  11439. var uniforms = cache.get(light);
  11440. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  11441. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11442. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11443. uniforms.direction.sub(vector3);
  11444. uniforms.direction.transformDirection(viewMatrix);
  11445. if (light.castShadow) {
  11446. var shadow = light.shadow;
  11447. var shadowUniforms = shadowCache.get(light);
  11448. shadowUniforms.shadowBias = shadow.bias;
  11449. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11450. shadowUniforms.shadowRadius = shadow.radius;
  11451. shadowUniforms.shadowMapSize = shadow.mapSize;
  11452. state.directionalShadow[directionalLength] = shadowUniforms;
  11453. state.directionalShadowMap[directionalLength] = shadowMap;
  11454. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  11455. numDirectionalShadows++;
  11456. }
  11457. state.directional[directionalLength] = uniforms;
  11458. directionalLength++;
  11459. } else if (light.isSpotLight) {
  11460. var _uniforms = cache.get(light);
  11461. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  11462. _uniforms.position.applyMatrix4(viewMatrix);
  11463. _uniforms.color.copy(color).multiplyScalar(intensity);
  11464. _uniforms.distance = distance;
  11465. _uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  11466. vector3.setFromMatrixPosition(light.target.matrixWorld);
  11467. _uniforms.direction.sub(vector3);
  11468. _uniforms.direction.transformDirection(viewMatrix);
  11469. _uniforms.coneCos = Math.cos(light.angle);
  11470. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  11471. _uniforms.decay = light.decay;
  11472. if (light.castShadow) {
  11473. var _shadow = light.shadow;
  11474. var _shadowUniforms = shadowCache.get(light);
  11475. _shadowUniforms.shadowBias = _shadow.bias;
  11476. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  11477. _shadowUniforms.shadowRadius = _shadow.radius;
  11478. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  11479. state.spotShadow[spotLength] = _shadowUniforms;
  11480. state.spotShadowMap[spotLength] = shadowMap;
  11481. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  11482. numSpotShadows++;
  11483. }
  11484. state.spot[spotLength] = _uniforms;
  11485. spotLength++;
  11486. } else if (light.isRectAreaLight) {
  11487. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  11488. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11489. // (b) intensity is the brightness of the light
  11490. _uniforms2.color.copy(color).multiplyScalar(intensity);
  11491. _uniforms2.position.setFromMatrixPosition(light.matrixWorld);
  11492. _uniforms2.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  11493. matrix42.identity();
  11494. matrix4.copy(light.matrixWorld);
  11495. matrix4.premultiply(viewMatrix);
  11496. matrix42.extractRotation(matrix4);
  11497. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  11498. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  11499. _uniforms2.halfWidth.applyMatrix4(matrix42);
  11500. _uniforms2.halfHeight.applyMatrix4(matrix42); // TODO (abelnation): RectAreaLight distance?
  11501. // uniforms.distance = distance;
  11502. state.rectArea[rectAreaLength] = _uniforms2;
  11503. rectAreaLength++;
  11504. } else if (light.isPointLight) {
  11505. var _uniforms3 = cache.get(light);
  11506. _uniforms3.position.setFromMatrixPosition(light.matrixWorld);
  11507. _uniforms3.position.applyMatrix4(viewMatrix);
  11508. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  11509. _uniforms3.distance = light.distance;
  11510. _uniforms3.decay = light.decay;
  11511. if (light.castShadow) {
  11512. var _shadow2 = light.shadow;
  11513. var _shadowUniforms2 = shadowCache.get(light);
  11514. _shadowUniforms2.shadowBias = _shadow2.bias;
  11515. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  11516. _shadowUniforms2.shadowRadius = _shadow2.radius;
  11517. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  11518. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  11519. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  11520. state.pointShadow[pointLength] = _shadowUniforms2;
  11521. state.pointShadowMap[pointLength] = shadowMap;
  11522. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  11523. numPointShadows++;
  11524. }
  11525. state.point[pointLength] = _uniforms3;
  11526. pointLength++;
  11527. } else if (light.isHemisphereLight) {
  11528. var _uniforms4 = cache.get(light);
  11529. _uniforms4.direction.setFromMatrixPosition(light.matrixWorld);
  11530. _uniforms4.direction.transformDirection(viewMatrix);
  11531. _uniforms4.direction.normalize();
  11532. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  11533. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  11534. state.hemi[hemiLength] = _uniforms4;
  11535. hemiLength++;
  11536. }
  11537. }
  11538. if (rectAreaLength > 0) {
  11539. if (capabilities.isWebGL2) {
  11540. // WebGL 2
  11541. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11542. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11543. } else {
  11544. // WebGL 1
  11545. if (extensions.has('OES_texture_float_linear') === true) {
  11546. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11547. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11548. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  11549. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11550. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11551. } else {
  11552. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  11553. }
  11554. }
  11555. }
  11556. state.ambient[0] = r;
  11557. state.ambient[1] = g;
  11558. state.ambient[2] = b;
  11559. var hash = state.hash;
  11560. 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) {
  11561. state.directional.length = directionalLength;
  11562. state.spot.length = spotLength;
  11563. state.rectArea.length = rectAreaLength;
  11564. state.point.length = pointLength;
  11565. state.hemi.length = hemiLength;
  11566. state.directionalShadow.length = numDirectionalShadows;
  11567. state.directionalShadowMap.length = numDirectionalShadows;
  11568. state.pointShadow.length = numPointShadows;
  11569. state.pointShadowMap.length = numPointShadows;
  11570. state.spotShadow.length = numSpotShadows;
  11571. state.spotShadowMap.length = numSpotShadows;
  11572. state.directionalShadowMatrix.length = numDirectionalShadows;
  11573. state.pointShadowMatrix.length = numPointShadows;
  11574. state.spotShadowMatrix.length = numSpotShadows;
  11575. hash.directionalLength = directionalLength;
  11576. hash.pointLength = pointLength;
  11577. hash.spotLength = spotLength;
  11578. hash.rectAreaLength = rectAreaLength;
  11579. hash.hemiLength = hemiLength;
  11580. hash.numDirectionalShadows = numDirectionalShadows;
  11581. hash.numPointShadows = numPointShadows;
  11582. hash.numSpotShadows = numSpotShadows;
  11583. state.version = nextVersion++;
  11584. }
  11585. }
  11586. return {
  11587. setup: setup,
  11588. state: state
  11589. };
  11590. }
  11591. function WebGLRenderState(extensions, capabilities) {
  11592. var lights = new WebGLLights(extensions, capabilities);
  11593. var lightsArray = [];
  11594. var shadowsArray = [];
  11595. function init() {
  11596. lightsArray.length = 0;
  11597. shadowsArray.length = 0;
  11598. }
  11599. function pushLight(light) {
  11600. lightsArray.push(light);
  11601. }
  11602. function pushShadow(shadowLight) {
  11603. shadowsArray.push(shadowLight);
  11604. }
  11605. function setupLights(camera) {
  11606. lights.setup(lightsArray, shadowsArray, camera);
  11607. }
  11608. var state = {
  11609. lightsArray: lightsArray,
  11610. shadowsArray: shadowsArray,
  11611. lights: lights
  11612. };
  11613. return {
  11614. init: init,
  11615. state: state,
  11616. setupLights: setupLights,
  11617. pushLight: pushLight,
  11618. pushShadow: pushShadow
  11619. };
  11620. }
  11621. function WebGLRenderStates(extensions, capabilities) {
  11622. var renderStates = new WeakMap();
  11623. function get(scene, camera) {
  11624. var renderState;
  11625. if (renderStates.has(scene) === false) {
  11626. renderState = new WebGLRenderState(extensions, capabilities);
  11627. renderStates.set(scene, new WeakMap());
  11628. renderStates.get(scene).set(camera, renderState);
  11629. } else {
  11630. if (renderStates.get(scene).has(camera) === false) {
  11631. renderState = new WebGLRenderState(extensions, capabilities);
  11632. renderStates.get(scene).set(camera, renderState);
  11633. } else {
  11634. renderState = renderStates.get(scene).get(camera);
  11635. }
  11636. }
  11637. return renderState;
  11638. }
  11639. function dispose() {
  11640. renderStates = new WeakMap();
  11641. }
  11642. return {
  11643. get: get,
  11644. dispose: dispose
  11645. };
  11646. }
  11647. /**
  11648. * parameters = {
  11649. *
  11650. * opacity: <float>,
  11651. *
  11652. * map: new THREE.Texture( <Image> ),
  11653. *
  11654. * alphaMap: new THREE.Texture( <Image> ),
  11655. *
  11656. * displacementMap: new THREE.Texture( <Image> ),
  11657. * displacementScale: <float>,
  11658. * displacementBias: <float>,
  11659. *
  11660. * wireframe: <boolean>,
  11661. * wireframeLinewidth: <float>
  11662. * }
  11663. */
  11664. function MeshDepthMaterial(parameters) {
  11665. Material.call(this);
  11666. this.type = 'MeshDepthMaterial';
  11667. this.depthPacking = BasicDepthPacking;
  11668. this.skinning = false;
  11669. this.morphTargets = false;
  11670. this.map = null;
  11671. this.alphaMap = null;
  11672. this.displacementMap = null;
  11673. this.displacementScale = 1;
  11674. this.displacementBias = 0;
  11675. this.wireframe = false;
  11676. this.wireframeLinewidth = 1;
  11677. this.fog = false;
  11678. this.setValues(parameters);
  11679. }
  11680. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  11681. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11682. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11683. MeshDepthMaterial.prototype.copy = function (source) {
  11684. Material.prototype.copy.call(this, source);
  11685. this.depthPacking = source.depthPacking;
  11686. this.skinning = source.skinning;
  11687. this.morphTargets = source.morphTargets;
  11688. this.map = source.map;
  11689. this.alphaMap = source.alphaMap;
  11690. this.displacementMap = source.displacementMap;
  11691. this.displacementScale = source.displacementScale;
  11692. this.displacementBias = source.displacementBias;
  11693. this.wireframe = source.wireframe;
  11694. this.wireframeLinewidth = source.wireframeLinewidth;
  11695. return this;
  11696. };
  11697. /**
  11698. * parameters = {
  11699. *
  11700. * referencePosition: <float>,
  11701. * nearDistance: <float>,
  11702. * farDistance: <float>,
  11703. *
  11704. * skinning: <bool>,
  11705. * morphTargets: <bool>,
  11706. *
  11707. * map: new THREE.Texture( <Image> ),
  11708. *
  11709. * alphaMap: new THREE.Texture( <Image> ),
  11710. *
  11711. * displacementMap: new THREE.Texture( <Image> ),
  11712. * displacementScale: <float>,
  11713. * displacementBias: <float>
  11714. *
  11715. * }
  11716. */
  11717. function MeshDistanceMaterial(parameters) {
  11718. Material.call(this);
  11719. this.type = 'MeshDistanceMaterial';
  11720. this.referencePosition = new Vector3();
  11721. this.nearDistance = 1;
  11722. this.farDistance = 1000;
  11723. this.skinning = false;
  11724. this.morphTargets = false;
  11725. this.map = null;
  11726. this.alphaMap = null;
  11727. this.displacementMap = null;
  11728. this.displacementScale = 1;
  11729. this.displacementBias = 0;
  11730. this.fog = false;
  11731. this.setValues(parameters);
  11732. }
  11733. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  11734. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11735. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11736. MeshDistanceMaterial.prototype.copy = function (source) {
  11737. Material.prototype.copy.call(this, source);
  11738. this.referencePosition.copy(source.referencePosition);
  11739. this.nearDistance = source.nearDistance;
  11740. this.farDistance = source.farDistance;
  11741. this.skinning = source.skinning;
  11742. this.morphTargets = source.morphTargets;
  11743. this.map = source.map;
  11744. this.alphaMap = source.alphaMap;
  11745. this.displacementMap = source.displacementMap;
  11746. this.displacementScale = source.displacementScale;
  11747. this.displacementBias = source.displacementBias;
  11748. return this;
  11749. };
  11750. 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}";
  11751. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11752. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  11753. var _frustum = new Frustum();
  11754. var _shadowMapSize = new Vector2(),
  11755. _viewportSize = new Vector2(),
  11756. _viewport = new Vector4(),
  11757. _depthMaterials = [],
  11758. _distanceMaterials = [],
  11759. _materialCache = {};
  11760. var shadowSide = {
  11761. 0: BackSide,
  11762. 1: FrontSide,
  11763. 2: DoubleSide
  11764. };
  11765. var shadowMaterialVertical = new ShaderMaterial({
  11766. defines: {
  11767. SAMPLE_RATE: 2.0 / 8.0,
  11768. HALF_SAMPLE_RATE: 1.0 / 8.0
  11769. },
  11770. uniforms: {
  11771. shadow_pass: {
  11772. value: null
  11773. },
  11774. resolution: {
  11775. value: new Vector2()
  11776. },
  11777. radius: {
  11778. value: 4.0
  11779. }
  11780. },
  11781. vertexShader: vsm_vert,
  11782. fragmentShader: vsm_frag
  11783. });
  11784. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11785. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11786. var fullScreenTri = new BufferGeometry();
  11787. fullScreenTri.setAttribute("position", new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  11788. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  11789. var scope = this;
  11790. this.enabled = false;
  11791. this.autoUpdate = true;
  11792. this.needsUpdate = false;
  11793. this.type = PCFShadowMap;
  11794. this.render = function (lights, scene, camera) {
  11795. if (scope.enabled === false) return;
  11796. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  11797. if (lights.length === 0) return;
  11798. var currentRenderTarget = _renderer.getRenderTarget();
  11799. var activeCubeFace = _renderer.getActiveCubeFace();
  11800. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11801. var _state = _renderer.state; // Set GL state for depth map.
  11802. _state.setBlending(NoBlending);
  11803. _state.buffers.color.setClear(1, 1, 1, 1);
  11804. _state.buffers.depth.setTest(true);
  11805. _state.setScissorTest(false); // render depth map
  11806. for (var i = 0, il = lights.length; i < il; i++) {
  11807. var light = lights[i];
  11808. var shadow = light.shadow;
  11809. if (shadow === undefined) {
  11810. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  11811. continue;
  11812. }
  11813. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  11814. _shadowMapSize.copy(shadow.mapSize);
  11815. var shadowFrameExtents = shadow.getFrameExtents();
  11816. _shadowMapSize.multiply(shadowFrameExtents);
  11817. _viewportSize.copy(shadow.mapSize);
  11818. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  11819. if (_shadowMapSize.x > maxTextureSize) {
  11820. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  11821. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11822. shadow.mapSize.x = _viewportSize.x;
  11823. }
  11824. if (_shadowMapSize.y > maxTextureSize) {
  11825. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  11826. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11827. shadow.mapSize.y = _viewportSize.y;
  11828. }
  11829. }
  11830. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11831. var pars = {
  11832. minFilter: LinearFilter,
  11833. magFilter: LinearFilter,
  11834. format: RGBAFormat
  11835. };
  11836. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11837. shadow.map.texture.name = light.name + ".shadowMap";
  11838. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  11839. shadow.camera.updateProjectionMatrix();
  11840. }
  11841. if (shadow.map === null) {
  11842. var _pars = {
  11843. minFilter: NearestFilter,
  11844. magFilter: NearestFilter,
  11845. format: RGBAFormat
  11846. };
  11847. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  11848. shadow.map.texture.name = light.name + ".shadowMap";
  11849. shadow.camera.updateProjectionMatrix();
  11850. }
  11851. _renderer.setRenderTarget(shadow.map);
  11852. _renderer.clear();
  11853. var viewportCount = shadow.getViewportCount();
  11854. for (var vp = 0; vp < viewportCount; vp++) {
  11855. var viewport = shadow.getViewport(vp);
  11856. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  11857. _state.viewport(_viewport);
  11858. shadow.updateMatrices(light, vp);
  11859. _frustum = shadow.getFrustum();
  11860. renderObject(scene, camera, shadow.camera, light, this.type);
  11861. } // do blur pass for VSM
  11862. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  11863. VSMPass(shadow, camera);
  11864. }
  11865. shadow.needsUpdate = false;
  11866. }
  11867. scope.needsUpdate = false;
  11868. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  11869. };
  11870. function VSMPass(shadow, camera) {
  11871. var geometry = _objects.update(fullScreenMesh); // vertical pass
  11872. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11873. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11874. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11875. _renderer.setRenderTarget(shadow.mapPass);
  11876. _renderer.clear();
  11877. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizonal pass
  11878. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11879. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11880. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11881. _renderer.setRenderTarget(shadow.map);
  11882. _renderer.clear();
  11883. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null);
  11884. }
  11885. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11886. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11887. var material = _depthMaterials[index];
  11888. if (material === undefined) {
  11889. material = new MeshDepthMaterial({
  11890. depthPacking: RGBADepthPacking,
  11891. morphTargets: useMorphing,
  11892. skinning: useSkinning
  11893. });
  11894. _depthMaterials[index] = material;
  11895. }
  11896. return material;
  11897. }
  11898. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  11899. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11900. var material = _distanceMaterials[index];
  11901. if (material === undefined) {
  11902. material = new MeshDistanceMaterial({
  11903. morphTargets: useMorphing,
  11904. skinning: useSkinning
  11905. });
  11906. _distanceMaterials[index] = material;
  11907. }
  11908. return material;
  11909. }
  11910. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  11911. var result = null;
  11912. var getMaterialVariant = getDepthMaterialVariant;
  11913. var customMaterial = object.customDepthMaterial;
  11914. if (light.isPointLight === true) {
  11915. getMaterialVariant = getDistanceMaterialVariant;
  11916. customMaterial = object.customDistanceMaterial;
  11917. }
  11918. if (customMaterial === undefined) {
  11919. var useMorphing = false;
  11920. if (material.morphTargets === true) {
  11921. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11922. }
  11923. var useSkinning = false;
  11924. if (object.isSkinnedMesh === true) {
  11925. if (material.skinning === true) {
  11926. useSkinning = true;
  11927. } else {
  11928. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  11929. }
  11930. }
  11931. var useInstancing = object.isInstancedMesh === true;
  11932. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  11933. } else {
  11934. result = customMaterial;
  11935. }
  11936. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  11937. // in this case we need a unique material instance reflecting the
  11938. // appropriate state
  11939. var keyA = result.uuid,
  11940. keyB = material.uuid;
  11941. var materialsForVariant = _materialCache[keyA];
  11942. if (materialsForVariant === undefined) {
  11943. materialsForVariant = {};
  11944. _materialCache[keyA] = materialsForVariant;
  11945. }
  11946. var cachedMaterial = materialsForVariant[keyB];
  11947. if (cachedMaterial === undefined) {
  11948. cachedMaterial = result.clone();
  11949. materialsForVariant[keyB] = cachedMaterial;
  11950. }
  11951. result = cachedMaterial;
  11952. }
  11953. result.visible = material.visible;
  11954. result.wireframe = material.wireframe;
  11955. if (type === VSMShadowMap) {
  11956. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  11957. } else {
  11958. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  11959. }
  11960. result.clipShadows = material.clipShadows;
  11961. result.clippingPlanes = material.clippingPlanes;
  11962. result.clipIntersection = material.clipIntersection;
  11963. result.wireframeLinewidth = material.wireframeLinewidth;
  11964. result.linewidth = material.linewidth;
  11965. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  11966. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  11967. result.nearDistance = shadowCameraNear;
  11968. result.farDistance = shadowCameraFar;
  11969. }
  11970. return result;
  11971. }
  11972. function renderObject(object, camera, shadowCamera, light, type) {
  11973. if (object.visible === false) return;
  11974. var visible = object.layers.test(camera.layers);
  11975. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  11976. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  11977. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  11978. var geometry = _objects.update(object);
  11979. var material = object.material;
  11980. if (Array.isArray(material)) {
  11981. var groups = geometry.groups;
  11982. for (var k = 0, kl = groups.length; k < kl; k++) {
  11983. var group = groups[k];
  11984. var groupMaterial = material[group.materialIndex];
  11985. if (groupMaterial && groupMaterial.visible) {
  11986. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  11987. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  11988. }
  11989. }
  11990. } else if (material.visible) {
  11991. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  11992. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  11993. }
  11994. }
  11995. }
  11996. var children = object.children;
  11997. for (var i = 0, l = children.length; i < l; i++) {
  11998. renderObject(children[i], camera, shadowCamera, light, type);
  11999. }
  12000. }
  12001. }
  12002. function WebGLState(gl, extensions, capabilities) {
  12003. var _equationToGL, _factorToGL;
  12004. var isWebGL2 = capabilities.isWebGL2;
  12005. function ColorBuffer() {
  12006. var locked = false;
  12007. var color = new Vector4();
  12008. var currentColorMask = null;
  12009. var currentColorClear = new Vector4(0, 0, 0, 0);
  12010. return {
  12011. setMask: function setMask(colorMask) {
  12012. if (currentColorMask !== colorMask && !locked) {
  12013. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12014. currentColorMask = colorMask;
  12015. }
  12016. },
  12017. setLocked: function setLocked(lock) {
  12018. locked = lock;
  12019. },
  12020. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12021. if (premultipliedAlpha === true) {
  12022. r *= a;
  12023. g *= a;
  12024. b *= a;
  12025. }
  12026. color.set(r, g, b, a);
  12027. if (currentColorClear.equals(color) === false) {
  12028. gl.clearColor(r, g, b, a);
  12029. currentColorClear.copy(color);
  12030. }
  12031. },
  12032. reset: function reset() {
  12033. locked = false;
  12034. currentColorMask = null;
  12035. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12036. }
  12037. };
  12038. }
  12039. function DepthBuffer() {
  12040. var locked = false;
  12041. var currentDepthMask = null;
  12042. var currentDepthFunc = null;
  12043. var currentDepthClear = null;
  12044. return {
  12045. setTest: function setTest(depthTest) {
  12046. if (depthTest) {
  12047. enable(2929);
  12048. } else {
  12049. disable(2929);
  12050. }
  12051. },
  12052. setMask: function setMask(depthMask) {
  12053. if (currentDepthMask !== depthMask && !locked) {
  12054. gl.depthMask(depthMask);
  12055. currentDepthMask = depthMask;
  12056. }
  12057. },
  12058. setFunc: function setFunc(depthFunc) {
  12059. if (currentDepthFunc !== depthFunc) {
  12060. if (depthFunc) {
  12061. switch (depthFunc) {
  12062. case NeverDepth:
  12063. gl.depthFunc(512);
  12064. break;
  12065. case AlwaysDepth:
  12066. gl.depthFunc(519);
  12067. break;
  12068. case LessDepth:
  12069. gl.depthFunc(513);
  12070. break;
  12071. case LessEqualDepth:
  12072. gl.depthFunc(515);
  12073. break;
  12074. case EqualDepth:
  12075. gl.depthFunc(514);
  12076. break;
  12077. case GreaterEqualDepth:
  12078. gl.depthFunc(518);
  12079. break;
  12080. case GreaterDepth:
  12081. gl.depthFunc(516);
  12082. break;
  12083. case NotEqualDepth:
  12084. gl.depthFunc(517);
  12085. break;
  12086. default:
  12087. gl.depthFunc(515);
  12088. }
  12089. } else {
  12090. gl.depthFunc(515);
  12091. }
  12092. currentDepthFunc = depthFunc;
  12093. }
  12094. },
  12095. setLocked: function setLocked(lock) {
  12096. locked = lock;
  12097. },
  12098. setClear: function setClear(depth) {
  12099. if (currentDepthClear !== depth) {
  12100. gl.clearDepth(depth);
  12101. currentDepthClear = depth;
  12102. }
  12103. },
  12104. reset: function reset() {
  12105. locked = false;
  12106. currentDepthMask = null;
  12107. currentDepthFunc = null;
  12108. currentDepthClear = null;
  12109. }
  12110. };
  12111. }
  12112. function StencilBuffer() {
  12113. var locked = false;
  12114. var currentStencilMask = null;
  12115. var currentStencilFunc = null;
  12116. var currentStencilRef = null;
  12117. var currentStencilFuncMask = null;
  12118. var currentStencilFail = null;
  12119. var currentStencilZFail = null;
  12120. var currentStencilZPass = null;
  12121. var currentStencilClear = null;
  12122. return {
  12123. setTest: function setTest(stencilTest) {
  12124. if (!locked) {
  12125. if (stencilTest) {
  12126. enable(2960);
  12127. } else {
  12128. disable(2960);
  12129. }
  12130. }
  12131. },
  12132. setMask: function setMask(stencilMask) {
  12133. if (currentStencilMask !== stencilMask && !locked) {
  12134. gl.stencilMask(stencilMask);
  12135. currentStencilMask = stencilMask;
  12136. }
  12137. },
  12138. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12139. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12140. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12141. currentStencilFunc = stencilFunc;
  12142. currentStencilRef = stencilRef;
  12143. currentStencilFuncMask = stencilMask;
  12144. }
  12145. },
  12146. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12147. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12148. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12149. currentStencilFail = stencilFail;
  12150. currentStencilZFail = stencilZFail;
  12151. currentStencilZPass = stencilZPass;
  12152. }
  12153. },
  12154. setLocked: function setLocked(lock) {
  12155. locked = lock;
  12156. },
  12157. setClear: function setClear(stencil) {
  12158. if (currentStencilClear !== stencil) {
  12159. gl.clearStencil(stencil);
  12160. currentStencilClear = stencil;
  12161. }
  12162. },
  12163. reset: function reset() {
  12164. locked = false;
  12165. currentStencilMask = null;
  12166. currentStencilFunc = null;
  12167. currentStencilRef = null;
  12168. currentStencilFuncMask = null;
  12169. currentStencilFail = null;
  12170. currentStencilZFail = null;
  12171. currentStencilZPass = null;
  12172. currentStencilClear = null;
  12173. }
  12174. };
  12175. } //
  12176. var colorBuffer = new ColorBuffer();
  12177. var depthBuffer = new DepthBuffer();
  12178. var stencilBuffer = new StencilBuffer();
  12179. var enabledCapabilities = {};
  12180. var currentProgram = null;
  12181. var currentBlendingEnabled = null;
  12182. var currentBlending = null;
  12183. var currentBlendEquation = null;
  12184. var currentBlendSrc = null;
  12185. var currentBlendDst = null;
  12186. var currentBlendEquationAlpha = null;
  12187. var currentBlendSrcAlpha = null;
  12188. var currentBlendDstAlpha = null;
  12189. var currentPremultipledAlpha = false;
  12190. var currentFlipSided = null;
  12191. var currentCullFace = null;
  12192. var currentLineWidth = null;
  12193. var currentPolygonOffsetFactor = null;
  12194. var currentPolygonOffsetUnits = null;
  12195. var maxTextures = gl.getParameter(35661);
  12196. var lineWidthAvailable = false;
  12197. var version = 0;
  12198. var glVersion = gl.getParameter(7938);
  12199. if (glVersion.indexOf('WebGL') !== -1) {
  12200. version = parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);
  12201. lineWidthAvailable = version >= 1.0;
  12202. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12203. version = parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);
  12204. lineWidthAvailable = version >= 2.0;
  12205. }
  12206. var currentTextureSlot = null;
  12207. var currentBoundTextures = {};
  12208. var currentScissor = new Vector4();
  12209. var currentViewport = new Vector4();
  12210. function createTexture(type, target, count) {
  12211. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12212. var texture = gl.createTexture();
  12213. gl.bindTexture(type, texture);
  12214. gl.texParameteri(type, 10241, 9728);
  12215. gl.texParameteri(type, 10240, 9728);
  12216. for (var i = 0; i < count; i++) {
  12217. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12218. }
  12219. return texture;
  12220. }
  12221. var emptyTextures = {};
  12222. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12223. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12224. colorBuffer.setClear(0, 0, 0, 1);
  12225. depthBuffer.setClear(1);
  12226. stencilBuffer.setClear(0);
  12227. enable(2929);
  12228. depthBuffer.setFunc(LessEqualDepth);
  12229. setFlipSided(false);
  12230. setCullFace(CullFaceBack);
  12231. enable(2884);
  12232. setBlending(NoBlending); //
  12233. function enable(id) {
  12234. if (enabledCapabilities[id] !== true) {
  12235. gl.enable(id);
  12236. enabledCapabilities[id] = true;
  12237. }
  12238. }
  12239. function disable(id) {
  12240. if (enabledCapabilities[id] !== false) {
  12241. gl.disable(id);
  12242. enabledCapabilities[id] = false;
  12243. }
  12244. }
  12245. function useProgram(program) {
  12246. if (currentProgram !== program) {
  12247. gl.useProgram(program);
  12248. currentProgram = program;
  12249. return true;
  12250. }
  12251. return false;
  12252. }
  12253. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12254. if (isWebGL2) {
  12255. equationToGL[MinEquation] = 32775;
  12256. equationToGL[MaxEquation] = 32776;
  12257. } else {
  12258. var extension = extensions.get('EXT_blend_minmax');
  12259. if (extension !== null) {
  12260. equationToGL[MinEquation] = extension.MIN_EXT;
  12261. equationToGL[MaxEquation] = extension.MAX_EXT;
  12262. }
  12263. }
  12264. 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);
  12265. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12266. if (blending === NoBlending) {
  12267. if (currentBlendingEnabled) {
  12268. disable(3042);
  12269. currentBlendingEnabled = false;
  12270. }
  12271. return;
  12272. }
  12273. if (!currentBlendingEnabled) {
  12274. enable(3042);
  12275. currentBlendingEnabled = true;
  12276. }
  12277. if (blending !== CustomBlending) {
  12278. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12279. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12280. gl.blendEquation(32774);
  12281. currentBlendEquation = AddEquation;
  12282. currentBlendEquationAlpha = AddEquation;
  12283. }
  12284. if (premultipliedAlpha) {
  12285. switch (blending) {
  12286. case NormalBlending:
  12287. gl.blendFuncSeparate(1, 771, 1, 771);
  12288. break;
  12289. case AdditiveBlending:
  12290. gl.blendFunc(1, 1);
  12291. break;
  12292. case SubtractiveBlending:
  12293. gl.blendFuncSeparate(0, 0, 769, 771);
  12294. break;
  12295. case MultiplyBlending:
  12296. gl.blendFuncSeparate(0, 768, 0, 770);
  12297. break;
  12298. default:
  12299. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12300. break;
  12301. }
  12302. } else {
  12303. switch (blending) {
  12304. case NormalBlending:
  12305. gl.blendFuncSeparate(770, 771, 1, 771);
  12306. break;
  12307. case AdditiveBlending:
  12308. gl.blendFunc(770, 1);
  12309. break;
  12310. case SubtractiveBlending:
  12311. gl.blendFunc(0, 769);
  12312. break;
  12313. case MultiplyBlending:
  12314. gl.blendFunc(0, 768);
  12315. break;
  12316. default:
  12317. console.error('THREE.WebGLState: Invalid blending: ', blending);
  12318. break;
  12319. }
  12320. }
  12321. currentBlendSrc = null;
  12322. currentBlendDst = null;
  12323. currentBlendSrcAlpha = null;
  12324. currentBlendDstAlpha = null;
  12325. currentBlending = blending;
  12326. currentPremultipledAlpha = premultipliedAlpha;
  12327. }
  12328. return;
  12329. } // custom blending
  12330. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12331. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12332. blendDstAlpha = blendDstAlpha || blendDst;
  12333. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  12334. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  12335. currentBlendEquation = blendEquation;
  12336. currentBlendEquationAlpha = blendEquationAlpha;
  12337. }
  12338. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  12339. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  12340. currentBlendSrc = blendSrc;
  12341. currentBlendDst = blendDst;
  12342. currentBlendSrcAlpha = blendSrcAlpha;
  12343. currentBlendDstAlpha = blendDstAlpha;
  12344. }
  12345. currentBlending = blending;
  12346. currentPremultipledAlpha = null;
  12347. }
  12348. function setMaterial(material, frontFaceCW) {
  12349. material.side === DoubleSide ? disable(2884) : enable(2884);
  12350. var flipSided = material.side === BackSide;
  12351. if (frontFaceCW) flipSided = !flipSided;
  12352. setFlipSided(flipSided);
  12353. 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);
  12354. depthBuffer.setFunc(material.depthFunc);
  12355. depthBuffer.setTest(material.depthTest);
  12356. depthBuffer.setMask(material.depthWrite);
  12357. colorBuffer.setMask(material.colorWrite);
  12358. var stencilWrite = material.stencilWrite;
  12359. stencilBuffer.setTest(stencilWrite);
  12360. if (stencilWrite) {
  12361. stencilBuffer.setMask(material.stencilWriteMask);
  12362. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  12363. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  12364. }
  12365. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  12366. } //
  12367. function setFlipSided(flipSided) {
  12368. if (currentFlipSided !== flipSided) {
  12369. if (flipSided) {
  12370. gl.frontFace(2304);
  12371. } else {
  12372. gl.frontFace(2305);
  12373. }
  12374. currentFlipSided = flipSided;
  12375. }
  12376. }
  12377. function setCullFace(cullFace) {
  12378. if (cullFace !== CullFaceNone) {
  12379. enable(2884);
  12380. if (cullFace !== currentCullFace) {
  12381. if (cullFace === CullFaceBack) {
  12382. gl.cullFace(1029);
  12383. } else if (cullFace === CullFaceFront) {
  12384. gl.cullFace(1028);
  12385. } else {
  12386. gl.cullFace(1032);
  12387. }
  12388. }
  12389. } else {
  12390. disable(2884);
  12391. }
  12392. currentCullFace = cullFace;
  12393. }
  12394. function setLineWidth(width) {
  12395. if (width !== currentLineWidth) {
  12396. if (lineWidthAvailable) gl.lineWidth(width);
  12397. currentLineWidth = width;
  12398. }
  12399. }
  12400. function setPolygonOffset(polygonOffset, factor, units) {
  12401. if (polygonOffset) {
  12402. enable(32823);
  12403. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  12404. gl.polygonOffset(factor, units);
  12405. currentPolygonOffsetFactor = factor;
  12406. currentPolygonOffsetUnits = units;
  12407. }
  12408. } else {
  12409. disable(32823);
  12410. }
  12411. }
  12412. function setScissorTest(scissorTest) {
  12413. if (scissorTest) {
  12414. enable(3089);
  12415. } else {
  12416. disable(3089);
  12417. }
  12418. } // texture
  12419. function activeTexture(webglSlot) {
  12420. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  12421. if (currentTextureSlot !== webglSlot) {
  12422. gl.activeTexture(webglSlot);
  12423. currentTextureSlot = webglSlot;
  12424. }
  12425. }
  12426. function bindTexture(webglType, webglTexture) {
  12427. if (currentTextureSlot === null) {
  12428. activeTexture();
  12429. }
  12430. var boundTexture = currentBoundTextures[currentTextureSlot];
  12431. if (boundTexture === undefined) {
  12432. boundTexture = {
  12433. type: undefined,
  12434. texture: undefined
  12435. };
  12436. currentBoundTextures[currentTextureSlot] = boundTexture;
  12437. }
  12438. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  12439. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  12440. boundTexture.type = webglType;
  12441. boundTexture.texture = webglTexture;
  12442. }
  12443. }
  12444. function unbindTexture() {
  12445. var boundTexture = currentBoundTextures[currentTextureSlot];
  12446. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  12447. gl.bindTexture(boundTexture.type, null);
  12448. boundTexture.type = undefined;
  12449. boundTexture.texture = undefined;
  12450. }
  12451. }
  12452. function compressedTexImage2D() {
  12453. try {
  12454. gl.compressedTexImage2D.apply(gl, arguments);
  12455. } catch (error) {
  12456. console.error('THREE.WebGLState:', error);
  12457. }
  12458. }
  12459. function texImage2D() {
  12460. try {
  12461. gl.texImage2D.apply(gl, arguments);
  12462. } catch (error) {
  12463. console.error('THREE.WebGLState:', error);
  12464. }
  12465. }
  12466. function texImage3D() {
  12467. try {
  12468. gl.texImage3D.apply(gl, arguments);
  12469. } catch (error) {
  12470. console.error('THREE.WebGLState:', error);
  12471. }
  12472. } //
  12473. function scissor(scissor) {
  12474. if (currentScissor.equals(scissor) === false) {
  12475. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  12476. currentScissor.copy(scissor);
  12477. }
  12478. }
  12479. function viewport(viewport) {
  12480. if (currentViewport.equals(viewport) === false) {
  12481. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  12482. currentViewport.copy(viewport);
  12483. }
  12484. } //
  12485. function reset() {
  12486. enabledCapabilities = {};
  12487. currentTextureSlot = null;
  12488. currentBoundTextures = {};
  12489. currentProgram = null;
  12490. currentBlending = null;
  12491. currentFlipSided = null;
  12492. currentCullFace = null;
  12493. colorBuffer.reset();
  12494. depthBuffer.reset();
  12495. stencilBuffer.reset();
  12496. }
  12497. return {
  12498. buffers: {
  12499. color: colorBuffer,
  12500. depth: depthBuffer,
  12501. stencil: stencilBuffer
  12502. },
  12503. enable: enable,
  12504. disable: disable,
  12505. useProgram: useProgram,
  12506. setBlending: setBlending,
  12507. setMaterial: setMaterial,
  12508. setFlipSided: setFlipSided,
  12509. setCullFace: setCullFace,
  12510. setLineWidth: setLineWidth,
  12511. setPolygonOffset: setPolygonOffset,
  12512. setScissorTest: setScissorTest,
  12513. activeTexture: activeTexture,
  12514. bindTexture: bindTexture,
  12515. unbindTexture: unbindTexture,
  12516. compressedTexImage2D: compressedTexImage2D,
  12517. texImage2D: texImage2D,
  12518. texImage3D: texImage3D,
  12519. scissor: scissor,
  12520. viewport: viewport,
  12521. reset: reset
  12522. };
  12523. }
  12524. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  12525. var _wrappingToGL, _filterToGL;
  12526. var isWebGL2 = capabilities.isWebGL2;
  12527. var maxTextures = capabilities.maxTextures;
  12528. var maxCubemapSize = capabilities.maxCubemapSize;
  12529. var maxTextureSize = capabilities.maxTextureSize;
  12530. var maxSamples = capabilities.maxSamples;
  12531. var _videoTextures = new WeakMap();
  12532. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12533. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12534. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12535. var useOffscreenCanvas = false;
  12536. try {
  12537. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  12538. } catch (err) {// Ignore any errors
  12539. }
  12540. function createCanvas(width, height) {
  12541. // Use OffscreenCanvas when available. Specially needed in web workers
  12542. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  12543. }
  12544. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  12545. var scale = 1; // handle case if texture exceeds max size
  12546. if (image.width > maxSize || image.height > maxSize) {
  12547. scale = maxSize / Math.max(image.width, image.height);
  12548. } // only perform resize if necessary
  12549. if (scale < 1 || needsPowerOfTwo === true) {
  12550. // only perform resize for certain image types
  12551. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  12552. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12553. var width = floor(scale * image.width);
  12554. var height = floor(scale * image.height);
  12555. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  12556. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  12557. canvas.width = width;
  12558. canvas.height = height;
  12559. var context = canvas.getContext('2d');
  12560. context.drawImage(image, 0, 0, width, height);
  12561. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  12562. return canvas;
  12563. } else {
  12564. if ('data' in image) {
  12565. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  12566. }
  12567. return image;
  12568. }
  12569. }
  12570. return image;
  12571. }
  12572. function isPowerOfTwo(image) {
  12573. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  12574. }
  12575. function textureNeedsPowerOfTwo(texture) {
  12576. if (isWebGL2) return false;
  12577. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12578. }
  12579. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  12580. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12581. }
  12582. function generateMipmap(target, texture, width, height) {
  12583. _gl.generateMipmap(target);
  12584. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12585. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  12586. }
  12587. function getInternalFormat(internalFormatName, glFormat, glType) {
  12588. if (isWebGL2 === false) return glFormat;
  12589. if (internalFormatName !== null) {
  12590. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  12591. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  12592. }
  12593. var internalFormat = glFormat;
  12594. if (glFormat === 6403) {
  12595. if (glType === 5126) internalFormat = 33326;
  12596. if (glType === 5131) internalFormat = 33325;
  12597. if (glType === 5121) internalFormat = 33321;
  12598. }
  12599. if (glFormat === 6407) {
  12600. if (glType === 5126) internalFormat = 34837;
  12601. if (glType === 5131) internalFormat = 34843;
  12602. if (glType === 5121) internalFormat = 32849;
  12603. }
  12604. if (glFormat === 6408) {
  12605. if (glType === 5126) internalFormat = 34836;
  12606. if (glType === 5131) internalFormat = 34842;
  12607. if (glType === 5121) internalFormat = 32856;
  12608. }
  12609. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  12610. extensions.get('EXT_color_buffer_float');
  12611. }
  12612. return internalFormat;
  12613. } // Fallback filters for non-power-of-2 textures
  12614. function filterFallback(f) {
  12615. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  12616. return 9728;
  12617. }
  12618. return 9729;
  12619. } //
  12620. function onTextureDispose(event) {
  12621. var texture = event.target;
  12622. texture.removeEventListener('dispose', onTextureDispose);
  12623. deallocateTexture(texture);
  12624. if (texture.isVideoTexture) {
  12625. _videoTextures.delete(texture);
  12626. }
  12627. info.memory.textures--;
  12628. }
  12629. function onRenderTargetDispose(event) {
  12630. var renderTarget = event.target;
  12631. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  12632. deallocateRenderTarget(renderTarget);
  12633. info.memory.textures--;
  12634. } //
  12635. function deallocateTexture(texture) {
  12636. var textureProperties = properties.get(texture);
  12637. if (textureProperties.__webglInit === undefined) return;
  12638. _gl.deleteTexture(textureProperties.__webglTexture);
  12639. properties.remove(texture);
  12640. }
  12641. function deallocateRenderTarget(renderTarget) {
  12642. var renderTargetProperties = properties.get(renderTarget);
  12643. var textureProperties = properties.get(renderTarget.texture);
  12644. if (!renderTarget) return;
  12645. if (textureProperties.__webglTexture !== undefined) {
  12646. _gl.deleteTexture(textureProperties.__webglTexture);
  12647. }
  12648. if (renderTarget.depthTexture) {
  12649. renderTarget.depthTexture.dispose();
  12650. }
  12651. if (renderTarget.isWebGLCubeRenderTarget) {
  12652. for (var i = 0; i < 6; i++) {
  12653. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  12654. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  12655. }
  12656. } else {
  12657. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  12658. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  12659. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  12660. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  12661. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  12662. }
  12663. properties.remove(renderTarget.texture);
  12664. properties.remove(renderTarget);
  12665. } //
  12666. var textureUnits = 0;
  12667. function resetTextureUnits() {
  12668. textureUnits = 0;
  12669. }
  12670. function allocateTextureUnit() {
  12671. var textureUnit = textureUnits;
  12672. if (textureUnit >= maxTextures) {
  12673. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  12674. }
  12675. textureUnits += 1;
  12676. return textureUnit;
  12677. } //
  12678. function setTexture2D(texture, slot) {
  12679. var textureProperties = properties.get(texture);
  12680. if (texture.isVideoTexture) updateVideoTexture(texture);
  12681. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12682. var image = texture.image;
  12683. if (image === undefined) {
  12684. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  12685. } else if (image.complete === false) {
  12686. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  12687. } else {
  12688. uploadTexture(textureProperties, texture, slot);
  12689. return;
  12690. }
  12691. }
  12692. state.activeTexture(33984 + slot);
  12693. state.bindTexture(3553, textureProperties.__webglTexture);
  12694. }
  12695. function setTexture2DArray(texture, slot) {
  12696. var textureProperties = properties.get(texture);
  12697. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12698. uploadTexture(textureProperties, texture, slot);
  12699. return;
  12700. }
  12701. state.activeTexture(33984 + slot);
  12702. state.bindTexture(35866, textureProperties.__webglTexture);
  12703. }
  12704. function setTexture3D(texture, slot) {
  12705. var textureProperties = properties.get(texture);
  12706. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12707. uploadTexture(textureProperties, texture, slot);
  12708. return;
  12709. }
  12710. state.activeTexture(33984 + slot);
  12711. state.bindTexture(32879, textureProperties.__webglTexture);
  12712. }
  12713. function setTextureCube(texture, slot) {
  12714. var textureProperties = properties.get(texture);
  12715. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  12716. uploadCubeTexture(textureProperties, texture, slot);
  12717. return;
  12718. }
  12719. state.activeTexture(33984 + slot);
  12720. state.bindTexture(34067, textureProperties.__webglTexture);
  12721. }
  12722. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  12723. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  12724. function setTextureParameters(textureType, texture, supportsMips) {
  12725. if (supportsMips) {
  12726. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  12727. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  12728. if (textureType === 32879 || textureType === 35866) {
  12729. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  12730. }
  12731. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  12732. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  12733. } else {
  12734. _gl.texParameteri(textureType, 10242, 33071);
  12735. _gl.texParameteri(textureType, 10243, 33071);
  12736. if (textureType === 32879 || textureType === 35866) {
  12737. _gl.texParameteri(textureType, 32882, 33071);
  12738. }
  12739. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  12740. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  12741. }
  12742. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  12743. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  12744. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  12745. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  12746. }
  12747. }
  12748. var extension = extensions.get('EXT_texture_filter_anisotropic');
  12749. if (extension) {
  12750. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  12751. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  12752. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  12753. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  12754. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  12755. }
  12756. }
  12757. }
  12758. function initTexture(textureProperties, texture) {
  12759. if (textureProperties.__webglInit === undefined) {
  12760. textureProperties.__webglInit = true;
  12761. texture.addEventListener('dispose', onTextureDispose);
  12762. textureProperties.__webglTexture = _gl.createTexture();
  12763. info.memory.textures++;
  12764. }
  12765. }
  12766. function uploadTexture(textureProperties, texture, slot) {
  12767. var textureType = 3553;
  12768. if (texture.isDataTexture2DArray) textureType = 35866;
  12769. if (texture.isDataTexture3D) textureType = 32879;
  12770. initTexture(textureProperties, texture);
  12771. state.activeTexture(33984 + slot);
  12772. state.bindTexture(textureType, textureProperties.__webglTexture);
  12773. _gl.pixelStorei(37440, texture.flipY);
  12774. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  12775. _gl.pixelStorei(3317, texture.unpackAlignment);
  12776. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  12777. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  12778. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  12779. glFormat = utils.convert(texture.format);
  12780. var glType = utils.convert(texture.type),
  12781. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12782. setTextureParameters(textureType, texture, supportsMips);
  12783. var mipmap;
  12784. var mipmaps = texture.mipmaps;
  12785. if (texture.isDepthTexture) {
  12786. // populate depth texture with dummy data
  12787. glInternalFormat = 6402;
  12788. if (isWebGL2) {
  12789. if (texture.type === FloatType) {
  12790. glInternalFormat = 36012;
  12791. } else if (texture.type === UnsignedIntType) {
  12792. glInternalFormat = 33190;
  12793. } else if (texture.type === UnsignedInt248Type) {
  12794. glInternalFormat = 35056;
  12795. } else {
  12796. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12797. }
  12798. } else {
  12799. if (texture.type === FloatType) {
  12800. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  12801. }
  12802. } // validation checks for WebGL 1
  12803. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  12804. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12805. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12806. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12807. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  12808. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  12809. texture.type = UnsignedShortType;
  12810. glType = utils.convert(texture.type);
  12811. }
  12812. }
  12813. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  12814. // Depth stencil textures need the DEPTH_STENCIL internal format
  12815. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12816. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12817. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12818. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12819. if (texture.type !== UnsignedInt248Type) {
  12820. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  12821. texture.type = UnsignedInt248Type;
  12822. glType = utils.convert(texture.type);
  12823. }
  12824. } //
  12825. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  12826. } else if (texture.isDataTexture) {
  12827. // use manually created mipmaps if available
  12828. // if there are no manual mipmaps
  12829. // set 0 level mipmap and then use GL to generate other mipmap levels
  12830. if (mipmaps.length > 0 && supportsMips) {
  12831. for (var i = 0, il = mipmaps.length; i < il; i++) {
  12832. mipmap = mipmaps[i];
  12833. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12834. }
  12835. texture.generateMipmaps = false;
  12836. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12837. } else {
  12838. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  12839. textureProperties.__maxMipLevel = 0;
  12840. }
  12841. } else if (texture.isCompressedTexture) {
  12842. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  12843. mipmap = mipmaps[_i];
  12844. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12845. if (glFormat !== null) {
  12846. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12847. } else {
  12848. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  12849. }
  12850. } else {
  12851. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12852. }
  12853. }
  12854. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12855. } else if (texture.isDataTexture2DArray) {
  12856. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12857. textureProperties.__maxMipLevel = 0;
  12858. } else if (texture.isDataTexture3D) {
  12859. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  12860. textureProperties.__maxMipLevel = 0;
  12861. } else {
  12862. // regular Texture (image, video, canvas)
  12863. // use manually created mipmaps if available
  12864. // if there are no manual mipmaps
  12865. // set 0 level mipmap and then use GL to generate other mipmap levels
  12866. if (mipmaps.length > 0 && supportsMips) {
  12867. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  12868. mipmap = mipmaps[_i2];
  12869. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  12870. }
  12871. texture.generateMipmaps = false;
  12872. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12873. } else {
  12874. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  12875. textureProperties.__maxMipLevel = 0;
  12876. }
  12877. }
  12878. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12879. generateMipmap(textureType, texture, image.width, image.height);
  12880. }
  12881. textureProperties.__version = texture.version;
  12882. if (texture.onUpdate) texture.onUpdate(texture);
  12883. }
  12884. function uploadCubeTexture(textureProperties, texture, slot) {
  12885. if (texture.image.length !== 6) return;
  12886. initTexture(textureProperties, texture);
  12887. state.activeTexture(33984 + slot);
  12888. state.bindTexture(34067, textureProperties.__webglTexture);
  12889. _gl.pixelStorei(37440, texture.flipY);
  12890. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  12891. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  12892. var cubeImage = [];
  12893. for (var i = 0; i < 6; i++) {
  12894. if (!isCompressed && !isDataTexture) {
  12895. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  12896. } else {
  12897. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  12898. }
  12899. }
  12900. var image = cubeImage[0],
  12901. supportsMips = isPowerOfTwo(image) || isWebGL2,
  12902. glFormat = utils.convert(texture.format),
  12903. glType = utils.convert(texture.type),
  12904. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  12905. setTextureParameters(34067, texture, supportsMips);
  12906. var mipmaps;
  12907. if (isCompressed) {
  12908. for (var _i3 = 0; _i3 < 6; _i3++) {
  12909. mipmaps = cubeImage[_i3].mipmaps;
  12910. for (var j = 0; j < mipmaps.length; j++) {
  12911. var mipmap = mipmaps[j];
  12912. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  12913. if (glFormat !== null) {
  12914. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  12915. } else {
  12916. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  12917. }
  12918. } else {
  12919. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  12920. }
  12921. }
  12922. }
  12923. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12924. } else {
  12925. mipmaps = texture.mipmaps;
  12926. for (var _i4 = 0; _i4 < 6; _i4++) {
  12927. if (isDataTexture) {
  12928. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  12929. for (var _j = 0; _j < mipmaps.length; _j++) {
  12930. var _mipmap = mipmaps[_j];
  12931. var mipmapImage = _mipmap.image[_i4].image;
  12932. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  12933. }
  12934. } else {
  12935. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  12936. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  12937. var _mipmap2 = mipmaps[_j2];
  12938. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  12939. }
  12940. }
  12941. }
  12942. textureProperties.__maxMipLevel = mipmaps.length;
  12943. }
  12944. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  12945. // We assume images for cube map have the same size.
  12946. generateMipmap(34067, texture, image.width, image.height);
  12947. }
  12948. textureProperties.__version = texture.version;
  12949. if (texture.onUpdate) texture.onUpdate(texture);
  12950. } // Render targets
  12951. // Setup storage for target texture and bind it to correct framebuffer
  12952. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  12953. var glFormat = utils.convert(renderTarget.texture.format);
  12954. var glType = utils.convert(renderTarget.texture.type);
  12955. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12956. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  12957. _gl.bindFramebuffer(36160, framebuffer);
  12958. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  12959. _gl.bindFramebuffer(36160, null);
  12960. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12961. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  12962. _gl.bindRenderbuffer(36161, renderbuffer);
  12963. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  12964. var glInternalFormat = 33189;
  12965. if (isMultisample) {
  12966. var depthTexture = renderTarget.depthTexture;
  12967. if (depthTexture && depthTexture.isDepthTexture) {
  12968. if (depthTexture.type === FloatType) {
  12969. glInternalFormat = 36012;
  12970. } else if (depthTexture.type === UnsignedIntType) {
  12971. glInternalFormat = 33190;
  12972. }
  12973. }
  12974. var samples = getRenderTargetSamples(renderTarget);
  12975. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  12976. } else {
  12977. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  12978. }
  12979. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  12980. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  12981. if (isMultisample) {
  12982. var _samples = getRenderTargetSamples(renderTarget);
  12983. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  12984. } else {
  12985. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  12986. }
  12987. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  12988. } else {
  12989. var glFormat = utils.convert(renderTarget.texture.format);
  12990. var glType = utils.convert(renderTarget.texture.type);
  12991. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  12992. if (isMultisample) {
  12993. var _samples2 = getRenderTargetSamples(renderTarget);
  12994. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  12995. } else {
  12996. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  12997. }
  12998. }
  12999. _gl.bindRenderbuffer(36161, null);
  13000. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13001. function setupDepthTexture(framebuffer, renderTarget) {
  13002. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13003. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13004. _gl.bindFramebuffer(36160, framebuffer);
  13005. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13006. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13007. } // upload an empty depth texture with framebuffer size
  13008. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13009. renderTarget.depthTexture.image.width = renderTarget.width;
  13010. renderTarget.depthTexture.image.height = renderTarget.height;
  13011. renderTarget.depthTexture.needsUpdate = true;
  13012. }
  13013. setTexture2D(renderTarget.depthTexture, 0);
  13014. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13015. if (renderTarget.depthTexture.format === DepthFormat) {
  13016. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13017. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13018. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13019. } else {
  13020. throw new Error('Unknown depthTexture format');
  13021. }
  13022. } // Setup GL resources for a non-texture depth buffer
  13023. function setupDepthRenderbuffer(renderTarget) {
  13024. var renderTargetProperties = properties.get(renderTarget);
  13025. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13026. if (renderTarget.depthTexture) {
  13027. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13028. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13029. } else {
  13030. if (isCube) {
  13031. renderTargetProperties.__webglDepthbuffer = [];
  13032. for (var i = 0; i < 6; i++) {
  13033. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13034. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13035. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13036. }
  13037. } else {
  13038. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13039. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13040. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13041. }
  13042. }
  13043. _gl.bindFramebuffer(36160, null);
  13044. } // Set up GL resources for the render target
  13045. function setupRenderTarget(renderTarget) {
  13046. var renderTargetProperties = properties.get(renderTarget);
  13047. var textureProperties = properties.get(renderTarget.texture);
  13048. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13049. textureProperties.__webglTexture = _gl.createTexture();
  13050. info.memory.textures++;
  13051. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13052. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13053. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13054. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13055. renderTarget.texture.format = RGBAFormat;
  13056. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13057. } // Setup framebuffer
  13058. if (isCube) {
  13059. renderTargetProperties.__webglFramebuffer = [];
  13060. for (var i = 0; i < 6; i++) {
  13061. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13062. }
  13063. } else {
  13064. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13065. if (isMultisample) {
  13066. if (isWebGL2) {
  13067. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13068. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13069. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13070. var glFormat = utils.convert(renderTarget.texture.format);
  13071. var glType = utils.convert(renderTarget.texture.type);
  13072. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13073. var samples = getRenderTargetSamples(renderTarget);
  13074. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13075. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13076. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13077. _gl.bindRenderbuffer(36161, null);
  13078. if (renderTarget.depthBuffer) {
  13079. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13080. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13081. }
  13082. _gl.bindFramebuffer(36160, null);
  13083. } else {
  13084. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13085. }
  13086. }
  13087. } // Setup color buffer
  13088. if (isCube) {
  13089. state.bindTexture(34067, textureProperties.__webglTexture);
  13090. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13091. for (var _i5 = 0; _i5 < 6; _i5++) {
  13092. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13093. }
  13094. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13095. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13096. }
  13097. state.bindTexture(34067, null);
  13098. } else {
  13099. state.bindTexture(3553, textureProperties.__webglTexture);
  13100. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13101. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13102. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13103. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13104. }
  13105. state.bindTexture(3553, null);
  13106. } // Setup depth and stencil buffers
  13107. if (renderTarget.depthBuffer) {
  13108. setupDepthRenderbuffer(renderTarget);
  13109. }
  13110. }
  13111. function updateRenderTargetMipmap(renderTarget) {
  13112. var texture = renderTarget.texture;
  13113. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13114. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13115. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13116. var webglTexture = properties.get(texture).__webglTexture;
  13117. state.bindTexture(target, webglTexture);
  13118. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13119. state.bindTexture(target, null);
  13120. }
  13121. }
  13122. function updateMultisampleRenderTarget(renderTarget) {
  13123. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13124. if (isWebGL2) {
  13125. var renderTargetProperties = properties.get(renderTarget);
  13126. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13127. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13128. var width = renderTarget.width;
  13129. var height = renderTarget.height;
  13130. var mask = 16384;
  13131. if (renderTarget.depthBuffer) mask |= 256;
  13132. if (renderTarget.stencilBuffer) mask |= 1024;
  13133. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13134. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13135. } else {
  13136. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13137. }
  13138. }
  13139. }
  13140. function getRenderTargetSamples(renderTarget) {
  13141. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13142. }
  13143. function updateVideoTexture(texture) {
  13144. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13145. if (_videoTextures.get(texture) !== frame) {
  13146. _videoTextures.set(texture, frame);
  13147. texture.update();
  13148. }
  13149. } // backwards compatibility
  13150. var warnedTexture2D = false;
  13151. var warnedTextureCube = false;
  13152. function safeSetTexture2D(texture, slot) {
  13153. if (texture && texture.isWebGLRenderTarget) {
  13154. if (warnedTexture2D === false) {
  13155. console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");
  13156. warnedTexture2D = true;
  13157. }
  13158. texture = texture.texture;
  13159. }
  13160. setTexture2D(texture, slot);
  13161. }
  13162. function safeSetTextureCube(texture, slot) {
  13163. if (texture && texture.isWebGLCubeRenderTarget) {
  13164. if (warnedTextureCube === false) {
  13165. console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");
  13166. warnedTextureCube = true;
  13167. }
  13168. texture = texture.texture;
  13169. }
  13170. setTextureCube(texture, slot);
  13171. } //
  13172. this.allocateTextureUnit = allocateTextureUnit;
  13173. this.resetTextureUnits = resetTextureUnits;
  13174. this.setTexture2D = setTexture2D;
  13175. this.setTexture2DArray = setTexture2DArray;
  13176. this.setTexture3D = setTexture3D;
  13177. this.setTextureCube = setTextureCube;
  13178. this.setupRenderTarget = setupRenderTarget;
  13179. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13180. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13181. this.safeSetTexture2D = safeSetTexture2D;
  13182. this.safeSetTextureCube = safeSetTextureCube;
  13183. }
  13184. function WebGLUtils(gl, extensions, capabilities) {
  13185. var isWebGL2 = capabilities.isWebGL2;
  13186. function convert(p) {
  13187. var extension;
  13188. if (p === UnsignedByteType) return 5121;
  13189. if (p === UnsignedShort4444Type) return 32819;
  13190. if (p === UnsignedShort5551Type) return 32820;
  13191. if (p === UnsignedShort565Type) return 33635;
  13192. if (p === ByteType) return 5120;
  13193. if (p === ShortType) return 5122;
  13194. if (p === UnsignedShortType) return 5123;
  13195. if (p === IntType) return 5124;
  13196. if (p === UnsignedIntType) return 5125;
  13197. if (p === FloatType) return 5126;
  13198. if (p === HalfFloatType) {
  13199. if (isWebGL2) return 5131;
  13200. extension = extensions.get('OES_texture_half_float');
  13201. if (extension !== null) {
  13202. return extension.HALF_FLOAT_OES;
  13203. } else {
  13204. return null;
  13205. }
  13206. }
  13207. if (p === AlphaFormat) return 6406;
  13208. if (p === RGBFormat) return 6407;
  13209. if (p === RGBAFormat) return 6408;
  13210. if (p === LuminanceFormat) return 6409;
  13211. if (p === LuminanceAlphaFormat) return 6410;
  13212. if (p === DepthFormat) return 6402;
  13213. if (p === DepthStencilFormat) return 34041;
  13214. if (p === RedFormat) return 6403; // WebGL2 formats.
  13215. if (p === RedIntegerFormat) return 36244;
  13216. if (p === RGFormat) return 33319;
  13217. if (p === RGIntegerFormat) return 33320;
  13218. if (p === RGBIntegerFormat) return 36248;
  13219. if (p === RGBAIntegerFormat) return 36249;
  13220. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13221. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13222. if (extension !== null) {
  13223. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13224. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13225. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13226. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13227. } else {
  13228. return null;
  13229. }
  13230. }
  13231. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13232. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13233. if (extension !== null) {
  13234. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13235. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13236. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13237. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13238. } else {
  13239. return null;
  13240. }
  13241. }
  13242. if (p === RGB_ETC1_Format) {
  13243. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13244. if (extension !== null) {
  13245. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13246. } else {
  13247. return null;
  13248. }
  13249. }
  13250. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13251. extension = extensions.get('WEBGL_compressed_texture_etc');
  13252. if (extension !== null) {
  13253. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13254. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13255. }
  13256. }
  13257. 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) {
  13258. extension = extensions.get('WEBGL_compressed_texture_astc');
  13259. if (extension !== null) {
  13260. // TODO Complete?
  13261. return p;
  13262. } else {
  13263. return null;
  13264. }
  13265. }
  13266. if (p === RGBA_BPTC_Format) {
  13267. extension = extensions.get('EXT_texture_compression_bptc');
  13268. if (extension !== null) {
  13269. // TODO Complete?
  13270. return p;
  13271. } else {
  13272. return null;
  13273. }
  13274. }
  13275. if (p === UnsignedInt248Type) {
  13276. if (isWebGL2) return 34042;
  13277. extension = extensions.get('WEBGL_depth_texture');
  13278. if (extension !== null) {
  13279. return extension.UNSIGNED_INT_24_8_WEBGL;
  13280. } else {
  13281. return null;
  13282. }
  13283. }
  13284. }
  13285. return {
  13286. convert: convert
  13287. };
  13288. }
  13289. function ArrayCamera(array) {
  13290. PerspectiveCamera.call(this);
  13291. this.cameras = array || [];
  13292. }
  13293. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  13294. constructor: ArrayCamera,
  13295. isArrayCamera: true
  13296. });
  13297. function Group() {
  13298. Object3D.call(this);
  13299. this.type = 'Group';
  13300. }
  13301. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  13302. constructor: Group,
  13303. isGroup: true
  13304. });
  13305. function WebXRController() {
  13306. this._targetRay = null;
  13307. this._grip = null;
  13308. this._hand = null;
  13309. }
  13310. Object.assign(WebXRController.prototype, {
  13311. constructor: WebXRController,
  13312. getHandSpace: function getHandSpace() {
  13313. if (this._hand === null) {
  13314. this._hand = new Group();
  13315. this._hand.matrixAutoUpdate = false;
  13316. this._hand.visible = false;
  13317. this._hand.joints = [];
  13318. this._hand.inputState = {
  13319. pinching: false
  13320. };
  13321. if (window.XRHand) {
  13322. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13323. // The transform of this joint will be updated with the joint pose on each frame
  13324. var joint = new Group();
  13325. joint.matrixAutoUpdate = false;
  13326. joint.visible = false;
  13327. this._hand.joints.push(joint); // ??
  13328. this._hand.add(joint);
  13329. }
  13330. }
  13331. }
  13332. return this._hand;
  13333. },
  13334. getTargetRaySpace: function getTargetRaySpace() {
  13335. if (this._targetRay === null) {
  13336. this._targetRay = new Group();
  13337. this._targetRay.matrixAutoUpdate = false;
  13338. this._targetRay.visible = false;
  13339. }
  13340. return this._targetRay;
  13341. },
  13342. getGripSpace: function getGripSpace() {
  13343. if (this._grip === null) {
  13344. this._grip = new Group();
  13345. this._grip.matrixAutoUpdate = false;
  13346. this._grip.visible = false;
  13347. }
  13348. return this._grip;
  13349. },
  13350. dispatchEvent: function dispatchEvent(event) {
  13351. if (this._targetRay !== null) {
  13352. this._targetRay.dispatchEvent(event);
  13353. }
  13354. if (this._grip !== null) {
  13355. this._grip.dispatchEvent(event);
  13356. }
  13357. if (this._hand !== null) {
  13358. this._hand.dispatchEvent(event);
  13359. }
  13360. return this;
  13361. },
  13362. disconnect: function disconnect(inputSource) {
  13363. this.dispatchEvent({
  13364. type: 'disconnected',
  13365. data: inputSource
  13366. });
  13367. if (this._targetRay !== null) {
  13368. this._targetRay.visible = false;
  13369. }
  13370. if (this._grip !== null) {
  13371. this._grip.visible = false;
  13372. }
  13373. if (this._hand !== null) {
  13374. this._hand.visible = false;
  13375. }
  13376. return this;
  13377. },
  13378. update: function update(inputSource, frame, referenceSpace) {
  13379. var inputPose = null;
  13380. var gripPose = null;
  13381. var handPose = null;
  13382. var targetRay = this._targetRay;
  13383. var grip = this._grip;
  13384. var hand = this._hand;
  13385. if (inputSource) {
  13386. if (hand && inputSource.hand) {
  13387. handPose = true;
  13388. for (var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i++) {
  13389. if (inputSource.hand[i]) {
  13390. // Update the joints groups with the XRJoint poses
  13391. var jointPose = frame.getJointPose(inputSource.hand[i], referenceSpace);
  13392. var joint = hand.joints[i];
  13393. if (jointPose !== null) {
  13394. joint.matrix.fromArray(jointPose.transform.matrix);
  13395. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  13396. joint.jointRadius = jointPose.radius;
  13397. }
  13398. joint.visible = jointPose !== null; // Custom events
  13399. // Check pinch
  13400. var indexTip = hand.joints[window.XRHand.INDEX_PHALANX_TIP];
  13401. var thumbTip = hand.joints[window.XRHand.THUMB_PHALANX_TIP];
  13402. var distance = indexTip.position.distanceTo(thumbTip.position);
  13403. var distanceToPinch = 0.02;
  13404. var threshold = 0.005;
  13405. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  13406. hand.inputState.pinching = false;
  13407. this.dispatchEvent({
  13408. type: "pinchend",
  13409. handedness: inputSource.handedness,
  13410. target: this
  13411. });
  13412. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  13413. hand.inputState.pinching = true;
  13414. this.dispatchEvent({
  13415. type: "pinchstart",
  13416. handedness: inputSource.handedness,
  13417. target: this
  13418. });
  13419. }
  13420. }
  13421. }
  13422. } else {
  13423. if (targetRay !== null) {
  13424. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  13425. if (inputPose !== null) {
  13426. targetRay.matrix.fromArray(inputPose.transform.matrix);
  13427. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  13428. }
  13429. }
  13430. if (grip !== null && inputSource.gripSpace) {
  13431. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  13432. if (gripPose !== null) {
  13433. grip.matrix.fromArray(gripPose.transform.matrix);
  13434. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  13435. }
  13436. }
  13437. }
  13438. }
  13439. if (targetRay !== null) {
  13440. targetRay.visible = inputPose !== null;
  13441. }
  13442. if (grip !== null) {
  13443. grip.visible = gripPose !== null;
  13444. }
  13445. if (hand !== null) {
  13446. hand.visible = handPose !== null;
  13447. }
  13448. return this;
  13449. }
  13450. });
  13451. function WebXRManager(renderer, gl) {
  13452. var scope = this;
  13453. var session = null;
  13454. var framebufferScaleFactor = 1.0;
  13455. var referenceSpace = null;
  13456. var referenceSpaceType = 'local-floor';
  13457. var pose = null;
  13458. var controllers = [];
  13459. var inputSourcesMap = new Map(); //
  13460. var cameraL = new PerspectiveCamera();
  13461. cameraL.layers.enable(1);
  13462. cameraL.viewport = new Vector4();
  13463. var cameraR = new PerspectiveCamera();
  13464. cameraR.layers.enable(2);
  13465. cameraR.viewport = new Vector4();
  13466. var cameras = [cameraL, cameraR];
  13467. var cameraVR = new ArrayCamera();
  13468. cameraVR.layers.enable(1);
  13469. cameraVR.layers.enable(2);
  13470. var _currentDepthNear = null;
  13471. var _currentDepthFar = null; //
  13472. this.enabled = false;
  13473. this.isPresenting = false;
  13474. this.getController = function (index) {
  13475. var controller = controllers[index];
  13476. if (controller === undefined) {
  13477. controller = new WebXRController();
  13478. controllers[index] = controller;
  13479. }
  13480. return controller.getTargetRaySpace();
  13481. };
  13482. this.getControllerGrip = function (index) {
  13483. var controller = controllers[index];
  13484. if (controller === undefined) {
  13485. controller = new WebXRController();
  13486. controllers[index] = controller;
  13487. }
  13488. return controller.getGripSpace();
  13489. };
  13490. this.getHand = function (index) {
  13491. var controller = controllers[index];
  13492. if (controller === undefined) {
  13493. controller = new WebXRController();
  13494. controllers[index] = controller;
  13495. }
  13496. return controller.getHandSpace();
  13497. }; //
  13498. function onSessionEvent(event) {
  13499. var controller = inputSourcesMap.get(event.inputSource);
  13500. if (controller) {
  13501. controller.dispatchEvent({
  13502. type: event.type,
  13503. data: event.inputSource
  13504. });
  13505. }
  13506. }
  13507. function onSessionEnd() {
  13508. inputSourcesMap.forEach(function (controller, inputSource) {
  13509. controller.disconnect(inputSource);
  13510. });
  13511. inputSourcesMap.clear(); //
  13512. renderer.setFramebuffer(null);
  13513. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  13514. animation.stop();
  13515. scope.isPresenting = false;
  13516. scope.dispatchEvent({
  13517. type: 'sessionend'
  13518. });
  13519. }
  13520. function onRequestReferenceSpace(value) {
  13521. referenceSpace = value;
  13522. animation.setContext(session);
  13523. animation.start();
  13524. scope.isPresenting = true;
  13525. scope.dispatchEvent({
  13526. type: 'sessionstart'
  13527. });
  13528. }
  13529. this.setFramebufferScaleFactor = function (value) {
  13530. framebufferScaleFactor = value;
  13531. if (scope.isPresenting === true) {
  13532. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  13533. }
  13534. };
  13535. this.setReferenceSpaceType = function (value) {
  13536. referenceSpaceType = value;
  13537. if (scope.isPresenting === true) {
  13538. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  13539. }
  13540. };
  13541. this.getReferenceSpace = function () {
  13542. return referenceSpace;
  13543. };
  13544. this.getSession = function () {
  13545. return session;
  13546. };
  13547. this.setSession = function (value) {
  13548. session = value;
  13549. if (session !== null) {
  13550. session.addEventListener('select', onSessionEvent);
  13551. session.addEventListener('selectstart', onSessionEvent);
  13552. session.addEventListener('selectend', onSessionEvent);
  13553. session.addEventListener('squeeze', onSessionEvent);
  13554. session.addEventListener('squeezestart', onSessionEvent);
  13555. session.addEventListener('squeezeend', onSessionEvent);
  13556. session.addEventListener('end', onSessionEnd);
  13557. var attributes = gl.getContextAttributes();
  13558. if (attributes.xrCompatible !== true) {
  13559. gl.makeXRCompatible();
  13560. }
  13561. var layerInit = {
  13562. antialias: attributes.antialias,
  13563. alpha: attributes.alpha,
  13564. depth: attributes.depth,
  13565. stencil: attributes.stencil,
  13566. framebufferScaleFactor: framebufferScaleFactor
  13567. }; // eslint-disable-next-line no-undef
  13568. var baseLayer = new XRWebGLLayer(session, gl, layerInit);
  13569. session.updateRenderState({
  13570. baseLayer: baseLayer
  13571. });
  13572. session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace); //
  13573. session.addEventListener('inputsourceschange', updateInputSources);
  13574. }
  13575. };
  13576. function updateInputSources(event) {
  13577. var inputSources = session.inputSources; // Assign inputSources to available controllers
  13578. for (var i = 0; i < controllers.length; i++) {
  13579. inputSourcesMap.set(inputSources[i], controllers[i]);
  13580. } // Notify disconnected
  13581. for (var _i = 0; _i < event.removed.length; _i++) {
  13582. var inputSource = event.removed[_i];
  13583. var controller = inputSourcesMap.get(inputSource);
  13584. if (controller) {
  13585. controller.dispatchEvent({
  13586. type: 'disconnected',
  13587. data: inputSource
  13588. });
  13589. inputSourcesMap.delete(inputSource);
  13590. }
  13591. } // Notify connected
  13592. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  13593. var _inputSource = event.added[_i2];
  13594. var _controller = inputSourcesMap.get(_inputSource);
  13595. if (_controller) {
  13596. _controller.dispatchEvent({
  13597. type: 'connected',
  13598. data: _inputSource
  13599. });
  13600. }
  13601. }
  13602. } //
  13603. var cameraLPos = new Vector3();
  13604. var cameraRPos = new Vector3();
  13605. /**
  13606. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13607. * the cameras' projection and world matrices have already been set.
  13608. * And that near and far planes are identical for both cameras.
  13609. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13610. */
  13611. function setProjectionFromUnion(camera, cameraL, cameraR) {
  13612. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  13613. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  13614. var ipd = cameraLPos.distanceTo(cameraRPos);
  13615. var projL = cameraL.projectionMatrix.elements;
  13616. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  13617. // most likely identical top and bottom frustum extents.
  13618. // Use the left camera for these values.
  13619. var near = projL[14] / (projL[10] - 1);
  13620. var far = projL[14] / (projL[10] + 1);
  13621. var topFov = (projL[9] + 1) / projL[5];
  13622. var bottomFov = (projL[9] - 1) / projL[5];
  13623. var leftFov = (projL[8] - 1) / projL[0];
  13624. var rightFov = (projR[8] + 1) / projR[0];
  13625. var left = near * leftFov;
  13626. var right = near * rightFov; // Calculate the new camera's position offset from the
  13627. // left camera. xOffset should be roughly half `ipd`.
  13628. var zOffset = ipd / (-leftFov + rightFov);
  13629. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  13630. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  13631. camera.translateX(xOffset);
  13632. camera.translateZ(zOffset);
  13633. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  13634. camera.matrixWorldInverse.getInverse(camera.matrixWorld); // Find the union of the frustum values of the cameras and scale
  13635. // the values so that the near plane's position does not change in world space,
  13636. // although must now be relative to the new union camera.
  13637. var near2 = near + zOffset;
  13638. var far2 = far + zOffset;
  13639. var left2 = left - xOffset;
  13640. var right2 = right + (ipd - xOffset);
  13641. var top2 = topFov * far / far2 * near2;
  13642. var bottom2 = bottomFov * far / far2 * near2;
  13643. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  13644. }
  13645. function updateCamera(camera, parent) {
  13646. if (parent === null) {
  13647. camera.matrixWorld.copy(camera.matrix);
  13648. } else {
  13649. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  13650. }
  13651. camera.matrixWorldInverse.getInverse(camera.matrixWorld);
  13652. }
  13653. this.getCamera = function (camera) {
  13654. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13655. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13656. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  13657. // Note that the new renderState won't apply until the next frame. See #18320
  13658. session.updateRenderState({
  13659. depthNear: cameraVR.near,
  13660. depthFar: cameraVR.far
  13661. });
  13662. _currentDepthNear = cameraVR.near;
  13663. _currentDepthFar = cameraVR.far;
  13664. }
  13665. var parent = camera.parent;
  13666. var cameras = cameraVR.cameras;
  13667. updateCamera(cameraVR, parent);
  13668. for (var i = 0; i < cameras.length; i++) {
  13669. updateCamera(cameras[i], parent);
  13670. } // update camera and its children
  13671. camera.matrixWorld.copy(cameraVR.matrixWorld);
  13672. var children = camera.children;
  13673. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  13674. children[_i3].updateMatrixWorld(true);
  13675. } // update projection matrix for proper view frustum culling
  13676. if (cameras.length === 2) {
  13677. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  13678. } else {
  13679. // assume single camera setup (AR)
  13680. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  13681. }
  13682. return cameraVR;
  13683. }; // Animation Loop
  13684. var onAnimationFrameCallback = null;
  13685. function onAnimationFrame(time, frame) {
  13686. pose = frame.getViewerPose(referenceSpace);
  13687. if (pose !== null) {
  13688. var views = pose.views;
  13689. var baseLayer = session.renderState.baseLayer;
  13690. renderer.setFramebuffer(baseLayer.framebuffer);
  13691. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  13692. if (views.length !== cameraVR.cameras.length) {
  13693. cameraVR.cameras.length = 0;
  13694. cameraVRNeedsUpdate = true;
  13695. }
  13696. for (var i = 0; i < views.length; i++) {
  13697. var view = views[i];
  13698. var viewport = baseLayer.getViewport(view);
  13699. var camera = cameras[i];
  13700. camera.matrix.fromArray(view.transform.matrix);
  13701. camera.projectionMatrix.fromArray(view.projectionMatrix);
  13702. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  13703. if (i === 0) {
  13704. cameraVR.matrix.copy(camera.matrix);
  13705. }
  13706. if (cameraVRNeedsUpdate === true) {
  13707. cameraVR.cameras.push(camera);
  13708. }
  13709. }
  13710. } //
  13711. var inputSources = session.inputSources;
  13712. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  13713. var controller = controllers[_i4];
  13714. var inputSource = inputSources[_i4];
  13715. controller.update(inputSource, frame, referenceSpace);
  13716. }
  13717. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  13718. }
  13719. var animation = new WebGLAnimation();
  13720. animation.setAnimationLoop(onAnimationFrame);
  13721. this.setAnimationLoop = function (callback) {
  13722. onAnimationFrameCallback = callback;
  13723. };
  13724. this.dispose = function () {};
  13725. }
  13726. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  13727. function WebGLMaterials(properties) {
  13728. function refreshFogUniforms(uniforms, fog) {
  13729. uniforms.fogColor.value.copy(fog.color);
  13730. if (fog.isFog) {
  13731. uniforms.fogNear.value = fog.near;
  13732. uniforms.fogFar.value = fog.far;
  13733. } else if (fog.isFogExp2) {
  13734. uniforms.fogDensity.value = fog.density;
  13735. }
  13736. }
  13737. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  13738. if (material.isMeshBasicMaterial) {
  13739. refreshUniformsCommon(uniforms, material);
  13740. } else if (material.isMeshLambertMaterial) {
  13741. refreshUniformsCommon(uniforms, material);
  13742. refreshUniformsLambert(uniforms, material);
  13743. } else if (material.isMeshToonMaterial) {
  13744. refreshUniformsCommon(uniforms, material);
  13745. refreshUniformsToon(uniforms, material);
  13746. } else if (material.isMeshPhongMaterial) {
  13747. refreshUniformsCommon(uniforms, material);
  13748. refreshUniformsPhong(uniforms, material);
  13749. } else if (material.isMeshStandardMaterial) {
  13750. refreshUniformsCommon(uniforms, material);
  13751. if (material.isMeshPhysicalMaterial) {
  13752. refreshUniformsPhysical(uniforms, material);
  13753. } else {
  13754. refreshUniformsStandard(uniforms, material);
  13755. }
  13756. } else if (material.isMeshMatcapMaterial) {
  13757. refreshUniformsCommon(uniforms, material);
  13758. refreshUniformsMatcap(uniforms, material);
  13759. } else if (material.isMeshDepthMaterial) {
  13760. refreshUniformsCommon(uniforms, material);
  13761. refreshUniformsDepth(uniforms, material);
  13762. } else if (material.isMeshDistanceMaterial) {
  13763. refreshUniformsCommon(uniforms, material);
  13764. refreshUniformsDistance(uniforms, material);
  13765. } else if (material.isMeshNormalMaterial) {
  13766. refreshUniformsCommon(uniforms, material);
  13767. refreshUniformsNormal(uniforms, material);
  13768. } else if (material.isLineBasicMaterial) {
  13769. refreshUniformsLine(uniforms, material);
  13770. if (material.isLineDashedMaterial) {
  13771. refreshUniformsDash(uniforms, material);
  13772. }
  13773. } else if (material.isPointsMaterial) {
  13774. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  13775. } else if (material.isSpriteMaterial) {
  13776. refreshUniformsSprites(uniforms, material);
  13777. } else if (material.isShadowMaterial) {
  13778. uniforms.color.value.copy(material.color);
  13779. uniforms.opacity.value = material.opacity;
  13780. } else if (material.isShaderMaterial) {
  13781. material.uniformsNeedUpdate = false; // #15581
  13782. }
  13783. }
  13784. function refreshUniformsCommon(uniforms, material) {
  13785. uniforms.opacity.value = material.opacity;
  13786. if (material.color) {
  13787. uniforms.diffuse.value.copy(material.color);
  13788. }
  13789. if (material.emissive) {
  13790. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  13791. }
  13792. if (material.map) {
  13793. uniforms.map.value = material.map;
  13794. }
  13795. if (material.alphaMap) {
  13796. uniforms.alphaMap.value = material.alphaMap;
  13797. }
  13798. if (material.specularMap) {
  13799. uniforms.specularMap.value = material.specularMap;
  13800. }
  13801. var envMap = properties.get(material).envMap;
  13802. if (envMap) {
  13803. uniforms.envMap.value = envMap;
  13804. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  13805. uniforms.reflectivity.value = material.reflectivity;
  13806. uniforms.refractionRatio.value = material.refractionRatio;
  13807. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  13808. if (maxMipLevel !== undefined) {
  13809. uniforms.maxMipLevel.value = maxMipLevel;
  13810. }
  13811. }
  13812. if (material.lightMap) {
  13813. uniforms.lightMap.value = material.lightMap;
  13814. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13815. }
  13816. if (material.aoMap) {
  13817. uniforms.aoMap.value = material.aoMap;
  13818. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13819. } // uv repeat and offset setting priorities
  13820. // 1. color map
  13821. // 2. specular map
  13822. // 3. displacementMap map
  13823. // 4. normal map
  13824. // 5. bump map
  13825. // 6. roughnessMap map
  13826. // 7. metalnessMap map
  13827. // 8. alphaMap map
  13828. // 9. emissiveMap map
  13829. // 10. clearcoat map
  13830. // 11. clearcoat normal map
  13831. // 12. clearcoat roughnessMap map
  13832. var uvScaleMap;
  13833. if (material.map) {
  13834. uvScaleMap = material.map;
  13835. } else if (material.specularMap) {
  13836. uvScaleMap = material.specularMap;
  13837. } else if (material.displacementMap) {
  13838. uvScaleMap = material.displacementMap;
  13839. } else if (material.normalMap) {
  13840. uvScaleMap = material.normalMap;
  13841. } else if (material.bumpMap) {
  13842. uvScaleMap = material.bumpMap;
  13843. } else if (material.roughnessMap) {
  13844. uvScaleMap = material.roughnessMap;
  13845. } else if (material.metalnessMap) {
  13846. uvScaleMap = material.metalnessMap;
  13847. } else if (material.alphaMap) {
  13848. uvScaleMap = material.alphaMap;
  13849. } else if (material.emissiveMap) {
  13850. uvScaleMap = material.emissiveMap;
  13851. } else if (material.clearcoatMap) {
  13852. uvScaleMap = material.clearcoatMap;
  13853. } else if (material.clearcoatNormalMap) {
  13854. uvScaleMap = material.clearcoatNormalMap;
  13855. } else if (material.clearcoatRoughnessMap) {
  13856. uvScaleMap = material.clearcoatRoughnessMap;
  13857. }
  13858. if (uvScaleMap !== undefined) {
  13859. // backwards compatibility
  13860. if (uvScaleMap.isWebGLRenderTarget) {
  13861. uvScaleMap = uvScaleMap.texture;
  13862. }
  13863. if (uvScaleMap.matrixAutoUpdate === true) {
  13864. uvScaleMap.updateMatrix();
  13865. }
  13866. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13867. } // uv repeat and offset setting priorities for uv2
  13868. // 1. ao map
  13869. // 2. light map
  13870. var uv2ScaleMap;
  13871. if (material.aoMap) {
  13872. uv2ScaleMap = material.aoMap;
  13873. } else if (material.lightMap) {
  13874. uv2ScaleMap = material.lightMap;
  13875. }
  13876. if (uv2ScaleMap !== undefined) {
  13877. // backwards compatibility
  13878. if (uv2ScaleMap.isWebGLRenderTarget) {
  13879. uv2ScaleMap = uv2ScaleMap.texture;
  13880. }
  13881. if (uv2ScaleMap.matrixAutoUpdate === true) {
  13882. uv2ScaleMap.updateMatrix();
  13883. }
  13884. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  13885. }
  13886. }
  13887. function refreshUniformsLine(uniforms, material) {
  13888. uniforms.diffuse.value.copy(material.color);
  13889. uniforms.opacity.value = material.opacity;
  13890. }
  13891. function refreshUniformsDash(uniforms, material) {
  13892. uniforms.dashSize.value = material.dashSize;
  13893. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13894. uniforms.scale.value = material.scale;
  13895. }
  13896. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  13897. uniforms.diffuse.value.copy(material.color);
  13898. uniforms.opacity.value = material.opacity;
  13899. uniforms.size.value = material.size * pixelRatio;
  13900. uniforms.scale.value = height * 0.5;
  13901. if (material.map) {
  13902. uniforms.map.value = material.map;
  13903. }
  13904. if (material.alphaMap) {
  13905. uniforms.alphaMap.value = material.alphaMap;
  13906. } // uv repeat and offset setting priorities
  13907. // 1. color map
  13908. // 2. alpha map
  13909. var uvScaleMap;
  13910. if (material.map) {
  13911. uvScaleMap = material.map;
  13912. } else if (material.alphaMap) {
  13913. uvScaleMap = material.alphaMap;
  13914. }
  13915. if (uvScaleMap !== undefined) {
  13916. if (uvScaleMap.matrixAutoUpdate === true) {
  13917. uvScaleMap.updateMatrix();
  13918. }
  13919. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13920. }
  13921. }
  13922. function refreshUniformsSprites(uniforms, material) {
  13923. uniforms.diffuse.value.copy(material.color);
  13924. uniforms.opacity.value = material.opacity;
  13925. uniforms.rotation.value = material.rotation;
  13926. if (material.map) {
  13927. uniforms.map.value = material.map;
  13928. }
  13929. if (material.alphaMap) {
  13930. uniforms.alphaMap.value = material.alphaMap;
  13931. } // uv repeat and offset setting priorities
  13932. // 1. color map
  13933. // 2. alpha map
  13934. var uvScaleMap;
  13935. if (material.map) {
  13936. uvScaleMap = material.map;
  13937. } else if (material.alphaMap) {
  13938. uvScaleMap = material.alphaMap;
  13939. }
  13940. if (uvScaleMap !== undefined) {
  13941. if (uvScaleMap.matrixAutoUpdate === true) {
  13942. uvScaleMap.updateMatrix();
  13943. }
  13944. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  13945. }
  13946. }
  13947. function refreshUniformsLambert(uniforms, material) {
  13948. if (material.emissiveMap) {
  13949. uniforms.emissiveMap.value = material.emissiveMap;
  13950. }
  13951. }
  13952. function refreshUniformsPhong(uniforms, material) {
  13953. uniforms.specular.value.copy(material.specular);
  13954. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  13955. if (material.emissiveMap) {
  13956. uniforms.emissiveMap.value = material.emissiveMap;
  13957. }
  13958. if (material.bumpMap) {
  13959. uniforms.bumpMap.value = material.bumpMap;
  13960. uniforms.bumpScale.value = material.bumpScale;
  13961. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13962. }
  13963. if (material.normalMap) {
  13964. uniforms.normalMap.value = material.normalMap;
  13965. uniforms.normalScale.value.copy(material.normalScale);
  13966. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13967. }
  13968. if (material.displacementMap) {
  13969. uniforms.displacementMap.value = material.displacementMap;
  13970. uniforms.displacementScale.value = material.displacementScale;
  13971. uniforms.displacementBias.value = material.displacementBias;
  13972. }
  13973. }
  13974. function refreshUniformsToon(uniforms, material) {
  13975. if (material.gradientMap) {
  13976. uniforms.gradientMap.value = material.gradientMap;
  13977. }
  13978. if (material.emissiveMap) {
  13979. uniforms.emissiveMap.value = material.emissiveMap;
  13980. }
  13981. if (material.bumpMap) {
  13982. uniforms.bumpMap.value = material.bumpMap;
  13983. uniforms.bumpScale.value = material.bumpScale;
  13984. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  13985. }
  13986. if (material.normalMap) {
  13987. uniforms.normalMap.value = material.normalMap;
  13988. uniforms.normalScale.value.copy(material.normalScale);
  13989. if (material.side === BackSide) uniforms.normalScale.value.negate();
  13990. }
  13991. if (material.displacementMap) {
  13992. uniforms.displacementMap.value = material.displacementMap;
  13993. uniforms.displacementScale.value = material.displacementScale;
  13994. uniforms.displacementBias.value = material.displacementBias;
  13995. }
  13996. }
  13997. function refreshUniformsStandard(uniforms, material) {
  13998. uniforms.roughness.value = material.roughness;
  13999. uniforms.metalness.value = material.metalness;
  14000. if (material.roughnessMap) {
  14001. uniforms.roughnessMap.value = material.roughnessMap;
  14002. }
  14003. if (material.metalnessMap) {
  14004. uniforms.metalnessMap.value = material.metalnessMap;
  14005. }
  14006. if (material.emissiveMap) {
  14007. uniforms.emissiveMap.value = material.emissiveMap;
  14008. }
  14009. if (material.bumpMap) {
  14010. uniforms.bumpMap.value = material.bumpMap;
  14011. uniforms.bumpScale.value = material.bumpScale;
  14012. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14013. }
  14014. if (material.normalMap) {
  14015. uniforms.normalMap.value = material.normalMap;
  14016. uniforms.normalScale.value.copy(material.normalScale);
  14017. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14018. }
  14019. if (material.displacementMap) {
  14020. uniforms.displacementMap.value = material.displacementMap;
  14021. uniforms.displacementScale.value = material.displacementScale;
  14022. uniforms.displacementBias.value = material.displacementBias;
  14023. }
  14024. var envMap = properties.get(material).envMap;
  14025. if (envMap) {
  14026. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14027. uniforms.envMapIntensity.value = material.envMapIntensity;
  14028. }
  14029. }
  14030. function refreshUniformsPhysical(uniforms, material) {
  14031. refreshUniformsStandard(uniforms, material);
  14032. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14033. uniforms.clearcoat.value = material.clearcoat;
  14034. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14035. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14036. if (material.clearcoatMap) {
  14037. uniforms.clearcoatMap.value = material.clearcoatMap;
  14038. }
  14039. if (material.clearcoatRoughnessMap) {
  14040. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14041. }
  14042. if (material.clearcoatNormalMap) {
  14043. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14044. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14045. if (material.side === BackSide) {
  14046. uniforms.clearcoatNormalScale.value.negate();
  14047. }
  14048. }
  14049. uniforms.transmission.value = material.transmission;
  14050. if (material.transmissionMap) {
  14051. uniforms.transmissionMap.value = material.transmissionMap;
  14052. }
  14053. }
  14054. function refreshUniformsMatcap(uniforms, material) {
  14055. if (material.matcap) {
  14056. uniforms.matcap.value = material.matcap;
  14057. }
  14058. if (material.bumpMap) {
  14059. uniforms.bumpMap.value = material.bumpMap;
  14060. uniforms.bumpScale.value = material.bumpScale;
  14061. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14062. }
  14063. if (material.normalMap) {
  14064. uniforms.normalMap.value = material.normalMap;
  14065. uniforms.normalScale.value.copy(material.normalScale);
  14066. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14067. }
  14068. if (material.displacementMap) {
  14069. uniforms.displacementMap.value = material.displacementMap;
  14070. uniforms.displacementScale.value = material.displacementScale;
  14071. uniforms.displacementBias.value = material.displacementBias;
  14072. }
  14073. }
  14074. function refreshUniformsDepth(uniforms, material) {
  14075. if (material.displacementMap) {
  14076. uniforms.displacementMap.value = material.displacementMap;
  14077. uniforms.displacementScale.value = material.displacementScale;
  14078. uniforms.displacementBias.value = material.displacementBias;
  14079. }
  14080. }
  14081. function refreshUniformsDistance(uniforms, material) {
  14082. if (material.displacementMap) {
  14083. uniforms.displacementMap.value = material.displacementMap;
  14084. uniforms.displacementScale.value = material.displacementScale;
  14085. uniforms.displacementBias.value = material.displacementBias;
  14086. }
  14087. uniforms.referencePosition.value.copy(material.referencePosition);
  14088. uniforms.nearDistance.value = material.nearDistance;
  14089. uniforms.farDistance.value = material.farDistance;
  14090. }
  14091. function refreshUniformsNormal(uniforms, material) {
  14092. if (material.bumpMap) {
  14093. uniforms.bumpMap.value = material.bumpMap;
  14094. uniforms.bumpScale.value = material.bumpScale;
  14095. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14096. }
  14097. if (material.normalMap) {
  14098. uniforms.normalMap.value = material.normalMap;
  14099. uniforms.normalScale.value.copy(material.normalScale);
  14100. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14101. }
  14102. if (material.displacementMap) {
  14103. uniforms.displacementMap.value = material.displacementMap;
  14104. uniforms.displacementScale.value = material.displacementScale;
  14105. uniforms.displacementBias.value = material.displacementBias;
  14106. }
  14107. }
  14108. return {
  14109. refreshFogUniforms: refreshFogUniforms,
  14110. refreshMaterialUniforms: refreshMaterialUniforms
  14111. };
  14112. }
  14113. function WebGLRenderer(parameters) {
  14114. parameters = parameters || {};
  14115. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'),
  14116. _context = parameters.context !== undefined ? parameters.context : null,
  14117. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14118. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14119. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14120. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14121. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14122. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14123. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14124. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14125. var currentRenderList = null;
  14126. var currentRenderState = null; // public properties
  14127. this.domElement = _canvas; // Debug configuration container
  14128. this.debug = {
  14129. /**
  14130. * Enables error checking and reporting when shader programs are being compiled
  14131. * @type {boolean}
  14132. */
  14133. checkShaderErrors: true
  14134. }; // clearing
  14135. this.autoClear = true;
  14136. this.autoClearColor = true;
  14137. this.autoClearDepth = true;
  14138. this.autoClearStencil = true; // scene graph
  14139. this.sortObjects = true; // user-defined clipping
  14140. this.clippingPlanes = [];
  14141. this.localClippingEnabled = false; // physically based shading
  14142. this.gammaFactor = 2.0; // for backwards compatibility
  14143. this.outputEncoding = LinearEncoding; // physical lights
  14144. this.physicallyCorrectLights = false; // tone mapping
  14145. this.toneMapping = NoToneMapping;
  14146. this.toneMappingExposure = 1.0; // morphs
  14147. this.maxMorphTargets = 8;
  14148. this.maxMorphNormals = 4; // internal properties
  14149. var _this = this;
  14150. var _isContextLost = false; // internal state cache
  14151. var _framebuffer = null;
  14152. var _currentActiveCubeFace = 0;
  14153. var _currentActiveMipmapLevel = 0;
  14154. var _currentRenderTarget = null;
  14155. var _currentFramebuffer = null;
  14156. var _currentMaterialId = -1;
  14157. var _currentCamera = null;
  14158. var _currentArrayCamera = null;
  14159. var _currentViewport = new Vector4();
  14160. var _currentScissor = new Vector4();
  14161. var _currentScissorTest = null; //
  14162. var _width = _canvas.width;
  14163. var _height = _canvas.height;
  14164. var _pixelRatio = 1;
  14165. var _opaqueSort = null;
  14166. var _transparentSort = null;
  14167. var _viewport = new Vector4(0, 0, _width, _height);
  14168. var _scissor = new Vector4(0, 0, _width, _height);
  14169. var _scissorTest = false; // frustum
  14170. var _frustum = new Frustum(); // clipping
  14171. var _clippingEnabled = false;
  14172. var _localClippingEnabled = false; // camera matrices cache
  14173. var _projScreenMatrix = new Matrix4();
  14174. var _vector3 = new Vector3();
  14175. var _emptyScene = {
  14176. background: null,
  14177. fog: null,
  14178. environment: null,
  14179. overrideMaterial: null,
  14180. isScene: true
  14181. };
  14182. function getTargetPixelRatio() {
  14183. return _currentRenderTarget === null ? _pixelRatio : 1;
  14184. } // initialize
  14185. var _gl = _context;
  14186. function getContext(contextNames, contextAttributes) {
  14187. for (var i = 0; i < contextNames.length; i++) {
  14188. var contextName = contextNames[i];
  14189. var context = _canvas.getContext(contextName, contextAttributes);
  14190. if (context !== null) return context;
  14191. }
  14192. return null;
  14193. }
  14194. try {
  14195. var contextAttributes = {
  14196. alpha: _alpha,
  14197. depth: _depth,
  14198. stencil: _stencil,
  14199. antialias: _antialias,
  14200. premultipliedAlpha: _premultipliedAlpha,
  14201. preserveDrawingBuffer: _preserveDrawingBuffer,
  14202. powerPreference: _powerPreference,
  14203. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14204. }; // event listeners must be registered before WebGL context is created, see #12753
  14205. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14206. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14207. if (_gl === null) {
  14208. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14209. if (_this.isWebGL1Renderer === true) {
  14210. contextNames.shift();
  14211. }
  14212. _gl = getContext(contextNames, contextAttributes);
  14213. if (_gl === null) {
  14214. if (getContext(contextNames)) {
  14215. throw new Error('Error creating WebGL context with your selected attributes.');
  14216. } else {
  14217. throw new Error('Error creating WebGL context.');
  14218. }
  14219. }
  14220. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14221. if (_gl.getShaderPrecisionFormat === undefined) {
  14222. _gl.getShaderPrecisionFormat = function () {
  14223. return {
  14224. 'rangeMin': 1,
  14225. 'rangeMax': 1,
  14226. 'precision': 1
  14227. };
  14228. };
  14229. }
  14230. } catch (error) {
  14231. console.error('THREE.WebGLRenderer: ' + error.message);
  14232. throw error;
  14233. }
  14234. var extensions, capabilities, state, info;
  14235. var properties, textures, cubemaps, attributes, geometries, objects;
  14236. var programCache, materials, renderLists, renderStates, clipping;
  14237. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14238. var utils, bindingStates;
  14239. function initGLContext() {
  14240. extensions = new WebGLExtensions(_gl);
  14241. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14242. if (capabilities.isWebGL2 === false) {
  14243. extensions.get('WEBGL_depth_texture');
  14244. extensions.get('OES_texture_float');
  14245. extensions.get('OES_texture_half_float');
  14246. extensions.get('OES_texture_half_float_linear');
  14247. extensions.get('OES_standard_derivatives');
  14248. extensions.get('OES_element_index_uint');
  14249. extensions.get('OES_vertex_array_object');
  14250. extensions.get('ANGLE_instanced_arrays');
  14251. }
  14252. extensions.get('OES_texture_float_linear');
  14253. utils = new WebGLUtils(_gl, extensions, capabilities);
  14254. state = new WebGLState(_gl, extensions, capabilities);
  14255. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14256. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14257. info = new WebGLInfo(_gl);
  14258. properties = new WebGLProperties();
  14259. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14260. cubemaps = new WebGLCubeMaps(_this);
  14261. attributes = new WebGLAttributes(_gl, capabilities);
  14262. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14263. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  14264. objects = new WebGLObjects(_gl, geometries, attributes, info);
  14265. morphtargets = new WebGLMorphtargets(_gl);
  14266. clipping = new WebGLClipping(properties);
  14267. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  14268. materials = new WebGLMaterials(properties);
  14269. renderLists = new WebGLRenderLists(properties);
  14270. renderStates = new WebGLRenderStates(extensions, capabilities);
  14271. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  14272. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  14273. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  14274. info.programs = programCache.programs;
  14275. _this.capabilities = capabilities;
  14276. _this.extensions = extensions;
  14277. _this.properties = properties;
  14278. _this.renderLists = renderLists;
  14279. _this.state = state;
  14280. _this.info = info;
  14281. }
  14282. initGLContext(); // xr
  14283. var xr = new WebXRManager(_this, _gl);
  14284. this.xr = xr; // shadow map
  14285. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  14286. this.shadowMap = shadowMap; // API
  14287. this.getContext = function () {
  14288. return _gl;
  14289. };
  14290. this.getContextAttributes = function () {
  14291. return _gl.getContextAttributes();
  14292. };
  14293. this.forceContextLoss = function () {
  14294. var extension = extensions.get('WEBGL_lose_context');
  14295. if (extension) extension.loseContext();
  14296. };
  14297. this.forceContextRestore = function () {
  14298. var extension = extensions.get('WEBGL_lose_context');
  14299. if (extension) extension.restoreContext();
  14300. };
  14301. this.getPixelRatio = function () {
  14302. return _pixelRatio;
  14303. };
  14304. this.setPixelRatio = function (value) {
  14305. if (value === undefined) return;
  14306. _pixelRatio = value;
  14307. this.setSize(_width, _height, false);
  14308. };
  14309. this.getSize = function (target) {
  14310. if (target === undefined) {
  14311. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  14312. target = new Vector2();
  14313. }
  14314. return target.set(_width, _height);
  14315. };
  14316. this.setSize = function (width, height, updateStyle) {
  14317. if (xr.isPresenting) {
  14318. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  14319. return;
  14320. }
  14321. _width = width;
  14322. _height = height;
  14323. _canvas.width = Math.floor(width * _pixelRatio);
  14324. _canvas.height = Math.floor(height * _pixelRatio);
  14325. if (updateStyle !== false) {
  14326. _canvas.style.width = width + 'px';
  14327. _canvas.style.height = height + 'px';
  14328. }
  14329. this.setViewport(0, 0, width, height);
  14330. };
  14331. this.getDrawingBufferSize = function (target) {
  14332. if (target === undefined) {
  14333. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  14334. target = new Vector2();
  14335. }
  14336. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  14337. };
  14338. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  14339. _width = width;
  14340. _height = height;
  14341. _pixelRatio = pixelRatio;
  14342. _canvas.width = Math.floor(width * pixelRatio);
  14343. _canvas.height = Math.floor(height * pixelRatio);
  14344. this.setViewport(0, 0, width, height);
  14345. };
  14346. this.getCurrentViewport = function (target) {
  14347. if (target === undefined) {
  14348. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  14349. target = new Vector4();
  14350. }
  14351. return target.copy(_currentViewport);
  14352. };
  14353. this.getViewport = function (target) {
  14354. return target.copy(_viewport);
  14355. };
  14356. this.setViewport = function (x, y, width, height) {
  14357. if (x.isVector4) {
  14358. _viewport.set(x.x, x.y, x.z, x.w);
  14359. } else {
  14360. _viewport.set(x, y, width, height);
  14361. }
  14362. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14363. };
  14364. this.getScissor = function (target) {
  14365. return target.copy(_scissor);
  14366. };
  14367. this.setScissor = function (x, y, width, height) {
  14368. if (x.isVector4) {
  14369. _scissor.set(x.x, x.y, x.z, x.w);
  14370. } else {
  14371. _scissor.set(x, y, width, height);
  14372. }
  14373. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14374. };
  14375. this.getScissorTest = function () {
  14376. return _scissorTest;
  14377. };
  14378. this.setScissorTest = function (boolean) {
  14379. state.setScissorTest(_scissorTest = boolean);
  14380. };
  14381. this.setOpaqueSort = function (method) {
  14382. _opaqueSort = method;
  14383. };
  14384. this.setTransparentSort = function (method) {
  14385. _transparentSort = method;
  14386. }; // Clearing
  14387. this.getClearColor = function () {
  14388. return background.getClearColor();
  14389. };
  14390. this.setClearColor = function () {
  14391. background.setClearColor.apply(background, arguments);
  14392. };
  14393. this.getClearAlpha = function () {
  14394. return background.getClearAlpha();
  14395. };
  14396. this.setClearAlpha = function () {
  14397. background.setClearAlpha.apply(background, arguments);
  14398. };
  14399. this.clear = function (color, depth, stencil) {
  14400. var bits = 0;
  14401. if (color === undefined || color) bits |= 16384;
  14402. if (depth === undefined || depth) bits |= 256;
  14403. if (stencil === undefined || stencil) bits |= 1024;
  14404. _gl.clear(bits);
  14405. };
  14406. this.clearColor = function () {
  14407. this.clear(true, false, false);
  14408. };
  14409. this.clearDepth = function () {
  14410. this.clear(false, true, false);
  14411. };
  14412. this.clearStencil = function () {
  14413. this.clear(false, false, true);
  14414. }; //
  14415. this.dispose = function () {
  14416. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  14417. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  14418. renderLists.dispose();
  14419. renderStates.dispose();
  14420. properties.dispose();
  14421. cubemaps.dispose();
  14422. objects.dispose();
  14423. bindingStates.dispose();
  14424. xr.dispose();
  14425. animation.stop();
  14426. }; // Events
  14427. function onContextLost(event) {
  14428. event.preventDefault();
  14429. console.log('THREE.WebGLRenderer: Context Lost.');
  14430. _isContextLost = true;
  14431. }
  14432. function onContextRestore()
  14433. /* event */
  14434. {
  14435. console.log('THREE.WebGLRenderer: Context Restored.');
  14436. _isContextLost = false;
  14437. initGLContext();
  14438. }
  14439. function onMaterialDispose(event) {
  14440. var material = event.target;
  14441. material.removeEventListener('dispose', onMaterialDispose);
  14442. deallocateMaterial(material);
  14443. } // Buffer deallocation
  14444. function deallocateMaterial(material) {
  14445. releaseMaterialProgramReference(material);
  14446. properties.remove(material);
  14447. }
  14448. function releaseMaterialProgramReference(material) {
  14449. var programInfo = properties.get(material).program;
  14450. if (programInfo !== undefined) {
  14451. programCache.releaseProgram(programInfo);
  14452. }
  14453. } // Buffer rendering
  14454. function renderObjectImmediate(object, program) {
  14455. object.render(function (object) {
  14456. _this.renderBufferImmediate(object, program);
  14457. });
  14458. }
  14459. this.renderBufferImmediate = function (object, program) {
  14460. bindingStates.initAttributes();
  14461. var buffers = properties.get(object);
  14462. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  14463. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  14464. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  14465. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  14466. var programAttributes = program.getAttributes();
  14467. if (object.hasPositions) {
  14468. _gl.bindBuffer(34962, buffers.position);
  14469. _gl.bufferData(34962, object.positionArray, 35048);
  14470. bindingStates.enableAttribute(programAttributes.position);
  14471. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  14472. }
  14473. if (object.hasNormals) {
  14474. _gl.bindBuffer(34962, buffers.normal);
  14475. _gl.bufferData(34962, object.normalArray, 35048);
  14476. bindingStates.enableAttribute(programAttributes.normal);
  14477. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  14478. }
  14479. if (object.hasUvs) {
  14480. _gl.bindBuffer(34962, buffers.uv);
  14481. _gl.bufferData(34962, object.uvArray, 35048);
  14482. bindingStates.enableAttribute(programAttributes.uv);
  14483. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  14484. }
  14485. if (object.hasColors) {
  14486. _gl.bindBuffer(34962, buffers.color);
  14487. _gl.bufferData(34962, object.colorArray, 35048);
  14488. bindingStates.enableAttribute(programAttributes.color);
  14489. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  14490. }
  14491. bindingStates.disableUnusedAttributes();
  14492. _gl.drawArrays(4, 0, object.count);
  14493. object.count = 0;
  14494. };
  14495. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  14496. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14497. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  14498. var program = setProgram(camera, scene, material, object);
  14499. state.setMaterial(material, frontFaceCW); //
  14500. var index = geometry.index;
  14501. var position = geometry.attributes.position; //
  14502. if (index === null) {
  14503. if (position === undefined || position.count === 0) return;
  14504. } else if (index.count === 0) {
  14505. return;
  14506. } //
  14507. var rangeFactor = 1;
  14508. if (material.wireframe === true) {
  14509. index = geometries.getWireframeAttribute(geometry);
  14510. rangeFactor = 2;
  14511. }
  14512. if (material.morphTargets || material.morphNormals) {
  14513. morphtargets.update(object, geometry, material, program);
  14514. }
  14515. bindingStates.setup(object, material, program, geometry, index);
  14516. var attribute;
  14517. var renderer = bufferRenderer;
  14518. if (index !== null) {
  14519. attribute = attributes.get(index);
  14520. renderer = indexedBufferRenderer;
  14521. renderer.setIndex(attribute);
  14522. } //
  14523. var dataCount = index !== null ? index.count : position.count;
  14524. var rangeStart = geometry.drawRange.start * rangeFactor;
  14525. var rangeCount = geometry.drawRange.count * rangeFactor;
  14526. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14527. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14528. var drawStart = Math.max(rangeStart, groupStart);
  14529. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  14530. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  14531. if (drawCount === 0) return; //
  14532. if (object.isMesh) {
  14533. if (material.wireframe === true) {
  14534. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  14535. renderer.setMode(1);
  14536. } else {
  14537. renderer.setMode(4);
  14538. }
  14539. } else if (object.isLine) {
  14540. var lineWidth = material.linewidth;
  14541. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  14542. state.setLineWidth(lineWidth * getTargetPixelRatio());
  14543. if (object.isLineSegments) {
  14544. renderer.setMode(1);
  14545. } else if (object.isLineLoop) {
  14546. renderer.setMode(2);
  14547. } else {
  14548. renderer.setMode(3);
  14549. }
  14550. } else if (object.isPoints) {
  14551. renderer.setMode(0);
  14552. } else if (object.isSprite) {
  14553. renderer.setMode(4);
  14554. }
  14555. if (object.isInstancedMesh) {
  14556. renderer.renderInstances(drawStart, drawCount, object.count);
  14557. } else if (geometry.isInstancedBufferGeometry) {
  14558. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  14559. renderer.renderInstances(drawStart, drawCount, instanceCount);
  14560. } else {
  14561. renderer.render(drawStart, drawCount);
  14562. }
  14563. }; // Compile
  14564. this.compile = function (scene, camera) {
  14565. currentRenderState = renderStates.get(scene, camera);
  14566. currentRenderState.init();
  14567. scene.traverseVisible(function (object) {
  14568. if (object.isLight && object.layers.test(camera.layers)) {
  14569. currentRenderState.pushLight(object);
  14570. if (object.castShadow) {
  14571. currentRenderState.pushShadow(object);
  14572. }
  14573. }
  14574. });
  14575. currentRenderState.setupLights(camera);
  14576. var compiled = new WeakMap();
  14577. scene.traverse(function (object) {
  14578. var material = object.material;
  14579. if (material) {
  14580. if (Array.isArray(material)) {
  14581. for (var i = 0; i < material.length; i++) {
  14582. var material2 = material[i];
  14583. if (compiled.has(material2) === false) {
  14584. initMaterial(material2, scene, object);
  14585. compiled.set(material2);
  14586. }
  14587. }
  14588. } else if (compiled.has(material) === false) {
  14589. initMaterial(material, scene, object);
  14590. compiled.set(material);
  14591. }
  14592. }
  14593. });
  14594. }; // Animation Loop
  14595. var onAnimationFrameCallback = null;
  14596. function onAnimationFrame(time) {
  14597. if (xr.isPresenting) return;
  14598. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  14599. }
  14600. var animation = new WebGLAnimation();
  14601. animation.setAnimationLoop(onAnimationFrame);
  14602. if (typeof window !== 'undefined') animation.setContext(window);
  14603. this.setAnimationLoop = function (callback) {
  14604. onAnimationFrameCallback = callback;
  14605. xr.setAnimationLoop(callback);
  14606. callback === null ? animation.stop() : animation.start();
  14607. }; // Rendering
  14608. this.render = function (scene, camera) {
  14609. var renderTarget, forceClear;
  14610. if (arguments[2] !== undefined) {
  14611. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  14612. renderTarget = arguments[2];
  14613. }
  14614. if (arguments[3] !== undefined) {
  14615. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  14616. forceClear = arguments[3];
  14617. }
  14618. if (camera !== undefined && camera.isCamera !== true) {
  14619. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  14620. return;
  14621. }
  14622. if (_isContextLost === true) return; // reset caching for this frame
  14623. bindingStates.resetDefaultState();
  14624. _currentMaterialId = -1;
  14625. _currentCamera = null; // update scene graph
  14626. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  14627. if (camera.parent === null) camera.updateMatrixWorld();
  14628. if (xr.enabled === true && xr.isPresenting === true) {
  14629. camera = xr.getCamera(camera);
  14630. } //
  14631. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  14632. currentRenderState = renderStates.get(scene, camera);
  14633. currentRenderState.init();
  14634. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  14635. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  14636. _localClippingEnabled = this.localClippingEnabled;
  14637. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  14638. currentRenderList = renderLists.get(scene, camera);
  14639. currentRenderList.init();
  14640. projectObject(scene, camera, 0, _this.sortObjects);
  14641. currentRenderList.finish();
  14642. if (_this.sortObjects === true) {
  14643. currentRenderList.sort(_opaqueSort, _transparentSort);
  14644. } //
  14645. if (_clippingEnabled === true) clipping.beginShadows();
  14646. var shadowsArray = currentRenderState.state.shadowsArray;
  14647. shadowMap.render(shadowsArray, scene, camera);
  14648. currentRenderState.setupLights(camera);
  14649. if (_clippingEnabled === true) clipping.endShadows(); //
  14650. if (this.info.autoReset === true) this.info.reset();
  14651. if (renderTarget !== undefined) {
  14652. this.setRenderTarget(renderTarget);
  14653. } //
  14654. background.render(currentRenderList, scene, camera, forceClear); // render scene
  14655. var opaqueObjects = currentRenderList.opaque;
  14656. var transparentObjects = currentRenderList.transparent;
  14657. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  14658. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  14659. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  14660. if (_currentRenderTarget !== null) {
  14661. // Generate mipmap if we're using any kind of mipmap filtering
  14662. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  14663. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  14664. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  14665. state.buffers.depth.setTest(true);
  14666. state.buffers.depth.setMask(true);
  14667. state.buffers.color.setMask(true);
  14668. state.setPolygonOffset(false); // _gl.finish();
  14669. currentRenderList = null;
  14670. currentRenderState = null;
  14671. };
  14672. function projectObject(object, camera, groupOrder, sortObjects) {
  14673. if (object.visible === false) return;
  14674. var visible = object.layers.test(camera.layers);
  14675. if (visible) {
  14676. if (object.isGroup) {
  14677. groupOrder = object.renderOrder;
  14678. } else if (object.isLOD) {
  14679. if (object.autoUpdate === true) object.update(camera);
  14680. } else if (object.isLight) {
  14681. currentRenderState.pushLight(object);
  14682. if (object.castShadow) {
  14683. currentRenderState.pushShadow(object);
  14684. }
  14685. } else if (object.isSprite) {
  14686. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  14687. if (sortObjects) {
  14688. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14689. }
  14690. var geometry = objects.update(object);
  14691. var material = object.material;
  14692. if (material.visible) {
  14693. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  14694. }
  14695. }
  14696. } else if (object.isImmediateRenderObject) {
  14697. if (sortObjects) {
  14698. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14699. }
  14700. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  14701. } else if (object.isMesh || object.isLine || object.isPoints) {
  14702. if (object.isSkinnedMesh) {
  14703. // update skeleton only once in a frame
  14704. if (object.skeleton.frame !== info.render.frame) {
  14705. object.skeleton.update();
  14706. object.skeleton.frame = info.render.frame;
  14707. }
  14708. }
  14709. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  14710. if (sortObjects) {
  14711. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  14712. }
  14713. var _geometry = objects.update(object);
  14714. var _material = object.material;
  14715. if (Array.isArray(_material)) {
  14716. var groups = _geometry.groups;
  14717. for (var i = 0, l = groups.length; i < l; i++) {
  14718. var group = groups[i];
  14719. var groupMaterial = _material[group.materialIndex];
  14720. if (groupMaterial && groupMaterial.visible) {
  14721. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  14722. }
  14723. }
  14724. } else if (_material.visible) {
  14725. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  14726. }
  14727. }
  14728. }
  14729. }
  14730. var children = object.children;
  14731. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  14732. projectObject(children[_i], camera, groupOrder, sortObjects);
  14733. }
  14734. }
  14735. function renderObjects(renderList, scene, camera) {
  14736. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14737. for (var i = 0, l = renderList.length; i < l; i++) {
  14738. var renderItem = renderList[i];
  14739. var object = renderItem.object;
  14740. var geometry = renderItem.geometry;
  14741. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14742. var group = renderItem.group;
  14743. if (camera.isArrayCamera) {
  14744. _currentArrayCamera = camera;
  14745. var cameras = camera.cameras;
  14746. for (var j = 0, jl = cameras.length; j < jl; j++) {
  14747. var camera2 = cameras[j];
  14748. if (object.layers.test(camera2.layers)) {
  14749. state.viewport(_currentViewport.copy(camera2.viewport));
  14750. currentRenderState.setupLights(camera2);
  14751. renderObject(object, scene, camera2, geometry, material, group);
  14752. }
  14753. }
  14754. } else {
  14755. _currentArrayCamera = null;
  14756. renderObject(object, scene, camera, geometry, material, group);
  14757. }
  14758. }
  14759. }
  14760. function renderObject(object, scene, camera, geometry, material, group) {
  14761. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  14762. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14763. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  14764. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  14765. if (object.isImmediateRenderObject) {
  14766. var program = setProgram(camera, scene, material, object);
  14767. state.setMaterial(material);
  14768. bindingStates.reset();
  14769. renderObjectImmediate(object, program);
  14770. } else {
  14771. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  14772. }
  14773. object.onAfterRender(_this, scene, camera, geometry, material, group);
  14774. currentRenderState = renderStates.get(scene, _currentArrayCamera || camera);
  14775. }
  14776. function initMaterial(material, scene, object) {
  14777. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14778. var materialProperties = properties.get(material);
  14779. var lights = currentRenderState.state.lights;
  14780. var shadowsArray = currentRenderState.state.shadowsArray;
  14781. var lightsStateVersion = lights.state.version;
  14782. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  14783. var programCacheKey = programCache.getProgramCacheKey(parameters);
  14784. var program = materialProperties.program;
  14785. var programChange = true;
  14786. if (program === undefined) {
  14787. // new material
  14788. material.addEventListener('dispose', onMaterialDispose);
  14789. } else if (program.cacheKey !== programCacheKey) {
  14790. // changed glsl or parameters
  14791. releaseMaterialProgramReference(material);
  14792. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  14793. programChange = false;
  14794. } else if (parameters.shaderID !== undefined) {
  14795. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14796. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14797. materialProperties.envMap = cubemaps.get(material.envMap || environment);
  14798. return;
  14799. } else {
  14800. // only rebuild uniform list
  14801. programChange = false;
  14802. }
  14803. if (programChange) {
  14804. parameters.uniforms = programCache.getUniforms(material);
  14805. material.onBeforeCompile(parameters, _this);
  14806. program = programCache.acquireProgram(parameters, programCacheKey);
  14807. materialProperties.program = program;
  14808. materialProperties.uniforms = parameters.uniforms;
  14809. materialProperties.outputEncoding = parameters.outputEncoding;
  14810. }
  14811. var uniforms = materialProperties.uniforms;
  14812. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  14813. materialProperties.numClippingPlanes = clipping.numPlanes;
  14814. materialProperties.numIntersection = clipping.numIntersection;
  14815. uniforms.clippingPlanes = clipping.uniform;
  14816. }
  14817. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14818. materialProperties.fog = scene.fog;
  14819. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment); // store the light setup it was created for
  14820. materialProperties.needsLights = materialNeedsLights(material);
  14821. materialProperties.lightsStateVersion = lightsStateVersion;
  14822. if (materialProperties.needsLights) {
  14823. // wire up the material to this renderer's lighting state
  14824. uniforms.ambientLightColor.value = lights.state.ambient;
  14825. uniforms.lightProbe.value = lights.state.probe;
  14826. uniforms.directionalLights.value = lights.state.directional;
  14827. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14828. uniforms.spotLights.value = lights.state.spot;
  14829. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14830. uniforms.rectAreaLights.value = lights.state.rectArea;
  14831. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14832. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14833. uniforms.pointLights.value = lights.state.point;
  14834. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14835. uniforms.hemisphereLights.value = lights.state.hemi;
  14836. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14837. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14838. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14839. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14840. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14841. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  14842. }
  14843. var progUniforms = materialProperties.program.getUniforms();
  14844. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  14845. materialProperties.uniformsList = uniformsList;
  14846. }
  14847. function setProgram(camera, scene, material, object) {
  14848. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14849. textures.resetTextureUnits();
  14850. var fog = scene.fog;
  14851. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  14852. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14853. var envMap = cubemaps.get(material.envMap || environment);
  14854. var materialProperties = properties.get(material);
  14855. var lights = currentRenderState.state.lights;
  14856. if (_clippingEnabled === true) {
  14857. if (_localClippingEnabled === true || camera !== _currentCamera) {
  14858. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  14859. // object instead of the material, once it becomes feasible
  14860. // (#8465, #8379)
  14861. clipping.setState(material, camera, useCache);
  14862. }
  14863. }
  14864. if (material.version === materialProperties.__version) {
  14865. if (material.fog && materialProperties.fog !== fog) {
  14866. initMaterial(material, scene, object);
  14867. } else if (materialProperties.environment !== environment) {
  14868. initMaterial(material, scene, object);
  14869. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  14870. initMaterial(material, scene, object);
  14871. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  14872. initMaterial(material, scene, object);
  14873. } else if (materialProperties.outputEncoding !== encoding) {
  14874. initMaterial(material, scene, object);
  14875. } else if (materialProperties.envMap !== envMap) {
  14876. initMaterial(material, scene, object);
  14877. }
  14878. } else {
  14879. initMaterial(material, scene, object);
  14880. materialProperties.__version = material.version;
  14881. }
  14882. var refreshProgram = false;
  14883. var refreshMaterial = false;
  14884. var refreshLights = false;
  14885. var program = materialProperties.program,
  14886. p_uniforms = program.getUniforms(),
  14887. m_uniforms = materialProperties.uniforms;
  14888. if (state.useProgram(program.program)) {
  14889. refreshProgram = true;
  14890. refreshMaterial = true;
  14891. refreshLights = true;
  14892. }
  14893. if (material.id !== _currentMaterialId) {
  14894. _currentMaterialId = material.id;
  14895. refreshMaterial = true;
  14896. }
  14897. if (refreshProgram || _currentCamera !== camera) {
  14898. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  14899. if (capabilities.logarithmicDepthBuffer) {
  14900. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  14901. }
  14902. if (_currentCamera !== camera) {
  14903. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  14904. // now, in case this material supports lights - or later, when
  14905. // the next material that does gets activated:
  14906. refreshMaterial = true; // set to true on material change
  14907. refreshLights = true; // remains set until update done
  14908. } // load material specific uniforms
  14909. // (shader material also gets them for the sake of genericity)
  14910. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  14911. var uCamPos = p_uniforms.map.cameraPosition;
  14912. if (uCamPos !== undefined) {
  14913. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  14914. }
  14915. }
  14916. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  14917. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  14918. }
  14919. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  14920. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  14921. }
  14922. } // skinning uniforms must be set even if material didn't change
  14923. // auto-setting of texture unit for bone texture must go before other textures
  14924. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14925. if (material.skinning) {
  14926. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  14927. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  14928. var skeleton = object.skeleton;
  14929. if (skeleton) {
  14930. var bones = skeleton.bones;
  14931. if (capabilities.floatVertexTextures) {
  14932. if (skeleton.boneTexture === undefined) {
  14933. // layout (1 matrix = 4 pixels)
  14934. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14935. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14936. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14937. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14938. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14939. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  14940. size = MathUtils.ceilPowerOfTwo(size);
  14941. size = Math.max(size, 4);
  14942. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  14943. boneMatrices.set(skeleton.boneMatrices); // copy current values
  14944. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  14945. skeleton.boneMatrices = boneMatrices;
  14946. skeleton.boneTexture = boneTexture;
  14947. skeleton.boneTextureSize = size;
  14948. }
  14949. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  14950. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  14951. } else {
  14952. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  14953. }
  14954. }
  14955. }
  14956. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  14957. materialProperties.receiveShadow = object.receiveShadow;
  14958. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  14959. }
  14960. if (refreshMaterial) {
  14961. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  14962. if (materialProperties.needsLights) {
  14963. // the current material requires lighting info
  14964. // note: all lighting uniforms are always set correctly
  14965. // they simply reference the renderer's state for their
  14966. // values
  14967. //
  14968. // use the current material's .needsUpdate flags to set
  14969. // the GL state when required
  14970. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  14971. } // refresh uniforms common to several materials
  14972. if (fog && material.fog) {
  14973. materials.refreshFogUniforms(m_uniforms, fog);
  14974. }
  14975. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  14976. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14977. }
  14978. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  14979. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  14980. material.uniformsNeedUpdate = false;
  14981. }
  14982. if (material.isSpriteMaterial) {
  14983. p_uniforms.setValue(_gl, 'center', object.center);
  14984. } // common matrices
  14985. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  14986. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  14987. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  14988. return program;
  14989. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14990. function markUniformsLightsNeedsUpdate(uniforms, value) {
  14991. uniforms.ambientLightColor.needsUpdate = value;
  14992. uniforms.lightProbe.needsUpdate = value;
  14993. uniforms.directionalLights.needsUpdate = value;
  14994. uniforms.directionalLightShadows.needsUpdate = value;
  14995. uniforms.pointLights.needsUpdate = value;
  14996. uniforms.pointLightShadows.needsUpdate = value;
  14997. uniforms.spotLights.needsUpdate = value;
  14998. uniforms.spotLightShadows.needsUpdate = value;
  14999. uniforms.rectAreaLights.needsUpdate = value;
  15000. uniforms.hemisphereLights.needsUpdate = value;
  15001. }
  15002. function materialNeedsLights(material) {
  15003. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15004. } //
  15005. this.setFramebuffer = function (value) {
  15006. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15007. _framebuffer = value;
  15008. };
  15009. this.getActiveCubeFace = function () {
  15010. return _currentActiveCubeFace;
  15011. };
  15012. this.getActiveMipmapLevel = function () {
  15013. return _currentActiveMipmapLevel;
  15014. };
  15015. this.getRenderList = function () {
  15016. return currentRenderList;
  15017. };
  15018. this.setRenderList = function (renderList) {
  15019. currentRenderList = renderList;
  15020. };
  15021. this.getRenderState = function () {
  15022. return currentRenderState;
  15023. };
  15024. this.setRenderState = function (renderState) {
  15025. currentRenderState = renderState;
  15026. };
  15027. this.getRenderTarget = function () {
  15028. return _currentRenderTarget;
  15029. };
  15030. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15031. if (activeCubeFace === void 0) {
  15032. activeCubeFace = 0;
  15033. }
  15034. if (activeMipmapLevel === void 0) {
  15035. activeMipmapLevel = 0;
  15036. }
  15037. _currentRenderTarget = renderTarget;
  15038. _currentActiveCubeFace = activeCubeFace;
  15039. _currentActiveMipmapLevel = activeMipmapLevel;
  15040. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15041. textures.setupRenderTarget(renderTarget);
  15042. }
  15043. var framebuffer = _framebuffer;
  15044. var isCube = false;
  15045. if (renderTarget) {
  15046. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15047. if (renderTarget.isWebGLCubeRenderTarget) {
  15048. framebuffer = __webglFramebuffer[activeCubeFace];
  15049. isCube = true;
  15050. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15051. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15052. } else {
  15053. framebuffer = __webglFramebuffer;
  15054. }
  15055. _currentViewport.copy(renderTarget.viewport);
  15056. _currentScissor.copy(renderTarget.scissor);
  15057. _currentScissorTest = renderTarget.scissorTest;
  15058. } else {
  15059. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15060. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15061. _currentScissorTest = _scissorTest;
  15062. }
  15063. if (_currentFramebuffer !== framebuffer) {
  15064. _gl.bindFramebuffer(36160, framebuffer);
  15065. _currentFramebuffer = framebuffer;
  15066. }
  15067. state.viewport(_currentViewport);
  15068. state.scissor(_currentScissor);
  15069. state.setScissorTest(_currentScissorTest);
  15070. if (isCube) {
  15071. var textureProperties = properties.get(renderTarget.texture);
  15072. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15073. }
  15074. };
  15075. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15076. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15077. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15078. return;
  15079. }
  15080. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15081. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15082. framebuffer = framebuffer[activeCubeFaceIndex];
  15083. }
  15084. if (framebuffer) {
  15085. var restore = false;
  15086. if (framebuffer !== _currentFramebuffer) {
  15087. _gl.bindFramebuffer(36160, framebuffer);
  15088. restore = true;
  15089. }
  15090. try {
  15091. var texture = renderTarget.texture;
  15092. var textureFormat = texture.format;
  15093. var textureType = texture.type;
  15094. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15095. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15096. return;
  15097. }
  15098. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15099. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.get('OES_texture_float') || extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15100. !(textureType === HalfFloatType && (capabilities.isWebGL2 ? extensions.get('EXT_color_buffer_float') : extensions.get('EXT_color_buffer_half_float')))) {
  15101. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15102. return;
  15103. }
  15104. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15105. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15106. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15107. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15108. }
  15109. } else {
  15110. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15111. }
  15112. } finally {
  15113. if (restore) {
  15114. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15115. }
  15116. }
  15117. }
  15118. };
  15119. this.copyFramebufferToTexture = function (position, texture, level) {
  15120. if (level === undefined) level = 0;
  15121. var levelScale = Math.pow(2, -level);
  15122. var width = Math.floor(texture.image.width * levelScale);
  15123. var height = Math.floor(texture.image.height * levelScale);
  15124. var glFormat = utils.convert(texture.format);
  15125. textures.setTexture2D(texture, 0);
  15126. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15127. state.unbindTexture();
  15128. };
  15129. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15130. if (level === undefined) level = 0;
  15131. var width = srcTexture.image.width;
  15132. var height = srcTexture.image.height;
  15133. var glFormat = utils.convert(dstTexture.format);
  15134. var glType = utils.convert(dstTexture.type);
  15135. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15136. // parameters, make sure they are correct for the dstTexture
  15137. _gl.pixelStorei(37440, dstTexture.flipY);
  15138. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15139. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15140. if (srcTexture.isDataTexture) {
  15141. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15142. } else {
  15143. if (srcTexture.isCompressedTexture) {
  15144. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15145. } else {
  15146. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15147. }
  15148. } // Generate mipmaps only when copying level 0
  15149. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15150. state.unbindTexture();
  15151. };
  15152. this.initTexture = function (texture) {
  15153. textures.setTexture2D(texture, 0);
  15154. state.unbindTexture();
  15155. };
  15156. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15157. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15158. detail: this
  15159. })); // eslint-disable-line no-undef
  15160. }
  15161. }
  15162. function WebGL1Renderer(parameters) {
  15163. WebGLRenderer.call(this, parameters);
  15164. }
  15165. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15166. constructor: WebGL1Renderer,
  15167. isWebGL1Renderer: true
  15168. });
  15169. var FogExp2 = /*#__PURE__*/function () {
  15170. function FogExp2(color, density) {
  15171. Object.defineProperty(this, 'isFogExp2', {
  15172. value: true
  15173. });
  15174. this.name = '';
  15175. this.color = new Color(color);
  15176. this.density = density !== undefined ? density : 0.00025;
  15177. }
  15178. var _proto = FogExp2.prototype;
  15179. _proto.clone = function clone() {
  15180. return new FogExp2(this.color, this.density);
  15181. };
  15182. _proto.toJSON = function toJSON()
  15183. /* meta */
  15184. {
  15185. return {
  15186. type: 'FogExp2',
  15187. color: this.color.getHex(),
  15188. density: this.density
  15189. };
  15190. };
  15191. return FogExp2;
  15192. }();
  15193. var Fog = /*#__PURE__*/function () {
  15194. function Fog(color, near, far) {
  15195. Object.defineProperty(this, 'isFog', {
  15196. value: true
  15197. });
  15198. this.name = '';
  15199. this.color = new Color(color);
  15200. this.near = near !== undefined ? near : 1;
  15201. this.far = far !== undefined ? far : 1000;
  15202. }
  15203. var _proto = Fog.prototype;
  15204. _proto.clone = function clone() {
  15205. return new Fog(this.color, this.near, this.far);
  15206. };
  15207. _proto.toJSON = function toJSON()
  15208. /* meta */
  15209. {
  15210. return {
  15211. type: 'Fog',
  15212. color: this.color.getHex(),
  15213. near: this.near,
  15214. far: this.far
  15215. };
  15216. };
  15217. return Fog;
  15218. }();
  15219. var Scene = /*#__PURE__*/function (_Object3D) {
  15220. _inheritsLoose(Scene, _Object3D);
  15221. function Scene() {
  15222. var _this;
  15223. _this = _Object3D.call(this) || this;
  15224. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15225. value: true
  15226. });
  15227. _this.type = 'Scene';
  15228. _this.background = null;
  15229. _this.environment = null;
  15230. _this.fog = null;
  15231. _this.overrideMaterial = null;
  15232. _this.autoUpdate = true; // checked by the renderer
  15233. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15234. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15235. detail: _assertThisInitialized(_this)
  15236. })); // eslint-disable-line no-undef
  15237. }
  15238. return _this;
  15239. }
  15240. var _proto = Scene.prototype;
  15241. _proto.copy = function copy(source, recursive) {
  15242. _Object3D.prototype.copy.call(this, source, recursive);
  15243. if (source.background !== null) this.background = source.background.clone();
  15244. if (source.environment !== null) this.environment = source.environment.clone();
  15245. if (source.fog !== null) this.fog = source.fog.clone();
  15246. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15247. this.autoUpdate = source.autoUpdate;
  15248. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15249. return this;
  15250. };
  15251. _proto.toJSON = function toJSON(meta) {
  15252. var data = _Object3D.prototype.toJSON.call(this, meta);
  15253. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15254. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15255. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  15256. return data;
  15257. };
  15258. return Scene;
  15259. }(Object3D);
  15260. function InterleavedBuffer(array, stride) {
  15261. this.array = array;
  15262. this.stride = stride;
  15263. this.count = array !== undefined ? array.length / stride : 0;
  15264. this.usage = StaticDrawUsage;
  15265. this.updateRange = {
  15266. offset: 0,
  15267. count: -1
  15268. };
  15269. this.version = 0;
  15270. this.uuid = MathUtils.generateUUID();
  15271. }
  15272. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  15273. set: function set(value) {
  15274. if (value === true) this.version++;
  15275. }
  15276. });
  15277. Object.assign(InterleavedBuffer.prototype, {
  15278. isInterleavedBuffer: true,
  15279. onUploadCallback: function onUploadCallback() {},
  15280. setUsage: function setUsage(value) {
  15281. this.usage = value;
  15282. return this;
  15283. },
  15284. copy: function copy(source) {
  15285. this.array = new source.array.constructor(source.array);
  15286. this.count = source.count;
  15287. this.stride = source.stride;
  15288. this.usage = source.usage;
  15289. return this;
  15290. },
  15291. copyAt: function copyAt(index1, attribute, index2) {
  15292. index1 *= this.stride;
  15293. index2 *= attribute.stride;
  15294. for (var i = 0, l = this.stride; i < l; i++) {
  15295. this.array[index1 + i] = attribute.array[index2 + i];
  15296. }
  15297. return this;
  15298. },
  15299. set: function set(value, offset) {
  15300. if (offset === undefined) offset = 0;
  15301. this.array.set(value, offset);
  15302. return this;
  15303. },
  15304. clone: function clone(data) {
  15305. if (data.arrayBuffers === undefined) {
  15306. data.arrayBuffers = {};
  15307. }
  15308. if (this.array.buffer._uuid === undefined) {
  15309. this.array.buffer._uuid = MathUtils.generateUUID();
  15310. }
  15311. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15312. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  15313. }
  15314. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  15315. var ib = new InterleavedBuffer(array, this.stride);
  15316. ib.setUsage(this.usage);
  15317. return ib;
  15318. },
  15319. onUpload: function onUpload(callback) {
  15320. this.onUploadCallback = callback;
  15321. return this;
  15322. },
  15323. toJSON: function toJSON(data) {
  15324. if (data.arrayBuffers === undefined) {
  15325. data.arrayBuffers = {};
  15326. } // generate UUID for array buffer if necessary
  15327. if (this.array.buffer._uuid === undefined) {
  15328. this.array.buffer._uuid = MathUtils.generateUUID();
  15329. }
  15330. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  15331. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  15332. } //
  15333. return {
  15334. uuid: this.uuid,
  15335. buffer: this.array.buffer._uuid,
  15336. type: this.array.constructor.name,
  15337. stride: this.stride
  15338. };
  15339. }
  15340. });
  15341. var _vector$6 = new Vector3();
  15342. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  15343. this.name = '';
  15344. this.data = interleavedBuffer;
  15345. this.itemSize = itemSize;
  15346. this.offset = offset;
  15347. this.normalized = normalized === true;
  15348. }
  15349. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  15350. count: {
  15351. get: function get() {
  15352. return this.data.count;
  15353. }
  15354. },
  15355. array: {
  15356. get: function get() {
  15357. return this.data.array;
  15358. }
  15359. },
  15360. needsUpdate: {
  15361. set: function set(value) {
  15362. this.data.needsUpdate = value;
  15363. }
  15364. }
  15365. });
  15366. Object.assign(InterleavedBufferAttribute.prototype, {
  15367. isInterleavedBufferAttribute: true,
  15368. applyMatrix4: function applyMatrix4(m) {
  15369. for (var i = 0, l = this.data.count; i < l; i++) {
  15370. _vector$6.x = this.getX(i);
  15371. _vector$6.y = this.getY(i);
  15372. _vector$6.z = this.getZ(i);
  15373. _vector$6.applyMatrix4(m);
  15374. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  15375. }
  15376. return this;
  15377. },
  15378. setX: function setX(index, x) {
  15379. this.data.array[index * this.data.stride + this.offset] = x;
  15380. return this;
  15381. },
  15382. setY: function setY(index, y) {
  15383. this.data.array[index * this.data.stride + this.offset + 1] = y;
  15384. return this;
  15385. },
  15386. setZ: function setZ(index, z) {
  15387. this.data.array[index * this.data.stride + this.offset + 2] = z;
  15388. return this;
  15389. },
  15390. setW: function setW(index, w) {
  15391. this.data.array[index * this.data.stride + this.offset + 3] = w;
  15392. return this;
  15393. },
  15394. getX: function getX(index) {
  15395. return this.data.array[index * this.data.stride + this.offset];
  15396. },
  15397. getY: function getY(index) {
  15398. return this.data.array[index * this.data.stride + this.offset + 1];
  15399. },
  15400. getZ: function getZ(index) {
  15401. return this.data.array[index * this.data.stride + this.offset + 2];
  15402. },
  15403. getW: function getW(index) {
  15404. return this.data.array[index * this.data.stride + this.offset + 3];
  15405. },
  15406. setXY: function setXY(index, x, y) {
  15407. index = index * this.data.stride + this.offset;
  15408. this.data.array[index + 0] = x;
  15409. this.data.array[index + 1] = y;
  15410. return this;
  15411. },
  15412. setXYZ: function setXYZ(index, x, y, z) {
  15413. index = index * this.data.stride + this.offset;
  15414. this.data.array[index + 0] = x;
  15415. this.data.array[index + 1] = y;
  15416. this.data.array[index + 2] = z;
  15417. return this;
  15418. },
  15419. setXYZW: function setXYZW(index, x, y, z, w) {
  15420. index = index * this.data.stride + this.offset;
  15421. this.data.array[index + 0] = x;
  15422. this.data.array[index + 1] = y;
  15423. this.data.array[index + 2] = z;
  15424. this.data.array[index + 3] = w;
  15425. return this;
  15426. },
  15427. clone: function clone(data) {
  15428. if (data === undefined) {
  15429. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  15430. var array = [];
  15431. for (var i = 0; i < this.count; i++) {
  15432. var index = i * this.data.stride + this.offset;
  15433. for (var j = 0; j < this.itemSize; j++) {
  15434. array.push(this.data.array[index + j]);
  15435. }
  15436. }
  15437. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  15438. } else {
  15439. if (data.interleavedBuffers === undefined) {
  15440. data.interleavedBuffers = {};
  15441. }
  15442. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15443. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  15444. }
  15445. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  15446. }
  15447. },
  15448. toJSON: function toJSON(data) {
  15449. if (data === undefined) {
  15450. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  15451. var array = [];
  15452. for (var i = 0; i < this.count; i++) {
  15453. var index = i * this.data.stride + this.offset;
  15454. for (var j = 0; j < this.itemSize; j++) {
  15455. array.push(this.data.array[index + j]);
  15456. }
  15457. } // deinterleave data and save it as an ordinary buffer attribute for now
  15458. return {
  15459. itemSize: this.itemSize,
  15460. type: this.array.constructor.name,
  15461. array: array,
  15462. normalized: this.normalized
  15463. };
  15464. } else {
  15465. // save as true interlaved attribtue
  15466. if (data.interleavedBuffers === undefined) {
  15467. data.interleavedBuffers = {};
  15468. }
  15469. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  15470. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  15471. }
  15472. return {
  15473. isInterleavedBufferAttribute: true,
  15474. itemSize: this.itemSize,
  15475. data: this.data.uuid,
  15476. offset: this.offset,
  15477. normalized: this.normalized
  15478. };
  15479. }
  15480. }
  15481. });
  15482. /**
  15483. * parameters = {
  15484. * color: <hex>,
  15485. * map: new THREE.Texture( <Image> ),
  15486. * alphaMap: new THREE.Texture( <Image> ),
  15487. * rotation: <float>,
  15488. * sizeAttenuation: <bool>
  15489. * }
  15490. */
  15491. function SpriteMaterial(parameters) {
  15492. Material.call(this);
  15493. this.type = 'SpriteMaterial';
  15494. this.color = new Color(0xffffff);
  15495. this.map = null;
  15496. this.alphaMap = null;
  15497. this.rotation = 0;
  15498. this.sizeAttenuation = true;
  15499. this.transparent = true;
  15500. this.setValues(parameters);
  15501. }
  15502. SpriteMaterial.prototype = Object.create(Material.prototype);
  15503. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15504. SpriteMaterial.prototype.isSpriteMaterial = true;
  15505. SpriteMaterial.prototype.copy = function (source) {
  15506. Material.prototype.copy.call(this, source);
  15507. this.color.copy(source.color);
  15508. this.map = source.map;
  15509. this.alphaMap = source.alphaMap;
  15510. this.rotation = source.rotation;
  15511. this.sizeAttenuation = source.sizeAttenuation;
  15512. return this;
  15513. };
  15514. var _geometry;
  15515. var _intersectPoint = new Vector3();
  15516. var _worldScale = new Vector3();
  15517. var _mvPosition = new Vector3();
  15518. var _alignedPosition = new Vector2();
  15519. var _rotatedPosition = new Vector2();
  15520. var _viewWorldMatrix = new Matrix4();
  15521. var _vA$1 = new Vector3();
  15522. var _vB$1 = new Vector3();
  15523. var _vC$1 = new Vector3();
  15524. var _uvA$1 = new Vector2();
  15525. var _uvB$1 = new Vector2();
  15526. var _uvC$1 = new Vector2();
  15527. function Sprite(material) {
  15528. Object3D.call(this);
  15529. this.type = 'Sprite';
  15530. if (_geometry === undefined) {
  15531. _geometry = new BufferGeometry();
  15532. 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]);
  15533. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  15534. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  15535. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  15536. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  15537. }
  15538. this.geometry = _geometry;
  15539. this.material = material !== undefined ? material : new SpriteMaterial();
  15540. this.center = new Vector2(0.5, 0.5);
  15541. }
  15542. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  15543. constructor: Sprite,
  15544. isSprite: true,
  15545. raycast: function raycast(raycaster, intersects) {
  15546. if (raycaster.camera === null) {
  15547. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  15548. }
  15549. _worldScale.setFromMatrixScale(this.matrixWorld);
  15550. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  15551. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  15552. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  15553. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  15554. _worldScale.multiplyScalar(-_mvPosition.z);
  15555. }
  15556. var rotation = this.material.rotation;
  15557. var sin, cos;
  15558. if (rotation !== 0) {
  15559. cos = Math.cos(rotation);
  15560. sin = Math.sin(rotation);
  15561. }
  15562. var center = this.center;
  15563. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15564. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15565. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15566. _uvA$1.set(0, 0);
  15567. _uvB$1.set(1, 0);
  15568. _uvC$1.set(1, 1); // check first triangle
  15569. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  15570. if (intersect === null) {
  15571. // check second triangle
  15572. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  15573. _uvB$1.set(0, 1);
  15574. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  15575. if (intersect === null) {
  15576. return;
  15577. }
  15578. }
  15579. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  15580. if (distance < raycaster.near || distance > raycaster.far) return;
  15581. intersects.push({
  15582. distance: distance,
  15583. point: _intersectPoint.clone(),
  15584. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  15585. face: null,
  15586. object: this
  15587. });
  15588. },
  15589. copy: function copy(source) {
  15590. Object3D.prototype.copy.call(this, source);
  15591. if (source.center !== undefined) this.center.copy(source.center);
  15592. this.material = source.material;
  15593. return this;
  15594. }
  15595. });
  15596. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  15597. // compute position in camera space
  15598. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  15599. if (sin !== undefined) {
  15600. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  15601. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  15602. } else {
  15603. _rotatedPosition.copy(_alignedPosition);
  15604. }
  15605. vertexPosition.copy(mvPosition);
  15606. vertexPosition.x += _rotatedPosition.x;
  15607. vertexPosition.y += _rotatedPosition.y; // transform to world space
  15608. vertexPosition.applyMatrix4(_viewWorldMatrix);
  15609. }
  15610. var _v1$4 = new Vector3();
  15611. var _v2$2 = new Vector3();
  15612. function LOD() {
  15613. Object3D.call(this);
  15614. this._currentLevel = 0;
  15615. this.type = 'LOD';
  15616. Object.defineProperties(this, {
  15617. levels: {
  15618. enumerable: true,
  15619. value: []
  15620. }
  15621. });
  15622. this.autoUpdate = true;
  15623. }
  15624. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  15625. constructor: LOD,
  15626. isLOD: true,
  15627. copy: function copy(source) {
  15628. Object3D.prototype.copy.call(this, source, false);
  15629. var levels = source.levels;
  15630. for (var i = 0, l = levels.length; i < l; i++) {
  15631. var level = levels[i];
  15632. this.addLevel(level.object.clone(), level.distance);
  15633. }
  15634. this.autoUpdate = source.autoUpdate;
  15635. return this;
  15636. },
  15637. addLevel: function addLevel(object, distance) {
  15638. if (distance === undefined) distance = 0;
  15639. distance = Math.abs(distance);
  15640. var levels = this.levels;
  15641. var l;
  15642. for (l = 0; l < levels.length; l++) {
  15643. if (distance < levels[l].distance) {
  15644. break;
  15645. }
  15646. }
  15647. levels.splice(l, 0, {
  15648. distance: distance,
  15649. object: object
  15650. });
  15651. this.add(object);
  15652. return this;
  15653. },
  15654. getCurrentLevel: function getCurrentLevel() {
  15655. return this._currentLevel;
  15656. },
  15657. getObjectForDistance: function getObjectForDistance(distance) {
  15658. var levels = this.levels;
  15659. if (levels.length > 0) {
  15660. var i, l;
  15661. for (i = 1, l = levels.length; i < l; i++) {
  15662. if (distance < levels[i].distance) {
  15663. break;
  15664. }
  15665. }
  15666. return levels[i - 1].object;
  15667. }
  15668. return null;
  15669. },
  15670. raycast: function raycast(raycaster, intersects) {
  15671. var levels = this.levels;
  15672. if (levels.length > 0) {
  15673. _v1$4.setFromMatrixPosition(this.matrixWorld);
  15674. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  15675. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  15676. }
  15677. },
  15678. update: function update(camera) {
  15679. var levels = this.levels;
  15680. if (levels.length > 1) {
  15681. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  15682. _v2$2.setFromMatrixPosition(this.matrixWorld);
  15683. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  15684. levels[0].object.visible = true;
  15685. var i, l;
  15686. for (i = 1, l = levels.length; i < l; i++) {
  15687. if (distance >= levels[i].distance) {
  15688. levels[i - 1].object.visible = false;
  15689. levels[i].object.visible = true;
  15690. } else {
  15691. break;
  15692. }
  15693. }
  15694. this._currentLevel = i - 1;
  15695. for (; i < l; i++) {
  15696. levels[i].object.visible = false;
  15697. }
  15698. }
  15699. },
  15700. toJSON: function toJSON(meta) {
  15701. var data = Object3D.prototype.toJSON.call(this, meta);
  15702. if (this.autoUpdate === false) data.object.autoUpdate = false;
  15703. data.object.levels = [];
  15704. var levels = this.levels;
  15705. for (var i = 0, l = levels.length; i < l; i++) {
  15706. var level = levels[i];
  15707. data.object.levels.push({
  15708. object: level.object.uuid,
  15709. distance: level.distance
  15710. });
  15711. }
  15712. return data;
  15713. }
  15714. });
  15715. function SkinnedMesh(geometry, material) {
  15716. if (geometry && geometry.isGeometry) {
  15717. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  15718. }
  15719. Mesh.call(this, geometry, material);
  15720. this.type = 'SkinnedMesh';
  15721. this.bindMode = 'attached';
  15722. this.bindMatrix = new Matrix4();
  15723. this.bindMatrixInverse = new Matrix4();
  15724. }
  15725. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15726. constructor: SkinnedMesh,
  15727. isSkinnedMesh: true,
  15728. copy: function copy(source) {
  15729. Mesh.prototype.copy.call(this, source);
  15730. this.bindMode = source.bindMode;
  15731. this.bindMatrix.copy(source.bindMatrix);
  15732. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  15733. this.skeleton = source.skeleton;
  15734. return this;
  15735. },
  15736. bind: function bind(skeleton, bindMatrix) {
  15737. this.skeleton = skeleton;
  15738. if (bindMatrix === undefined) {
  15739. this.updateMatrixWorld(true);
  15740. this.skeleton.calculateInverses();
  15741. bindMatrix = this.matrixWorld;
  15742. }
  15743. this.bindMatrix.copy(bindMatrix);
  15744. this.bindMatrixInverse.getInverse(bindMatrix);
  15745. },
  15746. pose: function pose() {
  15747. this.skeleton.pose();
  15748. },
  15749. normalizeSkinWeights: function normalizeSkinWeights() {
  15750. var vector = new Vector4();
  15751. var skinWeight = this.geometry.attributes.skinWeight;
  15752. for (var i = 0, l = skinWeight.count; i < l; i++) {
  15753. vector.x = skinWeight.getX(i);
  15754. vector.y = skinWeight.getY(i);
  15755. vector.z = skinWeight.getZ(i);
  15756. vector.w = skinWeight.getW(i);
  15757. var scale = 1.0 / vector.manhattanLength();
  15758. if (scale !== Infinity) {
  15759. vector.multiplyScalar(scale);
  15760. } else {
  15761. vector.set(1, 0, 0, 0); // do something reasonable
  15762. }
  15763. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  15764. }
  15765. },
  15766. updateMatrixWorld: function updateMatrixWorld(force) {
  15767. Mesh.prototype.updateMatrixWorld.call(this, force);
  15768. if (this.bindMode === 'attached') {
  15769. this.bindMatrixInverse.getInverse(this.matrixWorld);
  15770. } else if (this.bindMode === 'detached') {
  15771. this.bindMatrixInverse.getInverse(this.bindMatrix);
  15772. } else {
  15773. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  15774. }
  15775. },
  15776. boneTransform: function () {
  15777. var basePosition = new Vector3();
  15778. var skinIndex = new Vector4();
  15779. var skinWeight = new Vector4();
  15780. var vector = new Vector3();
  15781. var matrix = new Matrix4();
  15782. return function (index, target) {
  15783. var skeleton = this.skeleton;
  15784. var geometry = this.geometry;
  15785. skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  15786. skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  15787. basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  15788. target.set(0, 0, 0);
  15789. for (var i = 0; i < 4; i++) {
  15790. var weight = skinWeight.getComponent(i);
  15791. if (weight !== 0) {
  15792. var boneIndex = skinIndex.getComponent(i);
  15793. matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  15794. target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix), weight);
  15795. }
  15796. }
  15797. return target.applyMatrix4(this.bindMatrixInverse);
  15798. };
  15799. }()
  15800. });
  15801. var _offsetMatrix = new Matrix4();
  15802. var _identityMatrix = new Matrix4();
  15803. function Skeleton(bones, boneInverses) {
  15804. // copy the bone array
  15805. bones = bones || [];
  15806. this.bones = bones.slice(0);
  15807. this.boneMatrices = new Float32Array(this.bones.length * 16);
  15808. this.frame = -1; // use the supplied bone inverses or calculate the inverses
  15809. if (boneInverses === undefined) {
  15810. this.calculateInverses();
  15811. } else {
  15812. if (this.bones.length === boneInverses.length) {
  15813. this.boneInverses = boneInverses.slice(0);
  15814. } else {
  15815. console.warn('THREE.Skeleton boneInverses is the wrong length.');
  15816. this.boneInverses = [];
  15817. for (var i = 0, il = this.bones.length; i < il; i++) {
  15818. this.boneInverses.push(new Matrix4());
  15819. }
  15820. }
  15821. }
  15822. }
  15823. Object.assign(Skeleton.prototype, {
  15824. calculateInverses: function calculateInverses() {
  15825. this.boneInverses = [];
  15826. for (var i = 0, il = this.bones.length; i < il; i++) {
  15827. var inverse = new Matrix4();
  15828. if (this.bones[i]) {
  15829. inverse.getInverse(this.bones[i].matrixWorld);
  15830. }
  15831. this.boneInverses.push(inverse);
  15832. }
  15833. },
  15834. pose: function pose() {
  15835. // recover the bind-time world matrices
  15836. for (var i = 0, il = this.bones.length; i < il; i++) {
  15837. var bone = this.bones[i];
  15838. if (bone) {
  15839. bone.matrixWorld.getInverse(this.boneInverses[i]);
  15840. }
  15841. } // compute the local matrices, positions, rotations and scales
  15842. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  15843. var _bone = this.bones[_i];
  15844. if (_bone) {
  15845. if (_bone.parent && _bone.parent.isBone) {
  15846. _bone.matrix.getInverse(_bone.parent.matrixWorld);
  15847. _bone.matrix.multiply(_bone.matrixWorld);
  15848. } else {
  15849. _bone.matrix.copy(_bone.matrixWorld);
  15850. }
  15851. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  15852. }
  15853. }
  15854. },
  15855. update: function update() {
  15856. var bones = this.bones;
  15857. var boneInverses = this.boneInverses;
  15858. var boneMatrices = this.boneMatrices;
  15859. var boneTexture = this.boneTexture; // flatten bone matrices to array
  15860. for (var i = 0, il = bones.length; i < il; i++) {
  15861. // compute the offset between the current and the original transform
  15862. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  15863. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  15864. _offsetMatrix.toArray(boneMatrices, i * 16);
  15865. }
  15866. if (boneTexture !== undefined) {
  15867. boneTexture.needsUpdate = true;
  15868. }
  15869. },
  15870. clone: function clone() {
  15871. return new Skeleton(this.bones, this.boneInverses);
  15872. },
  15873. getBoneByName: function getBoneByName(name) {
  15874. for (var i = 0, il = this.bones.length; i < il; i++) {
  15875. var bone = this.bones[i];
  15876. if (bone.name === name) {
  15877. return bone;
  15878. }
  15879. }
  15880. return undefined;
  15881. },
  15882. dispose: function dispose() {
  15883. if (this.boneTexture) {
  15884. this.boneTexture.dispose();
  15885. this.boneTexture = undefined;
  15886. }
  15887. }
  15888. });
  15889. function Bone() {
  15890. Object3D.call(this);
  15891. this.type = 'Bone';
  15892. }
  15893. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  15894. constructor: Bone,
  15895. isBone: true
  15896. });
  15897. var _instanceLocalMatrix = new Matrix4();
  15898. var _instanceWorldMatrix = new Matrix4();
  15899. var _instanceIntersects = [];
  15900. var _mesh = new Mesh();
  15901. function InstancedMesh(geometry, material, count) {
  15902. Mesh.call(this, geometry, material);
  15903. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  15904. this.instanceColor = null;
  15905. this.count = count;
  15906. this.frustumCulled = false;
  15907. }
  15908. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  15909. constructor: InstancedMesh,
  15910. isInstancedMesh: true,
  15911. copy: function copy(source) {
  15912. Mesh.prototype.copy.call(this, source);
  15913. this.instanceMatrix.copy(source.instanceMatrix);
  15914. this.count = source.count;
  15915. return this;
  15916. },
  15917. setColorAt: function setColorAt(index, color) {
  15918. if (this.instanceColor === null) {
  15919. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  15920. }
  15921. color.toArray(this.instanceColor.array, index * 3);
  15922. },
  15923. getMatrixAt: function getMatrixAt(index, matrix) {
  15924. matrix.fromArray(this.instanceMatrix.array, index * 16);
  15925. },
  15926. raycast: function raycast(raycaster, intersects) {
  15927. var matrixWorld = this.matrixWorld;
  15928. var raycastTimes = this.count;
  15929. _mesh.geometry = this.geometry;
  15930. _mesh.material = this.material;
  15931. if (_mesh.material === undefined) return;
  15932. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  15933. // calculate the world matrix for each instance
  15934. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  15935. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  15936. _mesh.matrixWorld = _instanceWorldMatrix;
  15937. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  15938. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  15939. var intersect = _instanceIntersects[i];
  15940. intersect.instanceId = instanceId;
  15941. intersect.object = this;
  15942. intersects.push(intersect);
  15943. }
  15944. _instanceIntersects.length = 0;
  15945. }
  15946. },
  15947. setMatrixAt: function setMatrixAt(index, matrix) {
  15948. matrix.toArray(this.instanceMatrix.array, index * 16);
  15949. },
  15950. updateMorphTargets: function updateMorphTargets() {}
  15951. });
  15952. /**
  15953. * parameters = {
  15954. * color: <hex>,
  15955. * opacity: <float>,
  15956. *
  15957. * linewidth: <float>,
  15958. * linecap: "round",
  15959. * linejoin: "round"
  15960. * }
  15961. */
  15962. function LineBasicMaterial(parameters) {
  15963. Material.call(this);
  15964. this.type = 'LineBasicMaterial';
  15965. this.color = new Color(0xffffff);
  15966. this.linewidth = 1;
  15967. this.linecap = 'round';
  15968. this.linejoin = 'round';
  15969. this.morphTargets = false;
  15970. this.setValues(parameters);
  15971. }
  15972. LineBasicMaterial.prototype = Object.create(Material.prototype);
  15973. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15974. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15975. LineBasicMaterial.prototype.copy = function (source) {
  15976. Material.prototype.copy.call(this, source);
  15977. this.color.copy(source.color);
  15978. this.linewidth = source.linewidth;
  15979. this.linecap = source.linecap;
  15980. this.linejoin = source.linejoin;
  15981. this.morphTargets = source.morphTargets;
  15982. return this;
  15983. };
  15984. var _start = new Vector3();
  15985. var _end = new Vector3();
  15986. var _inverseMatrix$1 = new Matrix4();
  15987. var _ray$1 = new Ray();
  15988. var _sphere$2 = new Sphere();
  15989. function Line(geometry, material, mode) {
  15990. if (mode === 1) {
  15991. console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');
  15992. }
  15993. Object3D.call(this);
  15994. this.type = 'Line';
  15995. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15996. this.material = material !== undefined ? material : new LineBasicMaterial();
  15997. this.updateMorphTargets();
  15998. }
  15999. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16000. constructor: Line,
  16001. isLine: true,
  16002. copy: function copy(source) {
  16003. Object3D.prototype.copy.call(this, source);
  16004. this.material = source.material;
  16005. this.geometry = source.geometry;
  16006. return this;
  16007. },
  16008. computeLineDistances: function computeLineDistances() {
  16009. var geometry = this.geometry;
  16010. if (geometry.isBufferGeometry) {
  16011. // we assume non-indexed geometry
  16012. if (geometry.index === null) {
  16013. var positionAttribute = geometry.attributes.position;
  16014. var lineDistances = [0];
  16015. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16016. _start.fromBufferAttribute(positionAttribute, i - 1);
  16017. _end.fromBufferAttribute(positionAttribute, i);
  16018. lineDistances[i] = lineDistances[i - 1];
  16019. lineDistances[i] += _start.distanceTo(_end);
  16020. }
  16021. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16022. } else {
  16023. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16024. }
  16025. } else if (geometry.isGeometry) {
  16026. var vertices = geometry.vertices;
  16027. var _lineDistances = geometry.lineDistances;
  16028. _lineDistances[0] = 0;
  16029. for (var _i = 1, _l = vertices.length; _i < _l; _i++) {
  16030. _lineDistances[_i] = _lineDistances[_i - 1];
  16031. _lineDistances[_i] += vertices[_i - 1].distanceTo(vertices[_i]);
  16032. }
  16033. }
  16034. return this;
  16035. },
  16036. raycast: function raycast(raycaster, intersects) {
  16037. var geometry = this.geometry;
  16038. var matrixWorld = this.matrixWorld;
  16039. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16040. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16041. _sphere$2.copy(geometry.boundingSphere);
  16042. _sphere$2.applyMatrix4(matrixWorld);
  16043. _sphere$2.radius += threshold;
  16044. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16045. _inverseMatrix$1.getInverse(matrixWorld);
  16046. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16047. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16048. var localThresholdSq = localThreshold * localThreshold;
  16049. var vStart = new Vector3();
  16050. var vEnd = new Vector3();
  16051. var interSegment = new Vector3();
  16052. var interRay = new Vector3();
  16053. var step = this.isLineSegments ? 2 : 1;
  16054. if (geometry.isBufferGeometry) {
  16055. var index = geometry.index;
  16056. var attributes = geometry.attributes;
  16057. var positionAttribute = attributes.position;
  16058. if (index !== null) {
  16059. var indices = index.array;
  16060. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16061. var a = indices[i];
  16062. var b = indices[i + 1];
  16063. vStart.fromBufferAttribute(positionAttribute, a);
  16064. vEnd.fromBufferAttribute(positionAttribute, b);
  16065. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16066. if (distSq > localThresholdSq) continue;
  16067. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16068. var distance = raycaster.ray.origin.distanceTo(interRay);
  16069. if (distance < raycaster.near || distance > raycaster.far) continue;
  16070. intersects.push({
  16071. distance: distance,
  16072. // What do we want? intersection point on the ray or on the segment??
  16073. // point: raycaster.ray.at( distance ),
  16074. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16075. index: i,
  16076. face: null,
  16077. faceIndex: null,
  16078. object: this
  16079. });
  16080. }
  16081. } else {
  16082. for (var _i2 = 0, _l2 = positionAttribute.count - 1; _i2 < _l2; _i2 += step) {
  16083. vStart.fromBufferAttribute(positionAttribute, _i2);
  16084. vEnd.fromBufferAttribute(positionAttribute, _i2 + 1);
  16085. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16086. if (_distSq > localThresholdSq) continue;
  16087. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16088. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16089. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16090. intersects.push({
  16091. distance: _distance,
  16092. // What do we want? intersection point on the ray or on the segment??
  16093. // point: raycaster.ray.at( distance ),
  16094. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16095. index: _i2,
  16096. face: null,
  16097. faceIndex: null,
  16098. object: this
  16099. });
  16100. }
  16101. }
  16102. } else if (geometry.isGeometry) {
  16103. var vertices = geometry.vertices;
  16104. var nbVertices = vertices.length;
  16105. for (var _i3 = 0; _i3 < nbVertices - 1; _i3 += step) {
  16106. var _distSq2 = _ray$1.distanceSqToSegment(vertices[_i3], vertices[_i3 + 1], interRay, interSegment);
  16107. if (_distSq2 > localThresholdSq) continue;
  16108. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16109. var _distance2 = raycaster.ray.origin.distanceTo(interRay);
  16110. if (_distance2 < raycaster.near || _distance2 > raycaster.far) continue;
  16111. intersects.push({
  16112. distance: _distance2,
  16113. // What do we want? intersection point on the ray or on the segment??
  16114. // point: raycaster.ray.at( distance ),
  16115. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16116. index: _i3,
  16117. face: null,
  16118. faceIndex: null,
  16119. object: this
  16120. });
  16121. }
  16122. }
  16123. },
  16124. updateMorphTargets: function updateMorphTargets() {
  16125. var geometry = this.geometry;
  16126. if (geometry.isBufferGeometry) {
  16127. var morphAttributes = geometry.morphAttributes;
  16128. var keys = Object.keys(morphAttributes);
  16129. if (keys.length > 0) {
  16130. var morphAttribute = morphAttributes[keys[0]];
  16131. if (morphAttribute !== undefined) {
  16132. this.morphTargetInfluences = [];
  16133. this.morphTargetDictionary = {};
  16134. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16135. var name = morphAttribute[m].name || String(m);
  16136. this.morphTargetInfluences.push(0);
  16137. this.morphTargetDictionary[name] = m;
  16138. }
  16139. }
  16140. }
  16141. } else {
  16142. var morphTargets = geometry.morphTargets;
  16143. if (morphTargets !== undefined && morphTargets.length > 0) {
  16144. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16145. }
  16146. }
  16147. }
  16148. });
  16149. var _start$1 = new Vector3();
  16150. var _end$1 = new Vector3();
  16151. function LineSegments(geometry, material) {
  16152. Line.call(this, geometry, material);
  16153. this.type = 'LineSegments';
  16154. }
  16155. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16156. constructor: LineSegments,
  16157. isLineSegments: true,
  16158. computeLineDistances: function computeLineDistances() {
  16159. var geometry = this.geometry;
  16160. if (geometry.isBufferGeometry) {
  16161. // we assume non-indexed geometry
  16162. if (geometry.index === null) {
  16163. var positionAttribute = geometry.attributes.position;
  16164. var lineDistances = [];
  16165. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16166. _start$1.fromBufferAttribute(positionAttribute, i);
  16167. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16168. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16169. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16170. }
  16171. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16172. } else {
  16173. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16174. }
  16175. } else if (geometry.isGeometry) {
  16176. var vertices = geometry.vertices;
  16177. var _lineDistances = geometry.lineDistances;
  16178. for (var _i = 0, _l = vertices.length; _i < _l; _i += 2) {
  16179. _start$1.copy(vertices[_i]);
  16180. _end$1.copy(vertices[_i + 1]);
  16181. _lineDistances[_i] = _i === 0 ? 0 : _lineDistances[_i - 1];
  16182. _lineDistances[_i + 1] = _lineDistances[_i] + _start$1.distanceTo(_end$1);
  16183. }
  16184. }
  16185. return this;
  16186. }
  16187. });
  16188. function LineLoop(geometry, material) {
  16189. Line.call(this, geometry, material);
  16190. this.type = 'LineLoop';
  16191. }
  16192. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16193. constructor: LineLoop,
  16194. isLineLoop: true
  16195. });
  16196. /**
  16197. * parameters = {
  16198. * color: <hex>,
  16199. * opacity: <float>,
  16200. * map: new THREE.Texture( <Image> ),
  16201. * alphaMap: new THREE.Texture( <Image> ),
  16202. *
  16203. * size: <float>,
  16204. * sizeAttenuation: <bool>
  16205. *
  16206. * morphTargets: <bool>
  16207. * }
  16208. */
  16209. function PointsMaterial(parameters) {
  16210. Material.call(this);
  16211. this.type = 'PointsMaterial';
  16212. this.color = new Color(0xffffff);
  16213. this.map = null;
  16214. this.alphaMap = null;
  16215. this.size = 1;
  16216. this.sizeAttenuation = true;
  16217. this.morphTargets = false;
  16218. this.setValues(parameters);
  16219. }
  16220. PointsMaterial.prototype = Object.create(Material.prototype);
  16221. PointsMaterial.prototype.constructor = PointsMaterial;
  16222. PointsMaterial.prototype.isPointsMaterial = true;
  16223. PointsMaterial.prototype.copy = function (source) {
  16224. Material.prototype.copy.call(this, source);
  16225. this.color.copy(source.color);
  16226. this.map = source.map;
  16227. this.alphaMap = source.alphaMap;
  16228. this.size = source.size;
  16229. this.sizeAttenuation = source.sizeAttenuation;
  16230. this.morphTargets = source.morphTargets;
  16231. return this;
  16232. };
  16233. var _inverseMatrix$2 = new Matrix4();
  16234. var _ray$2 = new Ray();
  16235. var _sphere$3 = new Sphere();
  16236. var _position$1 = new Vector3();
  16237. function Points(geometry, material) {
  16238. Object3D.call(this);
  16239. this.type = 'Points';
  16240. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16241. this.material = material !== undefined ? material : new PointsMaterial();
  16242. this.updateMorphTargets();
  16243. }
  16244. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  16245. constructor: Points,
  16246. isPoints: true,
  16247. copy: function copy(source) {
  16248. Object3D.prototype.copy.call(this, source);
  16249. this.material = source.material;
  16250. this.geometry = source.geometry;
  16251. return this;
  16252. },
  16253. raycast: function raycast(raycaster, intersects) {
  16254. var geometry = this.geometry;
  16255. var matrixWorld = this.matrixWorld;
  16256. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  16257. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16258. _sphere$3.copy(geometry.boundingSphere);
  16259. _sphere$3.applyMatrix4(matrixWorld);
  16260. _sphere$3.radius += threshold;
  16261. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  16262. _inverseMatrix$2.getInverse(matrixWorld);
  16263. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  16264. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16265. var localThresholdSq = localThreshold * localThreshold;
  16266. if (geometry.isBufferGeometry) {
  16267. var index = geometry.index;
  16268. var attributes = geometry.attributes;
  16269. var positionAttribute = attributes.position;
  16270. if (index !== null) {
  16271. var indices = index.array;
  16272. for (var i = 0, il = indices.length; i < il; i++) {
  16273. var a = indices[i];
  16274. _position$1.fromBufferAttribute(positionAttribute, a);
  16275. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16276. }
  16277. } else {
  16278. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  16279. _position$1.fromBufferAttribute(positionAttribute, _i);
  16280. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16281. }
  16282. }
  16283. } else {
  16284. var vertices = geometry.vertices;
  16285. for (var _i2 = 0, _l = vertices.length; _i2 < _l; _i2++) {
  16286. testPoint(vertices[_i2], _i2, localThresholdSq, matrixWorld, raycaster, intersects, this);
  16287. }
  16288. }
  16289. },
  16290. updateMorphTargets: function updateMorphTargets() {
  16291. var geometry = this.geometry;
  16292. if (geometry.isBufferGeometry) {
  16293. var morphAttributes = geometry.morphAttributes;
  16294. var keys = Object.keys(morphAttributes);
  16295. if (keys.length > 0) {
  16296. var morphAttribute = morphAttributes[keys[0]];
  16297. if (morphAttribute !== undefined) {
  16298. this.morphTargetInfluences = [];
  16299. this.morphTargetDictionary = {};
  16300. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16301. var name = morphAttribute[m].name || String(m);
  16302. this.morphTargetInfluences.push(0);
  16303. this.morphTargetDictionary[name] = m;
  16304. }
  16305. }
  16306. }
  16307. } else {
  16308. var morphTargets = geometry.morphTargets;
  16309. if (morphTargets !== undefined && morphTargets.length > 0) {
  16310. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16311. }
  16312. }
  16313. }
  16314. });
  16315. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  16316. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  16317. if (rayPointDistanceSq < localThresholdSq) {
  16318. var intersectPoint = new Vector3();
  16319. _ray$2.closestPointToPoint(point, intersectPoint);
  16320. intersectPoint.applyMatrix4(matrixWorld);
  16321. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  16322. if (distance < raycaster.near || distance > raycaster.far) return;
  16323. intersects.push({
  16324. distance: distance,
  16325. distanceToRay: Math.sqrt(rayPointDistanceSq),
  16326. point: intersectPoint,
  16327. index: index,
  16328. face: null,
  16329. object: object
  16330. });
  16331. }
  16332. }
  16333. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16334. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16335. this.format = format !== undefined ? format : RGBFormat;
  16336. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16337. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16338. this.generateMipmaps = false;
  16339. var scope = this;
  16340. function updateVideo() {
  16341. scope.needsUpdate = true;
  16342. video.requestVideoFrameCallback(updateVideo);
  16343. }
  16344. if ('requestVideoFrameCallback' in video) {
  16345. video.requestVideoFrameCallback(updateVideo);
  16346. }
  16347. }
  16348. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  16349. constructor: VideoTexture,
  16350. clone: function clone() {
  16351. return new this.constructor(this.image).copy(this);
  16352. },
  16353. isVideoTexture: true,
  16354. update: function update() {
  16355. var video = this.image;
  16356. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  16357. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  16358. this.needsUpdate = true;
  16359. }
  16360. }
  16361. });
  16362. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  16363. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  16364. this.image = {
  16365. width: width,
  16366. height: height
  16367. };
  16368. this.mipmaps = mipmaps; // no flipping for cube textures
  16369. // (also flipping doesn't work for compressed textures )
  16370. this.flipY = false; // can't generate mipmaps for compressed textures
  16371. // mips must be embedded in DDS files
  16372. this.generateMipmaps = false;
  16373. }
  16374. CompressedTexture.prototype = Object.create(Texture.prototype);
  16375. CompressedTexture.prototype.constructor = CompressedTexture;
  16376. CompressedTexture.prototype.isCompressedTexture = true;
  16377. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  16378. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16379. this.needsUpdate = true;
  16380. }
  16381. CanvasTexture.prototype = Object.create(Texture.prototype);
  16382. CanvasTexture.prototype.constructor = CanvasTexture;
  16383. CanvasTexture.prototype.isCanvasTexture = true;
  16384. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  16385. format = format !== undefined ? format : DepthFormat;
  16386. if (format !== DepthFormat && format !== DepthStencilFormat) {
  16387. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  16388. }
  16389. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  16390. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  16391. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  16392. this.image = {
  16393. width: width,
  16394. height: height
  16395. };
  16396. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16397. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16398. this.flipY = false;
  16399. this.generateMipmaps = false;
  16400. }
  16401. DepthTexture.prototype = Object.create(Texture.prototype);
  16402. DepthTexture.prototype.constructor = DepthTexture;
  16403. DepthTexture.prototype.isDepthTexture = true;
  16404. var _geometryId = 0; // Geometry uses even numbers as Id
  16405. var _m1$3 = new Matrix4();
  16406. var _obj$1 = new Object3D();
  16407. var _offset$1 = new Vector3();
  16408. function Geometry() {
  16409. Object.defineProperty(this, 'id', {
  16410. value: _geometryId += 2
  16411. });
  16412. this.uuid = MathUtils.generateUUID();
  16413. this.name = '';
  16414. this.type = 'Geometry';
  16415. this.vertices = [];
  16416. this.colors = [];
  16417. this.faces = [];
  16418. this.faceVertexUvs = [[]];
  16419. this.morphTargets = [];
  16420. this.morphNormals = [];
  16421. this.skinWeights = [];
  16422. this.skinIndices = [];
  16423. this.lineDistances = [];
  16424. this.boundingBox = null;
  16425. this.boundingSphere = null; // update flags
  16426. this.elementsNeedUpdate = false;
  16427. this.verticesNeedUpdate = false;
  16428. this.uvsNeedUpdate = false;
  16429. this.normalsNeedUpdate = false;
  16430. this.colorsNeedUpdate = false;
  16431. this.lineDistancesNeedUpdate = false;
  16432. this.groupsNeedUpdate = false;
  16433. }
  16434. Geometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  16435. constructor: Geometry,
  16436. isGeometry: true,
  16437. applyMatrix4: function applyMatrix4(matrix) {
  16438. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16439. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16440. var vertex = this.vertices[i];
  16441. vertex.applyMatrix4(matrix);
  16442. }
  16443. for (var _i = 0, _il = this.faces.length; _i < _il; _i++) {
  16444. var face = this.faces[_i];
  16445. face.normal.applyMatrix3(normalMatrix).normalize();
  16446. for (var j = 0, jl = face.vertexNormals.length; j < jl; j++) {
  16447. face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();
  16448. }
  16449. }
  16450. if (this.boundingBox !== null) {
  16451. this.computeBoundingBox();
  16452. }
  16453. if (this.boundingSphere !== null) {
  16454. this.computeBoundingSphere();
  16455. }
  16456. this.verticesNeedUpdate = true;
  16457. this.normalsNeedUpdate = true;
  16458. return this;
  16459. },
  16460. rotateX: function rotateX(angle) {
  16461. // rotate geometry around world x-axis
  16462. _m1$3.makeRotationX(angle);
  16463. this.applyMatrix4(_m1$3);
  16464. return this;
  16465. },
  16466. rotateY: function rotateY(angle) {
  16467. // rotate geometry around world y-axis
  16468. _m1$3.makeRotationY(angle);
  16469. this.applyMatrix4(_m1$3);
  16470. return this;
  16471. },
  16472. rotateZ: function rotateZ(angle) {
  16473. // rotate geometry around world z-axis
  16474. _m1$3.makeRotationZ(angle);
  16475. this.applyMatrix4(_m1$3);
  16476. return this;
  16477. },
  16478. translate: function translate(x, y, z) {
  16479. // translate geometry
  16480. _m1$3.makeTranslation(x, y, z);
  16481. this.applyMatrix4(_m1$3);
  16482. return this;
  16483. },
  16484. scale: function scale(x, y, z) {
  16485. // scale geometry
  16486. _m1$3.makeScale(x, y, z);
  16487. this.applyMatrix4(_m1$3);
  16488. return this;
  16489. },
  16490. lookAt: function lookAt(vector) {
  16491. _obj$1.lookAt(vector);
  16492. _obj$1.updateMatrix();
  16493. this.applyMatrix4(_obj$1.matrix);
  16494. return this;
  16495. },
  16496. fromBufferGeometry: function fromBufferGeometry(geometry) {
  16497. var scope = this;
  16498. var index = geometry.index !== null ? geometry.index : undefined;
  16499. var attributes = geometry.attributes;
  16500. if (attributes.position === undefined) {
  16501. console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');
  16502. return this;
  16503. }
  16504. var position = attributes.position;
  16505. var normal = attributes.normal;
  16506. var color = attributes.color;
  16507. var uv = attributes.uv;
  16508. var uv2 = attributes.uv2;
  16509. if (uv2 !== undefined) this.faceVertexUvs[1] = [];
  16510. for (var i = 0; i < position.count; i++) {
  16511. scope.vertices.push(new Vector3().fromBufferAttribute(position, i));
  16512. if (color !== undefined) {
  16513. scope.colors.push(new Color().fromBufferAttribute(color, i));
  16514. }
  16515. }
  16516. function addFace(a, b, c, materialIndex) {
  16517. var vertexColors = color === undefined ? [] : [scope.colors[a].clone(), scope.colors[b].clone(), scope.colors[c].clone()];
  16518. var vertexNormals = normal === undefined ? [] : [new Vector3().fromBufferAttribute(normal, a), new Vector3().fromBufferAttribute(normal, b), new Vector3().fromBufferAttribute(normal, c)];
  16519. var face = new Face3(a, b, c, vertexNormals, vertexColors, materialIndex);
  16520. scope.faces.push(face);
  16521. if (uv !== undefined) {
  16522. scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv, a), new Vector2().fromBufferAttribute(uv, b), new Vector2().fromBufferAttribute(uv, c)]);
  16523. }
  16524. if (uv2 !== undefined) {
  16525. scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2, a), new Vector2().fromBufferAttribute(uv2, b), new Vector2().fromBufferAttribute(uv2, c)]);
  16526. }
  16527. }
  16528. var groups = geometry.groups;
  16529. if (groups.length > 0) {
  16530. for (var _i2 = 0; _i2 < groups.length; _i2++) {
  16531. var group = groups[_i2];
  16532. var start = group.start;
  16533. var count = group.count;
  16534. for (var j = start, jl = start + count; j < jl; j += 3) {
  16535. if (index !== undefined) {
  16536. addFace(index.getX(j), index.getX(j + 1), index.getX(j + 2), group.materialIndex);
  16537. } else {
  16538. addFace(j, j + 1, j + 2, group.materialIndex);
  16539. }
  16540. }
  16541. }
  16542. } else {
  16543. if (index !== undefined) {
  16544. for (var _i3 = 0; _i3 < index.count; _i3 += 3) {
  16545. addFace(index.getX(_i3), index.getX(_i3 + 1), index.getX(_i3 + 2));
  16546. }
  16547. } else {
  16548. for (var _i4 = 0; _i4 < position.count; _i4 += 3) {
  16549. addFace(_i4, _i4 + 1, _i4 + 2);
  16550. }
  16551. }
  16552. }
  16553. this.computeFaceNormals();
  16554. if (geometry.boundingBox !== null) {
  16555. this.boundingBox = geometry.boundingBox.clone();
  16556. }
  16557. if (geometry.boundingSphere !== null) {
  16558. this.boundingSphere = geometry.boundingSphere.clone();
  16559. }
  16560. return this;
  16561. },
  16562. center: function center() {
  16563. this.computeBoundingBox();
  16564. this.boundingBox.getCenter(_offset$1).negate();
  16565. this.translate(_offset$1.x, _offset$1.y, _offset$1.z);
  16566. return this;
  16567. },
  16568. normalize: function normalize() {
  16569. this.computeBoundingSphere();
  16570. var center = this.boundingSphere.center;
  16571. var radius = this.boundingSphere.radius;
  16572. var s = radius === 0 ? 1 : 1.0 / radius;
  16573. var matrix = new Matrix4();
  16574. matrix.set(s, 0, 0, -s * center.x, 0, s, 0, -s * center.y, 0, 0, s, -s * center.z, 0, 0, 0, 1);
  16575. this.applyMatrix4(matrix);
  16576. return this;
  16577. },
  16578. computeFaceNormals: function computeFaceNormals() {
  16579. var cb = new Vector3(),
  16580. ab = new Vector3();
  16581. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16582. var face = this.faces[f];
  16583. var vA = this.vertices[face.a];
  16584. var vB = this.vertices[face.b];
  16585. var vC = this.vertices[face.c];
  16586. cb.subVectors(vC, vB);
  16587. ab.subVectors(vA, vB);
  16588. cb.cross(ab);
  16589. cb.normalize();
  16590. face.normal.copy(cb);
  16591. }
  16592. },
  16593. computeVertexNormals: function computeVertexNormals(areaWeighted) {
  16594. if (areaWeighted === undefined) areaWeighted = true;
  16595. var vertices = new Array(this.vertices.length);
  16596. for (var v = 0, vl = this.vertices.length; v < vl; v++) {
  16597. vertices[v] = new Vector3();
  16598. }
  16599. if (areaWeighted) {
  16600. // vertex normals weighted by triangle areas
  16601. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16602. var cb = new Vector3(),
  16603. ab = new Vector3();
  16604. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16605. var face = this.faces[f];
  16606. var vA = this.vertices[face.a];
  16607. var vB = this.vertices[face.b];
  16608. var vC = this.vertices[face.c];
  16609. cb.subVectors(vC, vB);
  16610. ab.subVectors(vA, vB);
  16611. cb.cross(ab);
  16612. vertices[face.a].add(cb);
  16613. vertices[face.b].add(cb);
  16614. vertices[face.c].add(cb);
  16615. }
  16616. } else {
  16617. this.computeFaceNormals();
  16618. for (var _f = 0, _fl = this.faces.length; _f < _fl; _f++) {
  16619. var _face = this.faces[_f];
  16620. vertices[_face.a].add(_face.normal);
  16621. vertices[_face.b].add(_face.normal);
  16622. vertices[_face.c].add(_face.normal);
  16623. }
  16624. }
  16625. for (var _v = 0, _vl = this.vertices.length; _v < _vl; _v++) {
  16626. vertices[_v].normalize();
  16627. }
  16628. for (var _f2 = 0, _fl2 = this.faces.length; _f2 < _fl2; _f2++) {
  16629. var _face2 = this.faces[_f2];
  16630. var vertexNormals = _face2.vertexNormals;
  16631. if (vertexNormals.length === 3) {
  16632. vertexNormals[0].copy(vertices[_face2.a]);
  16633. vertexNormals[1].copy(vertices[_face2.b]);
  16634. vertexNormals[2].copy(vertices[_face2.c]);
  16635. } else {
  16636. vertexNormals[0] = vertices[_face2.a].clone();
  16637. vertexNormals[1] = vertices[_face2.b].clone();
  16638. vertexNormals[2] = vertices[_face2.c].clone();
  16639. }
  16640. }
  16641. if (this.faces.length > 0) {
  16642. this.normalsNeedUpdate = true;
  16643. }
  16644. },
  16645. computeFlatVertexNormals: function computeFlatVertexNormals() {
  16646. this.computeFaceNormals();
  16647. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16648. var face = this.faces[f];
  16649. var vertexNormals = face.vertexNormals;
  16650. if (vertexNormals.length === 3) {
  16651. vertexNormals[0].copy(face.normal);
  16652. vertexNormals[1].copy(face.normal);
  16653. vertexNormals[2].copy(face.normal);
  16654. } else {
  16655. vertexNormals[0] = face.normal.clone();
  16656. vertexNormals[1] = face.normal.clone();
  16657. vertexNormals[2] = face.normal.clone();
  16658. }
  16659. }
  16660. if (this.faces.length > 0) {
  16661. this.normalsNeedUpdate = true;
  16662. }
  16663. },
  16664. computeMorphNormals: function computeMorphNormals() {
  16665. // save original normals
  16666. // - create temp variables on first access
  16667. // otherwise just copy (for faster repeated calls)
  16668. for (var f = 0, fl = this.faces.length; f < fl; f++) {
  16669. var face = this.faces[f];
  16670. if (!face.__originalFaceNormal) {
  16671. face.__originalFaceNormal = face.normal.clone();
  16672. } else {
  16673. face.__originalFaceNormal.copy(face.normal);
  16674. }
  16675. if (!face.__originalVertexNormals) face.__originalVertexNormals = [];
  16676. for (var i = 0, il = face.vertexNormals.length; i < il; i++) {
  16677. if (!face.__originalVertexNormals[i]) {
  16678. face.__originalVertexNormals[i] = face.vertexNormals[i].clone();
  16679. } else {
  16680. face.__originalVertexNormals[i].copy(face.vertexNormals[i]);
  16681. }
  16682. }
  16683. } // use temp geometry to compute face and vertex normals for each morph
  16684. var tmpGeo = new Geometry();
  16685. tmpGeo.faces = this.faces;
  16686. for (var _i5 = 0, _il2 = this.morphTargets.length; _i5 < _il2; _i5++) {
  16687. // create on first access
  16688. if (!this.morphNormals[_i5]) {
  16689. this.morphNormals[_i5] = {};
  16690. this.morphNormals[_i5].faceNormals = [];
  16691. this.morphNormals[_i5].vertexNormals = [];
  16692. var dstNormalsFace = this.morphNormals[_i5].faceNormals;
  16693. var dstNormalsVertex = this.morphNormals[_i5].vertexNormals;
  16694. for (var _f3 = 0, _fl3 = this.faces.length; _f3 < _fl3; _f3++) {
  16695. var faceNormal = new Vector3();
  16696. var vertexNormals = {
  16697. a: new Vector3(),
  16698. b: new Vector3(),
  16699. c: new Vector3()
  16700. };
  16701. dstNormalsFace.push(faceNormal);
  16702. dstNormalsVertex.push(vertexNormals);
  16703. }
  16704. }
  16705. var morphNormals = this.morphNormals[_i5]; // set vertices to morph target
  16706. tmpGeo.vertices = this.morphTargets[_i5].vertices; // compute morph normals
  16707. tmpGeo.computeFaceNormals();
  16708. tmpGeo.computeVertexNormals(); // store morph normals
  16709. for (var _f4 = 0, _fl4 = this.faces.length; _f4 < _fl4; _f4++) {
  16710. var _face3 = this.faces[_f4];
  16711. var _faceNormal = morphNormals.faceNormals[_f4];
  16712. var _vertexNormals = morphNormals.vertexNormals[_f4];
  16713. _faceNormal.copy(_face3.normal);
  16714. _vertexNormals.a.copy(_face3.vertexNormals[0]);
  16715. _vertexNormals.b.copy(_face3.vertexNormals[1]);
  16716. _vertexNormals.c.copy(_face3.vertexNormals[2]);
  16717. }
  16718. } // restore original normals
  16719. for (var _f5 = 0, _fl5 = this.faces.length; _f5 < _fl5; _f5++) {
  16720. var _face4 = this.faces[_f5];
  16721. _face4.normal = _face4.__originalFaceNormal;
  16722. _face4.vertexNormals = _face4.__originalVertexNormals;
  16723. }
  16724. },
  16725. computeBoundingBox: function computeBoundingBox() {
  16726. if (this.boundingBox === null) {
  16727. this.boundingBox = new Box3();
  16728. }
  16729. this.boundingBox.setFromPoints(this.vertices);
  16730. },
  16731. computeBoundingSphere: function computeBoundingSphere() {
  16732. if (this.boundingSphere === null) {
  16733. this.boundingSphere = new Sphere();
  16734. }
  16735. this.boundingSphere.setFromPoints(this.vertices);
  16736. },
  16737. merge: function merge(geometry, matrix, materialIndexOffset) {
  16738. if (!(geometry && geometry.isGeometry)) {
  16739. console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry);
  16740. return;
  16741. }
  16742. var normalMatrix;
  16743. var vertexOffset = this.vertices.length,
  16744. vertices1 = this.vertices,
  16745. vertices2 = geometry.vertices,
  16746. faces1 = this.faces,
  16747. faces2 = geometry.faces,
  16748. colors1 = this.colors,
  16749. colors2 = geometry.colors;
  16750. if (materialIndexOffset === undefined) materialIndexOffset = 0;
  16751. if (matrix !== undefined) {
  16752. normalMatrix = new Matrix3().getNormalMatrix(matrix);
  16753. } // vertices
  16754. for (var i = 0, il = vertices2.length; i < il; i++) {
  16755. var vertex = vertices2[i];
  16756. var vertexCopy = vertex.clone();
  16757. if (matrix !== undefined) vertexCopy.applyMatrix4(matrix);
  16758. vertices1.push(vertexCopy);
  16759. } // colors
  16760. for (var _i6 = 0, _il3 = colors2.length; _i6 < _il3; _i6++) {
  16761. colors1.push(colors2[_i6].clone());
  16762. } // faces
  16763. for (var _i7 = 0, _il4 = faces2.length; _i7 < _il4; _i7++) {
  16764. var face = faces2[_i7];
  16765. var normal = void 0,
  16766. color = void 0;
  16767. var faceVertexNormals = face.vertexNormals,
  16768. faceVertexColors = face.vertexColors;
  16769. var faceCopy = new Face3(face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset);
  16770. faceCopy.normal.copy(face.normal);
  16771. if (normalMatrix !== undefined) {
  16772. faceCopy.normal.applyMatrix3(normalMatrix).normalize();
  16773. }
  16774. for (var j = 0, jl = faceVertexNormals.length; j < jl; j++) {
  16775. normal = faceVertexNormals[j].clone();
  16776. if (normalMatrix !== undefined) {
  16777. normal.applyMatrix3(normalMatrix).normalize();
  16778. }
  16779. faceCopy.vertexNormals.push(normal);
  16780. }
  16781. faceCopy.color.copy(face.color);
  16782. for (var _j = 0, _jl = faceVertexColors.length; _j < _jl; _j++) {
  16783. color = faceVertexColors[_j];
  16784. faceCopy.vertexColors.push(color.clone());
  16785. }
  16786. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16787. faces1.push(faceCopy);
  16788. } // uvs
  16789. for (var _i8 = 0, _il5 = geometry.faceVertexUvs.length; _i8 < _il5; _i8++) {
  16790. var faceVertexUvs2 = geometry.faceVertexUvs[_i8];
  16791. if (this.faceVertexUvs[_i8] === undefined) this.faceVertexUvs[_i8] = [];
  16792. for (var _j2 = 0, _jl2 = faceVertexUvs2.length; _j2 < _jl2; _j2++) {
  16793. var uvs2 = faceVertexUvs2[_j2],
  16794. uvsCopy = [];
  16795. for (var k = 0, kl = uvs2.length; k < kl; k++) {
  16796. uvsCopy.push(uvs2[k].clone());
  16797. }
  16798. this.faceVertexUvs[_i8].push(uvsCopy);
  16799. }
  16800. }
  16801. },
  16802. mergeMesh: function mergeMesh(mesh) {
  16803. if (!(mesh && mesh.isMesh)) {
  16804. console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh);
  16805. return;
  16806. }
  16807. if (mesh.matrixAutoUpdate) mesh.updateMatrix();
  16808. this.merge(mesh.geometry, mesh.matrix);
  16809. },
  16810. /*
  16811. * Checks for duplicate vertices with hashmap.
  16812. * Duplicated vertices are removed
  16813. * and faces' vertices are updated.
  16814. */
  16815. mergeVertices: function mergeVertices() {
  16816. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16817. var unique = [],
  16818. changes = [];
  16819. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  16820. var precision = Math.pow(10, precisionPoints);
  16821. for (var i = 0, il = this.vertices.length; i < il; i++) {
  16822. var v = this.vertices[i];
  16823. var key = Math.round(v.x * precision) + '_' + Math.round(v.y * precision) + '_' + Math.round(v.z * precision);
  16824. if (verticesMap[key] === undefined) {
  16825. verticesMap[key] = i;
  16826. unique.push(this.vertices[i]);
  16827. changes[i] = unique.length - 1;
  16828. } else {
  16829. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16830. changes[i] = changes[verticesMap[key]];
  16831. }
  16832. } // if faces are completely degenerate after merging vertices, we
  16833. // have to remove them from the geometry.
  16834. var faceIndicesToRemove = [];
  16835. for (var _i9 = 0, _il6 = this.faces.length; _i9 < _il6; _i9++) {
  16836. var face = this.faces[_i9];
  16837. face.a = changes[face.a];
  16838. face.b = changes[face.b];
  16839. face.c = changes[face.c];
  16840. var indices = [face.a, face.b, face.c]; // if any duplicate vertices are found in a Face3
  16841. // we have to remove the face as nothing can be saved
  16842. for (var n = 0; n < 3; n++) {
  16843. if (indices[n] === indices[(n + 1) % 3]) {
  16844. faceIndicesToRemove.push(_i9);
  16845. break;
  16846. }
  16847. }
  16848. }
  16849. for (var _i10 = faceIndicesToRemove.length - 1; _i10 >= 0; _i10--) {
  16850. var idx = faceIndicesToRemove[_i10];
  16851. this.faces.splice(idx, 1);
  16852. for (var j = 0, jl = this.faceVertexUvs.length; j < jl; j++) {
  16853. this.faceVertexUvs[j].splice(idx, 1);
  16854. }
  16855. } // Use unique set of vertices
  16856. var diff = this.vertices.length - unique.length;
  16857. this.vertices = unique;
  16858. return diff;
  16859. },
  16860. setFromPoints: function setFromPoints(points) {
  16861. this.vertices = [];
  16862. for (var i = 0, l = points.length; i < l; i++) {
  16863. var point = points[i];
  16864. this.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  16865. }
  16866. return this;
  16867. },
  16868. sortFacesByMaterialIndex: function sortFacesByMaterialIndex() {
  16869. var faces = this.faces;
  16870. var length = faces.length; // tag faces
  16871. for (var i = 0; i < length; i++) {
  16872. faces[i]._id = i;
  16873. } // sort faces
  16874. function materialIndexSort(a, b) {
  16875. return a.materialIndex - b.materialIndex;
  16876. }
  16877. faces.sort(materialIndexSort); // sort uvs
  16878. var uvs1 = this.faceVertexUvs[0];
  16879. var uvs2 = this.faceVertexUvs[1];
  16880. var newUvs1, newUvs2;
  16881. if (uvs1 && uvs1.length === length) newUvs1 = [];
  16882. if (uvs2 && uvs2.length === length) newUvs2 = [];
  16883. for (var _i11 = 0; _i11 < length; _i11++) {
  16884. var id = faces[_i11]._id;
  16885. if (newUvs1) newUvs1.push(uvs1[id]);
  16886. if (newUvs2) newUvs2.push(uvs2[id]);
  16887. }
  16888. if (newUvs1) this.faceVertexUvs[0] = newUvs1;
  16889. if (newUvs2) this.faceVertexUvs[1] = newUvs2;
  16890. },
  16891. toJSON: function toJSON() {
  16892. var data = {
  16893. metadata: {
  16894. version: 4.5,
  16895. type: 'Geometry',
  16896. generator: 'Geometry.toJSON'
  16897. }
  16898. }; // standard Geometry serialization
  16899. data.uuid = this.uuid;
  16900. data.type = this.type;
  16901. if (this.name !== '') data.name = this.name;
  16902. if (this.parameters !== undefined) {
  16903. var parameters = this.parameters;
  16904. for (var key in parameters) {
  16905. if (parameters[key] !== undefined) data[key] = parameters[key];
  16906. }
  16907. return data;
  16908. }
  16909. var vertices = [];
  16910. for (var i = 0; i < this.vertices.length; i++) {
  16911. var vertex = this.vertices[i];
  16912. vertices.push(vertex.x, vertex.y, vertex.z);
  16913. }
  16914. var faces = [];
  16915. var normals = [];
  16916. var normalsHash = {};
  16917. var colors = [];
  16918. var colorsHash = {};
  16919. var uvs = [];
  16920. var uvsHash = {};
  16921. for (var _i12 = 0; _i12 < this.faces.length; _i12++) {
  16922. var face = this.faces[_i12];
  16923. var hasMaterial = true;
  16924. var hasFaceUv = false; // deprecated
  16925. var hasFaceVertexUv = this.faceVertexUvs[0][_i12] !== undefined;
  16926. var hasFaceNormal = face.normal.length() > 0;
  16927. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  16928. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  16929. var hasFaceVertexColor = face.vertexColors.length > 0;
  16930. var faceType = 0;
  16931. faceType = setBit(faceType, 0, 0); // isQuad
  16932. faceType = setBit(faceType, 1, hasMaterial);
  16933. faceType = setBit(faceType, 2, hasFaceUv);
  16934. faceType = setBit(faceType, 3, hasFaceVertexUv);
  16935. faceType = setBit(faceType, 4, hasFaceNormal);
  16936. faceType = setBit(faceType, 5, hasFaceVertexNormal);
  16937. faceType = setBit(faceType, 6, hasFaceColor);
  16938. faceType = setBit(faceType, 7, hasFaceVertexColor);
  16939. faces.push(faceType);
  16940. faces.push(face.a, face.b, face.c);
  16941. faces.push(face.materialIndex);
  16942. if (hasFaceVertexUv) {
  16943. var faceVertexUvs = this.faceVertexUvs[0][_i12];
  16944. faces.push(getUvIndex(faceVertexUvs[0]), getUvIndex(faceVertexUvs[1]), getUvIndex(faceVertexUvs[2]));
  16945. }
  16946. if (hasFaceNormal) {
  16947. faces.push(getNormalIndex(face.normal));
  16948. }
  16949. if (hasFaceVertexNormal) {
  16950. var vertexNormals = face.vertexNormals;
  16951. faces.push(getNormalIndex(vertexNormals[0]), getNormalIndex(vertexNormals[1]), getNormalIndex(vertexNormals[2]));
  16952. }
  16953. if (hasFaceColor) {
  16954. faces.push(getColorIndex(face.color));
  16955. }
  16956. if (hasFaceVertexColor) {
  16957. var vertexColors = face.vertexColors;
  16958. faces.push(getColorIndex(vertexColors[0]), getColorIndex(vertexColors[1]), getColorIndex(vertexColors[2]));
  16959. }
  16960. }
  16961. function setBit(value, position, enabled) {
  16962. return enabled ? value | 1 << position : value & ~(1 << position);
  16963. }
  16964. function getNormalIndex(normal) {
  16965. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  16966. if (normalsHash[hash] !== undefined) {
  16967. return normalsHash[hash];
  16968. }
  16969. normalsHash[hash] = normals.length / 3;
  16970. normals.push(normal.x, normal.y, normal.z);
  16971. return normalsHash[hash];
  16972. }
  16973. function getColorIndex(color) {
  16974. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  16975. if (colorsHash[hash] !== undefined) {
  16976. return colorsHash[hash];
  16977. }
  16978. colorsHash[hash] = colors.length;
  16979. colors.push(color.getHex());
  16980. return colorsHash[hash];
  16981. }
  16982. function getUvIndex(uv) {
  16983. var hash = uv.x.toString() + uv.y.toString();
  16984. if (uvsHash[hash] !== undefined) {
  16985. return uvsHash[hash];
  16986. }
  16987. uvsHash[hash] = uvs.length / 2;
  16988. uvs.push(uv.x, uv.y);
  16989. return uvsHash[hash];
  16990. }
  16991. data.data = {};
  16992. data.data.vertices = vertices;
  16993. data.data.normals = normals;
  16994. if (colors.length > 0) data.data.colors = colors;
  16995. if (uvs.length > 0) data.data.uvs = [uvs]; // temporal backward compatibility
  16996. data.data.faces = faces;
  16997. return data;
  16998. },
  16999. clone: function clone() {
  17000. /*
  17001. // Handle primitives
  17002. const parameters = this.parameters;
  17003. if ( parameters !== undefined ) {
  17004. const values = [];
  17005. for ( const key in parameters ) {
  17006. values.push( parameters[ key ] );
  17007. }
  17008. const geometry = Object.create( this.constructor.prototype );
  17009. this.constructor.apply( geometry, values );
  17010. return geometry;
  17011. }
  17012. return new this.constructor().copy( this );
  17013. */
  17014. return new Geometry().copy(this);
  17015. },
  17016. copy: function copy(source) {
  17017. // reset
  17018. this.vertices = [];
  17019. this.colors = [];
  17020. this.faces = [];
  17021. this.faceVertexUvs = [[]];
  17022. this.morphTargets = [];
  17023. this.morphNormals = [];
  17024. this.skinWeights = [];
  17025. this.skinIndices = [];
  17026. this.lineDistances = [];
  17027. this.boundingBox = null;
  17028. this.boundingSphere = null; // name
  17029. this.name = source.name; // vertices
  17030. var vertices = source.vertices;
  17031. for (var i = 0, il = vertices.length; i < il; i++) {
  17032. this.vertices.push(vertices[i].clone());
  17033. } // colors
  17034. var colors = source.colors;
  17035. for (var _i13 = 0, _il7 = colors.length; _i13 < _il7; _i13++) {
  17036. this.colors.push(colors[_i13].clone());
  17037. } // faces
  17038. var faces = source.faces;
  17039. for (var _i14 = 0, _il8 = faces.length; _i14 < _il8; _i14++) {
  17040. this.faces.push(faces[_i14].clone());
  17041. } // face vertex uvs
  17042. for (var _i15 = 0, _il9 = source.faceVertexUvs.length; _i15 < _il9; _i15++) {
  17043. var faceVertexUvs = source.faceVertexUvs[_i15];
  17044. if (this.faceVertexUvs[_i15] === undefined) {
  17045. this.faceVertexUvs[_i15] = [];
  17046. }
  17047. for (var j = 0, jl = faceVertexUvs.length; j < jl; j++) {
  17048. var uvs = faceVertexUvs[j],
  17049. uvsCopy = [];
  17050. for (var k = 0, kl = uvs.length; k < kl; k++) {
  17051. var uv = uvs[k];
  17052. uvsCopy.push(uv.clone());
  17053. }
  17054. this.faceVertexUvs[_i15].push(uvsCopy);
  17055. }
  17056. } // morph targets
  17057. var morphTargets = source.morphTargets;
  17058. for (var _i16 = 0, _il10 = morphTargets.length; _i16 < _il10; _i16++) {
  17059. var morphTarget = {};
  17060. morphTarget.name = morphTargets[_i16].name; // vertices
  17061. if (morphTargets[_i16].vertices !== undefined) {
  17062. morphTarget.vertices = [];
  17063. for (var _j3 = 0, _jl3 = morphTargets[_i16].vertices.length; _j3 < _jl3; _j3++) {
  17064. morphTarget.vertices.push(morphTargets[_i16].vertices[_j3].clone());
  17065. }
  17066. } // normals
  17067. if (morphTargets[_i16].normals !== undefined) {
  17068. morphTarget.normals = [];
  17069. for (var _j4 = 0, _jl4 = morphTargets[_i16].normals.length; _j4 < _jl4; _j4++) {
  17070. morphTarget.normals.push(morphTargets[_i16].normals[_j4].clone());
  17071. }
  17072. }
  17073. this.morphTargets.push(morphTarget);
  17074. } // morph normals
  17075. var morphNormals = source.morphNormals;
  17076. for (var _i17 = 0, _il11 = morphNormals.length; _i17 < _il11; _i17++) {
  17077. var morphNormal = {}; // vertex normals
  17078. if (morphNormals[_i17].vertexNormals !== undefined) {
  17079. morphNormal.vertexNormals = [];
  17080. for (var _j5 = 0, _jl5 = morphNormals[_i17].vertexNormals.length; _j5 < _jl5; _j5++) {
  17081. var srcVertexNormal = morphNormals[_i17].vertexNormals[_j5];
  17082. var destVertexNormal = {};
  17083. destVertexNormal.a = srcVertexNormal.a.clone();
  17084. destVertexNormal.b = srcVertexNormal.b.clone();
  17085. destVertexNormal.c = srcVertexNormal.c.clone();
  17086. morphNormal.vertexNormals.push(destVertexNormal);
  17087. }
  17088. } // face normals
  17089. if (morphNormals[_i17].faceNormals !== undefined) {
  17090. morphNormal.faceNormals = [];
  17091. for (var _j6 = 0, _jl6 = morphNormals[_i17].faceNormals.length; _j6 < _jl6; _j6++) {
  17092. morphNormal.faceNormals.push(morphNormals[_i17].faceNormals[_j6].clone());
  17093. }
  17094. }
  17095. this.morphNormals.push(morphNormal);
  17096. } // skin weights
  17097. var skinWeights = source.skinWeights;
  17098. for (var _i18 = 0, _il12 = skinWeights.length; _i18 < _il12; _i18++) {
  17099. this.skinWeights.push(skinWeights[_i18].clone());
  17100. } // skin indices
  17101. var skinIndices = source.skinIndices;
  17102. for (var _i19 = 0, _il13 = skinIndices.length; _i19 < _il13; _i19++) {
  17103. this.skinIndices.push(skinIndices[_i19].clone());
  17104. } // line distances
  17105. var lineDistances = source.lineDistances;
  17106. for (var _i20 = 0, _il14 = lineDistances.length; _i20 < _il14; _i20++) {
  17107. this.lineDistances.push(lineDistances[_i20]);
  17108. } // bounding box
  17109. var boundingBox = source.boundingBox;
  17110. if (boundingBox !== null) {
  17111. this.boundingBox = boundingBox.clone();
  17112. } // bounding sphere
  17113. var boundingSphere = source.boundingSphere;
  17114. if (boundingSphere !== null) {
  17115. this.boundingSphere = boundingSphere.clone();
  17116. } // update flags
  17117. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17118. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17119. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17120. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17121. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17122. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17123. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17124. return this;
  17125. },
  17126. dispose: function dispose() {
  17127. this.dispatchEvent({
  17128. type: 'dispose'
  17129. });
  17130. }
  17131. });
  17132. var BoxGeometry = /*#__PURE__*/function (_Geometry) {
  17133. _inheritsLoose(BoxGeometry, _Geometry);
  17134. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  17135. var _this;
  17136. _this = _Geometry.call(this) || this;
  17137. _this.type = 'BoxGeometry';
  17138. _this.parameters = {
  17139. width: width,
  17140. height: height,
  17141. depth: depth,
  17142. widthSegments: widthSegments,
  17143. heightSegments: heightSegments,
  17144. depthSegments: depthSegments
  17145. };
  17146. _this.fromBufferGeometry(new BoxBufferGeometry(width, height, depth, widthSegments, heightSegments, depthSegments));
  17147. _this.mergeVertices();
  17148. return _this;
  17149. }
  17150. return BoxGeometry;
  17151. }(Geometry);
  17152. var CircleBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17153. _inheritsLoose(CircleBufferGeometry, _BufferGeometry);
  17154. function CircleBufferGeometry(radius, segments, thetaStart, thetaLength) {
  17155. var _this;
  17156. _this = _BufferGeometry.call(this) || this;
  17157. _this.type = 'CircleBufferGeometry';
  17158. _this.parameters = {
  17159. radius: radius,
  17160. segments: segments,
  17161. thetaStart: thetaStart,
  17162. thetaLength: thetaLength
  17163. };
  17164. radius = radius || 1;
  17165. segments = segments !== undefined ? Math.max(3, segments) : 8;
  17166. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17167. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17168. var indices = [];
  17169. var vertices = [];
  17170. var normals = [];
  17171. var uvs = []; // helper variables
  17172. var vertex = new Vector3();
  17173. var uv = new Vector2(); // center point
  17174. vertices.push(0, 0, 0);
  17175. normals.push(0, 0, 1);
  17176. uvs.push(0.5, 0.5);
  17177. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17178. var segment = thetaStart + s / segments * thetaLength; // vertex
  17179. vertex.x = radius * Math.cos(segment);
  17180. vertex.y = radius * Math.sin(segment);
  17181. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17182. normals.push(0, 0, 1); // uvs
  17183. uv.x = (vertices[i] / radius + 1) / 2;
  17184. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17185. uvs.push(uv.x, uv.y);
  17186. } // indices
  17187. for (var _i = 1; _i <= segments; _i++) {
  17188. indices.push(_i, _i + 1, 0);
  17189. } // build geometry
  17190. _this.setIndex(indices);
  17191. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17192. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17193. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17194. return _this;
  17195. }
  17196. return CircleBufferGeometry;
  17197. }(BufferGeometry);
  17198. var CircleGeometry = /*#__PURE__*/function (_Geometry) {
  17199. _inheritsLoose(CircleGeometry, _Geometry);
  17200. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17201. var _this;
  17202. _this = _Geometry.call(this) || this;
  17203. _this.type = 'CircleGeometry';
  17204. _this.parameters = {
  17205. radius: radius,
  17206. segments: segments,
  17207. thetaStart: thetaStart,
  17208. thetaLength: thetaLength
  17209. };
  17210. _this.fromBufferGeometry(new CircleBufferGeometry(radius, segments, thetaStart, thetaLength));
  17211. _this.mergeVertices();
  17212. return _this;
  17213. }
  17214. return CircleGeometry;
  17215. }(Geometry);
  17216. var CylinderBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17217. _inheritsLoose(CylinderBufferGeometry, _BufferGeometry);
  17218. function CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17219. var _this;
  17220. _this = _BufferGeometry.call(this) || this;
  17221. _this.type = 'CylinderBufferGeometry';
  17222. _this.parameters = {
  17223. radiusTop: radiusTop,
  17224. radiusBottom: radiusBottom,
  17225. height: height,
  17226. radialSegments: radialSegments,
  17227. heightSegments: heightSegments,
  17228. openEnded: openEnded,
  17229. thetaStart: thetaStart,
  17230. thetaLength: thetaLength
  17231. };
  17232. var scope = _assertThisInitialized(_this);
  17233. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17234. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17235. height = height || 1;
  17236. radialSegments = Math.floor(radialSegments) || 8;
  17237. heightSegments = Math.floor(heightSegments) || 1;
  17238. openEnded = openEnded !== undefined ? openEnded : false;
  17239. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17240. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; // buffers
  17241. var indices = [];
  17242. var vertices = [];
  17243. var normals = [];
  17244. var uvs = []; // helper variables
  17245. var index = 0;
  17246. var indexArray = [];
  17247. var halfHeight = height / 2;
  17248. var groupStart = 0; // generate geometry
  17249. generateTorso();
  17250. if (openEnded === false) {
  17251. if (radiusTop > 0) generateCap(true);
  17252. if (radiusBottom > 0) generateCap(false);
  17253. } // build geometry
  17254. _this.setIndex(indices);
  17255. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17256. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17257. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17258. function generateTorso() {
  17259. var normal = new Vector3();
  17260. var vertex = new Vector3();
  17261. var groupCount = 0; // this will be used to calculate the normal
  17262. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17263. for (var y = 0; y <= heightSegments; y++) {
  17264. var indexRow = [];
  17265. var v = y / heightSegments; // calculate the radius of the current row
  17266. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17267. for (var x = 0; x <= radialSegments; x++) {
  17268. var u = x / radialSegments;
  17269. var theta = u * thetaLength + thetaStart;
  17270. var sinTheta = Math.sin(theta);
  17271. var cosTheta = Math.cos(theta); // vertex
  17272. vertex.x = radius * sinTheta;
  17273. vertex.y = -v * height + halfHeight;
  17274. vertex.z = radius * cosTheta;
  17275. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17276. normal.set(sinTheta, slope, cosTheta).normalize();
  17277. normals.push(normal.x, normal.y, normal.z); // uv
  17278. uvs.push(u, 1 - v); // save index of vertex in respective row
  17279. indexRow.push(index++);
  17280. } // now save vertices of the row in our index array
  17281. indexArray.push(indexRow);
  17282. } // generate indices
  17283. for (var _x = 0; _x < radialSegments; _x++) {
  17284. for (var _y = 0; _y < heightSegments; _y++) {
  17285. // we use the index array to access the correct indices
  17286. var a = indexArray[_y][_x];
  17287. var b = indexArray[_y + 1][_x];
  17288. var c = indexArray[_y + 1][_x + 1];
  17289. var d = indexArray[_y][_x + 1]; // faces
  17290. indices.push(a, b, d);
  17291. indices.push(b, c, d); // update group counter
  17292. groupCount += 6;
  17293. }
  17294. } // add a group to the geometry. this will ensure multi material support
  17295. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17296. groupStart += groupCount;
  17297. }
  17298. function generateCap(top) {
  17299. // save the index of the first center vertex
  17300. var centerIndexStart = index;
  17301. var uv = new Vector2();
  17302. var vertex = new Vector3();
  17303. var groupCount = 0;
  17304. var radius = top === true ? radiusTop : radiusBottom;
  17305. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17306. // because the geometry needs one set of uvs per face,
  17307. // we must generate a center vertex per face/segment
  17308. for (var x = 1; x <= radialSegments; x++) {
  17309. // vertex
  17310. vertices.push(0, halfHeight * sign, 0); // normal
  17311. normals.push(0, sign, 0); // uv
  17312. uvs.push(0.5, 0.5); // increase index
  17313. index++;
  17314. } // save the index of the last center vertex
  17315. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17316. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17317. var u = _x2 / radialSegments;
  17318. var theta = u * thetaLength + thetaStart;
  17319. var cosTheta = Math.cos(theta);
  17320. var sinTheta = Math.sin(theta); // vertex
  17321. vertex.x = radius * sinTheta;
  17322. vertex.y = halfHeight * sign;
  17323. vertex.z = radius * cosTheta;
  17324. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17325. normals.push(0, sign, 0); // uv
  17326. uv.x = cosTheta * 0.5 + 0.5;
  17327. uv.y = sinTheta * 0.5 * sign + 0.5;
  17328. uvs.push(uv.x, uv.y); // increase index
  17329. index++;
  17330. } // generate indices
  17331. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17332. var c = centerIndexStart + _x3;
  17333. var i = centerIndexEnd + _x3;
  17334. if (top === true) {
  17335. // face top
  17336. indices.push(i, i + 1, c);
  17337. } else {
  17338. // face bottom
  17339. indices.push(i + 1, i, c);
  17340. }
  17341. groupCount += 3;
  17342. } // add a group to the geometry. this will ensure multi material support
  17343. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17344. groupStart += groupCount;
  17345. }
  17346. return _this;
  17347. }
  17348. return CylinderBufferGeometry;
  17349. }(BufferGeometry);
  17350. var CylinderGeometry = /*#__PURE__*/function (_Geometry) {
  17351. _inheritsLoose(CylinderGeometry, _Geometry);
  17352. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17353. var _this;
  17354. _this = _Geometry.call(this) || this;
  17355. _this.type = 'CylinderGeometry';
  17356. _this.parameters = {
  17357. radiusTop: radiusTop,
  17358. radiusBottom: radiusBottom,
  17359. height: height,
  17360. radialSegments: radialSegments,
  17361. heightSegments: heightSegments,
  17362. openEnded: openEnded,
  17363. thetaStart: thetaStart,
  17364. thetaLength: thetaLength
  17365. };
  17366. _this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength));
  17367. _this.mergeVertices();
  17368. return _this;
  17369. }
  17370. return CylinderGeometry;
  17371. }(Geometry);
  17372. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17373. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17374. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17375. var _this;
  17376. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17377. _this.type = 'ConeGeometry';
  17378. _this.parameters = {
  17379. radius: radius,
  17380. height: height,
  17381. radialSegments: radialSegments,
  17382. heightSegments: heightSegments,
  17383. openEnded: openEnded,
  17384. thetaStart: thetaStart,
  17385. thetaLength: thetaLength
  17386. };
  17387. return _this;
  17388. }
  17389. return ConeGeometry;
  17390. }(CylinderGeometry);
  17391. var ConeBufferGeometry = /*#__PURE__*/function (_CylinderBufferGeomet) {
  17392. _inheritsLoose(ConeBufferGeometry, _CylinderBufferGeomet);
  17393. function ConeBufferGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17394. var _this;
  17395. _this = _CylinderBufferGeomet.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17396. _this.type = 'ConeBufferGeometry';
  17397. _this.parameters = {
  17398. radius: radius,
  17399. height: height,
  17400. radialSegments: radialSegments,
  17401. heightSegments: heightSegments,
  17402. openEnded: openEnded,
  17403. thetaStart: thetaStart,
  17404. thetaLength: thetaLength
  17405. };
  17406. return _this;
  17407. }
  17408. return ConeBufferGeometry;
  17409. }(CylinderBufferGeometry);
  17410. var PolyhedronBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17411. _inheritsLoose(PolyhedronBufferGeometry, _BufferGeometry);
  17412. function PolyhedronBufferGeometry(vertices, indices, radius, detail) {
  17413. var _this;
  17414. _this = _BufferGeometry.call(this) || this;
  17415. _this.type = 'PolyhedronBufferGeometry';
  17416. _this.parameters = {
  17417. vertices: vertices,
  17418. indices: indices,
  17419. radius: radius,
  17420. detail: detail
  17421. };
  17422. radius = radius || 1;
  17423. detail = detail || 0; // default buffer data
  17424. var vertexBuffer = [];
  17425. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17426. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17427. applyRadius(radius); // finally, create the uv data
  17428. generateUVs(); // build non-indexed geometry
  17429. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17430. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17431. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17432. if (detail === 0) {
  17433. _this.computeVertexNormals(); // flat normals
  17434. } else {
  17435. _this.normalizeNormals(); // smooth normals
  17436. } // helper functions
  17437. function subdivide(detail) {
  17438. var a = new Vector3();
  17439. var b = new Vector3();
  17440. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17441. for (var i = 0; i < indices.length; i += 3) {
  17442. // get the vertices of the face
  17443. getVertexByIndex(indices[i + 0], a);
  17444. getVertexByIndex(indices[i + 1], b);
  17445. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17446. subdivideFace(a, b, c, detail);
  17447. }
  17448. }
  17449. function subdivideFace(a, b, c, detail) {
  17450. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17451. var v = []; // construct all of the vertices for this subdivision
  17452. for (var i = 0; i <= cols; i++) {
  17453. v[i] = [];
  17454. var aj = a.clone().lerp(c, i / cols);
  17455. var bj = b.clone().lerp(c, i / cols);
  17456. var rows = cols - i;
  17457. for (var j = 0; j <= rows; j++) {
  17458. if (j === 0 && i === cols) {
  17459. v[i][j] = aj;
  17460. } else {
  17461. v[i][j] = aj.clone().lerp(bj, j / rows);
  17462. }
  17463. }
  17464. } // construct all of the faces
  17465. for (var _i = 0; _i < cols; _i++) {
  17466. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17467. var k = Math.floor(_j / 2);
  17468. if (_j % 2 === 0) {
  17469. pushVertex(v[_i][k + 1]);
  17470. pushVertex(v[_i + 1][k]);
  17471. pushVertex(v[_i][k]);
  17472. } else {
  17473. pushVertex(v[_i][k + 1]);
  17474. pushVertex(v[_i + 1][k + 1]);
  17475. pushVertex(v[_i + 1][k]);
  17476. }
  17477. }
  17478. }
  17479. }
  17480. function applyRadius(radius) {
  17481. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17482. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17483. vertex.x = vertexBuffer[i + 0];
  17484. vertex.y = vertexBuffer[i + 1];
  17485. vertex.z = vertexBuffer[i + 2];
  17486. vertex.normalize().multiplyScalar(radius);
  17487. vertexBuffer[i + 0] = vertex.x;
  17488. vertexBuffer[i + 1] = vertex.y;
  17489. vertexBuffer[i + 2] = vertex.z;
  17490. }
  17491. }
  17492. function generateUVs() {
  17493. var vertex = new Vector3();
  17494. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17495. vertex.x = vertexBuffer[i + 0];
  17496. vertex.y = vertexBuffer[i + 1];
  17497. vertex.z = vertexBuffer[i + 2];
  17498. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17499. var v = inclination(vertex) / Math.PI + 0.5;
  17500. uvBuffer.push(u, 1 - v);
  17501. }
  17502. correctUVs();
  17503. correctSeam();
  17504. }
  17505. function correctSeam() {
  17506. // handle case when face straddles the seam, see #3269
  17507. for (var i = 0; i < uvBuffer.length; i += 6) {
  17508. // uv data of a single face
  17509. var x0 = uvBuffer[i + 0];
  17510. var x1 = uvBuffer[i + 2];
  17511. var x2 = uvBuffer[i + 4];
  17512. var max = Math.max(x0, x1, x2);
  17513. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17514. if (max > 0.9 && min < 0.1) {
  17515. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17516. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17517. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17518. }
  17519. }
  17520. }
  17521. function pushVertex(vertex) {
  17522. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17523. }
  17524. function getVertexByIndex(index, vertex) {
  17525. var stride = index * 3;
  17526. vertex.x = vertices[stride + 0];
  17527. vertex.y = vertices[stride + 1];
  17528. vertex.z = vertices[stride + 2];
  17529. }
  17530. function correctUVs() {
  17531. var a = new Vector3();
  17532. var b = new Vector3();
  17533. var c = new Vector3();
  17534. var centroid = new Vector3();
  17535. var uvA = new Vector2();
  17536. var uvB = new Vector2();
  17537. var uvC = new Vector2();
  17538. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17539. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17540. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17541. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17542. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17543. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17544. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17545. centroid.copy(a).add(b).add(c).divideScalar(3);
  17546. var azi = azimuth(centroid);
  17547. correctUV(uvA, j + 0, a, azi);
  17548. correctUV(uvB, j + 2, b, azi);
  17549. correctUV(uvC, j + 4, c, azi);
  17550. }
  17551. }
  17552. function correctUV(uv, stride, vector, azimuth) {
  17553. if (azimuth < 0 && uv.x === 1) {
  17554. uvBuffer[stride] = uv.x - 1;
  17555. }
  17556. if (vector.x === 0 && vector.z === 0) {
  17557. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17558. }
  17559. } // Angle around the Y axis, counter-clockwise when looking from above.
  17560. function azimuth(vector) {
  17561. return Math.atan2(vector.z, -vector.x);
  17562. } // Angle above the XZ plane.
  17563. function inclination(vector) {
  17564. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17565. }
  17566. return _this;
  17567. }
  17568. return PolyhedronBufferGeometry;
  17569. }(BufferGeometry);
  17570. var DodecahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  17571. _inheritsLoose(DodecahedronBufferGeometry, _PolyhedronBufferGeom);
  17572. function DodecahedronBufferGeometry(radius, detail) {
  17573. var _this;
  17574. var t = (1 + Math.sqrt(5)) / 2;
  17575. var r = 1 / t;
  17576. var vertices = [// (±1, ±1, ±1)
  17577. -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/φ, ±φ)
  17578. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17579. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17580. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17581. 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];
  17582. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  17583. _this.type = 'DodecahedronBufferGeometry';
  17584. _this.parameters = {
  17585. radius: radius,
  17586. detail: detail
  17587. };
  17588. return _this;
  17589. }
  17590. return DodecahedronBufferGeometry;
  17591. }(PolyhedronBufferGeometry);
  17592. var DodecahedronGeometry = /*#__PURE__*/function (_Geometry) {
  17593. _inheritsLoose(DodecahedronGeometry, _Geometry);
  17594. function DodecahedronGeometry(radius, detail) {
  17595. var _this;
  17596. _this = _Geometry.call(this) || this;
  17597. _this.type = 'DodecahedronGeometry';
  17598. _this.parameters = {
  17599. radius: radius,
  17600. detail: detail
  17601. };
  17602. _this.fromBufferGeometry(new DodecahedronBufferGeometry(radius, detail));
  17603. _this.mergeVertices();
  17604. return _this;
  17605. }
  17606. return DodecahedronGeometry;
  17607. }(Geometry);
  17608. var _v0$2 = new Vector3();
  17609. var _v1$5 = new Vector3();
  17610. var _normal$1 = new Vector3();
  17611. var _triangle = new Triangle();
  17612. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17613. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17614. function EdgesGeometry(geometry, thresholdAngle) {
  17615. var _this;
  17616. _this = _BufferGeometry.call(this) || this;
  17617. _this.type = 'EdgesGeometry';
  17618. _this.parameters = {
  17619. thresholdAngle: thresholdAngle
  17620. };
  17621. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17622. if (geometry.isGeometry) {
  17623. geometry = new BufferGeometry().fromGeometry(geometry);
  17624. }
  17625. var precisionPoints = 4;
  17626. var precision = Math.pow(10, precisionPoints);
  17627. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17628. var indexAttr = geometry.getIndex();
  17629. var positionAttr = geometry.getAttribute('position');
  17630. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17631. var indexArr = [0, 0, 0];
  17632. var vertKeys = ['a', 'b', 'c'];
  17633. var hashes = new Array(3);
  17634. var edgeData = {};
  17635. var vertices = [];
  17636. for (var i = 0; i < indexCount; i += 3) {
  17637. if (indexAttr) {
  17638. indexArr[0] = indexAttr.getX(i);
  17639. indexArr[1] = indexAttr.getX(i + 1);
  17640. indexArr[2] = indexAttr.getX(i + 2);
  17641. } else {
  17642. indexArr[0] = i;
  17643. indexArr[1] = i + 1;
  17644. indexArr[2] = i + 2;
  17645. }
  17646. var a = _triangle.a,
  17647. b = _triangle.b,
  17648. c = _triangle.c;
  17649. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17650. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17651. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17652. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17653. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17654. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17655. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17656. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17657. continue;
  17658. } // iterate over every edge
  17659. for (var j = 0; j < 3; j++) {
  17660. // get the first and next vertex making up the edge
  17661. var jNext = (j + 1) % 3;
  17662. var vecHash0 = hashes[j];
  17663. var vecHash1 = hashes[jNext];
  17664. var v0 = _triangle[vertKeys[j]];
  17665. var v1 = _triangle[vertKeys[jNext]];
  17666. var hash = vecHash0 + "_" + vecHash1;
  17667. var reverseHash = vecHash1 + "_" + vecHash0;
  17668. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17669. // if we found a sibling edge add it into the vertex array if
  17670. // it meets the angle threshold and delete the edge from the map.
  17671. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17672. vertices.push(v0.x, v0.y, v0.z);
  17673. vertices.push(v1.x, v1.y, v1.z);
  17674. }
  17675. edgeData[reverseHash] = null;
  17676. } else if (!(hash in edgeData)) {
  17677. // if we've already got an edge here then skip adding a new one
  17678. edgeData[hash] = {
  17679. index0: indexArr[j],
  17680. index1: indexArr[jNext],
  17681. normal: _normal$1.clone()
  17682. };
  17683. }
  17684. }
  17685. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17686. for (var key in edgeData) {
  17687. if (edgeData[key]) {
  17688. var _edgeData$key = edgeData[key],
  17689. index0 = _edgeData$key.index0,
  17690. index1 = _edgeData$key.index1;
  17691. _v0$2.fromBufferAttribute(positionAttr, index0);
  17692. _v1$5.fromBufferAttribute(positionAttr, index1);
  17693. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17694. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17695. }
  17696. }
  17697. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17698. return _this;
  17699. }
  17700. return EdgesGeometry;
  17701. }(BufferGeometry);
  17702. /**
  17703. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17704. */
  17705. var Earcut = {
  17706. triangulate: function triangulate(data, holeIndices, dim) {
  17707. dim = dim || 2;
  17708. var hasHoles = holeIndices && holeIndices.length;
  17709. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17710. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17711. var triangles = [];
  17712. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17713. var minX, minY, maxX, maxY, x, y, invSize;
  17714. 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
  17715. if (data.length > 80 * dim) {
  17716. minX = maxX = data[0];
  17717. minY = maxY = data[1];
  17718. for (var i = dim; i < outerLen; i += dim) {
  17719. x = data[i];
  17720. y = data[i + 1];
  17721. if (x < minX) minX = x;
  17722. if (y < minY) minY = y;
  17723. if (x > maxX) maxX = x;
  17724. if (y > maxY) maxY = y;
  17725. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17726. invSize = Math.max(maxX - minX, maxY - minY);
  17727. invSize = invSize !== 0 ? 1 / invSize : 0;
  17728. }
  17729. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17730. return triangles;
  17731. }
  17732. }; // create a circular doubly linked list from polygon points in the specified winding order
  17733. function linkedList(data, start, end, dim, clockwise) {
  17734. var i, last;
  17735. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17736. for (i = start; i < end; i += dim) {
  17737. last = insertNode(i, data[i], data[i + 1], last);
  17738. }
  17739. } else {
  17740. for (i = end - dim; i >= start; i -= dim) {
  17741. last = insertNode(i, data[i], data[i + 1], last);
  17742. }
  17743. }
  17744. if (last && equals(last, last.next)) {
  17745. removeNode(last);
  17746. last = last.next;
  17747. }
  17748. return last;
  17749. } // eliminate colinear or duplicate points
  17750. function filterPoints(start, end) {
  17751. if (!start) return start;
  17752. if (!end) end = start;
  17753. var p = start,
  17754. again;
  17755. do {
  17756. again = false;
  17757. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17758. removeNode(p);
  17759. p = end = p.prev;
  17760. if (p === p.next) break;
  17761. again = true;
  17762. } else {
  17763. p = p.next;
  17764. }
  17765. } while (again || p !== end);
  17766. return end;
  17767. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17768. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17769. if (!ear) return; // interlink polygon nodes in z-order
  17770. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17771. var stop = ear,
  17772. prev,
  17773. next; // iterate through ears, slicing them one by one
  17774. while (ear.prev !== ear.next) {
  17775. prev = ear.prev;
  17776. next = ear.next;
  17777. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17778. // cut off the triangle
  17779. triangles.push(prev.i / dim);
  17780. triangles.push(ear.i / dim);
  17781. triangles.push(next.i / dim);
  17782. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17783. ear = next.next;
  17784. stop = next.next;
  17785. continue;
  17786. }
  17787. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17788. if (ear === stop) {
  17789. // try filtering points and slicing again
  17790. if (!pass) {
  17791. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17792. } else if (pass === 1) {
  17793. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17794. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17795. } else if (pass === 2) {
  17796. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17797. }
  17798. break;
  17799. }
  17800. }
  17801. } // check whether a polygon node forms a valid ear with adjacent nodes
  17802. function isEar(ear) {
  17803. var a = ear.prev,
  17804. b = ear,
  17805. c = ear.next;
  17806. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17807. // now make sure we don't have other points inside the potential ear
  17808. var p = ear.next.next;
  17809. while (p !== ear.prev) {
  17810. 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;
  17811. p = p.next;
  17812. }
  17813. return true;
  17814. }
  17815. function isEarHashed(ear, minX, minY, invSize) {
  17816. var a = ear.prev,
  17817. b = ear,
  17818. c = ear.next;
  17819. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17820. // triangle bbox; min & max are calculated like this for speed
  17821. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17822. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17823. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17824. 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;
  17825. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17826. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17827. var p = ear.prevZ,
  17828. n = ear.nextZ; // look for points inside the triangle in both directions
  17829. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17830. 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;
  17831. p = p.prevZ;
  17832. 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;
  17833. n = n.nextZ;
  17834. } // look for remaining points in decreasing z-order
  17835. while (p && p.z >= minZ) {
  17836. 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;
  17837. p = p.prevZ;
  17838. } // look for remaining points in increasing z-order
  17839. while (n && n.z <= maxZ) {
  17840. 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;
  17841. n = n.nextZ;
  17842. }
  17843. return true;
  17844. } // go through all polygon nodes and cure small local self-intersections
  17845. function cureLocalIntersections(start, triangles, dim) {
  17846. var p = start;
  17847. do {
  17848. var a = p.prev,
  17849. b = p.next.next;
  17850. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17851. triangles.push(a.i / dim);
  17852. triangles.push(p.i / dim);
  17853. triangles.push(b.i / dim); // remove two nodes involved
  17854. removeNode(p);
  17855. removeNode(p.next);
  17856. p = start = b;
  17857. }
  17858. p = p.next;
  17859. } while (p !== start);
  17860. return filterPoints(p);
  17861. } // try splitting polygon into two and triangulate them independently
  17862. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17863. // look for a valid diagonal that divides the polygon into two
  17864. var a = start;
  17865. do {
  17866. var b = a.next.next;
  17867. while (b !== a.prev) {
  17868. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17869. // split the polygon in two by the diagonal
  17870. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17871. a = filterPoints(a, a.next);
  17872. c = filterPoints(c, c.next); // run earcut on each half
  17873. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17874. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17875. return;
  17876. }
  17877. b = b.next;
  17878. }
  17879. a = a.next;
  17880. } while (a !== start);
  17881. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17882. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17883. var queue = [];
  17884. var i, len, start, end, list;
  17885. for (i = 0, len = holeIndices.length; i < len; i++) {
  17886. start = holeIndices[i] * dim;
  17887. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17888. list = linkedList(data, start, end, dim, false);
  17889. if (list === list.next) list.steiner = true;
  17890. queue.push(getLeftmost(list));
  17891. }
  17892. queue.sort(compareX); // process holes from left to right
  17893. for (i = 0; i < queue.length; i++) {
  17894. eliminateHole(queue[i], outerNode);
  17895. outerNode = filterPoints(outerNode, outerNode.next);
  17896. }
  17897. return outerNode;
  17898. }
  17899. function compareX(a, b) {
  17900. return a.x - b.x;
  17901. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17902. function eliminateHole(hole, outerNode) {
  17903. outerNode = findHoleBridge(hole, outerNode);
  17904. if (outerNode) {
  17905. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17906. filterPoints(outerNode, outerNode.next);
  17907. filterPoints(b, b.next);
  17908. }
  17909. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17910. function findHoleBridge(hole, outerNode) {
  17911. var p = outerNode;
  17912. var hx = hole.x;
  17913. var hy = hole.y;
  17914. var qx = -Infinity,
  17915. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17916. // segment's endpoint with lesser x will be potential connection point
  17917. do {
  17918. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17919. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17920. if (x <= hx && x > qx) {
  17921. qx = x;
  17922. if (x === hx) {
  17923. if (hy === p.y) return p;
  17924. if (hy === p.next.y) return p.next;
  17925. }
  17926. m = p.x < p.next.x ? p : p.next;
  17927. }
  17928. }
  17929. p = p.next;
  17930. } while (p !== outerNode);
  17931. if (!m) return null;
  17932. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17933. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17934. // if there are no points found, we have a valid connection;
  17935. // otherwise choose the point of the minimum angle with the ray as connection point
  17936. var stop = m,
  17937. mx = m.x,
  17938. my = m.y;
  17939. var tanMin = Infinity,
  17940. tan;
  17941. p = m;
  17942. do {
  17943. 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)) {
  17944. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17945. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17946. m = p;
  17947. tanMin = tan;
  17948. }
  17949. }
  17950. p = p.next;
  17951. } while (p !== stop);
  17952. return m;
  17953. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17954. function sectorContainsSector(m, p) {
  17955. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17956. } // interlink polygon nodes in z-order
  17957. function indexCurve(start, minX, minY, invSize) {
  17958. var p = start;
  17959. do {
  17960. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17961. p.prevZ = p.prev;
  17962. p.nextZ = p.next;
  17963. p = p.next;
  17964. } while (p !== start);
  17965. p.prevZ.nextZ = null;
  17966. p.prevZ = null;
  17967. sortLinked(p);
  17968. } // Simon Tatham's linked list merge sort algorithm
  17969. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17970. function sortLinked(list) {
  17971. var i,
  17972. p,
  17973. q,
  17974. e,
  17975. tail,
  17976. numMerges,
  17977. pSize,
  17978. qSize,
  17979. inSize = 1;
  17980. do {
  17981. p = list;
  17982. list = null;
  17983. tail = null;
  17984. numMerges = 0;
  17985. while (p) {
  17986. numMerges++;
  17987. q = p;
  17988. pSize = 0;
  17989. for (i = 0; i < inSize; i++) {
  17990. pSize++;
  17991. q = q.nextZ;
  17992. if (!q) break;
  17993. }
  17994. qSize = inSize;
  17995. while (pSize > 0 || qSize > 0 && q) {
  17996. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  17997. e = p;
  17998. p = p.nextZ;
  17999. pSize--;
  18000. } else {
  18001. e = q;
  18002. q = q.nextZ;
  18003. qSize--;
  18004. }
  18005. if (tail) tail.nextZ = e;else list = e;
  18006. e.prevZ = tail;
  18007. tail = e;
  18008. }
  18009. p = q;
  18010. }
  18011. tail.nextZ = null;
  18012. inSize *= 2;
  18013. } while (numMerges > 1);
  18014. return list;
  18015. } // z-order of a point given coords and inverse of the longer side of data bbox
  18016. function zOrder(x, y, minX, minY, invSize) {
  18017. // coords are transformed into non-negative 15-bit integer range
  18018. x = 32767 * (x - minX) * invSize;
  18019. y = 32767 * (y - minY) * invSize;
  18020. x = (x | x << 8) & 0x00FF00FF;
  18021. x = (x | x << 4) & 0x0F0F0F0F;
  18022. x = (x | x << 2) & 0x33333333;
  18023. x = (x | x << 1) & 0x55555555;
  18024. y = (y | y << 8) & 0x00FF00FF;
  18025. y = (y | y << 4) & 0x0F0F0F0F;
  18026. y = (y | y << 2) & 0x33333333;
  18027. y = (y | y << 1) & 0x55555555;
  18028. return x | y << 1;
  18029. } // find the leftmost node of a polygon ring
  18030. function getLeftmost(start) {
  18031. var p = start,
  18032. leftmost = start;
  18033. do {
  18034. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18035. p = p.next;
  18036. } while (p !== start);
  18037. return leftmost;
  18038. } // check if a point lies within a convex triangle
  18039. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18040. 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;
  18041. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18042. function isValidDiagonal(a, b) {
  18043. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18044. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18045. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18046. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18047. } // signed area of a triangle
  18048. function area(p, q, r) {
  18049. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18050. } // check if two points are equal
  18051. function equals(p1, p2) {
  18052. return p1.x === p2.x && p1.y === p2.y;
  18053. } // check if two segments intersect
  18054. function intersects(p1, q1, p2, q2) {
  18055. var o1 = sign(area(p1, q1, p2));
  18056. var o2 = sign(area(p1, q1, q2));
  18057. var o3 = sign(area(p2, q2, p1));
  18058. var o4 = sign(area(p2, q2, q1));
  18059. if (o1 !== o2 && o3 !== o4) return true; // general case
  18060. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18061. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18062. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18063. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18064. return false;
  18065. } // for collinear points p, q, r, check if point q lies on segment pr
  18066. function onSegment(p, q, r) {
  18067. 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);
  18068. }
  18069. function sign(num) {
  18070. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18071. } // check if a polygon diagonal intersects any polygon segments
  18072. function intersectsPolygon(a, b) {
  18073. var p = a;
  18074. do {
  18075. 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;
  18076. p = p.next;
  18077. } while (p !== a);
  18078. return false;
  18079. } // check if a polygon diagonal is locally inside the polygon
  18080. function locallyInside(a, b) {
  18081. 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;
  18082. } // check if the middle point of a polygon diagonal is inside the polygon
  18083. function middleInside(a, b) {
  18084. var p = a,
  18085. inside = false;
  18086. var px = (a.x + b.x) / 2,
  18087. py = (a.y + b.y) / 2;
  18088. do {
  18089. 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;
  18090. p = p.next;
  18091. } while (p !== a);
  18092. return inside;
  18093. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18094. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18095. function splitPolygon(a, b) {
  18096. var a2 = new Node(a.i, a.x, a.y),
  18097. b2 = new Node(b.i, b.x, b.y),
  18098. an = a.next,
  18099. bp = b.prev;
  18100. a.next = b;
  18101. b.prev = a;
  18102. a2.next = an;
  18103. an.prev = a2;
  18104. b2.next = a2;
  18105. a2.prev = b2;
  18106. bp.next = b2;
  18107. b2.prev = bp;
  18108. return b2;
  18109. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18110. function insertNode(i, x, y, last) {
  18111. var p = new Node(i, x, y);
  18112. if (!last) {
  18113. p.prev = p;
  18114. p.next = p;
  18115. } else {
  18116. p.next = last.next;
  18117. p.prev = last;
  18118. last.next.prev = p;
  18119. last.next = p;
  18120. }
  18121. return p;
  18122. }
  18123. function removeNode(p) {
  18124. p.next.prev = p.prev;
  18125. p.prev.next = p.next;
  18126. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18127. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18128. }
  18129. function Node(i, x, y) {
  18130. // vertex index in coordinates array
  18131. this.i = i; // vertex coordinates
  18132. this.x = x;
  18133. this.y = y; // previous and next vertex nodes in a polygon ring
  18134. this.prev = null;
  18135. this.next = null; // z-order curve value
  18136. this.z = null; // previous and next nodes in z-order
  18137. this.prevZ = null;
  18138. this.nextZ = null; // indicates whether this is a steiner point
  18139. this.steiner = false;
  18140. }
  18141. function signedArea(data, start, end, dim) {
  18142. var sum = 0;
  18143. for (var i = start, j = end - dim; i < end; i += dim) {
  18144. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18145. j = i;
  18146. }
  18147. return sum;
  18148. }
  18149. var ShapeUtils = {
  18150. // calculate area of the contour polygon
  18151. area: function area(contour) {
  18152. var n = contour.length;
  18153. var a = 0.0;
  18154. for (var p = n - 1, q = 0; q < n; p = q++) {
  18155. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18156. }
  18157. return a * 0.5;
  18158. },
  18159. isClockWise: function isClockWise(pts) {
  18160. return ShapeUtils.area(pts) < 0;
  18161. },
  18162. triangulateShape: function triangulateShape(contour, holes) {
  18163. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18164. var holeIndices = []; // array of hole indices
  18165. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18166. removeDupEndPts(contour);
  18167. addContour(vertices, contour); //
  18168. var holeIndex = contour.length;
  18169. holes.forEach(removeDupEndPts);
  18170. for (var i = 0; i < holes.length; i++) {
  18171. holeIndices.push(holeIndex);
  18172. holeIndex += holes[i].length;
  18173. addContour(vertices, holes[i]);
  18174. } //
  18175. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18176. for (var _i = 0; _i < triangles.length; _i += 3) {
  18177. faces.push(triangles.slice(_i, _i + 3));
  18178. }
  18179. return faces;
  18180. }
  18181. };
  18182. function removeDupEndPts(points) {
  18183. var l = points.length;
  18184. if (l > 2 && points[l - 1].equals(points[0])) {
  18185. points.pop();
  18186. }
  18187. }
  18188. function addContour(vertices, contour) {
  18189. for (var i = 0; i < contour.length; i++) {
  18190. vertices.push(contour[i].x);
  18191. vertices.push(contour[i].y);
  18192. }
  18193. }
  18194. var ExtrudeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18195. _inheritsLoose(ExtrudeBufferGeometry, _BufferGeometry);
  18196. function ExtrudeBufferGeometry(shapes, options) {
  18197. var _this;
  18198. _this = _BufferGeometry.call(this) || this;
  18199. _this.type = 'ExtrudeBufferGeometry';
  18200. _this.parameters = {
  18201. shapes: shapes,
  18202. options: options
  18203. };
  18204. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18205. var scope = _assertThisInitialized(_this);
  18206. var verticesArray = [];
  18207. var uvArray = [];
  18208. for (var i = 0, l = shapes.length; i < l; i++) {
  18209. var shape = shapes[i];
  18210. addShape(shape);
  18211. } // build geometry
  18212. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18213. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18214. _this.computeVertexNormals(); // functions
  18215. function addShape(shape) {
  18216. var placeholder = []; // options
  18217. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18218. var steps = options.steps !== undefined ? options.steps : 1;
  18219. var depth = options.depth !== undefined ? options.depth : 100;
  18220. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18221. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18222. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18223. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18224. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18225. var extrudePath = options.extrudePath;
  18226. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18227. if (options.amount !== undefined) {
  18228. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18229. depth = options.amount;
  18230. } //
  18231. var extrudePts,
  18232. extrudeByPath = false;
  18233. var splineTube, binormal, normal, position2;
  18234. if (extrudePath) {
  18235. extrudePts = extrudePath.getSpacedPoints(steps);
  18236. extrudeByPath = true;
  18237. bevelEnabled = false; // bevels not supported for path extrusion
  18238. // SETUP TNB variables
  18239. // TODO1 - have a .isClosed in spline?
  18240. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18241. binormal = new Vector3();
  18242. normal = new Vector3();
  18243. position2 = new Vector3();
  18244. } // Safeguards if bevels are not enabled
  18245. if (!bevelEnabled) {
  18246. bevelSegments = 0;
  18247. bevelThickness = 0;
  18248. bevelSize = 0;
  18249. bevelOffset = 0;
  18250. } // Variables initialization
  18251. var shapePoints = shape.extractPoints(curveSegments);
  18252. var vertices = shapePoints.shape;
  18253. var holes = shapePoints.holes;
  18254. var reverse = !ShapeUtils.isClockWise(vertices);
  18255. if (reverse) {
  18256. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18257. for (var h = 0, hl = holes.length; h < hl; h++) {
  18258. var ahole = holes[h];
  18259. if (ShapeUtils.isClockWise(ahole)) {
  18260. holes[h] = ahole.reverse();
  18261. }
  18262. }
  18263. }
  18264. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18265. /* Vertices */
  18266. var contour = vertices; // vertices has all points but contour has only points of circumference
  18267. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18268. var _ahole = holes[_h];
  18269. vertices = vertices.concat(_ahole);
  18270. }
  18271. function scalePt2(pt, vec, size) {
  18272. if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
  18273. return vec.clone().multiplyScalar(size).add(pt);
  18274. }
  18275. var vlen = vertices.length,
  18276. flen = faces.length; // Find directions for point movement
  18277. function getBevelVec(inPt, inPrev, inNext) {
  18278. // computes for inPt the corresponding point inPt' on a new contour
  18279. // shifted by 1 unit (length of normalized vector) to the left
  18280. // if we walk along contour clockwise, this new contour is outside the old one
  18281. //
  18282. // inPt' is the intersection of the two lines parallel to the two
  18283. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18284. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18285. // good reading for geometry algorithms (here: line-line intersection)
  18286. // http://geomalgorithms.com/a05-_intersect-1.html
  18287. var v_prev_x = inPt.x - inPrev.x,
  18288. v_prev_y = inPt.y - inPrev.y;
  18289. var v_next_x = inNext.x - inPt.x,
  18290. v_next_y = inNext.y - inPt.y;
  18291. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18292. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18293. if (Math.abs(collinear0) > Number.EPSILON) {
  18294. // not collinear
  18295. // length of vectors for normalizing
  18296. var v_prev_len = Math.sqrt(v_prev_lensq);
  18297. 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
  18298. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18299. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18300. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18301. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18302. 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
  18303. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18304. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18305. // but prevent crazy spikes
  18306. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18307. if (v_trans_lensq <= 2) {
  18308. return new Vector2(v_trans_x, v_trans_y);
  18309. } else {
  18310. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18311. }
  18312. } else {
  18313. // handle special case of collinear edges
  18314. var direction_eq = false; // assumes: opposite
  18315. if (v_prev_x > Number.EPSILON) {
  18316. if (v_next_x > Number.EPSILON) {
  18317. direction_eq = true;
  18318. }
  18319. } else {
  18320. if (v_prev_x < -Number.EPSILON) {
  18321. if (v_next_x < -Number.EPSILON) {
  18322. direction_eq = true;
  18323. }
  18324. } else {
  18325. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18326. direction_eq = true;
  18327. }
  18328. }
  18329. }
  18330. if (direction_eq) {
  18331. // console.log("Warning: lines are a straight sequence");
  18332. v_trans_x = -v_prev_y;
  18333. v_trans_y = v_prev_x;
  18334. shrink_by = Math.sqrt(v_prev_lensq);
  18335. } else {
  18336. // console.log("Warning: lines are a straight spike");
  18337. v_trans_x = v_prev_x;
  18338. v_trans_y = v_prev_y;
  18339. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18340. }
  18341. }
  18342. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18343. }
  18344. var contourMovements = [];
  18345. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18346. if (j === il) j = 0;
  18347. if (k === il) k = 0; // (j)---(i)---(k)
  18348. // console.log('i,j,k', i, j , k)
  18349. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18350. }
  18351. var holesMovements = [];
  18352. var oneHoleMovements,
  18353. verticesMovements = contourMovements.concat();
  18354. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18355. var _ahole2 = holes[_h2];
  18356. oneHoleMovements = [];
  18357. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18358. if (_j === _il) _j = 0;
  18359. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18360. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18361. }
  18362. holesMovements.push(oneHoleMovements);
  18363. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18364. } // Loop bevelSegments, 1 for the front, 1 for the back
  18365. for (var b = 0; b < bevelSegments; b++) {
  18366. //for ( b = bevelSegments; b > 0; b -- ) {
  18367. var t = b / bevelSegments;
  18368. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18369. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18370. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18371. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18372. v(vert.x, vert.y, -z);
  18373. } // expand holes
  18374. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18375. var _ahole3 = holes[_h3];
  18376. oneHoleMovements = holesMovements[_h3];
  18377. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18378. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18379. v(_vert.x, _vert.y, -z);
  18380. }
  18381. }
  18382. }
  18383. var bs = bevelSize + bevelOffset; // Back facing vertices
  18384. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18385. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18386. if (!extrudeByPath) {
  18387. v(_vert2.x, _vert2.y, 0);
  18388. } else {
  18389. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18390. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18391. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18392. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18393. v(position2.x, position2.y, position2.z);
  18394. }
  18395. } // Add stepped vertices...
  18396. // Including front facing vertices
  18397. for (var s = 1; s <= steps; s++) {
  18398. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18399. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18400. if (!extrudeByPath) {
  18401. v(_vert3.x, _vert3.y, depth / steps * s);
  18402. } else {
  18403. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18404. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18405. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18406. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18407. v(position2.x, position2.y, position2.z);
  18408. }
  18409. }
  18410. } // Add bevel segments planes
  18411. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18412. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18413. var _t = _b / bevelSegments;
  18414. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18415. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18416. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18417. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18418. v(_vert4.x, _vert4.y, depth + _z);
  18419. } // expand holes
  18420. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18421. var _ahole4 = holes[_h4];
  18422. oneHoleMovements = holesMovements[_h4];
  18423. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18424. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18425. if (!extrudeByPath) {
  18426. v(_vert5.x, _vert5.y, depth + _z);
  18427. } else {
  18428. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18429. }
  18430. }
  18431. }
  18432. }
  18433. /* Faces */
  18434. // Top and bottom faces
  18435. buildLidFaces(); // Sides faces
  18436. buildSideFaces(); ///// Internal functions
  18437. function buildLidFaces() {
  18438. var start = verticesArray.length / 3;
  18439. if (bevelEnabled) {
  18440. var layer = 0; // steps + 1
  18441. var offset = vlen * layer; // Bottom faces
  18442. for (var _i9 = 0; _i9 < flen; _i9++) {
  18443. var face = faces[_i9];
  18444. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18445. }
  18446. layer = steps + bevelSegments * 2;
  18447. offset = vlen * layer; // Top faces
  18448. for (var _i10 = 0; _i10 < flen; _i10++) {
  18449. var _face = faces[_i10];
  18450. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18451. }
  18452. } else {
  18453. // Bottom faces
  18454. for (var _i11 = 0; _i11 < flen; _i11++) {
  18455. var _face2 = faces[_i11];
  18456. f3(_face2[2], _face2[1], _face2[0]);
  18457. } // Top faces
  18458. for (var _i12 = 0; _i12 < flen; _i12++) {
  18459. var _face3 = faces[_i12];
  18460. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18461. }
  18462. }
  18463. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18464. } // Create faces for the z-sides of the shape
  18465. function buildSideFaces() {
  18466. var start = verticesArray.length / 3;
  18467. var layeroffset = 0;
  18468. sidewalls(contour, layeroffset);
  18469. layeroffset += contour.length;
  18470. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18471. var _ahole5 = holes[_h5];
  18472. sidewalls(_ahole5, layeroffset); //, true
  18473. layeroffset += _ahole5.length;
  18474. }
  18475. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18476. }
  18477. function sidewalls(contour, layeroffset) {
  18478. var i = contour.length;
  18479. while (--i >= 0) {
  18480. var _j2 = i;
  18481. var _k2 = i - 1;
  18482. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18483. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18484. var slen1 = vlen * _s;
  18485. var slen2 = vlen * (_s + 1);
  18486. var a = layeroffset + _j2 + slen1,
  18487. _b2 = layeroffset + _k2 + slen1,
  18488. c = layeroffset + _k2 + slen2,
  18489. d = layeroffset + _j2 + slen2;
  18490. f4(a, _b2, c, d);
  18491. }
  18492. }
  18493. }
  18494. function v(x, y, z) {
  18495. placeholder.push(x);
  18496. placeholder.push(y);
  18497. placeholder.push(z);
  18498. }
  18499. function f3(a, b, c) {
  18500. addVertex(a);
  18501. addVertex(b);
  18502. addVertex(c);
  18503. var nextIndex = verticesArray.length / 3;
  18504. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18505. addUV(uvs[0]);
  18506. addUV(uvs[1]);
  18507. addUV(uvs[2]);
  18508. }
  18509. function f4(a, b, c, d) {
  18510. addVertex(a);
  18511. addVertex(b);
  18512. addVertex(d);
  18513. addVertex(b);
  18514. addVertex(c);
  18515. addVertex(d);
  18516. var nextIndex = verticesArray.length / 3;
  18517. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18518. addUV(uvs[0]);
  18519. addUV(uvs[1]);
  18520. addUV(uvs[3]);
  18521. addUV(uvs[1]);
  18522. addUV(uvs[2]);
  18523. addUV(uvs[3]);
  18524. }
  18525. function addVertex(index) {
  18526. verticesArray.push(placeholder[index * 3 + 0]);
  18527. verticesArray.push(placeholder[index * 3 + 1]);
  18528. verticesArray.push(placeholder[index * 3 + 2]);
  18529. }
  18530. function addUV(vector2) {
  18531. uvArray.push(vector2.x);
  18532. uvArray.push(vector2.y);
  18533. }
  18534. }
  18535. return _this;
  18536. }
  18537. var _proto = ExtrudeBufferGeometry.prototype;
  18538. _proto.toJSON = function toJSON() {
  18539. var data = BufferGeometry.prototype.toJSON.call(this);
  18540. var shapes = this.parameters.shapes;
  18541. var options = this.parameters.options;
  18542. return _toJSON(shapes, options, data);
  18543. };
  18544. return ExtrudeBufferGeometry;
  18545. }(BufferGeometry);
  18546. var WorldUVGenerator = {
  18547. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18548. var a_x = vertices[indexA * 3];
  18549. var a_y = vertices[indexA * 3 + 1];
  18550. var b_x = vertices[indexB * 3];
  18551. var b_y = vertices[indexB * 3 + 1];
  18552. var c_x = vertices[indexC * 3];
  18553. var c_y = vertices[indexC * 3 + 1];
  18554. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18555. },
  18556. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18557. var a_x = vertices[indexA * 3];
  18558. var a_y = vertices[indexA * 3 + 1];
  18559. var a_z = vertices[indexA * 3 + 2];
  18560. var b_x = vertices[indexB * 3];
  18561. var b_y = vertices[indexB * 3 + 1];
  18562. var b_z = vertices[indexB * 3 + 2];
  18563. var c_x = vertices[indexC * 3];
  18564. var c_y = vertices[indexC * 3 + 1];
  18565. var c_z = vertices[indexC * 3 + 2];
  18566. var d_x = vertices[indexD * 3];
  18567. var d_y = vertices[indexD * 3 + 1];
  18568. var d_z = vertices[indexD * 3 + 2];
  18569. if (Math.abs(a_y - b_y) < 0.01) {
  18570. 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)];
  18571. } else {
  18572. 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)];
  18573. }
  18574. }
  18575. };
  18576. function _toJSON(shapes, options, data) {
  18577. data.shapes = [];
  18578. if (Array.isArray(shapes)) {
  18579. for (var i = 0, l = shapes.length; i < l; i++) {
  18580. var shape = shapes[i];
  18581. data.shapes.push(shape.uuid);
  18582. }
  18583. } else {
  18584. data.shapes.push(shapes.uuid);
  18585. }
  18586. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18587. return data;
  18588. }
  18589. var ExtrudeGeometry = /*#__PURE__*/function (_Geometry) {
  18590. _inheritsLoose(ExtrudeGeometry, _Geometry);
  18591. function ExtrudeGeometry(shapes, options) {
  18592. var _this;
  18593. _this = _Geometry.call(this) || this;
  18594. _this.type = 'ExtrudeGeometry';
  18595. _this.parameters = {
  18596. shapes: shapes,
  18597. options: options
  18598. };
  18599. _this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes, options));
  18600. _this.mergeVertices();
  18601. return _this;
  18602. }
  18603. var _proto = ExtrudeGeometry.prototype;
  18604. _proto.toJSON = function toJSON() {
  18605. var data = _Geometry.prototype.toJSON.call(this);
  18606. var shapes = this.parameters.shapes;
  18607. var options = this.parameters.options;
  18608. return _toJSON$1(shapes, options, data);
  18609. };
  18610. return ExtrudeGeometry;
  18611. }(Geometry);
  18612. function _toJSON$1(shapes, options, data) {
  18613. data.shapes = [];
  18614. if (Array.isArray(shapes)) {
  18615. for (var i = 0, l = shapes.length; i < l; i++) {
  18616. var shape = shapes[i];
  18617. data.shapes.push(shape.uuid);
  18618. }
  18619. } else {
  18620. data.shapes.push(shapes.uuid);
  18621. }
  18622. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18623. return data;
  18624. }
  18625. var IcosahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18626. _inheritsLoose(IcosahedronBufferGeometry, _PolyhedronBufferGeom);
  18627. function IcosahedronBufferGeometry(radius, detail) {
  18628. var _this;
  18629. var t = (1 + Math.sqrt(5)) / 2;
  18630. 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];
  18631. 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];
  18632. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18633. _this.type = 'IcosahedronBufferGeometry';
  18634. _this.parameters = {
  18635. radius: radius,
  18636. detail: detail
  18637. };
  18638. return _this;
  18639. }
  18640. return IcosahedronBufferGeometry;
  18641. }(PolyhedronBufferGeometry);
  18642. var IcosahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18643. _inheritsLoose(IcosahedronGeometry, _Geometry);
  18644. function IcosahedronGeometry(radius, detail) {
  18645. var _this;
  18646. _this = _Geometry.call(this) || this;
  18647. _this.type = 'IcosahedronGeometry';
  18648. _this.parameters = {
  18649. radius: radius,
  18650. detail: detail
  18651. };
  18652. _this.fromBufferGeometry(new IcosahedronBufferGeometry(radius, detail));
  18653. _this.mergeVertices();
  18654. return _this;
  18655. }
  18656. return IcosahedronGeometry;
  18657. }(Geometry);
  18658. var LatheBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18659. _inheritsLoose(LatheBufferGeometry, _BufferGeometry);
  18660. function LatheBufferGeometry(points, segments, phiStart, phiLength) {
  18661. var _this;
  18662. _this = _BufferGeometry.call(this) || this;
  18663. _this.type = 'LatheBufferGeometry';
  18664. _this.parameters = {
  18665. points: points,
  18666. segments: segments,
  18667. phiStart: phiStart,
  18668. phiLength: phiLength
  18669. };
  18670. segments = Math.floor(segments) || 12;
  18671. phiStart = phiStart || 0;
  18672. phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ]
  18673. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18674. var indices = [];
  18675. var vertices = [];
  18676. var uvs = []; // helper variables
  18677. var inverseSegments = 1.0 / segments;
  18678. var vertex = new Vector3();
  18679. var uv = new Vector2(); // generate vertices and uvs
  18680. for (var i = 0; i <= segments; i++) {
  18681. var phi = phiStart + i * inverseSegments * phiLength;
  18682. var sin = Math.sin(phi);
  18683. var cos = Math.cos(phi);
  18684. for (var j = 0; j <= points.length - 1; j++) {
  18685. // vertex
  18686. vertex.x = points[j].x * sin;
  18687. vertex.y = points[j].y;
  18688. vertex.z = points[j].x * cos;
  18689. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18690. uv.x = i / segments;
  18691. uv.y = j / (points.length - 1);
  18692. uvs.push(uv.x, uv.y);
  18693. }
  18694. } // indices
  18695. for (var _i = 0; _i < segments; _i++) {
  18696. for (var _j = 0; _j < points.length - 1; _j++) {
  18697. var base = _j + _i * points.length;
  18698. var a = base;
  18699. var b = base + points.length;
  18700. var c = base + points.length + 1;
  18701. var d = base + 1; // faces
  18702. indices.push(a, b, d);
  18703. indices.push(b, c, d);
  18704. }
  18705. } // build geometry
  18706. _this.setIndex(indices);
  18707. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18708. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18709. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18710. // because the corresponding vertices are identical (but still have different UVs).
  18711. if (phiLength === Math.PI * 2) {
  18712. var normals = _this.attributes.normal.array;
  18713. var n1 = new Vector3();
  18714. var n2 = new Vector3();
  18715. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18716. var _base = segments * points.length * 3;
  18717. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18718. // select the normal of the vertex in the first line
  18719. n1.x = normals[_j2 + 0];
  18720. n1.y = normals[_j2 + 1];
  18721. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18722. n2.x = normals[_base + _j2 + 0];
  18723. n2.y = normals[_base + _j2 + 1];
  18724. n2.z = normals[_base + _j2 + 2]; // average normals
  18725. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18726. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18727. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18728. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18729. }
  18730. }
  18731. return _this;
  18732. }
  18733. return LatheBufferGeometry;
  18734. }(BufferGeometry);
  18735. var LatheGeometry = /*#__PURE__*/function (_Geometry) {
  18736. _inheritsLoose(LatheGeometry, _Geometry);
  18737. function LatheGeometry(points, segments, phiStart, phiLength) {
  18738. var _this;
  18739. _this = _Geometry.call(this) || this;
  18740. _this.type = 'LatheGeometry';
  18741. _this.parameters = {
  18742. points: points,
  18743. segments: segments,
  18744. phiStart: phiStart,
  18745. phiLength: phiLength
  18746. };
  18747. _this.fromBufferGeometry(new LatheBufferGeometry(points, segments, phiStart, phiLength));
  18748. _this.mergeVertices();
  18749. return _this;
  18750. }
  18751. return LatheGeometry;
  18752. }(Geometry);
  18753. var OctahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  18754. _inheritsLoose(OctahedronBufferGeometry, _PolyhedronBufferGeom);
  18755. function OctahedronBufferGeometry(radius, detail) {
  18756. var _this;
  18757. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18758. 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];
  18759. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  18760. _this.type = 'OctahedronBufferGeometry';
  18761. _this.parameters = {
  18762. radius: radius,
  18763. detail: detail
  18764. };
  18765. return _this;
  18766. }
  18767. return OctahedronBufferGeometry;
  18768. }(PolyhedronBufferGeometry);
  18769. var OctahedronGeometry = /*#__PURE__*/function (_Geometry) {
  18770. _inheritsLoose(OctahedronGeometry, _Geometry);
  18771. function OctahedronGeometry(radius, detail) {
  18772. var _this;
  18773. _this = _Geometry.call(this) || this;
  18774. _this.type = 'OctahedronGeometry';
  18775. _this.parameters = {
  18776. radius: radius,
  18777. detail: detail
  18778. };
  18779. _this.fromBufferGeometry(new OctahedronBufferGeometry(radius, detail));
  18780. _this.mergeVertices();
  18781. return _this;
  18782. }
  18783. return OctahedronGeometry;
  18784. }(Geometry);
  18785. /**
  18786. * Parametric Surfaces Geometry
  18787. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18788. */
  18789. function ParametricBufferGeometry(func, slices, stacks) {
  18790. BufferGeometry.call(this);
  18791. this.type = 'ParametricBufferGeometry';
  18792. this.parameters = {
  18793. func: func,
  18794. slices: slices,
  18795. stacks: stacks
  18796. }; // buffers
  18797. var indices = [];
  18798. var vertices = [];
  18799. var normals = [];
  18800. var uvs = [];
  18801. var EPS = 0.00001;
  18802. var normal = new Vector3();
  18803. var p0 = new Vector3(),
  18804. p1 = new Vector3();
  18805. var pu = new Vector3(),
  18806. pv = new Vector3();
  18807. if (func.length < 3) {
  18808. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18809. } // generate vertices, normals and uvs
  18810. var sliceCount = slices + 1;
  18811. for (var i = 0; i <= stacks; i++) {
  18812. var v = i / stacks;
  18813. for (var j = 0; j <= slices; j++) {
  18814. var u = j / slices; // vertex
  18815. func(u, v, p0);
  18816. vertices.push(p0.x, p0.y, p0.z); // normal
  18817. // approximate tangent vectors via finite differences
  18818. if (u - EPS >= 0) {
  18819. func(u - EPS, v, p1);
  18820. pu.subVectors(p0, p1);
  18821. } else {
  18822. func(u + EPS, v, p1);
  18823. pu.subVectors(p1, p0);
  18824. }
  18825. if (v - EPS >= 0) {
  18826. func(u, v - EPS, p1);
  18827. pv.subVectors(p0, p1);
  18828. } else {
  18829. func(u, v + EPS, p1);
  18830. pv.subVectors(p1, p0);
  18831. } // cross product of tangent vectors returns surface normal
  18832. normal.crossVectors(pu, pv).normalize();
  18833. normals.push(normal.x, normal.y, normal.z); // uv
  18834. uvs.push(u, v);
  18835. }
  18836. } // generate indices
  18837. for (var _i = 0; _i < stacks; _i++) {
  18838. for (var _j = 0; _j < slices; _j++) {
  18839. var a = _i * sliceCount + _j;
  18840. var b = _i * sliceCount + _j + 1;
  18841. var c = (_i + 1) * sliceCount + _j + 1;
  18842. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18843. indices.push(a, b, d);
  18844. indices.push(b, c, d);
  18845. }
  18846. } // build geometry
  18847. this.setIndex(indices);
  18848. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18849. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18850. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18851. }
  18852. ParametricBufferGeometry.prototype = Object.create(BufferGeometry.prototype);
  18853. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  18854. /**
  18855. * Parametric Surfaces Geometry
  18856. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18857. */
  18858. function ParametricGeometry(func, slices, stacks) {
  18859. Geometry.call(this);
  18860. this.type = 'ParametricGeometry';
  18861. this.parameters = {
  18862. func: func,
  18863. slices: slices,
  18864. stacks: stacks
  18865. };
  18866. this.fromBufferGeometry(new ParametricBufferGeometry(func, slices, stacks));
  18867. this.mergeVertices();
  18868. }
  18869. ParametricGeometry.prototype = Object.create(Geometry.prototype);
  18870. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18871. var PlaneGeometry = /*#__PURE__*/function (_Geometry) {
  18872. _inheritsLoose(PlaneGeometry, _Geometry);
  18873. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  18874. var _this;
  18875. _this = _Geometry.call(this) || this;
  18876. _this.type = 'PlaneGeometry';
  18877. _this.parameters = {
  18878. width: width,
  18879. height: height,
  18880. widthSegments: widthSegments,
  18881. heightSegments: heightSegments
  18882. };
  18883. _this.fromBufferGeometry(new PlaneBufferGeometry(width, height, widthSegments, heightSegments));
  18884. _this.mergeVertices();
  18885. return _this;
  18886. }
  18887. return PlaneGeometry;
  18888. }(Geometry);
  18889. var PolyhedronGeometry = /*#__PURE__*/function (_Geometry) {
  18890. _inheritsLoose(PolyhedronGeometry, _Geometry);
  18891. function PolyhedronGeometry(vertices, indices, radius, detail) {
  18892. var _this;
  18893. _this = _Geometry.call(this) || this;
  18894. _this.type = 'PolyhedronGeometry';
  18895. _this.parameters = {
  18896. vertices: vertices,
  18897. indices: indices,
  18898. radius: radius,
  18899. detail: detail
  18900. };
  18901. _this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices, indices, radius, detail));
  18902. _this.mergeVertices();
  18903. return _this;
  18904. }
  18905. return PolyhedronGeometry;
  18906. }(Geometry);
  18907. var RingBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18908. _inheritsLoose(RingBufferGeometry, _BufferGeometry);
  18909. function RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18910. var _this;
  18911. _this = _BufferGeometry.call(this) || this;
  18912. _this.type = 'RingBufferGeometry';
  18913. _this.parameters = {
  18914. innerRadius: innerRadius,
  18915. outerRadius: outerRadius,
  18916. thetaSegments: thetaSegments,
  18917. phiSegments: phiSegments,
  18918. thetaStart: thetaStart,
  18919. thetaLength: thetaLength
  18920. };
  18921. innerRadius = innerRadius || 0.5;
  18922. outerRadius = outerRadius || 1;
  18923. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18924. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18925. thetaSegments = thetaSegments !== undefined ? Math.max(3, thetaSegments) : 8;
  18926. phiSegments = phiSegments !== undefined ? Math.max(1, phiSegments) : 1; // buffers
  18927. var indices = [];
  18928. var vertices = [];
  18929. var normals = [];
  18930. var uvs = []; // some helper variables
  18931. var radius = innerRadius;
  18932. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18933. var vertex = new Vector3();
  18934. var uv = new Vector2(); // generate vertices, normals and uvs
  18935. for (var j = 0; j <= phiSegments; j++) {
  18936. for (var i = 0; i <= thetaSegments; i++) {
  18937. // values are generate from the inside of the ring to the outside
  18938. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18939. vertex.x = radius * Math.cos(segment);
  18940. vertex.y = radius * Math.sin(segment);
  18941. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18942. normals.push(0, 0, 1); // uv
  18943. uv.x = (vertex.x / outerRadius + 1) / 2;
  18944. uv.y = (vertex.y / outerRadius + 1) / 2;
  18945. uvs.push(uv.x, uv.y);
  18946. } // increase the radius for next row of vertices
  18947. radius += radiusStep;
  18948. } // indices
  18949. for (var _j = 0; _j < phiSegments; _j++) {
  18950. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18951. for (var _i = 0; _i < thetaSegments; _i++) {
  18952. var _segment = _i + thetaSegmentLevel;
  18953. var a = _segment;
  18954. var b = _segment + thetaSegments + 1;
  18955. var c = _segment + thetaSegments + 2;
  18956. var d = _segment + 1; // faces
  18957. indices.push(a, b, d);
  18958. indices.push(b, c, d);
  18959. }
  18960. } // build geometry
  18961. _this.setIndex(indices);
  18962. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18963. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18964. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18965. return _this;
  18966. }
  18967. return RingBufferGeometry;
  18968. }(BufferGeometry);
  18969. var RingGeometry = /*#__PURE__*/function (_Geometry) {
  18970. _inheritsLoose(RingGeometry, _Geometry);
  18971. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18972. var _this;
  18973. _this = _Geometry.call(this) || this;
  18974. _this.type = 'RingGeometry';
  18975. _this.parameters = {
  18976. innerRadius: innerRadius,
  18977. outerRadius: outerRadius,
  18978. thetaSegments: thetaSegments,
  18979. phiSegments: phiSegments,
  18980. thetaStart: thetaStart,
  18981. thetaLength: thetaLength
  18982. };
  18983. _this.fromBufferGeometry(new RingBufferGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength));
  18984. _this.mergeVertices();
  18985. return _this;
  18986. }
  18987. return RingGeometry;
  18988. }(Geometry);
  18989. var ShapeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18990. _inheritsLoose(ShapeBufferGeometry, _BufferGeometry);
  18991. function ShapeBufferGeometry(shapes, curveSegments) {
  18992. var _this;
  18993. _this = _BufferGeometry.call(this) || this;
  18994. _this.type = 'ShapeBufferGeometry';
  18995. _this.parameters = {
  18996. shapes: shapes,
  18997. curveSegments: curveSegments
  18998. };
  18999. curveSegments = curveSegments || 12; // buffers
  19000. var indices = [];
  19001. var vertices = [];
  19002. var normals = [];
  19003. var uvs = []; // helper variables
  19004. var groupStart = 0;
  19005. var groupCount = 0; // allow single and array values for "shapes" parameter
  19006. if (Array.isArray(shapes) === false) {
  19007. addShape(shapes);
  19008. } else {
  19009. for (var i = 0; i < shapes.length; i++) {
  19010. addShape(shapes[i]);
  19011. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19012. groupStart += groupCount;
  19013. groupCount = 0;
  19014. }
  19015. } // build geometry
  19016. _this.setIndex(indices);
  19017. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19018. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19019. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19020. function addShape(shape) {
  19021. var indexOffset = vertices.length / 3;
  19022. var points = shape.extractPoints(curveSegments);
  19023. var shapeVertices = points.shape;
  19024. var shapeHoles = points.holes; // check direction of vertices
  19025. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19026. shapeVertices = shapeVertices.reverse();
  19027. }
  19028. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19029. var shapeHole = shapeHoles[_i];
  19030. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19031. shapeHoles[_i] = shapeHole.reverse();
  19032. }
  19033. }
  19034. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19035. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19036. var _shapeHole = shapeHoles[_i2];
  19037. shapeVertices = shapeVertices.concat(_shapeHole);
  19038. } // vertices, normals, uvs
  19039. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19040. var vertex = shapeVertices[_i3];
  19041. vertices.push(vertex.x, vertex.y, 0);
  19042. normals.push(0, 0, 1);
  19043. uvs.push(vertex.x, vertex.y); // world uvs
  19044. } // incides
  19045. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19046. var face = faces[_i4];
  19047. var a = face[0] + indexOffset;
  19048. var b = face[1] + indexOffset;
  19049. var c = face[2] + indexOffset;
  19050. indices.push(a, b, c);
  19051. groupCount += 3;
  19052. }
  19053. }
  19054. return _this;
  19055. }
  19056. var _proto = ShapeBufferGeometry.prototype;
  19057. _proto.toJSON = function toJSON() {
  19058. var data = BufferGeometry.prototype.toJSON.call(this);
  19059. var shapes = this.parameters.shapes;
  19060. return _toJSON$2(shapes, data);
  19061. };
  19062. return ShapeBufferGeometry;
  19063. }(BufferGeometry);
  19064. function _toJSON$2(shapes, data) {
  19065. data.shapes = [];
  19066. if (Array.isArray(shapes)) {
  19067. for (var i = 0, l = shapes.length; i < l; i++) {
  19068. var shape = shapes[i];
  19069. data.shapes.push(shape.uuid);
  19070. }
  19071. } else {
  19072. data.shapes.push(shapes.uuid);
  19073. }
  19074. return data;
  19075. }
  19076. var ShapeGeometry = /*#__PURE__*/function (_Geometry) {
  19077. _inheritsLoose(ShapeGeometry, _Geometry);
  19078. function ShapeGeometry(shapes, curveSegments) {
  19079. var _this;
  19080. _this = _Geometry.call(this) || this;
  19081. _this.type = 'ShapeGeometry';
  19082. if (typeof curveSegments === 'object') {
  19083. console.warn('THREE.ShapeGeometry: Options parameter has been removed.');
  19084. curveSegments = curveSegments.curveSegments;
  19085. }
  19086. _this.parameters = {
  19087. shapes: shapes,
  19088. curveSegments: curveSegments
  19089. };
  19090. _this.fromBufferGeometry(new ShapeBufferGeometry(shapes, curveSegments));
  19091. _this.mergeVertices();
  19092. return _this;
  19093. }
  19094. var _proto = ShapeGeometry.prototype;
  19095. _proto.toJSON = function toJSON() {
  19096. var data = Geometry.prototype.toJSON.call(this);
  19097. var shapes = this.parameters.shapes;
  19098. return _toJSON$3(shapes, data);
  19099. };
  19100. return ShapeGeometry;
  19101. }(Geometry);
  19102. function _toJSON$3(shapes, data) {
  19103. data.shapes = [];
  19104. if (Array.isArray(shapes)) {
  19105. for (var i = 0, l = shapes.length; i < l; i++) {
  19106. var shape = shapes[i];
  19107. data.shapes.push(shape.uuid);
  19108. }
  19109. } else {
  19110. data.shapes.push(shapes.uuid);
  19111. }
  19112. return data;
  19113. }
  19114. var SphereBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19115. _inheritsLoose(SphereBufferGeometry, _BufferGeometry);
  19116. function SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19117. var _this;
  19118. _this = _BufferGeometry.call(this) || this;
  19119. _this.type = 'SphereBufferGeometry';
  19120. _this.parameters = {
  19121. radius: radius,
  19122. widthSegments: widthSegments,
  19123. heightSegments: heightSegments,
  19124. phiStart: phiStart,
  19125. phiLength: phiLength,
  19126. thetaStart: thetaStart,
  19127. thetaLength: thetaLength
  19128. };
  19129. radius = radius || 1;
  19130. widthSegments = Math.max(3, Math.floor(widthSegments) || 8);
  19131. heightSegments = Math.max(2, Math.floor(heightSegments) || 6);
  19132. phiStart = phiStart !== undefined ? phiStart : 0;
  19133. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19134. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19135. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19136. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19137. var index = 0;
  19138. var grid = [];
  19139. var vertex = new Vector3();
  19140. var normal = new Vector3(); // buffers
  19141. var indices = [];
  19142. var vertices = [];
  19143. var normals = [];
  19144. var uvs = []; // generate vertices, normals and uvs
  19145. for (var iy = 0; iy <= heightSegments; iy++) {
  19146. var verticesRow = [];
  19147. var v = iy / heightSegments; // special case for the poles
  19148. var uOffset = 0;
  19149. if (iy == 0 && thetaStart == 0) {
  19150. uOffset = 0.5 / widthSegments;
  19151. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19152. uOffset = -0.5 / widthSegments;
  19153. }
  19154. for (var ix = 0; ix <= widthSegments; ix++) {
  19155. var u = ix / widthSegments; // vertex
  19156. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19157. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19158. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19159. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19160. normal.copy(vertex).normalize();
  19161. normals.push(normal.x, normal.y, normal.z); // uv
  19162. uvs.push(u + uOffset, 1 - v);
  19163. verticesRow.push(index++);
  19164. }
  19165. grid.push(verticesRow);
  19166. } // indices
  19167. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19168. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19169. var a = grid[_iy][_ix + 1];
  19170. var b = grid[_iy][_ix];
  19171. var c = grid[_iy + 1][_ix];
  19172. var d = grid[_iy + 1][_ix + 1];
  19173. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19174. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19175. }
  19176. } // build geometry
  19177. _this.setIndex(indices);
  19178. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19179. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19180. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19181. return _this;
  19182. }
  19183. return SphereBufferGeometry;
  19184. }(BufferGeometry);
  19185. var SphereGeometry = /*#__PURE__*/function (_Geometry) {
  19186. _inheritsLoose(SphereGeometry, _Geometry);
  19187. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19188. var _this;
  19189. _this = _Geometry.call(this) || this;
  19190. _this.type = 'SphereGeometry';
  19191. _this.parameters = {
  19192. radius: radius,
  19193. widthSegments: widthSegments,
  19194. heightSegments: heightSegments,
  19195. phiStart: phiStart,
  19196. phiLength: phiLength,
  19197. thetaStart: thetaStart,
  19198. thetaLength: thetaLength
  19199. };
  19200. _this.fromBufferGeometry(new SphereBufferGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength));
  19201. _this.mergeVertices();
  19202. return _this;
  19203. }
  19204. return SphereGeometry;
  19205. }(Geometry);
  19206. var TetrahedronBufferGeometry = /*#__PURE__*/function (_PolyhedronBufferGeom) {
  19207. _inheritsLoose(TetrahedronBufferGeometry, _PolyhedronBufferGeom);
  19208. function TetrahedronBufferGeometry(radius, detail) {
  19209. var _this;
  19210. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19211. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19212. _this = _PolyhedronBufferGeom.call(this, vertices, indices, radius, detail) || this;
  19213. _this.type = 'TetrahedronBufferGeometry';
  19214. _this.parameters = {
  19215. radius: radius,
  19216. detail: detail
  19217. };
  19218. return _this;
  19219. }
  19220. return TetrahedronBufferGeometry;
  19221. }(PolyhedronBufferGeometry);
  19222. var TetrahedronGeometry = /*#__PURE__*/function (_Geometry) {
  19223. _inheritsLoose(TetrahedronGeometry, _Geometry);
  19224. function TetrahedronGeometry(radius, detail) {
  19225. var _this;
  19226. _this = _Geometry.call(this) || this;
  19227. _this.type = 'TetrahedronGeometry';
  19228. _this.parameters = {
  19229. radius: radius,
  19230. detail: detail
  19231. };
  19232. _this.fromBufferGeometry(new TetrahedronBufferGeometry(radius, detail));
  19233. _this.mergeVertices();
  19234. return _this;
  19235. }
  19236. return TetrahedronGeometry;
  19237. }(Geometry);
  19238. var TextBufferGeometry = /*#__PURE__*/function (_ExtrudeBufferGeometr) {
  19239. _inheritsLoose(TextBufferGeometry, _ExtrudeBufferGeometr);
  19240. function TextBufferGeometry(text, parameters) {
  19241. var _this;
  19242. parameters = parameters || {};
  19243. var font = parameters.font;
  19244. if (!(font && font.isFont)) {
  19245. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19246. return new BufferGeometry() || _assertThisInitialized(_this);
  19247. }
  19248. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19249. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19250. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19251. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19252. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19253. _this = _ExtrudeBufferGeometr.call(this, shapes, parameters) || this;
  19254. _this.type = 'TextBufferGeometry';
  19255. return _this;
  19256. }
  19257. return TextBufferGeometry;
  19258. }(ExtrudeBufferGeometry);
  19259. var TextGeometry = /*#__PURE__*/function (_Geometry) {
  19260. _inheritsLoose(TextGeometry, _Geometry);
  19261. function TextGeometry(text, parameters) {
  19262. var _this;
  19263. _this = _Geometry.call(this) || this;
  19264. _this.type = 'TextGeometry';
  19265. _this.parameters = {
  19266. text: text,
  19267. parameters: parameters
  19268. };
  19269. _this.fromBufferGeometry(new TextBufferGeometry(text, parameters));
  19270. _this.mergeVertices();
  19271. return _this;
  19272. }
  19273. return TextGeometry;
  19274. }(Geometry);
  19275. var TorusBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19276. _inheritsLoose(TorusBufferGeometry, _BufferGeometry);
  19277. function TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19278. var _this;
  19279. _this = _BufferGeometry.call(this) || this;
  19280. _this.type = 'TorusBufferGeometry';
  19281. _this.parameters = {
  19282. radius: radius,
  19283. tube: tube,
  19284. radialSegments: radialSegments,
  19285. tubularSegments: tubularSegments,
  19286. arc: arc
  19287. };
  19288. radius = radius || 1;
  19289. tube = tube || 0.4;
  19290. radialSegments = Math.floor(radialSegments) || 8;
  19291. tubularSegments = Math.floor(tubularSegments) || 6;
  19292. arc = arc || Math.PI * 2; // buffers
  19293. var indices = [];
  19294. var vertices = [];
  19295. var normals = [];
  19296. var uvs = []; // helper variables
  19297. var center = new Vector3();
  19298. var vertex = new Vector3();
  19299. var normal = new Vector3(); // generate vertices, normals and uvs
  19300. for (var j = 0; j <= radialSegments; j++) {
  19301. for (var i = 0; i <= tubularSegments; i++) {
  19302. var u = i / tubularSegments * arc;
  19303. var v = j / radialSegments * Math.PI * 2; // vertex
  19304. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19305. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19306. vertex.z = tube * Math.sin(v);
  19307. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19308. center.x = radius * Math.cos(u);
  19309. center.y = radius * Math.sin(u);
  19310. normal.subVectors(vertex, center).normalize();
  19311. normals.push(normal.x, normal.y, normal.z); // uv
  19312. uvs.push(i / tubularSegments);
  19313. uvs.push(j / radialSegments);
  19314. }
  19315. } // generate indices
  19316. for (var _j = 1; _j <= radialSegments; _j++) {
  19317. for (var _i = 1; _i <= tubularSegments; _i++) {
  19318. // indices
  19319. var a = (tubularSegments + 1) * _j + _i - 1;
  19320. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19321. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19322. var d = (tubularSegments + 1) * _j + _i; // faces
  19323. indices.push(a, b, d);
  19324. indices.push(b, c, d);
  19325. }
  19326. } // build geometry
  19327. _this.setIndex(indices);
  19328. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19329. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19330. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19331. return _this;
  19332. }
  19333. return TorusBufferGeometry;
  19334. }(BufferGeometry);
  19335. var TorusGeometry = /*#__PURE__*/function (_Geometry) {
  19336. _inheritsLoose(TorusGeometry, _Geometry);
  19337. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19338. var _this;
  19339. _this = _Geometry.call(this) || this;
  19340. _this.type = 'TorusGeometry';
  19341. _this.parameters = {
  19342. radius: radius,
  19343. tube: tube,
  19344. radialSegments: radialSegments,
  19345. tubularSegments: tubularSegments,
  19346. arc: arc
  19347. };
  19348. _this.fromBufferGeometry(new TorusBufferGeometry(radius, tube, radialSegments, tubularSegments, arc));
  19349. _this.mergeVertices();
  19350. return _this;
  19351. }
  19352. return TorusGeometry;
  19353. }(Geometry);
  19354. var TorusKnotBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19355. _inheritsLoose(TorusKnotBufferGeometry, _BufferGeometry);
  19356. function TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19357. var _this;
  19358. _this = _BufferGeometry.call(this) || this;
  19359. _this.type = 'TorusKnotBufferGeometry';
  19360. _this.parameters = {
  19361. radius: radius,
  19362. tube: tube,
  19363. tubularSegments: tubularSegments,
  19364. radialSegments: radialSegments,
  19365. p: p,
  19366. q: q
  19367. };
  19368. radius = radius || 1;
  19369. tube = tube || 0.4;
  19370. tubularSegments = Math.floor(tubularSegments) || 64;
  19371. radialSegments = Math.floor(radialSegments) || 8;
  19372. p = p || 2;
  19373. q = q || 3; // buffers
  19374. var indices = [];
  19375. var vertices = [];
  19376. var normals = [];
  19377. var uvs = []; // helper variables
  19378. var vertex = new Vector3();
  19379. var normal = new Vector3();
  19380. var P1 = new Vector3();
  19381. var P2 = new Vector3();
  19382. var B = new Vector3();
  19383. var T = new Vector3();
  19384. var N = new Vector3(); // generate vertices, normals and uvs
  19385. for (var i = 0; i <= tubularSegments; ++i) {
  19386. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19387. 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.
  19388. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19389. calculatePositionOnCurve(u, p, q, radius, P1);
  19390. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19391. T.subVectors(P2, P1);
  19392. N.addVectors(P2, P1);
  19393. B.crossVectors(T, N);
  19394. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19395. B.normalize();
  19396. N.normalize();
  19397. for (var j = 0; j <= radialSegments; ++j) {
  19398. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19399. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19400. var v = j / radialSegments * Math.PI * 2;
  19401. var cx = -tube * Math.cos(v);
  19402. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19403. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19404. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19405. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19406. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19407. 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)
  19408. normal.subVectors(vertex, P1).normalize();
  19409. normals.push(normal.x, normal.y, normal.z); // uv
  19410. uvs.push(i / tubularSegments);
  19411. uvs.push(j / radialSegments);
  19412. }
  19413. } // generate indices
  19414. for (var _j = 1; _j <= tubularSegments; _j++) {
  19415. for (var _i = 1; _i <= radialSegments; _i++) {
  19416. // indices
  19417. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19418. var b = (radialSegments + 1) * _j + (_i - 1);
  19419. var c = (radialSegments + 1) * _j + _i;
  19420. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19421. indices.push(a, b, d);
  19422. indices.push(b, c, d);
  19423. }
  19424. } // build geometry
  19425. _this.setIndex(indices);
  19426. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19427. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19428. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19429. function calculatePositionOnCurve(u, p, q, radius, position) {
  19430. var cu = Math.cos(u);
  19431. var su = Math.sin(u);
  19432. var quOverP = q / p * u;
  19433. var cs = Math.cos(quOverP);
  19434. position.x = radius * (2 + cs) * 0.5 * cu;
  19435. position.y = radius * (2 + cs) * su * 0.5;
  19436. position.z = radius * Math.sin(quOverP) * 0.5;
  19437. }
  19438. return _this;
  19439. }
  19440. return TorusKnotBufferGeometry;
  19441. }(BufferGeometry);
  19442. var TorusKnotGeometry = /*#__PURE__*/function (_Geometry) {
  19443. _inheritsLoose(TorusKnotGeometry, _Geometry);
  19444. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q, heightScale) {
  19445. var _this;
  19446. _this = _Geometry.call(this) || this;
  19447. _this.type = 'TorusKnotGeometry';
  19448. _this.parameters = {
  19449. radius: radius,
  19450. tube: tube,
  19451. tubularSegments: tubularSegments,
  19452. radialSegments: radialSegments,
  19453. p: p,
  19454. q: q
  19455. };
  19456. if (heightScale !== undefined) console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');
  19457. _this.fromBufferGeometry(new TorusKnotBufferGeometry(radius, tube, tubularSegments, radialSegments, p, q));
  19458. _this.mergeVertices();
  19459. return _this;
  19460. }
  19461. return TorusKnotGeometry;
  19462. }(Geometry);
  19463. var TubeBufferGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19464. _inheritsLoose(TubeBufferGeometry, _BufferGeometry);
  19465. function TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19466. var _this;
  19467. _this = _BufferGeometry.call(this) || this;
  19468. _this.type = 'TubeBufferGeometry';
  19469. _this.parameters = {
  19470. path: path,
  19471. tubularSegments: tubularSegments,
  19472. radius: radius,
  19473. radialSegments: radialSegments,
  19474. closed: closed
  19475. };
  19476. tubularSegments = tubularSegments || 64;
  19477. radius = radius || 1;
  19478. radialSegments = radialSegments || 8;
  19479. closed = closed || false;
  19480. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19481. _this.tangents = frames.tangents;
  19482. _this.normals = frames.normals;
  19483. _this.binormals = frames.binormals; // helper variables
  19484. var vertex = new Vector3();
  19485. var normal = new Vector3();
  19486. var uv = new Vector2();
  19487. var P = new Vector3(); // buffer
  19488. var vertices = [];
  19489. var normals = [];
  19490. var uvs = [];
  19491. var indices = []; // create buffer data
  19492. generateBufferData(); // build geometry
  19493. _this.setIndex(indices);
  19494. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19495. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19496. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19497. function generateBufferData() {
  19498. for (var i = 0; i < tubularSegments; i++) {
  19499. generateSegment(i);
  19500. } // if the geometry is not closed, generate the last row of vertices and normals
  19501. // at the regular position on the given path
  19502. //
  19503. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19504. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19505. // this makes it easy compute correct values for closed geometries
  19506. generateUVs(); // finally create faces
  19507. generateIndices();
  19508. }
  19509. function generateSegment(i) {
  19510. // we use getPointAt to sample evenly distributed points from the given path
  19511. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19512. var N = frames.normals[i];
  19513. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19514. for (var j = 0; j <= radialSegments; j++) {
  19515. var v = j / radialSegments * Math.PI * 2;
  19516. var sin = Math.sin(v);
  19517. var cos = -Math.cos(v); // normal
  19518. normal.x = cos * N.x + sin * B.x;
  19519. normal.y = cos * N.y + sin * B.y;
  19520. normal.z = cos * N.z + sin * B.z;
  19521. normal.normalize();
  19522. normals.push(normal.x, normal.y, normal.z); // vertex
  19523. vertex.x = P.x + radius * normal.x;
  19524. vertex.y = P.y + radius * normal.y;
  19525. vertex.z = P.z + radius * normal.z;
  19526. vertices.push(vertex.x, vertex.y, vertex.z);
  19527. }
  19528. }
  19529. function generateIndices() {
  19530. for (var j = 1; j <= tubularSegments; j++) {
  19531. for (var i = 1; i <= radialSegments; i++) {
  19532. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19533. var b = (radialSegments + 1) * j + (i - 1);
  19534. var c = (radialSegments + 1) * j + i;
  19535. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19536. indices.push(a, b, d);
  19537. indices.push(b, c, d);
  19538. }
  19539. }
  19540. }
  19541. function generateUVs() {
  19542. for (var i = 0; i <= tubularSegments; i++) {
  19543. for (var j = 0; j <= radialSegments; j++) {
  19544. uv.x = i / tubularSegments;
  19545. uv.y = j / radialSegments;
  19546. uvs.push(uv.x, uv.y);
  19547. }
  19548. }
  19549. }
  19550. return _this;
  19551. }
  19552. var _proto = TubeBufferGeometry.prototype;
  19553. _proto.toJSON = function toJSON() {
  19554. var data = BufferGeometry.prototype.toJSON.call(this);
  19555. data.path = this.parameters.path.toJSON();
  19556. return data;
  19557. };
  19558. return TubeBufferGeometry;
  19559. }(BufferGeometry);
  19560. var TubeGeometry = /*#__PURE__*/function (_Geometry) {
  19561. _inheritsLoose(TubeGeometry, _Geometry);
  19562. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed, taper) {
  19563. var _this;
  19564. _this = _Geometry.call(this) || this;
  19565. _this.type = 'TubeGeometry';
  19566. _this.parameters = {
  19567. path: path,
  19568. tubularSegments: tubularSegments,
  19569. radius: radius,
  19570. radialSegments: radialSegments,
  19571. closed: closed
  19572. };
  19573. if (taper !== undefined) console.warn('THREE.TubeGeometry: taper has been removed.');
  19574. var bufferGeometry = new TubeBufferGeometry(path, tubularSegments, radius, radialSegments, closed); // expose internals
  19575. _this.tangents = bufferGeometry.tangents;
  19576. _this.normals = bufferGeometry.normals;
  19577. _this.binormals = bufferGeometry.binormals; // create geometry
  19578. _this.fromBufferGeometry(bufferGeometry);
  19579. _this.mergeVertices();
  19580. return _this;
  19581. }
  19582. return TubeGeometry;
  19583. }(Geometry);
  19584. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19585. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19586. function WireframeGeometry(geometry) {
  19587. var _this;
  19588. _this = _BufferGeometry.call(this) || this;
  19589. _this.type = 'WireframeGeometry'; // buffer
  19590. var vertices = []; // helper variables
  19591. var edge = [0, 0],
  19592. edges = {};
  19593. var keys = ['a', 'b', 'c']; // different logic for Geometry and BufferGeometry
  19594. if (geometry && geometry.isGeometry) {
  19595. // create a data structure that contains all edges without duplicates
  19596. var faces = geometry.faces;
  19597. for (var i = 0, l = faces.length; i < l; i++) {
  19598. var face = faces[i];
  19599. for (var j = 0; j < 3; j++) {
  19600. var edge1 = face[keys[j]];
  19601. var edge2 = face[keys[(j + 1) % 3]];
  19602. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19603. edge[1] = Math.max(edge1, edge2);
  19604. var key = edge[0] + ',' + edge[1];
  19605. if (edges[key] === undefined) {
  19606. edges[key] = {
  19607. index1: edge[0],
  19608. index2: edge[1]
  19609. };
  19610. }
  19611. }
  19612. } // generate vertices
  19613. for (var _key in edges) {
  19614. var e = edges[_key];
  19615. var vertex = geometry.vertices[e.index1];
  19616. vertices.push(vertex.x, vertex.y, vertex.z);
  19617. vertex = geometry.vertices[e.index2];
  19618. vertices.push(vertex.x, vertex.y, vertex.z);
  19619. }
  19620. } else if (geometry && geometry.isBufferGeometry) {
  19621. var _vertex = new Vector3();
  19622. if (geometry.index !== null) {
  19623. // indexed BufferGeometry
  19624. var position = geometry.attributes.position;
  19625. var indices = geometry.index;
  19626. var groups = geometry.groups;
  19627. if (groups.length === 0) {
  19628. groups = [{
  19629. start: 0,
  19630. count: indices.count,
  19631. materialIndex: 0
  19632. }];
  19633. } // create a data structure that contains all eges without duplicates
  19634. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19635. var group = groups[o];
  19636. var start = group.start;
  19637. var count = group.count;
  19638. for (var _i = start, _l = start + count; _i < _l; _i += 3) {
  19639. for (var _j = 0; _j < 3; _j++) {
  19640. var _edge = indices.getX(_i + _j);
  19641. var _edge2 = indices.getX(_i + (_j + 1) % 3);
  19642. edge[0] = Math.min(_edge, _edge2); // sorting prevents duplicates
  19643. edge[1] = Math.max(_edge, _edge2);
  19644. var _key2 = edge[0] + ',' + edge[1];
  19645. if (edges[_key2] === undefined) {
  19646. edges[_key2] = {
  19647. index1: edge[0],
  19648. index2: edge[1]
  19649. };
  19650. }
  19651. }
  19652. }
  19653. } // generate vertices
  19654. for (var _key3 in edges) {
  19655. var _e = edges[_key3];
  19656. _vertex.fromBufferAttribute(position, _e.index1);
  19657. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19658. _vertex.fromBufferAttribute(position, _e.index2);
  19659. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19660. }
  19661. } else {
  19662. // non-indexed BufferGeometry
  19663. var _position = geometry.attributes.position;
  19664. for (var _i2 = 0, _l2 = _position.count / 3; _i2 < _l2; _i2++) {
  19665. for (var _j2 = 0; _j2 < 3; _j2++) {
  19666. // three edges per triangle, an edge is represented as (index1, index2)
  19667. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19668. var index1 = 3 * _i2 + _j2;
  19669. _vertex.fromBufferAttribute(_position, index1);
  19670. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19671. var index2 = 3 * _i2 + (_j2 + 1) % 3;
  19672. _vertex.fromBufferAttribute(_position, index2);
  19673. vertices.push(_vertex.x, _vertex.y, _vertex.z);
  19674. }
  19675. }
  19676. }
  19677. } // build geometry
  19678. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19679. return _this;
  19680. }
  19681. return WireframeGeometry;
  19682. }(BufferGeometry);
  19683. var Geometries = /*#__PURE__*/Object.freeze({
  19684. __proto__: null,
  19685. BoxGeometry: BoxGeometry,
  19686. BoxBufferGeometry: BoxBufferGeometry,
  19687. CircleGeometry: CircleGeometry,
  19688. CircleBufferGeometry: CircleBufferGeometry,
  19689. ConeGeometry: ConeGeometry,
  19690. ConeBufferGeometry: ConeBufferGeometry,
  19691. CylinderGeometry: CylinderGeometry,
  19692. CylinderBufferGeometry: CylinderBufferGeometry,
  19693. DodecahedronGeometry: DodecahedronGeometry,
  19694. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19695. EdgesGeometry: EdgesGeometry,
  19696. ExtrudeGeometry: ExtrudeGeometry,
  19697. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19698. IcosahedronGeometry: IcosahedronGeometry,
  19699. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19700. LatheGeometry: LatheGeometry,
  19701. LatheBufferGeometry: LatheBufferGeometry,
  19702. OctahedronGeometry: OctahedronGeometry,
  19703. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19704. ParametricGeometry: ParametricGeometry,
  19705. ParametricBufferGeometry: ParametricBufferGeometry,
  19706. PlaneGeometry: PlaneGeometry,
  19707. PlaneBufferGeometry: PlaneBufferGeometry,
  19708. PolyhedronGeometry: PolyhedronGeometry,
  19709. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19710. RingGeometry: RingGeometry,
  19711. RingBufferGeometry: RingBufferGeometry,
  19712. ShapeGeometry: ShapeGeometry,
  19713. ShapeBufferGeometry: ShapeBufferGeometry,
  19714. SphereGeometry: SphereGeometry,
  19715. SphereBufferGeometry: SphereBufferGeometry,
  19716. TetrahedronGeometry: TetrahedronGeometry,
  19717. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19718. TextGeometry: TextGeometry,
  19719. TextBufferGeometry: TextBufferGeometry,
  19720. TorusGeometry: TorusGeometry,
  19721. TorusBufferGeometry: TorusBufferGeometry,
  19722. TorusKnotGeometry: TorusKnotGeometry,
  19723. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19724. TubeGeometry: TubeGeometry,
  19725. TubeBufferGeometry: TubeBufferGeometry,
  19726. WireframeGeometry: WireframeGeometry
  19727. });
  19728. /**
  19729. * parameters = {
  19730. * color: <THREE.Color>
  19731. * }
  19732. */
  19733. function ShadowMaterial(parameters) {
  19734. Material.call(this);
  19735. this.type = 'ShadowMaterial';
  19736. this.color = new Color(0x000000);
  19737. this.transparent = true;
  19738. this.setValues(parameters);
  19739. }
  19740. ShadowMaterial.prototype = Object.create(Material.prototype);
  19741. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19742. ShadowMaterial.prototype.isShadowMaterial = true;
  19743. ShadowMaterial.prototype.copy = function (source) {
  19744. Material.prototype.copy.call(this, source);
  19745. this.color.copy(source.color);
  19746. return this;
  19747. };
  19748. function RawShaderMaterial(parameters) {
  19749. ShaderMaterial.call(this, parameters);
  19750. this.type = 'RawShaderMaterial';
  19751. }
  19752. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19753. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19754. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19755. /**
  19756. * parameters = {
  19757. * color: <hex>,
  19758. * roughness: <float>,
  19759. * metalness: <float>,
  19760. * opacity: <float>,
  19761. *
  19762. * map: new THREE.Texture( <Image> ),
  19763. *
  19764. * lightMap: new THREE.Texture( <Image> ),
  19765. * lightMapIntensity: <float>
  19766. *
  19767. * aoMap: new THREE.Texture( <Image> ),
  19768. * aoMapIntensity: <float>
  19769. *
  19770. * emissive: <hex>,
  19771. * emissiveIntensity: <float>
  19772. * emissiveMap: new THREE.Texture( <Image> ),
  19773. *
  19774. * bumpMap: new THREE.Texture( <Image> ),
  19775. * bumpScale: <float>,
  19776. *
  19777. * normalMap: new THREE.Texture( <Image> ),
  19778. * normalMapType: THREE.TangentSpaceNormalMap,
  19779. * normalScale: <Vector2>,
  19780. *
  19781. * displacementMap: new THREE.Texture( <Image> ),
  19782. * displacementScale: <float>,
  19783. * displacementBias: <float>,
  19784. *
  19785. * roughnessMap: new THREE.Texture( <Image> ),
  19786. *
  19787. * metalnessMap: new THREE.Texture( <Image> ),
  19788. *
  19789. * alphaMap: new THREE.Texture( <Image> ),
  19790. *
  19791. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19792. * envMapIntensity: <float>
  19793. *
  19794. * refractionRatio: <float>,
  19795. *
  19796. * wireframe: <boolean>,
  19797. * wireframeLinewidth: <float>,
  19798. *
  19799. * skinning: <bool>,
  19800. * morphTargets: <bool>,
  19801. * morphNormals: <bool>
  19802. * }
  19803. */
  19804. function MeshStandardMaterial(parameters) {
  19805. Material.call(this);
  19806. this.defines = {
  19807. 'STANDARD': ''
  19808. };
  19809. this.type = 'MeshStandardMaterial';
  19810. this.color = new Color(0xffffff); // diffuse
  19811. this.roughness = 1.0;
  19812. this.metalness = 0.0;
  19813. this.map = null;
  19814. this.lightMap = null;
  19815. this.lightMapIntensity = 1.0;
  19816. this.aoMap = null;
  19817. this.aoMapIntensity = 1.0;
  19818. this.emissive = new Color(0x000000);
  19819. this.emissiveIntensity = 1.0;
  19820. this.emissiveMap = null;
  19821. this.bumpMap = null;
  19822. this.bumpScale = 1;
  19823. this.normalMap = null;
  19824. this.normalMapType = TangentSpaceNormalMap;
  19825. this.normalScale = new Vector2(1, 1);
  19826. this.displacementMap = null;
  19827. this.displacementScale = 1;
  19828. this.displacementBias = 0;
  19829. this.roughnessMap = null;
  19830. this.metalnessMap = null;
  19831. this.alphaMap = null;
  19832. this.envMap = null;
  19833. this.envMapIntensity = 1.0;
  19834. this.refractionRatio = 0.98;
  19835. this.wireframe = false;
  19836. this.wireframeLinewidth = 1;
  19837. this.wireframeLinecap = 'round';
  19838. this.wireframeLinejoin = 'round';
  19839. this.skinning = false;
  19840. this.morphTargets = false;
  19841. this.morphNormals = false;
  19842. this.vertexTangents = false;
  19843. this.setValues(parameters);
  19844. }
  19845. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19846. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19847. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19848. MeshStandardMaterial.prototype.copy = function (source) {
  19849. Material.prototype.copy.call(this, source);
  19850. this.defines = {
  19851. 'STANDARD': ''
  19852. };
  19853. this.color.copy(source.color);
  19854. this.roughness = source.roughness;
  19855. this.metalness = source.metalness;
  19856. this.map = source.map;
  19857. this.lightMap = source.lightMap;
  19858. this.lightMapIntensity = source.lightMapIntensity;
  19859. this.aoMap = source.aoMap;
  19860. this.aoMapIntensity = source.aoMapIntensity;
  19861. this.emissive.copy(source.emissive);
  19862. this.emissiveMap = source.emissiveMap;
  19863. this.emissiveIntensity = source.emissiveIntensity;
  19864. this.bumpMap = source.bumpMap;
  19865. this.bumpScale = source.bumpScale;
  19866. this.normalMap = source.normalMap;
  19867. this.normalMapType = source.normalMapType;
  19868. this.normalScale.copy(source.normalScale);
  19869. this.displacementMap = source.displacementMap;
  19870. this.displacementScale = source.displacementScale;
  19871. this.displacementBias = source.displacementBias;
  19872. this.roughnessMap = source.roughnessMap;
  19873. this.metalnessMap = source.metalnessMap;
  19874. this.alphaMap = source.alphaMap;
  19875. this.envMap = source.envMap;
  19876. this.envMapIntensity = source.envMapIntensity;
  19877. this.refractionRatio = source.refractionRatio;
  19878. this.wireframe = source.wireframe;
  19879. this.wireframeLinewidth = source.wireframeLinewidth;
  19880. this.wireframeLinecap = source.wireframeLinecap;
  19881. this.wireframeLinejoin = source.wireframeLinejoin;
  19882. this.skinning = source.skinning;
  19883. this.morphTargets = source.morphTargets;
  19884. this.morphNormals = source.morphNormals;
  19885. this.vertexTangents = source.vertexTangents;
  19886. return this;
  19887. };
  19888. /**
  19889. * parameters = {
  19890. * clearcoat: <float>,
  19891. * clearcoatMap: new THREE.Texture( <Image> ),
  19892. * clearcoatRoughness: <float>,
  19893. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19894. * clearcoatNormalScale: <Vector2>,
  19895. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19896. *
  19897. * reflectivity: <float>,
  19898. * ior: <float>,
  19899. *
  19900. * sheen: <Color>,
  19901. *
  19902. * transmission: <float>,
  19903. * transmissionMap: new THREE.Texture( <Image> )
  19904. * }
  19905. */
  19906. function MeshPhysicalMaterial(parameters) {
  19907. MeshStandardMaterial.call(this);
  19908. this.defines = {
  19909. 'STANDARD': '',
  19910. 'PHYSICAL': ''
  19911. };
  19912. this.type = 'MeshPhysicalMaterial';
  19913. this.clearcoat = 0.0;
  19914. this.clearcoatMap = null;
  19915. this.clearcoatRoughness = 0.0;
  19916. this.clearcoatRoughnessMap = null;
  19917. this.clearcoatNormalScale = new Vector2(1, 1);
  19918. this.clearcoatNormalMap = null;
  19919. this.reflectivity = 0.5; // maps to F0 = 0.04
  19920. Object.defineProperty(this, 'ior', {
  19921. get: function get() {
  19922. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19923. },
  19924. set: function set(ior) {
  19925. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19926. }
  19927. });
  19928. this.sheen = null; // null will disable sheen bsdf
  19929. this.transmission = 0.0;
  19930. this.transmissionMap = null;
  19931. this.setValues(parameters);
  19932. }
  19933. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19934. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19935. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19936. MeshPhysicalMaterial.prototype.copy = function (source) {
  19937. MeshStandardMaterial.prototype.copy.call(this, source);
  19938. this.defines = {
  19939. 'STANDARD': '',
  19940. 'PHYSICAL': ''
  19941. };
  19942. this.clearcoat = source.clearcoat;
  19943. this.clearcoatMap = source.clearcoatMap;
  19944. this.clearcoatRoughness = source.clearcoatRoughness;
  19945. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19946. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19947. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19948. this.reflectivity = source.reflectivity;
  19949. if (source.sheen) {
  19950. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19951. } else {
  19952. this.sheen = null;
  19953. }
  19954. this.transmission = source.transmission;
  19955. this.transmissionMap = source.transmissionMap;
  19956. return this;
  19957. };
  19958. /**
  19959. * parameters = {
  19960. * color: <hex>,
  19961. * specular: <hex>,
  19962. * shininess: <float>,
  19963. * opacity: <float>,
  19964. *
  19965. * map: new THREE.Texture( <Image> ),
  19966. *
  19967. * lightMap: new THREE.Texture( <Image> ),
  19968. * lightMapIntensity: <float>
  19969. *
  19970. * aoMap: new THREE.Texture( <Image> ),
  19971. * aoMapIntensity: <float>
  19972. *
  19973. * emissive: <hex>,
  19974. * emissiveIntensity: <float>
  19975. * emissiveMap: new THREE.Texture( <Image> ),
  19976. *
  19977. * bumpMap: new THREE.Texture( <Image> ),
  19978. * bumpScale: <float>,
  19979. *
  19980. * normalMap: new THREE.Texture( <Image> ),
  19981. * normalMapType: THREE.TangentSpaceNormalMap,
  19982. * normalScale: <Vector2>,
  19983. *
  19984. * displacementMap: new THREE.Texture( <Image> ),
  19985. * displacementScale: <float>,
  19986. * displacementBias: <float>,
  19987. *
  19988. * specularMap: new THREE.Texture( <Image> ),
  19989. *
  19990. * alphaMap: new THREE.Texture( <Image> ),
  19991. *
  19992. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19993. * combine: THREE.MultiplyOperation,
  19994. * reflectivity: <float>,
  19995. * refractionRatio: <float>,
  19996. *
  19997. * wireframe: <boolean>,
  19998. * wireframeLinewidth: <float>,
  19999. *
  20000. * skinning: <bool>,
  20001. * morphTargets: <bool>,
  20002. * morphNormals: <bool>
  20003. * }
  20004. */
  20005. function MeshPhongMaterial(parameters) {
  20006. Material.call(this);
  20007. this.type = 'MeshPhongMaterial';
  20008. this.color = new Color(0xffffff); // diffuse
  20009. this.specular = new Color(0x111111);
  20010. this.shininess = 30;
  20011. this.map = null;
  20012. this.lightMap = null;
  20013. this.lightMapIntensity = 1.0;
  20014. this.aoMap = null;
  20015. this.aoMapIntensity = 1.0;
  20016. this.emissive = new Color(0x000000);
  20017. this.emissiveIntensity = 1.0;
  20018. this.emissiveMap = null;
  20019. this.bumpMap = null;
  20020. this.bumpScale = 1;
  20021. this.normalMap = null;
  20022. this.normalMapType = TangentSpaceNormalMap;
  20023. this.normalScale = new Vector2(1, 1);
  20024. this.displacementMap = null;
  20025. this.displacementScale = 1;
  20026. this.displacementBias = 0;
  20027. this.specularMap = null;
  20028. this.alphaMap = null;
  20029. this.envMap = null;
  20030. this.combine = MultiplyOperation;
  20031. this.reflectivity = 1;
  20032. this.refractionRatio = 0.98;
  20033. this.wireframe = false;
  20034. this.wireframeLinewidth = 1;
  20035. this.wireframeLinecap = 'round';
  20036. this.wireframeLinejoin = 'round';
  20037. this.skinning = false;
  20038. this.morphTargets = false;
  20039. this.morphNormals = false;
  20040. this.setValues(parameters);
  20041. }
  20042. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  20043. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20044. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20045. MeshPhongMaterial.prototype.copy = function (source) {
  20046. Material.prototype.copy.call(this, source);
  20047. this.color.copy(source.color);
  20048. this.specular.copy(source.specular);
  20049. this.shininess = source.shininess;
  20050. this.map = source.map;
  20051. this.lightMap = source.lightMap;
  20052. this.lightMapIntensity = source.lightMapIntensity;
  20053. this.aoMap = source.aoMap;
  20054. this.aoMapIntensity = source.aoMapIntensity;
  20055. this.emissive.copy(source.emissive);
  20056. this.emissiveMap = source.emissiveMap;
  20057. this.emissiveIntensity = source.emissiveIntensity;
  20058. this.bumpMap = source.bumpMap;
  20059. this.bumpScale = source.bumpScale;
  20060. this.normalMap = source.normalMap;
  20061. this.normalMapType = source.normalMapType;
  20062. this.normalScale.copy(source.normalScale);
  20063. this.displacementMap = source.displacementMap;
  20064. this.displacementScale = source.displacementScale;
  20065. this.displacementBias = source.displacementBias;
  20066. this.specularMap = source.specularMap;
  20067. this.alphaMap = source.alphaMap;
  20068. this.envMap = source.envMap;
  20069. this.combine = source.combine;
  20070. this.reflectivity = source.reflectivity;
  20071. this.refractionRatio = source.refractionRatio;
  20072. this.wireframe = source.wireframe;
  20073. this.wireframeLinewidth = source.wireframeLinewidth;
  20074. this.wireframeLinecap = source.wireframeLinecap;
  20075. this.wireframeLinejoin = source.wireframeLinejoin;
  20076. this.skinning = source.skinning;
  20077. this.morphTargets = source.morphTargets;
  20078. this.morphNormals = source.morphNormals;
  20079. return this;
  20080. };
  20081. /**
  20082. * parameters = {
  20083. * color: <hex>,
  20084. *
  20085. * map: new THREE.Texture( <Image> ),
  20086. * gradientMap: new THREE.Texture( <Image> ),
  20087. *
  20088. * lightMap: new THREE.Texture( <Image> ),
  20089. * lightMapIntensity: <float>
  20090. *
  20091. * aoMap: new THREE.Texture( <Image> ),
  20092. * aoMapIntensity: <float>
  20093. *
  20094. * emissive: <hex>,
  20095. * emissiveIntensity: <float>
  20096. * emissiveMap: new THREE.Texture( <Image> ),
  20097. *
  20098. * bumpMap: new THREE.Texture( <Image> ),
  20099. * bumpScale: <float>,
  20100. *
  20101. * normalMap: new THREE.Texture( <Image> ),
  20102. * normalMapType: THREE.TangentSpaceNormalMap,
  20103. * normalScale: <Vector2>,
  20104. *
  20105. * displacementMap: new THREE.Texture( <Image> ),
  20106. * displacementScale: <float>,
  20107. * displacementBias: <float>,
  20108. *
  20109. * alphaMap: new THREE.Texture( <Image> ),
  20110. *
  20111. * wireframe: <boolean>,
  20112. * wireframeLinewidth: <float>,
  20113. *
  20114. * skinning: <bool>,
  20115. * morphTargets: <bool>,
  20116. * morphNormals: <bool>
  20117. * }
  20118. */
  20119. function MeshToonMaterial(parameters) {
  20120. Material.call(this);
  20121. this.defines = {
  20122. 'TOON': ''
  20123. };
  20124. this.type = 'MeshToonMaterial';
  20125. this.color = new Color(0xffffff);
  20126. this.map = null;
  20127. this.gradientMap = null;
  20128. this.lightMap = null;
  20129. this.lightMapIntensity = 1.0;
  20130. this.aoMap = null;
  20131. this.aoMapIntensity = 1.0;
  20132. this.emissive = new Color(0x000000);
  20133. this.emissiveIntensity = 1.0;
  20134. this.emissiveMap = null;
  20135. this.bumpMap = null;
  20136. this.bumpScale = 1;
  20137. this.normalMap = null;
  20138. this.normalMapType = TangentSpaceNormalMap;
  20139. this.normalScale = new Vector2(1, 1);
  20140. this.displacementMap = null;
  20141. this.displacementScale = 1;
  20142. this.displacementBias = 0;
  20143. this.alphaMap = null;
  20144. this.wireframe = false;
  20145. this.wireframeLinewidth = 1;
  20146. this.wireframeLinecap = 'round';
  20147. this.wireframeLinejoin = 'round';
  20148. this.skinning = false;
  20149. this.morphTargets = false;
  20150. this.morphNormals = false;
  20151. this.setValues(parameters);
  20152. }
  20153. MeshToonMaterial.prototype = Object.create(Material.prototype);
  20154. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20155. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20156. MeshToonMaterial.prototype.copy = function (source) {
  20157. Material.prototype.copy.call(this, source);
  20158. this.color.copy(source.color);
  20159. this.map = source.map;
  20160. this.gradientMap = source.gradientMap;
  20161. this.lightMap = source.lightMap;
  20162. this.lightMapIntensity = source.lightMapIntensity;
  20163. this.aoMap = source.aoMap;
  20164. this.aoMapIntensity = source.aoMapIntensity;
  20165. this.emissive.copy(source.emissive);
  20166. this.emissiveMap = source.emissiveMap;
  20167. this.emissiveIntensity = source.emissiveIntensity;
  20168. this.bumpMap = source.bumpMap;
  20169. this.bumpScale = source.bumpScale;
  20170. this.normalMap = source.normalMap;
  20171. this.normalMapType = source.normalMapType;
  20172. this.normalScale.copy(source.normalScale);
  20173. this.displacementMap = source.displacementMap;
  20174. this.displacementScale = source.displacementScale;
  20175. this.displacementBias = source.displacementBias;
  20176. this.alphaMap = source.alphaMap;
  20177. this.wireframe = source.wireframe;
  20178. this.wireframeLinewidth = source.wireframeLinewidth;
  20179. this.wireframeLinecap = source.wireframeLinecap;
  20180. this.wireframeLinejoin = source.wireframeLinejoin;
  20181. this.skinning = source.skinning;
  20182. this.morphTargets = source.morphTargets;
  20183. this.morphNormals = source.morphNormals;
  20184. return this;
  20185. };
  20186. /**
  20187. * parameters = {
  20188. * opacity: <float>,
  20189. *
  20190. * bumpMap: new THREE.Texture( <Image> ),
  20191. * bumpScale: <float>,
  20192. *
  20193. * normalMap: new THREE.Texture( <Image> ),
  20194. * normalMapType: THREE.TangentSpaceNormalMap,
  20195. * normalScale: <Vector2>,
  20196. *
  20197. * displacementMap: new THREE.Texture( <Image> ),
  20198. * displacementScale: <float>,
  20199. * displacementBias: <float>,
  20200. *
  20201. * wireframe: <boolean>,
  20202. * wireframeLinewidth: <float>
  20203. *
  20204. * skinning: <bool>,
  20205. * morphTargets: <bool>,
  20206. * morphNormals: <bool>
  20207. * }
  20208. */
  20209. function MeshNormalMaterial(parameters) {
  20210. Material.call(this);
  20211. this.type = 'MeshNormalMaterial';
  20212. this.bumpMap = null;
  20213. this.bumpScale = 1;
  20214. this.normalMap = null;
  20215. this.normalMapType = TangentSpaceNormalMap;
  20216. this.normalScale = new Vector2(1, 1);
  20217. this.displacementMap = null;
  20218. this.displacementScale = 1;
  20219. this.displacementBias = 0;
  20220. this.wireframe = false;
  20221. this.wireframeLinewidth = 1;
  20222. this.fog = false;
  20223. this.skinning = false;
  20224. this.morphTargets = false;
  20225. this.morphNormals = false;
  20226. this.setValues(parameters);
  20227. }
  20228. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20229. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20230. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20231. MeshNormalMaterial.prototype.copy = function (source) {
  20232. Material.prototype.copy.call(this, source);
  20233. this.bumpMap = source.bumpMap;
  20234. this.bumpScale = source.bumpScale;
  20235. this.normalMap = source.normalMap;
  20236. this.normalMapType = source.normalMapType;
  20237. this.normalScale.copy(source.normalScale);
  20238. this.displacementMap = source.displacementMap;
  20239. this.displacementScale = source.displacementScale;
  20240. this.displacementBias = source.displacementBias;
  20241. this.wireframe = source.wireframe;
  20242. this.wireframeLinewidth = source.wireframeLinewidth;
  20243. this.skinning = source.skinning;
  20244. this.morphTargets = source.morphTargets;
  20245. this.morphNormals = source.morphNormals;
  20246. return this;
  20247. };
  20248. /**
  20249. * parameters = {
  20250. * color: <hex>,
  20251. * opacity: <float>,
  20252. *
  20253. * map: new THREE.Texture( <Image> ),
  20254. *
  20255. * lightMap: new THREE.Texture( <Image> ),
  20256. * lightMapIntensity: <float>
  20257. *
  20258. * aoMap: new THREE.Texture( <Image> ),
  20259. * aoMapIntensity: <float>
  20260. *
  20261. * emissive: <hex>,
  20262. * emissiveIntensity: <float>
  20263. * emissiveMap: new THREE.Texture( <Image> ),
  20264. *
  20265. * specularMap: new THREE.Texture( <Image> ),
  20266. *
  20267. * alphaMap: new THREE.Texture( <Image> ),
  20268. *
  20269. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20270. * combine: THREE.Multiply,
  20271. * reflectivity: <float>,
  20272. * refractionRatio: <float>,
  20273. *
  20274. * wireframe: <boolean>,
  20275. * wireframeLinewidth: <float>,
  20276. *
  20277. * skinning: <bool>,
  20278. * morphTargets: <bool>,
  20279. * morphNormals: <bool>
  20280. * }
  20281. */
  20282. function MeshLambertMaterial(parameters) {
  20283. Material.call(this);
  20284. this.type = 'MeshLambertMaterial';
  20285. this.color = new Color(0xffffff); // diffuse
  20286. this.map = null;
  20287. this.lightMap = null;
  20288. this.lightMapIntensity = 1.0;
  20289. this.aoMap = null;
  20290. this.aoMapIntensity = 1.0;
  20291. this.emissive = new Color(0x000000);
  20292. this.emissiveIntensity = 1.0;
  20293. this.emissiveMap = null;
  20294. this.specularMap = null;
  20295. this.alphaMap = null;
  20296. this.envMap = null;
  20297. this.combine = MultiplyOperation;
  20298. this.reflectivity = 1;
  20299. this.refractionRatio = 0.98;
  20300. this.wireframe = false;
  20301. this.wireframeLinewidth = 1;
  20302. this.wireframeLinecap = 'round';
  20303. this.wireframeLinejoin = 'round';
  20304. this.skinning = false;
  20305. this.morphTargets = false;
  20306. this.morphNormals = false;
  20307. this.setValues(parameters);
  20308. }
  20309. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20310. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20311. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20312. MeshLambertMaterial.prototype.copy = function (source) {
  20313. Material.prototype.copy.call(this, source);
  20314. this.color.copy(source.color);
  20315. this.map = source.map;
  20316. this.lightMap = source.lightMap;
  20317. this.lightMapIntensity = source.lightMapIntensity;
  20318. this.aoMap = source.aoMap;
  20319. this.aoMapIntensity = source.aoMapIntensity;
  20320. this.emissive.copy(source.emissive);
  20321. this.emissiveMap = source.emissiveMap;
  20322. this.emissiveIntensity = source.emissiveIntensity;
  20323. this.specularMap = source.specularMap;
  20324. this.alphaMap = source.alphaMap;
  20325. this.envMap = source.envMap;
  20326. this.combine = source.combine;
  20327. this.reflectivity = source.reflectivity;
  20328. this.refractionRatio = source.refractionRatio;
  20329. this.wireframe = source.wireframe;
  20330. this.wireframeLinewidth = source.wireframeLinewidth;
  20331. this.wireframeLinecap = source.wireframeLinecap;
  20332. this.wireframeLinejoin = source.wireframeLinejoin;
  20333. this.skinning = source.skinning;
  20334. this.morphTargets = source.morphTargets;
  20335. this.morphNormals = source.morphNormals;
  20336. return this;
  20337. };
  20338. /**
  20339. * parameters = {
  20340. * color: <hex>,
  20341. * opacity: <float>,
  20342. *
  20343. * matcap: new THREE.Texture( <Image> ),
  20344. *
  20345. * map: new THREE.Texture( <Image> ),
  20346. *
  20347. * bumpMap: new THREE.Texture( <Image> ),
  20348. * bumpScale: <float>,
  20349. *
  20350. * normalMap: new THREE.Texture( <Image> ),
  20351. * normalMapType: THREE.TangentSpaceNormalMap,
  20352. * normalScale: <Vector2>,
  20353. *
  20354. * displacementMap: new THREE.Texture( <Image> ),
  20355. * displacementScale: <float>,
  20356. * displacementBias: <float>,
  20357. *
  20358. * alphaMap: new THREE.Texture( <Image> ),
  20359. *
  20360. * skinning: <bool>,
  20361. * morphTargets: <bool>,
  20362. * morphNormals: <bool>
  20363. * }
  20364. */
  20365. function MeshMatcapMaterial(parameters) {
  20366. Material.call(this);
  20367. this.defines = {
  20368. 'MATCAP': ''
  20369. };
  20370. this.type = 'MeshMatcapMaterial';
  20371. this.color = new Color(0xffffff); // diffuse
  20372. this.matcap = null;
  20373. this.map = null;
  20374. this.bumpMap = null;
  20375. this.bumpScale = 1;
  20376. this.normalMap = null;
  20377. this.normalMapType = TangentSpaceNormalMap;
  20378. this.normalScale = new Vector2(1, 1);
  20379. this.displacementMap = null;
  20380. this.displacementScale = 1;
  20381. this.displacementBias = 0;
  20382. this.alphaMap = null;
  20383. this.skinning = false;
  20384. this.morphTargets = false;
  20385. this.morphNormals = false;
  20386. this.setValues(parameters);
  20387. }
  20388. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20389. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20390. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20391. MeshMatcapMaterial.prototype.copy = function (source) {
  20392. Material.prototype.copy.call(this, source);
  20393. this.defines = {
  20394. 'MATCAP': ''
  20395. };
  20396. this.color.copy(source.color);
  20397. this.matcap = source.matcap;
  20398. this.map = source.map;
  20399. this.bumpMap = source.bumpMap;
  20400. this.bumpScale = source.bumpScale;
  20401. this.normalMap = source.normalMap;
  20402. this.normalMapType = source.normalMapType;
  20403. this.normalScale.copy(source.normalScale);
  20404. this.displacementMap = source.displacementMap;
  20405. this.displacementScale = source.displacementScale;
  20406. this.displacementBias = source.displacementBias;
  20407. this.alphaMap = source.alphaMap;
  20408. this.skinning = source.skinning;
  20409. this.morphTargets = source.morphTargets;
  20410. this.morphNormals = source.morphNormals;
  20411. return this;
  20412. };
  20413. /**
  20414. * parameters = {
  20415. * color: <hex>,
  20416. * opacity: <float>,
  20417. *
  20418. * linewidth: <float>,
  20419. *
  20420. * scale: <float>,
  20421. * dashSize: <float>,
  20422. * gapSize: <float>
  20423. * }
  20424. */
  20425. function LineDashedMaterial(parameters) {
  20426. LineBasicMaterial.call(this);
  20427. this.type = 'LineDashedMaterial';
  20428. this.scale = 1;
  20429. this.dashSize = 3;
  20430. this.gapSize = 1;
  20431. this.setValues(parameters);
  20432. }
  20433. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20434. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20435. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20436. LineDashedMaterial.prototype.copy = function (source) {
  20437. LineBasicMaterial.prototype.copy.call(this, source);
  20438. this.scale = source.scale;
  20439. this.dashSize = source.dashSize;
  20440. this.gapSize = source.gapSize;
  20441. return this;
  20442. };
  20443. var Materials = /*#__PURE__*/Object.freeze({
  20444. __proto__: null,
  20445. ShadowMaterial: ShadowMaterial,
  20446. SpriteMaterial: SpriteMaterial,
  20447. RawShaderMaterial: RawShaderMaterial,
  20448. ShaderMaterial: ShaderMaterial,
  20449. PointsMaterial: PointsMaterial,
  20450. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20451. MeshStandardMaterial: MeshStandardMaterial,
  20452. MeshPhongMaterial: MeshPhongMaterial,
  20453. MeshToonMaterial: MeshToonMaterial,
  20454. MeshNormalMaterial: MeshNormalMaterial,
  20455. MeshLambertMaterial: MeshLambertMaterial,
  20456. MeshDepthMaterial: MeshDepthMaterial,
  20457. MeshDistanceMaterial: MeshDistanceMaterial,
  20458. MeshBasicMaterial: MeshBasicMaterial,
  20459. MeshMatcapMaterial: MeshMatcapMaterial,
  20460. LineDashedMaterial: LineDashedMaterial,
  20461. LineBasicMaterial: LineBasicMaterial,
  20462. Material: Material
  20463. });
  20464. var AnimationUtils = {
  20465. // same as Array.prototype.slice, but also works on typed arrays
  20466. arraySlice: function arraySlice(array, from, to) {
  20467. if (AnimationUtils.isTypedArray(array)) {
  20468. // in ios9 array.subarray(from, undefined) will return empty array
  20469. // but array.subarray(from) or array.subarray(from, len) is correct
  20470. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20471. }
  20472. return array.slice(from, to);
  20473. },
  20474. // converts an array to a specific type
  20475. convertArray: function convertArray(array, type, forceClone) {
  20476. if (!array || // let 'undefined' and 'null' pass
  20477. !forceClone && array.constructor === type) return array;
  20478. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20479. return new type(array); // create typed array
  20480. }
  20481. return Array.prototype.slice.call(array); // create Array
  20482. },
  20483. isTypedArray: function isTypedArray(object) {
  20484. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20485. },
  20486. // returns an array by which times and values can be sorted
  20487. getKeyframeOrder: function getKeyframeOrder(times) {
  20488. function compareTime(i, j) {
  20489. return times[i] - times[j];
  20490. }
  20491. var n = times.length;
  20492. var result = new Array(n);
  20493. for (var i = 0; i !== n; ++i) {
  20494. result[i] = i;
  20495. }
  20496. result.sort(compareTime);
  20497. return result;
  20498. },
  20499. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20500. sortedArray: function sortedArray(values, stride, order) {
  20501. var nValues = values.length;
  20502. var result = new values.constructor(nValues);
  20503. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20504. var srcOffset = order[i] * stride;
  20505. for (var j = 0; j !== stride; ++j) {
  20506. result[dstOffset++] = values[srcOffset + j];
  20507. }
  20508. }
  20509. return result;
  20510. },
  20511. // function for parsing AOS keyframe formats
  20512. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20513. var i = 1,
  20514. key = jsonKeys[0];
  20515. while (key !== undefined && key[valuePropertyName] === undefined) {
  20516. key = jsonKeys[i++];
  20517. }
  20518. if (key === undefined) return; // no data
  20519. var value = key[valuePropertyName];
  20520. if (value === undefined) return; // no data
  20521. if (Array.isArray(value)) {
  20522. do {
  20523. value = key[valuePropertyName];
  20524. if (value !== undefined) {
  20525. times.push(key.time);
  20526. values.push.apply(values, value); // push all elements
  20527. }
  20528. key = jsonKeys[i++];
  20529. } while (key !== undefined);
  20530. } else if (value.toArray !== undefined) {
  20531. // ...assume THREE.Math-ish
  20532. do {
  20533. value = key[valuePropertyName];
  20534. if (value !== undefined) {
  20535. times.push(key.time);
  20536. value.toArray(values, values.length);
  20537. }
  20538. key = jsonKeys[i++];
  20539. } while (key !== undefined);
  20540. } else {
  20541. // otherwise push as-is
  20542. do {
  20543. value = key[valuePropertyName];
  20544. if (value !== undefined) {
  20545. times.push(key.time);
  20546. values.push(value);
  20547. }
  20548. key = jsonKeys[i++];
  20549. } while (key !== undefined);
  20550. }
  20551. },
  20552. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20553. fps = fps || 30;
  20554. var clip = sourceClip.clone();
  20555. clip.name = name;
  20556. var tracks = [];
  20557. for (var i = 0; i < clip.tracks.length; ++i) {
  20558. var track = clip.tracks[i];
  20559. var valueSize = track.getValueSize();
  20560. var times = [];
  20561. var values = [];
  20562. for (var j = 0; j < track.times.length; ++j) {
  20563. var frame = track.times[j] * fps;
  20564. if (frame < startFrame || frame >= endFrame) continue;
  20565. times.push(track.times[j]);
  20566. for (var k = 0; k < valueSize; ++k) {
  20567. values.push(track.values[j * valueSize + k]);
  20568. }
  20569. }
  20570. if (times.length === 0) continue;
  20571. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20572. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20573. tracks.push(track);
  20574. }
  20575. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20576. var minStartTime = Infinity;
  20577. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20578. if (minStartTime > clip.tracks[_i].times[0]) {
  20579. minStartTime = clip.tracks[_i].times[0];
  20580. }
  20581. } // shift all tracks such that clip begins at t=0
  20582. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20583. clip.tracks[_i2].shift(-1 * minStartTime);
  20584. }
  20585. clip.resetDuration();
  20586. return clip;
  20587. },
  20588. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20589. if (referenceFrame === undefined) referenceFrame = 0;
  20590. if (referenceClip === undefined) referenceClip = targetClip;
  20591. if (fps === undefined || fps <= 0) fps = 30;
  20592. var numTracks = referenceClip.tracks.length;
  20593. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20594. var _loop = function _loop(i) {
  20595. var referenceTrack = referenceClip.tracks[i];
  20596. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20597. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20598. var targetTrack = targetClip.tracks.find(function (track) {
  20599. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20600. });
  20601. if (targetTrack === undefined) return "continue";
  20602. var referenceOffset = 0;
  20603. var referenceValueSize = referenceTrack.getValueSize();
  20604. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20605. referenceOffset = referenceValueSize / 3;
  20606. }
  20607. var targetOffset = 0;
  20608. var targetValueSize = targetTrack.getValueSize();
  20609. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20610. targetOffset = targetValueSize / 3;
  20611. }
  20612. var lastIndex = referenceTrack.times.length - 1;
  20613. var referenceValue = void 0; // Find the value to subtract out of the track
  20614. if (referenceTime <= referenceTrack.times[0]) {
  20615. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20616. var startIndex = referenceOffset;
  20617. var endIndex = referenceValueSize - referenceOffset;
  20618. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20619. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20620. // Reference frame is after the last keyframe, so just use the last keyframe
  20621. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20622. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20623. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20624. } else {
  20625. // Interpolate to the reference value
  20626. var interpolant = referenceTrack.createInterpolant();
  20627. var _startIndex2 = referenceOffset;
  20628. var _endIndex2 = referenceValueSize - referenceOffset;
  20629. interpolant.evaluate(referenceTime);
  20630. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20631. } // Conjugate the quaternion
  20632. if (referenceTrackType === 'quaternion') {
  20633. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20634. referenceQuat.toArray(referenceValue);
  20635. } // Subtract the reference value from all of the track values
  20636. var numTimes = targetTrack.times.length;
  20637. for (var j = 0; j < numTimes; ++j) {
  20638. var valueStart = j * targetValueSize + targetOffset;
  20639. if (referenceTrackType === 'quaternion') {
  20640. // Multiply the conjugate for quaternion track types
  20641. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20642. } else {
  20643. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20644. for (var k = 0; k < valueEnd; ++k) {
  20645. targetTrack.values[valueStart + k] -= referenceValue[k];
  20646. }
  20647. }
  20648. }
  20649. };
  20650. for (var i = 0; i < numTracks; ++i) {
  20651. var _ret = _loop(i);
  20652. if (_ret === "continue") continue;
  20653. }
  20654. targetClip.blendMode = AdditiveAnimationBlendMode;
  20655. return targetClip;
  20656. }
  20657. };
  20658. /**
  20659. * Abstract base class of interpolants over parametric samples.
  20660. *
  20661. * The parameter domain is one dimensional, typically the time or a path
  20662. * along a curve defined by the data.
  20663. *
  20664. * The sample values can have any dimensionality and derived classes may
  20665. * apply special interpretations to the data.
  20666. *
  20667. * This class provides the interval seek in a Template Method, deferring
  20668. * the actual interpolation to derived classes.
  20669. *
  20670. * Time complexity is O(1) for linear access crossing at most two points
  20671. * and O(log N) for random access, where N is the number of positions.
  20672. *
  20673. * References:
  20674. *
  20675. * http://www.oodesign.com/template-method-pattern.html
  20676. *
  20677. */
  20678. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20679. this.parameterPositions = parameterPositions;
  20680. this._cachedIndex = 0;
  20681. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20682. this.sampleValues = sampleValues;
  20683. this.valueSize = sampleSize;
  20684. }
  20685. Object.assign(Interpolant.prototype, {
  20686. evaluate: function evaluate(t) {
  20687. var pp = this.parameterPositions;
  20688. var i1 = this._cachedIndex,
  20689. t1 = pp[i1],
  20690. t0 = pp[i1 - 1];
  20691. validate_interval: {
  20692. seek: {
  20693. var right;
  20694. linear_scan: {
  20695. //- See http://jsperf.com/comparison-to-undefined/3
  20696. //- slower code:
  20697. //-
  20698. //- if ( t >= t1 || t1 === undefined ) {
  20699. forward_scan: if (!(t < t1)) {
  20700. for (var giveUpAt = i1 + 2;;) {
  20701. if (t1 === undefined) {
  20702. if (t < t0) break forward_scan; // after end
  20703. i1 = pp.length;
  20704. this._cachedIndex = i1;
  20705. return this.afterEnd_(i1 - 1, t, t0);
  20706. }
  20707. if (i1 === giveUpAt) break; // this loop
  20708. t0 = t1;
  20709. t1 = pp[++i1];
  20710. if (t < t1) {
  20711. // we have arrived at the sought interval
  20712. break seek;
  20713. }
  20714. } // prepare binary search on the right side of the index
  20715. right = pp.length;
  20716. break linear_scan;
  20717. } //- slower code:
  20718. //- if ( t < t0 || t0 === undefined ) {
  20719. if (!(t >= t0)) {
  20720. // looping?
  20721. var t1global = pp[1];
  20722. if (t < t1global) {
  20723. i1 = 2; // + 1, using the scan for the details
  20724. t0 = t1global;
  20725. } // linear reverse scan
  20726. for (var _giveUpAt = i1 - 2;;) {
  20727. if (t0 === undefined) {
  20728. // before start
  20729. this._cachedIndex = 0;
  20730. return this.beforeStart_(0, t, t1);
  20731. }
  20732. if (i1 === _giveUpAt) break; // this loop
  20733. t1 = t0;
  20734. t0 = pp[--i1 - 1];
  20735. if (t >= t0) {
  20736. // we have arrived at the sought interval
  20737. break seek;
  20738. }
  20739. } // prepare binary search on the left side of the index
  20740. right = i1;
  20741. i1 = 0;
  20742. break linear_scan;
  20743. } // the interval is valid
  20744. break validate_interval;
  20745. } // linear scan
  20746. // binary search
  20747. while (i1 < right) {
  20748. var mid = i1 + right >>> 1;
  20749. if (t < pp[mid]) {
  20750. right = mid;
  20751. } else {
  20752. i1 = mid + 1;
  20753. }
  20754. }
  20755. t1 = pp[i1];
  20756. t0 = pp[i1 - 1]; // check boundary cases, again
  20757. if (t0 === undefined) {
  20758. this._cachedIndex = 0;
  20759. return this.beforeStart_(0, t, t1);
  20760. }
  20761. if (t1 === undefined) {
  20762. i1 = pp.length;
  20763. this._cachedIndex = i1;
  20764. return this.afterEnd_(i1 - 1, t0, t);
  20765. }
  20766. } // seek
  20767. this._cachedIndex = i1;
  20768. this.intervalChanged_(i1, t0, t1);
  20769. } // validate_interval
  20770. return this.interpolate_(i1, t0, t, t1);
  20771. },
  20772. settings: null,
  20773. // optional, subclass-specific settings structure
  20774. // Note: The indirection allows central control of many interpolants.
  20775. // --- Protected interface
  20776. DefaultSettings_: {},
  20777. getSettings_: function getSettings_() {
  20778. return this.settings || this.DefaultSettings_;
  20779. },
  20780. copySampleValue_: function copySampleValue_(index) {
  20781. // copies a sample value to the result buffer
  20782. var result = this.resultBuffer,
  20783. values = this.sampleValues,
  20784. stride = this.valueSize,
  20785. offset = index * stride;
  20786. for (var i = 0; i !== stride; ++i) {
  20787. result[i] = values[offset + i];
  20788. }
  20789. return result;
  20790. },
  20791. // Template methods for derived classes:
  20792. interpolate_: function interpolate_()
  20793. /* i1, t0, t, t1 */
  20794. {
  20795. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20796. },
  20797. intervalChanged_: function intervalChanged_()
  20798. /* i1, t0, t1 */
  20799. {// empty
  20800. }
  20801. }); // DECLARE ALIAS AFTER assign prototype
  20802. Object.assign(Interpolant.prototype, {
  20803. //( 0, t, t0 ), returns this.resultBuffer
  20804. beforeStart_: Interpolant.prototype.copySampleValue_,
  20805. //( N-1, tN-1, t ), returns this.resultBuffer
  20806. afterEnd_: Interpolant.prototype.copySampleValue_
  20807. });
  20808. /**
  20809. * Fast and simple cubic spline interpolant.
  20810. *
  20811. * It was derived from a Hermitian construction setting the first derivative
  20812. * at each sample position to the linear slope between neighboring positions
  20813. * over their parameter interval.
  20814. */
  20815. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20816. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20817. this._weightPrev = -0;
  20818. this._offsetPrev = -0;
  20819. this._weightNext = -0;
  20820. this._offsetNext = -0;
  20821. }
  20822. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20823. constructor: CubicInterpolant,
  20824. DefaultSettings_: {
  20825. endingStart: ZeroCurvatureEnding,
  20826. endingEnd: ZeroCurvatureEnding
  20827. },
  20828. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20829. var pp = this.parameterPositions;
  20830. var iPrev = i1 - 2,
  20831. iNext = i1 + 1,
  20832. tPrev = pp[iPrev],
  20833. tNext = pp[iNext];
  20834. if (tPrev === undefined) {
  20835. switch (this.getSettings_().endingStart) {
  20836. case ZeroSlopeEnding:
  20837. // f'(t0) = 0
  20838. iPrev = i1;
  20839. tPrev = 2 * t0 - t1;
  20840. break;
  20841. case WrapAroundEnding:
  20842. // use the other end of the curve
  20843. iPrev = pp.length - 2;
  20844. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20845. break;
  20846. default:
  20847. // ZeroCurvatureEnding
  20848. // f''(t0) = 0 a.k.a. Natural Spline
  20849. iPrev = i1;
  20850. tPrev = t1;
  20851. }
  20852. }
  20853. if (tNext === undefined) {
  20854. switch (this.getSettings_().endingEnd) {
  20855. case ZeroSlopeEnding:
  20856. // f'(tN) = 0
  20857. iNext = i1;
  20858. tNext = 2 * t1 - t0;
  20859. break;
  20860. case WrapAroundEnding:
  20861. // use the other end of the curve
  20862. iNext = 1;
  20863. tNext = t1 + pp[1] - pp[0];
  20864. break;
  20865. default:
  20866. // ZeroCurvatureEnding
  20867. // f''(tN) = 0, a.k.a. Natural Spline
  20868. iNext = i1 - 1;
  20869. tNext = t0;
  20870. }
  20871. }
  20872. var halfDt = (t1 - t0) * 0.5,
  20873. stride = this.valueSize;
  20874. this._weightPrev = halfDt / (t0 - tPrev);
  20875. this._weightNext = halfDt / (tNext - t1);
  20876. this._offsetPrev = iPrev * stride;
  20877. this._offsetNext = iNext * stride;
  20878. },
  20879. interpolate_: function interpolate_(i1, t0, t, t1) {
  20880. var result = this.resultBuffer,
  20881. values = this.sampleValues,
  20882. stride = this.valueSize,
  20883. o1 = i1 * stride,
  20884. o0 = o1 - stride,
  20885. oP = this._offsetPrev,
  20886. oN = this._offsetNext,
  20887. wP = this._weightPrev,
  20888. wN = this._weightNext,
  20889. p = (t - t0) / (t1 - t0),
  20890. pp = p * p,
  20891. ppp = pp * p; // evaluate polynomials
  20892. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20893. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20894. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20895. var sN = wN * ppp - wN * pp; // combine data linearly
  20896. for (var i = 0; i !== stride; ++i) {
  20897. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20898. }
  20899. return result;
  20900. }
  20901. });
  20902. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20903. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20904. }
  20905. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20906. constructor: LinearInterpolant,
  20907. interpolate_: function interpolate_(i1, t0, t, t1) {
  20908. var result = this.resultBuffer,
  20909. values = this.sampleValues,
  20910. stride = this.valueSize,
  20911. offset1 = i1 * stride,
  20912. offset0 = offset1 - stride,
  20913. weight1 = (t - t0) / (t1 - t0),
  20914. weight0 = 1 - weight1;
  20915. for (var i = 0; i !== stride; ++i) {
  20916. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20917. }
  20918. return result;
  20919. }
  20920. });
  20921. /**
  20922. *
  20923. * Interpolant that evaluates to the sample value at the position preceeding
  20924. * the parameter.
  20925. */
  20926. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20927. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20928. }
  20929. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20930. constructor: DiscreteInterpolant,
  20931. interpolate_: function interpolate_(i1
  20932. /*, t0, t, t1 */
  20933. ) {
  20934. return this.copySampleValue_(i1 - 1);
  20935. }
  20936. });
  20937. function KeyframeTrack(name, times, values, interpolation) {
  20938. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20939. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20940. this.name = name;
  20941. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20942. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20943. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20944. } // Static methods
  20945. Object.assign(KeyframeTrack, {
  20946. // Serialization (in static context, because of constructor invocation
  20947. // and automatic invocation of .toJSON):
  20948. toJSON: function toJSON(track) {
  20949. var trackType = track.constructor;
  20950. var json; // derived classes can define a static toJSON method
  20951. if (trackType.toJSON !== undefined) {
  20952. json = trackType.toJSON(track);
  20953. } else {
  20954. // by default, we assume the data can be serialized as-is
  20955. json = {
  20956. 'name': track.name,
  20957. 'times': AnimationUtils.convertArray(track.times, Array),
  20958. 'values': AnimationUtils.convertArray(track.values, Array)
  20959. };
  20960. var interpolation = track.getInterpolation();
  20961. if (interpolation !== track.DefaultInterpolation) {
  20962. json.interpolation = interpolation;
  20963. }
  20964. }
  20965. json.type = track.ValueTypeName; // mandatory
  20966. return json;
  20967. }
  20968. });
  20969. Object.assign(KeyframeTrack.prototype, {
  20970. constructor: KeyframeTrack,
  20971. TimeBufferType: Float32Array,
  20972. ValueBufferType: Float32Array,
  20973. DefaultInterpolation: InterpolateLinear,
  20974. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20975. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20976. },
  20977. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20978. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20979. },
  20980. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20981. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20982. },
  20983. setInterpolation: function setInterpolation(interpolation) {
  20984. var factoryMethod;
  20985. switch (interpolation) {
  20986. case InterpolateDiscrete:
  20987. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20988. break;
  20989. case InterpolateLinear:
  20990. factoryMethod = this.InterpolantFactoryMethodLinear;
  20991. break;
  20992. case InterpolateSmooth:
  20993. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20994. break;
  20995. }
  20996. if (factoryMethod === undefined) {
  20997. var message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
  20998. if (this.createInterpolant === undefined) {
  20999. // fall back to default, unless the default itself is messed up
  21000. if (interpolation !== this.DefaultInterpolation) {
  21001. this.setInterpolation(this.DefaultInterpolation);
  21002. } else {
  21003. throw new Error(message); // fatal, in this case
  21004. }
  21005. }
  21006. console.warn('THREE.KeyframeTrack:', message);
  21007. return this;
  21008. }
  21009. this.createInterpolant = factoryMethod;
  21010. return this;
  21011. },
  21012. getInterpolation: function getInterpolation() {
  21013. switch (this.createInterpolant) {
  21014. case this.InterpolantFactoryMethodDiscrete:
  21015. return InterpolateDiscrete;
  21016. case this.InterpolantFactoryMethodLinear:
  21017. return InterpolateLinear;
  21018. case this.InterpolantFactoryMethodSmooth:
  21019. return InterpolateSmooth;
  21020. }
  21021. },
  21022. getValueSize: function getValueSize() {
  21023. return this.values.length / this.times.length;
  21024. },
  21025. // move all keyframes either forwards or backwards in time
  21026. shift: function shift(timeOffset) {
  21027. if (timeOffset !== 0.0) {
  21028. var times = this.times;
  21029. for (var i = 0, n = times.length; i !== n; ++i) {
  21030. times[i] += timeOffset;
  21031. }
  21032. }
  21033. return this;
  21034. },
  21035. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21036. scale: function scale(timeScale) {
  21037. if (timeScale !== 1.0) {
  21038. var times = this.times;
  21039. for (var i = 0, n = times.length; i !== n; ++i) {
  21040. times[i] *= timeScale;
  21041. }
  21042. }
  21043. return this;
  21044. },
  21045. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21046. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21047. trim: function trim(startTime, endTime) {
  21048. var times = this.times,
  21049. nKeys = times.length;
  21050. var from = 0,
  21051. to = nKeys - 1;
  21052. while (from !== nKeys && times[from] < startTime) {
  21053. ++from;
  21054. }
  21055. while (to !== -1 && times[to] > endTime) {
  21056. --to;
  21057. }
  21058. ++to; // inclusive -> exclusive bound
  21059. if (from !== 0 || to !== nKeys) {
  21060. // empty tracks are forbidden, so keep at least one keyframe
  21061. if (from >= to) {
  21062. to = Math.max(to, 1);
  21063. from = to - 1;
  21064. }
  21065. var stride = this.getValueSize();
  21066. this.times = AnimationUtils.arraySlice(times, from, to);
  21067. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21068. }
  21069. return this;
  21070. },
  21071. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21072. validate: function validate() {
  21073. var valid = true;
  21074. var valueSize = this.getValueSize();
  21075. if (valueSize - Math.floor(valueSize) !== 0) {
  21076. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21077. valid = false;
  21078. }
  21079. var times = this.times,
  21080. values = this.values,
  21081. nKeys = times.length;
  21082. if (nKeys === 0) {
  21083. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21084. valid = false;
  21085. }
  21086. var prevTime = null;
  21087. for (var i = 0; i !== nKeys; i++) {
  21088. var currTime = times[i];
  21089. if (typeof currTime === 'number' && isNaN(currTime)) {
  21090. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21091. valid = false;
  21092. break;
  21093. }
  21094. if (prevTime !== null && prevTime > currTime) {
  21095. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21096. valid = false;
  21097. break;
  21098. }
  21099. prevTime = currTime;
  21100. }
  21101. if (values !== undefined) {
  21102. if (AnimationUtils.isTypedArray(values)) {
  21103. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21104. var value = values[_i];
  21105. if (isNaN(value)) {
  21106. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21107. valid = false;
  21108. break;
  21109. }
  21110. }
  21111. }
  21112. }
  21113. return valid;
  21114. },
  21115. // removes equivalent sequential keys as common in morph target sequences
  21116. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21117. optimize: function optimize() {
  21118. // times or values may be shared with other tracks, so overwriting is unsafe
  21119. var times = AnimationUtils.arraySlice(this.times),
  21120. values = AnimationUtils.arraySlice(this.values),
  21121. stride = this.getValueSize(),
  21122. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21123. lastIndex = times.length - 1;
  21124. var writeIndex = 1;
  21125. for (var i = 1; i < lastIndex; ++i) {
  21126. var keep = false;
  21127. var time = times[i];
  21128. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21129. if (time !== timeNext && (i !== 1 || time !== time[0])) {
  21130. if (!smoothInterpolation) {
  21131. // remove unnecessary keyframes same as their neighbors
  21132. var offset = i * stride,
  21133. offsetP = offset - stride,
  21134. offsetN = offset + stride;
  21135. for (var j = 0; j !== stride; ++j) {
  21136. var value = values[offset + j];
  21137. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21138. keep = true;
  21139. break;
  21140. }
  21141. }
  21142. } else {
  21143. keep = true;
  21144. }
  21145. } // in-place compaction
  21146. if (keep) {
  21147. if (i !== writeIndex) {
  21148. times[writeIndex] = times[i];
  21149. var readOffset = i * stride,
  21150. writeOffset = writeIndex * stride;
  21151. for (var _j = 0; _j !== stride; ++_j) {
  21152. values[writeOffset + _j] = values[readOffset + _j];
  21153. }
  21154. }
  21155. ++writeIndex;
  21156. }
  21157. } // flush last keyframe (compaction looks ahead)
  21158. if (lastIndex > 0) {
  21159. times[writeIndex] = times[lastIndex];
  21160. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21161. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21162. }
  21163. ++writeIndex;
  21164. }
  21165. if (writeIndex !== times.length) {
  21166. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21167. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21168. } else {
  21169. this.times = times;
  21170. this.values = values;
  21171. }
  21172. return this;
  21173. },
  21174. clone: function clone() {
  21175. var times = AnimationUtils.arraySlice(this.times, 0);
  21176. var values = AnimationUtils.arraySlice(this.values, 0);
  21177. var TypedKeyframeTrack = this.constructor;
  21178. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21179. track.createInterpolant = this.createInterpolant;
  21180. return track;
  21181. }
  21182. });
  21183. /**
  21184. * A Track of Boolean keyframe values.
  21185. */
  21186. function BooleanKeyframeTrack(name, times, values) {
  21187. KeyframeTrack.call(this, name, times, values);
  21188. }
  21189. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21190. constructor: BooleanKeyframeTrack,
  21191. ValueTypeName: 'bool',
  21192. ValueBufferType: Array,
  21193. DefaultInterpolation: InterpolateDiscrete,
  21194. InterpolantFactoryMethodLinear: undefined,
  21195. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21196. // representation of a single value and a custom interpolant that
  21197. // computes "firstValue ^ isOdd( index )".
  21198. });
  21199. /**
  21200. * A Track of keyframe values that represent color.
  21201. */
  21202. function ColorKeyframeTrack(name, times, values, interpolation) {
  21203. KeyframeTrack.call(this, name, times, values, interpolation);
  21204. }
  21205. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21206. constructor: ColorKeyframeTrack,
  21207. ValueTypeName: 'color' // ValueBufferType is inherited
  21208. // DefaultInterpolation is inherited
  21209. // Note: Very basic implementation and nothing special yet.
  21210. // However, this is the place for color space parameterization.
  21211. });
  21212. /**
  21213. * A Track of numeric keyframe values.
  21214. */
  21215. function NumberKeyframeTrack(name, times, values, interpolation) {
  21216. KeyframeTrack.call(this, name, times, values, interpolation);
  21217. }
  21218. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21219. constructor: NumberKeyframeTrack,
  21220. ValueTypeName: 'number' // ValueBufferType is inherited
  21221. // DefaultInterpolation is inherited
  21222. });
  21223. /**
  21224. * Spherical linear unit quaternion interpolant.
  21225. */
  21226. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21227. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21228. }
  21229. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21230. constructor: QuaternionLinearInterpolant,
  21231. interpolate_: function interpolate_(i1, t0, t, t1) {
  21232. var result = this.resultBuffer,
  21233. values = this.sampleValues,
  21234. stride = this.valueSize,
  21235. alpha = (t - t0) / (t1 - t0);
  21236. var offset = i1 * stride;
  21237. for (var end = offset + stride; offset !== end; offset += 4) {
  21238. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21239. }
  21240. return result;
  21241. }
  21242. });
  21243. /**
  21244. * A Track of quaternion keyframe values.
  21245. */
  21246. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21247. KeyframeTrack.call(this, name, times, values, interpolation);
  21248. }
  21249. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21250. constructor: QuaternionKeyframeTrack,
  21251. ValueTypeName: 'quaternion',
  21252. // ValueBufferType is inherited
  21253. DefaultInterpolation: InterpolateLinear,
  21254. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21255. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21256. },
  21257. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21258. });
  21259. /**
  21260. * A Track that interpolates Strings
  21261. */
  21262. function StringKeyframeTrack(name, times, values, interpolation) {
  21263. KeyframeTrack.call(this, name, times, values, interpolation);
  21264. }
  21265. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21266. constructor: StringKeyframeTrack,
  21267. ValueTypeName: 'string',
  21268. ValueBufferType: Array,
  21269. DefaultInterpolation: InterpolateDiscrete,
  21270. InterpolantFactoryMethodLinear: undefined,
  21271. InterpolantFactoryMethodSmooth: undefined
  21272. });
  21273. /**
  21274. * A Track of vectored keyframe values.
  21275. */
  21276. function VectorKeyframeTrack(name, times, values, interpolation) {
  21277. KeyframeTrack.call(this, name, times, values, interpolation);
  21278. }
  21279. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21280. constructor: VectorKeyframeTrack,
  21281. ValueTypeName: 'vector' // ValueBufferType is inherited
  21282. // DefaultInterpolation is inherited
  21283. });
  21284. function AnimationClip(name, duration, tracks, blendMode) {
  21285. this.name = name;
  21286. this.tracks = tracks;
  21287. this.duration = duration !== undefined ? duration : -1;
  21288. this.blendMode = blendMode !== undefined ? blendMode : NormalAnimationBlendMode;
  21289. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21290. if (this.duration < 0) {
  21291. this.resetDuration();
  21292. }
  21293. }
  21294. function getTrackTypeForValueTypeName(typeName) {
  21295. switch (typeName.toLowerCase()) {
  21296. case 'scalar':
  21297. case 'double':
  21298. case 'float':
  21299. case 'number':
  21300. case 'integer':
  21301. return NumberKeyframeTrack;
  21302. case 'vector':
  21303. case 'vector2':
  21304. case 'vector3':
  21305. case 'vector4':
  21306. return VectorKeyframeTrack;
  21307. case 'color':
  21308. return ColorKeyframeTrack;
  21309. case 'quaternion':
  21310. return QuaternionKeyframeTrack;
  21311. case 'bool':
  21312. case 'boolean':
  21313. return BooleanKeyframeTrack;
  21314. case 'string':
  21315. return StringKeyframeTrack;
  21316. }
  21317. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21318. }
  21319. function parseKeyframeTrack(json) {
  21320. if (json.type === undefined) {
  21321. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21322. }
  21323. var trackType = getTrackTypeForValueTypeName(json.type);
  21324. if (json.times === undefined) {
  21325. var times = [],
  21326. values = [];
  21327. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21328. json.times = times;
  21329. json.values = values;
  21330. } // derived classes can define a static parse method
  21331. if (trackType.parse !== undefined) {
  21332. return trackType.parse(json);
  21333. } else {
  21334. // by default, we assume a constructor compatible with the base
  21335. return new trackType(json.name, json.times, json.values, json.interpolation);
  21336. }
  21337. }
  21338. Object.assign(AnimationClip, {
  21339. parse: function parse(json) {
  21340. var tracks = [],
  21341. jsonTracks = json.tracks,
  21342. frameTime = 1.0 / (json.fps || 1.0);
  21343. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21344. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21345. }
  21346. return new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21347. },
  21348. toJSON: function toJSON(clip) {
  21349. var tracks = [],
  21350. clipTracks = clip.tracks;
  21351. var json = {
  21352. 'name': clip.name,
  21353. 'duration': clip.duration,
  21354. 'tracks': tracks,
  21355. 'uuid': clip.uuid,
  21356. 'blendMode': clip.blendMode
  21357. };
  21358. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21359. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21360. }
  21361. return json;
  21362. },
  21363. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21364. var numMorphTargets = morphTargetSequence.length;
  21365. var tracks = [];
  21366. for (var i = 0; i < numMorphTargets; i++) {
  21367. var times = [];
  21368. var values = [];
  21369. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21370. values.push(0, 1, 0);
  21371. var order = AnimationUtils.getKeyframeOrder(times);
  21372. times = AnimationUtils.sortedArray(times, 1, order);
  21373. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21374. // last frame as well for perfect loop.
  21375. if (!noLoop && times[0] === 0) {
  21376. times.push(numMorphTargets);
  21377. values.push(values[0]);
  21378. }
  21379. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21380. }
  21381. return new AnimationClip(name, -1, tracks);
  21382. },
  21383. findByName: function findByName(objectOrClipArray, name) {
  21384. var clipArray = objectOrClipArray;
  21385. if (!Array.isArray(objectOrClipArray)) {
  21386. var o = objectOrClipArray;
  21387. clipArray = o.geometry && o.geometry.animations || o.animations;
  21388. }
  21389. for (var i = 0; i < clipArray.length; i++) {
  21390. if (clipArray[i].name === name) {
  21391. return clipArray[i];
  21392. }
  21393. }
  21394. return null;
  21395. },
  21396. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21397. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21398. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21399. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21400. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21401. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21402. var morphTarget = morphTargets[i];
  21403. var parts = morphTarget.name.match(pattern);
  21404. if (parts && parts.length > 1) {
  21405. var name = parts[1];
  21406. var animationMorphTargets = animationToMorphTargets[name];
  21407. if (!animationMorphTargets) {
  21408. animationToMorphTargets[name] = animationMorphTargets = [];
  21409. }
  21410. animationMorphTargets.push(morphTarget);
  21411. }
  21412. }
  21413. var clips = [];
  21414. for (var _name in animationToMorphTargets) {
  21415. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21416. }
  21417. return clips;
  21418. },
  21419. // parse the animation.hierarchy format
  21420. parseAnimation: function parseAnimation(animation, bones) {
  21421. if (!animation) {
  21422. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21423. return null;
  21424. }
  21425. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21426. // only return track if there are actually keys.
  21427. if (animationKeys.length !== 0) {
  21428. var times = [];
  21429. var values = [];
  21430. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21431. if (times.length !== 0) {
  21432. destTracks.push(new trackType(trackName, times, values));
  21433. }
  21434. }
  21435. };
  21436. var tracks = [];
  21437. var clipName = animation.name || 'default';
  21438. var fps = animation.fps || 30;
  21439. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21440. var duration = animation.length || -1;
  21441. var hierarchyTracks = animation.hierarchy || [];
  21442. for (var h = 0; h < hierarchyTracks.length; h++) {
  21443. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21444. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21445. if (animationKeys[0].morphTargets) {
  21446. // figure out all morph targets used in this track
  21447. var morphTargetNames = {};
  21448. var k = void 0;
  21449. for (k = 0; k < animationKeys.length; k++) {
  21450. if (animationKeys[k].morphTargets) {
  21451. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21452. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21453. }
  21454. }
  21455. } // create a track for each morph target with all zero
  21456. // morphTargetInfluences except for the keys in which
  21457. // the morphTarget is named.
  21458. for (var morphTargetName in morphTargetNames) {
  21459. var times = [];
  21460. var values = [];
  21461. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21462. var animationKey = animationKeys[k];
  21463. times.push(animationKey.time);
  21464. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21465. }
  21466. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21467. }
  21468. duration = morphTargetNames.length * (fps || 1.0);
  21469. } else {
  21470. // ...assume skeletal animation
  21471. var boneName = '.bones[' + bones[h].name + ']';
  21472. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21473. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21474. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21475. }
  21476. }
  21477. if (tracks.length === 0) {
  21478. return null;
  21479. }
  21480. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21481. return clip;
  21482. }
  21483. });
  21484. Object.assign(AnimationClip.prototype, {
  21485. resetDuration: function resetDuration() {
  21486. var tracks = this.tracks;
  21487. var duration = 0;
  21488. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21489. var track = this.tracks[i];
  21490. duration = Math.max(duration, track.times[track.times.length - 1]);
  21491. }
  21492. this.duration = duration;
  21493. return this;
  21494. },
  21495. trim: function trim() {
  21496. for (var i = 0; i < this.tracks.length; i++) {
  21497. this.tracks[i].trim(0, this.duration);
  21498. }
  21499. return this;
  21500. },
  21501. validate: function validate() {
  21502. var valid = true;
  21503. for (var i = 0; i < this.tracks.length; i++) {
  21504. valid = valid && this.tracks[i].validate();
  21505. }
  21506. return valid;
  21507. },
  21508. optimize: function optimize() {
  21509. for (var i = 0; i < this.tracks.length; i++) {
  21510. this.tracks[i].optimize();
  21511. }
  21512. return this;
  21513. },
  21514. clone: function clone() {
  21515. var tracks = [];
  21516. for (var i = 0; i < this.tracks.length; i++) {
  21517. tracks.push(this.tracks[i].clone());
  21518. }
  21519. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21520. }
  21521. });
  21522. var Cache = {
  21523. enabled: false,
  21524. files: {},
  21525. add: function add(key, file) {
  21526. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21527. this.files[key] = file;
  21528. },
  21529. get: function get(key) {
  21530. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21531. return this.files[key];
  21532. },
  21533. remove: function remove(key) {
  21534. delete this.files[key];
  21535. },
  21536. clear: function clear() {
  21537. this.files = {};
  21538. }
  21539. };
  21540. function LoadingManager(onLoad, onProgress, onError) {
  21541. var scope = this;
  21542. var isLoading = false;
  21543. var itemsLoaded = 0;
  21544. var itemsTotal = 0;
  21545. var urlModifier = undefined;
  21546. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21547. // in the constructor
  21548. this.onStart = undefined;
  21549. this.onLoad = onLoad;
  21550. this.onProgress = onProgress;
  21551. this.onError = onError;
  21552. this.itemStart = function (url) {
  21553. itemsTotal++;
  21554. if (isLoading === false) {
  21555. if (scope.onStart !== undefined) {
  21556. scope.onStart(url, itemsLoaded, itemsTotal);
  21557. }
  21558. }
  21559. isLoading = true;
  21560. };
  21561. this.itemEnd = function (url) {
  21562. itemsLoaded++;
  21563. if (scope.onProgress !== undefined) {
  21564. scope.onProgress(url, itemsLoaded, itemsTotal);
  21565. }
  21566. if (itemsLoaded === itemsTotal) {
  21567. isLoading = false;
  21568. if (scope.onLoad !== undefined) {
  21569. scope.onLoad();
  21570. }
  21571. }
  21572. };
  21573. this.itemError = function (url) {
  21574. if (scope.onError !== undefined) {
  21575. scope.onError(url);
  21576. }
  21577. };
  21578. this.resolveURL = function (url) {
  21579. if (urlModifier) {
  21580. return urlModifier(url);
  21581. }
  21582. return url;
  21583. };
  21584. this.setURLModifier = function (transform) {
  21585. urlModifier = transform;
  21586. return this;
  21587. };
  21588. this.addHandler = function (regex, loader) {
  21589. handlers.push(regex, loader);
  21590. return this;
  21591. };
  21592. this.removeHandler = function (regex) {
  21593. var index = handlers.indexOf(regex);
  21594. if (index !== -1) {
  21595. handlers.splice(index, 2);
  21596. }
  21597. return this;
  21598. };
  21599. this.getHandler = function (file) {
  21600. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21601. var regex = handlers[i];
  21602. var loader = handlers[i + 1];
  21603. if (regex.global) regex.lastIndex = 0; // see #17920
  21604. if (regex.test(file)) {
  21605. return loader;
  21606. }
  21607. }
  21608. return null;
  21609. };
  21610. }
  21611. var DefaultLoadingManager = new LoadingManager();
  21612. function Loader(manager) {
  21613. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21614. this.crossOrigin = 'anonymous';
  21615. this.withCredentials = false;
  21616. this.path = '';
  21617. this.resourcePath = '';
  21618. this.requestHeader = {};
  21619. }
  21620. Object.assign(Loader.prototype, {
  21621. load: function load()
  21622. /* url, onLoad, onProgress, onError */
  21623. {},
  21624. loadAsync: function loadAsync(url, onProgress) {
  21625. var scope = this;
  21626. return new Promise(function (resolve, reject) {
  21627. scope.load(url, resolve, onProgress, reject);
  21628. });
  21629. },
  21630. parse: function parse()
  21631. /* data */
  21632. {},
  21633. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21634. this.crossOrigin = crossOrigin;
  21635. return this;
  21636. },
  21637. setWithCredentials: function setWithCredentials(value) {
  21638. this.withCredentials = value;
  21639. return this;
  21640. },
  21641. setPath: function setPath(path) {
  21642. this.path = path;
  21643. return this;
  21644. },
  21645. setResourcePath: function setResourcePath(resourcePath) {
  21646. this.resourcePath = resourcePath;
  21647. return this;
  21648. },
  21649. setRequestHeader: function setRequestHeader(requestHeader) {
  21650. this.requestHeader = requestHeader;
  21651. return this;
  21652. }
  21653. });
  21654. var loading = {};
  21655. function FileLoader(manager) {
  21656. Loader.call(this, manager);
  21657. }
  21658. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21659. constructor: FileLoader,
  21660. load: function load(url, onLoad, onProgress, onError) {
  21661. if (url === undefined) url = '';
  21662. if (this.path !== undefined) url = this.path + url;
  21663. url = this.manager.resolveURL(url);
  21664. var scope = this;
  21665. var cached = Cache.get(url);
  21666. if (cached !== undefined) {
  21667. scope.manager.itemStart(url);
  21668. setTimeout(function () {
  21669. if (onLoad) onLoad(cached);
  21670. scope.manager.itemEnd(url);
  21671. }, 0);
  21672. return cached;
  21673. } // Check if request is duplicate
  21674. if (loading[url] !== undefined) {
  21675. loading[url].push({
  21676. onLoad: onLoad,
  21677. onProgress: onProgress,
  21678. onError: onError
  21679. });
  21680. return;
  21681. } // Check for data: URI
  21682. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21683. var dataUriRegexResult = url.match(dataUriRegex);
  21684. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21685. if (dataUriRegexResult) {
  21686. var mimeType = dataUriRegexResult[1];
  21687. var isBase64 = !!dataUriRegexResult[2];
  21688. var data = dataUriRegexResult[3];
  21689. data = decodeURIComponent(data);
  21690. if (isBase64) data = atob(data);
  21691. try {
  21692. var response;
  21693. var responseType = (this.responseType || '').toLowerCase();
  21694. switch (responseType) {
  21695. case 'arraybuffer':
  21696. case 'blob':
  21697. var view = new Uint8Array(data.length);
  21698. for (var i = 0; i < data.length; i++) {
  21699. view[i] = data.charCodeAt(i);
  21700. }
  21701. if (responseType === 'blob') {
  21702. response = new Blob([view.buffer], {
  21703. type: mimeType
  21704. });
  21705. } else {
  21706. response = view.buffer;
  21707. }
  21708. break;
  21709. case 'document':
  21710. var parser = new DOMParser();
  21711. response = parser.parseFromString(data, mimeType);
  21712. break;
  21713. case 'json':
  21714. response = JSON.parse(data);
  21715. break;
  21716. default:
  21717. // 'text' or other
  21718. response = data;
  21719. break;
  21720. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21721. setTimeout(function () {
  21722. if (onLoad) onLoad(response);
  21723. scope.manager.itemEnd(url);
  21724. }, 0);
  21725. } catch (error) {
  21726. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21727. setTimeout(function () {
  21728. if (onError) onError(error);
  21729. scope.manager.itemError(url);
  21730. scope.manager.itemEnd(url);
  21731. }, 0);
  21732. }
  21733. } else {
  21734. // Initialise array for duplicate requests
  21735. loading[url] = [];
  21736. loading[url].push({
  21737. onLoad: onLoad,
  21738. onProgress: onProgress,
  21739. onError: onError
  21740. });
  21741. request = new XMLHttpRequest();
  21742. request.open('GET', url, true);
  21743. request.addEventListener('load', function (event) {
  21744. var response = this.response;
  21745. var callbacks = loading[url];
  21746. delete loading[url];
  21747. if (this.status === 200 || this.status === 0) {
  21748. // Some browsers return HTTP Status 0 when using non-http protocol
  21749. // e.g. 'file://' or 'data://'. Handle as success.
  21750. 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
  21751. // error response bodies as proper responses to requests.
  21752. Cache.add(url, response);
  21753. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21754. var callback = callbacks[_i];
  21755. if (callback.onLoad) callback.onLoad(response);
  21756. }
  21757. scope.manager.itemEnd(url);
  21758. } else {
  21759. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21760. var _callback = callbacks[_i2];
  21761. if (_callback.onError) _callback.onError(event);
  21762. }
  21763. scope.manager.itemError(url);
  21764. scope.manager.itemEnd(url);
  21765. }
  21766. }, false);
  21767. request.addEventListener('progress', function (event) {
  21768. var callbacks = loading[url];
  21769. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21770. var callback = callbacks[_i3];
  21771. if (callback.onProgress) callback.onProgress(event);
  21772. }
  21773. }, false);
  21774. request.addEventListener('error', function (event) {
  21775. var callbacks = loading[url];
  21776. delete loading[url];
  21777. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21778. var callback = callbacks[_i4];
  21779. if (callback.onError) callback.onError(event);
  21780. }
  21781. scope.manager.itemError(url);
  21782. scope.manager.itemEnd(url);
  21783. }, false);
  21784. request.addEventListener('abort', function (event) {
  21785. var callbacks = loading[url];
  21786. delete loading[url];
  21787. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21788. var callback = callbacks[_i5];
  21789. if (callback.onError) callback.onError(event);
  21790. }
  21791. scope.manager.itemError(url);
  21792. scope.manager.itemEnd(url);
  21793. }, false);
  21794. if (this.responseType !== undefined) request.responseType = this.responseType;
  21795. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21796. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21797. for (var header in this.requestHeader) {
  21798. request.setRequestHeader(header, this.requestHeader[header]);
  21799. }
  21800. request.send(null);
  21801. }
  21802. scope.manager.itemStart(url);
  21803. return request;
  21804. },
  21805. setResponseType: function setResponseType(value) {
  21806. this.responseType = value;
  21807. return this;
  21808. },
  21809. setMimeType: function setMimeType(value) {
  21810. this.mimeType = value;
  21811. return this;
  21812. }
  21813. });
  21814. function AnimationLoader(manager) {
  21815. Loader.call(this, manager);
  21816. }
  21817. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21818. constructor: AnimationLoader,
  21819. load: function load(url, onLoad, onProgress, onError) {
  21820. var scope = this;
  21821. var loader = new FileLoader(scope.manager);
  21822. loader.setPath(scope.path);
  21823. loader.setRequestHeader(scope.requestHeader);
  21824. loader.setWithCredentials(scope.withCredentials);
  21825. loader.load(url, function (text) {
  21826. try {
  21827. onLoad(scope.parse(JSON.parse(text)));
  21828. } catch (e) {
  21829. if (onError) {
  21830. onError(e);
  21831. } else {
  21832. console.error(e);
  21833. }
  21834. scope.manager.itemError(url);
  21835. }
  21836. }, onProgress, onError);
  21837. },
  21838. parse: function parse(json) {
  21839. var animations = [];
  21840. for (var i = 0; i < json.length; i++) {
  21841. var clip = AnimationClip.parse(json[i]);
  21842. animations.push(clip);
  21843. }
  21844. return animations;
  21845. }
  21846. });
  21847. /**
  21848. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21849. *
  21850. * Sub classes have to implement the parse() method which will be used in load().
  21851. */
  21852. function CompressedTextureLoader(manager) {
  21853. Loader.call(this, manager);
  21854. }
  21855. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21856. constructor: CompressedTextureLoader,
  21857. load: function load(url, onLoad, onProgress, onError) {
  21858. var scope = this;
  21859. var images = [];
  21860. var texture = new CompressedTexture();
  21861. texture.image = images;
  21862. var loader = new FileLoader(this.manager);
  21863. loader.setPath(this.path);
  21864. loader.setResponseType('arraybuffer');
  21865. loader.setRequestHeader(this.requestHeader);
  21866. loader.setWithCredentials(scope.withCredentials);
  21867. var loaded = 0;
  21868. function loadTexture(i) {
  21869. loader.load(url[i], function (buffer) {
  21870. var texDatas = scope.parse(buffer, true);
  21871. images[i] = {
  21872. width: texDatas.width,
  21873. height: texDatas.height,
  21874. format: texDatas.format,
  21875. mipmaps: texDatas.mipmaps
  21876. };
  21877. loaded += 1;
  21878. if (loaded === 6) {
  21879. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21880. texture.format = texDatas.format;
  21881. texture.needsUpdate = true;
  21882. if (onLoad) onLoad(texture);
  21883. }
  21884. }, onProgress, onError);
  21885. }
  21886. if (Array.isArray(url)) {
  21887. for (var i = 0, il = url.length; i < il; ++i) {
  21888. loadTexture(i);
  21889. }
  21890. } else {
  21891. // compressed cubemap texture stored in a single DDS file
  21892. loader.load(url, function (buffer) {
  21893. var texDatas = scope.parse(buffer, true);
  21894. if (texDatas.isCubemap) {
  21895. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21896. for (var f = 0; f < faces; f++) {
  21897. images[f] = {
  21898. mipmaps: []
  21899. };
  21900. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21901. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21902. images[f].format = texDatas.format;
  21903. images[f].width = texDatas.width;
  21904. images[f].height = texDatas.height;
  21905. }
  21906. }
  21907. } else {
  21908. texture.image.width = texDatas.width;
  21909. texture.image.height = texDatas.height;
  21910. texture.mipmaps = texDatas.mipmaps;
  21911. }
  21912. if (texDatas.mipmapCount === 1) {
  21913. texture.minFilter = LinearFilter;
  21914. }
  21915. texture.format = texDatas.format;
  21916. texture.needsUpdate = true;
  21917. if (onLoad) onLoad(texture);
  21918. }, onProgress, onError);
  21919. }
  21920. return texture;
  21921. }
  21922. });
  21923. function ImageLoader(manager) {
  21924. Loader.call(this, manager);
  21925. }
  21926. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21927. constructor: ImageLoader,
  21928. load: function load(url, onLoad, onProgress, onError) {
  21929. if (this.path !== undefined) url = this.path + url;
  21930. url = this.manager.resolveURL(url);
  21931. var scope = this;
  21932. var cached = Cache.get(url);
  21933. if (cached !== undefined) {
  21934. scope.manager.itemStart(url);
  21935. setTimeout(function () {
  21936. if (onLoad) onLoad(cached);
  21937. scope.manager.itemEnd(url);
  21938. }, 0);
  21939. return cached;
  21940. }
  21941. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21942. function onImageLoad() {
  21943. image.removeEventListener('load', onImageLoad, false);
  21944. image.removeEventListener('error', onImageError, false);
  21945. Cache.add(url, this);
  21946. if (onLoad) onLoad(this);
  21947. scope.manager.itemEnd(url);
  21948. }
  21949. function onImageError(event) {
  21950. image.removeEventListener('load', onImageLoad, false);
  21951. image.removeEventListener('error', onImageError, false);
  21952. if (onError) onError(event);
  21953. scope.manager.itemError(url);
  21954. scope.manager.itemEnd(url);
  21955. }
  21956. image.addEventListener('load', onImageLoad, false);
  21957. image.addEventListener('error', onImageError, false);
  21958. if (url.substr(0, 5) !== 'data:') {
  21959. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21960. }
  21961. scope.manager.itemStart(url);
  21962. image.src = url;
  21963. return image;
  21964. }
  21965. });
  21966. function CubeTextureLoader(manager) {
  21967. Loader.call(this, manager);
  21968. }
  21969. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21970. constructor: CubeTextureLoader,
  21971. load: function load(urls, onLoad, onProgress, onError) {
  21972. var texture = new CubeTexture();
  21973. var loader = new ImageLoader(this.manager);
  21974. loader.setCrossOrigin(this.crossOrigin);
  21975. loader.setPath(this.path);
  21976. var loaded = 0;
  21977. function loadTexture(i) {
  21978. loader.load(urls[i], function (image) {
  21979. texture.images[i] = image;
  21980. loaded++;
  21981. if (loaded === 6) {
  21982. texture.needsUpdate = true;
  21983. if (onLoad) onLoad(texture);
  21984. }
  21985. }, undefined, onError);
  21986. }
  21987. for (var i = 0; i < urls.length; ++i) {
  21988. loadTexture(i);
  21989. }
  21990. return texture;
  21991. }
  21992. });
  21993. /**
  21994. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21995. *
  21996. * Sub classes have to implement the parse() method which will be used in load().
  21997. */
  21998. function DataTextureLoader(manager) {
  21999. Loader.call(this, manager);
  22000. }
  22001. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22002. constructor: DataTextureLoader,
  22003. load: function load(url, onLoad, onProgress, onError) {
  22004. var scope = this;
  22005. var texture = new DataTexture();
  22006. var loader = new FileLoader(this.manager);
  22007. loader.setResponseType('arraybuffer');
  22008. loader.setRequestHeader(this.requestHeader);
  22009. loader.setPath(this.path);
  22010. loader.setWithCredentials(scope.withCredentials);
  22011. loader.load(url, function (buffer) {
  22012. var texData = scope.parse(buffer);
  22013. if (!texData) return;
  22014. if (texData.image !== undefined) {
  22015. texture.image = texData.image;
  22016. } else if (texData.data !== undefined) {
  22017. texture.image.width = texData.width;
  22018. texture.image.height = texData.height;
  22019. texture.image.data = texData.data;
  22020. }
  22021. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22022. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22023. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22024. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22025. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22026. if (texData.format !== undefined) {
  22027. texture.format = texData.format;
  22028. }
  22029. if (texData.type !== undefined) {
  22030. texture.type = texData.type;
  22031. }
  22032. if (texData.mipmaps !== undefined) {
  22033. texture.mipmaps = texData.mipmaps;
  22034. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22035. }
  22036. if (texData.mipmapCount === 1) {
  22037. texture.minFilter = LinearFilter;
  22038. }
  22039. texture.needsUpdate = true;
  22040. if (onLoad) onLoad(texture, texData);
  22041. }, onProgress, onError);
  22042. return texture;
  22043. }
  22044. });
  22045. function TextureLoader(manager) {
  22046. Loader.call(this, manager);
  22047. }
  22048. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22049. constructor: TextureLoader,
  22050. load: function load(url, onLoad, onProgress, onError) {
  22051. var texture = new Texture();
  22052. var loader = new ImageLoader(this.manager);
  22053. loader.setCrossOrigin(this.crossOrigin);
  22054. loader.setPath(this.path);
  22055. loader.load(url, function (image) {
  22056. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22057. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22058. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22059. texture.needsUpdate = true;
  22060. if (onLoad !== undefined) {
  22061. onLoad(texture);
  22062. }
  22063. }, onProgress, onError);
  22064. return texture;
  22065. }
  22066. });
  22067. /**
  22068. * Extensible curve object.
  22069. *
  22070. * Some common of curve methods:
  22071. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22072. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22073. * .getPoints(), .getSpacedPoints()
  22074. * .getLength()
  22075. * .updateArcLengths()
  22076. *
  22077. * This following curves inherit from THREE.Curve:
  22078. *
  22079. * -- 2D curves --
  22080. * THREE.ArcCurve
  22081. * THREE.CubicBezierCurve
  22082. * THREE.EllipseCurve
  22083. * THREE.LineCurve
  22084. * THREE.QuadraticBezierCurve
  22085. * THREE.SplineCurve
  22086. *
  22087. * -- 3D curves --
  22088. * THREE.CatmullRomCurve3
  22089. * THREE.CubicBezierCurve3
  22090. * THREE.LineCurve3
  22091. * THREE.QuadraticBezierCurve3
  22092. *
  22093. * A series of curves can be represented as a THREE.CurvePath.
  22094. *
  22095. **/
  22096. function Curve() {
  22097. this.type = 'Curve';
  22098. this.arcLengthDivisions = 200;
  22099. }
  22100. Object.assign(Curve.prototype, {
  22101. // Virtual base class method to overwrite and implement in subclasses
  22102. // - t [0 .. 1]
  22103. getPoint: function getPoint()
  22104. /* t, optionalTarget */
  22105. {
  22106. console.warn('THREE.Curve: .getPoint() not implemented.');
  22107. return null;
  22108. },
  22109. // Get point at relative position in curve according to arc length
  22110. // - u [0 .. 1]
  22111. getPointAt: function getPointAt(u, optionalTarget) {
  22112. var t = this.getUtoTmapping(u);
  22113. return this.getPoint(t, optionalTarget);
  22114. },
  22115. // Get sequence of points using getPoint( t )
  22116. getPoints: function getPoints(divisions) {
  22117. if (divisions === undefined) divisions = 5;
  22118. var points = [];
  22119. for (var d = 0; d <= divisions; d++) {
  22120. points.push(this.getPoint(d / divisions));
  22121. }
  22122. return points;
  22123. },
  22124. // Get sequence of points using getPointAt( u )
  22125. getSpacedPoints: function getSpacedPoints(divisions) {
  22126. if (divisions === undefined) divisions = 5;
  22127. var points = [];
  22128. for (var d = 0; d <= divisions; d++) {
  22129. points.push(this.getPointAt(d / divisions));
  22130. }
  22131. return points;
  22132. },
  22133. // Get total curve arc length
  22134. getLength: function getLength() {
  22135. var lengths = this.getLengths();
  22136. return lengths[lengths.length - 1];
  22137. },
  22138. // Get list of cumulative segment lengths
  22139. getLengths: function getLengths(divisions) {
  22140. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22141. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22142. return this.cacheArcLengths;
  22143. }
  22144. this.needsUpdate = false;
  22145. var cache = [];
  22146. var current,
  22147. last = this.getPoint(0);
  22148. var sum = 0;
  22149. cache.push(0);
  22150. for (var p = 1; p <= divisions; p++) {
  22151. current = this.getPoint(p / divisions);
  22152. sum += current.distanceTo(last);
  22153. cache.push(sum);
  22154. last = current;
  22155. }
  22156. this.cacheArcLengths = cache;
  22157. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22158. },
  22159. updateArcLengths: function updateArcLengths() {
  22160. this.needsUpdate = true;
  22161. this.getLengths();
  22162. },
  22163. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22164. getUtoTmapping: function getUtoTmapping(u, distance) {
  22165. var arcLengths = this.getLengths();
  22166. var i = 0;
  22167. var il = arcLengths.length;
  22168. var targetArcLength; // The targeted u distance value to get
  22169. if (distance) {
  22170. targetArcLength = distance;
  22171. } else {
  22172. targetArcLength = u * arcLengths[il - 1];
  22173. } // binary search for the index with largest value smaller than target u distance
  22174. var low = 0,
  22175. high = il - 1,
  22176. comparison;
  22177. while (low <= high) {
  22178. 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
  22179. comparison = arcLengths[i] - targetArcLength;
  22180. if (comparison < 0) {
  22181. low = i + 1;
  22182. } else if (comparison > 0) {
  22183. high = i - 1;
  22184. } else {
  22185. high = i;
  22186. break; // DONE
  22187. }
  22188. }
  22189. i = high;
  22190. if (arcLengths[i] === targetArcLength) {
  22191. return i / (il - 1);
  22192. } // we could get finer grain at lengths, or use simple interpolation between two points
  22193. var lengthBefore = arcLengths[i];
  22194. var lengthAfter = arcLengths[i + 1];
  22195. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22196. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22197. var t = (i + segmentFraction) / (il - 1);
  22198. return t;
  22199. },
  22200. // Returns a unit vector tangent at t
  22201. // In case any sub curve does not implement its tangent derivation,
  22202. // 2 points a small delta apart will be used to find its gradient
  22203. // which seems to give a reasonable approximation
  22204. getTangent: function getTangent(t, optionalTarget) {
  22205. var delta = 0.0001;
  22206. var t1 = t - delta;
  22207. var t2 = t + delta; // Capping in case of danger
  22208. if (t1 < 0) t1 = 0;
  22209. if (t2 > 1) t2 = 1;
  22210. var pt1 = this.getPoint(t1);
  22211. var pt2 = this.getPoint(t2);
  22212. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22213. tangent.copy(pt2).sub(pt1).normalize();
  22214. return tangent;
  22215. },
  22216. getTangentAt: function getTangentAt(u, optionalTarget) {
  22217. var t = this.getUtoTmapping(u);
  22218. return this.getTangent(t, optionalTarget);
  22219. },
  22220. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22221. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22222. var normal = new Vector3();
  22223. var tangents = [];
  22224. var normals = [];
  22225. var binormals = [];
  22226. var vec = new Vector3();
  22227. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22228. for (var i = 0; i <= segments; i++) {
  22229. var u = i / segments;
  22230. tangents[i] = this.getTangentAt(u, new Vector3());
  22231. tangents[i].normalize();
  22232. } // select an initial normal vector perpendicular to the first tangent vector,
  22233. // and in the direction of the minimum tangent xyz component
  22234. normals[0] = new Vector3();
  22235. binormals[0] = new Vector3();
  22236. var min = Number.MAX_VALUE;
  22237. var tx = Math.abs(tangents[0].x);
  22238. var ty = Math.abs(tangents[0].y);
  22239. var tz = Math.abs(tangents[0].z);
  22240. if (tx <= min) {
  22241. min = tx;
  22242. normal.set(1, 0, 0);
  22243. }
  22244. if (ty <= min) {
  22245. min = ty;
  22246. normal.set(0, 1, 0);
  22247. }
  22248. if (tz <= min) {
  22249. normal.set(0, 0, 1);
  22250. }
  22251. vec.crossVectors(tangents[0], normal).normalize();
  22252. normals[0].crossVectors(tangents[0], vec);
  22253. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22254. for (var _i = 1; _i <= segments; _i++) {
  22255. normals[_i] = normals[_i - 1].clone();
  22256. binormals[_i] = binormals[_i - 1].clone();
  22257. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22258. if (vec.length() > Number.EPSILON) {
  22259. vec.normalize();
  22260. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22261. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22262. }
  22263. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22264. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22265. if (closed === true) {
  22266. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22267. _theta /= segments;
  22268. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22269. _theta = -_theta;
  22270. }
  22271. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22272. // twist a little...
  22273. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22274. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22275. }
  22276. }
  22277. return {
  22278. tangents: tangents,
  22279. normals: normals,
  22280. binormals: binormals
  22281. };
  22282. },
  22283. clone: function clone() {
  22284. return new this.constructor().copy(this);
  22285. },
  22286. copy: function copy(source) {
  22287. this.arcLengthDivisions = source.arcLengthDivisions;
  22288. return this;
  22289. },
  22290. toJSON: function toJSON() {
  22291. var data = {
  22292. metadata: {
  22293. version: 4.5,
  22294. type: 'Curve',
  22295. generator: 'Curve.toJSON'
  22296. }
  22297. };
  22298. data.arcLengthDivisions = this.arcLengthDivisions;
  22299. data.type = this.type;
  22300. return data;
  22301. },
  22302. fromJSON: function fromJSON(json) {
  22303. this.arcLengthDivisions = json.arcLengthDivisions;
  22304. return this;
  22305. }
  22306. });
  22307. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22308. Curve.call(this);
  22309. this.type = 'EllipseCurve';
  22310. this.aX = aX || 0;
  22311. this.aY = aY || 0;
  22312. this.xRadius = xRadius || 1;
  22313. this.yRadius = yRadius || 1;
  22314. this.aStartAngle = aStartAngle || 0;
  22315. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22316. this.aClockwise = aClockwise || false;
  22317. this.aRotation = aRotation || 0;
  22318. }
  22319. EllipseCurve.prototype = Object.create(Curve.prototype);
  22320. EllipseCurve.prototype.constructor = EllipseCurve;
  22321. EllipseCurve.prototype.isEllipseCurve = true;
  22322. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22323. var point = optionalTarget || new Vector2();
  22324. var twoPi = Math.PI * 2;
  22325. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22326. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22327. while (deltaAngle < 0) {
  22328. deltaAngle += twoPi;
  22329. }
  22330. while (deltaAngle > twoPi) {
  22331. deltaAngle -= twoPi;
  22332. }
  22333. if (deltaAngle < Number.EPSILON) {
  22334. if (samePoints) {
  22335. deltaAngle = 0;
  22336. } else {
  22337. deltaAngle = twoPi;
  22338. }
  22339. }
  22340. if (this.aClockwise === true && !samePoints) {
  22341. if (deltaAngle === twoPi) {
  22342. deltaAngle = -twoPi;
  22343. } else {
  22344. deltaAngle = deltaAngle - twoPi;
  22345. }
  22346. }
  22347. var angle = this.aStartAngle + t * deltaAngle;
  22348. var x = this.aX + this.xRadius * Math.cos(angle);
  22349. var y = this.aY + this.yRadius * Math.sin(angle);
  22350. if (this.aRotation !== 0) {
  22351. var cos = Math.cos(this.aRotation);
  22352. var sin = Math.sin(this.aRotation);
  22353. var tx = x - this.aX;
  22354. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22355. x = tx * cos - ty * sin + this.aX;
  22356. y = tx * sin + ty * cos + this.aY;
  22357. }
  22358. return point.set(x, y);
  22359. };
  22360. EllipseCurve.prototype.copy = function (source) {
  22361. Curve.prototype.copy.call(this, source);
  22362. this.aX = source.aX;
  22363. this.aY = source.aY;
  22364. this.xRadius = source.xRadius;
  22365. this.yRadius = source.yRadius;
  22366. this.aStartAngle = source.aStartAngle;
  22367. this.aEndAngle = source.aEndAngle;
  22368. this.aClockwise = source.aClockwise;
  22369. this.aRotation = source.aRotation;
  22370. return this;
  22371. };
  22372. EllipseCurve.prototype.toJSON = function () {
  22373. var data = Curve.prototype.toJSON.call(this);
  22374. data.aX = this.aX;
  22375. data.aY = this.aY;
  22376. data.xRadius = this.xRadius;
  22377. data.yRadius = this.yRadius;
  22378. data.aStartAngle = this.aStartAngle;
  22379. data.aEndAngle = this.aEndAngle;
  22380. data.aClockwise = this.aClockwise;
  22381. data.aRotation = this.aRotation;
  22382. return data;
  22383. };
  22384. EllipseCurve.prototype.fromJSON = function (json) {
  22385. Curve.prototype.fromJSON.call(this, json);
  22386. this.aX = json.aX;
  22387. this.aY = json.aY;
  22388. this.xRadius = json.xRadius;
  22389. this.yRadius = json.yRadius;
  22390. this.aStartAngle = json.aStartAngle;
  22391. this.aEndAngle = json.aEndAngle;
  22392. this.aClockwise = json.aClockwise;
  22393. this.aRotation = json.aRotation;
  22394. return this;
  22395. };
  22396. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22397. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22398. this.type = 'ArcCurve';
  22399. }
  22400. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22401. ArcCurve.prototype.constructor = ArcCurve;
  22402. ArcCurve.prototype.isArcCurve = true;
  22403. /**
  22404. * Centripetal CatmullRom Curve - which is useful for avoiding
  22405. * cusps and self-intersections in non-uniform catmull rom curves.
  22406. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22407. *
  22408. * curve.type accepts centripetal(default), chordal and catmullrom
  22409. * curve.tension is used for catmullrom which defaults to 0.5
  22410. */
  22411. /*
  22412. Based on an optimized c++ solution in
  22413. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22414. - http://ideone.com/NoEbVM
  22415. This CubicPoly class could be used for reusing some variables and calculations,
  22416. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22417. which can be placed in CurveUtils.
  22418. */
  22419. function CubicPoly() {
  22420. var c0 = 0,
  22421. c1 = 0,
  22422. c2 = 0,
  22423. c3 = 0;
  22424. /*
  22425. * Compute coefficients for a cubic polynomial
  22426. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22427. * such that
  22428. * p(0) = x0, p(1) = x1
  22429. * and
  22430. * p'(0) = t0, p'(1) = t1.
  22431. */
  22432. function init(x0, x1, t0, t1) {
  22433. c0 = x0;
  22434. c1 = t0;
  22435. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22436. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22437. }
  22438. return {
  22439. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22440. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22441. },
  22442. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22443. // compute tangents when parameterized in [t1,t2]
  22444. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22445. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22446. t1 *= dt1;
  22447. t2 *= dt1;
  22448. init(x1, x2, t1, t2);
  22449. },
  22450. calc: function calc(t) {
  22451. var t2 = t * t;
  22452. var t3 = t2 * t;
  22453. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22454. }
  22455. };
  22456. } //
  22457. var tmp = new Vector3();
  22458. var px = new CubicPoly(),
  22459. py = new CubicPoly(),
  22460. pz = new CubicPoly();
  22461. function CatmullRomCurve3(points, closed, curveType, tension) {
  22462. Curve.call(this);
  22463. this.type = 'CatmullRomCurve3';
  22464. this.points = points || [];
  22465. this.closed = closed || false;
  22466. this.curveType = curveType || 'centripetal';
  22467. this.tension = tension !== undefined ? tension : 0.5;
  22468. }
  22469. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22470. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22471. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22472. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22473. var point = optionalTarget || new Vector3();
  22474. var points = this.points;
  22475. var l = points.length;
  22476. var p = (l - (this.closed ? 0 : 1)) * t;
  22477. var intPoint = Math.floor(p);
  22478. var weight = p - intPoint;
  22479. if (this.closed) {
  22480. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22481. } else if (weight === 0 && intPoint === l - 1) {
  22482. intPoint = l - 2;
  22483. weight = 1;
  22484. }
  22485. var p0, p3; // 4 points (p1 & p2 defined below)
  22486. if (this.closed || intPoint > 0) {
  22487. p0 = points[(intPoint - 1) % l];
  22488. } else {
  22489. // extrapolate first point
  22490. tmp.subVectors(points[0], points[1]).add(points[0]);
  22491. p0 = tmp;
  22492. }
  22493. var p1 = points[intPoint % l];
  22494. var p2 = points[(intPoint + 1) % l];
  22495. if (this.closed || intPoint + 2 < l) {
  22496. p3 = points[(intPoint + 2) % l];
  22497. } else {
  22498. // extrapolate last point
  22499. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22500. p3 = tmp;
  22501. }
  22502. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22503. // init Centripetal / Chordal Catmull-Rom
  22504. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22505. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22506. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22507. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22508. if (dt1 < 1e-4) dt1 = 1.0;
  22509. if (dt0 < 1e-4) dt0 = dt1;
  22510. if (dt2 < 1e-4) dt2 = dt1;
  22511. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22512. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22513. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22514. } else if (this.curveType === 'catmullrom') {
  22515. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22516. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22517. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22518. }
  22519. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22520. return point;
  22521. };
  22522. CatmullRomCurve3.prototype.copy = function (source) {
  22523. Curve.prototype.copy.call(this, source);
  22524. this.points = [];
  22525. for (var i = 0, l = source.points.length; i < l; i++) {
  22526. var point = source.points[i];
  22527. this.points.push(point.clone());
  22528. }
  22529. this.closed = source.closed;
  22530. this.curveType = source.curveType;
  22531. this.tension = source.tension;
  22532. return this;
  22533. };
  22534. CatmullRomCurve3.prototype.toJSON = function () {
  22535. var data = Curve.prototype.toJSON.call(this);
  22536. data.points = [];
  22537. for (var i = 0, l = this.points.length; i < l; i++) {
  22538. var point = this.points[i];
  22539. data.points.push(point.toArray());
  22540. }
  22541. data.closed = this.closed;
  22542. data.curveType = this.curveType;
  22543. data.tension = this.tension;
  22544. return data;
  22545. };
  22546. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22547. Curve.prototype.fromJSON.call(this, json);
  22548. this.points = [];
  22549. for (var i = 0, l = json.points.length; i < l; i++) {
  22550. var point = json.points[i];
  22551. this.points.push(new Vector3().fromArray(point));
  22552. }
  22553. this.closed = json.closed;
  22554. this.curveType = json.curveType;
  22555. this.tension = json.tension;
  22556. return this;
  22557. };
  22558. /**
  22559. * Bezier Curves formulas obtained from
  22560. * http://en.wikipedia.org/wiki/Bézier_curve
  22561. */
  22562. function CatmullRom(t, p0, p1, p2, p3) {
  22563. var v0 = (p2 - p0) * 0.5;
  22564. var v1 = (p3 - p1) * 0.5;
  22565. var t2 = t * t;
  22566. var t3 = t * t2;
  22567. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22568. } //
  22569. function QuadraticBezierP0(t, p) {
  22570. var k = 1 - t;
  22571. return k * k * p;
  22572. }
  22573. function QuadraticBezierP1(t, p) {
  22574. return 2 * (1 - t) * t * p;
  22575. }
  22576. function QuadraticBezierP2(t, p) {
  22577. return t * t * p;
  22578. }
  22579. function QuadraticBezier(t, p0, p1, p2) {
  22580. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22581. } //
  22582. function CubicBezierP0(t, p) {
  22583. var k = 1 - t;
  22584. return k * k * k * p;
  22585. }
  22586. function CubicBezierP1(t, p) {
  22587. var k = 1 - t;
  22588. return 3 * k * k * t * p;
  22589. }
  22590. function CubicBezierP2(t, p) {
  22591. return 3 * (1 - t) * t * t * p;
  22592. }
  22593. function CubicBezierP3(t, p) {
  22594. return t * t * t * p;
  22595. }
  22596. function CubicBezier(t, p0, p1, p2, p3) {
  22597. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22598. }
  22599. function CubicBezierCurve(v0, v1, v2, v3) {
  22600. Curve.call(this);
  22601. this.type = 'CubicBezierCurve';
  22602. this.v0 = v0 || new Vector2();
  22603. this.v1 = v1 || new Vector2();
  22604. this.v2 = v2 || new Vector2();
  22605. this.v3 = v3 || new Vector2();
  22606. }
  22607. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22608. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22609. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22610. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22611. var point = optionalTarget || new Vector2();
  22612. var v0 = this.v0,
  22613. v1 = this.v1,
  22614. v2 = this.v2,
  22615. v3 = this.v3;
  22616. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22617. return point;
  22618. };
  22619. CubicBezierCurve.prototype.copy = function (source) {
  22620. Curve.prototype.copy.call(this, source);
  22621. this.v0.copy(source.v0);
  22622. this.v1.copy(source.v1);
  22623. this.v2.copy(source.v2);
  22624. this.v3.copy(source.v3);
  22625. return this;
  22626. };
  22627. CubicBezierCurve.prototype.toJSON = function () {
  22628. var data = Curve.prototype.toJSON.call(this);
  22629. data.v0 = this.v0.toArray();
  22630. data.v1 = this.v1.toArray();
  22631. data.v2 = this.v2.toArray();
  22632. data.v3 = this.v3.toArray();
  22633. return data;
  22634. };
  22635. CubicBezierCurve.prototype.fromJSON = function (json) {
  22636. Curve.prototype.fromJSON.call(this, json);
  22637. this.v0.fromArray(json.v0);
  22638. this.v1.fromArray(json.v1);
  22639. this.v2.fromArray(json.v2);
  22640. this.v3.fromArray(json.v3);
  22641. return this;
  22642. };
  22643. function CubicBezierCurve3(v0, v1, v2, v3) {
  22644. Curve.call(this);
  22645. this.type = 'CubicBezierCurve3';
  22646. this.v0 = v0 || new Vector3();
  22647. this.v1 = v1 || new Vector3();
  22648. this.v2 = v2 || new Vector3();
  22649. this.v3 = v3 || new Vector3();
  22650. }
  22651. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22652. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22653. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22654. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22655. var point = optionalTarget || new Vector3();
  22656. var v0 = this.v0,
  22657. v1 = this.v1,
  22658. v2 = this.v2,
  22659. v3 = this.v3;
  22660. 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));
  22661. return point;
  22662. };
  22663. CubicBezierCurve3.prototype.copy = function (source) {
  22664. Curve.prototype.copy.call(this, source);
  22665. this.v0.copy(source.v0);
  22666. this.v1.copy(source.v1);
  22667. this.v2.copy(source.v2);
  22668. this.v3.copy(source.v3);
  22669. return this;
  22670. };
  22671. CubicBezierCurve3.prototype.toJSON = function () {
  22672. var data = Curve.prototype.toJSON.call(this);
  22673. data.v0 = this.v0.toArray();
  22674. data.v1 = this.v1.toArray();
  22675. data.v2 = this.v2.toArray();
  22676. data.v3 = this.v3.toArray();
  22677. return data;
  22678. };
  22679. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22680. Curve.prototype.fromJSON.call(this, json);
  22681. this.v0.fromArray(json.v0);
  22682. this.v1.fromArray(json.v1);
  22683. this.v2.fromArray(json.v2);
  22684. this.v3.fromArray(json.v3);
  22685. return this;
  22686. };
  22687. function LineCurve(v1, v2) {
  22688. Curve.call(this);
  22689. this.type = 'LineCurve';
  22690. this.v1 = v1 || new Vector2();
  22691. this.v2 = v2 || new Vector2();
  22692. }
  22693. LineCurve.prototype = Object.create(Curve.prototype);
  22694. LineCurve.prototype.constructor = LineCurve;
  22695. LineCurve.prototype.isLineCurve = true;
  22696. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22697. var point = optionalTarget || new Vector2();
  22698. if (t === 1) {
  22699. point.copy(this.v2);
  22700. } else {
  22701. point.copy(this.v2).sub(this.v1);
  22702. point.multiplyScalar(t).add(this.v1);
  22703. }
  22704. return point;
  22705. }; // Line curve is linear, so we can overwrite default getPointAt
  22706. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22707. return this.getPoint(u, optionalTarget);
  22708. };
  22709. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22710. var tangent = optionalTarget || new Vector2();
  22711. tangent.copy(this.v2).sub(this.v1).normalize();
  22712. return tangent;
  22713. };
  22714. LineCurve.prototype.copy = function (source) {
  22715. Curve.prototype.copy.call(this, source);
  22716. this.v1.copy(source.v1);
  22717. this.v2.copy(source.v2);
  22718. return this;
  22719. };
  22720. LineCurve.prototype.toJSON = function () {
  22721. var data = Curve.prototype.toJSON.call(this);
  22722. data.v1 = this.v1.toArray();
  22723. data.v2 = this.v2.toArray();
  22724. return data;
  22725. };
  22726. LineCurve.prototype.fromJSON = function (json) {
  22727. Curve.prototype.fromJSON.call(this, json);
  22728. this.v1.fromArray(json.v1);
  22729. this.v2.fromArray(json.v2);
  22730. return this;
  22731. };
  22732. function LineCurve3(v1, v2) {
  22733. Curve.call(this);
  22734. this.type = 'LineCurve3';
  22735. this.v1 = v1 || new Vector3();
  22736. this.v2 = v2 || new Vector3();
  22737. }
  22738. LineCurve3.prototype = Object.create(Curve.prototype);
  22739. LineCurve3.prototype.constructor = LineCurve3;
  22740. LineCurve3.prototype.isLineCurve3 = true;
  22741. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22742. var point = optionalTarget || new Vector3();
  22743. if (t === 1) {
  22744. point.copy(this.v2);
  22745. } else {
  22746. point.copy(this.v2).sub(this.v1);
  22747. point.multiplyScalar(t).add(this.v1);
  22748. }
  22749. return point;
  22750. }; // Line curve is linear, so we can overwrite default getPointAt
  22751. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22752. return this.getPoint(u, optionalTarget);
  22753. };
  22754. LineCurve3.prototype.copy = function (source) {
  22755. Curve.prototype.copy.call(this, source);
  22756. this.v1.copy(source.v1);
  22757. this.v2.copy(source.v2);
  22758. return this;
  22759. };
  22760. LineCurve3.prototype.toJSON = function () {
  22761. var data = Curve.prototype.toJSON.call(this);
  22762. data.v1 = this.v1.toArray();
  22763. data.v2 = this.v2.toArray();
  22764. return data;
  22765. };
  22766. LineCurve3.prototype.fromJSON = function (json) {
  22767. Curve.prototype.fromJSON.call(this, json);
  22768. this.v1.fromArray(json.v1);
  22769. this.v2.fromArray(json.v2);
  22770. return this;
  22771. };
  22772. function QuadraticBezierCurve(v0, v1, v2) {
  22773. Curve.call(this);
  22774. this.type = 'QuadraticBezierCurve';
  22775. this.v0 = v0 || new Vector2();
  22776. this.v1 = v1 || new Vector2();
  22777. this.v2 = v2 || new Vector2();
  22778. }
  22779. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22780. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22781. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22782. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22783. var point = optionalTarget || new Vector2();
  22784. var v0 = this.v0,
  22785. v1 = this.v1,
  22786. v2 = this.v2;
  22787. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22788. return point;
  22789. };
  22790. QuadraticBezierCurve.prototype.copy = function (source) {
  22791. Curve.prototype.copy.call(this, source);
  22792. this.v0.copy(source.v0);
  22793. this.v1.copy(source.v1);
  22794. this.v2.copy(source.v2);
  22795. return this;
  22796. };
  22797. QuadraticBezierCurve.prototype.toJSON = function () {
  22798. var data = Curve.prototype.toJSON.call(this);
  22799. data.v0 = this.v0.toArray();
  22800. data.v1 = this.v1.toArray();
  22801. data.v2 = this.v2.toArray();
  22802. return data;
  22803. };
  22804. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22805. Curve.prototype.fromJSON.call(this, json);
  22806. this.v0.fromArray(json.v0);
  22807. this.v1.fromArray(json.v1);
  22808. this.v2.fromArray(json.v2);
  22809. return this;
  22810. };
  22811. function QuadraticBezierCurve3(v0, v1, v2) {
  22812. Curve.call(this);
  22813. this.type = 'QuadraticBezierCurve3';
  22814. this.v0 = v0 || new Vector3();
  22815. this.v1 = v1 || new Vector3();
  22816. this.v2 = v2 || new Vector3();
  22817. }
  22818. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22819. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22820. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22821. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22822. var point = optionalTarget || new Vector3();
  22823. var v0 = this.v0,
  22824. v1 = this.v1,
  22825. v2 = this.v2;
  22826. 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));
  22827. return point;
  22828. };
  22829. QuadraticBezierCurve3.prototype.copy = function (source) {
  22830. Curve.prototype.copy.call(this, source);
  22831. this.v0.copy(source.v0);
  22832. this.v1.copy(source.v1);
  22833. this.v2.copy(source.v2);
  22834. return this;
  22835. };
  22836. QuadraticBezierCurve3.prototype.toJSON = function () {
  22837. var data = Curve.prototype.toJSON.call(this);
  22838. data.v0 = this.v0.toArray();
  22839. data.v1 = this.v1.toArray();
  22840. data.v2 = this.v2.toArray();
  22841. return data;
  22842. };
  22843. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22844. Curve.prototype.fromJSON.call(this, json);
  22845. this.v0.fromArray(json.v0);
  22846. this.v1.fromArray(json.v1);
  22847. this.v2.fromArray(json.v2);
  22848. return this;
  22849. };
  22850. function SplineCurve(points) {
  22851. Curve.call(this);
  22852. this.type = 'SplineCurve';
  22853. this.points = points || [];
  22854. }
  22855. SplineCurve.prototype = Object.create(Curve.prototype);
  22856. SplineCurve.prototype.constructor = SplineCurve;
  22857. SplineCurve.prototype.isSplineCurve = true;
  22858. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22859. var point = optionalTarget || new Vector2();
  22860. var points = this.points;
  22861. var p = (points.length - 1) * t;
  22862. var intPoint = Math.floor(p);
  22863. var weight = p - intPoint;
  22864. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22865. var p1 = points[intPoint];
  22866. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22867. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22868. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22869. return point;
  22870. };
  22871. SplineCurve.prototype.copy = function (source) {
  22872. Curve.prototype.copy.call(this, source);
  22873. this.points = [];
  22874. for (var i = 0, l = source.points.length; i < l; i++) {
  22875. var point = source.points[i];
  22876. this.points.push(point.clone());
  22877. }
  22878. return this;
  22879. };
  22880. SplineCurve.prototype.toJSON = function () {
  22881. var data = Curve.prototype.toJSON.call(this);
  22882. data.points = [];
  22883. for (var i = 0, l = this.points.length; i < l; i++) {
  22884. var point = this.points[i];
  22885. data.points.push(point.toArray());
  22886. }
  22887. return data;
  22888. };
  22889. SplineCurve.prototype.fromJSON = function (json) {
  22890. Curve.prototype.fromJSON.call(this, json);
  22891. this.points = [];
  22892. for (var i = 0, l = json.points.length; i < l; i++) {
  22893. var point = json.points[i];
  22894. this.points.push(new Vector2().fromArray(point));
  22895. }
  22896. return this;
  22897. };
  22898. var Curves = /*#__PURE__*/Object.freeze({
  22899. __proto__: null,
  22900. ArcCurve: ArcCurve,
  22901. CatmullRomCurve3: CatmullRomCurve3,
  22902. CubicBezierCurve: CubicBezierCurve,
  22903. CubicBezierCurve3: CubicBezierCurve3,
  22904. EllipseCurve: EllipseCurve,
  22905. LineCurve: LineCurve,
  22906. LineCurve3: LineCurve3,
  22907. QuadraticBezierCurve: QuadraticBezierCurve,
  22908. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22909. SplineCurve: SplineCurve
  22910. });
  22911. /**************************************************************
  22912. * Curved Path - a curve path is simply a array of connected
  22913. * curves, but retains the api of a curve
  22914. **************************************************************/
  22915. function CurvePath() {
  22916. Curve.call(this);
  22917. this.type = 'CurvePath';
  22918. this.curves = [];
  22919. this.autoClose = false; // Automatically closes the path
  22920. }
  22921. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22922. constructor: CurvePath,
  22923. add: function add(curve) {
  22924. this.curves.push(curve);
  22925. },
  22926. closePath: function closePath() {
  22927. // Add a line curve if start and end of lines are not connected
  22928. var startPoint = this.curves[0].getPoint(0);
  22929. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22930. if (!startPoint.equals(endPoint)) {
  22931. this.curves.push(new LineCurve(endPoint, startPoint));
  22932. }
  22933. },
  22934. // To get accurate point with reference to
  22935. // entire path distance at time t,
  22936. // following has to be done:
  22937. // 1. Length of each sub path have to be known
  22938. // 2. Locate and identify type of curve
  22939. // 3. Get t for the curve
  22940. // 4. Return curve.getPointAt(t')
  22941. getPoint: function getPoint(t) {
  22942. var d = t * this.getLength();
  22943. var curveLengths = this.getCurveLengths();
  22944. var i = 0; // To think about boundaries points.
  22945. while (i < curveLengths.length) {
  22946. if (curveLengths[i] >= d) {
  22947. var diff = curveLengths[i] - d;
  22948. var curve = this.curves[i];
  22949. var segmentLength = curve.getLength();
  22950. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22951. return curve.getPointAt(u);
  22952. }
  22953. i++;
  22954. }
  22955. return null; // loop where sum != 0, sum > d , sum+1 <d
  22956. },
  22957. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22958. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22959. // getPoint() depends on getLength
  22960. getLength: function getLength() {
  22961. var lens = this.getCurveLengths();
  22962. return lens[lens.length - 1];
  22963. },
  22964. // cacheLengths must be recalculated.
  22965. updateArcLengths: function updateArcLengths() {
  22966. this.needsUpdate = true;
  22967. this.cacheLengths = null;
  22968. this.getCurveLengths();
  22969. },
  22970. // Compute lengths and cache them
  22971. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22972. getCurveLengths: function getCurveLengths() {
  22973. // We use cache values if curves and cache array are same length
  22974. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22975. return this.cacheLengths;
  22976. } // Get length of sub-curve
  22977. // Push sums into cached array
  22978. var lengths = [];
  22979. var sums = 0;
  22980. for (var i = 0, l = this.curves.length; i < l; i++) {
  22981. sums += this.curves[i].getLength();
  22982. lengths.push(sums);
  22983. }
  22984. this.cacheLengths = lengths;
  22985. return lengths;
  22986. },
  22987. getSpacedPoints: function getSpacedPoints(divisions) {
  22988. if (divisions === undefined) divisions = 40;
  22989. var points = [];
  22990. for (var i = 0; i <= divisions; i++) {
  22991. points.push(this.getPoint(i / divisions));
  22992. }
  22993. if (this.autoClose) {
  22994. points.push(points[0]);
  22995. }
  22996. return points;
  22997. },
  22998. getPoints: function getPoints(divisions) {
  22999. divisions = divisions || 12;
  23000. var points = [];
  23001. var last;
  23002. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23003. var curve = curves[i];
  23004. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23005. var pts = curve.getPoints(resolution);
  23006. for (var j = 0; j < pts.length; j++) {
  23007. var point = pts[j];
  23008. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23009. points.push(point);
  23010. last = point;
  23011. }
  23012. }
  23013. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23014. points.push(points[0]);
  23015. }
  23016. return points;
  23017. },
  23018. copy: function copy(source) {
  23019. Curve.prototype.copy.call(this, source);
  23020. this.curves = [];
  23021. for (var i = 0, l = source.curves.length; i < l; i++) {
  23022. var curve = source.curves[i];
  23023. this.curves.push(curve.clone());
  23024. }
  23025. this.autoClose = source.autoClose;
  23026. return this;
  23027. },
  23028. toJSON: function toJSON() {
  23029. var data = Curve.prototype.toJSON.call(this);
  23030. data.autoClose = this.autoClose;
  23031. data.curves = [];
  23032. for (var i = 0, l = this.curves.length; i < l; i++) {
  23033. var curve = this.curves[i];
  23034. data.curves.push(curve.toJSON());
  23035. }
  23036. return data;
  23037. },
  23038. fromJSON: function fromJSON(json) {
  23039. Curve.prototype.fromJSON.call(this, json);
  23040. this.autoClose = json.autoClose;
  23041. this.curves = [];
  23042. for (var i = 0, l = json.curves.length; i < l; i++) {
  23043. var curve = json.curves[i];
  23044. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23045. }
  23046. return this;
  23047. }
  23048. });
  23049. function Path(points) {
  23050. CurvePath.call(this);
  23051. this.type = 'Path';
  23052. this.currentPoint = new Vector2();
  23053. if (points) {
  23054. this.setFromPoints(points);
  23055. }
  23056. }
  23057. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  23058. constructor: Path,
  23059. setFromPoints: function setFromPoints(points) {
  23060. this.moveTo(points[0].x, points[0].y);
  23061. for (var i = 1, l = points.length; i < l; i++) {
  23062. this.lineTo(points[i].x, points[i].y);
  23063. }
  23064. return this;
  23065. },
  23066. moveTo: function moveTo(x, y) {
  23067. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23068. return this;
  23069. },
  23070. lineTo: function lineTo(x, y) {
  23071. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23072. this.curves.push(curve);
  23073. this.currentPoint.set(x, y);
  23074. return this;
  23075. },
  23076. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23077. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23078. this.curves.push(curve);
  23079. this.currentPoint.set(aX, aY);
  23080. return this;
  23081. },
  23082. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23083. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23084. this.curves.push(curve);
  23085. this.currentPoint.set(aX, aY);
  23086. return this;
  23087. },
  23088. splineThru: function splineThru(pts
  23089. /*Array of Vector*/
  23090. ) {
  23091. var npts = [this.currentPoint.clone()].concat(pts);
  23092. var curve = new SplineCurve(npts);
  23093. this.curves.push(curve);
  23094. this.currentPoint.copy(pts[pts.length - 1]);
  23095. return this;
  23096. },
  23097. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23098. var x0 = this.currentPoint.x;
  23099. var y0 = this.currentPoint.y;
  23100. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23101. return this;
  23102. },
  23103. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23104. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23105. return this;
  23106. },
  23107. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23108. var x0 = this.currentPoint.x;
  23109. var y0 = this.currentPoint.y;
  23110. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23111. return this;
  23112. },
  23113. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23114. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23115. if (this.curves.length > 0) {
  23116. // if a previous curve is present, attempt to join
  23117. var firstPoint = curve.getPoint(0);
  23118. if (!firstPoint.equals(this.currentPoint)) {
  23119. this.lineTo(firstPoint.x, firstPoint.y);
  23120. }
  23121. }
  23122. this.curves.push(curve);
  23123. var lastPoint = curve.getPoint(1);
  23124. this.currentPoint.copy(lastPoint);
  23125. return this;
  23126. },
  23127. copy: function copy(source) {
  23128. CurvePath.prototype.copy.call(this, source);
  23129. this.currentPoint.copy(source.currentPoint);
  23130. return this;
  23131. },
  23132. toJSON: function toJSON() {
  23133. var data = CurvePath.prototype.toJSON.call(this);
  23134. data.currentPoint = this.currentPoint.toArray();
  23135. return data;
  23136. },
  23137. fromJSON: function fromJSON(json) {
  23138. CurvePath.prototype.fromJSON.call(this, json);
  23139. this.currentPoint.fromArray(json.currentPoint);
  23140. return this;
  23141. }
  23142. });
  23143. function Shape(points) {
  23144. Path.call(this, points);
  23145. this.uuid = MathUtils.generateUUID();
  23146. this.type = 'Shape';
  23147. this.holes = [];
  23148. }
  23149. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23150. constructor: Shape,
  23151. getPointsHoles: function getPointsHoles(divisions) {
  23152. var holesPts = [];
  23153. for (var i = 0, l = this.holes.length; i < l; i++) {
  23154. holesPts[i] = this.holes[i].getPoints(divisions);
  23155. }
  23156. return holesPts;
  23157. },
  23158. // get points of shape and holes (keypoints based on segments parameter)
  23159. extractPoints: function extractPoints(divisions) {
  23160. return {
  23161. shape: this.getPoints(divisions),
  23162. holes: this.getPointsHoles(divisions)
  23163. };
  23164. },
  23165. copy: function copy(source) {
  23166. Path.prototype.copy.call(this, source);
  23167. this.holes = [];
  23168. for (var i = 0, l = source.holes.length; i < l; i++) {
  23169. var hole = source.holes[i];
  23170. this.holes.push(hole.clone());
  23171. }
  23172. return this;
  23173. },
  23174. toJSON: function toJSON() {
  23175. var data = Path.prototype.toJSON.call(this);
  23176. data.uuid = this.uuid;
  23177. data.holes = [];
  23178. for (var i = 0, l = this.holes.length; i < l; i++) {
  23179. var hole = this.holes[i];
  23180. data.holes.push(hole.toJSON());
  23181. }
  23182. return data;
  23183. },
  23184. fromJSON: function fromJSON(json) {
  23185. Path.prototype.fromJSON.call(this, json);
  23186. this.uuid = json.uuid;
  23187. this.holes = [];
  23188. for (var i = 0, l = json.holes.length; i < l; i++) {
  23189. var hole = json.holes[i];
  23190. this.holes.push(new Path().fromJSON(hole));
  23191. }
  23192. return this;
  23193. }
  23194. });
  23195. function Light(color, intensity) {
  23196. Object3D.call(this);
  23197. this.type = 'Light';
  23198. this.color = new Color(color);
  23199. this.intensity = intensity !== undefined ? intensity : 1;
  23200. }
  23201. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23202. constructor: Light,
  23203. isLight: true,
  23204. copy: function copy(source) {
  23205. Object3D.prototype.copy.call(this, source);
  23206. this.color.copy(source.color);
  23207. this.intensity = source.intensity;
  23208. return this;
  23209. },
  23210. toJSON: function toJSON(meta) {
  23211. var data = Object3D.prototype.toJSON.call(this, meta);
  23212. data.object.color = this.color.getHex();
  23213. data.object.intensity = this.intensity;
  23214. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23215. if (this.distance !== undefined) data.object.distance = this.distance;
  23216. if (this.angle !== undefined) data.object.angle = this.angle;
  23217. if (this.decay !== undefined) data.object.decay = this.decay;
  23218. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23219. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23220. return data;
  23221. }
  23222. });
  23223. function HemisphereLight(skyColor, groundColor, intensity) {
  23224. Light.call(this, skyColor, intensity);
  23225. this.type = 'HemisphereLight';
  23226. this.position.copy(Object3D.DefaultUp);
  23227. this.updateMatrix();
  23228. this.groundColor = new Color(groundColor);
  23229. }
  23230. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23231. constructor: HemisphereLight,
  23232. isHemisphereLight: true,
  23233. copy: function copy(source) {
  23234. Light.prototype.copy.call(this, source);
  23235. this.groundColor.copy(source.groundColor);
  23236. return this;
  23237. }
  23238. });
  23239. function LightShadow(camera) {
  23240. this.camera = camera;
  23241. this.bias = 0;
  23242. this.normalBias = 0;
  23243. this.radius = 1;
  23244. this.mapSize = new Vector2(512, 512);
  23245. this.map = null;
  23246. this.mapPass = null;
  23247. this.matrix = new Matrix4();
  23248. this.autoUpdate = true;
  23249. this.needsUpdate = false;
  23250. this._frustum = new Frustum();
  23251. this._frameExtents = new Vector2(1, 1);
  23252. this._viewportCount = 1;
  23253. this._viewports = [new Vector4(0, 0, 1, 1)];
  23254. }
  23255. Object.assign(LightShadow.prototype, {
  23256. _projScreenMatrix: new Matrix4(),
  23257. _lightPositionWorld: new Vector3(),
  23258. _lookTarget: new Vector3(),
  23259. getViewportCount: function getViewportCount() {
  23260. return this._viewportCount;
  23261. },
  23262. getFrustum: function getFrustum() {
  23263. return this._frustum;
  23264. },
  23265. updateMatrices: function updateMatrices(light) {
  23266. var shadowCamera = this.camera,
  23267. shadowMatrix = this.matrix,
  23268. projScreenMatrix = this._projScreenMatrix,
  23269. lookTarget = this._lookTarget,
  23270. lightPositionWorld = this._lightPositionWorld;
  23271. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23272. shadowCamera.position.copy(lightPositionWorld);
  23273. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23274. shadowCamera.lookAt(lookTarget);
  23275. shadowCamera.updateMatrixWorld();
  23276. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23277. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23278. 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);
  23279. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23280. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23281. },
  23282. getViewport: function getViewport(viewportIndex) {
  23283. return this._viewports[viewportIndex];
  23284. },
  23285. getFrameExtents: function getFrameExtents() {
  23286. return this._frameExtents;
  23287. },
  23288. copy: function copy(source) {
  23289. this.camera = source.camera.clone();
  23290. this.bias = source.bias;
  23291. this.radius = source.radius;
  23292. this.mapSize.copy(source.mapSize);
  23293. return this;
  23294. },
  23295. clone: function clone() {
  23296. return new this.constructor().copy(this);
  23297. },
  23298. toJSON: function toJSON() {
  23299. var object = {};
  23300. if (this.bias !== 0) object.bias = this.bias;
  23301. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23302. if (this.radius !== 1) object.radius = this.radius;
  23303. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23304. object.camera = this.camera.toJSON(false).object;
  23305. delete object.camera.matrix;
  23306. return object;
  23307. }
  23308. });
  23309. function SpotLightShadow() {
  23310. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23311. this.focus = 1;
  23312. }
  23313. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23314. constructor: SpotLightShadow,
  23315. isSpotLightShadow: true,
  23316. updateMatrices: function updateMatrices(light) {
  23317. var camera = this.camera;
  23318. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23319. var aspect = this.mapSize.width / this.mapSize.height;
  23320. var far = light.distance || camera.far;
  23321. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23322. camera.fov = fov;
  23323. camera.aspect = aspect;
  23324. camera.far = far;
  23325. camera.updateProjectionMatrix();
  23326. }
  23327. LightShadow.prototype.updateMatrices.call(this, light);
  23328. }
  23329. });
  23330. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23331. Light.call(this, color, intensity);
  23332. this.type = 'SpotLight';
  23333. this.position.copy(Object3D.DefaultUp);
  23334. this.updateMatrix();
  23335. this.target = new Object3D();
  23336. Object.defineProperty(this, 'power', {
  23337. get: function get() {
  23338. // intensity = power per solid angle.
  23339. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23340. return this.intensity * Math.PI;
  23341. },
  23342. set: function set(power) {
  23343. // intensity = power per solid angle.
  23344. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23345. this.intensity = power / Math.PI;
  23346. }
  23347. });
  23348. this.distance = distance !== undefined ? distance : 0;
  23349. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23350. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23351. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23352. this.shadow = new SpotLightShadow();
  23353. }
  23354. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23355. constructor: SpotLight,
  23356. isSpotLight: true,
  23357. copy: function copy(source) {
  23358. Light.prototype.copy.call(this, source);
  23359. this.distance = source.distance;
  23360. this.angle = source.angle;
  23361. this.penumbra = source.penumbra;
  23362. this.decay = source.decay;
  23363. this.target = source.target.clone();
  23364. this.shadow = source.shadow.clone();
  23365. return this;
  23366. }
  23367. });
  23368. function PointLightShadow() {
  23369. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23370. this._frameExtents = new Vector2(4, 2);
  23371. this._viewportCount = 6;
  23372. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23373. // following orientation:
  23374. //
  23375. // xzXZ
  23376. // y Y
  23377. //
  23378. // X - Positive x direction
  23379. // x - Negative x direction
  23380. // Y - Positive y direction
  23381. // y - Negative y direction
  23382. // Z - Positive z direction
  23383. // z - Negative z direction
  23384. // positive X
  23385. new Vector4(2, 1, 1, 1), // negative X
  23386. new Vector4(0, 1, 1, 1), // positive Z
  23387. new Vector4(3, 1, 1, 1), // negative Z
  23388. new Vector4(1, 1, 1, 1), // positive Y
  23389. new Vector4(3, 0, 1, 1), // negative Y
  23390. new Vector4(1, 0, 1, 1)];
  23391. 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)];
  23392. 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)];
  23393. }
  23394. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23395. constructor: PointLightShadow,
  23396. isPointLightShadow: true,
  23397. updateMatrices: function updateMatrices(light, viewportIndex) {
  23398. if (viewportIndex === undefined) viewportIndex = 0;
  23399. var camera = this.camera,
  23400. shadowMatrix = this.matrix,
  23401. lightPositionWorld = this._lightPositionWorld,
  23402. lookTarget = this._lookTarget,
  23403. projScreenMatrix = this._projScreenMatrix;
  23404. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23405. camera.position.copy(lightPositionWorld);
  23406. lookTarget.copy(camera.position);
  23407. lookTarget.add(this._cubeDirections[viewportIndex]);
  23408. camera.up.copy(this._cubeUps[viewportIndex]);
  23409. camera.lookAt(lookTarget);
  23410. camera.updateMatrixWorld();
  23411. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23412. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23413. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23414. }
  23415. });
  23416. function PointLight(color, intensity, distance, decay) {
  23417. Light.call(this, color, intensity);
  23418. this.type = 'PointLight';
  23419. Object.defineProperty(this, 'power', {
  23420. get: function get() {
  23421. // intensity = power per solid angle.
  23422. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23423. return this.intensity * 4 * Math.PI;
  23424. },
  23425. set: function set(power) {
  23426. // intensity = power per solid angle.
  23427. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23428. this.intensity = power / (4 * Math.PI);
  23429. }
  23430. });
  23431. this.distance = distance !== undefined ? distance : 0;
  23432. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23433. this.shadow = new PointLightShadow();
  23434. }
  23435. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23436. constructor: PointLight,
  23437. isPointLight: true,
  23438. copy: function copy(source) {
  23439. Light.prototype.copy.call(this, source);
  23440. this.distance = source.distance;
  23441. this.decay = source.decay;
  23442. this.shadow = source.shadow.clone();
  23443. return this;
  23444. }
  23445. });
  23446. function OrthographicCamera(left, right, top, bottom, near, far) {
  23447. Camera.call(this);
  23448. this.type = 'OrthographicCamera';
  23449. this.zoom = 1;
  23450. this.view = null;
  23451. this.left = left !== undefined ? left : -1;
  23452. this.right = right !== undefined ? right : 1;
  23453. this.top = top !== undefined ? top : 1;
  23454. this.bottom = bottom !== undefined ? bottom : -1;
  23455. this.near = near !== undefined ? near : 0.1;
  23456. this.far = far !== undefined ? far : 2000;
  23457. this.updateProjectionMatrix();
  23458. }
  23459. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23460. constructor: OrthographicCamera,
  23461. isOrthographicCamera: true,
  23462. copy: function copy(source, recursive) {
  23463. Camera.prototype.copy.call(this, source, recursive);
  23464. this.left = source.left;
  23465. this.right = source.right;
  23466. this.top = source.top;
  23467. this.bottom = source.bottom;
  23468. this.near = source.near;
  23469. this.far = source.far;
  23470. this.zoom = source.zoom;
  23471. this.view = source.view === null ? null : Object.assign({}, source.view);
  23472. return this;
  23473. },
  23474. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23475. if (this.view === null) {
  23476. this.view = {
  23477. enabled: true,
  23478. fullWidth: 1,
  23479. fullHeight: 1,
  23480. offsetX: 0,
  23481. offsetY: 0,
  23482. width: 1,
  23483. height: 1
  23484. };
  23485. }
  23486. this.view.enabled = true;
  23487. this.view.fullWidth = fullWidth;
  23488. this.view.fullHeight = fullHeight;
  23489. this.view.offsetX = x;
  23490. this.view.offsetY = y;
  23491. this.view.width = width;
  23492. this.view.height = height;
  23493. this.updateProjectionMatrix();
  23494. },
  23495. clearViewOffset: function clearViewOffset() {
  23496. if (this.view !== null) {
  23497. this.view.enabled = false;
  23498. }
  23499. this.updateProjectionMatrix();
  23500. },
  23501. updateProjectionMatrix: function updateProjectionMatrix() {
  23502. var dx = (this.right - this.left) / (2 * this.zoom);
  23503. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23504. var cx = (this.right + this.left) / 2;
  23505. var cy = (this.top + this.bottom) / 2;
  23506. var left = cx - dx;
  23507. var right = cx + dx;
  23508. var top = cy + dy;
  23509. var bottom = cy - dy;
  23510. if (this.view !== null && this.view.enabled) {
  23511. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23512. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23513. left += scaleW * this.view.offsetX;
  23514. right = left + scaleW * this.view.width;
  23515. top -= scaleH * this.view.offsetY;
  23516. bottom = top - scaleH * this.view.height;
  23517. }
  23518. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23519. this.projectionMatrixInverse.getInverse(this.projectionMatrix);
  23520. },
  23521. toJSON: function toJSON(meta) {
  23522. var data = Object3D.prototype.toJSON.call(this, meta);
  23523. data.object.zoom = this.zoom;
  23524. data.object.left = this.left;
  23525. data.object.right = this.right;
  23526. data.object.top = this.top;
  23527. data.object.bottom = this.bottom;
  23528. data.object.near = this.near;
  23529. data.object.far = this.far;
  23530. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23531. return data;
  23532. }
  23533. });
  23534. function DirectionalLightShadow() {
  23535. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23536. }
  23537. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23538. constructor: DirectionalLightShadow,
  23539. isDirectionalLightShadow: true,
  23540. updateMatrices: function updateMatrices(light) {
  23541. LightShadow.prototype.updateMatrices.call(this, light);
  23542. }
  23543. });
  23544. function DirectionalLight(color, intensity) {
  23545. Light.call(this, color, intensity);
  23546. this.type = 'DirectionalLight';
  23547. this.position.copy(Object3D.DefaultUp);
  23548. this.updateMatrix();
  23549. this.target = new Object3D();
  23550. this.shadow = new DirectionalLightShadow();
  23551. }
  23552. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23553. constructor: DirectionalLight,
  23554. isDirectionalLight: true,
  23555. copy: function copy(source) {
  23556. Light.prototype.copy.call(this, source);
  23557. this.target = source.target.clone();
  23558. this.shadow = source.shadow.clone();
  23559. return this;
  23560. }
  23561. });
  23562. function AmbientLight(color, intensity) {
  23563. Light.call(this, color, intensity);
  23564. this.type = 'AmbientLight';
  23565. }
  23566. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23567. constructor: AmbientLight,
  23568. isAmbientLight: true
  23569. });
  23570. function RectAreaLight(color, intensity, width, height) {
  23571. Light.call(this, color, intensity);
  23572. this.type = 'RectAreaLight';
  23573. this.width = width !== undefined ? width : 10;
  23574. this.height = height !== undefined ? height : 10;
  23575. }
  23576. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23577. constructor: RectAreaLight,
  23578. isRectAreaLight: true,
  23579. copy: function copy(source) {
  23580. Light.prototype.copy.call(this, source);
  23581. this.width = source.width;
  23582. this.height = source.height;
  23583. return this;
  23584. },
  23585. toJSON: function toJSON(meta) {
  23586. var data = Light.prototype.toJSON.call(this, meta);
  23587. data.object.width = this.width;
  23588. data.object.height = this.height;
  23589. return data;
  23590. }
  23591. });
  23592. /**
  23593. * Primary reference:
  23594. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23595. *
  23596. * Secondary reference:
  23597. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23598. */
  23599. // 3-band SH defined by 9 coefficients
  23600. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23601. function SphericalHarmonics3() {
  23602. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23603. value: true
  23604. });
  23605. this.coefficients = [];
  23606. for (var i = 0; i < 9; i++) {
  23607. this.coefficients.push(new Vector3());
  23608. }
  23609. }
  23610. var _proto = SphericalHarmonics3.prototype;
  23611. _proto.set = function set(coefficients) {
  23612. for (var i = 0; i < 9; i++) {
  23613. this.coefficients[i].copy(coefficients[i]);
  23614. }
  23615. return this;
  23616. };
  23617. _proto.zero = function zero() {
  23618. for (var i = 0; i < 9; i++) {
  23619. this.coefficients[i].set(0, 0, 0);
  23620. }
  23621. return this;
  23622. } // get the radiance in the direction of the normal
  23623. // target is a Vector3
  23624. ;
  23625. _proto.getAt = function getAt(normal, target) {
  23626. // normal is assumed to be unit length
  23627. var x = normal.x,
  23628. y = normal.y,
  23629. z = normal.z;
  23630. var coeff = this.coefficients; // band 0
  23631. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23632. target.addScaledVector(coeff[1], 0.488603 * y);
  23633. target.addScaledVector(coeff[2], 0.488603 * z);
  23634. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23635. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23636. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23637. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23638. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23639. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23640. return target;
  23641. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23642. // target is a Vector3
  23643. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23644. ;
  23645. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23646. // normal is assumed to be unit length
  23647. var x = normal.x,
  23648. y = normal.y,
  23649. z = normal.z;
  23650. var coeff = this.coefficients; // band 0
  23651. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23652. // band 1
  23653. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23654. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23655. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23656. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23657. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23658. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23659. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23660. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23661. return target;
  23662. };
  23663. _proto.add = function add(sh) {
  23664. for (var i = 0; i < 9; i++) {
  23665. this.coefficients[i].add(sh.coefficients[i]);
  23666. }
  23667. return this;
  23668. };
  23669. _proto.addScaledSH = function addScaledSH(sh, s) {
  23670. for (var i = 0; i < 9; i++) {
  23671. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23672. }
  23673. return this;
  23674. };
  23675. _proto.scale = function scale(s) {
  23676. for (var i = 0; i < 9; i++) {
  23677. this.coefficients[i].multiplyScalar(s);
  23678. }
  23679. return this;
  23680. };
  23681. _proto.lerp = function lerp(sh, alpha) {
  23682. for (var i = 0; i < 9; i++) {
  23683. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23684. }
  23685. return this;
  23686. };
  23687. _proto.equals = function equals(sh) {
  23688. for (var i = 0; i < 9; i++) {
  23689. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23690. return false;
  23691. }
  23692. }
  23693. return true;
  23694. };
  23695. _proto.copy = function copy(sh) {
  23696. return this.set(sh.coefficients);
  23697. };
  23698. _proto.clone = function clone() {
  23699. return new this.constructor().copy(this);
  23700. };
  23701. _proto.fromArray = function fromArray(array, offset) {
  23702. if (offset === void 0) {
  23703. offset = 0;
  23704. }
  23705. var coefficients = this.coefficients;
  23706. for (var i = 0; i < 9; i++) {
  23707. coefficients[i].fromArray(array, offset + i * 3);
  23708. }
  23709. return this;
  23710. };
  23711. _proto.toArray = function toArray(array, offset) {
  23712. if (array === void 0) {
  23713. array = [];
  23714. }
  23715. if (offset === void 0) {
  23716. offset = 0;
  23717. }
  23718. var coefficients = this.coefficients;
  23719. for (var i = 0; i < 9; i++) {
  23720. coefficients[i].toArray(array, offset + i * 3);
  23721. }
  23722. return array;
  23723. } // evaluate the basis functions
  23724. // shBasis is an Array[ 9 ]
  23725. ;
  23726. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23727. // normal is assumed to be unit length
  23728. var x = normal.x,
  23729. y = normal.y,
  23730. z = normal.z; // band 0
  23731. shBasis[0] = 0.282095; // band 1
  23732. shBasis[1] = 0.488603 * y;
  23733. shBasis[2] = 0.488603 * z;
  23734. shBasis[3] = 0.488603 * x; // band 2
  23735. shBasis[4] = 1.092548 * x * y;
  23736. shBasis[5] = 1.092548 * y * z;
  23737. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23738. shBasis[7] = 1.092548 * x * z;
  23739. shBasis[8] = 0.546274 * (x * x - y * y);
  23740. };
  23741. return SphericalHarmonics3;
  23742. }();
  23743. function LightProbe(sh, intensity) {
  23744. Light.call(this, undefined, intensity);
  23745. this.type = 'LightProbe';
  23746. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23747. }
  23748. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23749. constructor: LightProbe,
  23750. isLightProbe: true,
  23751. copy: function copy(source) {
  23752. Light.prototype.copy.call(this, source);
  23753. this.sh.copy(source.sh);
  23754. return this;
  23755. },
  23756. fromJSON: function fromJSON(json) {
  23757. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23758. this.sh.fromArray(json.sh);
  23759. return this;
  23760. },
  23761. toJSON: function toJSON(meta) {
  23762. var data = Light.prototype.toJSON.call(this, meta);
  23763. data.object.sh = this.sh.toArray();
  23764. return data;
  23765. }
  23766. });
  23767. function MaterialLoader(manager) {
  23768. Loader.call(this, manager);
  23769. this.textures = {};
  23770. }
  23771. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23772. constructor: MaterialLoader,
  23773. load: function load(url, onLoad, onProgress, onError) {
  23774. var scope = this;
  23775. var loader = new FileLoader(scope.manager);
  23776. loader.setPath(scope.path);
  23777. loader.setRequestHeader(scope.requestHeader);
  23778. loader.setWithCredentials(scope.withCredentials);
  23779. loader.load(url, function (text) {
  23780. try {
  23781. onLoad(scope.parse(JSON.parse(text)));
  23782. } catch (e) {
  23783. if (onError) {
  23784. onError(e);
  23785. } else {
  23786. console.error(e);
  23787. }
  23788. scope.manager.itemError(url);
  23789. }
  23790. }, onProgress, onError);
  23791. },
  23792. parse: function parse(json) {
  23793. var textures = this.textures;
  23794. function getTexture(name) {
  23795. if (textures[name] === undefined) {
  23796. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23797. }
  23798. return textures[name];
  23799. }
  23800. var material = new Materials[json.type]();
  23801. if (json.uuid !== undefined) material.uuid = json.uuid;
  23802. if (json.name !== undefined) material.name = json.name;
  23803. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23804. if (json.roughness !== undefined) material.roughness = json.roughness;
  23805. if (json.metalness !== undefined) material.metalness = json.metalness;
  23806. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23807. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23808. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23809. if (json.shininess !== undefined) material.shininess = json.shininess;
  23810. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23811. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23812. if (json.fog !== undefined) material.fog = json.fog;
  23813. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23814. if (json.blending !== undefined) material.blending = json.blending;
  23815. if (json.combine !== undefined) material.combine = json.combine;
  23816. if (json.side !== undefined) material.side = json.side;
  23817. if (json.opacity !== undefined) material.opacity = json.opacity;
  23818. if (json.transparent !== undefined) material.transparent = json.transparent;
  23819. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23820. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23821. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23822. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23823. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23824. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23825. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23826. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23827. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23828. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23829. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23830. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23831. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23832. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23833. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23834. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23835. if (json.rotation !== undefined) material.rotation = json.rotation;
  23836. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23837. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23838. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23839. if (json.scale !== undefined) material.scale = json.scale;
  23840. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23841. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23842. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23843. if (json.skinning !== undefined) material.skinning = json.skinning;
  23844. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23845. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23846. if (json.dithering !== undefined) material.dithering = json.dithering;
  23847. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23848. if (json.visible !== undefined) material.visible = json.visible;
  23849. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23850. if (json.userData !== undefined) material.userData = json.userData;
  23851. if (json.vertexColors !== undefined) {
  23852. if (typeof json.vertexColors === 'number') {
  23853. material.vertexColors = json.vertexColors > 0 ? true : false;
  23854. } else {
  23855. material.vertexColors = json.vertexColors;
  23856. }
  23857. } // Shader Material
  23858. if (json.uniforms !== undefined) {
  23859. for (var name in json.uniforms) {
  23860. var uniform = json.uniforms[name];
  23861. material.uniforms[name] = {};
  23862. switch (uniform.type) {
  23863. case 't':
  23864. material.uniforms[name].value = getTexture(uniform.value);
  23865. break;
  23866. case 'c':
  23867. material.uniforms[name].value = new Color().setHex(uniform.value);
  23868. break;
  23869. case 'v2':
  23870. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23871. break;
  23872. case 'v3':
  23873. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23874. break;
  23875. case 'v4':
  23876. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23877. break;
  23878. case 'm3':
  23879. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23880. break;
  23881. case 'm4':
  23882. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23883. break;
  23884. default:
  23885. material.uniforms[name].value = uniform.value;
  23886. }
  23887. }
  23888. }
  23889. if (json.defines !== undefined) material.defines = json.defines;
  23890. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23891. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23892. if (json.extensions !== undefined) {
  23893. for (var key in json.extensions) {
  23894. material.extensions[key] = json.extensions[key];
  23895. }
  23896. } // Deprecated
  23897. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23898. // for PointsMaterial
  23899. if (json.size !== undefined) material.size = json.size;
  23900. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23901. if (json.map !== undefined) material.map = getTexture(json.map);
  23902. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23903. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23904. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23905. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23906. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23907. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23908. if (json.normalScale !== undefined) {
  23909. var normalScale = json.normalScale;
  23910. if (Array.isArray(normalScale) === false) {
  23911. // Blender exporter used to export a scalar. See #7459
  23912. normalScale = [normalScale, normalScale];
  23913. }
  23914. material.normalScale = new Vector2().fromArray(normalScale);
  23915. }
  23916. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23917. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23918. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23919. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23920. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23921. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23922. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23923. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23924. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23925. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23926. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23927. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23928. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23929. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23930. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23931. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23932. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23933. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23934. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23935. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23936. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23937. if (json.transmission !== undefined) material.transmission = json.transmission;
  23938. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23939. return material;
  23940. },
  23941. setTextures: function setTextures(value) {
  23942. this.textures = value;
  23943. return this;
  23944. }
  23945. });
  23946. var LoaderUtils = {
  23947. decodeText: function decodeText(array) {
  23948. if (typeof TextDecoder !== 'undefined') {
  23949. return new TextDecoder().decode(array);
  23950. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23951. // throws a "maximum call stack size exceeded" error for large arrays.
  23952. var s = '';
  23953. for (var i = 0, il = array.length; i < il; i++) {
  23954. // Implicitly assumes little-endian.
  23955. s += String.fromCharCode(array[i]);
  23956. }
  23957. try {
  23958. // merges multi-byte utf-8 characters.
  23959. return decodeURIComponent(escape(s));
  23960. } catch (e) {
  23961. // see #16358
  23962. return s;
  23963. }
  23964. },
  23965. extractUrlBase: function extractUrlBase(url) {
  23966. var index = url.lastIndexOf('/');
  23967. if (index === -1) return './';
  23968. return url.substr(0, index + 1);
  23969. }
  23970. };
  23971. function InstancedBufferGeometry() {
  23972. BufferGeometry.call(this);
  23973. this.type = 'InstancedBufferGeometry';
  23974. this.instanceCount = Infinity;
  23975. }
  23976. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23977. constructor: InstancedBufferGeometry,
  23978. isInstancedBufferGeometry: true,
  23979. copy: function copy(source) {
  23980. BufferGeometry.prototype.copy.call(this, source);
  23981. this.instanceCount = source.instanceCount;
  23982. return this;
  23983. },
  23984. clone: function clone() {
  23985. return new this.constructor().copy(this);
  23986. },
  23987. toJSON: function toJSON() {
  23988. var data = BufferGeometry.prototype.toJSON.call(this);
  23989. data.instanceCount = this.instanceCount;
  23990. data.isInstancedBufferGeometry = true;
  23991. return data;
  23992. }
  23993. });
  23994. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23995. if (typeof normalized === 'number') {
  23996. meshPerAttribute = normalized;
  23997. normalized = false;
  23998. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23999. }
  24000. BufferAttribute.call(this, array, itemSize, normalized);
  24001. this.meshPerAttribute = meshPerAttribute || 1;
  24002. }
  24003. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24004. constructor: InstancedBufferAttribute,
  24005. isInstancedBufferAttribute: true,
  24006. copy: function copy(source) {
  24007. BufferAttribute.prototype.copy.call(this, source);
  24008. this.meshPerAttribute = source.meshPerAttribute;
  24009. return this;
  24010. },
  24011. toJSON: function toJSON() {
  24012. var data = BufferAttribute.prototype.toJSON.call(this);
  24013. data.meshPerAttribute = this.meshPerAttribute;
  24014. data.isInstancedBufferAttribute = true;
  24015. return data;
  24016. }
  24017. });
  24018. function BufferGeometryLoader(manager) {
  24019. Loader.call(this, manager);
  24020. }
  24021. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24022. constructor: BufferGeometryLoader,
  24023. load: function load(url, onLoad, onProgress, onError) {
  24024. var scope = this;
  24025. var loader = new FileLoader(scope.manager);
  24026. loader.setPath(scope.path);
  24027. loader.setRequestHeader(scope.requestHeader);
  24028. loader.setWithCredentials(scope.withCredentials);
  24029. loader.load(url, function (text) {
  24030. try {
  24031. onLoad(scope.parse(JSON.parse(text)));
  24032. } catch (e) {
  24033. if (onError) {
  24034. onError(e);
  24035. } else {
  24036. console.error(e);
  24037. }
  24038. scope.manager.itemError(url);
  24039. }
  24040. }, onProgress, onError);
  24041. },
  24042. parse: function parse(json) {
  24043. var interleavedBufferMap = {};
  24044. var arrayBufferMap = {};
  24045. function getInterleavedBuffer(json, uuid) {
  24046. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24047. var interleavedBuffers = json.interleavedBuffers;
  24048. var interleavedBuffer = interleavedBuffers[uuid];
  24049. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24050. var array = new TYPED_ARRAYS[interleavedBuffer.type](buffer);
  24051. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24052. ib.uuid = interleavedBuffer.uuid;
  24053. interleavedBufferMap[uuid] = ib;
  24054. return ib;
  24055. }
  24056. function getArrayBuffer(json, uuid) {
  24057. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24058. var arrayBuffers = json.arrayBuffers;
  24059. var arrayBuffer = arrayBuffers[uuid];
  24060. var ab = new Uint32Array(arrayBuffer).buffer;
  24061. arrayBufferMap[uuid] = ab;
  24062. return ab;
  24063. }
  24064. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24065. var index = json.data.index;
  24066. if (index !== undefined) {
  24067. var typedArray = new TYPED_ARRAYS[index.type](index.array);
  24068. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24069. }
  24070. var attributes = json.data.attributes;
  24071. for (var key in attributes) {
  24072. var attribute = attributes[key];
  24073. var bufferAttribute = void 0;
  24074. if (attribute.isInterleavedBufferAttribute) {
  24075. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24076. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24077. } else {
  24078. var _typedArray = new TYPED_ARRAYS[attribute.type](attribute.array);
  24079. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24080. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24081. }
  24082. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24083. geometry.setAttribute(key, bufferAttribute);
  24084. }
  24085. var morphAttributes = json.data.morphAttributes;
  24086. if (morphAttributes) {
  24087. for (var _key in morphAttributes) {
  24088. var attributeArray = morphAttributes[_key];
  24089. var array = [];
  24090. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24091. var _attribute = attributeArray[i];
  24092. var _bufferAttribute = void 0;
  24093. if (_attribute.isInterleavedBufferAttribute) {
  24094. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24095. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24096. } else {
  24097. var _typedArray2 = new TYPED_ARRAYS[_attribute.type](_attribute.array);
  24098. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24099. }
  24100. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24101. array.push(_bufferAttribute);
  24102. }
  24103. geometry.morphAttributes[_key] = array;
  24104. }
  24105. }
  24106. var morphTargetsRelative = json.data.morphTargetsRelative;
  24107. if (morphTargetsRelative) {
  24108. geometry.morphTargetsRelative = true;
  24109. }
  24110. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24111. if (groups !== undefined) {
  24112. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24113. var group = groups[_i];
  24114. geometry.addGroup(group.start, group.count, group.materialIndex);
  24115. }
  24116. }
  24117. var boundingSphere = json.data.boundingSphere;
  24118. if (boundingSphere !== undefined) {
  24119. var center = new Vector3();
  24120. if (boundingSphere.center !== undefined) {
  24121. center.fromArray(boundingSphere.center);
  24122. }
  24123. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24124. }
  24125. if (json.name) geometry.name = json.name;
  24126. if (json.userData) geometry.userData = json.userData;
  24127. return geometry;
  24128. }
  24129. });
  24130. var TYPED_ARRAYS = {
  24131. Int8Array: Int8Array,
  24132. Uint8Array: Uint8Array,
  24133. // Workaround for IE11 pre KB2929437. See #11440
  24134. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24135. Int16Array: Int16Array,
  24136. Uint16Array: Uint16Array,
  24137. Int32Array: Int32Array,
  24138. Uint32Array: Uint32Array,
  24139. Float32Array: Float32Array,
  24140. Float64Array: Float64Array
  24141. };
  24142. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24143. _inheritsLoose(ObjectLoader, _Loader);
  24144. function ObjectLoader(manager) {
  24145. return _Loader.call(this, manager) || this;
  24146. }
  24147. var _proto = ObjectLoader.prototype;
  24148. _proto.load = function load(url, onLoad, onProgress, onError) {
  24149. var scope = this;
  24150. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24151. this.resourcePath = this.resourcePath || path;
  24152. var loader = new FileLoader(this.manager);
  24153. loader.setPath(this.path);
  24154. loader.setRequestHeader(this.requestHeader);
  24155. loader.setWithCredentials(this.withCredentials);
  24156. loader.load(url, function (text) {
  24157. var json = null;
  24158. try {
  24159. json = JSON.parse(text);
  24160. } catch (error) {
  24161. if (onError !== undefined) onError(error);
  24162. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24163. return;
  24164. }
  24165. var metadata = json.metadata;
  24166. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24167. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24168. return;
  24169. }
  24170. scope.parse(json, onLoad);
  24171. }, onProgress, onError);
  24172. };
  24173. _proto.parse = function parse(json, onLoad) {
  24174. var shapes = this.parseShape(json.shapes);
  24175. var geometries = this.parseGeometries(json.geometries, shapes);
  24176. var images = this.parseImages(json.images, function () {
  24177. if (onLoad !== undefined) onLoad(object);
  24178. });
  24179. var textures = this.parseTextures(json.textures, images);
  24180. var materials = this.parseMaterials(json.materials, textures);
  24181. var object = this.parseObject(json.object, geometries, materials);
  24182. if (json.animations) {
  24183. object.animations = this.parseAnimations(json.animations);
  24184. }
  24185. if (json.images === undefined || json.images.length === 0) {
  24186. if (onLoad !== undefined) onLoad(object);
  24187. }
  24188. return object;
  24189. };
  24190. _proto.parseShape = function parseShape(json) {
  24191. var shapes = {};
  24192. if (json !== undefined) {
  24193. for (var i = 0, l = json.length; i < l; i++) {
  24194. var shape = new Shape().fromJSON(json[i]);
  24195. shapes[shape.uuid] = shape;
  24196. }
  24197. }
  24198. return shapes;
  24199. };
  24200. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24201. var geometries = {};
  24202. var geometryShapes;
  24203. if (json !== undefined) {
  24204. var bufferGeometryLoader = new BufferGeometryLoader();
  24205. for (var i = 0, l = json.length; i < l; i++) {
  24206. var geometry = void 0;
  24207. var data = json[i];
  24208. switch (data.type) {
  24209. case 'PlaneGeometry':
  24210. case 'PlaneBufferGeometry':
  24211. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24212. break;
  24213. case 'BoxGeometry':
  24214. case 'BoxBufferGeometry':
  24215. case 'CubeGeometry':
  24216. // backwards compatible
  24217. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24218. break;
  24219. case 'CircleGeometry':
  24220. case 'CircleBufferGeometry':
  24221. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24222. break;
  24223. case 'CylinderGeometry':
  24224. case 'CylinderBufferGeometry':
  24225. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24226. break;
  24227. case 'ConeGeometry':
  24228. case 'ConeBufferGeometry':
  24229. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24230. break;
  24231. case 'SphereGeometry':
  24232. case 'SphereBufferGeometry':
  24233. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24234. break;
  24235. case 'DodecahedronGeometry':
  24236. case 'DodecahedronBufferGeometry':
  24237. case 'IcosahedronGeometry':
  24238. case 'IcosahedronBufferGeometry':
  24239. case 'OctahedronGeometry':
  24240. case 'OctahedronBufferGeometry':
  24241. case 'TetrahedronGeometry':
  24242. case 'TetrahedronBufferGeometry':
  24243. geometry = new Geometries[data.type](data.radius, data.detail);
  24244. break;
  24245. case 'RingGeometry':
  24246. case 'RingBufferGeometry':
  24247. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24248. break;
  24249. case 'TorusGeometry':
  24250. case 'TorusBufferGeometry':
  24251. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24252. break;
  24253. case 'TorusKnotGeometry':
  24254. case 'TorusKnotBufferGeometry':
  24255. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24256. break;
  24257. case 'TubeGeometry':
  24258. case 'TubeBufferGeometry':
  24259. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24260. // User defined curves or instances of CurvePath will not be deserialized.
  24261. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24262. break;
  24263. case 'LatheGeometry':
  24264. case 'LatheBufferGeometry':
  24265. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24266. break;
  24267. case 'PolyhedronGeometry':
  24268. case 'PolyhedronBufferGeometry':
  24269. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24270. break;
  24271. case 'ShapeGeometry':
  24272. case 'ShapeBufferGeometry':
  24273. geometryShapes = [];
  24274. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24275. var shape = shapes[data.shapes[j]];
  24276. geometryShapes.push(shape);
  24277. }
  24278. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24279. break;
  24280. case 'ExtrudeGeometry':
  24281. case 'ExtrudeBufferGeometry':
  24282. geometryShapes = [];
  24283. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24284. var _shape = shapes[data.shapes[_j]];
  24285. geometryShapes.push(_shape);
  24286. }
  24287. var extrudePath = data.options.extrudePath;
  24288. if (extrudePath !== undefined) {
  24289. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24290. }
  24291. geometry = new Geometries[data.type](geometryShapes, data.options);
  24292. break;
  24293. case 'BufferGeometry':
  24294. case 'InstancedBufferGeometry':
  24295. geometry = bufferGeometryLoader.parse(data);
  24296. break;
  24297. case 'Geometry':
  24298. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24299. break;
  24300. default:
  24301. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24302. continue;
  24303. }
  24304. geometry.uuid = data.uuid;
  24305. if (data.name !== undefined) geometry.name = data.name;
  24306. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24307. geometries[data.uuid] = geometry;
  24308. }
  24309. }
  24310. return geometries;
  24311. };
  24312. _proto.parseMaterials = function parseMaterials(json, textures) {
  24313. var cache = {}; // MultiMaterial
  24314. var materials = {};
  24315. if (json !== undefined) {
  24316. var loader = new MaterialLoader();
  24317. loader.setTextures(textures);
  24318. for (var i = 0, l = json.length; i < l; i++) {
  24319. var data = json[i];
  24320. if (data.type === 'MultiMaterial') {
  24321. // Deprecated
  24322. var array = [];
  24323. for (var j = 0; j < data.materials.length; j++) {
  24324. var material = data.materials[j];
  24325. if (cache[material.uuid] === undefined) {
  24326. cache[material.uuid] = loader.parse(material);
  24327. }
  24328. array.push(cache[material.uuid]);
  24329. }
  24330. materials[data.uuid] = array;
  24331. } else {
  24332. if (cache[data.uuid] === undefined) {
  24333. cache[data.uuid] = loader.parse(data);
  24334. }
  24335. materials[data.uuid] = cache[data.uuid];
  24336. }
  24337. }
  24338. }
  24339. return materials;
  24340. };
  24341. _proto.parseAnimations = function parseAnimations(json) {
  24342. var animations = [];
  24343. for (var i = 0; i < json.length; i++) {
  24344. var data = json[i];
  24345. var clip = AnimationClip.parse(data);
  24346. if (data.uuid !== undefined) clip.uuid = data.uuid;
  24347. animations.push(clip);
  24348. }
  24349. return animations;
  24350. };
  24351. _proto.parseImages = function parseImages(json, onLoad) {
  24352. var scope = this;
  24353. var images = {};
  24354. var loader;
  24355. function loadImage(url) {
  24356. scope.manager.itemStart(url);
  24357. return loader.load(url, function () {
  24358. scope.manager.itemEnd(url);
  24359. }, undefined, function () {
  24360. scope.manager.itemError(url);
  24361. scope.manager.itemEnd(url);
  24362. });
  24363. }
  24364. if (json !== undefined && json.length > 0) {
  24365. var manager = new LoadingManager(onLoad);
  24366. loader = new ImageLoader(manager);
  24367. loader.setCrossOrigin(this.crossOrigin);
  24368. for (var i = 0, il = json.length; i < il; i++) {
  24369. var image = json[i];
  24370. var url = image.url;
  24371. if (Array.isArray(url)) {
  24372. // load array of images e.g CubeTexture
  24373. images[image.uuid] = [];
  24374. for (var j = 0, jl = url.length; j < jl; j++) {
  24375. var currentUrl = url[j];
  24376. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(currentUrl) ? currentUrl : scope.resourcePath + currentUrl;
  24377. images[image.uuid].push(loadImage(path));
  24378. }
  24379. } else {
  24380. // load single image
  24381. var _path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(image.url) ? image.url : scope.resourcePath + image.url;
  24382. images[image.uuid] = loadImage(_path);
  24383. }
  24384. }
  24385. }
  24386. return images;
  24387. };
  24388. _proto.parseTextures = function parseTextures(json, images) {
  24389. function parseConstant(value, type) {
  24390. if (typeof value === 'number') return value;
  24391. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24392. return type[value];
  24393. }
  24394. var textures = {};
  24395. if (json !== undefined) {
  24396. for (var i = 0, l = json.length; i < l; i++) {
  24397. var data = json[i];
  24398. if (data.image === undefined) {
  24399. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24400. }
  24401. if (images[data.image] === undefined) {
  24402. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24403. }
  24404. var texture = void 0;
  24405. if (Array.isArray(images[data.image])) {
  24406. texture = new CubeTexture(images[data.image]);
  24407. } else {
  24408. texture = new Texture(images[data.image]);
  24409. }
  24410. texture.needsUpdate = true;
  24411. texture.uuid = data.uuid;
  24412. if (data.name !== undefined) texture.name = data.name;
  24413. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24414. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24415. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24416. if (data.center !== undefined) texture.center.fromArray(data.center);
  24417. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24418. if (data.wrap !== undefined) {
  24419. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24420. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24421. }
  24422. if (data.format !== undefined) texture.format = data.format;
  24423. if (data.type !== undefined) texture.type = data.type;
  24424. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24425. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24426. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24427. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24428. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24429. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24430. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24431. textures[data.uuid] = texture;
  24432. }
  24433. }
  24434. return textures;
  24435. };
  24436. _proto.parseObject = function parseObject(data, geometries, materials) {
  24437. var object;
  24438. function getGeometry(name) {
  24439. if (geometries[name] === undefined) {
  24440. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24441. }
  24442. return geometries[name];
  24443. }
  24444. function getMaterial(name) {
  24445. if (name === undefined) return undefined;
  24446. if (Array.isArray(name)) {
  24447. var array = [];
  24448. for (var i = 0, l = name.length; i < l; i++) {
  24449. var uuid = name[i];
  24450. if (materials[uuid] === undefined) {
  24451. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24452. }
  24453. array.push(materials[uuid]);
  24454. }
  24455. return array;
  24456. }
  24457. if (materials[name] === undefined) {
  24458. console.warn('THREE.ObjectLoader: Undefined material', name);
  24459. }
  24460. return materials[name];
  24461. }
  24462. var geometry, material;
  24463. switch (data.type) {
  24464. case 'Scene':
  24465. object = new Scene();
  24466. if (data.background !== undefined) {
  24467. if (Number.isInteger(data.background)) {
  24468. object.background = new Color(data.background);
  24469. }
  24470. }
  24471. if (data.fog !== undefined) {
  24472. if (data.fog.type === 'Fog') {
  24473. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24474. } else if (data.fog.type === 'FogExp2') {
  24475. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24476. }
  24477. }
  24478. break;
  24479. case 'PerspectiveCamera':
  24480. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24481. if (data.focus !== undefined) object.focus = data.focus;
  24482. if (data.zoom !== undefined) object.zoom = data.zoom;
  24483. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24484. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24485. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24486. break;
  24487. case 'OrthographicCamera':
  24488. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24489. if (data.zoom !== undefined) object.zoom = data.zoom;
  24490. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24491. break;
  24492. case 'AmbientLight':
  24493. object = new AmbientLight(data.color, data.intensity);
  24494. break;
  24495. case 'DirectionalLight':
  24496. object = new DirectionalLight(data.color, data.intensity);
  24497. break;
  24498. case 'PointLight':
  24499. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24500. break;
  24501. case 'RectAreaLight':
  24502. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24503. break;
  24504. case 'SpotLight':
  24505. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24506. break;
  24507. case 'HemisphereLight':
  24508. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24509. break;
  24510. case 'LightProbe':
  24511. object = new LightProbe().fromJSON(data);
  24512. break;
  24513. case 'SkinnedMesh':
  24514. console.warn('THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.');
  24515. case 'Mesh':
  24516. geometry = getGeometry(data.geometry);
  24517. material = getMaterial(data.material);
  24518. object = new Mesh(geometry, material);
  24519. break;
  24520. case 'InstancedMesh':
  24521. geometry = getGeometry(data.geometry);
  24522. material = getMaterial(data.material);
  24523. var count = data.count;
  24524. var instanceMatrix = data.instanceMatrix;
  24525. object = new InstancedMesh(geometry, material, count);
  24526. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24527. break;
  24528. case 'LOD':
  24529. object = new LOD();
  24530. break;
  24531. case 'Line':
  24532. object = new Line(getGeometry(data.geometry), getMaterial(data.material), data.mode);
  24533. break;
  24534. case 'LineLoop':
  24535. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24536. break;
  24537. case 'LineSegments':
  24538. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24539. break;
  24540. case 'PointCloud':
  24541. case 'Points':
  24542. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24543. break;
  24544. case 'Sprite':
  24545. object = new Sprite(getMaterial(data.material));
  24546. break;
  24547. case 'Group':
  24548. object = new Group();
  24549. break;
  24550. default:
  24551. object = new Object3D();
  24552. }
  24553. object.uuid = data.uuid;
  24554. if (data.name !== undefined) object.name = data.name;
  24555. if (data.matrix !== undefined) {
  24556. object.matrix.fromArray(data.matrix);
  24557. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24558. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24559. } else {
  24560. if (data.position !== undefined) object.position.fromArray(data.position);
  24561. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24562. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24563. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24564. }
  24565. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24566. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24567. if (data.shadow) {
  24568. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24569. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24570. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24571. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24572. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24573. }
  24574. if (data.visible !== undefined) object.visible = data.visible;
  24575. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24576. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24577. if (data.userData !== undefined) object.userData = data.userData;
  24578. if (data.layers !== undefined) object.layers.mask = data.layers;
  24579. if (data.children !== undefined) {
  24580. var children = data.children;
  24581. for (var i = 0; i < children.length; i++) {
  24582. object.add(this.parseObject(children[i], geometries, materials));
  24583. }
  24584. }
  24585. if (data.type === 'LOD') {
  24586. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24587. var levels = data.levels;
  24588. for (var l = 0; l < levels.length; l++) {
  24589. var level = levels[l];
  24590. var child = object.getObjectByProperty('uuid', level.object);
  24591. if (child !== undefined) {
  24592. object.addLevel(child, level.distance);
  24593. }
  24594. }
  24595. }
  24596. return object;
  24597. }
  24598. /* DEPRECATED */
  24599. ;
  24600. _proto.setTexturePath = function setTexturePath(value) {
  24601. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24602. return this.setResourcePath(value);
  24603. };
  24604. return ObjectLoader;
  24605. }(Loader);
  24606. var TEXTURE_MAPPING = {
  24607. UVMapping: UVMapping,
  24608. CubeReflectionMapping: CubeReflectionMapping,
  24609. CubeRefractionMapping: CubeRefractionMapping,
  24610. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24611. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24612. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24613. CubeUVRefractionMapping: CubeUVRefractionMapping
  24614. };
  24615. var TEXTURE_WRAPPING = {
  24616. RepeatWrapping: RepeatWrapping,
  24617. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24618. MirroredRepeatWrapping: MirroredRepeatWrapping
  24619. };
  24620. var TEXTURE_FILTER = {
  24621. NearestFilter: NearestFilter,
  24622. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24623. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24624. LinearFilter: LinearFilter,
  24625. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24626. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24627. };
  24628. function ImageBitmapLoader(manager) {
  24629. if (typeof createImageBitmap === 'undefined') {
  24630. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24631. }
  24632. if (typeof fetch === 'undefined') {
  24633. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24634. }
  24635. Loader.call(this, manager);
  24636. this.options = {
  24637. premultiplyAlpha: 'none'
  24638. };
  24639. }
  24640. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24641. constructor: ImageBitmapLoader,
  24642. isImageBitmapLoader: true,
  24643. setOptions: function setOptions(options) {
  24644. this.options = options;
  24645. return this;
  24646. },
  24647. load: function load(url, onLoad, onProgress, onError) {
  24648. if (url === undefined) url = '';
  24649. if (this.path !== undefined) url = this.path + url;
  24650. url = this.manager.resolveURL(url);
  24651. var scope = this;
  24652. var cached = Cache.get(url);
  24653. if (cached !== undefined) {
  24654. scope.manager.itemStart(url);
  24655. setTimeout(function () {
  24656. if (onLoad) onLoad(cached);
  24657. scope.manager.itemEnd(url);
  24658. }, 0);
  24659. return cached;
  24660. }
  24661. var fetchOptions = {};
  24662. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24663. fetch(url, fetchOptions).then(function (res) {
  24664. return res.blob();
  24665. }).then(function (blob) {
  24666. return createImageBitmap(blob, scope.options);
  24667. }).then(function (imageBitmap) {
  24668. Cache.add(url, imageBitmap);
  24669. if (onLoad) onLoad(imageBitmap);
  24670. scope.manager.itemEnd(url);
  24671. }).catch(function (e) {
  24672. if (onError) onError(e);
  24673. scope.manager.itemError(url);
  24674. scope.manager.itemEnd(url);
  24675. });
  24676. scope.manager.itemStart(url);
  24677. }
  24678. });
  24679. function ShapePath() {
  24680. this.type = 'ShapePath';
  24681. this.color = new Color();
  24682. this.subPaths = [];
  24683. this.currentPath = null;
  24684. }
  24685. Object.assign(ShapePath.prototype, {
  24686. moveTo: function moveTo(x, y) {
  24687. this.currentPath = new Path();
  24688. this.subPaths.push(this.currentPath);
  24689. this.currentPath.moveTo(x, y);
  24690. return this;
  24691. },
  24692. lineTo: function lineTo(x, y) {
  24693. this.currentPath.lineTo(x, y);
  24694. return this;
  24695. },
  24696. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24697. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24698. return this;
  24699. },
  24700. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24701. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24702. return this;
  24703. },
  24704. splineThru: function splineThru(pts) {
  24705. this.currentPath.splineThru(pts);
  24706. return this;
  24707. },
  24708. toShapes: function toShapes(isCCW, noHoles) {
  24709. function toShapesNoHoles(inSubpaths) {
  24710. var shapes = [];
  24711. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24712. var _tmpPath = inSubpaths[i];
  24713. var _tmpShape = new Shape();
  24714. _tmpShape.curves = _tmpPath.curves;
  24715. shapes.push(_tmpShape);
  24716. }
  24717. return shapes;
  24718. }
  24719. function isPointInsidePolygon(inPt, inPolygon) {
  24720. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24721. // toggling of inside/outside at every single! intersection point of an edge
  24722. // with the horizontal line through inPt, left of inPt
  24723. // not counting lowerY endpoints of edges and whole edges on that line
  24724. var inside = false;
  24725. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24726. var edgeLowPt = inPolygon[p];
  24727. var edgeHighPt = inPolygon[q];
  24728. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24729. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24730. if (Math.abs(edgeDy) > Number.EPSILON) {
  24731. // not parallel
  24732. if (edgeDy < 0) {
  24733. edgeLowPt = inPolygon[q];
  24734. edgeDx = -edgeDx;
  24735. edgeHighPt = inPolygon[p];
  24736. edgeDy = -edgeDy;
  24737. }
  24738. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24739. if (inPt.y === edgeLowPt.y) {
  24740. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24741. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24742. } else {
  24743. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24744. if (perpEdge === 0) return true; // inPt is on contour ?
  24745. if (perpEdge < 0) continue;
  24746. inside = !inside; // true intersection left of inPt
  24747. }
  24748. } else {
  24749. // parallel or collinear
  24750. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24751. // edge lies on the same horizontal line as inPt
  24752. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24753. // continue;
  24754. }
  24755. }
  24756. return inside;
  24757. }
  24758. var isClockWise = ShapeUtils.isClockWise;
  24759. var subPaths = this.subPaths;
  24760. if (subPaths.length === 0) return [];
  24761. if (noHoles === true) return toShapesNoHoles(subPaths);
  24762. var solid, tmpPath, tmpShape;
  24763. var shapes = [];
  24764. if (subPaths.length === 1) {
  24765. tmpPath = subPaths[0];
  24766. tmpShape = new Shape();
  24767. tmpShape.curves = tmpPath.curves;
  24768. shapes.push(tmpShape);
  24769. return shapes;
  24770. }
  24771. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24772. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24773. var betterShapeHoles = [];
  24774. var newShapes = [];
  24775. var newShapeHoles = [];
  24776. var mainIdx = 0;
  24777. var tmpPoints;
  24778. newShapes[mainIdx] = undefined;
  24779. newShapeHoles[mainIdx] = [];
  24780. for (var i = 0, l = subPaths.length; i < l; i++) {
  24781. tmpPath = subPaths[i];
  24782. tmpPoints = tmpPath.getPoints();
  24783. solid = isClockWise(tmpPoints);
  24784. solid = isCCW ? !solid : solid;
  24785. if (solid) {
  24786. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24787. newShapes[mainIdx] = {
  24788. s: new Shape(),
  24789. p: tmpPoints
  24790. };
  24791. newShapes[mainIdx].s.curves = tmpPath.curves;
  24792. if (holesFirst) mainIdx++;
  24793. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24794. } else {
  24795. newShapeHoles[mainIdx].push({
  24796. h: tmpPath,
  24797. p: tmpPoints[0]
  24798. }); //console.log('ccw', i);
  24799. }
  24800. } // only Holes? -> probably all Shapes with wrong orientation
  24801. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24802. if (newShapes.length > 1) {
  24803. var ambiguous = false;
  24804. var toChange = [];
  24805. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24806. betterShapeHoles[sIdx] = [];
  24807. }
  24808. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24809. var sho = newShapeHoles[_sIdx];
  24810. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24811. var ho = sho[hIdx];
  24812. var hole_unassigned = true;
  24813. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24814. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24815. if (_sIdx !== s2Idx) toChange.push({
  24816. froms: _sIdx,
  24817. tos: s2Idx,
  24818. hole: hIdx
  24819. });
  24820. if (hole_unassigned) {
  24821. hole_unassigned = false;
  24822. betterShapeHoles[s2Idx].push(ho);
  24823. } else {
  24824. ambiguous = true;
  24825. }
  24826. }
  24827. }
  24828. if (hole_unassigned) {
  24829. betterShapeHoles[_sIdx].push(ho);
  24830. }
  24831. }
  24832. } // console.log("ambiguous: ", ambiguous);
  24833. if (toChange.length > 0) {
  24834. // console.log("to change: ", toChange);
  24835. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24836. }
  24837. }
  24838. var tmpHoles;
  24839. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24840. tmpShape = newShapes[_i].s;
  24841. shapes.push(tmpShape);
  24842. tmpHoles = newShapeHoles[_i];
  24843. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24844. tmpShape.holes.push(tmpHoles[j].h);
  24845. }
  24846. } //console.log("shape", shapes);
  24847. return shapes;
  24848. }
  24849. });
  24850. function Font(data) {
  24851. this.type = 'Font';
  24852. this.data = data;
  24853. }
  24854. Object.assign(Font.prototype, {
  24855. isFont: true,
  24856. generateShapes: function generateShapes(text, size) {
  24857. if (size === undefined) size = 100;
  24858. var shapes = [];
  24859. var paths = createPaths(text, size, this.data);
  24860. for (var p = 0, pl = paths.length; p < pl; p++) {
  24861. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24862. }
  24863. return shapes;
  24864. }
  24865. });
  24866. function createPaths(text, size, data) {
  24867. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24868. var scale = size / data.resolution;
  24869. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24870. var paths = [];
  24871. var offsetX = 0,
  24872. offsetY = 0;
  24873. for (var i = 0; i < chars.length; i++) {
  24874. var char = chars[i];
  24875. if (char === '\n') {
  24876. offsetX = 0;
  24877. offsetY -= line_height;
  24878. } else {
  24879. var ret = createPath(char, scale, offsetX, offsetY, data);
  24880. offsetX += ret.offsetX;
  24881. paths.push(ret.path);
  24882. }
  24883. }
  24884. return paths;
  24885. }
  24886. function createPath(char, scale, offsetX, offsetY, data) {
  24887. var glyph = data.glyphs[char] || data.glyphs['?'];
  24888. if (!glyph) {
  24889. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24890. return;
  24891. }
  24892. var path = new ShapePath();
  24893. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24894. if (glyph.o) {
  24895. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24896. for (var i = 0, l = outline.length; i < l;) {
  24897. var action = outline[i++];
  24898. switch (action) {
  24899. case 'm':
  24900. // moveTo
  24901. x = outline[i++] * scale + offsetX;
  24902. y = outline[i++] * scale + offsetY;
  24903. path.moveTo(x, y);
  24904. break;
  24905. case 'l':
  24906. // lineTo
  24907. x = outline[i++] * scale + offsetX;
  24908. y = outline[i++] * scale + offsetY;
  24909. path.lineTo(x, y);
  24910. break;
  24911. case 'q':
  24912. // quadraticCurveTo
  24913. cpx = outline[i++] * scale + offsetX;
  24914. cpy = outline[i++] * scale + offsetY;
  24915. cpx1 = outline[i++] * scale + offsetX;
  24916. cpy1 = outline[i++] * scale + offsetY;
  24917. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24918. break;
  24919. case 'b':
  24920. // bezierCurveTo
  24921. cpx = outline[i++] * scale + offsetX;
  24922. cpy = outline[i++] * scale + offsetY;
  24923. cpx1 = outline[i++] * scale + offsetX;
  24924. cpy1 = outline[i++] * scale + offsetY;
  24925. cpx2 = outline[i++] * scale + offsetX;
  24926. cpy2 = outline[i++] * scale + offsetY;
  24927. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24928. break;
  24929. }
  24930. }
  24931. }
  24932. return {
  24933. offsetX: glyph.ha * scale,
  24934. path: path
  24935. };
  24936. }
  24937. function FontLoader(manager) {
  24938. Loader.call(this, manager);
  24939. }
  24940. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24941. constructor: FontLoader,
  24942. load: function load(url, onLoad, onProgress, onError) {
  24943. var scope = this;
  24944. var loader = new FileLoader(this.manager);
  24945. loader.setPath(this.path);
  24946. loader.setRequestHeader(this.requestHeader);
  24947. loader.setWithCredentials(scope.withCredentials);
  24948. loader.load(url, function (text) {
  24949. var json;
  24950. try {
  24951. json = JSON.parse(text);
  24952. } catch (e) {
  24953. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24954. json = JSON.parse(text.substring(65, text.length - 2));
  24955. }
  24956. var font = scope.parse(json);
  24957. if (onLoad) onLoad(font);
  24958. }, onProgress, onError);
  24959. },
  24960. parse: function parse(json) {
  24961. return new Font(json);
  24962. }
  24963. });
  24964. var _context;
  24965. var AudioContext = {
  24966. getContext: function getContext() {
  24967. if (_context === undefined) {
  24968. _context = new (window.AudioContext || window.webkitAudioContext)();
  24969. }
  24970. return _context;
  24971. },
  24972. setContext: function setContext(value) {
  24973. _context = value;
  24974. }
  24975. };
  24976. function AudioLoader(manager) {
  24977. Loader.call(this, manager);
  24978. }
  24979. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24980. constructor: AudioLoader,
  24981. load: function load(url, onLoad, onProgress, onError) {
  24982. var scope = this;
  24983. var loader = new FileLoader(scope.manager);
  24984. loader.setResponseType('arraybuffer');
  24985. loader.setPath(scope.path);
  24986. loader.setRequestHeader(scope.requestHeader);
  24987. loader.setWithCredentials(scope.withCredentials);
  24988. loader.load(url, function (buffer) {
  24989. try {
  24990. // Create a copy of the buffer. The `decodeAudioData` method
  24991. // detaches the buffer when complete, preventing reuse.
  24992. var bufferCopy = buffer.slice(0);
  24993. var context = AudioContext.getContext();
  24994. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24995. onLoad(audioBuffer);
  24996. });
  24997. } catch (e) {
  24998. if (onError) {
  24999. onError(e);
  25000. } else {
  25001. console.error(e);
  25002. }
  25003. scope.manager.itemError(url);
  25004. }
  25005. }, onProgress, onError);
  25006. }
  25007. });
  25008. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25009. LightProbe.call(this, undefined, intensity);
  25010. var color1 = new Color().set(skyColor);
  25011. var color2 = new Color().set(groundColor);
  25012. var sky = new Vector3(color1.r, color1.g, color1.b);
  25013. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25014. var c0 = Math.sqrt(Math.PI);
  25015. var c1 = c0 * Math.sqrt(0.75);
  25016. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25017. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25018. }
  25019. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25020. constructor: HemisphereLightProbe,
  25021. isHemisphereLightProbe: true,
  25022. copy: function copy(source) {
  25023. // modifying colors not currently supported
  25024. LightProbe.prototype.copy.call(this, source);
  25025. return this;
  25026. },
  25027. toJSON: function toJSON(meta) {
  25028. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25029. return data;
  25030. }
  25031. });
  25032. function AmbientLightProbe(color, intensity) {
  25033. LightProbe.call(this, undefined, intensity);
  25034. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25035. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25036. }
  25037. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25038. constructor: AmbientLightProbe,
  25039. isAmbientLightProbe: true,
  25040. copy: function copy(source) {
  25041. // modifying color not currently supported
  25042. LightProbe.prototype.copy.call(this, source);
  25043. return this;
  25044. },
  25045. toJSON: function toJSON(meta) {
  25046. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25047. return data;
  25048. }
  25049. });
  25050. var _eyeRight = new Matrix4();
  25051. var _eyeLeft = new Matrix4();
  25052. function StereoCamera() {
  25053. this.type = 'StereoCamera';
  25054. this.aspect = 1;
  25055. this.eyeSep = 0.064;
  25056. this.cameraL = new PerspectiveCamera();
  25057. this.cameraL.layers.enable(1);
  25058. this.cameraL.matrixAutoUpdate = false;
  25059. this.cameraR = new PerspectiveCamera();
  25060. this.cameraR.layers.enable(2);
  25061. this.cameraR.matrixAutoUpdate = false;
  25062. this._cache = {
  25063. focus: null,
  25064. fov: null,
  25065. aspect: null,
  25066. near: null,
  25067. far: null,
  25068. zoom: null,
  25069. eyeSep: null
  25070. };
  25071. }
  25072. Object.assign(StereoCamera.prototype, {
  25073. update: function update(camera) {
  25074. var cache = this._cache;
  25075. 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;
  25076. if (needsUpdate) {
  25077. cache.focus = camera.focus;
  25078. cache.fov = camera.fov;
  25079. cache.aspect = camera.aspect * this.aspect;
  25080. cache.near = camera.near;
  25081. cache.far = camera.far;
  25082. cache.zoom = camera.zoom;
  25083. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25084. // http://paulbourke.net/stereographics/stereorender/
  25085. var projectionMatrix = camera.projectionMatrix.clone();
  25086. var eyeSepHalf = cache.eyeSep / 2;
  25087. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25088. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25089. var xmin, xmax; // translate xOffset
  25090. _eyeLeft.elements[12] = -eyeSepHalf;
  25091. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25092. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25093. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25094. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25095. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25096. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25097. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25098. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25099. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25100. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25101. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25102. }
  25103. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25104. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25105. }
  25106. });
  25107. var Clock = /*#__PURE__*/function () {
  25108. function Clock(autoStart) {
  25109. this.autoStart = autoStart !== undefined ? autoStart : true;
  25110. this.startTime = 0;
  25111. this.oldTime = 0;
  25112. this.elapsedTime = 0;
  25113. this.running = false;
  25114. }
  25115. var _proto = Clock.prototype;
  25116. _proto.start = function start() {
  25117. this.startTime = (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25118. this.oldTime = this.startTime;
  25119. this.elapsedTime = 0;
  25120. this.running = true;
  25121. };
  25122. _proto.stop = function stop() {
  25123. this.getElapsedTime();
  25124. this.running = false;
  25125. this.autoStart = false;
  25126. };
  25127. _proto.getElapsedTime = function getElapsedTime() {
  25128. this.getDelta();
  25129. return this.elapsedTime;
  25130. };
  25131. _proto.getDelta = function getDelta() {
  25132. var diff = 0;
  25133. if (this.autoStart && !this.running) {
  25134. this.start();
  25135. return 0;
  25136. }
  25137. if (this.running) {
  25138. var newTime = (typeof performance === 'undefined' ? Date : performance).now();
  25139. diff = (newTime - this.oldTime) / 1000;
  25140. this.oldTime = newTime;
  25141. this.elapsedTime += diff;
  25142. }
  25143. return diff;
  25144. };
  25145. return Clock;
  25146. }();
  25147. var _position$2 = /*@__PURE__*/new Vector3();
  25148. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25149. var _scale$1 = /*@__PURE__*/new Vector3();
  25150. var _orientation = /*@__PURE__*/new Vector3();
  25151. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25152. _inheritsLoose(AudioListener, _Object3D);
  25153. function AudioListener() {
  25154. var _this;
  25155. _this = _Object3D.call(this) || this;
  25156. _this.type = 'AudioListener';
  25157. _this.context = AudioContext.getContext();
  25158. _this.gain = _this.context.createGain();
  25159. _this.gain.connect(_this.context.destination);
  25160. _this.filter = null;
  25161. _this.timeDelta = 0; // private
  25162. _this._clock = new Clock();
  25163. return _this;
  25164. }
  25165. var _proto = AudioListener.prototype;
  25166. _proto.getInput = function getInput() {
  25167. return this.gain;
  25168. };
  25169. _proto.removeFilter = function removeFilter() {
  25170. if (this.filter !== null) {
  25171. this.gain.disconnect(this.filter);
  25172. this.filter.disconnect(this.context.destination);
  25173. this.gain.connect(this.context.destination);
  25174. this.filter = null;
  25175. }
  25176. return this;
  25177. };
  25178. _proto.getFilter = function getFilter() {
  25179. return this.filter;
  25180. };
  25181. _proto.setFilter = function setFilter(value) {
  25182. if (this.filter !== null) {
  25183. this.gain.disconnect(this.filter);
  25184. this.filter.disconnect(this.context.destination);
  25185. } else {
  25186. this.gain.disconnect(this.context.destination);
  25187. }
  25188. this.filter = value;
  25189. this.gain.connect(this.filter);
  25190. this.filter.connect(this.context.destination);
  25191. return this;
  25192. };
  25193. _proto.getMasterVolume = function getMasterVolume() {
  25194. return this.gain.gain.value;
  25195. };
  25196. _proto.setMasterVolume = function setMasterVolume(value) {
  25197. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25198. return this;
  25199. };
  25200. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25201. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25202. var listener = this.context.listener;
  25203. var up = this.up;
  25204. this.timeDelta = this._clock.getDelta();
  25205. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25206. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25207. if (listener.positionX) {
  25208. // code path for Chrome (see #14393)
  25209. var endTime = this.context.currentTime + this.timeDelta;
  25210. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25211. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25212. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25213. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25214. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25215. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25216. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25217. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25218. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25219. } else {
  25220. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25221. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25222. }
  25223. };
  25224. return AudioListener;
  25225. }(Object3D);
  25226. var Audio = /*#__PURE__*/function (_Object3D) {
  25227. _inheritsLoose(Audio, _Object3D);
  25228. function Audio(listener) {
  25229. var _this;
  25230. _this = _Object3D.call(this) || this;
  25231. _this.type = 'Audio';
  25232. _this.listener = listener;
  25233. _this.context = listener.context;
  25234. _this.gain = _this.context.createGain();
  25235. _this.gain.connect(listener.getInput());
  25236. _this.autoplay = false;
  25237. _this.buffer = null;
  25238. _this.detune = 0;
  25239. _this.loop = false;
  25240. _this.loopStart = 0;
  25241. _this.loopEnd = 0;
  25242. _this.offset = 0;
  25243. _this.duration = undefined;
  25244. _this.playbackRate = 1;
  25245. _this.isPlaying = false;
  25246. _this.hasPlaybackControl = true;
  25247. _this.source = null;
  25248. _this.sourceType = 'empty';
  25249. _this._startedAt = 0;
  25250. _this._progress = 0;
  25251. _this._connected = false;
  25252. _this.filters = [];
  25253. return _this;
  25254. }
  25255. var _proto = Audio.prototype;
  25256. _proto.getOutput = function getOutput() {
  25257. return this.gain;
  25258. };
  25259. _proto.setNodeSource = function setNodeSource(audioNode) {
  25260. this.hasPlaybackControl = false;
  25261. this.sourceType = 'audioNode';
  25262. this.source = audioNode;
  25263. this.connect();
  25264. return this;
  25265. };
  25266. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25267. this.hasPlaybackControl = false;
  25268. this.sourceType = 'mediaNode';
  25269. this.source = this.context.createMediaElementSource(mediaElement);
  25270. this.connect();
  25271. return this;
  25272. };
  25273. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25274. this.hasPlaybackControl = false;
  25275. this.sourceType = 'mediaStreamNode';
  25276. this.source = this.context.createMediaStreamSource(mediaStream);
  25277. this.connect();
  25278. return this;
  25279. };
  25280. _proto.setBuffer = function setBuffer(audioBuffer) {
  25281. this.buffer = audioBuffer;
  25282. this.sourceType = 'buffer';
  25283. if (this.autoplay) this.play();
  25284. return this;
  25285. };
  25286. _proto.play = function play(delay) {
  25287. if (delay === undefined) delay = 0;
  25288. if (this.isPlaying === true) {
  25289. console.warn('THREE.Audio: Audio is already playing.');
  25290. return;
  25291. }
  25292. if (this.hasPlaybackControl === false) {
  25293. console.warn('THREE.Audio: this Audio has no playback control.');
  25294. return;
  25295. }
  25296. this._startedAt = this.context.currentTime + delay;
  25297. var source = this.context.createBufferSource();
  25298. source.buffer = this.buffer;
  25299. source.loop = this.loop;
  25300. source.loopStart = this.loopStart;
  25301. source.loopEnd = this.loopEnd;
  25302. source.onended = this.onEnded.bind(this);
  25303. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25304. this.isPlaying = true;
  25305. this.source = source;
  25306. this.setDetune(this.detune);
  25307. this.setPlaybackRate(this.playbackRate);
  25308. return this.connect();
  25309. };
  25310. _proto.pause = function pause() {
  25311. if (this.hasPlaybackControl === false) {
  25312. console.warn('THREE.Audio: this Audio has no playback control.');
  25313. return;
  25314. }
  25315. if (this.isPlaying === true) {
  25316. // update current progress
  25317. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25318. if (this.loop === true) {
  25319. // ensure _progress does not exceed duration with looped audios
  25320. this._progress = this._progress % (this.duration || this.buffer.duration);
  25321. }
  25322. this.source.stop();
  25323. this.source.onended = null;
  25324. this.isPlaying = false;
  25325. }
  25326. return this;
  25327. };
  25328. _proto.stop = function stop() {
  25329. if (this.hasPlaybackControl === false) {
  25330. console.warn('THREE.Audio: this Audio has no playback control.');
  25331. return;
  25332. }
  25333. this._progress = 0;
  25334. this.source.stop();
  25335. this.source.onended = null;
  25336. this.isPlaying = false;
  25337. return this;
  25338. };
  25339. _proto.connect = function connect() {
  25340. if (this.filters.length > 0) {
  25341. this.source.connect(this.filters[0]);
  25342. for (var i = 1, l = this.filters.length; i < l; i++) {
  25343. this.filters[i - 1].connect(this.filters[i]);
  25344. }
  25345. this.filters[this.filters.length - 1].connect(this.getOutput());
  25346. } else {
  25347. this.source.connect(this.getOutput());
  25348. }
  25349. this._connected = true;
  25350. return this;
  25351. };
  25352. _proto.disconnect = function disconnect() {
  25353. if (this.filters.length > 0) {
  25354. this.source.disconnect(this.filters[0]);
  25355. for (var i = 1, l = this.filters.length; i < l; i++) {
  25356. this.filters[i - 1].disconnect(this.filters[i]);
  25357. }
  25358. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25359. } else {
  25360. this.source.disconnect(this.getOutput());
  25361. }
  25362. this._connected = false;
  25363. return this;
  25364. };
  25365. _proto.getFilters = function getFilters() {
  25366. return this.filters;
  25367. };
  25368. _proto.setFilters = function setFilters(value) {
  25369. if (!value) value = [];
  25370. if (this._connected === true) {
  25371. this.disconnect();
  25372. this.filters = value.slice();
  25373. this.connect();
  25374. } else {
  25375. this.filters = value.slice();
  25376. }
  25377. return this;
  25378. };
  25379. _proto.setDetune = function setDetune(value) {
  25380. this.detune = value;
  25381. if (this.source.detune === undefined) return; // only set detune when available
  25382. if (this.isPlaying === true) {
  25383. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25384. }
  25385. return this;
  25386. };
  25387. _proto.getDetune = function getDetune() {
  25388. return this.detune;
  25389. };
  25390. _proto.getFilter = function getFilter() {
  25391. return this.getFilters()[0];
  25392. };
  25393. _proto.setFilter = function setFilter(filter) {
  25394. return this.setFilters(filter ? [filter] : []);
  25395. };
  25396. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25397. if (this.hasPlaybackControl === false) {
  25398. console.warn('THREE.Audio: this Audio has no playback control.');
  25399. return;
  25400. }
  25401. this.playbackRate = value;
  25402. if (this.isPlaying === true) {
  25403. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25404. }
  25405. return this;
  25406. };
  25407. _proto.getPlaybackRate = function getPlaybackRate() {
  25408. return this.playbackRate;
  25409. };
  25410. _proto.onEnded = function onEnded() {
  25411. this.isPlaying = false;
  25412. };
  25413. _proto.getLoop = function getLoop() {
  25414. if (this.hasPlaybackControl === false) {
  25415. console.warn('THREE.Audio: this Audio has no playback control.');
  25416. return false;
  25417. }
  25418. return this.loop;
  25419. };
  25420. _proto.setLoop = function setLoop(value) {
  25421. if (this.hasPlaybackControl === false) {
  25422. console.warn('THREE.Audio: this Audio has no playback control.');
  25423. return;
  25424. }
  25425. this.loop = value;
  25426. if (this.isPlaying === true) {
  25427. this.source.loop = this.loop;
  25428. }
  25429. return this;
  25430. };
  25431. _proto.setLoopStart = function setLoopStart(value) {
  25432. this.loopStart = value;
  25433. return this;
  25434. };
  25435. _proto.setLoopEnd = function setLoopEnd(value) {
  25436. this.loopEnd = value;
  25437. return this;
  25438. };
  25439. _proto.getVolume = function getVolume() {
  25440. return this.gain.gain.value;
  25441. };
  25442. _proto.setVolume = function setVolume(value) {
  25443. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25444. return this;
  25445. };
  25446. return Audio;
  25447. }(Object3D);
  25448. var _position$3 = /*@__PURE__*/new Vector3();
  25449. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25450. var _scale$2 = /*@__PURE__*/new Vector3();
  25451. var _orientation$1 = /*@__PURE__*/new Vector3();
  25452. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25453. _inheritsLoose(PositionalAudio, _Audio);
  25454. function PositionalAudio(listener) {
  25455. var _this;
  25456. _this = _Audio.call(this, listener) || this;
  25457. _this.panner = _this.context.createPanner();
  25458. _this.panner.panningModel = 'HRTF';
  25459. _this.panner.connect(_this.gain);
  25460. return _this;
  25461. }
  25462. var _proto = PositionalAudio.prototype;
  25463. _proto.getOutput = function getOutput() {
  25464. return this.panner;
  25465. };
  25466. _proto.getRefDistance = function getRefDistance() {
  25467. return this.panner.refDistance;
  25468. };
  25469. _proto.setRefDistance = function setRefDistance(value) {
  25470. this.panner.refDistance = value;
  25471. return this;
  25472. };
  25473. _proto.getRolloffFactor = function getRolloffFactor() {
  25474. return this.panner.rolloffFactor;
  25475. };
  25476. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25477. this.panner.rolloffFactor = value;
  25478. return this;
  25479. };
  25480. _proto.getDistanceModel = function getDistanceModel() {
  25481. return this.panner.distanceModel;
  25482. };
  25483. _proto.setDistanceModel = function setDistanceModel(value) {
  25484. this.panner.distanceModel = value;
  25485. return this;
  25486. };
  25487. _proto.getMaxDistance = function getMaxDistance() {
  25488. return this.panner.maxDistance;
  25489. };
  25490. _proto.setMaxDistance = function setMaxDistance(value) {
  25491. this.panner.maxDistance = value;
  25492. return this;
  25493. };
  25494. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25495. this.panner.coneInnerAngle = coneInnerAngle;
  25496. this.panner.coneOuterAngle = coneOuterAngle;
  25497. this.panner.coneOuterGain = coneOuterGain;
  25498. return this;
  25499. };
  25500. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25501. _Audio.prototype.updateMatrixWorld.call(this, force);
  25502. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25503. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25504. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25505. var panner = this.panner;
  25506. if (panner.positionX) {
  25507. // code path for Chrome and Firefox (see #14393)
  25508. var endTime = this.context.currentTime + this.listener.timeDelta;
  25509. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25510. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25511. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25512. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25513. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25514. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25515. } else {
  25516. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25517. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25518. }
  25519. };
  25520. return PositionalAudio;
  25521. }(Audio);
  25522. var AudioAnalyser = /*#__PURE__*/function () {
  25523. function AudioAnalyser(audio, fftSize) {
  25524. this.analyser = audio.context.createAnalyser();
  25525. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25526. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25527. audio.getOutput().connect(this.analyser);
  25528. }
  25529. var _proto = AudioAnalyser.prototype;
  25530. _proto.getFrequencyData = function getFrequencyData() {
  25531. this.analyser.getByteFrequencyData(this.data);
  25532. return this.data;
  25533. };
  25534. _proto.getAverageFrequency = function getAverageFrequency() {
  25535. var value = 0;
  25536. var data = this.getFrequencyData();
  25537. for (var i = 0; i < data.length; i++) {
  25538. value += data[i];
  25539. }
  25540. return value / data.length;
  25541. };
  25542. return AudioAnalyser;
  25543. }();
  25544. function PropertyMixer(binding, typeName, valueSize) {
  25545. this.binding = binding;
  25546. this.valueSize = valueSize;
  25547. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25548. //
  25549. // interpolators can use .buffer as their .result
  25550. // the data then goes to 'incoming'
  25551. //
  25552. // 'accu0' and 'accu1' are used frame-interleaved for
  25553. // the cumulative result and are compared to detect
  25554. // changes
  25555. //
  25556. // 'orig' stores the original state of the property
  25557. //
  25558. // 'add' is used for additive cumulative results
  25559. //
  25560. // 'work' is optional and is only present for quaternion types. It is used
  25561. // to store intermediate quaternion multiplication results
  25562. switch (typeName) {
  25563. case 'quaternion':
  25564. mixFunction = this._slerp;
  25565. mixFunctionAdditive = this._slerpAdditive;
  25566. setIdentity = this._setAdditiveIdentityQuaternion;
  25567. this.buffer = new Float64Array(valueSize * 6);
  25568. this._workIndex = 5;
  25569. break;
  25570. case 'string':
  25571. case 'bool':
  25572. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25573. // additive is not relevant for non-numeric types
  25574. mixFunctionAdditive = this._select;
  25575. setIdentity = this._setAdditiveIdentityOther;
  25576. this.buffer = new Array(valueSize * 5);
  25577. break;
  25578. default:
  25579. mixFunction = this._lerp;
  25580. mixFunctionAdditive = this._lerpAdditive;
  25581. setIdentity = this._setAdditiveIdentityNumeric;
  25582. this.buffer = new Float64Array(valueSize * 5);
  25583. }
  25584. this._mixBufferRegion = mixFunction;
  25585. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25586. this._setIdentity = setIdentity;
  25587. this._origIndex = 3;
  25588. this._addIndex = 4;
  25589. this.cumulativeWeight = 0;
  25590. this.cumulativeWeightAdditive = 0;
  25591. this.useCount = 0;
  25592. this.referenceCount = 0;
  25593. }
  25594. Object.assign(PropertyMixer.prototype, {
  25595. // accumulate data in the 'incoming' region into 'accu<i>'
  25596. accumulate: function accumulate(accuIndex, weight) {
  25597. // note: happily accumulating nothing when weight = 0, the caller knows
  25598. // the weight and shouldn't have made the call in the first place
  25599. var buffer = this.buffer,
  25600. stride = this.valueSize,
  25601. offset = accuIndex * stride + stride;
  25602. var currentWeight = this.cumulativeWeight;
  25603. if (currentWeight === 0) {
  25604. // accuN := incoming * weight
  25605. for (var i = 0; i !== stride; ++i) {
  25606. buffer[offset + i] = buffer[i];
  25607. }
  25608. currentWeight = weight;
  25609. } else {
  25610. // accuN := accuN + incoming * weight
  25611. currentWeight += weight;
  25612. var mix = weight / currentWeight;
  25613. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25614. }
  25615. this.cumulativeWeight = currentWeight;
  25616. },
  25617. // accumulate data in the 'incoming' region into 'add'
  25618. accumulateAdditive: function accumulateAdditive(weight) {
  25619. var buffer = this.buffer,
  25620. stride = this.valueSize,
  25621. offset = stride * this._addIndex;
  25622. if (this.cumulativeWeightAdditive === 0) {
  25623. // add = identity
  25624. this._setIdentity();
  25625. } // add := add + incoming * weight
  25626. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25627. this.cumulativeWeightAdditive += weight;
  25628. },
  25629. // apply the state of 'accu<i>' to the binding when accus differ
  25630. apply: function apply(accuIndex) {
  25631. var stride = this.valueSize,
  25632. buffer = this.buffer,
  25633. offset = accuIndex * stride + stride,
  25634. weight = this.cumulativeWeight,
  25635. weightAdditive = this.cumulativeWeightAdditive,
  25636. binding = this.binding;
  25637. this.cumulativeWeight = 0;
  25638. this.cumulativeWeightAdditive = 0;
  25639. if (weight < 1) {
  25640. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25641. var originalValueOffset = stride * this._origIndex;
  25642. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25643. }
  25644. if (weightAdditive > 0) {
  25645. // accuN := accuN + additive accuN
  25646. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25647. }
  25648. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25649. if (buffer[i] !== buffer[i + stride]) {
  25650. // value has changed -> update scene graph
  25651. binding.setValue(buffer, offset);
  25652. break;
  25653. }
  25654. }
  25655. },
  25656. // remember the state of the bound property and copy it to both accus
  25657. saveOriginalState: function saveOriginalState() {
  25658. var binding = this.binding;
  25659. var buffer = this.buffer,
  25660. stride = this.valueSize,
  25661. originalValueOffset = stride * this._origIndex;
  25662. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25663. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25664. buffer[i] = buffer[originalValueOffset + i % stride];
  25665. } // Add to identity for additive
  25666. this._setIdentity();
  25667. this.cumulativeWeight = 0;
  25668. this.cumulativeWeightAdditive = 0;
  25669. },
  25670. // apply the state previously taken via 'saveOriginalState' to the binding
  25671. restoreOriginalState: function restoreOriginalState() {
  25672. var originalValueOffset = this.valueSize * 3;
  25673. this.binding.setValue(this.buffer, originalValueOffset);
  25674. },
  25675. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25676. var startIndex = this._addIndex * this.valueSize;
  25677. var endIndex = startIndex + this.valueSize;
  25678. for (var i = startIndex; i < endIndex; i++) {
  25679. this.buffer[i] = 0;
  25680. }
  25681. },
  25682. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25683. this._setAdditiveIdentityNumeric();
  25684. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25685. },
  25686. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25687. var startIndex = this._origIndex * this.valueSize;
  25688. var targetIndex = this._addIndex * this.valueSize;
  25689. for (var i = 0; i < this.valueSize; i++) {
  25690. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25691. }
  25692. },
  25693. // mix functions
  25694. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25695. if (t >= 0.5) {
  25696. for (var i = 0; i !== stride; ++i) {
  25697. buffer[dstOffset + i] = buffer[srcOffset + i];
  25698. }
  25699. }
  25700. },
  25701. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25702. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25703. },
  25704. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25705. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25706. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25707. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25708. },
  25709. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25710. var s = 1 - t;
  25711. for (var i = 0; i !== stride; ++i) {
  25712. var j = dstOffset + i;
  25713. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25714. }
  25715. },
  25716. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25717. for (var i = 0; i !== stride; ++i) {
  25718. var j = dstOffset + i;
  25719. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25720. }
  25721. }
  25722. });
  25723. // Characters [].:/ are reserved for track binding syntax.
  25724. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25725. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25726. // only latin characters, and the unicode \p{L} is not yet supported. So
  25727. // instead, we exclude reserved characters and match everything else.
  25728. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25729. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25730. // be matched to parse the rest of the track name.
  25731. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25732. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25733. // characters. Accessor may contain any character except closing bracket.
  25734. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25735. // contain any non-bracket characters.
  25736. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25737. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25738. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25739. function Composite(targetGroup, path, optionalParsedPath) {
  25740. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25741. this._targetGroup = targetGroup;
  25742. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25743. }
  25744. Object.assign(Composite.prototype, {
  25745. getValue: function getValue(array, offset) {
  25746. this.bind(); // bind all binding
  25747. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25748. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25749. if (binding !== undefined) binding.getValue(array, offset);
  25750. },
  25751. setValue: function setValue(array, offset) {
  25752. var bindings = this._bindings;
  25753. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25754. bindings[i].setValue(array, offset);
  25755. }
  25756. },
  25757. bind: function bind() {
  25758. var bindings = this._bindings;
  25759. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25760. bindings[i].bind();
  25761. }
  25762. },
  25763. unbind: function unbind() {
  25764. var bindings = this._bindings;
  25765. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25766. bindings[i].unbind();
  25767. }
  25768. }
  25769. });
  25770. function PropertyBinding(rootNode, path, parsedPath) {
  25771. this.path = path;
  25772. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25773. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25774. this.rootNode = rootNode;
  25775. }
  25776. Object.assign(PropertyBinding, {
  25777. Composite: Composite,
  25778. create: function create(root, path, parsedPath) {
  25779. if (!(root && root.isAnimationObjectGroup)) {
  25780. return new PropertyBinding(root, path, parsedPath);
  25781. } else {
  25782. return new PropertyBinding.Composite(root, path, parsedPath);
  25783. }
  25784. },
  25785. /**
  25786. * Replaces spaces with underscores and removes unsupported characters from
  25787. * node names, to ensure compatibility with parseTrackName().
  25788. *
  25789. * @param {string} name Node name to be sanitized.
  25790. * @return {string}
  25791. */
  25792. sanitizeNodeName: function sanitizeNodeName(name) {
  25793. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25794. },
  25795. parseTrackName: function parseTrackName(trackName) {
  25796. var matches = _trackRe.exec(trackName);
  25797. if (!matches) {
  25798. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25799. }
  25800. var results = {
  25801. // directoryName: matches[ 1 ], // (tschw) currently unused
  25802. nodeName: matches[2],
  25803. objectName: matches[3],
  25804. objectIndex: matches[4],
  25805. propertyName: matches[5],
  25806. // required
  25807. propertyIndex: matches[6]
  25808. };
  25809. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25810. if (lastDot !== undefined && lastDot !== -1) {
  25811. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25812. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25813. // 'bar' could be the objectName, or part of a nodeName (which can
  25814. // include '.' characters).
  25815. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25816. results.nodeName = results.nodeName.substring(0, lastDot);
  25817. results.objectName = objectName;
  25818. }
  25819. }
  25820. if (results.propertyName === null || results.propertyName.length === 0) {
  25821. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25822. }
  25823. return results;
  25824. },
  25825. findNode: function findNode(root, nodeName) {
  25826. if (!nodeName || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25827. return root;
  25828. } // search into skeleton bones.
  25829. if (root.skeleton) {
  25830. var bone = root.skeleton.getBoneByName(nodeName);
  25831. if (bone !== undefined) {
  25832. return bone;
  25833. }
  25834. } // search into node subtree.
  25835. if (root.children) {
  25836. var searchNodeSubtree = function searchNodeSubtree(children) {
  25837. for (var i = 0; i < children.length; i++) {
  25838. var childNode = children[i];
  25839. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25840. return childNode;
  25841. }
  25842. var result = searchNodeSubtree(childNode.children);
  25843. if (result) return result;
  25844. }
  25845. return null;
  25846. };
  25847. var subTreeNode = searchNodeSubtree(root.children);
  25848. if (subTreeNode) {
  25849. return subTreeNode;
  25850. }
  25851. }
  25852. return null;
  25853. }
  25854. });
  25855. Object.assign(PropertyBinding.prototype, {
  25856. // prototype, continued
  25857. // these are used to "bind" a nonexistent property
  25858. _getValue_unavailable: function _getValue_unavailable() {},
  25859. _setValue_unavailable: function _setValue_unavailable() {},
  25860. BindingType: {
  25861. Direct: 0,
  25862. EntireArray: 1,
  25863. ArrayElement: 2,
  25864. HasFromToArray: 3
  25865. },
  25866. Versioning: {
  25867. None: 0,
  25868. NeedsUpdate: 1,
  25869. MatrixWorldNeedsUpdate: 2
  25870. },
  25871. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25872. buffer[offset] = this.node[this.propertyName];
  25873. }, function getValue_array(buffer, offset) {
  25874. var source = this.resolvedProperty;
  25875. for (var i = 0, n = source.length; i !== n; ++i) {
  25876. buffer[offset++] = source[i];
  25877. }
  25878. }, function getValue_arrayElement(buffer, offset) {
  25879. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25880. }, function getValue_toArray(buffer, offset) {
  25881. this.resolvedProperty.toArray(buffer, offset);
  25882. }],
  25883. SetterByBindingTypeAndVersioning: [[// Direct
  25884. function setValue_direct(buffer, offset) {
  25885. this.targetObject[this.propertyName] = buffer[offset];
  25886. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25887. this.targetObject[this.propertyName] = buffer[offset];
  25888. this.targetObject.needsUpdate = true;
  25889. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25890. this.targetObject[this.propertyName] = buffer[offset];
  25891. this.targetObject.matrixWorldNeedsUpdate = true;
  25892. }], [// EntireArray
  25893. function setValue_array(buffer, offset) {
  25894. var dest = this.resolvedProperty;
  25895. for (var i = 0, n = dest.length; i !== n; ++i) {
  25896. dest[i] = buffer[offset++];
  25897. }
  25898. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25899. var dest = this.resolvedProperty;
  25900. for (var i = 0, n = dest.length; i !== n; ++i) {
  25901. dest[i] = buffer[offset++];
  25902. }
  25903. this.targetObject.needsUpdate = true;
  25904. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25905. var dest = this.resolvedProperty;
  25906. for (var i = 0, n = dest.length; i !== n; ++i) {
  25907. dest[i] = buffer[offset++];
  25908. }
  25909. this.targetObject.matrixWorldNeedsUpdate = true;
  25910. }], [// ArrayElement
  25911. function setValue_arrayElement(buffer, offset) {
  25912. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25913. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25914. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25915. this.targetObject.needsUpdate = true;
  25916. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25917. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25918. this.targetObject.matrixWorldNeedsUpdate = true;
  25919. }], [// HasToFromArray
  25920. function setValue_fromArray(buffer, offset) {
  25921. this.resolvedProperty.fromArray(buffer, offset);
  25922. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25923. this.resolvedProperty.fromArray(buffer, offset);
  25924. this.targetObject.needsUpdate = true;
  25925. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25926. this.resolvedProperty.fromArray(buffer, offset);
  25927. this.targetObject.matrixWorldNeedsUpdate = true;
  25928. }]],
  25929. getValue: function getValue_unbound(targetArray, offset) {
  25930. this.bind();
  25931. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25932. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25933. // prototype version of these methods with one that represents
  25934. // the bound state. When the property is not found, the methods
  25935. // become no-ops.
  25936. },
  25937. setValue: function getValue_unbound(sourceArray, offset) {
  25938. this.bind();
  25939. this.setValue(sourceArray, offset);
  25940. },
  25941. // create getter / setter pair for a property in the scene graph
  25942. bind: function bind() {
  25943. var targetObject = this.node;
  25944. var parsedPath = this.parsedPath;
  25945. var objectName = parsedPath.objectName;
  25946. var propertyName = parsedPath.propertyName;
  25947. var propertyIndex = parsedPath.propertyIndex;
  25948. if (!targetObject) {
  25949. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25950. this.node = targetObject;
  25951. } // set fail state so we can just 'return' on error
  25952. this.getValue = this._getValue_unavailable;
  25953. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25954. if (!targetObject) {
  25955. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25956. return;
  25957. }
  25958. if (objectName) {
  25959. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25960. switch (objectName) {
  25961. case 'materials':
  25962. if (!targetObject.material) {
  25963. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25964. return;
  25965. }
  25966. if (!targetObject.material.materials) {
  25967. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25968. return;
  25969. }
  25970. targetObject = targetObject.material.materials;
  25971. break;
  25972. case 'bones':
  25973. if (!targetObject.skeleton) {
  25974. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25975. return;
  25976. } // potential future optimization: skip this if propertyIndex is already an integer
  25977. // and convert the integer string to a true integer.
  25978. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25979. for (var i = 0; i < targetObject.length; i++) {
  25980. if (targetObject[i].name === objectIndex) {
  25981. objectIndex = i;
  25982. break;
  25983. }
  25984. }
  25985. break;
  25986. default:
  25987. if (targetObject[objectName] === undefined) {
  25988. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25989. return;
  25990. }
  25991. targetObject = targetObject[objectName];
  25992. }
  25993. if (objectIndex !== undefined) {
  25994. if (targetObject[objectIndex] === undefined) {
  25995. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25996. return;
  25997. }
  25998. targetObject = targetObject[objectIndex];
  25999. }
  26000. } // resolve property
  26001. var nodeProperty = targetObject[propertyName];
  26002. if (nodeProperty === undefined) {
  26003. var nodeName = parsedPath.nodeName;
  26004. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26005. return;
  26006. } // determine versioning scheme
  26007. var versioning = this.Versioning.None;
  26008. this.targetObject = targetObject;
  26009. if (targetObject.needsUpdate !== undefined) {
  26010. // material
  26011. versioning = this.Versioning.NeedsUpdate;
  26012. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26013. // node transform
  26014. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26015. } // determine how the property gets bound
  26016. var bindingType = this.BindingType.Direct;
  26017. if (propertyIndex !== undefined) {
  26018. // access a sub element of the property array (only primitives are supported right now)
  26019. if (propertyName === "morphTargetInfluences") {
  26020. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26021. // support resolving morphTarget names into indices.
  26022. if (!targetObject.geometry) {
  26023. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26024. return;
  26025. }
  26026. if (targetObject.geometry.isBufferGeometry) {
  26027. if (!targetObject.geometry.morphAttributes) {
  26028. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26029. return;
  26030. }
  26031. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26032. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26033. }
  26034. } else {
  26035. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26036. return;
  26037. }
  26038. }
  26039. bindingType = this.BindingType.ArrayElement;
  26040. this.resolvedProperty = nodeProperty;
  26041. this.propertyIndex = propertyIndex;
  26042. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26043. // must use copy for Object3D.Euler/Quaternion
  26044. bindingType = this.BindingType.HasFromToArray;
  26045. this.resolvedProperty = nodeProperty;
  26046. } else if (Array.isArray(nodeProperty)) {
  26047. bindingType = this.BindingType.EntireArray;
  26048. this.resolvedProperty = nodeProperty;
  26049. } else {
  26050. this.propertyName = propertyName;
  26051. } // select getter / setter
  26052. this.getValue = this.GetterByBindingType[bindingType];
  26053. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26054. },
  26055. unbind: function unbind() {
  26056. this.node = null; // back to the prototype version of getValue / setValue
  26057. // note: avoiding to mutate the shape of 'this' via 'delete'
  26058. this.getValue = this._getValue_unbound;
  26059. this.setValue = this._setValue_unbound;
  26060. }
  26061. }); // DECLARE ALIAS AFTER assign prototype
  26062. Object.assign(PropertyBinding.prototype, {
  26063. // initial state of these methods that calls 'bind'
  26064. _getValue_unbound: PropertyBinding.prototype.getValue,
  26065. _setValue_unbound: PropertyBinding.prototype.setValue
  26066. });
  26067. /**
  26068. *
  26069. * A group of objects that receives a shared animation state.
  26070. *
  26071. * Usage:
  26072. *
  26073. * - Add objects you would otherwise pass as 'root' to the
  26074. * constructor or the .clipAction method of AnimationMixer.
  26075. *
  26076. * - Instead pass this object as 'root'.
  26077. *
  26078. * - You can also add and remove objects later when the mixer
  26079. * is running.
  26080. *
  26081. * Note:
  26082. *
  26083. * Objects of this class appear as one object to the mixer,
  26084. * so cache control of the individual objects must be done
  26085. * on the group.
  26086. *
  26087. * Limitation:
  26088. *
  26089. * - The animated properties must be compatible among the
  26090. * all objects in the group.
  26091. *
  26092. * - A single property can either be controlled through a
  26093. * target group or directly, but not both.
  26094. */
  26095. function AnimationObjectGroup() {
  26096. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26097. this._objects = Array.prototype.slice.call(arguments);
  26098. this.nCachedObjects_ = 0; // threshold
  26099. // note: read by PropertyBinding.Composite
  26100. var indices = {};
  26101. this._indicesByUUID = indices; // for bookkeeping
  26102. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26103. indices[arguments[i].uuid] = i;
  26104. }
  26105. this._paths = []; // inside: string
  26106. this._parsedPaths = []; // inside: { we don't care, here }
  26107. this._bindings = []; // inside: Array< PropertyBinding >
  26108. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26109. var scope = this;
  26110. this.stats = {
  26111. objects: {
  26112. get total() {
  26113. return scope._objects.length;
  26114. },
  26115. get inUse() {
  26116. return this.total - scope.nCachedObjects_;
  26117. }
  26118. },
  26119. get bindingsPerObject() {
  26120. return scope._bindings.length;
  26121. }
  26122. };
  26123. }
  26124. Object.assign(AnimationObjectGroup.prototype, {
  26125. isAnimationObjectGroup: true,
  26126. add: function add() {
  26127. var objects = this._objects,
  26128. indicesByUUID = this._indicesByUUID,
  26129. paths = this._paths,
  26130. parsedPaths = this._parsedPaths,
  26131. bindings = this._bindings,
  26132. nBindings = bindings.length;
  26133. var knownObject = undefined,
  26134. nObjects = objects.length,
  26135. nCachedObjects = this.nCachedObjects_;
  26136. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26137. var object = arguments[i],
  26138. uuid = object.uuid;
  26139. var index = indicesByUUID[uuid];
  26140. if (index === undefined) {
  26141. // unknown object -> add it to the ACTIVE region
  26142. index = nObjects++;
  26143. indicesByUUID[uuid] = index;
  26144. objects.push(object); // accounting is done, now do the same for all bindings
  26145. for (var j = 0, m = nBindings; j !== m; ++j) {
  26146. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26147. }
  26148. } else if (index < nCachedObjects) {
  26149. knownObject = objects[index]; // move existing object to the ACTIVE region
  26150. var firstActiveIndex = --nCachedObjects,
  26151. lastCachedObject = objects[firstActiveIndex];
  26152. indicesByUUID[lastCachedObject.uuid] = index;
  26153. objects[index] = lastCachedObject;
  26154. indicesByUUID[uuid] = firstActiveIndex;
  26155. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26156. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26157. var bindingsForPath = bindings[_j],
  26158. lastCached = bindingsForPath[firstActiveIndex];
  26159. var binding = bindingsForPath[index];
  26160. bindingsForPath[index] = lastCached;
  26161. if (binding === undefined) {
  26162. // since we do not bother to create new bindings
  26163. // for objects that are cached, the binding may
  26164. // or may not exist
  26165. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26166. }
  26167. bindingsForPath[firstActiveIndex] = binding;
  26168. }
  26169. } else if (objects[index] !== knownObject) {
  26170. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26171. } // else the object is already where we want it to be
  26172. } // for arguments
  26173. this.nCachedObjects_ = nCachedObjects;
  26174. },
  26175. remove: function remove() {
  26176. var objects = this._objects,
  26177. indicesByUUID = this._indicesByUUID,
  26178. bindings = this._bindings,
  26179. nBindings = bindings.length;
  26180. var nCachedObjects = this.nCachedObjects_;
  26181. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26182. var object = arguments[i],
  26183. uuid = object.uuid,
  26184. index = indicesByUUID[uuid];
  26185. if (index !== undefined && index >= nCachedObjects) {
  26186. // move existing object into the CACHED region
  26187. var lastCachedIndex = nCachedObjects++,
  26188. firstActiveObject = objects[lastCachedIndex];
  26189. indicesByUUID[firstActiveObject.uuid] = index;
  26190. objects[index] = firstActiveObject;
  26191. indicesByUUID[uuid] = lastCachedIndex;
  26192. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26193. for (var j = 0, m = nBindings; j !== m; ++j) {
  26194. var bindingsForPath = bindings[j],
  26195. firstActive = bindingsForPath[lastCachedIndex],
  26196. binding = bindingsForPath[index];
  26197. bindingsForPath[index] = firstActive;
  26198. bindingsForPath[lastCachedIndex] = binding;
  26199. }
  26200. }
  26201. } // for arguments
  26202. this.nCachedObjects_ = nCachedObjects;
  26203. },
  26204. // remove & forget
  26205. uncache: function uncache() {
  26206. var objects = this._objects,
  26207. indicesByUUID = this._indicesByUUID,
  26208. bindings = this._bindings,
  26209. nBindings = bindings.length;
  26210. var nCachedObjects = this.nCachedObjects_,
  26211. nObjects = objects.length;
  26212. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26213. var object = arguments[i],
  26214. uuid = object.uuid,
  26215. index = indicesByUUID[uuid];
  26216. if (index !== undefined) {
  26217. delete indicesByUUID[uuid];
  26218. if (index < nCachedObjects) {
  26219. // object is cached, shrink the CACHED region
  26220. var firstActiveIndex = --nCachedObjects,
  26221. lastCachedObject = objects[firstActiveIndex],
  26222. lastIndex = --nObjects,
  26223. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26224. indicesByUUID[lastCachedObject.uuid] = index;
  26225. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26226. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26227. objects[firstActiveIndex] = lastObject;
  26228. objects.pop(); // accounting is done, now do the same for all bindings
  26229. for (var j = 0, m = nBindings; j !== m; ++j) {
  26230. var bindingsForPath = bindings[j],
  26231. lastCached = bindingsForPath[firstActiveIndex],
  26232. last = bindingsForPath[lastIndex];
  26233. bindingsForPath[index] = lastCached;
  26234. bindingsForPath[firstActiveIndex] = last;
  26235. bindingsForPath.pop();
  26236. }
  26237. } else {
  26238. // object is active, just swap with the last and pop
  26239. var _lastIndex = --nObjects,
  26240. _lastObject = objects[_lastIndex];
  26241. if (_lastIndex > 0) {
  26242. indicesByUUID[_lastObject.uuid] = index;
  26243. }
  26244. objects[index] = _lastObject;
  26245. objects.pop(); // accounting is done, now do the same for all bindings
  26246. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26247. var _bindingsForPath = bindings[_j2];
  26248. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26249. _bindingsForPath.pop();
  26250. }
  26251. } // cached or active
  26252. } // if object is known
  26253. } // for arguments
  26254. this.nCachedObjects_ = nCachedObjects;
  26255. },
  26256. // Internal interface used by befriended PropertyBinding.Composite:
  26257. subscribe_: function subscribe_(path, parsedPath) {
  26258. // returns an array of bindings for the given path that is changed
  26259. // according to the contained objects in the group
  26260. var indicesByPath = this._bindingsIndicesByPath;
  26261. var index = indicesByPath[path];
  26262. var bindings = this._bindings;
  26263. if (index !== undefined) return bindings[index];
  26264. var paths = this._paths,
  26265. parsedPaths = this._parsedPaths,
  26266. objects = this._objects,
  26267. nObjects = objects.length,
  26268. nCachedObjects = this.nCachedObjects_,
  26269. bindingsForPath = new Array(nObjects);
  26270. index = bindings.length;
  26271. indicesByPath[path] = index;
  26272. paths.push(path);
  26273. parsedPaths.push(parsedPath);
  26274. bindings.push(bindingsForPath);
  26275. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26276. var object = objects[i];
  26277. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26278. }
  26279. return bindingsForPath;
  26280. },
  26281. unsubscribe_: function unsubscribe_(path) {
  26282. // tells the group to forget about a property path and no longer
  26283. // update the array previously obtained with 'subscribe_'
  26284. var indicesByPath = this._bindingsIndicesByPath,
  26285. index = indicesByPath[path];
  26286. if (index !== undefined) {
  26287. var paths = this._paths,
  26288. parsedPaths = this._parsedPaths,
  26289. bindings = this._bindings,
  26290. lastBindingsIndex = bindings.length - 1,
  26291. lastBindings = bindings[lastBindingsIndex],
  26292. lastBindingsPath = path[lastBindingsIndex];
  26293. indicesByPath[lastBindingsPath] = index;
  26294. bindings[index] = lastBindings;
  26295. bindings.pop();
  26296. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26297. parsedPaths.pop();
  26298. paths[index] = paths[lastBindingsIndex];
  26299. paths.pop();
  26300. }
  26301. }
  26302. });
  26303. var AnimationAction = /*#__PURE__*/function () {
  26304. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26305. this._mixer = mixer;
  26306. this._clip = clip;
  26307. this._localRoot = localRoot || null;
  26308. this.blendMode = blendMode || clip.blendMode;
  26309. var tracks = clip.tracks,
  26310. nTracks = tracks.length,
  26311. interpolants = new Array(nTracks);
  26312. var interpolantSettings = {
  26313. endingStart: ZeroCurvatureEnding,
  26314. endingEnd: ZeroCurvatureEnding
  26315. };
  26316. for (var i = 0; i !== nTracks; ++i) {
  26317. var interpolant = tracks[i].createInterpolant(null);
  26318. interpolants[i] = interpolant;
  26319. interpolant.settings = interpolantSettings;
  26320. }
  26321. this._interpolantSettings = interpolantSettings;
  26322. this._interpolants = interpolants; // bound by the mixer
  26323. // inside: PropertyMixer (managed by the mixer)
  26324. this._propertyBindings = new Array(nTracks);
  26325. this._cacheIndex = null; // for the memory manager
  26326. this._byClipCacheIndex = null; // for the memory manager
  26327. this._timeScaleInterpolant = null;
  26328. this._weightInterpolant = null;
  26329. this.loop = LoopRepeat;
  26330. this._loopCount = -1; // global mixer time when the action is to be started
  26331. // it's set back to 'null' upon start of the action
  26332. this._startTime = null; // scaled local time of the action
  26333. // gets clamped or wrapped to 0..clip.duration according to loop
  26334. this.time = 0;
  26335. this.timeScale = 1;
  26336. this._effectiveTimeScale = 1;
  26337. this.weight = 1;
  26338. this._effectiveWeight = 1;
  26339. this.repetitions = Infinity; // no. of repetitions when looping
  26340. this.paused = false; // true -> zero effective time scale
  26341. this.enabled = true; // false -> zero effective weight
  26342. this.clampWhenFinished = false; // keep feeding the last frame?
  26343. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26344. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26345. } // State & Scheduling
  26346. var _proto = AnimationAction.prototype;
  26347. _proto.play = function play() {
  26348. this._mixer._activateAction(this);
  26349. return this;
  26350. };
  26351. _proto.stop = function stop() {
  26352. this._mixer._deactivateAction(this);
  26353. return this.reset();
  26354. };
  26355. _proto.reset = function reset() {
  26356. this.paused = false;
  26357. this.enabled = true;
  26358. this.time = 0; // restart clip
  26359. this._loopCount = -1; // forget previous loops
  26360. this._startTime = null; // forget scheduling
  26361. return this.stopFading().stopWarping();
  26362. };
  26363. _proto.isRunning = function isRunning() {
  26364. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26365. } // return true when play has been called
  26366. ;
  26367. _proto.isScheduled = function isScheduled() {
  26368. return this._mixer._isActiveAction(this);
  26369. };
  26370. _proto.startAt = function startAt(time) {
  26371. this._startTime = time;
  26372. return this;
  26373. };
  26374. _proto.setLoop = function setLoop(mode, repetitions) {
  26375. this.loop = mode;
  26376. this.repetitions = repetitions;
  26377. return this;
  26378. } // Weight
  26379. // set the weight stopping any scheduled fading
  26380. // although .enabled = false yields an effective weight of zero, this
  26381. // method does *not* change .enabled, because it would be confusing
  26382. ;
  26383. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26384. this.weight = weight; // note: same logic as when updated at runtime
  26385. this._effectiveWeight = this.enabled ? weight : 0;
  26386. return this.stopFading();
  26387. } // return the weight considering fading and .enabled
  26388. ;
  26389. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26390. return this._effectiveWeight;
  26391. };
  26392. _proto.fadeIn = function fadeIn(duration) {
  26393. return this._scheduleFading(duration, 0, 1);
  26394. };
  26395. _proto.fadeOut = function fadeOut(duration) {
  26396. return this._scheduleFading(duration, 1, 0);
  26397. };
  26398. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26399. fadeOutAction.fadeOut(duration);
  26400. this.fadeIn(duration);
  26401. if (warp) {
  26402. var fadeInDuration = this._clip.duration,
  26403. fadeOutDuration = fadeOutAction._clip.duration,
  26404. startEndRatio = fadeOutDuration / fadeInDuration,
  26405. endStartRatio = fadeInDuration / fadeOutDuration;
  26406. fadeOutAction.warp(1.0, startEndRatio, duration);
  26407. this.warp(endStartRatio, 1.0, duration);
  26408. }
  26409. return this;
  26410. };
  26411. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26412. return fadeInAction.crossFadeFrom(this, duration, warp);
  26413. };
  26414. _proto.stopFading = function stopFading() {
  26415. var weightInterpolant = this._weightInterpolant;
  26416. if (weightInterpolant !== null) {
  26417. this._weightInterpolant = null;
  26418. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26419. }
  26420. return this;
  26421. } // Time Scale Control
  26422. // set the time scale stopping any scheduled warping
  26423. // although .paused = true yields an effective time scale of zero, this
  26424. // method does *not* change .paused, because it would be confusing
  26425. ;
  26426. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26427. this.timeScale = timeScale;
  26428. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26429. return this.stopWarping();
  26430. } // return the time scale considering warping and .paused
  26431. ;
  26432. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26433. return this._effectiveTimeScale;
  26434. };
  26435. _proto.setDuration = function setDuration(duration) {
  26436. this.timeScale = this._clip.duration / duration;
  26437. return this.stopWarping();
  26438. };
  26439. _proto.syncWith = function syncWith(action) {
  26440. this.time = action.time;
  26441. this.timeScale = action.timeScale;
  26442. return this.stopWarping();
  26443. };
  26444. _proto.halt = function halt(duration) {
  26445. return this.warp(this._effectiveTimeScale, 0, duration);
  26446. };
  26447. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26448. var mixer = this._mixer,
  26449. now = mixer.time,
  26450. timeScale = this.timeScale;
  26451. var interpolant = this._timeScaleInterpolant;
  26452. if (interpolant === null) {
  26453. interpolant = mixer._lendControlInterpolant();
  26454. this._timeScaleInterpolant = interpolant;
  26455. }
  26456. var times = interpolant.parameterPositions,
  26457. values = interpolant.sampleValues;
  26458. times[0] = now;
  26459. times[1] = now + duration;
  26460. values[0] = startTimeScale / timeScale;
  26461. values[1] = endTimeScale / timeScale;
  26462. return this;
  26463. };
  26464. _proto.stopWarping = function stopWarping() {
  26465. var timeScaleInterpolant = this._timeScaleInterpolant;
  26466. if (timeScaleInterpolant !== null) {
  26467. this._timeScaleInterpolant = null;
  26468. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26469. }
  26470. return this;
  26471. } // Object Accessors
  26472. ;
  26473. _proto.getMixer = function getMixer() {
  26474. return this._mixer;
  26475. };
  26476. _proto.getClip = function getClip() {
  26477. return this._clip;
  26478. };
  26479. _proto.getRoot = function getRoot() {
  26480. return this._localRoot || this._mixer._root;
  26481. } // Interna
  26482. ;
  26483. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26484. // called by the mixer
  26485. if (!this.enabled) {
  26486. // call ._updateWeight() to update ._effectiveWeight
  26487. this._updateWeight(time);
  26488. return;
  26489. }
  26490. var startTime = this._startTime;
  26491. if (startTime !== null) {
  26492. // check for scheduled start of action
  26493. var timeRunning = (time - startTime) * timeDirection;
  26494. if (timeRunning < 0 || timeDirection === 0) {
  26495. return; // yet to come / don't decide when delta = 0
  26496. } // start
  26497. this._startTime = null; // unschedule
  26498. deltaTime = timeDirection * timeRunning;
  26499. } // apply time scale and advance time
  26500. deltaTime *= this._updateTimeScale(time);
  26501. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26502. // an effective weight of 0
  26503. var weight = this._updateWeight(time);
  26504. if (weight > 0) {
  26505. var _interpolants = this._interpolants;
  26506. var propertyMixers = this._propertyBindings;
  26507. switch (this.blendMode) {
  26508. case AdditiveAnimationBlendMode:
  26509. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26510. _interpolants[j].evaluate(clipTime);
  26511. propertyMixers[j].accumulateAdditive(weight);
  26512. }
  26513. break;
  26514. case NormalAnimationBlendMode:
  26515. default:
  26516. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26517. _interpolants[_j].evaluate(clipTime);
  26518. propertyMixers[_j].accumulate(accuIndex, weight);
  26519. }
  26520. }
  26521. }
  26522. };
  26523. _proto._updateWeight = function _updateWeight(time) {
  26524. var weight = 0;
  26525. if (this.enabled) {
  26526. weight = this.weight;
  26527. var interpolant = this._weightInterpolant;
  26528. if (interpolant !== null) {
  26529. var interpolantValue = interpolant.evaluate(time)[0];
  26530. weight *= interpolantValue;
  26531. if (time > interpolant.parameterPositions[1]) {
  26532. this.stopFading();
  26533. if (interpolantValue === 0) {
  26534. // faded out, disable
  26535. this.enabled = false;
  26536. }
  26537. }
  26538. }
  26539. }
  26540. this._effectiveWeight = weight;
  26541. return weight;
  26542. };
  26543. _proto._updateTimeScale = function _updateTimeScale(time) {
  26544. var timeScale = 0;
  26545. if (!this.paused) {
  26546. timeScale = this.timeScale;
  26547. var interpolant = this._timeScaleInterpolant;
  26548. if (interpolant !== null) {
  26549. var interpolantValue = interpolant.evaluate(time)[0];
  26550. timeScale *= interpolantValue;
  26551. if (time > interpolant.parameterPositions[1]) {
  26552. this.stopWarping();
  26553. if (timeScale === 0) {
  26554. // motion has halted, pause
  26555. this.paused = true;
  26556. } else {
  26557. // warp done - apply final time scale
  26558. this.timeScale = timeScale;
  26559. }
  26560. }
  26561. }
  26562. }
  26563. this._effectiveTimeScale = timeScale;
  26564. return timeScale;
  26565. };
  26566. _proto._updateTime = function _updateTime(deltaTime) {
  26567. var duration = this._clip.duration;
  26568. var loop = this.loop;
  26569. var time = this.time + deltaTime;
  26570. var loopCount = this._loopCount;
  26571. var pingPong = loop === LoopPingPong;
  26572. if (deltaTime === 0) {
  26573. if (loopCount === -1) return time;
  26574. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26575. }
  26576. if (loop === LoopOnce) {
  26577. if (loopCount === -1) {
  26578. // just started
  26579. this._loopCount = 0;
  26580. this._setEndings(true, true, false);
  26581. }
  26582. handle_stop: {
  26583. if (time >= duration) {
  26584. time = duration;
  26585. } else if (time < 0) {
  26586. time = 0;
  26587. } else {
  26588. this.time = time;
  26589. break handle_stop;
  26590. }
  26591. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26592. this.time = time;
  26593. this._mixer.dispatchEvent({
  26594. type: 'finished',
  26595. action: this,
  26596. direction: deltaTime < 0 ? -1 : 1
  26597. });
  26598. }
  26599. } else {
  26600. // repetitive Repeat or PingPong
  26601. if (loopCount === -1) {
  26602. // just started
  26603. if (deltaTime >= 0) {
  26604. loopCount = 0;
  26605. this._setEndings(true, this.repetitions === 0, pingPong);
  26606. } else {
  26607. // when looping in reverse direction, the initial
  26608. // transition through zero counts as a repetition,
  26609. // so leave loopCount at -1
  26610. this._setEndings(this.repetitions === 0, true, pingPong);
  26611. }
  26612. }
  26613. if (time >= duration || time < 0) {
  26614. // wrap around
  26615. var loopDelta = Math.floor(time / duration); // signed
  26616. time -= duration * loopDelta;
  26617. loopCount += Math.abs(loopDelta);
  26618. var pending = this.repetitions - loopCount;
  26619. if (pending <= 0) {
  26620. // have to stop (switch state, clamp time, fire event)
  26621. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26622. time = deltaTime > 0 ? duration : 0;
  26623. this.time = time;
  26624. this._mixer.dispatchEvent({
  26625. type: 'finished',
  26626. action: this,
  26627. direction: deltaTime > 0 ? 1 : -1
  26628. });
  26629. } else {
  26630. // keep running
  26631. if (pending === 1) {
  26632. // entering the last round
  26633. var atStart = deltaTime < 0;
  26634. this._setEndings(atStart, !atStart, pingPong);
  26635. } else {
  26636. this._setEndings(false, false, pingPong);
  26637. }
  26638. this._loopCount = loopCount;
  26639. this.time = time;
  26640. this._mixer.dispatchEvent({
  26641. type: 'loop',
  26642. action: this,
  26643. loopDelta: loopDelta
  26644. });
  26645. }
  26646. } else {
  26647. this.time = time;
  26648. }
  26649. if (pingPong && (loopCount & 1) === 1) {
  26650. // invert time for the "pong round"
  26651. return duration - time;
  26652. }
  26653. }
  26654. return time;
  26655. };
  26656. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26657. var settings = this._interpolantSettings;
  26658. if (pingPong) {
  26659. settings.endingStart = ZeroSlopeEnding;
  26660. settings.endingEnd = ZeroSlopeEnding;
  26661. } else {
  26662. // assuming for LoopOnce atStart == atEnd == true
  26663. if (atStart) {
  26664. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26665. } else {
  26666. settings.endingStart = WrapAroundEnding;
  26667. }
  26668. if (atEnd) {
  26669. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26670. } else {
  26671. settings.endingEnd = WrapAroundEnding;
  26672. }
  26673. }
  26674. };
  26675. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26676. var mixer = this._mixer,
  26677. now = mixer.time;
  26678. var interpolant = this._weightInterpolant;
  26679. if (interpolant === null) {
  26680. interpolant = mixer._lendControlInterpolant();
  26681. this._weightInterpolant = interpolant;
  26682. }
  26683. var times = interpolant.parameterPositions,
  26684. values = interpolant.sampleValues;
  26685. times[0] = now;
  26686. values[0] = weightNow;
  26687. times[1] = now + duration;
  26688. values[1] = weightThen;
  26689. return this;
  26690. };
  26691. return AnimationAction;
  26692. }();
  26693. function AnimationMixer(root) {
  26694. this._root = root;
  26695. this._initMemoryManager();
  26696. this._accuIndex = 0;
  26697. this.time = 0;
  26698. this.timeScale = 1.0;
  26699. }
  26700. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26701. constructor: AnimationMixer,
  26702. _bindAction: function _bindAction(action, prototypeAction) {
  26703. var root = action._localRoot || this._root,
  26704. tracks = action._clip.tracks,
  26705. nTracks = tracks.length,
  26706. bindings = action._propertyBindings,
  26707. interpolants = action._interpolants,
  26708. rootUuid = root.uuid,
  26709. bindingsByRoot = this._bindingsByRootAndName;
  26710. var bindingsByName = bindingsByRoot[rootUuid];
  26711. if (bindingsByName === undefined) {
  26712. bindingsByName = {};
  26713. bindingsByRoot[rootUuid] = bindingsByName;
  26714. }
  26715. for (var i = 0; i !== nTracks; ++i) {
  26716. var track = tracks[i],
  26717. trackName = track.name;
  26718. var binding = bindingsByName[trackName];
  26719. if (binding !== undefined) {
  26720. bindings[i] = binding;
  26721. } else {
  26722. binding = bindings[i];
  26723. if (binding !== undefined) {
  26724. // existing binding, make sure the cache knows
  26725. if (binding._cacheIndex === null) {
  26726. ++binding.referenceCount;
  26727. this._addInactiveBinding(binding, rootUuid, trackName);
  26728. }
  26729. continue;
  26730. }
  26731. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26732. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26733. ++binding.referenceCount;
  26734. this._addInactiveBinding(binding, rootUuid, trackName);
  26735. bindings[i] = binding;
  26736. }
  26737. interpolants[i].resultBuffer = binding.buffer;
  26738. }
  26739. },
  26740. _activateAction: function _activateAction(action) {
  26741. if (!this._isActiveAction(action)) {
  26742. if (action._cacheIndex === null) {
  26743. // this action has been forgotten by the cache, but the user
  26744. // appears to be still using it -> rebind
  26745. var rootUuid = (action._localRoot || this._root).uuid,
  26746. clipUuid = action._clip.uuid,
  26747. actionsForClip = this._actionsByClip[clipUuid];
  26748. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26749. this._addInactiveAction(action, clipUuid, rootUuid);
  26750. }
  26751. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26752. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26753. var binding = bindings[i];
  26754. if (binding.useCount++ === 0) {
  26755. this._lendBinding(binding);
  26756. binding.saveOriginalState();
  26757. }
  26758. }
  26759. this._lendAction(action);
  26760. }
  26761. },
  26762. _deactivateAction: function _deactivateAction(action) {
  26763. if (this._isActiveAction(action)) {
  26764. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26765. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26766. var binding = bindings[i];
  26767. if (--binding.useCount === 0) {
  26768. binding.restoreOriginalState();
  26769. this._takeBackBinding(binding);
  26770. }
  26771. }
  26772. this._takeBackAction(action);
  26773. }
  26774. },
  26775. // Memory manager
  26776. _initMemoryManager: function _initMemoryManager() {
  26777. this._actions = []; // 'nActiveActions' followed by inactive ones
  26778. this._nActiveActions = 0;
  26779. this._actionsByClip = {}; // inside:
  26780. // {
  26781. // knownActions: Array< AnimationAction > - used as prototypes
  26782. // actionByRoot: AnimationAction - lookup
  26783. // }
  26784. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26785. this._nActiveBindings = 0;
  26786. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26787. this._controlInterpolants = []; // same game as above
  26788. this._nActiveControlInterpolants = 0;
  26789. var scope = this;
  26790. this.stats = {
  26791. actions: {
  26792. get total() {
  26793. return scope._actions.length;
  26794. },
  26795. get inUse() {
  26796. return scope._nActiveActions;
  26797. }
  26798. },
  26799. bindings: {
  26800. get total() {
  26801. return scope._bindings.length;
  26802. },
  26803. get inUse() {
  26804. return scope._nActiveBindings;
  26805. }
  26806. },
  26807. controlInterpolants: {
  26808. get total() {
  26809. return scope._controlInterpolants.length;
  26810. },
  26811. get inUse() {
  26812. return scope._nActiveControlInterpolants;
  26813. }
  26814. }
  26815. };
  26816. },
  26817. // Memory management for AnimationAction objects
  26818. _isActiveAction: function _isActiveAction(action) {
  26819. var index = action._cacheIndex;
  26820. return index !== null && index < this._nActiveActions;
  26821. },
  26822. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26823. var actions = this._actions,
  26824. actionsByClip = this._actionsByClip;
  26825. var actionsForClip = actionsByClip[clipUuid];
  26826. if (actionsForClip === undefined) {
  26827. actionsForClip = {
  26828. knownActions: [action],
  26829. actionByRoot: {}
  26830. };
  26831. action._byClipCacheIndex = 0;
  26832. actionsByClip[clipUuid] = actionsForClip;
  26833. } else {
  26834. var knownActions = actionsForClip.knownActions;
  26835. action._byClipCacheIndex = knownActions.length;
  26836. knownActions.push(action);
  26837. }
  26838. action._cacheIndex = actions.length;
  26839. actions.push(action);
  26840. actionsForClip.actionByRoot[rootUuid] = action;
  26841. },
  26842. _removeInactiveAction: function _removeInactiveAction(action) {
  26843. var actions = this._actions,
  26844. lastInactiveAction = actions[actions.length - 1],
  26845. cacheIndex = action._cacheIndex;
  26846. lastInactiveAction._cacheIndex = cacheIndex;
  26847. actions[cacheIndex] = lastInactiveAction;
  26848. actions.pop();
  26849. action._cacheIndex = null;
  26850. var clipUuid = action._clip.uuid,
  26851. actionsByClip = this._actionsByClip,
  26852. actionsForClip = actionsByClip[clipUuid],
  26853. knownActionsForClip = actionsForClip.knownActions,
  26854. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26855. byClipCacheIndex = action._byClipCacheIndex;
  26856. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26857. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26858. knownActionsForClip.pop();
  26859. action._byClipCacheIndex = null;
  26860. var actionByRoot = actionsForClip.actionByRoot,
  26861. rootUuid = (action._localRoot || this._root).uuid;
  26862. delete actionByRoot[rootUuid];
  26863. if (knownActionsForClip.length === 0) {
  26864. delete actionsByClip[clipUuid];
  26865. }
  26866. this._removeInactiveBindingsForAction(action);
  26867. },
  26868. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26869. var bindings = action._propertyBindings;
  26870. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26871. var binding = bindings[i];
  26872. if (--binding.referenceCount === 0) {
  26873. this._removeInactiveBinding(binding);
  26874. }
  26875. }
  26876. },
  26877. _lendAction: function _lendAction(action) {
  26878. // [ active actions | inactive actions ]
  26879. // [ active actions >| inactive actions ]
  26880. // s a
  26881. // <-swap->
  26882. // a s
  26883. var actions = this._actions,
  26884. prevIndex = action._cacheIndex,
  26885. lastActiveIndex = this._nActiveActions++,
  26886. firstInactiveAction = actions[lastActiveIndex];
  26887. action._cacheIndex = lastActiveIndex;
  26888. actions[lastActiveIndex] = action;
  26889. firstInactiveAction._cacheIndex = prevIndex;
  26890. actions[prevIndex] = firstInactiveAction;
  26891. },
  26892. _takeBackAction: function _takeBackAction(action) {
  26893. // [ active actions | inactive actions ]
  26894. // [ active actions |< inactive actions ]
  26895. // a s
  26896. // <-swap->
  26897. // s a
  26898. var actions = this._actions,
  26899. prevIndex = action._cacheIndex,
  26900. firstInactiveIndex = --this._nActiveActions,
  26901. lastActiveAction = actions[firstInactiveIndex];
  26902. action._cacheIndex = firstInactiveIndex;
  26903. actions[firstInactiveIndex] = action;
  26904. lastActiveAction._cacheIndex = prevIndex;
  26905. actions[prevIndex] = lastActiveAction;
  26906. },
  26907. // Memory management for PropertyMixer objects
  26908. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26909. var bindingsByRoot = this._bindingsByRootAndName,
  26910. bindings = this._bindings;
  26911. var bindingByName = bindingsByRoot[rootUuid];
  26912. if (bindingByName === undefined) {
  26913. bindingByName = {};
  26914. bindingsByRoot[rootUuid] = bindingByName;
  26915. }
  26916. bindingByName[trackName] = binding;
  26917. binding._cacheIndex = bindings.length;
  26918. bindings.push(binding);
  26919. },
  26920. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26921. var bindings = this._bindings,
  26922. propBinding = binding.binding,
  26923. rootUuid = propBinding.rootNode.uuid,
  26924. trackName = propBinding.path,
  26925. bindingsByRoot = this._bindingsByRootAndName,
  26926. bindingByName = bindingsByRoot[rootUuid],
  26927. lastInactiveBinding = bindings[bindings.length - 1],
  26928. cacheIndex = binding._cacheIndex;
  26929. lastInactiveBinding._cacheIndex = cacheIndex;
  26930. bindings[cacheIndex] = lastInactiveBinding;
  26931. bindings.pop();
  26932. delete bindingByName[trackName];
  26933. if (Object.keys(bindingByName).length === 0) {
  26934. delete bindingsByRoot[rootUuid];
  26935. }
  26936. },
  26937. _lendBinding: function _lendBinding(binding) {
  26938. var bindings = this._bindings,
  26939. prevIndex = binding._cacheIndex,
  26940. lastActiveIndex = this._nActiveBindings++,
  26941. firstInactiveBinding = bindings[lastActiveIndex];
  26942. binding._cacheIndex = lastActiveIndex;
  26943. bindings[lastActiveIndex] = binding;
  26944. firstInactiveBinding._cacheIndex = prevIndex;
  26945. bindings[prevIndex] = firstInactiveBinding;
  26946. },
  26947. _takeBackBinding: function _takeBackBinding(binding) {
  26948. var bindings = this._bindings,
  26949. prevIndex = binding._cacheIndex,
  26950. firstInactiveIndex = --this._nActiveBindings,
  26951. lastActiveBinding = bindings[firstInactiveIndex];
  26952. binding._cacheIndex = firstInactiveIndex;
  26953. bindings[firstInactiveIndex] = binding;
  26954. lastActiveBinding._cacheIndex = prevIndex;
  26955. bindings[prevIndex] = lastActiveBinding;
  26956. },
  26957. // Memory management of Interpolants for weight and time scale
  26958. _lendControlInterpolant: function _lendControlInterpolant() {
  26959. var interpolants = this._controlInterpolants,
  26960. lastActiveIndex = this._nActiveControlInterpolants++;
  26961. var interpolant = interpolants[lastActiveIndex];
  26962. if (interpolant === undefined) {
  26963. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26964. interpolant.__cacheIndex = lastActiveIndex;
  26965. interpolants[lastActiveIndex] = interpolant;
  26966. }
  26967. return interpolant;
  26968. },
  26969. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26970. var interpolants = this._controlInterpolants,
  26971. prevIndex = interpolant.__cacheIndex,
  26972. firstInactiveIndex = --this._nActiveControlInterpolants,
  26973. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26974. interpolant.__cacheIndex = firstInactiveIndex;
  26975. interpolants[firstInactiveIndex] = interpolant;
  26976. lastActiveInterpolant.__cacheIndex = prevIndex;
  26977. interpolants[prevIndex] = lastActiveInterpolant;
  26978. },
  26979. _controlInterpolantsResultBuffer: new Float32Array(1),
  26980. // return an action for a clip optionally using a custom root target
  26981. // object (this method allocates a lot of dynamic memory in case a
  26982. // previously unknown clip/root combination is specified)
  26983. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26984. var root = optionalRoot || this._root,
  26985. rootUuid = root.uuid;
  26986. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26987. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26988. var actionsForClip = this._actionsByClip[clipUuid];
  26989. var prototypeAction = null;
  26990. if (blendMode === undefined) {
  26991. if (clipObject !== null) {
  26992. blendMode = clipObject.blendMode;
  26993. } else {
  26994. blendMode = NormalAnimationBlendMode;
  26995. }
  26996. }
  26997. if (actionsForClip !== undefined) {
  26998. var existingAction = actionsForClip.actionByRoot[rootUuid];
  26999. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27000. return existingAction;
  27001. } // we know the clip, so we don't have to parse all
  27002. // the bindings again but can just copy
  27003. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27004. if (clipObject === null) clipObject = prototypeAction._clip;
  27005. } // clip must be known when specified via string
  27006. if (clipObject === null) return null; // allocate all resources required to run it
  27007. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27008. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27009. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27010. return newAction;
  27011. },
  27012. // get an existing action
  27013. existingAction: function existingAction(clip, optionalRoot) {
  27014. var root = optionalRoot || this._root,
  27015. rootUuid = root.uuid,
  27016. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27017. clipUuid = clipObject ? clipObject.uuid : clip,
  27018. actionsForClip = this._actionsByClip[clipUuid];
  27019. if (actionsForClip !== undefined) {
  27020. return actionsForClip.actionByRoot[rootUuid] || null;
  27021. }
  27022. return null;
  27023. },
  27024. // deactivates all previously scheduled actions
  27025. stopAllAction: function stopAllAction() {
  27026. var actions = this._actions,
  27027. nActions = this._nActiveActions;
  27028. for (var i = nActions - 1; i >= 0; --i) {
  27029. actions[i].stop();
  27030. }
  27031. return this;
  27032. },
  27033. // advance the time and update apply the animation
  27034. update: function update(deltaTime) {
  27035. deltaTime *= this.timeScale;
  27036. var actions = this._actions,
  27037. nActions = this._nActiveActions,
  27038. time = this.time += deltaTime,
  27039. timeDirection = Math.sign(deltaTime),
  27040. accuIndex = this._accuIndex ^= 1; // run active actions
  27041. for (var i = 0; i !== nActions; ++i) {
  27042. var action = actions[i];
  27043. action._update(time, deltaTime, timeDirection, accuIndex);
  27044. } // update scene graph
  27045. var bindings = this._bindings,
  27046. nBindings = this._nActiveBindings;
  27047. for (var _i = 0; _i !== nBindings; ++_i) {
  27048. bindings[_i].apply(accuIndex);
  27049. }
  27050. return this;
  27051. },
  27052. // Allows you to seek to a specific time in an animation.
  27053. setTime: function setTime(timeInSeconds) {
  27054. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27055. for (var i = 0; i < this._actions.length; i++) {
  27056. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27057. }
  27058. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27059. },
  27060. // return this mixer's root target object
  27061. getRoot: function getRoot() {
  27062. return this._root;
  27063. },
  27064. // free all resources specific to a particular clip
  27065. uncacheClip: function uncacheClip(clip) {
  27066. var actions = this._actions,
  27067. clipUuid = clip.uuid,
  27068. actionsByClip = this._actionsByClip,
  27069. actionsForClip = actionsByClip[clipUuid];
  27070. if (actionsForClip !== undefined) {
  27071. // note: just calling _removeInactiveAction would mess up the
  27072. // iteration state and also require updating the state we can
  27073. // just throw away
  27074. var actionsToRemove = actionsForClip.knownActions;
  27075. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27076. var action = actionsToRemove[i];
  27077. this._deactivateAction(action);
  27078. var cacheIndex = action._cacheIndex,
  27079. lastInactiveAction = actions[actions.length - 1];
  27080. action._cacheIndex = null;
  27081. action._byClipCacheIndex = null;
  27082. lastInactiveAction._cacheIndex = cacheIndex;
  27083. actions[cacheIndex] = lastInactiveAction;
  27084. actions.pop();
  27085. this._removeInactiveBindingsForAction(action);
  27086. }
  27087. delete actionsByClip[clipUuid];
  27088. }
  27089. },
  27090. // free all resources specific to a particular root target object
  27091. uncacheRoot: function uncacheRoot(root) {
  27092. var rootUuid = root.uuid,
  27093. actionsByClip = this._actionsByClip;
  27094. for (var clipUuid in actionsByClip) {
  27095. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27096. action = actionByRoot[rootUuid];
  27097. if (action !== undefined) {
  27098. this._deactivateAction(action);
  27099. this._removeInactiveAction(action);
  27100. }
  27101. }
  27102. var bindingsByRoot = this._bindingsByRootAndName,
  27103. bindingByName = bindingsByRoot[rootUuid];
  27104. if (bindingByName !== undefined) {
  27105. for (var trackName in bindingByName) {
  27106. var binding = bindingByName[trackName];
  27107. binding.restoreOriginalState();
  27108. this._removeInactiveBinding(binding);
  27109. }
  27110. }
  27111. },
  27112. // remove a targeted clip from the cache
  27113. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27114. var action = this.existingAction(clip, optionalRoot);
  27115. if (action !== null) {
  27116. this._deactivateAction(action);
  27117. this._removeInactiveAction(action);
  27118. }
  27119. }
  27120. });
  27121. var Uniform = /*#__PURE__*/function () {
  27122. function Uniform(value) {
  27123. if (typeof value === 'string') {
  27124. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27125. value = arguments[1];
  27126. }
  27127. this.value = value;
  27128. }
  27129. var _proto = Uniform.prototype;
  27130. _proto.clone = function clone() {
  27131. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27132. };
  27133. return Uniform;
  27134. }();
  27135. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27136. InterleavedBuffer.call(this, array, stride);
  27137. this.meshPerAttribute = meshPerAttribute || 1;
  27138. }
  27139. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27140. constructor: InstancedInterleavedBuffer,
  27141. isInstancedInterleavedBuffer: true,
  27142. copy: function copy(source) {
  27143. InterleavedBuffer.prototype.copy.call(this, source);
  27144. this.meshPerAttribute = source.meshPerAttribute;
  27145. return this;
  27146. },
  27147. clone: function clone(data) {
  27148. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27149. ib.meshPerAttribute = this.meshPerAttribute;
  27150. return ib;
  27151. },
  27152. toJSON: function toJSON(data) {
  27153. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27154. json.isInstancedInterleavedBuffer = true;
  27155. json.meshPerAttribute = this.meshPerAttribute;
  27156. return json;
  27157. }
  27158. });
  27159. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27160. this.buffer = buffer;
  27161. this.type = type;
  27162. this.itemSize = itemSize;
  27163. this.elementSize = elementSize;
  27164. this.count = count;
  27165. this.version = 0;
  27166. }
  27167. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27168. set: function set(value) {
  27169. if (value === true) this.version++;
  27170. }
  27171. });
  27172. Object.assign(GLBufferAttribute.prototype, {
  27173. isGLBufferAttribute: true,
  27174. setBuffer: function setBuffer(buffer) {
  27175. this.buffer = buffer;
  27176. return this;
  27177. },
  27178. setType: function setType(type, elementSize) {
  27179. this.type = type;
  27180. this.elementSize = elementSize;
  27181. return this;
  27182. },
  27183. setItemSize: function setItemSize(itemSize) {
  27184. this.itemSize = itemSize;
  27185. return this;
  27186. },
  27187. setCount: function setCount(count) {
  27188. this.count = count;
  27189. return this;
  27190. }
  27191. });
  27192. function Raycaster(origin, direction, near, far) {
  27193. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27194. this.near = near || 0;
  27195. this.far = far || Infinity;
  27196. this.camera = null;
  27197. this.layers = new Layers();
  27198. this.params = {
  27199. Mesh: {},
  27200. Line: {
  27201. threshold: 1
  27202. },
  27203. LOD: {},
  27204. Points: {
  27205. threshold: 1
  27206. },
  27207. Sprite: {}
  27208. };
  27209. Object.defineProperties(this.params, {
  27210. PointCloud: {
  27211. get: function get() {
  27212. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27213. return this.Points;
  27214. }
  27215. }
  27216. });
  27217. }
  27218. function ascSort(a, b) {
  27219. return a.distance - b.distance;
  27220. }
  27221. function _intersectObject(object, raycaster, intersects, recursive) {
  27222. if (object.layers.test(raycaster.layers)) {
  27223. object.raycast(raycaster, intersects);
  27224. }
  27225. if (recursive === true) {
  27226. var children = object.children;
  27227. for (var i = 0, l = children.length; i < l; i++) {
  27228. _intersectObject(children[i], raycaster, intersects, true);
  27229. }
  27230. }
  27231. }
  27232. Object.assign(Raycaster.prototype, {
  27233. set: function set(origin, direction) {
  27234. // direction is assumed to be normalized (for accurate distance calculations)
  27235. this.ray.set(origin, direction);
  27236. },
  27237. setFromCamera: function setFromCamera(coords, camera) {
  27238. if (camera && camera.isPerspectiveCamera) {
  27239. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27240. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27241. this.camera = camera;
  27242. } else if (camera && camera.isOrthographicCamera) {
  27243. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27244. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27245. this.camera = camera;
  27246. } else {
  27247. console.error('THREE.Raycaster: Unsupported camera type.');
  27248. }
  27249. },
  27250. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27251. var intersects = optionalTarget || [];
  27252. _intersectObject(object, this, intersects, recursive);
  27253. intersects.sort(ascSort);
  27254. return intersects;
  27255. },
  27256. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27257. var intersects = optionalTarget || [];
  27258. if (Array.isArray(objects) === false) {
  27259. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27260. return intersects;
  27261. }
  27262. for (var i = 0, l = objects.length; i < l; i++) {
  27263. _intersectObject(objects[i], this, intersects, recursive);
  27264. }
  27265. intersects.sort(ascSort);
  27266. return intersects;
  27267. }
  27268. });
  27269. /**
  27270. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27271. *
  27272. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27273. * The azimuthal angle (theta) is measured from the positive z-axis.
  27274. */
  27275. var Spherical = /*#__PURE__*/function () {
  27276. function Spherical(radius, phi, theta) {
  27277. if (radius === void 0) {
  27278. radius = 1;
  27279. }
  27280. if (phi === void 0) {
  27281. phi = 0;
  27282. }
  27283. if (theta === void 0) {
  27284. theta = 0;
  27285. }
  27286. this.radius = radius;
  27287. this.phi = phi; // polar angle
  27288. this.theta = theta; // azimuthal angle
  27289. return this;
  27290. }
  27291. var _proto = Spherical.prototype;
  27292. _proto.set = function set(radius, phi, theta) {
  27293. this.radius = radius;
  27294. this.phi = phi;
  27295. this.theta = theta;
  27296. return this;
  27297. };
  27298. _proto.clone = function clone() {
  27299. return new this.constructor().copy(this);
  27300. };
  27301. _proto.copy = function copy(other) {
  27302. this.radius = other.radius;
  27303. this.phi = other.phi;
  27304. this.theta = other.theta;
  27305. return this;
  27306. } // restrict phi to be betwee EPS and PI-EPS
  27307. ;
  27308. _proto.makeSafe = function makeSafe() {
  27309. var EPS = 0.000001;
  27310. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27311. return this;
  27312. };
  27313. _proto.setFromVector3 = function setFromVector3(v) {
  27314. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27315. };
  27316. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27317. this.radius = Math.sqrt(x * x + y * y + z * z);
  27318. if (this.radius === 0) {
  27319. this.theta = 0;
  27320. this.phi = 0;
  27321. } else {
  27322. this.theta = Math.atan2(x, z);
  27323. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27324. }
  27325. return this;
  27326. };
  27327. return Spherical;
  27328. }();
  27329. /**
  27330. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27331. */
  27332. var Cylindrical = /*#__PURE__*/function () {
  27333. function Cylindrical(radius, theta, y) {
  27334. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27335. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27336. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27337. return this;
  27338. }
  27339. var _proto = Cylindrical.prototype;
  27340. _proto.set = function set(radius, theta, y) {
  27341. this.radius = radius;
  27342. this.theta = theta;
  27343. this.y = y;
  27344. return this;
  27345. };
  27346. _proto.clone = function clone() {
  27347. return new this.constructor().copy(this);
  27348. };
  27349. _proto.copy = function copy(other) {
  27350. this.radius = other.radius;
  27351. this.theta = other.theta;
  27352. this.y = other.y;
  27353. return this;
  27354. };
  27355. _proto.setFromVector3 = function setFromVector3(v) {
  27356. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27357. };
  27358. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27359. this.radius = Math.sqrt(x * x + z * z);
  27360. this.theta = Math.atan2(x, z);
  27361. this.y = y;
  27362. return this;
  27363. };
  27364. return Cylindrical;
  27365. }();
  27366. var _vector$7 = /*@__PURE__*/new Vector2();
  27367. var Box2 = /*#__PURE__*/function () {
  27368. function Box2(min, max) {
  27369. Object.defineProperty(this, 'isBox2', {
  27370. value: true
  27371. });
  27372. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27373. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27374. }
  27375. var _proto = Box2.prototype;
  27376. _proto.set = function set(min, max) {
  27377. this.min.copy(min);
  27378. this.max.copy(max);
  27379. return this;
  27380. };
  27381. _proto.setFromPoints = function setFromPoints(points) {
  27382. this.makeEmpty();
  27383. for (var i = 0, il = points.length; i < il; i++) {
  27384. this.expandByPoint(points[i]);
  27385. }
  27386. return this;
  27387. };
  27388. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27389. var halfSize = _vector$7.copy(size).multiplyScalar(0.5);
  27390. this.min.copy(center).sub(halfSize);
  27391. this.max.copy(center).add(halfSize);
  27392. return this;
  27393. };
  27394. _proto.clone = function clone() {
  27395. return new this.constructor().copy(this);
  27396. };
  27397. _proto.copy = function copy(box) {
  27398. this.min.copy(box.min);
  27399. this.max.copy(box.max);
  27400. return this;
  27401. };
  27402. _proto.makeEmpty = function makeEmpty() {
  27403. this.min.x = this.min.y = +Infinity;
  27404. this.max.x = this.max.y = -Infinity;
  27405. return this;
  27406. };
  27407. _proto.isEmpty = function isEmpty() {
  27408. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27409. return this.max.x < this.min.x || this.max.y < this.min.y;
  27410. };
  27411. _proto.getCenter = function getCenter(target) {
  27412. if (target === undefined) {
  27413. console.warn('THREE.Box2: .getCenter() target is now required');
  27414. target = new Vector2();
  27415. }
  27416. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27417. };
  27418. _proto.getSize = function getSize(target) {
  27419. if (target === undefined) {
  27420. console.warn('THREE.Box2: .getSize() target is now required');
  27421. target = new Vector2();
  27422. }
  27423. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27424. };
  27425. _proto.expandByPoint = function expandByPoint(point) {
  27426. this.min.min(point);
  27427. this.max.max(point);
  27428. return this;
  27429. };
  27430. _proto.expandByVector = function expandByVector(vector) {
  27431. this.min.sub(vector);
  27432. this.max.add(vector);
  27433. return this;
  27434. };
  27435. _proto.expandByScalar = function expandByScalar(scalar) {
  27436. this.min.addScalar(-scalar);
  27437. this.max.addScalar(scalar);
  27438. return this;
  27439. };
  27440. _proto.containsPoint = function containsPoint(point) {
  27441. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27442. };
  27443. _proto.containsBox = function containsBox(box) {
  27444. 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;
  27445. };
  27446. _proto.getParameter = function getParameter(point, target) {
  27447. // This can potentially have a divide by zero if the box
  27448. // has a size dimension of 0.
  27449. if (target === undefined) {
  27450. console.warn('THREE.Box2: .getParameter() target is now required');
  27451. target = new Vector2();
  27452. }
  27453. 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));
  27454. };
  27455. _proto.intersectsBox = function intersectsBox(box) {
  27456. // using 4 splitting planes to rule out intersections
  27457. 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;
  27458. };
  27459. _proto.clampPoint = function clampPoint(point, target) {
  27460. if (target === undefined) {
  27461. console.warn('THREE.Box2: .clampPoint() target is now required');
  27462. target = new Vector2();
  27463. }
  27464. return target.copy(point).clamp(this.min, this.max);
  27465. };
  27466. _proto.distanceToPoint = function distanceToPoint(point) {
  27467. var clampedPoint = _vector$7.copy(point).clamp(this.min, this.max);
  27468. return clampedPoint.sub(point).length();
  27469. };
  27470. _proto.intersect = function intersect(box) {
  27471. this.min.max(box.min);
  27472. this.max.min(box.max);
  27473. return this;
  27474. };
  27475. _proto.union = function union(box) {
  27476. this.min.min(box.min);
  27477. this.max.max(box.max);
  27478. return this;
  27479. };
  27480. _proto.translate = function translate(offset) {
  27481. this.min.add(offset);
  27482. this.max.add(offset);
  27483. return this;
  27484. };
  27485. _proto.equals = function equals(box) {
  27486. return box.min.equals(this.min) && box.max.equals(this.max);
  27487. };
  27488. return Box2;
  27489. }();
  27490. var _startP = /*@__PURE__*/new Vector3();
  27491. var _startEnd = /*@__PURE__*/new Vector3();
  27492. var Line3 = /*#__PURE__*/function () {
  27493. function Line3(start, end) {
  27494. this.start = start !== undefined ? start : new Vector3();
  27495. this.end = end !== undefined ? end : new Vector3();
  27496. }
  27497. var _proto = Line3.prototype;
  27498. _proto.set = function set(start, end) {
  27499. this.start.copy(start);
  27500. this.end.copy(end);
  27501. return this;
  27502. };
  27503. _proto.clone = function clone() {
  27504. return new this.constructor().copy(this);
  27505. };
  27506. _proto.copy = function copy(line) {
  27507. this.start.copy(line.start);
  27508. this.end.copy(line.end);
  27509. return this;
  27510. };
  27511. _proto.getCenter = function getCenter(target) {
  27512. if (target === undefined) {
  27513. console.warn('THREE.Line3: .getCenter() target is now required');
  27514. target = new Vector3();
  27515. }
  27516. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27517. };
  27518. _proto.delta = function delta(target) {
  27519. if (target === undefined) {
  27520. console.warn('THREE.Line3: .delta() target is now required');
  27521. target = new Vector3();
  27522. }
  27523. return target.subVectors(this.end, this.start);
  27524. };
  27525. _proto.distanceSq = function distanceSq() {
  27526. return this.start.distanceToSquared(this.end);
  27527. };
  27528. _proto.distance = function distance() {
  27529. return this.start.distanceTo(this.end);
  27530. };
  27531. _proto.at = function at(t, target) {
  27532. if (target === undefined) {
  27533. console.warn('THREE.Line3: .at() target is now required');
  27534. target = new Vector3();
  27535. }
  27536. return this.delta(target).multiplyScalar(t).add(this.start);
  27537. };
  27538. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27539. _startP.subVectors(point, this.start);
  27540. _startEnd.subVectors(this.end, this.start);
  27541. var startEnd2 = _startEnd.dot(_startEnd);
  27542. var startEnd_startP = _startEnd.dot(_startP);
  27543. var t = startEnd_startP / startEnd2;
  27544. if (clampToLine) {
  27545. t = MathUtils.clamp(t, 0, 1);
  27546. }
  27547. return t;
  27548. };
  27549. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27550. var t = this.closestPointToPointParameter(point, clampToLine);
  27551. if (target === undefined) {
  27552. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27553. target = new Vector3();
  27554. }
  27555. return this.delta(target).multiplyScalar(t).add(this.start);
  27556. };
  27557. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27558. this.start.applyMatrix4(matrix);
  27559. this.end.applyMatrix4(matrix);
  27560. return this;
  27561. };
  27562. _proto.equals = function equals(line) {
  27563. return line.start.equals(this.start) && line.end.equals(this.end);
  27564. };
  27565. return Line3;
  27566. }();
  27567. function ImmediateRenderObject(material) {
  27568. Object3D.call(this);
  27569. this.material = material;
  27570. this.render = function ()
  27571. /* renderCallback */
  27572. {};
  27573. this.hasPositions = false;
  27574. this.hasNormals = false;
  27575. this.hasColors = false;
  27576. this.hasUvs = false;
  27577. this.positionArray = null;
  27578. this.normalArray = null;
  27579. this.colorArray = null;
  27580. this.uvArray = null;
  27581. this.count = 0;
  27582. }
  27583. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27584. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27585. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27586. var _vector$8 = /*@__PURE__*/new Vector3();
  27587. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27588. _inheritsLoose(SpotLightHelper, _Object3D);
  27589. function SpotLightHelper(light, color) {
  27590. var _this;
  27591. _this = _Object3D.call(this) || this;
  27592. _this.light = light;
  27593. _this.light.updateMatrixWorld();
  27594. _this.matrix = light.matrixWorld;
  27595. _this.matrixAutoUpdate = false;
  27596. _this.color = color;
  27597. var geometry = new BufferGeometry();
  27598. 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];
  27599. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27600. var p1 = i / l * Math.PI * 2;
  27601. var p2 = j / l * Math.PI * 2;
  27602. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27603. }
  27604. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27605. var material = new LineBasicMaterial({
  27606. fog: false,
  27607. toneMapped: false
  27608. });
  27609. _this.cone = new LineSegments(geometry, material);
  27610. _this.add(_this.cone);
  27611. _this.update();
  27612. return _this;
  27613. }
  27614. var _proto = SpotLightHelper.prototype;
  27615. _proto.dispose = function dispose() {
  27616. this.cone.geometry.dispose();
  27617. this.cone.material.dispose();
  27618. };
  27619. _proto.update = function update() {
  27620. this.light.updateMatrixWorld();
  27621. var coneLength = this.light.distance ? this.light.distance : 1000;
  27622. var coneWidth = coneLength * Math.tan(this.light.angle);
  27623. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27624. _vector$8.setFromMatrixPosition(this.light.target.matrixWorld);
  27625. this.cone.lookAt(_vector$8);
  27626. if (this.color !== undefined) {
  27627. this.cone.material.color.set(this.color);
  27628. } else {
  27629. this.cone.material.color.copy(this.light.color);
  27630. }
  27631. };
  27632. return SpotLightHelper;
  27633. }(Object3D);
  27634. var _vector$9 = /*@__PURE__*/new Vector3();
  27635. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27636. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27637. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27638. _inheritsLoose(SkeletonHelper, _LineSegments);
  27639. function SkeletonHelper(object) {
  27640. var _this;
  27641. var bones = getBoneList(object);
  27642. var geometry = new BufferGeometry();
  27643. var vertices = [];
  27644. var colors = [];
  27645. var color1 = new Color(0, 0, 1);
  27646. var color2 = new Color(0, 1, 0);
  27647. for (var i = 0; i < bones.length; i++) {
  27648. var bone = bones[i];
  27649. if (bone.parent && bone.parent.isBone) {
  27650. vertices.push(0, 0, 0);
  27651. vertices.push(0, 0, 0);
  27652. colors.push(color1.r, color1.g, color1.b);
  27653. colors.push(color2.r, color2.g, color2.b);
  27654. }
  27655. }
  27656. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27657. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27658. var material = new LineBasicMaterial({
  27659. vertexColors: true,
  27660. depthTest: false,
  27661. depthWrite: false,
  27662. toneMapped: false,
  27663. transparent: true
  27664. });
  27665. _this = _LineSegments.call(this, geometry, material) || this;
  27666. _this.type = 'SkeletonHelper';
  27667. _this.isSkeletonHelper = true;
  27668. _this.root = object;
  27669. _this.bones = bones;
  27670. _this.matrix = object.matrixWorld;
  27671. _this.matrixAutoUpdate = false;
  27672. return _this;
  27673. }
  27674. var _proto = SkeletonHelper.prototype;
  27675. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27676. var bones = this.bones;
  27677. var geometry = this.geometry;
  27678. var position = geometry.getAttribute('position');
  27679. _matrixWorldInv.getInverse(this.root.matrixWorld);
  27680. for (var i = 0, j = 0; i < bones.length; i++) {
  27681. var bone = bones[i];
  27682. if (bone.parent && bone.parent.isBone) {
  27683. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27684. _vector$9.setFromMatrixPosition(_boneMatrix);
  27685. position.setXYZ(j, _vector$9.x, _vector$9.y, _vector$9.z);
  27686. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27687. _vector$9.setFromMatrixPosition(_boneMatrix);
  27688. position.setXYZ(j + 1, _vector$9.x, _vector$9.y, _vector$9.z);
  27689. j += 2;
  27690. }
  27691. }
  27692. geometry.getAttribute('position').needsUpdate = true;
  27693. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27694. };
  27695. return SkeletonHelper;
  27696. }(LineSegments);
  27697. function getBoneList(object) {
  27698. var boneList = [];
  27699. if (object && object.isBone) {
  27700. boneList.push(object);
  27701. }
  27702. for (var i = 0; i < object.children.length; i++) {
  27703. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27704. }
  27705. return boneList;
  27706. }
  27707. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27708. _inheritsLoose(PointLightHelper, _Mesh);
  27709. function PointLightHelper(light, sphereSize, color) {
  27710. var _this;
  27711. var geometry = new SphereBufferGeometry(sphereSize, 4, 2);
  27712. var material = new MeshBasicMaterial({
  27713. wireframe: true,
  27714. fog: false,
  27715. toneMapped: false
  27716. });
  27717. _this = _Mesh.call(this, geometry, material) || this;
  27718. _this.light = light;
  27719. _this.light.updateMatrixWorld();
  27720. _this.color = color;
  27721. _this.type = 'PointLightHelper';
  27722. _this.matrix = _this.light.matrixWorld;
  27723. _this.matrixAutoUpdate = false;
  27724. _this.update();
  27725. /*
  27726. // TODO: delete this comment?
  27727. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27728. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27729. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27730. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27731. const d = light.distance;
  27732. if ( d === 0.0 ) {
  27733. this.lightDistance.visible = false;
  27734. } else {
  27735. this.lightDistance.scale.set( d, d, d );
  27736. }
  27737. this.add( this.lightDistance );
  27738. */
  27739. return _this;
  27740. }
  27741. var _proto = PointLightHelper.prototype;
  27742. _proto.dispose = function dispose() {
  27743. this.geometry.dispose();
  27744. this.material.dispose();
  27745. };
  27746. _proto.update = function update() {
  27747. if (this.color !== undefined) {
  27748. this.material.color.set(this.color);
  27749. } else {
  27750. this.material.color.copy(this.light.color);
  27751. }
  27752. /*
  27753. const d = this.light.distance;
  27754. if ( d === 0.0 ) {
  27755. this.lightDistance.visible = false;
  27756. } else {
  27757. this.lightDistance.visible = true;
  27758. this.lightDistance.scale.set( d, d, d );
  27759. }
  27760. */
  27761. };
  27762. return PointLightHelper;
  27763. }(Mesh);
  27764. var _vector$a = /*@__PURE__*/new Vector3();
  27765. var _color1 = /*@__PURE__*/new Color();
  27766. var _color2 = /*@__PURE__*/new Color();
  27767. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27768. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27769. function HemisphereLightHelper(light, size, color) {
  27770. var _this;
  27771. _this = _Object3D.call(this) || this;
  27772. _this.light = light;
  27773. _this.light.updateMatrixWorld();
  27774. _this.matrix = light.matrixWorld;
  27775. _this.matrixAutoUpdate = false;
  27776. _this.color = color;
  27777. var geometry = new OctahedronBufferGeometry(size);
  27778. geometry.rotateY(Math.PI * 0.5);
  27779. _this.material = new MeshBasicMaterial({
  27780. wireframe: true,
  27781. fog: false,
  27782. toneMapped: false
  27783. });
  27784. if (_this.color === undefined) _this.material.vertexColors = true;
  27785. var position = geometry.getAttribute('position');
  27786. var colors = new Float32Array(position.count * 3);
  27787. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27788. _this.add(new Mesh(geometry, _this.material));
  27789. _this.update();
  27790. return _this;
  27791. }
  27792. var _proto = HemisphereLightHelper.prototype;
  27793. _proto.dispose = function dispose() {
  27794. this.children[0].geometry.dispose();
  27795. this.children[0].material.dispose();
  27796. };
  27797. _proto.update = function update() {
  27798. var mesh = this.children[0];
  27799. if (this.color !== undefined) {
  27800. this.material.color.set(this.color);
  27801. } else {
  27802. var colors = mesh.geometry.getAttribute('color');
  27803. _color1.copy(this.light.color);
  27804. _color2.copy(this.light.groundColor);
  27805. for (var i = 0, l = colors.count; i < l; i++) {
  27806. var color = i < l / 2 ? _color1 : _color2;
  27807. colors.setXYZ(i, color.r, color.g, color.b);
  27808. }
  27809. colors.needsUpdate = true;
  27810. }
  27811. mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());
  27812. };
  27813. return HemisphereLightHelper;
  27814. }(Object3D);
  27815. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27816. _inheritsLoose(GridHelper, _LineSegments);
  27817. function GridHelper(size, divisions, color1, color2) {
  27818. var _this;
  27819. size = size || 10;
  27820. divisions = divisions || 10;
  27821. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27822. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27823. var center = divisions / 2;
  27824. var step = size / divisions;
  27825. var halfSize = size / 2;
  27826. var vertices = [],
  27827. colors = [];
  27828. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27829. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27830. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27831. var color = i === center ? color1 : color2;
  27832. color.toArray(colors, j);
  27833. j += 3;
  27834. color.toArray(colors, j);
  27835. j += 3;
  27836. color.toArray(colors, j);
  27837. j += 3;
  27838. color.toArray(colors, j);
  27839. j += 3;
  27840. }
  27841. var geometry = new BufferGeometry();
  27842. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27843. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27844. var material = new LineBasicMaterial({
  27845. vertexColors: true,
  27846. toneMapped: false
  27847. });
  27848. _this = _LineSegments.call(this, geometry, material) || this;
  27849. _this.type = 'GridHelper';
  27850. return _this;
  27851. }
  27852. return GridHelper;
  27853. }(LineSegments);
  27854. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27855. _inheritsLoose(PolarGridHelper, _LineSegments);
  27856. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27857. var _this;
  27858. radius = radius || 10;
  27859. radials = radials || 16;
  27860. circles = circles || 8;
  27861. divisions = divisions || 64;
  27862. color1 = new Color(color1 !== undefined ? color1 : 0x444444);
  27863. color2 = new Color(color2 !== undefined ? color2 : 0x888888);
  27864. var vertices = [];
  27865. var colors = []; // create the radials
  27866. for (var i = 0; i <= radials; i++) {
  27867. var v = i / radials * (Math.PI * 2);
  27868. var x = Math.sin(v) * radius;
  27869. var z = Math.cos(v) * radius;
  27870. vertices.push(0, 0, 0);
  27871. vertices.push(x, 0, z);
  27872. var color = i & 1 ? color1 : color2;
  27873. colors.push(color.r, color.g, color.b);
  27874. colors.push(color.r, color.g, color.b);
  27875. } // create the circles
  27876. for (var _i = 0; _i <= circles; _i++) {
  27877. var _color = _i & 1 ? color1 : color2;
  27878. var r = radius - radius / circles * _i;
  27879. for (var j = 0; j < divisions; j++) {
  27880. // first vertex
  27881. var _v = j / divisions * (Math.PI * 2);
  27882. var _x = Math.sin(_v) * r;
  27883. var _z = Math.cos(_v) * r;
  27884. vertices.push(_x, 0, _z);
  27885. colors.push(_color.r, _color.g, _color.b); // second vertex
  27886. _v = (j + 1) / divisions * (Math.PI * 2);
  27887. _x = Math.sin(_v) * r;
  27888. _z = Math.cos(_v) * r;
  27889. vertices.push(_x, 0, _z);
  27890. colors.push(_color.r, _color.g, _color.b);
  27891. }
  27892. }
  27893. var geometry = new BufferGeometry();
  27894. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27895. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27896. var material = new LineBasicMaterial({
  27897. vertexColors: true,
  27898. toneMapped: false
  27899. });
  27900. _this = _LineSegments.call(this, geometry, material) || this;
  27901. _this.type = 'PolarGridHelper';
  27902. return _this;
  27903. }
  27904. return PolarGridHelper;
  27905. }(LineSegments);
  27906. var _v1$6 = /*@__PURE__*/new Vector3();
  27907. var _v2$3 = /*@__PURE__*/new Vector3();
  27908. var _v3$1 = /*@__PURE__*/new Vector3();
  27909. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27910. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27911. function DirectionalLightHelper(light, size, color) {
  27912. var _this;
  27913. _this = _Object3D.call(this) || this;
  27914. _this.light = light;
  27915. _this.light.updateMatrixWorld();
  27916. _this.matrix = light.matrixWorld;
  27917. _this.matrixAutoUpdate = false;
  27918. _this.color = color;
  27919. if (size === undefined) size = 1;
  27920. var geometry = new BufferGeometry();
  27921. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27922. var material = new LineBasicMaterial({
  27923. fog: false,
  27924. toneMapped: false
  27925. });
  27926. _this.lightPlane = new Line(geometry, material);
  27927. _this.add(_this.lightPlane);
  27928. geometry = new BufferGeometry();
  27929. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27930. _this.targetLine = new Line(geometry, material);
  27931. _this.add(_this.targetLine);
  27932. _this.update();
  27933. return _this;
  27934. }
  27935. var _proto = DirectionalLightHelper.prototype;
  27936. _proto.dispose = function dispose() {
  27937. this.lightPlane.geometry.dispose();
  27938. this.lightPlane.material.dispose();
  27939. this.targetLine.geometry.dispose();
  27940. this.targetLine.material.dispose();
  27941. };
  27942. _proto.update = function update() {
  27943. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27944. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27945. _v3$1.subVectors(_v2$3, _v1$6);
  27946. this.lightPlane.lookAt(_v2$3);
  27947. if (this.color !== undefined) {
  27948. this.lightPlane.material.color.set(this.color);
  27949. this.targetLine.material.color.set(this.color);
  27950. } else {
  27951. this.lightPlane.material.color.copy(this.light.color);
  27952. this.targetLine.material.color.copy(this.light.color);
  27953. }
  27954. this.targetLine.lookAt(_v2$3);
  27955. this.targetLine.scale.z = _v3$1.length();
  27956. };
  27957. return DirectionalLightHelper;
  27958. }(Object3D);
  27959. var _vector$b = /*@__PURE__*/new Vector3();
  27960. var _camera = /*@__PURE__*/new Camera();
  27961. /**
  27962. * - shows frustum, line of sight and up of the camera
  27963. * - suitable for fast updates
  27964. * - based on frustum visualization in lightgl.js shadowmap example
  27965. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27966. */
  27967. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  27968. _inheritsLoose(CameraHelper, _LineSegments);
  27969. function CameraHelper(camera) {
  27970. var _this;
  27971. var geometry = new BufferGeometry();
  27972. var material = new LineBasicMaterial({
  27973. color: 0xffffff,
  27974. vertexColors: true,
  27975. toneMapped: false
  27976. });
  27977. var vertices = [];
  27978. var colors = [];
  27979. var pointMap = {}; // colors
  27980. var colorFrustum = new Color(0xffaa00);
  27981. var colorCone = new Color(0xff0000);
  27982. var colorUp = new Color(0x00aaff);
  27983. var colorTarget = new Color(0xffffff);
  27984. var colorCross = new Color(0x333333); // near
  27985. addLine('n1', 'n2', colorFrustum);
  27986. addLine('n2', 'n4', colorFrustum);
  27987. addLine('n4', 'n3', colorFrustum);
  27988. addLine('n3', 'n1', colorFrustum); // far
  27989. addLine('f1', 'f2', colorFrustum);
  27990. addLine('f2', 'f4', colorFrustum);
  27991. addLine('f4', 'f3', colorFrustum);
  27992. addLine('f3', 'f1', colorFrustum); // sides
  27993. addLine('n1', 'f1', colorFrustum);
  27994. addLine('n2', 'f2', colorFrustum);
  27995. addLine('n3', 'f3', colorFrustum);
  27996. addLine('n4', 'f4', colorFrustum); // cone
  27997. addLine('p', 'n1', colorCone);
  27998. addLine('p', 'n2', colorCone);
  27999. addLine('p', 'n3', colorCone);
  28000. addLine('p', 'n4', colorCone); // up
  28001. addLine('u1', 'u2', colorUp);
  28002. addLine('u2', 'u3', colorUp);
  28003. addLine('u3', 'u1', colorUp); // target
  28004. addLine('c', 't', colorTarget);
  28005. addLine('p', 'c', colorCross); // cross
  28006. addLine('cn1', 'cn2', colorCross);
  28007. addLine('cn3', 'cn4', colorCross);
  28008. addLine('cf1', 'cf2', colorCross);
  28009. addLine('cf3', 'cf4', colorCross);
  28010. function addLine(a, b, color) {
  28011. addPoint(a, color);
  28012. addPoint(b, color);
  28013. }
  28014. function addPoint(id, color) {
  28015. vertices.push(0, 0, 0);
  28016. colors.push(color.r, color.g, color.b);
  28017. if (pointMap[id] === undefined) {
  28018. pointMap[id] = [];
  28019. }
  28020. pointMap[id].push(vertices.length / 3 - 1);
  28021. }
  28022. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28023. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28024. _this = _LineSegments.call(this, geometry, material) || this;
  28025. _this.type = 'CameraHelper';
  28026. _this.camera = camera;
  28027. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28028. _this.matrix = camera.matrixWorld;
  28029. _this.matrixAutoUpdate = false;
  28030. _this.pointMap = pointMap;
  28031. _this.update();
  28032. return _this;
  28033. }
  28034. var _proto = CameraHelper.prototype;
  28035. _proto.update = function update() {
  28036. var geometry = this.geometry;
  28037. var pointMap = this.pointMap;
  28038. var w = 1,
  28039. h = 1; // we need just camera projection matrix inverse
  28040. // world matrix must be identity
  28041. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28042. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28043. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28044. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28045. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28046. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28047. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28048. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28049. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28050. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28051. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28052. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28053. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28054. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28055. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28056. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28057. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28058. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28059. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28060. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28061. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28062. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28063. geometry.getAttribute('position').needsUpdate = true;
  28064. };
  28065. return CameraHelper;
  28066. }(LineSegments);
  28067. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28068. _vector$b.set(x, y, z).unproject(camera);
  28069. var points = pointMap[point];
  28070. if (points !== undefined) {
  28071. var position = geometry.getAttribute('position');
  28072. for (var i = 0, l = points.length; i < l; i++) {
  28073. position.setXYZ(points[i], _vector$b.x, _vector$b.y, _vector$b.z);
  28074. }
  28075. }
  28076. }
  28077. var _box$3 = /*@__PURE__*/new Box3();
  28078. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28079. _inheritsLoose(BoxHelper, _LineSegments);
  28080. function BoxHelper(object, color) {
  28081. var _this;
  28082. if (color === void 0) {
  28083. color = 0xffff00;
  28084. }
  28085. 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]);
  28086. var positions = new Float32Array(8 * 3);
  28087. var geometry = new BufferGeometry();
  28088. geometry.setIndex(new BufferAttribute(indices, 1));
  28089. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28090. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28091. color: color,
  28092. toneMapped: false
  28093. })) || this;
  28094. _this.object = object;
  28095. _this.type = 'BoxHelper';
  28096. _this.matrixAutoUpdate = false;
  28097. _this.update();
  28098. return _this;
  28099. }
  28100. var _proto = BoxHelper.prototype;
  28101. _proto.update = function update(object) {
  28102. if (object !== undefined) {
  28103. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28104. }
  28105. if (this.object !== undefined) {
  28106. _box$3.setFromObject(this.object);
  28107. }
  28108. if (_box$3.isEmpty()) return;
  28109. var min = _box$3.min;
  28110. var max = _box$3.max;
  28111. /*
  28112. 5____4
  28113. 1/___0/|
  28114. | 6__|_7
  28115. 2/___3/
  28116. 0: max.x, max.y, max.z
  28117. 1: min.x, max.y, max.z
  28118. 2: min.x, min.y, max.z
  28119. 3: max.x, min.y, max.z
  28120. 4: max.x, max.y, min.z
  28121. 5: min.x, max.y, min.z
  28122. 6: min.x, min.y, min.z
  28123. 7: max.x, min.y, min.z
  28124. */
  28125. var position = this.geometry.attributes.position;
  28126. var array = position.array;
  28127. array[0] = max.x;
  28128. array[1] = max.y;
  28129. array[2] = max.z;
  28130. array[3] = min.x;
  28131. array[4] = max.y;
  28132. array[5] = max.z;
  28133. array[6] = min.x;
  28134. array[7] = min.y;
  28135. array[8] = max.z;
  28136. array[9] = max.x;
  28137. array[10] = min.y;
  28138. array[11] = max.z;
  28139. array[12] = max.x;
  28140. array[13] = max.y;
  28141. array[14] = min.z;
  28142. array[15] = min.x;
  28143. array[16] = max.y;
  28144. array[17] = min.z;
  28145. array[18] = min.x;
  28146. array[19] = min.y;
  28147. array[20] = min.z;
  28148. array[21] = max.x;
  28149. array[22] = min.y;
  28150. array[23] = min.z;
  28151. position.needsUpdate = true;
  28152. this.geometry.computeBoundingSphere();
  28153. };
  28154. _proto.setFromObject = function setFromObject(object) {
  28155. this.object = object;
  28156. this.update();
  28157. return this;
  28158. };
  28159. _proto.copy = function copy(source) {
  28160. LineSegments.prototype.copy.call(this, source);
  28161. this.object = source.object;
  28162. return this;
  28163. };
  28164. return BoxHelper;
  28165. }(LineSegments);
  28166. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28167. _inheritsLoose(Box3Helper, _LineSegments);
  28168. function Box3Helper(box, color) {
  28169. var _this;
  28170. if (color === void 0) {
  28171. color = 0xffff00;
  28172. }
  28173. 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]);
  28174. 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];
  28175. var geometry = new BufferGeometry();
  28176. geometry.setIndex(new BufferAttribute(indices, 1));
  28177. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28178. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28179. color: color,
  28180. toneMapped: false
  28181. })) || this;
  28182. _this.box = box;
  28183. _this.type = 'Box3Helper';
  28184. _this.geometry.computeBoundingSphere();
  28185. return _this;
  28186. }
  28187. var _proto = Box3Helper.prototype;
  28188. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28189. var box = this.box;
  28190. if (box.isEmpty()) return;
  28191. box.getCenter(this.position);
  28192. box.getSize(this.scale);
  28193. this.scale.multiplyScalar(0.5);
  28194. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28195. };
  28196. return Box3Helper;
  28197. }(LineSegments);
  28198. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28199. _inheritsLoose(PlaneHelper, _Line);
  28200. function PlaneHelper(plane, size, hex) {
  28201. var _this;
  28202. var color = hex !== undefined ? hex : 0xffff00;
  28203. 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];
  28204. var geometry = new BufferGeometry();
  28205. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28206. geometry.computeBoundingSphere();
  28207. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28208. color: color,
  28209. toneMapped: false
  28210. })) || this;
  28211. _this.type = 'PlaneHelper';
  28212. _this.plane = plane;
  28213. _this.size = size === undefined ? 1 : size;
  28214. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28215. var geometry2 = new BufferGeometry();
  28216. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28217. geometry2.computeBoundingSphere();
  28218. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28219. color: color,
  28220. opacity: 0.2,
  28221. transparent: true,
  28222. depthWrite: false,
  28223. toneMapped: false
  28224. })));
  28225. return _this;
  28226. }
  28227. var _proto = PlaneHelper.prototype;
  28228. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28229. var scale = -this.plane.constant;
  28230. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28231. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28232. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28233. this.lookAt(this.plane.normal);
  28234. _Line.prototype.updateMatrixWorld.call(this, force);
  28235. };
  28236. return PlaneHelper;
  28237. }(Line);
  28238. var _axis = /*@__PURE__*/new Vector3();
  28239. var _lineGeometry, _coneGeometry;
  28240. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28241. _inheritsLoose(ArrowHelper, _Object3D);
  28242. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28243. var _this;
  28244. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28245. _this.type = 'ArrowHelper';
  28246. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28247. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28248. if (length === undefined) length = 1;
  28249. if (color === undefined) color = 0xffff00;
  28250. if (headLength === undefined) headLength = 0.2 * length;
  28251. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28252. if (_lineGeometry === undefined) {
  28253. _lineGeometry = new BufferGeometry();
  28254. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28255. _coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 5, 1);
  28256. _coneGeometry.translate(0, -0.5, 0);
  28257. }
  28258. _this.position.copy(origin);
  28259. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28260. color: color,
  28261. toneMapped: false
  28262. }));
  28263. _this.line.matrixAutoUpdate = false;
  28264. _this.add(_this.line);
  28265. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28266. color: color,
  28267. toneMapped: false
  28268. }));
  28269. _this.cone.matrixAutoUpdate = false;
  28270. _this.add(_this.cone);
  28271. _this.setDirection(dir);
  28272. _this.setLength(length, headLength, headWidth);
  28273. return _this;
  28274. }
  28275. var _proto = ArrowHelper.prototype;
  28276. _proto.setDirection = function setDirection(dir) {
  28277. // dir is assumed to be normalized
  28278. if (dir.y > 0.99999) {
  28279. this.quaternion.set(0, 0, 0, 1);
  28280. } else if (dir.y < -0.99999) {
  28281. this.quaternion.set(1, 0, 0, 0);
  28282. } else {
  28283. _axis.set(dir.z, 0, -dir.x).normalize();
  28284. var radians = Math.acos(dir.y);
  28285. this.quaternion.setFromAxisAngle(_axis, radians);
  28286. }
  28287. };
  28288. _proto.setLength = function setLength(length, headLength, headWidth) {
  28289. if (headLength === undefined) headLength = 0.2 * length;
  28290. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28291. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28292. this.line.updateMatrix();
  28293. this.cone.scale.set(headWidth, headLength, headWidth);
  28294. this.cone.position.y = length;
  28295. this.cone.updateMatrix();
  28296. };
  28297. _proto.setColor = function setColor(color) {
  28298. this.line.material.color.set(color);
  28299. this.cone.material.color.set(color);
  28300. };
  28301. _proto.copy = function copy(source) {
  28302. _Object3D.prototype.copy.call(this, source, false);
  28303. this.line.copy(source.line);
  28304. this.cone.copy(source.cone);
  28305. return this;
  28306. };
  28307. return ArrowHelper;
  28308. }(Object3D);
  28309. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28310. _inheritsLoose(AxesHelper, _LineSegments);
  28311. function AxesHelper(size) {
  28312. var _this;
  28313. if (size === void 0) {
  28314. size = 1;
  28315. }
  28316. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28317. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28318. var geometry = new BufferGeometry();
  28319. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28320. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28321. var material = new LineBasicMaterial({
  28322. vertexColors: true,
  28323. toneMapped: false
  28324. });
  28325. _this = _LineSegments.call(this, geometry, material) || this;
  28326. _this.type = 'AxesHelper';
  28327. return _this;
  28328. }
  28329. return AxesHelper;
  28330. }(LineSegments);
  28331. var _ENCODINGS;
  28332. var LOD_MIN = 4;
  28333. var LOD_MAX = 8;
  28334. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28335. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28336. // geometric shadowing function. These sigma values squared must match the
  28337. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28338. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28339. 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
  28340. // samples and exit early, but not recompile the shader.
  28341. var MAX_SAMPLES = 20;
  28342. 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);
  28343. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28344. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28345. _lodPlanes = _createPlanes2._lodPlanes,
  28346. _sizeLods = _createPlanes2._sizeLods,
  28347. _sigmas = _createPlanes2._sigmas;
  28348. var _oldTarget = null; // Golden Ratio
  28349. var PHI = (1 + Math.sqrt(5)) / 2;
  28350. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28351. // same axis), used as axis directions evenly spread on a sphere.
  28352. 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)];
  28353. /**
  28354. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28355. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28356. * blur to be quickly accessed based on material roughness. It is packed into a
  28357. * special CubeUV format that allows us to perform custom interpolation so that
  28358. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28359. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28360. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28361. * higher roughness levels. In this way we maintain resolution to smoothly
  28362. * interpolate diffuse lighting while limiting sampling computation.
  28363. */
  28364. var PMREMGenerator = /*#__PURE__*/function () {
  28365. function PMREMGenerator(renderer) {
  28366. this._renderer = renderer;
  28367. this._pingPongRenderTarget = null;
  28368. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28369. this._equirectShader = null;
  28370. this._cubemapShader = null;
  28371. this._compileMaterial(this._blurMaterial);
  28372. }
  28373. /**
  28374. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28375. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28376. * in radians to be applied to the scene before PMREM generation. Optional near
  28377. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28378. * is placed at the origin).
  28379. */
  28380. var _proto = PMREMGenerator.prototype;
  28381. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28382. if (sigma === void 0) {
  28383. sigma = 0;
  28384. }
  28385. if (near === void 0) {
  28386. near = 0.1;
  28387. }
  28388. if (far === void 0) {
  28389. far = 100;
  28390. }
  28391. _oldTarget = this._renderer.getRenderTarget();
  28392. var cubeUVRenderTarget = this._allocateTargets();
  28393. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28394. if (sigma > 0) {
  28395. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28396. }
  28397. this._applyPMREM(cubeUVRenderTarget);
  28398. this._cleanup(cubeUVRenderTarget);
  28399. return cubeUVRenderTarget;
  28400. }
  28401. /**
  28402. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28403. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28404. * as this matches best with the 256 x 256 cubemap output.
  28405. */
  28406. ;
  28407. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28408. return this._fromTexture(equirectangular);
  28409. }
  28410. /**
  28411. * Generates a PMREM from an cubemap texture, which can be either LDR
  28412. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28413. * as this matches best with the 256 x 256 cubemap output.
  28414. */
  28415. ;
  28416. _proto.fromCubemap = function fromCubemap(cubemap) {
  28417. return this._fromTexture(cubemap);
  28418. }
  28419. /**
  28420. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28421. * your texture's network fetch for increased concurrency.
  28422. */
  28423. ;
  28424. _proto.compileCubemapShader = function compileCubemapShader() {
  28425. if (this._cubemapShader === null) {
  28426. this._cubemapShader = _getCubemapShader();
  28427. this._compileMaterial(this._cubemapShader);
  28428. }
  28429. }
  28430. /**
  28431. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28432. * your texture's network fetch for increased concurrency.
  28433. */
  28434. ;
  28435. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28436. if (this._equirectShader === null) {
  28437. this._equirectShader = _getEquirectShader();
  28438. this._compileMaterial(this._equirectShader);
  28439. }
  28440. }
  28441. /**
  28442. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28443. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28444. * one of them will cause any others to also become unusable.
  28445. */
  28446. ;
  28447. _proto.dispose = function dispose() {
  28448. this._blurMaterial.dispose();
  28449. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28450. if (this._equirectShader !== null) this._equirectShader.dispose();
  28451. for (var i = 0; i < _lodPlanes.length; i++) {
  28452. _lodPlanes[i].dispose();
  28453. }
  28454. } // private interface
  28455. ;
  28456. _proto._cleanup = function _cleanup(outputTarget) {
  28457. this._pingPongRenderTarget.dispose();
  28458. this._renderer.setRenderTarget(_oldTarget);
  28459. outputTarget.scissorTest = false;
  28460. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28461. };
  28462. _proto._fromTexture = function _fromTexture(texture) {
  28463. _oldTarget = this._renderer.getRenderTarget();
  28464. var cubeUVRenderTarget = this._allocateTargets(texture);
  28465. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28466. this._applyPMREM(cubeUVRenderTarget);
  28467. this._cleanup(cubeUVRenderTarget);
  28468. return cubeUVRenderTarget;
  28469. };
  28470. _proto._allocateTargets = function _allocateTargets(texture) {
  28471. // warning: null texture is valid
  28472. var params = {
  28473. magFilter: NearestFilter,
  28474. minFilter: NearestFilter,
  28475. generateMipmaps: false,
  28476. type: UnsignedByteType,
  28477. format: RGBEFormat,
  28478. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28479. depthBuffer: false
  28480. };
  28481. var cubeUVRenderTarget = _createRenderTarget(params);
  28482. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28483. this._pingPongRenderTarget = _createRenderTarget(params);
  28484. return cubeUVRenderTarget;
  28485. };
  28486. _proto._compileMaterial = function _compileMaterial(material) {
  28487. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28488. this._renderer.compile(tmpMesh, _flatCamera);
  28489. };
  28490. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28491. var fov = 90;
  28492. var aspect = 1;
  28493. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28494. var upSign = [1, -1, 1, 1, 1, 1];
  28495. var forwardSign = [1, 1, 1, -1, -1, -1];
  28496. var renderer = this._renderer;
  28497. var outputEncoding = renderer.outputEncoding;
  28498. var toneMapping = renderer.toneMapping;
  28499. var clearColor = renderer.getClearColor();
  28500. var clearAlpha = renderer.getClearAlpha();
  28501. renderer.toneMapping = NoToneMapping;
  28502. renderer.outputEncoding = LinearEncoding;
  28503. var background = scene.background;
  28504. if (background && background.isColor) {
  28505. background.convertSRGBToLinear(); // Convert linear to RGBE
  28506. var maxComponent = Math.max(background.r, background.g, background.b);
  28507. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28508. background = background.multiplyScalar(Math.pow(2.0, -fExp));
  28509. var alpha = (fExp + 128.0) / 255.0;
  28510. renderer.setClearColor(background, alpha);
  28511. scene.background = null;
  28512. }
  28513. for (var i = 0; i < 6; i++) {
  28514. var col = i % 3;
  28515. if (col == 0) {
  28516. cubeCamera.up.set(0, upSign[i], 0);
  28517. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28518. } else if (col == 1) {
  28519. cubeCamera.up.set(0, 0, upSign[i]);
  28520. cubeCamera.lookAt(0, forwardSign[i], 0);
  28521. } else {
  28522. cubeCamera.up.set(0, upSign[i], 0);
  28523. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28524. }
  28525. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28526. renderer.setRenderTarget(cubeUVRenderTarget);
  28527. renderer.render(scene, cubeCamera);
  28528. }
  28529. renderer.toneMapping = toneMapping;
  28530. renderer.outputEncoding = outputEncoding;
  28531. renderer.setClearColor(clearColor, clearAlpha);
  28532. };
  28533. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28534. var renderer = this._renderer;
  28535. if (texture.isCubeTexture) {
  28536. if (this._cubemapShader == null) {
  28537. this._cubemapShader = _getCubemapShader();
  28538. }
  28539. } else {
  28540. if (this._equirectShader == null) {
  28541. this._equirectShader = _getEquirectShader();
  28542. }
  28543. }
  28544. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28545. var mesh = new Mesh(_lodPlanes[0], material);
  28546. var uniforms = material.uniforms;
  28547. uniforms['envMap'].value = texture;
  28548. if (!texture.isCubeTexture) {
  28549. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28550. }
  28551. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28552. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28553. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28554. renderer.setRenderTarget(cubeUVRenderTarget);
  28555. renderer.render(mesh, _flatCamera);
  28556. };
  28557. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28558. var renderer = this._renderer;
  28559. var autoClear = renderer.autoClear;
  28560. renderer.autoClear = false;
  28561. for (var i = 1; i < TOTAL_LODS; i++) {
  28562. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28563. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28564. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28565. }
  28566. renderer.autoClear = autoClear;
  28567. }
  28568. /**
  28569. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28570. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28571. * the blur latitudinally (around the poles), and then longitudinally (towards
  28572. * the poles) to approximate the orthogonally-separable blur. It is least
  28573. * accurate at the poles, but still does a decent job.
  28574. */
  28575. ;
  28576. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28577. var pingPongRenderTarget = this._pingPongRenderTarget;
  28578. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28579. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28580. };
  28581. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28582. var renderer = this._renderer;
  28583. var blurMaterial = this._blurMaterial;
  28584. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28585. console.error('blur direction must be either latitudinal or longitudinal!');
  28586. } // Number of standard deviations at which to cut off the discrete approximation.
  28587. var STANDARD_DEVIATIONS = 3;
  28588. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28589. var blurUniforms = blurMaterial.uniforms;
  28590. var pixels = _sizeLods[lodIn] - 1;
  28591. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28592. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28593. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28594. if (samples > MAX_SAMPLES) {
  28595. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28596. }
  28597. var weights = [];
  28598. var sum = 0;
  28599. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28600. var _x = i / sigmaPixels;
  28601. var weight = Math.exp(-_x * _x / 2);
  28602. weights.push(weight);
  28603. if (i == 0) {
  28604. sum += weight;
  28605. } else if (i < samples) {
  28606. sum += 2 * weight;
  28607. }
  28608. }
  28609. for (var _i = 0; _i < weights.length; _i++) {
  28610. weights[_i] = weights[_i] / sum;
  28611. }
  28612. blurUniforms['envMap'].value = targetIn.texture;
  28613. blurUniforms['samples'].value = samples;
  28614. blurUniforms['weights'].value = weights;
  28615. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28616. if (poleAxis) {
  28617. blurUniforms['poleAxis'].value = poleAxis;
  28618. }
  28619. blurUniforms['dTheta'].value = radiansPerPixel;
  28620. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28621. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28622. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28623. var outputSize = _sizeLods[lodOut];
  28624. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28625. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28626. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28627. renderer.setRenderTarget(targetOut);
  28628. renderer.render(blurMesh, _flatCamera);
  28629. };
  28630. return PMREMGenerator;
  28631. }();
  28632. function _isLDR(texture) {
  28633. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28634. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28635. }
  28636. function _createPlanes() {
  28637. var _lodPlanes = [];
  28638. var _sizeLods = [];
  28639. var _sigmas = [];
  28640. var lod = LOD_MAX;
  28641. for (var i = 0; i < TOTAL_LODS; i++) {
  28642. var sizeLod = Math.pow(2, lod);
  28643. _sizeLods.push(sizeLod);
  28644. var sigma = 1.0 / sizeLod;
  28645. if (i > LOD_MAX - LOD_MIN) {
  28646. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28647. } else if (i == 0) {
  28648. sigma = 0;
  28649. }
  28650. _sigmas.push(sigma);
  28651. var texelSize = 1.0 / (sizeLod - 1);
  28652. var min = -texelSize / 2;
  28653. var max = 1 + texelSize / 2;
  28654. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28655. var cubeFaces = 6;
  28656. var vertices = 6;
  28657. var positionSize = 3;
  28658. var uvSize = 2;
  28659. var faceIndexSize = 1;
  28660. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28661. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28662. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28663. for (var face = 0; face < cubeFaces; face++) {
  28664. var x = face % 3 * 2 / 3 - 1;
  28665. var y = face > 2 ? 0 : -1;
  28666. 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];
  28667. position.set(coordinates, positionSize * vertices * face);
  28668. uv.set(uv1, uvSize * vertices * face);
  28669. var fill = [face, face, face, face, face, face];
  28670. faceIndex.set(fill, faceIndexSize * vertices * face);
  28671. }
  28672. var planes = new BufferGeometry();
  28673. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28674. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28675. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28676. _lodPlanes.push(planes);
  28677. if (lod > LOD_MIN) {
  28678. lod--;
  28679. }
  28680. }
  28681. return {
  28682. _lodPlanes: _lodPlanes,
  28683. _sizeLods: _sizeLods,
  28684. _sigmas: _sigmas
  28685. };
  28686. }
  28687. function _createRenderTarget(params) {
  28688. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28689. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28690. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28691. cubeUVRenderTarget.scissorTest = true;
  28692. return cubeUVRenderTarget;
  28693. }
  28694. function _setViewport(target, x, y, width, height) {
  28695. target.viewport.set(x, y, width, height);
  28696. target.scissor.set(x, y, width, height);
  28697. }
  28698. function _getBlurShader(maxSamples) {
  28699. var weights = new Float32Array(maxSamples);
  28700. var poleAxis = new Vector3(0, 1, 0);
  28701. var shaderMaterial = new RawShaderMaterial({
  28702. name: 'SphericalGaussianBlur',
  28703. defines: {
  28704. 'n': maxSamples
  28705. },
  28706. uniforms: {
  28707. 'envMap': {
  28708. value: null
  28709. },
  28710. 'samples': {
  28711. value: 1
  28712. },
  28713. 'weights': {
  28714. value: weights
  28715. },
  28716. 'latitudinal': {
  28717. value: false
  28718. },
  28719. 'dTheta': {
  28720. value: 0
  28721. },
  28722. 'mipInt': {
  28723. value: 0
  28724. },
  28725. 'poleAxis': {
  28726. value: poleAxis
  28727. },
  28728. 'inputEncoding': {
  28729. value: ENCODINGS[LinearEncoding]
  28730. },
  28731. 'outputEncoding': {
  28732. value: ENCODINGS[LinearEncoding]
  28733. }
  28734. },
  28735. vertexShader: _getCommonVertexShader(),
  28736. fragmentShader:
  28737. /* glsl */
  28738. "\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",
  28739. blending: NoBlending,
  28740. depthTest: false,
  28741. depthWrite: false
  28742. });
  28743. return shaderMaterial;
  28744. }
  28745. function _getEquirectShader() {
  28746. var texelSize = new Vector2(1, 1);
  28747. var shaderMaterial = new RawShaderMaterial({
  28748. name: 'EquirectangularToCubeUV',
  28749. uniforms: {
  28750. 'envMap': {
  28751. value: null
  28752. },
  28753. 'texelSize': {
  28754. value: texelSize
  28755. },
  28756. 'inputEncoding': {
  28757. value: ENCODINGS[LinearEncoding]
  28758. },
  28759. 'outputEncoding': {
  28760. value: ENCODINGS[LinearEncoding]
  28761. }
  28762. },
  28763. vertexShader: _getCommonVertexShader(),
  28764. fragmentShader:
  28765. /* glsl */
  28766. "\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",
  28767. blending: NoBlending,
  28768. depthTest: false,
  28769. depthWrite: false
  28770. });
  28771. return shaderMaterial;
  28772. }
  28773. function _getCubemapShader() {
  28774. var shaderMaterial = new RawShaderMaterial({
  28775. name: 'CubemapToCubeUV',
  28776. uniforms: {
  28777. 'envMap': {
  28778. value: null
  28779. },
  28780. 'inputEncoding': {
  28781. value: ENCODINGS[LinearEncoding]
  28782. },
  28783. 'outputEncoding': {
  28784. value: ENCODINGS[LinearEncoding]
  28785. }
  28786. },
  28787. vertexShader: _getCommonVertexShader(),
  28788. fragmentShader:
  28789. /* glsl */
  28790. "\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",
  28791. blending: NoBlending,
  28792. depthTest: false,
  28793. depthWrite: false
  28794. });
  28795. return shaderMaterial;
  28796. }
  28797. function _getCommonVertexShader() {
  28798. return (
  28799. /* glsl */
  28800. "\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"
  28801. );
  28802. }
  28803. function _getEncodings() {
  28804. return (
  28805. /* glsl */
  28806. "\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"
  28807. );
  28808. }
  28809. function Face4(a, b, c, d, normal, color, materialIndex) {
  28810. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28811. return new Face3(a, b, c, normal, color, materialIndex);
  28812. }
  28813. var LineStrip = 0;
  28814. var LinePieces = 1;
  28815. var NoColors = 0;
  28816. var FaceColors = 1;
  28817. var VertexColors = 2;
  28818. function MeshFaceMaterial(materials) {
  28819. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28820. return materials;
  28821. }
  28822. function MultiMaterial(materials) {
  28823. if (materials === undefined) materials = [];
  28824. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28825. materials.isMultiMaterial = true;
  28826. materials.materials = materials;
  28827. materials.clone = function () {
  28828. return materials.slice();
  28829. };
  28830. return materials;
  28831. }
  28832. function PointCloud(geometry, material) {
  28833. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28834. return new Points(geometry, material);
  28835. }
  28836. function Particle(material) {
  28837. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28838. return new Sprite(material);
  28839. }
  28840. function ParticleSystem(geometry, material) {
  28841. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28842. return new Points(geometry, material);
  28843. }
  28844. function PointCloudMaterial(parameters) {
  28845. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28846. return new PointsMaterial(parameters);
  28847. }
  28848. function ParticleBasicMaterial(parameters) {
  28849. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28850. return new PointsMaterial(parameters);
  28851. }
  28852. function ParticleSystemMaterial(parameters) {
  28853. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28854. return new PointsMaterial(parameters);
  28855. }
  28856. function Vertex(x, y, z) {
  28857. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28858. return new Vector3(x, y, z);
  28859. } //
  28860. function DynamicBufferAttribute(array, itemSize) {
  28861. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28862. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28863. }
  28864. function Int8Attribute(array, itemSize) {
  28865. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28866. return new Int8BufferAttribute(array, itemSize);
  28867. }
  28868. function Uint8Attribute(array, itemSize) {
  28869. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28870. return new Uint8BufferAttribute(array, itemSize);
  28871. }
  28872. function Uint8ClampedAttribute(array, itemSize) {
  28873. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28874. return new Uint8ClampedBufferAttribute(array, itemSize);
  28875. }
  28876. function Int16Attribute(array, itemSize) {
  28877. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28878. return new Int16BufferAttribute(array, itemSize);
  28879. }
  28880. function Uint16Attribute(array, itemSize) {
  28881. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28882. return new Uint16BufferAttribute(array, itemSize);
  28883. }
  28884. function Int32Attribute(array, itemSize) {
  28885. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  28886. return new Int32BufferAttribute(array, itemSize);
  28887. }
  28888. function Uint32Attribute(array, itemSize) {
  28889. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  28890. return new Uint32BufferAttribute(array, itemSize);
  28891. }
  28892. function Float32Attribute(array, itemSize) {
  28893. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  28894. return new Float32BufferAttribute(array, itemSize);
  28895. }
  28896. function Float64Attribute(array, itemSize) {
  28897. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  28898. return new Float64BufferAttribute(array, itemSize);
  28899. } //
  28900. Curve.create = function (construct, getPoint) {
  28901. console.log('THREE.Curve.create() has been deprecated');
  28902. construct.prototype = Object.create(Curve.prototype);
  28903. construct.prototype.constructor = construct;
  28904. construct.prototype.getPoint = getPoint;
  28905. return construct;
  28906. }; //
  28907. Object.assign(CurvePath.prototype, {
  28908. createPointsGeometry: function createPointsGeometry(divisions) {
  28909. 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)
  28910. var pts = this.getPoints(divisions);
  28911. return this.createGeometry(pts);
  28912. },
  28913. createSpacedPointsGeometry: function createSpacedPointsGeometry(divisions) {
  28914. console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.'); // generate geometry from equidistant sampling along the path
  28915. var pts = this.getSpacedPoints(divisions);
  28916. return this.createGeometry(pts);
  28917. },
  28918. createGeometry: function createGeometry(points) {
  28919. console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');
  28920. var geometry = new Geometry();
  28921. for (var i = 0, l = points.length; i < l; i++) {
  28922. var point = points[i];
  28923. geometry.vertices.push(new Vector3(point.x, point.y, point.z || 0));
  28924. }
  28925. return geometry;
  28926. }
  28927. }); //
  28928. Object.assign(Path.prototype, {
  28929. fromPoints: function fromPoints(points) {
  28930. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  28931. return this.setFromPoints(points);
  28932. }
  28933. }); //
  28934. function ClosedSplineCurve3(points) {
  28935. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28936. CatmullRomCurve3.call(this, points);
  28937. this.type = 'catmullrom';
  28938. this.closed = true;
  28939. }
  28940. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28941. function SplineCurve3(points) {
  28942. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  28943. CatmullRomCurve3.call(this, points);
  28944. this.type = 'catmullrom';
  28945. }
  28946. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  28947. function Spline(points) {
  28948. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  28949. CatmullRomCurve3.call(this, points);
  28950. this.type = 'catmullrom';
  28951. }
  28952. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  28953. Object.assign(Spline.prototype, {
  28954. initFromArray: function initFromArray()
  28955. /* a */
  28956. {
  28957. console.error('THREE.Spline: .initFromArray() has been removed.');
  28958. },
  28959. getControlPointsArray: function getControlPointsArray()
  28960. /* optionalTarget */
  28961. {
  28962. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  28963. },
  28964. reparametrizeByArcLength: function reparametrizeByArcLength()
  28965. /* samplingCoef */
  28966. {
  28967. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  28968. }
  28969. }); //
  28970. function AxisHelper(size) {
  28971. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  28972. return new AxesHelper(size);
  28973. }
  28974. function BoundingBoxHelper(object, color) {
  28975. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  28976. return new BoxHelper(object, color);
  28977. }
  28978. function EdgesHelper(object, hex) {
  28979. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  28980. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  28981. color: hex !== undefined ? hex : 0xffffff
  28982. }));
  28983. }
  28984. GridHelper.prototype.setColors = function () {
  28985. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  28986. };
  28987. SkeletonHelper.prototype.update = function () {
  28988. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  28989. };
  28990. function WireframeHelper(object, hex) {
  28991. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  28992. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  28993. color: hex !== undefined ? hex : 0xffffff
  28994. }));
  28995. } //
  28996. Object.assign(Loader.prototype, {
  28997. extractUrlBase: function extractUrlBase(url) {
  28998. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  28999. return LoaderUtils.extractUrlBase(url);
  29000. }
  29001. });
  29002. Loader.Handlers = {
  29003. add: function add()
  29004. /* regex, loader */
  29005. {
  29006. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29007. },
  29008. get: function get()
  29009. /* file */
  29010. {
  29011. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29012. }
  29013. };
  29014. function XHRLoader(manager) {
  29015. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29016. return new FileLoader(manager);
  29017. }
  29018. function BinaryTextureLoader(manager) {
  29019. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29020. return new DataTextureLoader(manager);
  29021. } //
  29022. Object.assign(Box2.prototype, {
  29023. center: function center(optionalTarget) {
  29024. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29025. return this.getCenter(optionalTarget);
  29026. },
  29027. empty: function empty() {
  29028. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29029. return this.isEmpty();
  29030. },
  29031. isIntersectionBox: function isIntersectionBox(box) {
  29032. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29033. return this.intersectsBox(box);
  29034. },
  29035. size: function size(optionalTarget) {
  29036. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29037. return this.getSize(optionalTarget);
  29038. }
  29039. });
  29040. Object.assign(Box3.prototype, {
  29041. center: function center(optionalTarget) {
  29042. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29043. return this.getCenter(optionalTarget);
  29044. },
  29045. empty: function empty() {
  29046. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29047. return this.isEmpty();
  29048. },
  29049. isIntersectionBox: function isIntersectionBox(box) {
  29050. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29051. return this.intersectsBox(box);
  29052. },
  29053. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29054. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29055. return this.intersectsSphere(sphere);
  29056. },
  29057. size: function size(optionalTarget) {
  29058. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29059. return this.getSize(optionalTarget);
  29060. }
  29061. });
  29062. Object.assign(Sphere.prototype, {
  29063. empty: function empty() {
  29064. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29065. return this.isEmpty();
  29066. }
  29067. });
  29068. Frustum.prototype.setFromMatrix = function (m) {
  29069. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29070. return this.setFromProjectionMatrix(m);
  29071. };
  29072. Line3.prototype.center = function (optionalTarget) {
  29073. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29074. return this.getCenter(optionalTarget);
  29075. };
  29076. Object.assign(MathUtils, {
  29077. random16: function random16() {
  29078. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29079. return Math.random();
  29080. },
  29081. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29082. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29083. return MathUtils.floorPowerOfTwo(value);
  29084. },
  29085. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29086. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29087. return MathUtils.ceilPowerOfTwo(value);
  29088. }
  29089. });
  29090. Object.assign(Matrix3.prototype, {
  29091. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29092. console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29093. return this.toArray(array, offset);
  29094. },
  29095. multiplyVector3: function multiplyVector3(vector) {
  29096. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29097. return vector.applyMatrix3(this);
  29098. },
  29099. multiplyVector3Array: function multiplyVector3Array()
  29100. /* a */
  29101. {
  29102. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29103. },
  29104. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29105. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29106. return attribute.applyMatrix3(this);
  29107. },
  29108. applyToVector3Array: function applyToVector3Array()
  29109. /* array, offset, length */
  29110. {
  29111. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29112. }
  29113. });
  29114. Object.assign(Matrix4.prototype, {
  29115. extractPosition: function extractPosition(m) {
  29116. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29117. return this.copyPosition(m);
  29118. },
  29119. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29120. console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");
  29121. return this.toArray(array, offset);
  29122. },
  29123. getPosition: function getPosition() {
  29124. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29125. return new Vector3().setFromMatrixColumn(this, 3);
  29126. },
  29127. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29128. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29129. return this.makeRotationFromQuaternion(q);
  29130. },
  29131. multiplyToArray: function multiplyToArray() {
  29132. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29133. },
  29134. multiplyVector3: function multiplyVector3(vector) {
  29135. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29136. return vector.applyMatrix4(this);
  29137. },
  29138. multiplyVector4: function multiplyVector4(vector) {
  29139. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29140. return vector.applyMatrix4(this);
  29141. },
  29142. multiplyVector3Array: function multiplyVector3Array()
  29143. /* a */
  29144. {
  29145. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29146. },
  29147. rotateAxis: function rotateAxis(v) {
  29148. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29149. v.transformDirection(this);
  29150. },
  29151. crossVector: function crossVector(vector) {
  29152. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29153. return vector.applyMatrix4(this);
  29154. },
  29155. translate: function translate() {
  29156. console.error('THREE.Matrix4: .translate() has been removed.');
  29157. },
  29158. rotateX: function rotateX() {
  29159. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29160. },
  29161. rotateY: function rotateY() {
  29162. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29163. },
  29164. rotateZ: function rotateZ() {
  29165. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29166. },
  29167. rotateByAxis: function rotateByAxis() {
  29168. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29169. },
  29170. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29171. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29172. return attribute.applyMatrix4(this);
  29173. },
  29174. applyToVector3Array: function applyToVector3Array()
  29175. /* array, offset, length */
  29176. {
  29177. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29178. },
  29179. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29180. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29181. return this.makePerspective(left, right, top, bottom, near, far);
  29182. }
  29183. });
  29184. Plane.prototype.isIntersectionLine = function (line) {
  29185. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29186. return this.intersectsLine(line);
  29187. };
  29188. Quaternion.prototype.multiplyVector3 = function (vector) {
  29189. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29190. return vector.applyQuaternion(this);
  29191. };
  29192. Object.assign(Ray.prototype, {
  29193. isIntersectionBox: function isIntersectionBox(box) {
  29194. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29195. return this.intersectsBox(box);
  29196. },
  29197. isIntersectionPlane: function isIntersectionPlane(plane) {
  29198. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29199. return this.intersectsPlane(plane);
  29200. },
  29201. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29202. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29203. return this.intersectsSphere(sphere);
  29204. }
  29205. });
  29206. Object.assign(Triangle.prototype, {
  29207. area: function area() {
  29208. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29209. return this.getArea();
  29210. },
  29211. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29212. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29213. return this.getBarycoord(point, target);
  29214. },
  29215. midpoint: function midpoint(target) {
  29216. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29217. return this.getMidpoint(target);
  29218. },
  29219. normal: function normal(target) {
  29220. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29221. return this.getNormal(target);
  29222. },
  29223. plane: function plane(target) {
  29224. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29225. return this.getPlane(target);
  29226. }
  29227. });
  29228. Object.assign(Triangle, {
  29229. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29230. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29231. return Triangle.getBarycoord(point, a, b, c, target);
  29232. },
  29233. normal: function normal(a, b, c, target) {
  29234. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29235. return Triangle.getNormal(a, b, c, target);
  29236. }
  29237. });
  29238. Object.assign(Shape.prototype, {
  29239. extractAllPoints: function extractAllPoints(divisions) {
  29240. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29241. return this.extractPoints(divisions);
  29242. },
  29243. extrude: function extrude(options) {
  29244. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29245. return new ExtrudeGeometry(this, options);
  29246. },
  29247. makeGeometry: function makeGeometry(options) {
  29248. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29249. return new ShapeGeometry(this, options);
  29250. }
  29251. });
  29252. Object.assign(Vector2.prototype, {
  29253. fromAttribute: function fromAttribute(attribute, index, offset) {
  29254. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29255. return this.fromBufferAttribute(attribute, index, offset);
  29256. },
  29257. distanceToManhattan: function distanceToManhattan(v) {
  29258. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29259. return this.manhattanDistanceTo(v);
  29260. },
  29261. lengthManhattan: function lengthManhattan() {
  29262. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29263. return this.manhattanLength();
  29264. }
  29265. });
  29266. Object.assign(Vector3.prototype, {
  29267. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29268. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29269. },
  29270. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29271. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29272. },
  29273. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29274. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29275. return this.setFromMatrixPosition(m);
  29276. },
  29277. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29278. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29279. return this.setFromMatrixScale(m);
  29280. },
  29281. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29282. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29283. return this.setFromMatrixColumn(matrix, index);
  29284. },
  29285. applyProjection: function applyProjection(m) {
  29286. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29287. return this.applyMatrix4(m);
  29288. },
  29289. fromAttribute: function fromAttribute(attribute, index, offset) {
  29290. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29291. return this.fromBufferAttribute(attribute, index, offset);
  29292. },
  29293. distanceToManhattan: function distanceToManhattan(v) {
  29294. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29295. return this.manhattanDistanceTo(v);
  29296. },
  29297. lengthManhattan: function lengthManhattan() {
  29298. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29299. return this.manhattanLength();
  29300. }
  29301. });
  29302. Object.assign(Vector4.prototype, {
  29303. fromAttribute: function fromAttribute(attribute, index, offset) {
  29304. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29305. return this.fromBufferAttribute(attribute, index, offset);
  29306. },
  29307. lengthManhattan: function lengthManhattan() {
  29308. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29309. return this.manhattanLength();
  29310. }
  29311. }); //
  29312. Object.assign(Geometry.prototype, {
  29313. computeTangents: function computeTangents() {
  29314. console.error('THREE.Geometry: .computeTangents() has been removed.');
  29315. },
  29316. computeLineDistances: function computeLineDistances() {
  29317. console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');
  29318. },
  29319. applyMatrix: function applyMatrix(matrix) {
  29320. console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29321. return this.applyMatrix4(matrix);
  29322. }
  29323. });
  29324. Object.assign(Object3D.prototype, {
  29325. getChildByName: function getChildByName(name) {
  29326. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29327. return this.getObjectByName(name);
  29328. },
  29329. renderDepth: function renderDepth() {
  29330. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29331. },
  29332. translate: function translate(distance, axis) {
  29333. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29334. return this.translateOnAxis(axis, distance);
  29335. },
  29336. getWorldRotation: function getWorldRotation() {
  29337. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29338. },
  29339. applyMatrix: function applyMatrix(matrix) {
  29340. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29341. return this.applyMatrix4(matrix);
  29342. }
  29343. });
  29344. Object.defineProperties(Object3D.prototype, {
  29345. eulerOrder: {
  29346. get: function get() {
  29347. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29348. return this.rotation.order;
  29349. },
  29350. set: function set(value) {
  29351. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29352. this.rotation.order = value;
  29353. }
  29354. },
  29355. useQuaternion: {
  29356. get: function get() {
  29357. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29358. },
  29359. set: function set() {
  29360. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29361. }
  29362. }
  29363. });
  29364. Object.assign(Mesh.prototype, {
  29365. setDrawMode: function setDrawMode() {
  29366. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29367. }
  29368. });
  29369. Object.defineProperties(Mesh.prototype, {
  29370. drawMode: {
  29371. get: function get() {
  29372. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29373. return TrianglesDrawMode;
  29374. },
  29375. set: function set() {
  29376. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29377. }
  29378. }
  29379. });
  29380. Object.defineProperties(LOD.prototype, {
  29381. objects: {
  29382. get: function get() {
  29383. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29384. return this.levels;
  29385. }
  29386. }
  29387. });
  29388. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29389. get: function get() {
  29390. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29391. },
  29392. set: function set() {
  29393. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29394. }
  29395. });
  29396. SkinnedMesh.prototype.initBones = function () {
  29397. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29398. };
  29399. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29400. get: function get() {
  29401. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29402. return this.arcLengthDivisions;
  29403. },
  29404. set: function set(value) {
  29405. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29406. this.arcLengthDivisions = value;
  29407. }
  29408. }); //
  29409. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29410. console.warn("THREE.PerspectiveCamera.setLens is deprecated. " + "Use .setFocalLength and .filmGauge for a photographic setup.");
  29411. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29412. this.setFocalLength(focalLength);
  29413. }; //
  29414. Object.defineProperties(Light.prototype, {
  29415. onlyShadow: {
  29416. set: function set() {
  29417. console.warn('THREE.Light: .onlyShadow has been removed.');
  29418. }
  29419. },
  29420. shadowCameraFov: {
  29421. set: function set(value) {
  29422. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29423. this.shadow.camera.fov = value;
  29424. }
  29425. },
  29426. shadowCameraLeft: {
  29427. set: function set(value) {
  29428. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29429. this.shadow.camera.left = value;
  29430. }
  29431. },
  29432. shadowCameraRight: {
  29433. set: function set(value) {
  29434. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29435. this.shadow.camera.right = value;
  29436. }
  29437. },
  29438. shadowCameraTop: {
  29439. set: function set(value) {
  29440. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29441. this.shadow.camera.top = value;
  29442. }
  29443. },
  29444. shadowCameraBottom: {
  29445. set: function set(value) {
  29446. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29447. this.shadow.camera.bottom = value;
  29448. }
  29449. },
  29450. shadowCameraNear: {
  29451. set: function set(value) {
  29452. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29453. this.shadow.camera.near = value;
  29454. }
  29455. },
  29456. shadowCameraFar: {
  29457. set: function set(value) {
  29458. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29459. this.shadow.camera.far = value;
  29460. }
  29461. },
  29462. shadowCameraVisible: {
  29463. set: function set() {
  29464. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29465. }
  29466. },
  29467. shadowBias: {
  29468. set: function set(value) {
  29469. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29470. this.shadow.bias = value;
  29471. }
  29472. },
  29473. shadowDarkness: {
  29474. set: function set() {
  29475. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29476. }
  29477. },
  29478. shadowMapWidth: {
  29479. set: function set(value) {
  29480. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29481. this.shadow.mapSize.width = value;
  29482. }
  29483. },
  29484. shadowMapHeight: {
  29485. set: function set(value) {
  29486. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29487. this.shadow.mapSize.height = value;
  29488. }
  29489. }
  29490. }); //
  29491. Object.defineProperties(BufferAttribute.prototype, {
  29492. length: {
  29493. get: function get() {
  29494. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29495. return this.array.length;
  29496. }
  29497. },
  29498. dynamic: {
  29499. get: function get() {
  29500. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29501. return this.usage === DynamicDrawUsage;
  29502. },
  29503. set: function set()
  29504. /* value */
  29505. {
  29506. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29507. this.setUsage(DynamicDrawUsage);
  29508. }
  29509. }
  29510. });
  29511. Object.assign(BufferAttribute.prototype, {
  29512. setDynamic: function setDynamic(value) {
  29513. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29514. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29515. return this;
  29516. },
  29517. copyIndicesArray: function copyIndicesArray()
  29518. /* indices */
  29519. {
  29520. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29521. },
  29522. setArray: function setArray()
  29523. /* array */
  29524. {
  29525. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29526. }
  29527. });
  29528. Object.assign(BufferGeometry.prototype, {
  29529. addIndex: function addIndex(index) {
  29530. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29531. this.setIndex(index);
  29532. },
  29533. addAttribute: function addAttribute(name, attribute) {
  29534. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29535. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29536. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29537. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29538. }
  29539. if (name === 'index') {
  29540. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29541. this.setIndex(attribute);
  29542. return this;
  29543. }
  29544. return this.setAttribute(name, attribute);
  29545. },
  29546. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29547. if (indexOffset !== undefined) {
  29548. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29549. }
  29550. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29551. this.addGroup(start, count);
  29552. },
  29553. clearDrawCalls: function clearDrawCalls() {
  29554. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29555. this.clearGroups();
  29556. },
  29557. computeTangents: function computeTangents() {
  29558. console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');
  29559. },
  29560. computeOffsets: function computeOffsets() {
  29561. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29562. },
  29563. removeAttribute: function removeAttribute(name) {
  29564. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29565. return this.deleteAttribute(name);
  29566. },
  29567. applyMatrix: function applyMatrix(matrix) {
  29568. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29569. return this.applyMatrix4(matrix);
  29570. }
  29571. });
  29572. Object.defineProperties(BufferGeometry.prototype, {
  29573. drawcalls: {
  29574. get: function get() {
  29575. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29576. return this.groups;
  29577. }
  29578. },
  29579. offsets: {
  29580. get: function get() {
  29581. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29582. return this.groups;
  29583. }
  29584. }
  29585. });
  29586. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29587. maxInstancedCount: {
  29588. get: function get() {
  29589. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29590. return this.instanceCount;
  29591. },
  29592. set: function set(value) {
  29593. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29594. this.instanceCount = value;
  29595. }
  29596. }
  29597. });
  29598. Object.defineProperties(Raycaster.prototype, {
  29599. linePrecision: {
  29600. get: function get() {
  29601. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29602. return this.params.Line.threshold;
  29603. },
  29604. set: function set(value) {
  29605. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29606. this.params.Line.threshold = value;
  29607. }
  29608. }
  29609. });
  29610. Object.defineProperties(InterleavedBuffer.prototype, {
  29611. dynamic: {
  29612. get: function get() {
  29613. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29614. return this.usage === DynamicDrawUsage;
  29615. },
  29616. set: function set(value) {
  29617. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29618. this.setUsage(value);
  29619. }
  29620. }
  29621. });
  29622. Object.assign(InterleavedBuffer.prototype, {
  29623. setDynamic: function setDynamic(value) {
  29624. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29625. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29626. return this;
  29627. },
  29628. setArray: function setArray()
  29629. /* array */
  29630. {
  29631. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29632. }
  29633. }); //
  29634. Object.assign(ExtrudeBufferGeometry.prototype, {
  29635. getArrays: function getArrays() {
  29636. console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');
  29637. },
  29638. addShapeList: function addShapeList() {
  29639. console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');
  29640. },
  29641. addShape: function addShape() {
  29642. console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');
  29643. }
  29644. }); //
  29645. Object.assign(Scene.prototype, {
  29646. dispose: function dispose() {
  29647. console.error('THREE.Scene: .dispose() has been removed.');
  29648. }
  29649. }); //
  29650. Object.defineProperties(Uniform.prototype, {
  29651. dynamic: {
  29652. set: function set() {
  29653. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29654. }
  29655. },
  29656. onUpdate: {
  29657. value: function value() {
  29658. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29659. return this;
  29660. }
  29661. }
  29662. }); //
  29663. Object.defineProperties(Material.prototype, {
  29664. wrapAround: {
  29665. get: function get() {
  29666. console.warn('THREE.Material: .wrapAround has been removed.');
  29667. },
  29668. set: function set() {
  29669. console.warn('THREE.Material: .wrapAround has been removed.');
  29670. }
  29671. },
  29672. overdraw: {
  29673. get: function get() {
  29674. console.warn('THREE.Material: .overdraw has been removed.');
  29675. },
  29676. set: function set() {
  29677. console.warn('THREE.Material: .overdraw has been removed.');
  29678. }
  29679. },
  29680. wrapRGB: {
  29681. get: function get() {
  29682. console.warn('THREE.Material: .wrapRGB has been removed.');
  29683. return new Color();
  29684. }
  29685. },
  29686. shading: {
  29687. get: function get() {
  29688. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29689. },
  29690. set: function set(value) {
  29691. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29692. this.flatShading = value === FlatShading;
  29693. }
  29694. },
  29695. stencilMask: {
  29696. get: function get() {
  29697. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29698. return this.stencilFuncMask;
  29699. },
  29700. set: function set(value) {
  29701. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29702. this.stencilFuncMask = value;
  29703. }
  29704. }
  29705. });
  29706. Object.defineProperties(MeshPhongMaterial.prototype, {
  29707. metal: {
  29708. get: function get() {
  29709. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29710. return false;
  29711. },
  29712. set: function set() {
  29713. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29714. }
  29715. }
  29716. });
  29717. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29718. transparency: {
  29719. get: function get() {
  29720. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29721. return this.transmission;
  29722. },
  29723. set: function set(value) {
  29724. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29725. this.transmission = value;
  29726. }
  29727. }
  29728. });
  29729. Object.defineProperties(ShaderMaterial.prototype, {
  29730. derivatives: {
  29731. get: function get() {
  29732. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29733. return this.extensions.derivatives;
  29734. },
  29735. set: function set(value) {
  29736. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29737. this.extensions.derivatives = value;
  29738. }
  29739. }
  29740. }); //
  29741. Object.assign(WebGLRenderer.prototype, {
  29742. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29743. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29744. this.setRenderTarget(renderTarget);
  29745. this.clear(color, depth, stencil);
  29746. },
  29747. animate: function animate(callback) {
  29748. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29749. this.setAnimationLoop(callback);
  29750. },
  29751. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29752. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29753. return this.getRenderTarget();
  29754. },
  29755. getMaxAnisotropy: function getMaxAnisotropy() {
  29756. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29757. return this.capabilities.getMaxAnisotropy();
  29758. },
  29759. getPrecision: function getPrecision() {
  29760. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29761. return this.capabilities.precision;
  29762. },
  29763. resetGLState: function resetGLState() {
  29764. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29765. return this.state.reset();
  29766. },
  29767. supportsFloatTextures: function supportsFloatTextures() {
  29768. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29769. return this.extensions.get('OES_texture_float');
  29770. },
  29771. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29772. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29773. return this.extensions.get('OES_texture_half_float');
  29774. },
  29775. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29776. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29777. return this.extensions.get('OES_standard_derivatives');
  29778. },
  29779. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29780. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29781. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29782. },
  29783. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29784. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29785. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29786. },
  29787. supportsBlendMinMax: function supportsBlendMinMax() {
  29788. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29789. return this.extensions.get('EXT_blend_minmax');
  29790. },
  29791. supportsVertexTextures: function supportsVertexTextures() {
  29792. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29793. return this.capabilities.vertexTextures;
  29794. },
  29795. supportsInstancedArrays: function supportsInstancedArrays() {
  29796. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29797. return this.extensions.get('ANGLE_instanced_arrays');
  29798. },
  29799. enableScissorTest: function enableScissorTest(boolean) {
  29800. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29801. this.setScissorTest(boolean);
  29802. },
  29803. initMaterial: function initMaterial() {
  29804. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29805. },
  29806. addPrePlugin: function addPrePlugin() {
  29807. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29808. },
  29809. addPostPlugin: function addPostPlugin() {
  29810. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29811. },
  29812. updateShadowMap: function updateShadowMap() {
  29813. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29814. },
  29815. setFaceCulling: function setFaceCulling() {
  29816. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29817. },
  29818. allocTextureUnit: function allocTextureUnit() {
  29819. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29820. },
  29821. setTexture: function setTexture() {
  29822. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29823. },
  29824. setTexture2D: function setTexture2D() {
  29825. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29826. },
  29827. setTextureCube: function setTextureCube() {
  29828. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29829. },
  29830. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29831. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29832. return this.getActiveMipmapLevel();
  29833. }
  29834. });
  29835. Object.defineProperties(WebGLRenderer.prototype, {
  29836. shadowMapEnabled: {
  29837. get: function get() {
  29838. return this.shadowMap.enabled;
  29839. },
  29840. set: function set(value) {
  29841. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29842. this.shadowMap.enabled = value;
  29843. }
  29844. },
  29845. shadowMapType: {
  29846. get: function get() {
  29847. return this.shadowMap.type;
  29848. },
  29849. set: function set(value) {
  29850. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29851. this.shadowMap.type = value;
  29852. }
  29853. },
  29854. shadowMapCullFace: {
  29855. get: function get() {
  29856. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29857. return undefined;
  29858. },
  29859. set: function set()
  29860. /* value */
  29861. {
  29862. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29863. }
  29864. },
  29865. context: {
  29866. get: function get() {
  29867. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29868. return this.getContext();
  29869. }
  29870. },
  29871. vr: {
  29872. get: function get() {
  29873. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29874. return this.xr;
  29875. }
  29876. },
  29877. gammaInput: {
  29878. get: function get() {
  29879. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29880. return false;
  29881. },
  29882. set: function set() {
  29883. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29884. }
  29885. },
  29886. gammaOutput: {
  29887. get: function get() {
  29888. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29889. return false;
  29890. },
  29891. set: function set(value) {
  29892. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29893. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29894. }
  29895. },
  29896. toneMappingWhitePoint: {
  29897. get: function get() {
  29898. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29899. return 1.0;
  29900. },
  29901. set: function set() {
  29902. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29903. }
  29904. }
  29905. });
  29906. Object.defineProperties(WebGLShadowMap.prototype, {
  29907. cullFace: {
  29908. get: function get() {
  29909. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29910. return undefined;
  29911. },
  29912. set: function set()
  29913. /* cullFace */
  29914. {
  29915. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29916. }
  29917. },
  29918. renderReverseSided: {
  29919. get: function get() {
  29920. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29921. return undefined;
  29922. },
  29923. set: function set() {
  29924. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  29925. }
  29926. },
  29927. renderSingleSided: {
  29928. get: function get() {
  29929. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29930. return undefined;
  29931. },
  29932. set: function set() {
  29933. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  29934. }
  29935. }
  29936. });
  29937. function WebGLRenderTargetCube(width, height, options) {
  29938. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  29939. return new WebGLCubeRenderTarget(width, options);
  29940. } //
  29941. Object.defineProperties(WebGLRenderTarget.prototype, {
  29942. wrapS: {
  29943. get: function get() {
  29944. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29945. return this.texture.wrapS;
  29946. },
  29947. set: function set(value) {
  29948. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  29949. this.texture.wrapS = value;
  29950. }
  29951. },
  29952. wrapT: {
  29953. get: function get() {
  29954. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29955. return this.texture.wrapT;
  29956. },
  29957. set: function set(value) {
  29958. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  29959. this.texture.wrapT = value;
  29960. }
  29961. },
  29962. magFilter: {
  29963. get: function get() {
  29964. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29965. return this.texture.magFilter;
  29966. },
  29967. set: function set(value) {
  29968. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  29969. this.texture.magFilter = value;
  29970. }
  29971. },
  29972. minFilter: {
  29973. get: function get() {
  29974. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29975. return this.texture.minFilter;
  29976. },
  29977. set: function set(value) {
  29978. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  29979. this.texture.minFilter = value;
  29980. }
  29981. },
  29982. anisotropy: {
  29983. get: function get() {
  29984. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29985. return this.texture.anisotropy;
  29986. },
  29987. set: function set(value) {
  29988. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  29989. this.texture.anisotropy = value;
  29990. }
  29991. },
  29992. offset: {
  29993. get: function get() {
  29994. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29995. return this.texture.offset;
  29996. },
  29997. set: function set(value) {
  29998. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  29999. this.texture.offset = value;
  30000. }
  30001. },
  30002. repeat: {
  30003. get: function get() {
  30004. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30005. return this.texture.repeat;
  30006. },
  30007. set: function set(value) {
  30008. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30009. this.texture.repeat = value;
  30010. }
  30011. },
  30012. format: {
  30013. get: function get() {
  30014. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30015. return this.texture.format;
  30016. },
  30017. set: function set(value) {
  30018. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30019. this.texture.format = value;
  30020. }
  30021. },
  30022. type: {
  30023. get: function get() {
  30024. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30025. return this.texture.type;
  30026. },
  30027. set: function set(value) {
  30028. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30029. this.texture.type = value;
  30030. }
  30031. },
  30032. generateMipmaps: {
  30033. get: function get() {
  30034. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30035. return this.texture.generateMipmaps;
  30036. },
  30037. set: function set(value) {
  30038. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30039. this.texture.generateMipmaps = value;
  30040. }
  30041. }
  30042. }); //
  30043. Object.defineProperties(Audio.prototype, {
  30044. load: {
  30045. value: function value(file) {
  30046. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30047. var scope = this;
  30048. var audioLoader = new AudioLoader();
  30049. audioLoader.load(file, function (buffer) {
  30050. scope.setBuffer(buffer);
  30051. });
  30052. return this;
  30053. }
  30054. },
  30055. startTime: {
  30056. set: function set() {
  30057. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30058. }
  30059. }
  30060. });
  30061. AudioAnalyser.prototype.getData = function () {
  30062. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30063. return this.getFrequencyData();
  30064. }; //
  30065. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30066. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30067. return this.update(renderer, scene);
  30068. };
  30069. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30070. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30071. return this.renderTarget.clear(renderer, color, depth, stencil);
  30072. }; //
  30073. var GeometryUtils = {
  30074. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30075. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30076. var matrix;
  30077. if (geometry2.isMesh) {
  30078. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30079. matrix = geometry2.matrix;
  30080. geometry2 = geometry2.geometry;
  30081. }
  30082. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30083. },
  30084. center: function center(geometry) {
  30085. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30086. return geometry.center();
  30087. }
  30088. };
  30089. ImageUtils.crossOrigin = undefined;
  30090. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30091. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30092. var loader = new TextureLoader();
  30093. loader.setCrossOrigin(this.crossOrigin);
  30094. var texture = loader.load(url, onLoad, undefined, onError);
  30095. if (mapping) texture.mapping = mapping;
  30096. return texture;
  30097. };
  30098. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30099. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30100. var loader = new CubeTextureLoader();
  30101. loader.setCrossOrigin(this.crossOrigin);
  30102. var texture = loader.load(urls, onLoad, undefined, onError);
  30103. if (mapping) texture.mapping = mapping;
  30104. return texture;
  30105. };
  30106. ImageUtils.loadCompressedTexture = function () {
  30107. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30108. };
  30109. ImageUtils.loadCompressedTextureCube = function () {
  30110. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30111. }; //
  30112. function CanvasRenderer() {
  30113. console.error('THREE.CanvasRenderer has been removed');
  30114. } //
  30115. function JSONLoader() {
  30116. console.error('THREE.JSONLoader has been removed.');
  30117. } //
  30118. var SceneUtils = {
  30119. createMultiMaterialObject: function createMultiMaterialObject()
  30120. /* geometry, materials */
  30121. {
  30122. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30123. },
  30124. detach: function detach()
  30125. /* child, parent, scene */
  30126. {
  30127. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30128. },
  30129. attach: function attach()
  30130. /* child, scene, parent */
  30131. {
  30132. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30133. }
  30134. }; //
  30135. function LensFlare() {
  30136. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30137. }
  30138. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30139. /* eslint-disable no-undef */
  30140. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30141. detail: {
  30142. revision: REVISION
  30143. }
  30144. }));
  30145. /* eslint-enable no-undef */
  30146. }
  30147. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30148. exports.AddEquation = AddEquation;
  30149. exports.AddOperation = AddOperation;
  30150. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30151. exports.AdditiveBlending = AdditiveBlending;
  30152. exports.AlphaFormat = AlphaFormat;
  30153. exports.AlwaysDepth = AlwaysDepth;
  30154. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30155. exports.AmbientLight = AmbientLight;
  30156. exports.AmbientLightProbe = AmbientLightProbe;
  30157. exports.AnimationClip = AnimationClip;
  30158. exports.AnimationLoader = AnimationLoader;
  30159. exports.AnimationMixer = AnimationMixer;
  30160. exports.AnimationObjectGroup = AnimationObjectGroup;
  30161. exports.AnimationUtils = AnimationUtils;
  30162. exports.ArcCurve = ArcCurve;
  30163. exports.ArrayCamera = ArrayCamera;
  30164. exports.ArrowHelper = ArrowHelper;
  30165. exports.Audio = Audio;
  30166. exports.AudioAnalyser = AudioAnalyser;
  30167. exports.AudioContext = AudioContext;
  30168. exports.AudioListener = AudioListener;
  30169. exports.AudioLoader = AudioLoader;
  30170. exports.AxesHelper = AxesHelper;
  30171. exports.AxisHelper = AxisHelper;
  30172. exports.BackSide = BackSide;
  30173. exports.BasicDepthPacking = BasicDepthPacking;
  30174. exports.BasicShadowMap = BasicShadowMap;
  30175. exports.BinaryTextureLoader = BinaryTextureLoader;
  30176. exports.Bone = Bone;
  30177. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30178. exports.BoundingBoxHelper = BoundingBoxHelper;
  30179. exports.Box2 = Box2;
  30180. exports.Box3 = Box3;
  30181. exports.Box3Helper = Box3Helper;
  30182. exports.BoxBufferGeometry = BoxBufferGeometry;
  30183. exports.BoxGeometry = BoxGeometry;
  30184. exports.BoxHelper = BoxHelper;
  30185. exports.BufferAttribute = BufferAttribute;
  30186. exports.BufferGeometry = BufferGeometry;
  30187. exports.BufferGeometryLoader = BufferGeometryLoader;
  30188. exports.ByteType = ByteType;
  30189. exports.Cache = Cache;
  30190. exports.Camera = Camera;
  30191. exports.CameraHelper = CameraHelper;
  30192. exports.CanvasRenderer = CanvasRenderer;
  30193. exports.CanvasTexture = CanvasTexture;
  30194. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30195. exports.CineonToneMapping = CineonToneMapping;
  30196. exports.CircleBufferGeometry = CircleBufferGeometry;
  30197. exports.CircleGeometry = CircleGeometry;
  30198. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30199. exports.Clock = Clock;
  30200. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30201. exports.Color = Color;
  30202. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30203. exports.CompressedTexture = CompressedTexture;
  30204. exports.CompressedTextureLoader = CompressedTextureLoader;
  30205. exports.ConeBufferGeometry = ConeBufferGeometry;
  30206. exports.ConeGeometry = ConeGeometry;
  30207. exports.CubeCamera = CubeCamera;
  30208. exports.CubeGeometry = BoxGeometry;
  30209. exports.CubeReflectionMapping = CubeReflectionMapping;
  30210. exports.CubeRefractionMapping = CubeRefractionMapping;
  30211. exports.CubeTexture = CubeTexture;
  30212. exports.CubeTextureLoader = CubeTextureLoader;
  30213. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30214. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30215. exports.CubicBezierCurve = CubicBezierCurve;
  30216. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30217. exports.CubicInterpolant = CubicInterpolant;
  30218. exports.CullFaceBack = CullFaceBack;
  30219. exports.CullFaceFront = CullFaceFront;
  30220. exports.CullFaceFrontBack = CullFaceFrontBack;
  30221. exports.CullFaceNone = CullFaceNone;
  30222. exports.Curve = Curve;
  30223. exports.CurvePath = CurvePath;
  30224. exports.CustomBlending = CustomBlending;
  30225. exports.CustomToneMapping = CustomToneMapping;
  30226. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30227. exports.CylinderGeometry = CylinderGeometry;
  30228. exports.Cylindrical = Cylindrical;
  30229. exports.DataTexture = DataTexture;
  30230. exports.DataTexture2DArray = DataTexture2DArray;
  30231. exports.DataTexture3D = DataTexture3D;
  30232. exports.DataTextureLoader = DataTextureLoader;
  30233. exports.DecrementStencilOp = DecrementStencilOp;
  30234. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30235. exports.DefaultLoadingManager = DefaultLoadingManager;
  30236. exports.DepthFormat = DepthFormat;
  30237. exports.DepthStencilFormat = DepthStencilFormat;
  30238. exports.DepthTexture = DepthTexture;
  30239. exports.DirectionalLight = DirectionalLight;
  30240. exports.DirectionalLightHelper = DirectionalLightHelper;
  30241. exports.DiscreteInterpolant = DiscreteInterpolant;
  30242. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30243. exports.DodecahedronGeometry = DodecahedronGeometry;
  30244. exports.DoubleSide = DoubleSide;
  30245. exports.DstAlphaFactor = DstAlphaFactor;
  30246. exports.DstColorFactor = DstColorFactor;
  30247. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30248. exports.DynamicCopyUsage = DynamicCopyUsage;
  30249. exports.DynamicDrawUsage = DynamicDrawUsage;
  30250. exports.DynamicReadUsage = DynamicReadUsage;
  30251. exports.EdgesGeometry = EdgesGeometry;
  30252. exports.EdgesHelper = EdgesHelper;
  30253. exports.EllipseCurve = EllipseCurve;
  30254. exports.EqualDepth = EqualDepth;
  30255. exports.EqualStencilFunc = EqualStencilFunc;
  30256. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30257. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30258. exports.Euler = Euler;
  30259. exports.EventDispatcher = EventDispatcher;
  30260. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30261. exports.ExtrudeGeometry = ExtrudeGeometry;
  30262. exports.Face3 = Face3;
  30263. exports.Face4 = Face4;
  30264. exports.FaceColors = FaceColors;
  30265. exports.FileLoader = FileLoader;
  30266. exports.FlatShading = FlatShading;
  30267. exports.Float32Attribute = Float32Attribute;
  30268. exports.Float32BufferAttribute = Float32BufferAttribute;
  30269. exports.Float64Attribute = Float64Attribute;
  30270. exports.Float64BufferAttribute = Float64BufferAttribute;
  30271. exports.FloatType = FloatType;
  30272. exports.Fog = Fog;
  30273. exports.FogExp2 = FogExp2;
  30274. exports.Font = Font;
  30275. exports.FontLoader = FontLoader;
  30276. exports.FrontSide = FrontSide;
  30277. exports.Frustum = Frustum;
  30278. exports.GLBufferAttribute = GLBufferAttribute;
  30279. exports.GLSL1 = GLSL1;
  30280. exports.GLSL3 = GLSL3;
  30281. exports.GammaEncoding = GammaEncoding;
  30282. exports.Geometry = Geometry;
  30283. exports.GeometryUtils = GeometryUtils;
  30284. exports.GreaterDepth = GreaterDepth;
  30285. exports.GreaterEqualDepth = GreaterEqualDepth;
  30286. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30287. exports.GreaterStencilFunc = GreaterStencilFunc;
  30288. exports.GridHelper = GridHelper;
  30289. exports.Group = Group;
  30290. exports.HalfFloatType = HalfFloatType;
  30291. exports.HemisphereLight = HemisphereLight;
  30292. exports.HemisphereLightHelper = HemisphereLightHelper;
  30293. exports.HemisphereLightProbe = HemisphereLightProbe;
  30294. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30295. exports.IcosahedronGeometry = IcosahedronGeometry;
  30296. exports.ImageBitmapLoader = ImageBitmapLoader;
  30297. exports.ImageLoader = ImageLoader;
  30298. exports.ImageUtils = ImageUtils;
  30299. exports.ImmediateRenderObject = ImmediateRenderObject;
  30300. exports.IncrementStencilOp = IncrementStencilOp;
  30301. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30302. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30303. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30304. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30305. exports.InstancedMesh = InstancedMesh;
  30306. exports.Int16Attribute = Int16Attribute;
  30307. exports.Int16BufferAttribute = Int16BufferAttribute;
  30308. exports.Int32Attribute = Int32Attribute;
  30309. exports.Int32BufferAttribute = Int32BufferAttribute;
  30310. exports.Int8Attribute = Int8Attribute;
  30311. exports.Int8BufferAttribute = Int8BufferAttribute;
  30312. exports.IntType = IntType;
  30313. exports.InterleavedBuffer = InterleavedBuffer;
  30314. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30315. exports.Interpolant = Interpolant;
  30316. exports.InterpolateDiscrete = InterpolateDiscrete;
  30317. exports.InterpolateLinear = InterpolateLinear;
  30318. exports.InterpolateSmooth = InterpolateSmooth;
  30319. exports.InvertStencilOp = InvertStencilOp;
  30320. exports.JSONLoader = JSONLoader;
  30321. exports.KeepStencilOp = KeepStencilOp;
  30322. exports.KeyframeTrack = KeyframeTrack;
  30323. exports.LOD = LOD;
  30324. exports.LatheBufferGeometry = LatheBufferGeometry;
  30325. exports.LatheGeometry = LatheGeometry;
  30326. exports.Layers = Layers;
  30327. exports.LensFlare = LensFlare;
  30328. exports.LessDepth = LessDepth;
  30329. exports.LessEqualDepth = LessEqualDepth;
  30330. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30331. exports.LessStencilFunc = LessStencilFunc;
  30332. exports.Light = Light;
  30333. exports.LightProbe = LightProbe;
  30334. exports.Line = Line;
  30335. exports.Line3 = Line3;
  30336. exports.LineBasicMaterial = LineBasicMaterial;
  30337. exports.LineCurve = LineCurve;
  30338. exports.LineCurve3 = LineCurve3;
  30339. exports.LineDashedMaterial = LineDashedMaterial;
  30340. exports.LineLoop = LineLoop;
  30341. exports.LinePieces = LinePieces;
  30342. exports.LineSegments = LineSegments;
  30343. exports.LineStrip = LineStrip;
  30344. exports.LinearEncoding = LinearEncoding;
  30345. exports.LinearFilter = LinearFilter;
  30346. exports.LinearInterpolant = LinearInterpolant;
  30347. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30348. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30349. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30350. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30351. exports.LinearToneMapping = LinearToneMapping;
  30352. exports.Loader = Loader;
  30353. exports.LoaderUtils = LoaderUtils;
  30354. exports.LoadingManager = LoadingManager;
  30355. exports.LogLuvEncoding = LogLuvEncoding;
  30356. exports.LoopOnce = LoopOnce;
  30357. exports.LoopPingPong = LoopPingPong;
  30358. exports.LoopRepeat = LoopRepeat;
  30359. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30360. exports.LuminanceFormat = LuminanceFormat;
  30361. exports.MOUSE = MOUSE;
  30362. exports.Material = Material;
  30363. exports.MaterialLoader = MaterialLoader;
  30364. exports.Math = MathUtils;
  30365. exports.MathUtils = MathUtils;
  30366. exports.Matrix3 = Matrix3;
  30367. exports.Matrix4 = Matrix4;
  30368. exports.MaxEquation = MaxEquation;
  30369. exports.Mesh = Mesh;
  30370. exports.MeshBasicMaterial = MeshBasicMaterial;
  30371. exports.MeshDepthMaterial = MeshDepthMaterial;
  30372. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30373. exports.MeshFaceMaterial = MeshFaceMaterial;
  30374. exports.MeshLambertMaterial = MeshLambertMaterial;
  30375. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30376. exports.MeshNormalMaterial = MeshNormalMaterial;
  30377. exports.MeshPhongMaterial = MeshPhongMaterial;
  30378. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30379. exports.MeshStandardMaterial = MeshStandardMaterial;
  30380. exports.MeshToonMaterial = MeshToonMaterial;
  30381. exports.MinEquation = MinEquation;
  30382. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30383. exports.MixOperation = MixOperation;
  30384. exports.MultiMaterial = MultiMaterial;
  30385. exports.MultiplyBlending = MultiplyBlending;
  30386. exports.MultiplyOperation = MultiplyOperation;
  30387. exports.NearestFilter = NearestFilter;
  30388. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30389. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30390. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30391. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30392. exports.NeverDepth = NeverDepth;
  30393. exports.NeverStencilFunc = NeverStencilFunc;
  30394. exports.NoBlending = NoBlending;
  30395. exports.NoColors = NoColors;
  30396. exports.NoToneMapping = NoToneMapping;
  30397. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30398. exports.NormalBlending = NormalBlending;
  30399. exports.NotEqualDepth = NotEqualDepth;
  30400. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30401. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30402. exports.Object3D = Object3D;
  30403. exports.ObjectLoader = ObjectLoader;
  30404. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30405. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  30406. exports.OctahedronGeometry = OctahedronGeometry;
  30407. exports.OneFactor = OneFactor;
  30408. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30409. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30410. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30411. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30412. exports.OrthographicCamera = OrthographicCamera;
  30413. exports.PCFShadowMap = PCFShadowMap;
  30414. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30415. exports.PMREMGenerator = PMREMGenerator;
  30416. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  30417. exports.ParametricGeometry = ParametricGeometry;
  30418. exports.Particle = Particle;
  30419. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30420. exports.ParticleSystem = ParticleSystem;
  30421. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30422. exports.Path = Path;
  30423. exports.PerspectiveCamera = PerspectiveCamera;
  30424. exports.Plane = Plane;
  30425. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  30426. exports.PlaneGeometry = PlaneGeometry;
  30427. exports.PlaneHelper = PlaneHelper;
  30428. exports.PointCloud = PointCloud;
  30429. exports.PointCloudMaterial = PointCloudMaterial;
  30430. exports.PointLight = PointLight;
  30431. exports.PointLightHelper = PointLightHelper;
  30432. exports.Points = Points;
  30433. exports.PointsMaterial = PointsMaterial;
  30434. exports.PolarGridHelper = PolarGridHelper;
  30435. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  30436. exports.PolyhedronGeometry = PolyhedronGeometry;
  30437. exports.PositionalAudio = PositionalAudio;
  30438. exports.PropertyBinding = PropertyBinding;
  30439. exports.PropertyMixer = PropertyMixer;
  30440. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30441. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30442. exports.Quaternion = Quaternion;
  30443. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30444. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30445. exports.REVISION = REVISION;
  30446. exports.RGBADepthPacking = RGBADepthPacking;
  30447. exports.RGBAFormat = RGBAFormat;
  30448. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30449. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30450. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30451. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30452. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30453. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30454. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30455. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30456. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30457. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30458. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30459. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30460. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30461. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30462. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30463. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30464. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30465. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30466. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30467. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30468. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30469. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30470. exports.RGBDEncoding = RGBDEncoding;
  30471. exports.RGBEEncoding = RGBEEncoding;
  30472. exports.RGBEFormat = RGBEFormat;
  30473. exports.RGBFormat = RGBFormat;
  30474. exports.RGBIntegerFormat = RGBIntegerFormat;
  30475. exports.RGBM16Encoding = RGBM16Encoding;
  30476. exports.RGBM7Encoding = RGBM7Encoding;
  30477. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30478. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30479. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30480. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30481. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30482. exports.RGFormat = RGFormat;
  30483. exports.RGIntegerFormat = RGIntegerFormat;
  30484. exports.RawShaderMaterial = RawShaderMaterial;
  30485. exports.Ray = Ray;
  30486. exports.Raycaster = Raycaster;
  30487. exports.RectAreaLight = RectAreaLight;
  30488. exports.RedFormat = RedFormat;
  30489. exports.RedIntegerFormat = RedIntegerFormat;
  30490. exports.ReinhardToneMapping = ReinhardToneMapping;
  30491. exports.RepeatWrapping = RepeatWrapping;
  30492. exports.ReplaceStencilOp = ReplaceStencilOp;
  30493. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30494. exports.RingBufferGeometry = RingBufferGeometry;
  30495. exports.RingGeometry = RingGeometry;
  30496. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30497. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30498. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30499. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30500. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30501. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30502. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30503. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30504. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30505. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30506. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30507. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30508. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30509. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30510. exports.Scene = Scene;
  30511. exports.SceneUtils = SceneUtils;
  30512. exports.ShaderChunk = ShaderChunk;
  30513. exports.ShaderLib = ShaderLib;
  30514. exports.ShaderMaterial = ShaderMaterial;
  30515. exports.ShadowMaterial = ShadowMaterial;
  30516. exports.Shape = Shape;
  30517. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  30518. exports.ShapeGeometry = ShapeGeometry;
  30519. exports.ShapePath = ShapePath;
  30520. exports.ShapeUtils = ShapeUtils;
  30521. exports.ShortType = ShortType;
  30522. exports.Skeleton = Skeleton;
  30523. exports.SkeletonHelper = SkeletonHelper;
  30524. exports.SkinnedMesh = SkinnedMesh;
  30525. exports.SmoothShading = SmoothShading;
  30526. exports.Sphere = Sphere;
  30527. exports.SphereBufferGeometry = SphereBufferGeometry;
  30528. exports.SphereGeometry = SphereGeometry;
  30529. exports.Spherical = Spherical;
  30530. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30531. exports.Spline = Spline;
  30532. exports.SplineCurve = SplineCurve;
  30533. exports.SplineCurve3 = SplineCurve3;
  30534. exports.SpotLight = SpotLight;
  30535. exports.SpotLightHelper = SpotLightHelper;
  30536. exports.Sprite = Sprite;
  30537. exports.SpriteMaterial = SpriteMaterial;
  30538. exports.SrcAlphaFactor = SrcAlphaFactor;
  30539. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30540. exports.SrcColorFactor = SrcColorFactor;
  30541. exports.StaticCopyUsage = StaticCopyUsage;
  30542. exports.StaticDrawUsage = StaticDrawUsage;
  30543. exports.StaticReadUsage = StaticReadUsage;
  30544. exports.StereoCamera = StereoCamera;
  30545. exports.StreamCopyUsage = StreamCopyUsage;
  30546. exports.StreamDrawUsage = StreamDrawUsage;
  30547. exports.StreamReadUsage = StreamReadUsage;
  30548. exports.StringKeyframeTrack = StringKeyframeTrack;
  30549. exports.SubtractEquation = SubtractEquation;
  30550. exports.SubtractiveBlending = SubtractiveBlending;
  30551. exports.TOUCH = TOUCH;
  30552. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30553. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  30554. exports.TetrahedronGeometry = TetrahedronGeometry;
  30555. exports.TextBufferGeometry = TextBufferGeometry;
  30556. exports.TextGeometry = TextGeometry;
  30557. exports.Texture = Texture;
  30558. exports.TextureLoader = TextureLoader;
  30559. exports.TorusBufferGeometry = TorusBufferGeometry;
  30560. exports.TorusGeometry = TorusGeometry;
  30561. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  30562. exports.TorusKnotGeometry = TorusKnotGeometry;
  30563. exports.Triangle = Triangle;
  30564. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30565. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30566. exports.TrianglesDrawMode = TrianglesDrawMode;
  30567. exports.TubeBufferGeometry = TubeBufferGeometry;
  30568. exports.TubeGeometry = TubeGeometry;
  30569. exports.UVMapping = UVMapping;
  30570. exports.Uint16Attribute = Uint16Attribute;
  30571. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30572. exports.Uint32Attribute = Uint32Attribute;
  30573. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30574. exports.Uint8Attribute = Uint8Attribute;
  30575. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30576. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30577. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30578. exports.Uniform = Uniform;
  30579. exports.UniformsLib = UniformsLib;
  30580. exports.UniformsUtils = UniformsUtils;
  30581. exports.UnsignedByteType = UnsignedByteType;
  30582. exports.UnsignedInt248Type = UnsignedInt248Type;
  30583. exports.UnsignedIntType = UnsignedIntType;
  30584. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30585. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30586. exports.UnsignedShort565Type = UnsignedShort565Type;
  30587. exports.UnsignedShortType = UnsignedShortType;
  30588. exports.VSMShadowMap = VSMShadowMap;
  30589. exports.Vector2 = Vector2;
  30590. exports.Vector3 = Vector3;
  30591. exports.Vector4 = Vector4;
  30592. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30593. exports.Vertex = Vertex;
  30594. exports.VertexColors = VertexColors;
  30595. exports.VideoTexture = VideoTexture;
  30596. exports.WebGL1Renderer = WebGL1Renderer;
  30597. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30598. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30599. exports.WebGLRenderTarget = WebGLRenderTarget;
  30600. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30601. exports.WebGLRenderer = WebGLRenderer;
  30602. exports.WebGLUtils = WebGLUtils;
  30603. exports.WireframeGeometry = WireframeGeometry;
  30604. exports.WireframeHelper = WireframeHelper;
  30605. exports.WrapAroundEnding = WrapAroundEnding;
  30606. exports.XHRLoader = XHRLoader;
  30607. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30608. exports.ZeroFactor = ZeroFactor;
  30609. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30610. exports.ZeroStencilOp = ZeroStencilOp;
  30611. exports.sRGBEncoding = sRGBEncoding;
  30612. Object.defineProperty(exports, '__esModule', { value: true });
  30613. })));
粤ICP备19079148号