three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.THREE = {}));
  5. }(this, (function (exports) { 'use strict';
  6. // Polyfills
  7. if ( Number.EPSILON === undefined ) {
  8. Number.EPSILON = Math.pow( 2, - 52 );
  9. }
  10. if ( Number.isInteger === undefined ) {
  11. // Missing in IE
  12. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  13. Number.isInteger = function ( value ) {
  14. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  15. };
  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 () {
  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 = '118';
  55. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  56. var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  57. var CullFaceNone = 0;
  58. var CullFaceBack = 1;
  59. var CullFaceFront = 2;
  60. var CullFaceFrontBack = 3;
  61. var FrontFaceDirectionCW = 0;
  62. var FrontFaceDirectionCCW = 1;
  63. var BasicShadowMap = 0;
  64. var PCFShadowMap = 1;
  65. var PCFSoftShadowMap = 2;
  66. var VSMShadowMap = 3;
  67. var FrontSide = 0;
  68. var BackSide = 1;
  69. var DoubleSide = 2;
  70. var FlatShading = 1;
  71. var SmoothShading = 2;
  72. var NoBlending = 0;
  73. var NormalBlending = 1;
  74. var AdditiveBlending = 2;
  75. var SubtractiveBlending = 3;
  76. var MultiplyBlending = 4;
  77. var CustomBlending = 5;
  78. var AddEquation = 100;
  79. var SubtractEquation = 101;
  80. var ReverseSubtractEquation = 102;
  81. var MinEquation = 103;
  82. var MaxEquation = 104;
  83. var ZeroFactor = 200;
  84. var OneFactor = 201;
  85. var SrcColorFactor = 202;
  86. var OneMinusSrcColorFactor = 203;
  87. var SrcAlphaFactor = 204;
  88. var OneMinusSrcAlphaFactor = 205;
  89. var DstAlphaFactor = 206;
  90. var OneMinusDstAlphaFactor = 207;
  91. var DstColorFactor = 208;
  92. var OneMinusDstColorFactor = 209;
  93. var SrcAlphaSaturateFactor = 210;
  94. var NeverDepth = 0;
  95. var AlwaysDepth = 1;
  96. var LessDepth = 2;
  97. var LessEqualDepth = 3;
  98. var EqualDepth = 4;
  99. var GreaterEqualDepth = 5;
  100. var GreaterDepth = 6;
  101. var NotEqualDepth = 7;
  102. var MultiplyOperation = 0;
  103. var MixOperation = 1;
  104. var AddOperation = 2;
  105. var NoToneMapping = 0;
  106. var LinearToneMapping = 1;
  107. var ReinhardToneMapping = 2;
  108. var CineonToneMapping = 3;
  109. var ACESFilmicToneMapping = 4;
  110. var CustomToneMapping = 5;
  111. var UVMapping = 300;
  112. var CubeReflectionMapping = 301;
  113. var CubeRefractionMapping = 302;
  114. var EquirectangularReflectionMapping = 303;
  115. var EquirectangularRefractionMapping = 304;
  116. var CubeUVReflectionMapping = 306;
  117. var CubeUVRefractionMapping = 307;
  118. var RepeatWrapping = 1000;
  119. var ClampToEdgeWrapping = 1001;
  120. var MirroredRepeatWrapping = 1002;
  121. var NearestFilter = 1003;
  122. var NearestMipmapNearestFilter = 1004;
  123. var NearestMipMapNearestFilter = 1004;
  124. var NearestMipmapLinearFilter = 1005;
  125. var NearestMipMapLinearFilter = 1005;
  126. var LinearFilter = 1006;
  127. var LinearMipmapNearestFilter = 1007;
  128. var LinearMipMapNearestFilter = 1007;
  129. var LinearMipmapLinearFilter = 1008;
  130. var LinearMipMapLinearFilter = 1008;
  131. var UnsignedByteType = 1009;
  132. var ByteType = 1010;
  133. var ShortType = 1011;
  134. var UnsignedShortType = 1012;
  135. var IntType = 1013;
  136. var UnsignedIntType = 1014;
  137. var FloatType = 1015;
  138. var HalfFloatType = 1016;
  139. var UnsignedShort4444Type = 1017;
  140. var UnsignedShort5551Type = 1018;
  141. var UnsignedShort565Type = 1019;
  142. var UnsignedInt248Type = 1020;
  143. var AlphaFormat = 1021;
  144. var RGBFormat = 1022;
  145. var RGBAFormat = 1023;
  146. var LuminanceFormat = 1024;
  147. var LuminanceAlphaFormat = 1025;
  148. var RGBEFormat = RGBAFormat;
  149. var DepthFormat = 1026;
  150. var DepthStencilFormat = 1027;
  151. var RedFormat = 1028;
  152. var RedIntegerFormat = 1029;
  153. var RGFormat = 1030;
  154. var RGIntegerFormat = 1031;
  155. var RGBIntegerFormat = 1032;
  156. var RGBAIntegerFormat = 1033;
  157. var RGB_S3TC_DXT1_Format = 33776;
  158. var RGBA_S3TC_DXT1_Format = 33777;
  159. var RGBA_S3TC_DXT3_Format = 33778;
  160. var RGBA_S3TC_DXT5_Format = 33779;
  161. var RGB_PVRTC_4BPPV1_Format = 35840;
  162. var RGB_PVRTC_2BPPV1_Format = 35841;
  163. var RGBA_PVRTC_4BPPV1_Format = 35842;
  164. var RGBA_PVRTC_2BPPV1_Format = 35843;
  165. var RGB_ETC1_Format = 36196;
  166. var RGB_ETC2_Format = 37492;
  167. var RGBA_ETC2_EAC_Format = 37496;
  168. var RGBA_ASTC_4x4_Format = 37808;
  169. var RGBA_ASTC_5x4_Format = 37809;
  170. var RGBA_ASTC_5x5_Format = 37810;
  171. var RGBA_ASTC_6x5_Format = 37811;
  172. var RGBA_ASTC_6x6_Format = 37812;
  173. var RGBA_ASTC_8x5_Format = 37813;
  174. var RGBA_ASTC_8x6_Format = 37814;
  175. var RGBA_ASTC_8x8_Format = 37815;
  176. var RGBA_ASTC_10x5_Format = 37816;
  177. var RGBA_ASTC_10x6_Format = 37817;
  178. var RGBA_ASTC_10x8_Format = 37818;
  179. var RGBA_ASTC_10x10_Format = 37819;
  180. var RGBA_ASTC_12x10_Format = 37820;
  181. var RGBA_ASTC_12x12_Format = 37821;
  182. var RGBA_BPTC_Format = 36492;
  183. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  184. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  185. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  186. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  187. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  188. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  189. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  190. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  191. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  192. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  193. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  194. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  195. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  196. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  197. var LoopOnce = 2200;
  198. var LoopRepeat = 2201;
  199. var LoopPingPong = 2202;
  200. var InterpolateDiscrete = 2300;
  201. var InterpolateLinear = 2301;
  202. var InterpolateSmooth = 2302;
  203. var ZeroCurvatureEnding = 2400;
  204. var ZeroSlopeEnding = 2401;
  205. var WrapAroundEnding = 2402;
  206. var NormalAnimationBlendMode = 2500;
  207. var AdditiveAnimationBlendMode = 2501;
  208. var TrianglesDrawMode = 0;
  209. var TriangleStripDrawMode = 1;
  210. var TriangleFanDrawMode = 2;
  211. var LinearEncoding = 3000;
  212. var sRGBEncoding = 3001;
  213. var GammaEncoding = 3007;
  214. var RGBEEncoding = 3002;
  215. var LogLuvEncoding = 3003;
  216. var RGBM7Encoding = 3004;
  217. var RGBM16Encoding = 3005;
  218. var RGBDEncoding = 3006;
  219. var BasicDepthPacking = 3200;
  220. var RGBADepthPacking = 3201;
  221. var TangentSpaceNormalMap = 0;
  222. var ObjectSpaceNormalMap = 1;
  223. var ZeroStencilOp = 0;
  224. var KeepStencilOp = 7680;
  225. var ReplaceStencilOp = 7681;
  226. var IncrementStencilOp = 7682;
  227. var DecrementStencilOp = 7683;
  228. var IncrementWrapStencilOp = 34055;
  229. var DecrementWrapStencilOp = 34056;
  230. var InvertStencilOp = 5386;
  231. var NeverStencilFunc = 512;
  232. var LessStencilFunc = 513;
  233. var EqualStencilFunc = 514;
  234. var LessEqualStencilFunc = 515;
  235. var GreaterStencilFunc = 516;
  236. var NotEqualStencilFunc = 517;
  237. var GreaterEqualStencilFunc = 518;
  238. var AlwaysStencilFunc = 519;
  239. var StaticDrawUsage = 35044;
  240. var DynamicDrawUsage = 35048;
  241. var StreamDrawUsage = 35040;
  242. var StaticReadUsage = 35045;
  243. var DynamicReadUsage = 35049;
  244. var StreamReadUsage = 35041;
  245. var StaticCopyUsage = 35046;
  246. var DynamicCopyUsage = 35050;
  247. var StreamCopyUsage = 35042;
  248. /**
  249. * https://github.com/mrdoob/eventdispatcher.js/
  250. */
  251. function EventDispatcher() {}
  252. Object.assign( EventDispatcher.prototype, {
  253. addEventListener: function ( type, listener ) {
  254. if ( this._listeners === undefined ) { this._listeners = {}; }
  255. var listeners = this._listeners;
  256. if ( listeners[ type ] === undefined ) {
  257. listeners[ type ] = [];
  258. }
  259. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  260. listeners[ type ].push( listener );
  261. }
  262. },
  263. hasEventListener: function ( type, listener ) {
  264. if ( this._listeners === undefined ) { return false; }
  265. var listeners = this._listeners;
  266. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  267. },
  268. removeEventListener: function ( type, listener ) {
  269. if ( this._listeners === undefined ) { return; }
  270. var listeners = this._listeners;
  271. var listenerArray = listeners[ type ];
  272. if ( listenerArray !== undefined ) {
  273. var index = listenerArray.indexOf( listener );
  274. if ( index !== - 1 ) {
  275. listenerArray.splice( index, 1 );
  276. }
  277. }
  278. },
  279. dispatchEvent: function ( event ) {
  280. if ( this._listeners === undefined ) { return; }
  281. var listeners = this._listeners;
  282. var listenerArray = listeners[ event.type ];
  283. if ( listenerArray !== undefined ) {
  284. event.target = this;
  285. // Make a copy, in case listeners are removed while iterating.
  286. var array = listenerArray.slice( 0 );
  287. for ( var i = 0, l = array.length; i < l; i ++ ) {
  288. array[ i ].call( this, event );
  289. }
  290. }
  291. }
  292. } );
  293. /**
  294. * @author alteredq / http://alteredqualia.com/
  295. * @author mrdoob / http://mrdoob.com/
  296. * @author WestLangley / http://github.com/WestLangley
  297. * @author thezwap
  298. */
  299. var _lut = [];
  300. for ( var i = 0; i < 256; i ++ ) {
  301. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  302. }
  303. var MathUtils = {
  304. DEG2RAD: Math.PI / 180,
  305. RAD2DEG: 180 / Math.PI,
  306. generateUUID: function () {
  307. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  308. var d0 = Math.random() * 0xffffffff | 0;
  309. var d1 = Math.random() * 0xffffffff | 0;
  310. var d2 = Math.random() * 0xffffffff | 0;
  311. var d3 = Math.random() * 0xffffffff | 0;
  312. var uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  313. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  314. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  315. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  316. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  317. return uuid.toUpperCase();
  318. },
  319. clamp: function ( value, min, max ) {
  320. return Math.max( min, Math.min( max, value ) );
  321. },
  322. // compute euclidian modulo of m % n
  323. // https://en.wikipedia.org/wiki/Modulo_operation
  324. euclideanModulo: function ( n, m ) {
  325. return ( ( n % m ) + m ) % m;
  326. },
  327. // Linear mapping from range <a1, a2> to range <b1, b2>
  328. mapLinear: function ( x, a1, a2, b1, b2 ) {
  329. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  330. },
  331. // https://en.wikipedia.org/wiki/Linear_interpolation
  332. lerp: function ( x, y, t ) {
  333. return ( 1 - t ) * x + t * y;
  334. },
  335. // http://en.wikipedia.org/wiki/Smoothstep
  336. smoothstep: function ( x, min, max ) {
  337. if ( x <= min ) { return 0; }
  338. if ( x >= max ) { return 1; }
  339. x = ( x - min ) / ( max - min );
  340. return x * x * ( 3 - 2 * x );
  341. },
  342. smootherstep: function ( x, min, max ) {
  343. if ( x <= min ) { return 0; }
  344. if ( x >= max ) { return 1; }
  345. x = ( x - min ) / ( max - min );
  346. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  347. },
  348. // Random integer from <low, high> interval
  349. randInt: function ( low, high ) {
  350. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  351. },
  352. // Random float from <low, high> interval
  353. randFloat: function ( low, high ) {
  354. return low + Math.random() * ( high - low );
  355. },
  356. // Random float from <-range/2, range/2> interval
  357. randFloatSpread: function ( range ) {
  358. return range * ( 0.5 - Math.random() );
  359. },
  360. degToRad: function ( degrees ) {
  361. return degrees * MathUtils.DEG2RAD;
  362. },
  363. radToDeg: function ( radians ) {
  364. return radians * MathUtils.RAD2DEG;
  365. },
  366. isPowerOfTwo: function ( value ) {
  367. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  368. },
  369. ceilPowerOfTwo: function ( value ) {
  370. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  371. },
  372. floorPowerOfTwo: function ( value ) {
  373. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  374. },
  375. setQuaternionFromProperEuler: function ( q, a, b, c, order ) {
  376. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  377. // rotations are applied to the axes in the order specified by 'order'
  378. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  379. // angles are in radians
  380. var cos = Math.cos;
  381. var sin = Math.sin;
  382. var c2 = cos( b / 2 );
  383. var s2 = sin( b / 2 );
  384. var c13 = cos( ( a + c ) / 2 );
  385. var s13 = sin( ( a + c ) / 2 );
  386. var c1_3 = cos( ( a - c ) / 2 );
  387. var s1_3 = sin( ( a - c ) / 2 );
  388. var c3_1 = cos( ( c - a ) / 2 );
  389. var s3_1 = sin( ( c - a ) / 2 );
  390. switch ( order ) {
  391. case 'XYX':
  392. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  393. break;
  394. case 'YZY':
  395. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  396. break;
  397. case 'ZXZ':
  398. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  399. break;
  400. case 'XZX':
  401. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  402. break;
  403. case 'YXY':
  404. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  405. break;
  406. case 'ZYZ':
  407. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  408. break;
  409. default:
  410. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  411. }
  412. }
  413. };
  414. /**
  415. * @author mrdoob / http://mrdoob.com/
  416. * @author philogb / http://blog.thejit.org/
  417. * @author egraether / http://egraether.com/
  418. * @author zz85 / http://www.lab4games.net/zz85/blog
  419. */
  420. function Vector2( x, y ) {
  421. if ( x === void 0 ) x = 0;
  422. if ( y === void 0 ) y = 0;
  423. this.x = x;
  424. this.y = y;
  425. }
  426. Object.defineProperties( Vector2.prototype, {
  427. "width": {
  428. get: function () {
  429. return this.x;
  430. },
  431. set: function ( value ) {
  432. this.x = value;
  433. }
  434. },
  435. "height": {
  436. get: function () {
  437. return this.y;
  438. },
  439. set: function ( value ) {
  440. this.y = value;
  441. }
  442. }
  443. } );
  444. Object.assign( Vector2.prototype, {
  445. isVector2: true,
  446. set: function ( x, y ) {
  447. this.x = x;
  448. this.y = y;
  449. return this;
  450. },
  451. setScalar: function ( scalar ) {
  452. this.x = scalar;
  453. this.y = scalar;
  454. return this;
  455. },
  456. setX: function ( x ) {
  457. this.x = x;
  458. return this;
  459. },
  460. setY: function ( y ) {
  461. this.y = y;
  462. return this;
  463. },
  464. setComponent: function ( index, value ) {
  465. switch ( index ) {
  466. case 0: this.x = value; break;
  467. case 1: this.y = value; break;
  468. default: throw new Error( 'index is out of range: ' + index );
  469. }
  470. return this;
  471. },
  472. getComponent: function ( index ) {
  473. switch ( index ) {
  474. case 0: return this.x;
  475. case 1: return this.y;
  476. default: throw new Error( 'index is out of range: ' + index );
  477. }
  478. },
  479. clone: function () {
  480. return new this.constructor( this.x, this.y );
  481. },
  482. copy: function ( v ) {
  483. this.x = v.x;
  484. this.y = v.y;
  485. return this;
  486. },
  487. add: function ( v, w ) {
  488. if ( w !== undefined ) {
  489. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  490. return this.addVectors( v, w );
  491. }
  492. this.x += v.x;
  493. this.y += v.y;
  494. return this;
  495. },
  496. addScalar: function ( s ) {
  497. this.x += s;
  498. this.y += s;
  499. return this;
  500. },
  501. addVectors: function ( a, b ) {
  502. this.x = a.x + b.x;
  503. this.y = a.y + b.y;
  504. return this;
  505. },
  506. addScaledVector: function ( v, s ) {
  507. this.x += v.x * s;
  508. this.y += v.y * s;
  509. return this;
  510. },
  511. sub: function ( v, w ) {
  512. if ( w !== undefined ) {
  513. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  514. return this.subVectors( v, w );
  515. }
  516. this.x -= v.x;
  517. this.y -= v.y;
  518. return this;
  519. },
  520. subScalar: function ( s ) {
  521. this.x -= s;
  522. this.y -= s;
  523. return this;
  524. },
  525. subVectors: function ( a, b ) {
  526. this.x = a.x - b.x;
  527. this.y = a.y - b.y;
  528. return this;
  529. },
  530. multiply: function ( v ) {
  531. this.x *= v.x;
  532. this.y *= v.y;
  533. return this;
  534. },
  535. multiplyScalar: function ( scalar ) {
  536. this.x *= scalar;
  537. this.y *= scalar;
  538. return this;
  539. },
  540. divide: function ( v ) {
  541. this.x /= v.x;
  542. this.y /= v.y;
  543. return this;
  544. },
  545. divideScalar: function ( scalar ) {
  546. return this.multiplyScalar( 1 / scalar );
  547. },
  548. applyMatrix3: function ( m ) {
  549. var x = this.x, y = this.y;
  550. var e = m.elements;
  551. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  552. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  553. return this;
  554. },
  555. min: function ( v ) {
  556. this.x = Math.min( this.x, v.x );
  557. this.y = Math.min( this.y, v.y );
  558. return this;
  559. },
  560. max: function ( v ) {
  561. this.x = Math.max( this.x, v.x );
  562. this.y = Math.max( this.y, v.y );
  563. return this;
  564. },
  565. clamp: function ( min, max ) {
  566. // assumes min < max, componentwise
  567. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  568. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  569. return this;
  570. },
  571. clampScalar: function ( minVal, maxVal ) {
  572. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  573. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  574. return this;
  575. },
  576. clampLength: function ( min, max ) {
  577. var length = this.length();
  578. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  579. },
  580. floor: function () {
  581. this.x = Math.floor( this.x );
  582. this.y = Math.floor( this.y );
  583. return this;
  584. },
  585. ceil: function () {
  586. this.x = Math.ceil( this.x );
  587. this.y = Math.ceil( this.y );
  588. return this;
  589. },
  590. round: function () {
  591. this.x = Math.round( this.x );
  592. this.y = Math.round( this.y );
  593. return this;
  594. },
  595. roundToZero: function () {
  596. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  597. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  598. return this;
  599. },
  600. negate: function () {
  601. this.x = - this.x;
  602. this.y = - this.y;
  603. return this;
  604. },
  605. dot: function ( v ) {
  606. return this.x * v.x + this.y * v.y;
  607. },
  608. cross: function ( v ) {
  609. return this.x * v.y - this.y * v.x;
  610. },
  611. lengthSq: function () {
  612. return this.x * this.x + this.y * this.y;
  613. },
  614. length: function () {
  615. return Math.sqrt( this.x * this.x + this.y * this.y );
  616. },
  617. manhattanLength: function () {
  618. return Math.abs( this.x ) + Math.abs( this.y );
  619. },
  620. normalize: function () {
  621. return this.divideScalar( this.length() || 1 );
  622. },
  623. angle: function () {
  624. // computes the angle in radians with respect to the positive x-axis
  625. var angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  626. return angle;
  627. },
  628. distanceTo: function ( v ) {
  629. return Math.sqrt( this.distanceToSquared( v ) );
  630. },
  631. distanceToSquared: function ( v ) {
  632. var dx = this.x - v.x, dy = this.y - v.y;
  633. return dx * dx + dy * dy;
  634. },
  635. manhattanDistanceTo: function ( v ) {
  636. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  637. },
  638. setLength: function ( length ) {
  639. return this.normalize().multiplyScalar( length );
  640. },
  641. lerp: function ( v, alpha ) {
  642. this.x += ( v.x - this.x ) * alpha;
  643. this.y += ( v.y - this.y ) * alpha;
  644. return this;
  645. },
  646. lerpVectors: function ( v1, v2, alpha ) {
  647. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  648. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  649. return this;
  650. },
  651. equals: function ( v ) {
  652. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  653. },
  654. fromArray: function ( array, offset ) {
  655. if ( offset === undefined ) { offset = 0; }
  656. this.x = array[ offset ];
  657. this.y = array[ offset + 1 ];
  658. return this;
  659. },
  660. toArray: function ( array, offset ) {
  661. if ( array === undefined ) { array = []; }
  662. if ( offset === undefined ) { offset = 0; }
  663. array[ offset ] = this.x;
  664. array[ offset + 1 ] = this.y;
  665. return array;
  666. },
  667. fromBufferAttribute: function ( attribute, index, offset ) {
  668. if ( offset !== undefined ) {
  669. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  670. }
  671. this.x = attribute.getX( index );
  672. this.y = attribute.getY( index );
  673. return this;
  674. },
  675. rotateAround: function ( center, angle ) {
  676. var c = Math.cos( angle ), s = Math.sin( angle );
  677. var x = this.x - center.x;
  678. var y = this.y - center.y;
  679. this.x = x * c - y * s + center.x;
  680. this.y = x * s + y * c + center.y;
  681. return this;
  682. },
  683. random: function () {
  684. this.x = Math.random();
  685. this.y = Math.random();
  686. return this;
  687. }
  688. } );
  689. /**
  690. * @author alteredq / http://alteredqualia.com/
  691. * @author WestLangley / http://github.com/WestLangley
  692. * @author bhouston / http://clara.io
  693. * @author tschw
  694. */
  695. function Matrix3() {
  696. this.elements = [
  697. 1, 0, 0,
  698. 0, 1, 0,
  699. 0, 0, 1
  700. ];
  701. if ( arguments.length > 0 ) {
  702. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  703. }
  704. }
  705. Object.assign( Matrix3.prototype, {
  706. isMatrix3: true,
  707. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  708. var te = this.elements;
  709. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  710. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  711. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  712. return this;
  713. },
  714. identity: function () {
  715. this.set(
  716. 1, 0, 0,
  717. 0, 1, 0,
  718. 0, 0, 1
  719. );
  720. return this;
  721. },
  722. clone: function () {
  723. return new this.constructor().fromArray( this.elements );
  724. },
  725. copy: function ( m ) {
  726. var te = this.elements;
  727. var me = m.elements;
  728. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  729. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  730. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  731. return this;
  732. },
  733. extractBasis: function ( xAxis, yAxis, zAxis ) {
  734. xAxis.setFromMatrix3Column( this, 0 );
  735. yAxis.setFromMatrix3Column( this, 1 );
  736. zAxis.setFromMatrix3Column( this, 2 );
  737. return this;
  738. },
  739. setFromMatrix4: function ( m ) {
  740. var me = m.elements;
  741. this.set(
  742. me[ 0 ], me[ 4 ], me[ 8 ],
  743. me[ 1 ], me[ 5 ], me[ 9 ],
  744. me[ 2 ], me[ 6 ], me[ 10 ]
  745. );
  746. return this;
  747. },
  748. multiply: function ( m ) {
  749. return this.multiplyMatrices( this, m );
  750. },
  751. premultiply: function ( m ) {
  752. return this.multiplyMatrices( m, this );
  753. },
  754. multiplyMatrices: function ( a, b ) {
  755. var ae = a.elements;
  756. var be = b.elements;
  757. var te = this.elements;
  758. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  759. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  760. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  761. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  762. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  763. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  764. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  765. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  766. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  767. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  768. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  769. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  770. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  771. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  772. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  773. return this;
  774. },
  775. multiplyScalar: function ( s ) {
  776. var te = this.elements;
  777. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  778. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  779. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  780. return this;
  781. },
  782. determinant: function () {
  783. var te = this.elements;
  784. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  785. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  786. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  787. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  788. },
  789. getInverse: function ( matrix, throwOnDegenerate ) {
  790. if ( throwOnDegenerate !== undefined ) {
  791. console.warn( "THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate." );
  792. }
  793. var me = matrix.elements,
  794. te = this.elements,
  795. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  796. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  797. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  798. t11 = n33 * n22 - n32 * n23,
  799. t12 = n32 * n13 - n33 * n12,
  800. t13 = n23 * n12 - n22 * n13,
  801. det = n11 * t11 + n21 * t12 + n31 * t13;
  802. if ( det === 0 ) { return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); }
  803. var detInv = 1 / det;
  804. te[ 0 ] = t11 * detInv;
  805. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  806. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  807. te[ 3 ] = t12 * detInv;
  808. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  809. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  810. te[ 6 ] = t13 * detInv;
  811. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  812. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  813. return this;
  814. },
  815. transpose: function () {
  816. var tmp;
  817. var m = this.elements;
  818. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  819. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  820. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  821. return this;
  822. },
  823. getNormalMatrix: function ( matrix4 ) {
  824. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  825. },
  826. transposeIntoArray: function ( r ) {
  827. var m = this.elements;
  828. r[ 0 ] = m[ 0 ];
  829. r[ 1 ] = m[ 3 ];
  830. r[ 2 ] = m[ 6 ];
  831. r[ 3 ] = m[ 1 ];
  832. r[ 4 ] = m[ 4 ];
  833. r[ 5 ] = m[ 7 ];
  834. r[ 6 ] = m[ 2 ];
  835. r[ 7 ] = m[ 5 ];
  836. r[ 8 ] = m[ 8 ];
  837. return this;
  838. },
  839. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  840. var c = Math.cos( rotation );
  841. var s = Math.sin( rotation );
  842. this.set(
  843. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  844. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  845. 0, 0, 1
  846. );
  847. },
  848. scale: function ( sx, sy ) {
  849. var te = this.elements;
  850. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  851. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  852. return this;
  853. },
  854. rotate: function ( theta ) {
  855. var c = Math.cos( theta );
  856. var s = Math.sin( theta );
  857. var te = this.elements;
  858. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  859. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  860. te[ 0 ] = c * a11 + s * a21;
  861. te[ 3 ] = c * a12 + s * a22;
  862. te[ 6 ] = c * a13 + s * a23;
  863. te[ 1 ] = - s * a11 + c * a21;
  864. te[ 4 ] = - s * a12 + c * a22;
  865. te[ 7 ] = - s * a13 + c * a23;
  866. return this;
  867. },
  868. translate: function ( tx, ty ) {
  869. var te = this.elements;
  870. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  871. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  872. return this;
  873. },
  874. equals: function ( matrix ) {
  875. var te = this.elements;
  876. var me = matrix.elements;
  877. for ( var i = 0; i < 9; i ++ ) {
  878. if ( te[ i ] !== me[ i ] ) { return false; }
  879. }
  880. return true;
  881. },
  882. fromArray: function ( array, offset ) {
  883. if ( offset === undefined ) { offset = 0; }
  884. for ( var i = 0; i < 9; i ++ ) {
  885. this.elements[ i ] = array[ i + offset ];
  886. }
  887. return this;
  888. },
  889. toArray: function ( array, offset ) {
  890. if ( array === undefined ) { array = []; }
  891. if ( offset === undefined ) { offset = 0; }
  892. var te = this.elements;
  893. array[ offset ] = te[ 0 ];
  894. array[ offset + 1 ] = te[ 1 ];
  895. array[ offset + 2 ] = te[ 2 ];
  896. array[ offset + 3 ] = te[ 3 ];
  897. array[ offset + 4 ] = te[ 4 ];
  898. array[ offset + 5 ] = te[ 5 ];
  899. array[ offset + 6 ] = te[ 6 ];
  900. array[ offset + 7 ] = te[ 7 ];
  901. array[ offset + 8 ] = te[ 8 ];
  902. return array;
  903. }
  904. } );
  905. /**
  906. * @author mrdoob / http://mrdoob.com/
  907. * @author alteredq / http://alteredqualia.com/
  908. * @author szimek / https://github.com/szimek/
  909. */
  910. var _canvas;
  911. var ImageUtils = {
  912. getDataURL: function ( image ) {
  913. if ( /^data:/i.test( image.src ) ) {
  914. return image.src;
  915. }
  916. if ( typeof HTMLCanvasElement == 'undefined' ) {
  917. return image.src;
  918. }
  919. var canvas;
  920. if ( image instanceof HTMLCanvasElement ) {
  921. canvas = image;
  922. } else {
  923. if ( _canvas === undefined ) { _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); }
  924. _canvas.width = image.width;
  925. _canvas.height = image.height;
  926. var context = _canvas.getContext( '2d' );
  927. if ( image instanceof ImageData ) {
  928. context.putImageData( image, 0, 0 );
  929. } else {
  930. context.drawImage( image, 0, 0, image.width, image.height );
  931. }
  932. canvas = _canvas;
  933. }
  934. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  935. return canvas.toDataURL( 'image/jpeg', 0.6 );
  936. } else {
  937. return canvas.toDataURL( 'image/png' );
  938. }
  939. }
  940. };
  941. /**
  942. * @author mrdoob / http://mrdoob.com/
  943. * @author alteredq / http://alteredqualia.com/
  944. * @author szimek / https://github.com/szimek/
  945. */
  946. var textureId = 0;
  947. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  948. Object.defineProperty( this, 'id', { value: textureId ++ } );
  949. this.uuid = MathUtils.generateUUID();
  950. this.name = '';
  951. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  952. this.mipmaps = [];
  953. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  954. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  955. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  956. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  957. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  958. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  959. this.format = format !== undefined ? format : RGBAFormat;
  960. this.internalFormat = null;
  961. this.type = type !== undefined ? type : UnsignedByteType;
  962. this.offset = new Vector2( 0, 0 );
  963. this.repeat = new Vector2( 1, 1 );
  964. this.center = new Vector2( 0, 0 );
  965. this.rotation = 0;
  966. this.matrixAutoUpdate = true;
  967. this.matrix = new Matrix3();
  968. this.generateMipmaps = true;
  969. this.premultiplyAlpha = false;
  970. this.flipY = true;
  971. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  972. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  973. //
  974. // Also changing the encoding after already used by a Material will not automatically make the Material
  975. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  976. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  977. this.version = 0;
  978. this.onUpdate = null;
  979. }
  980. Texture.DEFAULT_IMAGE = undefined;
  981. Texture.DEFAULT_MAPPING = UVMapping;
  982. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  983. constructor: Texture,
  984. isTexture: true,
  985. updateMatrix: function () {
  986. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  987. },
  988. clone: function () {
  989. return new this.constructor().copy( this );
  990. },
  991. copy: function ( source ) {
  992. this.name = source.name;
  993. this.image = source.image;
  994. this.mipmaps = source.mipmaps.slice( 0 );
  995. this.mapping = source.mapping;
  996. this.wrapS = source.wrapS;
  997. this.wrapT = source.wrapT;
  998. this.magFilter = source.magFilter;
  999. this.minFilter = source.minFilter;
  1000. this.anisotropy = source.anisotropy;
  1001. this.format = source.format;
  1002. this.internalFormat = source.internalFormat;
  1003. this.type = source.type;
  1004. this.offset.copy( source.offset );
  1005. this.repeat.copy( source.repeat );
  1006. this.center.copy( source.center );
  1007. this.rotation = source.rotation;
  1008. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1009. this.matrix.copy( source.matrix );
  1010. this.generateMipmaps = source.generateMipmaps;
  1011. this.premultiplyAlpha = source.premultiplyAlpha;
  1012. this.flipY = source.flipY;
  1013. this.unpackAlignment = source.unpackAlignment;
  1014. this.encoding = source.encoding;
  1015. return this;
  1016. },
  1017. toJSON: function ( meta ) {
  1018. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1019. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1020. return meta.textures[ this.uuid ];
  1021. }
  1022. var output = {
  1023. metadata: {
  1024. version: 4.5,
  1025. type: 'Texture',
  1026. generator: 'Texture.toJSON'
  1027. },
  1028. uuid: this.uuid,
  1029. name: this.name,
  1030. mapping: this.mapping,
  1031. repeat: [ this.repeat.x, this.repeat.y ],
  1032. offset: [ this.offset.x, this.offset.y ],
  1033. center: [ this.center.x, this.center.y ],
  1034. rotation: this.rotation,
  1035. wrap: [ this.wrapS, this.wrapT ],
  1036. format: this.format,
  1037. type: this.type,
  1038. encoding: this.encoding,
  1039. minFilter: this.minFilter,
  1040. magFilter: this.magFilter,
  1041. anisotropy: this.anisotropy,
  1042. flipY: this.flipY,
  1043. premultiplyAlpha: this.premultiplyAlpha,
  1044. unpackAlignment: this.unpackAlignment
  1045. };
  1046. if ( this.image !== undefined ) {
  1047. // TODO: Move to THREE.Image
  1048. var image = this.image;
  1049. if ( image.uuid === undefined ) {
  1050. image.uuid = MathUtils.generateUUID(); // UGH
  1051. }
  1052. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1053. var url;
  1054. if ( Array.isArray( image ) ) {
  1055. // process array of images e.g. CubeTexture
  1056. url = [];
  1057. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1058. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1059. }
  1060. } else {
  1061. // process single image
  1062. url = ImageUtils.getDataURL( image );
  1063. }
  1064. meta.images[ image.uuid ] = {
  1065. uuid: image.uuid,
  1066. url: url
  1067. };
  1068. }
  1069. output.image = image.uuid;
  1070. }
  1071. if ( ! isRootObject ) {
  1072. meta.textures[ this.uuid ] = output;
  1073. }
  1074. return output;
  1075. },
  1076. dispose: function () {
  1077. this.dispatchEvent( { type: 'dispose' } );
  1078. },
  1079. transformUv: function ( uv ) {
  1080. if ( this.mapping !== UVMapping ) { return uv; }
  1081. uv.applyMatrix3( this.matrix );
  1082. if ( uv.x < 0 || uv.x > 1 ) {
  1083. switch ( this.wrapS ) {
  1084. case RepeatWrapping:
  1085. uv.x = uv.x - Math.floor( uv.x );
  1086. break;
  1087. case ClampToEdgeWrapping:
  1088. uv.x = uv.x < 0 ? 0 : 1;
  1089. break;
  1090. case MirroredRepeatWrapping:
  1091. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1092. uv.x = Math.ceil( uv.x ) - uv.x;
  1093. } else {
  1094. uv.x = uv.x - Math.floor( uv.x );
  1095. }
  1096. break;
  1097. }
  1098. }
  1099. if ( uv.y < 0 || uv.y > 1 ) {
  1100. switch ( this.wrapT ) {
  1101. case RepeatWrapping:
  1102. uv.y = uv.y - Math.floor( uv.y );
  1103. break;
  1104. case ClampToEdgeWrapping:
  1105. uv.y = uv.y < 0 ? 0 : 1;
  1106. break;
  1107. case MirroredRepeatWrapping:
  1108. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1109. uv.y = Math.ceil( uv.y ) - uv.y;
  1110. } else {
  1111. uv.y = uv.y - Math.floor( uv.y );
  1112. }
  1113. break;
  1114. }
  1115. }
  1116. if ( this.flipY ) {
  1117. uv.y = 1 - uv.y;
  1118. }
  1119. return uv;
  1120. }
  1121. } );
  1122. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1123. set: function ( value ) {
  1124. if ( value === true ) { this.version ++; }
  1125. }
  1126. } );
  1127. /**
  1128. * @author supereggbert / http://www.paulbrunt.co.uk/
  1129. * @author philogb / http://blog.thejit.org/
  1130. * @author mikael emtinger / http://gomo.se/
  1131. * @author egraether / http://egraether.com/
  1132. * @author WestLangley / http://github.com/WestLangley
  1133. */
  1134. function Vector4( x, y, z, w ) {
  1135. if ( x === void 0 ) x = 0;
  1136. if ( y === void 0 ) y = 0;
  1137. if ( z === void 0 ) z = 0;
  1138. if ( w === void 0 ) w = 1;
  1139. this.x = x;
  1140. this.y = y;
  1141. this.z = z;
  1142. this.w = w;
  1143. }
  1144. Object.defineProperties( Vector4.prototype, {
  1145. "width": {
  1146. get: function () {
  1147. return this.z;
  1148. },
  1149. set: function ( value ) {
  1150. this.z = value;
  1151. }
  1152. },
  1153. "height": {
  1154. get: function () {
  1155. return this.w;
  1156. },
  1157. set: function ( value ) {
  1158. this.w = value;
  1159. }
  1160. }
  1161. } );
  1162. Object.assign( Vector4.prototype, {
  1163. isVector4: true,
  1164. set: function ( x, y, z, w ) {
  1165. this.x = x;
  1166. this.y = y;
  1167. this.z = z;
  1168. this.w = w;
  1169. return this;
  1170. },
  1171. setScalar: function ( scalar ) {
  1172. this.x = scalar;
  1173. this.y = scalar;
  1174. this.z = scalar;
  1175. this.w = scalar;
  1176. return this;
  1177. },
  1178. setX: function ( x ) {
  1179. this.x = x;
  1180. return this;
  1181. },
  1182. setY: function ( y ) {
  1183. this.y = y;
  1184. return this;
  1185. },
  1186. setZ: function ( z ) {
  1187. this.z = z;
  1188. return this;
  1189. },
  1190. setW: function ( w ) {
  1191. this.w = w;
  1192. return this;
  1193. },
  1194. setComponent: function ( index, value ) {
  1195. switch ( index ) {
  1196. case 0: this.x = value; break;
  1197. case 1: this.y = value; break;
  1198. case 2: this.z = value; break;
  1199. case 3: this.w = value; break;
  1200. default: throw new Error( 'index is out of range: ' + index );
  1201. }
  1202. return this;
  1203. },
  1204. getComponent: function ( index ) {
  1205. switch ( index ) {
  1206. case 0: return this.x;
  1207. case 1: return this.y;
  1208. case 2: return this.z;
  1209. case 3: return this.w;
  1210. default: throw new Error( 'index is out of range: ' + index );
  1211. }
  1212. },
  1213. clone: function () {
  1214. return new this.constructor( this.x, this.y, this.z, this.w );
  1215. },
  1216. copy: function ( v ) {
  1217. this.x = v.x;
  1218. this.y = v.y;
  1219. this.z = v.z;
  1220. this.w = ( v.w !== undefined ) ? v.w : 1;
  1221. return this;
  1222. },
  1223. add: function ( v, w ) {
  1224. if ( w !== undefined ) {
  1225. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1226. return this.addVectors( v, w );
  1227. }
  1228. this.x += v.x;
  1229. this.y += v.y;
  1230. this.z += v.z;
  1231. this.w += v.w;
  1232. return this;
  1233. },
  1234. addScalar: function ( s ) {
  1235. this.x += s;
  1236. this.y += s;
  1237. this.z += s;
  1238. this.w += s;
  1239. return this;
  1240. },
  1241. addVectors: function ( a, b ) {
  1242. this.x = a.x + b.x;
  1243. this.y = a.y + b.y;
  1244. this.z = a.z + b.z;
  1245. this.w = a.w + b.w;
  1246. return this;
  1247. },
  1248. addScaledVector: function ( v, s ) {
  1249. this.x += v.x * s;
  1250. this.y += v.y * s;
  1251. this.z += v.z * s;
  1252. this.w += v.w * s;
  1253. return this;
  1254. },
  1255. sub: function ( v, w ) {
  1256. if ( w !== undefined ) {
  1257. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1258. return this.subVectors( v, w );
  1259. }
  1260. this.x -= v.x;
  1261. this.y -= v.y;
  1262. this.z -= v.z;
  1263. this.w -= v.w;
  1264. return this;
  1265. },
  1266. subScalar: function ( s ) {
  1267. this.x -= s;
  1268. this.y -= s;
  1269. this.z -= s;
  1270. this.w -= s;
  1271. return this;
  1272. },
  1273. subVectors: function ( a, b ) {
  1274. this.x = a.x - b.x;
  1275. this.y = a.y - b.y;
  1276. this.z = a.z - b.z;
  1277. this.w = a.w - b.w;
  1278. return this;
  1279. },
  1280. multiplyScalar: function ( scalar ) {
  1281. this.x *= scalar;
  1282. this.y *= scalar;
  1283. this.z *= scalar;
  1284. this.w *= scalar;
  1285. return this;
  1286. },
  1287. applyMatrix4: function ( m ) {
  1288. var x = this.x, y = this.y, z = this.z, w = this.w;
  1289. var e = m.elements;
  1290. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1291. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1292. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1293. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1294. return this;
  1295. },
  1296. divideScalar: function ( scalar ) {
  1297. return this.multiplyScalar( 1 / scalar );
  1298. },
  1299. setAxisAngleFromQuaternion: function ( q ) {
  1300. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1301. // q is assumed to be normalized
  1302. this.w = 2 * Math.acos( q.w );
  1303. var s = Math.sqrt( 1 - q.w * q.w );
  1304. if ( s < 0.0001 ) {
  1305. this.x = 1;
  1306. this.y = 0;
  1307. this.z = 0;
  1308. } else {
  1309. this.x = q.x / s;
  1310. this.y = q.y / s;
  1311. this.z = q.z / s;
  1312. }
  1313. return this;
  1314. },
  1315. setAxisAngleFromRotationMatrix: function ( m ) {
  1316. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1317. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1318. var angle, x, y, z; // variables for result
  1319. var epsilon = 0.01, // margin to allow for rounding errors
  1320. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1321. te = m.elements,
  1322. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1323. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1324. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1325. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1326. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1327. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1328. // singularity found
  1329. // first check for identity matrix which must have +1 for all terms
  1330. // in leading diagonal and zero in other terms
  1331. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1332. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1333. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1334. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1335. // this singularity is identity matrix so angle = 0
  1336. this.set( 1, 0, 0, 0 );
  1337. return this; // zero angle, arbitrary axis
  1338. }
  1339. // otherwise this singularity is angle = 180
  1340. angle = Math.PI;
  1341. var xx = ( m11 + 1 ) / 2;
  1342. var yy = ( m22 + 1 ) / 2;
  1343. var zz = ( m33 + 1 ) / 2;
  1344. var xy = ( m12 + m21 ) / 4;
  1345. var xz = ( m13 + m31 ) / 4;
  1346. var yz = ( m23 + m32 ) / 4;
  1347. if ( ( xx > yy ) && ( xx > zz ) ) {
  1348. // m11 is the largest diagonal term
  1349. if ( xx < epsilon ) {
  1350. x = 0;
  1351. y = 0.707106781;
  1352. z = 0.707106781;
  1353. } else {
  1354. x = Math.sqrt( xx );
  1355. y = xy / x;
  1356. z = xz / x;
  1357. }
  1358. } else if ( yy > zz ) {
  1359. // m22 is the largest diagonal term
  1360. if ( yy < epsilon ) {
  1361. x = 0.707106781;
  1362. y = 0;
  1363. z = 0.707106781;
  1364. } else {
  1365. y = Math.sqrt( yy );
  1366. x = xy / y;
  1367. z = yz / y;
  1368. }
  1369. } else {
  1370. // m33 is the largest diagonal term so base result on this
  1371. if ( zz < epsilon ) {
  1372. x = 0.707106781;
  1373. y = 0.707106781;
  1374. z = 0;
  1375. } else {
  1376. z = Math.sqrt( zz );
  1377. x = xz / z;
  1378. y = yz / z;
  1379. }
  1380. }
  1381. this.set( x, y, z, angle );
  1382. return this; // return 180 deg rotation
  1383. }
  1384. // as we have reached here there are no singularities so we can handle normally
  1385. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1386. ( m13 - m31 ) * ( m13 - m31 ) +
  1387. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1388. if ( Math.abs( s ) < 0.001 ) { s = 1; }
  1389. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1390. // caught by singularity test above, but I've left it in just in case
  1391. this.x = ( m32 - m23 ) / s;
  1392. this.y = ( m13 - m31 ) / s;
  1393. this.z = ( m21 - m12 ) / s;
  1394. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1395. return this;
  1396. },
  1397. min: function ( v ) {
  1398. this.x = Math.min( this.x, v.x );
  1399. this.y = Math.min( this.y, v.y );
  1400. this.z = Math.min( this.z, v.z );
  1401. this.w = Math.min( this.w, v.w );
  1402. return this;
  1403. },
  1404. max: function ( v ) {
  1405. this.x = Math.max( this.x, v.x );
  1406. this.y = Math.max( this.y, v.y );
  1407. this.z = Math.max( this.z, v.z );
  1408. this.w = Math.max( this.w, v.w );
  1409. return this;
  1410. },
  1411. clamp: function ( min, max ) {
  1412. // assumes min < max, componentwise
  1413. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1414. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1415. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1416. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1417. return this;
  1418. },
  1419. clampScalar: function ( minVal, maxVal ) {
  1420. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1421. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1422. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1423. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1424. return this;
  1425. },
  1426. clampLength: function ( min, max ) {
  1427. var length = this.length();
  1428. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1429. },
  1430. floor: function () {
  1431. this.x = Math.floor( this.x );
  1432. this.y = Math.floor( this.y );
  1433. this.z = Math.floor( this.z );
  1434. this.w = Math.floor( this.w );
  1435. return this;
  1436. },
  1437. ceil: function () {
  1438. this.x = Math.ceil( this.x );
  1439. this.y = Math.ceil( this.y );
  1440. this.z = Math.ceil( this.z );
  1441. this.w = Math.ceil( this.w );
  1442. return this;
  1443. },
  1444. round: function () {
  1445. this.x = Math.round( this.x );
  1446. this.y = Math.round( this.y );
  1447. this.z = Math.round( this.z );
  1448. this.w = Math.round( this.w );
  1449. return this;
  1450. },
  1451. roundToZero: function () {
  1452. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1453. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1454. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1455. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1456. return this;
  1457. },
  1458. negate: function () {
  1459. this.x = - this.x;
  1460. this.y = - this.y;
  1461. this.z = - this.z;
  1462. this.w = - this.w;
  1463. return this;
  1464. },
  1465. dot: function ( v ) {
  1466. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1467. },
  1468. lengthSq: function () {
  1469. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1470. },
  1471. length: function () {
  1472. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1473. },
  1474. manhattanLength: function () {
  1475. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1476. },
  1477. normalize: function () {
  1478. return this.divideScalar( this.length() || 1 );
  1479. },
  1480. setLength: function ( length ) {
  1481. return this.normalize().multiplyScalar( length );
  1482. },
  1483. lerp: function ( v, alpha ) {
  1484. this.x += ( v.x - this.x ) * alpha;
  1485. this.y += ( v.y - this.y ) * alpha;
  1486. this.z += ( v.z - this.z ) * alpha;
  1487. this.w += ( v.w - this.w ) * alpha;
  1488. return this;
  1489. },
  1490. lerpVectors: function ( v1, v2, alpha ) {
  1491. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1492. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1493. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1494. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1495. return this;
  1496. },
  1497. equals: function ( v ) {
  1498. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1499. },
  1500. fromArray: function ( array, offset ) {
  1501. if ( offset === undefined ) { offset = 0; }
  1502. this.x = array[ offset ];
  1503. this.y = array[ offset + 1 ];
  1504. this.z = array[ offset + 2 ];
  1505. this.w = array[ offset + 3 ];
  1506. return this;
  1507. },
  1508. toArray: function ( array, offset ) {
  1509. if ( array === undefined ) { array = []; }
  1510. if ( offset === undefined ) { offset = 0; }
  1511. array[ offset ] = this.x;
  1512. array[ offset + 1 ] = this.y;
  1513. array[ offset + 2 ] = this.z;
  1514. array[ offset + 3 ] = this.w;
  1515. return array;
  1516. },
  1517. fromBufferAttribute: function ( attribute, index, offset ) {
  1518. if ( offset !== undefined ) {
  1519. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1520. }
  1521. this.x = attribute.getX( index );
  1522. this.y = attribute.getY( index );
  1523. this.z = attribute.getZ( index );
  1524. this.w = attribute.getW( index );
  1525. return this;
  1526. },
  1527. random: function () {
  1528. this.x = Math.random();
  1529. this.y = Math.random();
  1530. this.z = Math.random();
  1531. this.w = Math.random();
  1532. return this;
  1533. }
  1534. } );
  1535. /**
  1536. * @author szimek / https://github.com/szimek/
  1537. * @author alteredq / http://alteredqualia.com/
  1538. * @author Marius Kintel / https://github.com/kintel
  1539. */
  1540. /*
  1541. In options, we can specify:
  1542. * Texture parameters for an auto-generated target texture
  1543. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1544. */
  1545. function WebGLRenderTarget( width, height, options ) {
  1546. this.width = width;
  1547. this.height = height;
  1548. this.scissor = new Vector4( 0, 0, width, height );
  1549. this.scissorTest = false;
  1550. this.viewport = new Vector4( 0, 0, width, height );
  1551. options = options || {};
  1552. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1553. this.texture.image = {};
  1554. this.texture.image.width = width;
  1555. this.texture.image.height = height;
  1556. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1557. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1558. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1559. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  1560. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1561. }
  1562. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1563. constructor: WebGLRenderTarget,
  1564. isWebGLRenderTarget: true,
  1565. setSize: function ( width, height ) {
  1566. if ( this.width !== width || this.height !== height ) {
  1567. this.width = width;
  1568. this.height = height;
  1569. this.texture.image.width = width;
  1570. this.texture.image.height = height;
  1571. this.dispose();
  1572. }
  1573. this.viewport.set( 0, 0, width, height );
  1574. this.scissor.set( 0, 0, width, height );
  1575. },
  1576. clone: function () {
  1577. return new this.constructor().copy( this );
  1578. },
  1579. copy: function ( source ) {
  1580. this.width = source.width;
  1581. this.height = source.height;
  1582. this.viewport.copy( source.viewport );
  1583. this.texture = source.texture.clone();
  1584. this.depthBuffer = source.depthBuffer;
  1585. this.stencilBuffer = source.stencilBuffer;
  1586. this.depthTexture = source.depthTexture;
  1587. return this;
  1588. },
  1589. dispose: function () {
  1590. this.dispatchEvent( { type: 'dispose' } );
  1591. }
  1592. } );
  1593. /**
  1594. * @author Mugen87 / https://github.com/Mugen87
  1595. * @author Matt DesLauriers / @mattdesl
  1596. */
  1597. function WebGLMultisampleRenderTarget( width, height, options ) {
  1598. WebGLRenderTarget.call( this, width, height, options );
  1599. this.samples = 4;
  1600. }
  1601. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  1602. constructor: WebGLMultisampleRenderTarget,
  1603. isWebGLMultisampleRenderTarget: true,
  1604. copy: function ( source ) {
  1605. WebGLRenderTarget.prototype.copy.call( this, source );
  1606. this.samples = source.samples;
  1607. return this;
  1608. }
  1609. } );
  1610. /**
  1611. * @author mikael emtinger / http://gomo.se/
  1612. * @author alteredq / http://alteredqualia.com/
  1613. * @author WestLangley / http://github.com/WestLangley
  1614. * @author bhouston / http://clara.io
  1615. */
  1616. function Quaternion( x, y, z, w ) {
  1617. if ( x === void 0 ) x = 0;
  1618. if ( y === void 0 ) y = 0;
  1619. if ( z === void 0 ) z = 0;
  1620. if ( w === void 0 ) w = 1;
  1621. this._x = x;
  1622. this._y = y;
  1623. this._z = z;
  1624. this._w = w;
  1625. }
  1626. Object.assign( Quaternion, {
  1627. slerp: function ( qa, qb, qm, t ) {
  1628. return qm.copy( qa ).slerp( qb, t );
  1629. },
  1630. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1631. // fuzz-free, array-based Quaternion SLERP operation
  1632. var x0 = src0[ srcOffset0 + 0 ],
  1633. y0 = src0[ srcOffset0 + 1 ],
  1634. z0 = src0[ srcOffset0 + 2 ],
  1635. w0 = src0[ srcOffset0 + 3 ];
  1636. var x1 = src1[ srcOffset1 + 0 ],
  1637. y1 = src1[ srcOffset1 + 1 ],
  1638. z1 = src1[ srcOffset1 + 2 ],
  1639. w1 = src1[ srcOffset1 + 3 ];
  1640. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1641. var s = 1 - t,
  1642. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1643. dir = ( cos >= 0 ? 1 : - 1 ),
  1644. sqrSin = 1 - cos * cos;
  1645. // Skip the Slerp for tiny steps to avoid numeric problems:
  1646. if ( sqrSin > Number.EPSILON ) {
  1647. var sin = Math.sqrt( sqrSin ),
  1648. len = Math.atan2( sin, cos * dir );
  1649. s = Math.sin( s * len ) / sin;
  1650. t = Math.sin( t * len ) / sin;
  1651. }
  1652. var tDir = t * dir;
  1653. x0 = x0 * s + x1 * tDir;
  1654. y0 = y0 * s + y1 * tDir;
  1655. z0 = z0 * s + z1 * tDir;
  1656. w0 = w0 * s + w1 * tDir;
  1657. // Normalize in case we just did a lerp:
  1658. if ( s === 1 - t ) {
  1659. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1660. x0 *= f;
  1661. y0 *= f;
  1662. z0 *= f;
  1663. w0 *= f;
  1664. }
  1665. }
  1666. dst[ dstOffset ] = x0;
  1667. dst[ dstOffset + 1 ] = y0;
  1668. dst[ dstOffset + 2 ] = z0;
  1669. dst[ dstOffset + 3 ] = w0;
  1670. },
  1671. multiplyQuaternionsFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1672. var x0 = src0[ srcOffset0 ];
  1673. var y0 = src0[ srcOffset0 + 1 ];
  1674. var z0 = src0[ srcOffset0 + 2 ];
  1675. var w0 = src0[ srcOffset0 + 3 ];
  1676. var x1 = src1[ srcOffset1 ];
  1677. var y1 = src1[ srcOffset1 + 1 ];
  1678. var z1 = src1[ srcOffset1 + 2 ];
  1679. var w1 = src1[ srcOffset1 + 3 ];
  1680. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1681. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1682. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1683. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1684. return dst;
  1685. }
  1686. } );
  1687. Object.defineProperties( Quaternion.prototype, {
  1688. x: {
  1689. get: function () {
  1690. return this._x;
  1691. },
  1692. set: function ( value ) {
  1693. this._x = value;
  1694. this._onChangeCallback();
  1695. }
  1696. },
  1697. y: {
  1698. get: function () {
  1699. return this._y;
  1700. },
  1701. set: function ( value ) {
  1702. this._y = value;
  1703. this._onChangeCallback();
  1704. }
  1705. },
  1706. z: {
  1707. get: function () {
  1708. return this._z;
  1709. },
  1710. set: function ( value ) {
  1711. this._z = value;
  1712. this._onChangeCallback();
  1713. }
  1714. },
  1715. w: {
  1716. get: function () {
  1717. return this._w;
  1718. },
  1719. set: function ( value ) {
  1720. this._w = value;
  1721. this._onChangeCallback();
  1722. }
  1723. }
  1724. } );
  1725. Object.assign( Quaternion.prototype, {
  1726. isQuaternion: true,
  1727. set: function ( x, y, z, w ) {
  1728. this._x = x;
  1729. this._y = y;
  1730. this._z = z;
  1731. this._w = w;
  1732. this._onChangeCallback();
  1733. return this;
  1734. },
  1735. clone: function () {
  1736. return new this.constructor( this._x, this._y, this._z, this._w );
  1737. },
  1738. copy: function ( quaternion ) {
  1739. this._x = quaternion.x;
  1740. this._y = quaternion.y;
  1741. this._z = quaternion.z;
  1742. this._w = quaternion.w;
  1743. this._onChangeCallback();
  1744. return this;
  1745. },
  1746. setFromEuler: function ( euler, update ) {
  1747. if ( ! ( euler && euler.isEuler ) ) {
  1748. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1749. }
  1750. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1751. // http://www.mathworks.com/matlabcentral/fileexchange/
  1752. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1753. // content/SpinCalc.m
  1754. var cos = Math.cos;
  1755. var sin = Math.sin;
  1756. var c1 = cos( x / 2 );
  1757. var c2 = cos( y / 2 );
  1758. var c3 = cos( z / 2 );
  1759. var s1 = sin( x / 2 );
  1760. var s2 = sin( y / 2 );
  1761. var s3 = sin( z / 2 );
  1762. switch ( order ) {
  1763. case 'XYZ':
  1764. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1765. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1766. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1767. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1768. break;
  1769. case 'YXZ':
  1770. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1771. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1772. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1773. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1774. break;
  1775. case 'ZXY':
  1776. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1777. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1778. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1779. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1780. break;
  1781. case 'ZYX':
  1782. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1783. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1784. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1785. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1786. break;
  1787. case 'YZX':
  1788. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1789. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1790. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1791. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1792. break;
  1793. case 'XZY':
  1794. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1795. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1796. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1797. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1798. break;
  1799. default:
  1800. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1801. }
  1802. if ( update !== false ) { this._onChangeCallback(); }
  1803. return this;
  1804. },
  1805. setFromAxisAngle: function ( axis, angle ) {
  1806. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1807. // assumes axis is normalized
  1808. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1809. this._x = axis.x * s;
  1810. this._y = axis.y * s;
  1811. this._z = axis.z * s;
  1812. this._w = Math.cos( halfAngle );
  1813. this._onChangeCallback();
  1814. return this;
  1815. },
  1816. setFromRotationMatrix: function ( m ) {
  1817. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1818. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1819. var te = m.elements,
  1820. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1821. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1822. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1823. trace = m11 + m22 + m33;
  1824. if ( trace > 0 ) {
  1825. var s = 0.5 / Math.sqrt( trace + 1.0 );
  1826. this._w = 0.25 / s;
  1827. this._x = ( m32 - m23 ) * s;
  1828. this._y = ( m13 - m31 ) * s;
  1829. this._z = ( m21 - m12 ) * s;
  1830. } else if ( m11 > m22 && m11 > m33 ) {
  1831. var s$1 = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1832. this._w = ( m32 - m23 ) / s$1;
  1833. this._x = 0.25 * s$1;
  1834. this._y = ( m12 + m21 ) / s$1;
  1835. this._z = ( m13 + m31 ) / s$1;
  1836. } else if ( m22 > m33 ) {
  1837. var s$2 = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1838. this._w = ( m13 - m31 ) / s$2;
  1839. this._x = ( m12 + m21 ) / s$2;
  1840. this._y = 0.25 * s$2;
  1841. this._z = ( m23 + m32 ) / s$2;
  1842. } else {
  1843. var s$3 = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1844. this._w = ( m21 - m12 ) / s$3;
  1845. this._x = ( m13 + m31 ) / s$3;
  1846. this._y = ( m23 + m32 ) / s$3;
  1847. this._z = 0.25 * s$3;
  1848. }
  1849. this._onChangeCallback();
  1850. return this;
  1851. },
  1852. setFromUnitVectors: function ( vFrom, vTo ) {
  1853. // assumes direction vectors vFrom and vTo are normalized
  1854. var EPS = 0.000001;
  1855. var r = vFrom.dot( vTo ) + 1;
  1856. if ( r < EPS ) {
  1857. r = 0;
  1858. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1859. this._x = - vFrom.y;
  1860. this._y = vFrom.x;
  1861. this._z = 0;
  1862. this._w = r;
  1863. } else {
  1864. this._x = 0;
  1865. this._y = - vFrom.z;
  1866. this._z = vFrom.y;
  1867. this._w = r;
  1868. }
  1869. } else {
  1870. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1871. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1872. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1873. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1874. this._w = r;
  1875. }
  1876. return this.normalize();
  1877. },
  1878. angleTo: function ( q ) {
  1879. return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
  1880. },
  1881. rotateTowards: function ( q, step ) {
  1882. var angle = this.angleTo( q );
  1883. if ( angle === 0 ) { return this; }
  1884. var t = Math.min( 1, step / angle );
  1885. this.slerp( q, t );
  1886. return this;
  1887. },
  1888. inverse: function () {
  1889. // quaternion is assumed to have unit length
  1890. return this.conjugate();
  1891. },
  1892. conjugate: function () {
  1893. this._x *= - 1;
  1894. this._y *= - 1;
  1895. this._z *= - 1;
  1896. this._onChangeCallback();
  1897. return this;
  1898. },
  1899. dot: function ( v ) {
  1900. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1901. },
  1902. lengthSq: function () {
  1903. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1904. },
  1905. length: function () {
  1906. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1907. },
  1908. normalize: function () {
  1909. var l = this.length();
  1910. if ( l === 0 ) {
  1911. this._x = 0;
  1912. this._y = 0;
  1913. this._z = 0;
  1914. this._w = 1;
  1915. } else {
  1916. l = 1 / l;
  1917. this._x = this._x * l;
  1918. this._y = this._y * l;
  1919. this._z = this._z * l;
  1920. this._w = this._w * l;
  1921. }
  1922. this._onChangeCallback();
  1923. return this;
  1924. },
  1925. multiply: function ( q, p ) {
  1926. if ( p !== undefined ) {
  1927. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1928. return this.multiplyQuaternions( q, p );
  1929. }
  1930. return this.multiplyQuaternions( this, q );
  1931. },
  1932. premultiply: function ( q ) {
  1933. return this.multiplyQuaternions( q, this );
  1934. },
  1935. multiplyQuaternions: function ( a, b ) {
  1936. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1937. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1938. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1939. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1940. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1941. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1942. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1943. this._onChangeCallback();
  1944. return this;
  1945. },
  1946. slerp: function ( qb, t ) {
  1947. if ( t === 0 ) { return this; }
  1948. if ( t === 1 ) { return this.copy( qb ); }
  1949. var x = this._x, y = this._y, z = this._z, w = this._w;
  1950. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1951. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1952. if ( cosHalfTheta < 0 ) {
  1953. this._w = - qb._w;
  1954. this._x = - qb._x;
  1955. this._y = - qb._y;
  1956. this._z = - qb._z;
  1957. cosHalfTheta = - cosHalfTheta;
  1958. } else {
  1959. this.copy( qb );
  1960. }
  1961. if ( cosHalfTheta >= 1.0 ) {
  1962. this._w = w;
  1963. this._x = x;
  1964. this._y = y;
  1965. this._z = z;
  1966. return this;
  1967. }
  1968. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1969. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1970. var s = 1 - t;
  1971. this._w = s * w + t * this._w;
  1972. this._x = s * x + t * this._x;
  1973. this._y = s * y + t * this._y;
  1974. this._z = s * z + t * this._z;
  1975. this.normalize();
  1976. this._onChangeCallback();
  1977. return this;
  1978. }
  1979. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1980. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1981. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1982. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1983. this._w = ( w * ratioA + this._w * ratioB );
  1984. this._x = ( x * ratioA + this._x * ratioB );
  1985. this._y = ( y * ratioA + this._y * ratioB );
  1986. this._z = ( z * ratioA + this._z * ratioB );
  1987. this._onChangeCallback();
  1988. return this;
  1989. },
  1990. equals: function ( quaternion ) {
  1991. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1992. },
  1993. fromArray: function ( array, offset ) {
  1994. if ( offset === undefined ) { offset = 0; }
  1995. this._x = array[ offset ];
  1996. this._y = array[ offset + 1 ];
  1997. this._z = array[ offset + 2 ];
  1998. this._w = array[ offset + 3 ];
  1999. this._onChangeCallback();
  2000. return this;
  2001. },
  2002. toArray: function ( array, offset ) {
  2003. if ( array === undefined ) { array = []; }
  2004. if ( offset === undefined ) { offset = 0; }
  2005. array[ offset ] = this._x;
  2006. array[ offset + 1 ] = this._y;
  2007. array[ offset + 2 ] = this._z;
  2008. array[ offset + 3 ] = this._w;
  2009. return array;
  2010. },
  2011. fromBufferAttribute: function ( attribute, index ) {
  2012. this._x = attribute.getX( index );
  2013. this._y = attribute.getY( index );
  2014. this._z = attribute.getZ( index );
  2015. this._w = attribute.getW( index );
  2016. return this;
  2017. },
  2018. _onChange: function ( callback ) {
  2019. this._onChangeCallback = callback;
  2020. return this;
  2021. },
  2022. _onChangeCallback: function () {}
  2023. } );
  2024. /**
  2025. * @author mrdoob / http://mrdoob.com/
  2026. * @author kile / http://kile.stravaganza.org/
  2027. * @author philogb / http://blog.thejit.org/
  2028. * @author mikael emtinger / http://gomo.se/
  2029. * @author egraether / http://egraether.com/
  2030. * @author WestLangley / http://github.com/WestLangley
  2031. */
  2032. var _vector = new Vector3();
  2033. var _quaternion = new Quaternion();
  2034. function Vector3( x, y, z ) {
  2035. if ( x === void 0 ) x = 0;
  2036. if ( y === void 0 ) y = 0;
  2037. if ( z === void 0 ) z = 0;
  2038. this.x = x;
  2039. this.y = y;
  2040. this.z = z;
  2041. }
  2042. Object.assign( Vector3.prototype, {
  2043. isVector3: true,
  2044. set: function ( x, y, z ) {
  2045. this.x = x;
  2046. this.y = y;
  2047. this.z = z;
  2048. return this;
  2049. },
  2050. setScalar: function ( scalar ) {
  2051. this.x = scalar;
  2052. this.y = scalar;
  2053. this.z = scalar;
  2054. return this;
  2055. },
  2056. setX: function ( x ) {
  2057. this.x = x;
  2058. return this;
  2059. },
  2060. setY: function ( y ) {
  2061. this.y = y;
  2062. return this;
  2063. },
  2064. setZ: function ( z ) {
  2065. this.z = z;
  2066. return this;
  2067. },
  2068. setComponent: function ( index, value ) {
  2069. switch ( index ) {
  2070. case 0: this.x = value; break;
  2071. case 1: this.y = value; break;
  2072. case 2: this.z = value; break;
  2073. default: throw new Error( 'index is out of range: ' + index );
  2074. }
  2075. return this;
  2076. },
  2077. getComponent: function ( index ) {
  2078. switch ( index ) {
  2079. case 0: return this.x;
  2080. case 1: return this.y;
  2081. case 2: return this.z;
  2082. default: throw new Error( 'index is out of range: ' + index );
  2083. }
  2084. },
  2085. clone: function () {
  2086. return new this.constructor( this.x, this.y, this.z );
  2087. },
  2088. copy: function ( v ) {
  2089. this.x = v.x;
  2090. this.y = v.y;
  2091. this.z = v.z;
  2092. return this;
  2093. },
  2094. add: function ( v, w ) {
  2095. if ( w !== undefined ) {
  2096. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2097. return this.addVectors( v, w );
  2098. }
  2099. this.x += v.x;
  2100. this.y += v.y;
  2101. this.z += v.z;
  2102. return this;
  2103. },
  2104. addScalar: function ( s ) {
  2105. this.x += s;
  2106. this.y += s;
  2107. this.z += s;
  2108. return this;
  2109. },
  2110. addVectors: function ( a, b ) {
  2111. this.x = a.x + b.x;
  2112. this.y = a.y + b.y;
  2113. this.z = a.z + b.z;
  2114. return this;
  2115. },
  2116. addScaledVector: function ( v, s ) {
  2117. this.x += v.x * s;
  2118. this.y += v.y * s;
  2119. this.z += v.z * s;
  2120. return this;
  2121. },
  2122. sub: function ( v, w ) {
  2123. if ( w !== undefined ) {
  2124. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2125. return this.subVectors( v, w );
  2126. }
  2127. this.x -= v.x;
  2128. this.y -= v.y;
  2129. this.z -= v.z;
  2130. return this;
  2131. },
  2132. subScalar: function ( s ) {
  2133. this.x -= s;
  2134. this.y -= s;
  2135. this.z -= s;
  2136. return this;
  2137. },
  2138. subVectors: function ( a, b ) {
  2139. this.x = a.x - b.x;
  2140. this.y = a.y - b.y;
  2141. this.z = a.z - b.z;
  2142. return this;
  2143. },
  2144. multiply: function ( v, w ) {
  2145. if ( w !== undefined ) {
  2146. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2147. return this.multiplyVectors( v, w );
  2148. }
  2149. this.x *= v.x;
  2150. this.y *= v.y;
  2151. this.z *= v.z;
  2152. return this;
  2153. },
  2154. multiplyScalar: function ( scalar ) {
  2155. this.x *= scalar;
  2156. this.y *= scalar;
  2157. this.z *= scalar;
  2158. return this;
  2159. },
  2160. multiplyVectors: function ( a, b ) {
  2161. this.x = a.x * b.x;
  2162. this.y = a.y * b.y;
  2163. this.z = a.z * b.z;
  2164. return this;
  2165. },
  2166. applyEuler: function ( euler ) {
  2167. if ( ! ( euler && euler.isEuler ) ) {
  2168. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2169. }
  2170. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  2171. },
  2172. applyAxisAngle: function ( axis, angle ) {
  2173. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  2174. },
  2175. applyMatrix3: function ( m ) {
  2176. var x = this.x, y = this.y, z = this.z;
  2177. var e = m.elements;
  2178. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2179. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2180. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2181. return this;
  2182. },
  2183. applyNormalMatrix: function ( m ) {
  2184. return this.applyMatrix3( m ).normalize();
  2185. },
  2186. applyMatrix4: function ( m ) {
  2187. var x = this.x, y = this.y, z = this.z;
  2188. var e = m.elements;
  2189. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2190. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2191. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2192. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2193. return this;
  2194. },
  2195. applyQuaternion: function ( q ) {
  2196. var x = this.x, y = this.y, z = this.z;
  2197. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2198. // calculate quat * vector
  2199. var ix = qw * x + qy * z - qz * y;
  2200. var iy = qw * y + qz * x - qx * z;
  2201. var iz = qw * z + qx * y - qy * x;
  2202. var iw = - qx * x - qy * y - qz * z;
  2203. // calculate result * inverse quat
  2204. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2205. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2206. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2207. return this;
  2208. },
  2209. project: function ( camera ) {
  2210. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2211. },
  2212. unproject: function ( camera ) {
  2213. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2214. },
  2215. transformDirection: function ( m ) {
  2216. // input: THREE.Matrix4 affine matrix
  2217. // vector interpreted as a direction
  2218. var x = this.x, y = this.y, z = this.z;
  2219. var e = m.elements;
  2220. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2221. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2222. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2223. return this.normalize();
  2224. },
  2225. divide: function ( v ) {
  2226. this.x /= v.x;
  2227. this.y /= v.y;
  2228. this.z /= v.z;
  2229. return this;
  2230. },
  2231. divideScalar: function ( scalar ) {
  2232. return this.multiplyScalar( 1 / scalar );
  2233. },
  2234. min: function ( v ) {
  2235. this.x = Math.min( this.x, v.x );
  2236. this.y = Math.min( this.y, v.y );
  2237. this.z = Math.min( this.z, v.z );
  2238. return this;
  2239. },
  2240. max: function ( v ) {
  2241. this.x = Math.max( this.x, v.x );
  2242. this.y = Math.max( this.y, v.y );
  2243. this.z = Math.max( this.z, v.z );
  2244. return this;
  2245. },
  2246. clamp: function ( min, max ) {
  2247. // assumes min < max, componentwise
  2248. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2249. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2250. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2251. return this;
  2252. },
  2253. clampScalar: function ( minVal, maxVal ) {
  2254. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2255. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2256. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2257. return this;
  2258. },
  2259. clampLength: function ( min, max ) {
  2260. var length = this.length();
  2261. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2262. },
  2263. floor: function () {
  2264. this.x = Math.floor( this.x );
  2265. this.y = Math.floor( this.y );
  2266. this.z = Math.floor( this.z );
  2267. return this;
  2268. },
  2269. ceil: function () {
  2270. this.x = Math.ceil( this.x );
  2271. this.y = Math.ceil( this.y );
  2272. this.z = Math.ceil( this.z );
  2273. return this;
  2274. },
  2275. round: function () {
  2276. this.x = Math.round( this.x );
  2277. this.y = Math.round( this.y );
  2278. this.z = Math.round( this.z );
  2279. return this;
  2280. },
  2281. roundToZero: function () {
  2282. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2283. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2284. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2285. return this;
  2286. },
  2287. negate: function () {
  2288. this.x = - this.x;
  2289. this.y = - this.y;
  2290. this.z = - this.z;
  2291. return this;
  2292. },
  2293. dot: function ( v ) {
  2294. return this.x * v.x + this.y * v.y + this.z * v.z;
  2295. },
  2296. // TODO lengthSquared?
  2297. lengthSq: function () {
  2298. return this.x * this.x + this.y * this.y + this.z * this.z;
  2299. },
  2300. length: function () {
  2301. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2302. },
  2303. manhattanLength: function () {
  2304. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2305. },
  2306. normalize: function () {
  2307. return this.divideScalar( this.length() || 1 );
  2308. },
  2309. setLength: function ( length ) {
  2310. return this.normalize().multiplyScalar( length );
  2311. },
  2312. lerp: function ( v, alpha ) {
  2313. this.x += ( v.x - this.x ) * alpha;
  2314. this.y += ( v.y - this.y ) * alpha;
  2315. this.z += ( v.z - this.z ) * alpha;
  2316. return this;
  2317. },
  2318. lerpVectors: function ( v1, v2, alpha ) {
  2319. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2320. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2321. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2322. return this;
  2323. },
  2324. cross: function ( v, w ) {
  2325. if ( w !== undefined ) {
  2326. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2327. return this.crossVectors( v, w );
  2328. }
  2329. return this.crossVectors( this, v );
  2330. },
  2331. crossVectors: function ( a, b ) {
  2332. var ax = a.x, ay = a.y, az = a.z;
  2333. var bx = b.x, by = b.y, bz = b.z;
  2334. this.x = ay * bz - az * by;
  2335. this.y = az * bx - ax * bz;
  2336. this.z = ax * by - ay * bx;
  2337. return this;
  2338. },
  2339. projectOnVector: function ( v ) {
  2340. var denominator = v.lengthSq();
  2341. if ( denominator === 0 ) { return this.set( 0, 0, 0 ); }
  2342. var scalar = v.dot( this ) / denominator;
  2343. return this.copy( v ).multiplyScalar( scalar );
  2344. },
  2345. projectOnPlane: function ( planeNormal ) {
  2346. _vector.copy( this ).projectOnVector( planeNormal );
  2347. return this.sub( _vector );
  2348. },
  2349. reflect: function ( normal ) {
  2350. // reflect incident vector off plane orthogonal to normal
  2351. // normal is assumed to have unit length
  2352. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2353. },
  2354. angleTo: function ( v ) {
  2355. var denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2356. if ( denominator === 0 ) { return Math.PI / 2; }
  2357. var theta = this.dot( v ) / denominator;
  2358. // clamp, to handle numerical problems
  2359. return Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
  2360. },
  2361. distanceTo: function ( v ) {
  2362. return Math.sqrt( this.distanceToSquared( v ) );
  2363. },
  2364. distanceToSquared: function ( v ) {
  2365. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2366. return dx * dx + dy * dy + dz * dz;
  2367. },
  2368. manhattanDistanceTo: function ( v ) {
  2369. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2370. },
  2371. setFromSpherical: function ( s ) {
  2372. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2373. },
  2374. setFromSphericalCoords: function ( radius, phi, theta ) {
  2375. var sinPhiRadius = Math.sin( phi ) * radius;
  2376. this.x = sinPhiRadius * Math.sin( theta );
  2377. this.y = Math.cos( phi ) * radius;
  2378. this.z = sinPhiRadius * Math.cos( theta );
  2379. return this;
  2380. },
  2381. setFromCylindrical: function ( c ) {
  2382. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2383. },
  2384. setFromCylindricalCoords: function ( radius, theta, y ) {
  2385. this.x = radius * Math.sin( theta );
  2386. this.y = y;
  2387. this.z = radius * Math.cos( theta );
  2388. return this;
  2389. },
  2390. setFromMatrixPosition: function ( m ) {
  2391. var e = m.elements;
  2392. this.x = e[ 12 ];
  2393. this.y = e[ 13 ];
  2394. this.z = e[ 14 ];
  2395. return this;
  2396. },
  2397. setFromMatrixScale: function ( m ) {
  2398. var sx = this.setFromMatrixColumn( m, 0 ).length();
  2399. var sy = this.setFromMatrixColumn( m, 1 ).length();
  2400. var sz = this.setFromMatrixColumn( m, 2 ).length();
  2401. this.x = sx;
  2402. this.y = sy;
  2403. this.z = sz;
  2404. return this;
  2405. },
  2406. setFromMatrixColumn: function ( m, index ) {
  2407. return this.fromArray( m.elements, index * 4 );
  2408. },
  2409. setFromMatrix3Column: function ( m, index ) {
  2410. return this.fromArray( m.elements, index * 3 );
  2411. },
  2412. equals: function ( v ) {
  2413. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2414. },
  2415. fromArray: function ( array, offset ) {
  2416. if ( offset === undefined ) { offset = 0; }
  2417. this.x = array[ offset ];
  2418. this.y = array[ offset + 1 ];
  2419. this.z = array[ offset + 2 ];
  2420. return this;
  2421. },
  2422. toArray: function ( array, offset ) {
  2423. if ( array === undefined ) { array = []; }
  2424. if ( offset === undefined ) { offset = 0; }
  2425. array[ offset ] = this.x;
  2426. array[ offset + 1 ] = this.y;
  2427. array[ offset + 2 ] = this.z;
  2428. return array;
  2429. },
  2430. fromBufferAttribute: function ( attribute, index, offset ) {
  2431. if ( offset !== undefined ) {
  2432. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2433. }
  2434. this.x = attribute.getX( index );
  2435. this.y = attribute.getY( index );
  2436. this.z = attribute.getZ( index );
  2437. return this;
  2438. },
  2439. random: function () {
  2440. this.x = Math.random();
  2441. this.y = Math.random();
  2442. this.z = Math.random();
  2443. return this;
  2444. }
  2445. } );
  2446. var _v1 = new Vector3();
  2447. var _m1 = new Matrix4();
  2448. var _zero = new Vector3( 0, 0, 0 );
  2449. var _one = new Vector3( 1, 1, 1 );
  2450. var _x = new Vector3();
  2451. var _y = new Vector3();
  2452. var _z = new Vector3();
  2453. /**
  2454. * @author mrdoob / http://mrdoob.com/
  2455. * @author supereggbert / http://www.paulbrunt.co.uk/
  2456. * @author philogb / http://blog.thejit.org/
  2457. * @author jordi_ros / http://plattsoft.com
  2458. * @author D1plo1d / http://github.com/D1plo1d
  2459. * @author alteredq / http://alteredqualia.com/
  2460. * @author mikael emtinger / http://gomo.se/
  2461. * @author timknip / http://www.floorplanner.com/
  2462. * @author bhouston / http://clara.io
  2463. * @author WestLangley / http://github.com/WestLangley
  2464. */
  2465. function Matrix4() {
  2466. this.elements = [
  2467. 1, 0, 0, 0,
  2468. 0, 1, 0, 0,
  2469. 0, 0, 1, 0,
  2470. 0, 0, 0, 1
  2471. ];
  2472. if ( arguments.length > 0 ) {
  2473. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2474. }
  2475. }
  2476. Object.assign( Matrix4.prototype, {
  2477. isMatrix4: true,
  2478. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2479. var te = this.elements;
  2480. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2481. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2482. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2483. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2484. return this;
  2485. },
  2486. identity: function () {
  2487. this.set(
  2488. 1, 0, 0, 0,
  2489. 0, 1, 0, 0,
  2490. 0, 0, 1, 0,
  2491. 0, 0, 0, 1
  2492. );
  2493. return this;
  2494. },
  2495. clone: function () {
  2496. return new Matrix4().fromArray( this.elements );
  2497. },
  2498. copy: function ( m ) {
  2499. var te = this.elements;
  2500. var me = m.elements;
  2501. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2502. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2503. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2504. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2505. return this;
  2506. },
  2507. copyPosition: function ( m ) {
  2508. var te = this.elements, me = m.elements;
  2509. te[ 12 ] = me[ 12 ];
  2510. te[ 13 ] = me[ 13 ];
  2511. te[ 14 ] = me[ 14 ];
  2512. return this;
  2513. },
  2514. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2515. xAxis.setFromMatrixColumn( this, 0 );
  2516. yAxis.setFromMatrixColumn( this, 1 );
  2517. zAxis.setFromMatrixColumn( this, 2 );
  2518. return this;
  2519. },
  2520. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2521. this.set(
  2522. xAxis.x, yAxis.x, zAxis.x, 0,
  2523. xAxis.y, yAxis.y, zAxis.y, 0,
  2524. xAxis.z, yAxis.z, zAxis.z, 0,
  2525. 0, 0, 0, 1
  2526. );
  2527. return this;
  2528. },
  2529. extractRotation: function ( m ) {
  2530. // this method does not support reflection matrices
  2531. var te = this.elements;
  2532. var me = m.elements;
  2533. var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
  2534. var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
  2535. var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
  2536. te[ 0 ] = me[ 0 ] * scaleX;
  2537. te[ 1 ] = me[ 1 ] * scaleX;
  2538. te[ 2 ] = me[ 2 ] * scaleX;
  2539. te[ 3 ] = 0;
  2540. te[ 4 ] = me[ 4 ] * scaleY;
  2541. te[ 5 ] = me[ 5 ] * scaleY;
  2542. te[ 6 ] = me[ 6 ] * scaleY;
  2543. te[ 7 ] = 0;
  2544. te[ 8 ] = me[ 8 ] * scaleZ;
  2545. te[ 9 ] = me[ 9 ] * scaleZ;
  2546. te[ 10 ] = me[ 10 ] * scaleZ;
  2547. te[ 11 ] = 0;
  2548. te[ 12 ] = 0;
  2549. te[ 13 ] = 0;
  2550. te[ 14 ] = 0;
  2551. te[ 15 ] = 1;
  2552. return this;
  2553. },
  2554. makeRotationFromEuler: function ( euler ) {
  2555. if ( ! ( euler && euler.isEuler ) ) {
  2556. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2557. }
  2558. var te = this.elements;
  2559. var x = euler.x, y = euler.y, z = euler.z;
  2560. var a = Math.cos( x ), b = Math.sin( x );
  2561. var c = Math.cos( y ), d = Math.sin( y );
  2562. var e = Math.cos( z ), f = Math.sin( z );
  2563. if ( euler.order === 'XYZ' ) {
  2564. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2565. te[ 0 ] = c * e;
  2566. te[ 4 ] = - c * f;
  2567. te[ 8 ] = d;
  2568. te[ 1 ] = af + be * d;
  2569. te[ 5 ] = ae - bf * d;
  2570. te[ 9 ] = - b * c;
  2571. te[ 2 ] = bf - ae * d;
  2572. te[ 6 ] = be + af * d;
  2573. te[ 10 ] = a * c;
  2574. } else if ( euler.order === 'YXZ' ) {
  2575. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2576. te[ 0 ] = ce + df * b;
  2577. te[ 4 ] = de * b - cf;
  2578. te[ 8 ] = a * d;
  2579. te[ 1 ] = a * f;
  2580. te[ 5 ] = a * e;
  2581. te[ 9 ] = - b;
  2582. te[ 2 ] = cf * b - de;
  2583. te[ 6 ] = df + ce * b;
  2584. te[ 10 ] = a * c;
  2585. } else if ( euler.order === 'ZXY' ) {
  2586. var ce$1 = c * e, cf$1 = c * f, de$1 = d * e, df$1 = d * f;
  2587. te[ 0 ] = ce$1 - df$1 * b;
  2588. te[ 4 ] = - a * f;
  2589. te[ 8 ] = de$1 + cf$1 * b;
  2590. te[ 1 ] = cf$1 + de$1 * b;
  2591. te[ 5 ] = a * e;
  2592. te[ 9 ] = df$1 - ce$1 * b;
  2593. te[ 2 ] = - a * d;
  2594. te[ 6 ] = b;
  2595. te[ 10 ] = a * c;
  2596. } else if ( euler.order === 'ZYX' ) {
  2597. var ae$1 = a * e, af$1 = a * f, be$1 = b * e, bf$1 = b * f;
  2598. te[ 0 ] = c * e;
  2599. te[ 4 ] = be$1 * d - af$1;
  2600. te[ 8 ] = ae$1 * d + bf$1;
  2601. te[ 1 ] = c * f;
  2602. te[ 5 ] = bf$1 * d + ae$1;
  2603. te[ 9 ] = af$1 * d - be$1;
  2604. te[ 2 ] = - d;
  2605. te[ 6 ] = b * c;
  2606. te[ 10 ] = a * c;
  2607. } else if ( euler.order === 'YZX' ) {
  2608. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2609. te[ 0 ] = c * e;
  2610. te[ 4 ] = bd - ac * f;
  2611. te[ 8 ] = bc * f + ad;
  2612. te[ 1 ] = f;
  2613. te[ 5 ] = a * e;
  2614. te[ 9 ] = - b * e;
  2615. te[ 2 ] = - d * e;
  2616. te[ 6 ] = ad * f + bc;
  2617. te[ 10 ] = ac - bd * f;
  2618. } else if ( euler.order === 'XZY' ) {
  2619. var ac$1 = a * c, ad$1 = a * d, bc$1 = b * c, bd$1 = b * d;
  2620. te[ 0 ] = c * e;
  2621. te[ 4 ] = - f;
  2622. te[ 8 ] = d * e;
  2623. te[ 1 ] = ac$1 * f + bd$1;
  2624. te[ 5 ] = a * e;
  2625. te[ 9 ] = ad$1 * f - bc$1;
  2626. te[ 2 ] = bc$1 * f - ad$1;
  2627. te[ 6 ] = b * e;
  2628. te[ 10 ] = bd$1 * f + ac$1;
  2629. }
  2630. // bottom row
  2631. te[ 3 ] = 0;
  2632. te[ 7 ] = 0;
  2633. te[ 11 ] = 0;
  2634. // last column
  2635. te[ 12 ] = 0;
  2636. te[ 13 ] = 0;
  2637. te[ 14 ] = 0;
  2638. te[ 15 ] = 1;
  2639. return this;
  2640. },
  2641. makeRotationFromQuaternion: function ( q ) {
  2642. return this.compose( _zero, q, _one );
  2643. },
  2644. lookAt: function ( eye, target, up ) {
  2645. var te = this.elements;
  2646. _z.subVectors( eye, target );
  2647. if ( _z.lengthSq() === 0 ) {
  2648. // eye and target are in the same position
  2649. _z.z = 1;
  2650. }
  2651. _z.normalize();
  2652. _x.crossVectors( up, _z );
  2653. if ( _x.lengthSq() === 0 ) {
  2654. // up and z are parallel
  2655. if ( Math.abs( up.z ) === 1 ) {
  2656. _z.x += 0.0001;
  2657. } else {
  2658. _z.z += 0.0001;
  2659. }
  2660. _z.normalize();
  2661. _x.crossVectors( up, _z );
  2662. }
  2663. _x.normalize();
  2664. _y.crossVectors( _z, _x );
  2665. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  2666. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  2667. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  2668. return this;
  2669. },
  2670. multiply: function ( m, n ) {
  2671. if ( n !== undefined ) {
  2672. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2673. return this.multiplyMatrices( m, n );
  2674. }
  2675. return this.multiplyMatrices( this, m );
  2676. },
  2677. premultiply: function ( m ) {
  2678. return this.multiplyMatrices( m, this );
  2679. },
  2680. multiplyMatrices: function ( a, b ) {
  2681. var ae = a.elements;
  2682. var be = b.elements;
  2683. var te = this.elements;
  2684. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2685. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2686. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2687. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2688. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2689. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2690. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2691. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2692. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2693. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2694. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2695. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2696. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2697. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2698. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2699. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2700. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2701. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2702. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2703. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2704. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2705. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2706. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2707. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2708. return this;
  2709. },
  2710. multiplyScalar: function ( s ) {
  2711. var te = this.elements;
  2712. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2713. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2714. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2715. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2716. return this;
  2717. },
  2718. determinant: function () {
  2719. var te = this.elements;
  2720. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2721. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2722. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2723. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2724. //TODO: make this more efficient
  2725. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2726. return (
  2727. n41 * (
  2728. + n14 * n23 * n32
  2729. - n13 * n24 * n32
  2730. - n14 * n22 * n33
  2731. + n12 * n24 * n33
  2732. + n13 * n22 * n34
  2733. - n12 * n23 * n34
  2734. ) +
  2735. n42 * (
  2736. + n11 * n23 * n34
  2737. - n11 * n24 * n33
  2738. + n14 * n21 * n33
  2739. - n13 * n21 * n34
  2740. + n13 * n24 * n31
  2741. - n14 * n23 * n31
  2742. ) +
  2743. n43 * (
  2744. + n11 * n24 * n32
  2745. - n11 * n22 * n34
  2746. - n14 * n21 * n32
  2747. + n12 * n21 * n34
  2748. + n14 * n22 * n31
  2749. - n12 * n24 * n31
  2750. ) +
  2751. n44 * (
  2752. - n13 * n22 * n31
  2753. - n11 * n23 * n32
  2754. + n11 * n22 * n33
  2755. + n13 * n21 * n32
  2756. - n12 * n21 * n33
  2757. + n12 * n23 * n31
  2758. )
  2759. );
  2760. },
  2761. transpose: function () {
  2762. var te = this.elements;
  2763. var tmp;
  2764. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2765. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2766. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2767. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2768. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2769. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2770. return this;
  2771. },
  2772. setPosition: function ( x, y, z ) {
  2773. var te = this.elements;
  2774. if ( x.isVector3 ) {
  2775. te[ 12 ] = x.x;
  2776. te[ 13 ] = x.y;
  2777. te[ 14 ] = x.z;
  2778. } else {
  2779. te[ 12 ] = x;
  2780. te[ 13 ] = y;
  2781. te[ 14 ] = z;
  2782. }
  2783. return this;
  2784. },
  2785. getInverse: function ( m, throwOnDegenerate ) {
  2786. if ( throwOnDegenerate !== undefined ) {
  2787. console.warn( "THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate." );
  2788. }
  2789. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2790. var te = this.elements,
  2791. me = m.elements,
  2792. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2793. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2794. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2795. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2796. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2797. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2798. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2799. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2800. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2801. if ( det === 0 ) { return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); }
  2802. var detInv = 1 / det;
  2803. te[ 0 ] = t11 * detInv;
  2804. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2805. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2806. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2807. te[ 4 ] = t12 * detInv;
  2808. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2809. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2810. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2811. te[ 8 ] = t13 * detInv;
  2812. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2813. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2814. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2815. te[ 12 ] = t14 * detInv;
  2816. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2817. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2818. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2819. return this;
  2820. },
  2821. scale: function ( v ) {
  2822. var te = this.elements;
  2823. var x = v.x, y = v.y, z = v.z;
  2824. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2825. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2826. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2827. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2828. return this;
  2829. },
  2830. getMaxScaleOnAxis: function () {
  2831. var te = this.elements;
  2832. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2833. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2834. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2835. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2836. },
  2837. makeTranslation: function ( x, y, z ) {
  2838. this.set(
  2839. 1, 0, 0, x,
  2840. 0, 1, 0, y,
  2841. 0, 0, 1, z,
  2842. 0, 0, 0, 1
  2843. );
  2844. return this;
  2845. },
  2846. makeRotationX: function ( theta ) {
  2847. var c = Math.cos( theta ), s = Math.sin( theta );
  2848. this.set(
  2849. 1, 0, 0, 0,
  2850. 0, c, - s, 0,
  2851. 0, s, c, 0,
  2852. 0, 0, 0, 1
  2853. );
  2854. return this;
  2855. },
  2856. makeRotationY: function ( theta ) {
  2857. var c = Math.cos( theta ), s = Math.sin( theta );
  2858. this.set(
  2859. c, 0, s, 0,
  2860. 0, 1, 0, 0,
  2861. - s, 0, c, 0,
  2862. 0, 0, 0, 1
  2863. );
  2864. return this;
  2865. },
  2866. makeRotationZ: function ( theta ) {
  2867. var c = Math.cos( theta ), s = Math.sin( theta );
  2868. this.set(
  2869. c, - s, 0, 0,
  2870. s, c, 0, 0,
  2871. 0, 0, 1, 0,
  2872. 0, 0, 0, 1
  2873. );
  2874. return this;
  2875. },
  2876. makeRotationAxis: function ( axis, angle ) {
  2877. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2878. var c = Math.cos( angle );
  2879. var s = Math.sin( angle );
  2880. var t = 1 - c;
  2881. var x = axis.x, y = axis.y, z = axis.z;
  2882. var tx = t * x, ty = t * y;
  2883. this.set(
  2884. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2885. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2886. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2887. 0, 0, 0, 1
  2888. );
  2889. return this;
  2890. },
  2891. makeScale: function ( x, y, z ) {
  2892. this.set(
  2893. x, 0, 0, 0,
  2894. 0, y, 0, 0,
  2895. 0, 0, z, 0,
  2896. 0, 0, 0, 1
  2897. );
  2898. return this;
  2899. },
  2900. makeShear: function ( x, y, z ) {
  2901. this.set(
  2902. 1, y, z, 0,
  2903. x, 1, z, 0,
  2904. x, y, 1, 0,
  2905. 0, 0, 0, 1
  2906. );
  2907. return this;
  2908. },
  2909. compose: function ( position, quaternion, scale ) {
  2910. var te = this.elements;
  2911. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2912. var x2 = x + x, y2 = y + y, z2 = z + z;
  2913. var xx = x * x2, xy = x * y2, xz = x * z2;
  2914. var yy = y * y2, yz = y * z2, zz = z * z2;
  2915. var wx = w * x2, wy = w * y2, wz = w * z2;
  2916. var sx = scale.x, sy = scale.y, sz = scale.z;
  2917. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2918. te[ 1 ] = ( xy + wz ) * sx;
  2919. te[ 2 ] = ( xz - wy ) * sx;
  2920. te[ 3 ] = 0;
  2921. te[ 4 ] = ( xy - wz ) * sy;
  2922. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2923. te[ 6 ] = ( yz + wx ) * sy;
  2924. te[ 7 ] = 0;
  2925. te[ 8 ] = ( xz + wy ) * sz;
  2926. te[ 9 ] = ( yz - wx ) * sz;
  2927. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2928. te[ 11 ] = 0;
  2929. te[ 12 ] = position.x;
  2930. te[ 13 ] = position.y;
  2931. te[ 14 ] = position.z;
  2932. te[ 15 ] = 1;
  2933. return this;
  2934. },
  2935. decompose: function ( position, quaternion, scale ) {
  2936. var te = this.elements;
  2937. var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2938. var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2939. var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2940. // if determine is negative, we need to invert one scale
  2941. var det = this.determinant();
  2942. if ( det < 0 ) { sx = - sx; }
  2943. position.x = te[ 12 ];
  2944. position.y = te[ 13 ];
  2945. position.z = te[ 14 ];
  2946. // scale the rotation part
  2947. _m1.copy( this );
  2948. var invSX = 1 / sx;
  2949. var invSY = 1 / sy;
  2950. var invSZ = 1 / sz;
  2951. _m1.elements[ 0 ] *= invSX;
  2952. _m1.elements[ 1 ] *= invSX;
  2953. _m1.elements[ 2 ] *= invSX;
  2954. _m1.elements[ 4 ] *= invSY;
  2955. _m1.elements[ 5 ] *= invSY;
  2956. _m1.elements[ 6 ] *= invSY;
  2957. _m1.elements[ 8 ] *= invSZ;
  2958. _m1.elements[ 9 ] *= invSZ;
  2959. _m1.elements[ 10 ] *= invSZ;
  2960. quaternion.setFromRotationMatrix( _m1 );
  2961. scale.x = sx;
  2962. scale.y = sy;
  2963. scale.z = sz;
  2964. return this;
  2965. },
  2966. makePerspective: function ( left, right, top, bottom, near, far ) {
  2967. if ( far === undefined ) {
  2968. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2969. }
  2970. var te = this.elements;
  2971. var x = 2 * near / ( right - left );
  2972. var y = 2 * near / ( top - bottom );
  2973. var a = ( right + left ) / ( right - left );
  2974. var b = ( top + bottom ) / ( top - bottom );
  2975. var c = - ( far + near ) / ( far - near );
  2976. var d = - 2 * far * near / ( far - near );
  2977. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2978. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2979. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2980. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2981. return this;
  2982. },
  2983. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2984. var te = this.elements;
  2985. var w = 1.0 / ( right - left );
  2986. var h = 1.0 / ( top - bottom );
  2987. var p = 1.0 / ( far - near );
  2988. var x = ( right + left ) * w;
  2989. var y = ( top + bottom ) * h;
  2990. var z = ( far + near ) * p;
  2991. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2992. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2993. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2994. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2995. return this;
  2996. },
  2997. equals: function ( matrix ) {
  2998. var te = this.elements;
  2999. var me = matrix.elements;
  3000. for ( var i = 0; i < 16; i ++ ) {
  3001. if ( te[ i ] !== me[ i ] ) { return false; }
  3002. }
  3003. return true;
  3004. },
  3005. fromArray: function ( array, offset ) {
  3006. if ( offset === undefined ) { offset = 0; }
  3007. for ( var i = 0; i < 16; i ++ ) {
  3008. this.elements[ i ] = array[ i + offset ];
  3009. }
  3010. return this;
  3011. },
  3012. toArray: function ( array, offset ) {
  3013. if ( array === undefined ) { array = []; }
  3014. if ( offset === undefined ) { offset = 0; }
  3015. var te = this.elements;
  3016. array[ offset ] = te[ 0 ];
  3017. array[ offset + 1 ] = te[ 1 ];
  3018. array[ offset + 2 ] = te[ 2 ];
  3019. array[ offset + 3 ] = te[ 3 ];
  3020. array[ offset + 4 ] = te[ 4 ];
  3021. array[ offset + 5 ] = te[ 5 ];
  3022. array[ offset + 6 ] = te[ 6 ];
  3023. array[ offset + 7 ] = te[ 7 ];
  3024. array[ offset + 8 ] = te[ 8 ];
  3025. array[ offset + 9 ] = te[ 9 ];
  3026. array[ offset + 10 ] = te[ 10 ];
  3027. array[ offset + 11 ] = te[ 11 ];
  3028. array[ offset + 12 ] = te[ 12 ];
  3029. array[ offset + 13 ] = te[ 13 ];
  3030. array[ offset + 14 ] = te[ 14 ];
  3031. array[ offset + 15 ] = te[ 15 ];
  3032. return array;
  3033. }
  3034. } );
  3035. /**
  3036. * @author mrdoob / http://mrdoob.com/
  3037. * @author WestLangley / http://github.com/WestLangley
  3038. * @author bhouston / http://clara.io
  3039. */
  3040. var _matrix = new Matrix4();
  3041. var _quaternion$1 = new Quaternion();
  3042. function Euler( x, y, z, order ) {
  3043. if ( x === void 0 ) x = 0;
  3044. if ( y === void 0 ) y = 0;
  3045. if ( z === void 0 ) z = 0;
  3046. if ( order === void 0 ) order = Euler.DefaultOrder;
  3047. this._x = x;
  3048. this._y = y;
  3049. this._z = z;
  3050. this._order = order;
  3051. }
  3052. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3053. Euler.DefaultOrder = 'XYZ';
  3054. Object.defineProperties( Euler.prototype, {
  3055. x: {
  3056. get: function () {
  3057. return this._x;
  3058. },
  3059. set: function ( value ) {
  3060. this._x = value;
  3061. this._onChangeCallback();
  3062. }
  3063. },
  3064. y: {
  3065. get: function () {
  3066. return this._y;
  3067. },
  3068. set: function ( value ) {
  3069. this._y = value;
  3070. this._onChangeCallback();
  3071. }
  3072. },
  3073. z: {
  3074. get: function () {
  3075. return this._z;
  3076. },
  3077. set: function ( value ) {
  3078. this._z = value;
  3079. this._onChangeCallback();
  3080. }
  3081. },
  3082. order: {
  3083. get: function () {
  3084. return this._order;
  3085. },
  3086. set: function ( value ) {
  3087. this._order = value;
  3088. this._onChangeCallback();
  3089. }
  3090. }
  3091. } );
  3092. Object.assign( Euler.prototype, {
  3093. isEuler: true,
  3094. set: function ( x, y, z, order ) {
  3095. this._x = x;
  3096. this._y = y;
  3097. this._z = z;
  3098. this._order = order || this._order;
  3099. this._onChangeCallback();
  3100. return this;
  3101. },
  3102. clone: function () {
  3103. return new this.constructor( this._x, this._y, this._z, this._order );
  3104. },
  3105. copy: function ( euler ) {
  3106. this._x = euler._x;
  3107. this._y = euler._y;
  3108. this._z = euler._z;
  3109. this._order = euler._order;
  3110. this._onChangeCallback();
  3111. return this;
  3112. },
  3113. setFromRotationMatrix: function ( m, order, update ) {
  3114. var clamp = MathUtils.clamp;
  3115. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3116. var te = m.elements;
  3117. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3118. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3119. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3120. order = order || this._order;
  3121. switch ( order ) {
  3122. case 'XYZ':
  3123. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3124. if ( Math.abs( m13 ) < 0.9999999 ) {
  3125. this._x = Math.atan2( - m23, m33 );
  3126. this._z = Math.atan2( - m12, m11 );
  3127. } else {
  3128. this._x = Math.atan2( m32, m22 );
  3129. this._z = 0;
  3130. }
  3131. break;
  3132. case 'YXZ':
  3133. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3134. if ( Math.abs( m23 ) < 0.9999999 ) {
  3135. this._y = Math.atan2( m13, m33 );
  3136. this._z = Math.atan2( m21, m22 );
  3137. } else {
  3138. this._y = Math.atan2( - m31, m11 );
  3139. this._z = 0;
  3140. }
  3141. break;
  3142. case 'ZXY':
  3143. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3144. if ( Math.abs( m32 ) < 0.9999999 ) {
  3145. this._y = Math.atan2( - m31, m33 );
  3146. this._z = Math.atan2( - m12, m22 );
  3147. } else {
  3148. this._y = 0;
  3149. this._z = Math.atan2( m21, m11 );
  3150. }
  3151. break;
  3152. case 'ZYX':
  3153. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3154. if ( Math.abs( m31 ) < 0.9999999 ) {
  3155. this._x = Math.atan2( m32, m33 );
  3156. this._z = Math.atan2( m21, m11 );
  3157. } else {
  3158. this._x = 0;
  3159. this._z = Math.atan2( - m12, m22 );
  3160. }
  3161. break;
  3162. case 'YZX':
  3163. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3164. if ( Math.abs( m21 ) < 0.9999999 ) {
  3165. this._x = Math.atan2( - m23, m22 );
  3166. this._y = Math.atan2( - m31, m11 );
  3167. } else {
  3168. this._x = 0;
  3169. this._y = Math.atan2( m13, m33 );
  3170. }
  3171. break;
  3172. case 'XZY':
  3173. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3174. if ( Math.abs( m12 ) < 0.9999999 ) {
  3175. this._x = Math.atan2( m32, m22 );
  3176. this._y = Math.atan2( m13, m11 );
  3177. } else {
  3178. this._x = Math.atan2( - m23, m33 );
  3179. this._y = 0;
  3180. }
  3181. break;
  3182. default:
  3183. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3184. }
  3185. this._order = order;
  3186. if ( update !== false ) { this._onChangeCallback(); }
  3187. return this;
  3188. },
  3189. setFromQuaternion: function ( q, order, update ) {
  3190. _matrix.makeRotationFromQuaternion( q );
  3191. return this.setFromRotationMatrix( _matrix, order, update );
  3192. },
  3193. setFromVector3: function ( v, order ) {
  3194. return this.set( v.x, v.y, v.z, order || this._order );
  3195. },
  3196. reorder: function ( newOrder ) {
  3197. // WARNING: this discards revolution information -bhouston
  3198. _quaternion$1.setFromEuler( this );
  3199. return this.setFromQuaternion( _quaternion$1, newOrder );
  3200. },
  3201. equals: function ( euler ) {
  3202. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3203. },
  3204. fromArray: function ( array ) {
  3205. this._x = array[ 0 ];
  3206. this._y = array[ 1 ];
  3207. this._z = array[ 2 ];
  3208. if ( array[ 3 ] !== undefined ) { this._order = array[ 3 ]; }
  3209. this._onChangeCallback();
  3210. return this;
  3211. },
  3212. toArray: function ( array, offset ) {
  3213. if ( array === undefined ) { array = []; }
  3214. if ( offset === undefined ) { offset = 0; }
  3215. array[ offset ] = this._x;
  3216. array[ offset + 1 ] = this._y;
  3217. array[ offset + 2 ] = this._z;
  3218. array[ offset + 3 ] = this._order;
  3219. return array;
  3220. },
  3221. toVector3: function ( optionalResult ) {
  3222. if ( optionalResult ) {
  3223. return optionalResult.set( this._x, this._y, this._z );
  3224. } else {
  3225. return new Vector3( this._x, this._y, this._z );
  3226. }
  3227. },
  3228. _onChange: function ( callback ) {
  3229. this._onChangeCallback = callback;
  3230. return this;
  3231. },
  3232. _onChangeCallback: function () {}
  3233. } );
  3234. /**
  3235. * @author mrdoob / http://mrdoob.com/
  3236. */
  3237. function Layers() {
  3238. this.mask = 1 | 0;
  3239. }
  3240. Object.assign( Layers.prototype, {
  3241. set: function ( channel ) {
  3242. this.mask = 1 << channel | 0;
  3243. },
  3244. enable: function ( channel ) {
  3245. this.mask |= 1 << channel | 0;
  3246. },
  3247. enableAll: function () {
  3248. this.mask = 0xffffffff | 0;
  3249. },
  3250. toggle: function ( channel ) {
  3251. this.mask ^= 1 << channel | 0;
  3252. },
  3253. disable: function ( channel ) {
  3254. this.mask &= ~ ( 1 << channel | 0 );
  3255. },
  3256. disableAll: function () {
  3257. this.mask = 0;
  3258. },
  3259. test: function ( layers ) {
  3260. return ( this.mask & layers.mask ) !== 0;
  3261. }
  3262. } );
  3263. var _object3DId = 0;
  3264. var _v1$1 = new Vector3();
  3265. var _q1 = new Quaternion();
  3266. var _m1$1 = new Matrix4();
  3267. var _target = new Vector3();
  3268. var _position = new Vector3();
  3269. var _scale = new Vector3();
  3270. var _quaternion$2 = new Quaternion();
  3271. var _xAxis = new Vector3( 1, 0, 0 );
  3272. var _yAxis = new Vector3( 0, 1, 0 );
  3273. var _zAxis = new Vector3( 0, 0, 1 );
  3274. var _addedEvent = { type: 'added' };
  3275. var _removedEvent = { type: 'removed' };
  3276. /**
  3277. * @author mrdoob / http://mrdoob.com/
  3278. * @author mikael emtinger / http://gomo.se/
  3279. * @author alteredq / http://alteredqualia.com/
  3280. * @author WestLangley / http://github.com/WestLangley
  3281. * @author elephantatwork / www.elephantatwork.ch
  3282. */
  3283. function Object3D() {
  3284. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3285. this.uuid = MathUtils.generateUUID();
  3286. this.name = '';
  3287. this.type = 'Object3D';
  3288. this.parent = null;
  3289. this.children = [];
  3290. this.up = Object3D.DefaultUp.clone();
  3291. var position = new Vector3();
  3292. var rotation = new Euler();
  3293. var quaternion = new Quaternion();
  3294. var scale = new Vector3( 1, 1, 1 );
  3295. function onRotationChange() {
  3296. quaternion.setFromEuler( rotation, false );
  3297. }
  3298. function onQuaternionChange() {
  3299. rotation.setFromQuaternion( quaternion, undefined, false );
  3300. }
  3301. rotation._onChange( onRotationChange );
  3302. quaternion._onChange( onQuaternionChange );
  3303. Object.defineProperties( this, {
  3304. position: {
  3305. configurable: true,
  3306. enumerable: true,
  3307. value: position
  3308. },
  3309. rotation: {
  3310. configurable: true,
  3311. enumerable: true,
  3312. value: rotation
  3313. },
  3314. quaternion: {
  3315. configurable: true,
  3316. enumerable: true,
  3317. value: quaternion
  3318. },
  3319. scale: {
  3320. configurable: true,
  3321. enumerable: true,
  3322. value: scale
  3323. },
  3324. modelViewMatrix: {
  3325. value: new Matrix4()
  3326. },
  3327. normalMatrix: {
  3328. value: new Matrix3()
  3329. }
  3330. } );
  3331. this.matrix = new Matrix4();
  3332. this.matrixWorld = new Matrix4();
  3333. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3334. this.matrixWorldNeedsUpdate = false;
  3335. this.layers = new Layers();
  3336. this.visible = true;
  3337. this.castShadow = false;
  3338. this.receiveShadow = false;
  3339. this.frustumCulled = true;
  3340. this.renderOrder = 0;
  3341. this.userData = {};
  3342. }
  3343. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3344. Object3D.DefaultMatrixAutoUpdate = true;
  3345. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3346. constructor: Object3D,
  3347. isObject3D: true,
  3348. onBeforeRender: function () {},
  3349. onAfterRender: function () {},
  3350. applyMatrix4: function ( matrix ) {
  3351. if ( this.matrixAutoUpdate ) { this.updateMatrix(); }
  3352. this.matrix.premultiply( matrix );
  3353. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3354. },
  3355. applyQuaternion: function ( q ) {
  3356. this.quaternion.premultiply( q );
  3357. return this;
  3358. },
  3359. setRotationFromAxisAngle: function ( axis, angle ) {
  3360. // assumes axis is normalized
  3361. this.quaternion.setFromAxisAngle( axis, angle );
  3362. },
  3363. setRotationFromEuler: function ( euler ) {
  3364. this.quaternion.setFromEuler( euler, true );
  3365. },
  3366. setRotationFromMatrix: function ( m ) {
  3367. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3368. this.quaternion.setFromRotationMatrix( m );
  3369. },
  3370. setRotationFromQuaternion: function ( q ) {
  3371. // assumes q is normalized
  3372. this.quaternion.copy( q );
  3373. },
  3374. rotateOnAxis: function ( axis, angle ) {
  3375. // rotate object on axis in object space
  3376. // axis is assumed to be normalized
  3377. _q1.setFromAxisAngle( axis, angle );
  3378. this.quaternion.multiply( _q1 );
  3379. return this;
  3380. },
  3381. rotateOnWorldAxis: function ( axis, angle ) {
  3382. // rotate object on axis in world space
  3383. // axis is assumed to be normalized
  3384. // method assumes no rotated parent
  3385. _q1.setFromAxisAngle( axis, angle );
  3386. this.quaternion.premultiply( _q1 );
  3387. return this;
  3388. },
  3389. rotateX: function ( angle ) {
  3390. return this.rotateOnAxis( _xAxis, angle );
  3391. },
  3392. rotateY: function ( angle ) {
  3393. return this.rotateOnAxis( _yAxis, angle );
  3394. },
  3395. rotateZ: function ( angle ) {
  3396. return this.rotateOnAxis( _zAxis, angle );
  3397. },
  3398. translateOnAxis: function ( axis, distance ) {
  3399. // translate object by distance along axis in object space
  3400. // axis is assumed to be normalized
  3401. _v1$1.copy( axis ).applyQuaternion( this.quaternion );
  3402. this.position.add( _v1$1.multiplyScalar( distance ) );
  3403. return this;
  3404. },
  3405. translateX: function ( distance ) {
  3406. return this.translateOnAxis( _xAxis, distance );
  3407. },
  3408. translateY: function ( distance ) {
  3409. return this.translateOnAxis( _yAxis, distance );
  3410. },
  3411. translateZ: function ( distance ) {
  3412. return this.translateOnAxis( _zAxis, distance );
  3413. },
  3414. localToWorld: function ( vector ) {
  3415. return vector.applyMatrix4( this.matrixWorld );
  3416. },
  3417. worldToLocal: function ( vector ) {
  3418. return vector.applyMatrix4( _m1$1.getInverse( this.matrixWorld ) );
  3419. },
  3420. lookAt: function ( x, y, z ) {
  3421. // This method does not support objects having non-uniformly-scaled parent(s)
  3422. if ( x.isVector3 ) {
  3423. _target.copy( x );
  3424. } else {
  3425. _target.set( x, y, z );
  3426. }
  3427. var parent = this.parent;
  3428. this.updateWorldMatrix( true, false );
  3429. _position.setFromMatrixPosition( this.matrixWorld );
  3430. if ( this.isCamera || this.isLight ) {
  3431. _m1$1.lookAt( _position, _target, this.up );
  3432. } else {
  3433. _m1$1.lookAt( _target, _position, this.up );
  3434. }
  3435. this.quaternion.setFromRotationMatrix( _m1$1 );
  3436. if ( parent ) {
  3437. _m1$1.extractRotation( parent.matrixWorld );
  3438. _q1.setFromRotationMatrix( _m1$1 );
  3439. this.quaternion.premultiply( _q1.inverse() );
  3440. }
  3441. },
  3442. add: function ( object ) {
  3443. if ( arguments.length > 1 ) {
  3444. for ( var i = 0; i < arguments.length; i ++ ) {
  3445. this.add( arguments[ i ] );
  3446. }
  3447. return this;
  3448. }
  3449. if ( object === this ) {
  3450. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3451. return this;
  3452. }
  3453. if ( ( object && object.isObject3D ) ) {
  3454. if ( object.parent !== null ) {
  3455. object.parent.remove( object );
  3456. }
  3457. object.parent = this;
  3458. this.children.push( object );
  3459. object.dispatchEvent( _addedEvent );
  3460. } else {
  3461. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3462. }
  3463. return this;
  3464. },
  3465. remove: function ( object ) {
  3466. if ( arguments.length > 1 ) {
  3467. for ( var i = 0; i < arguments.length; i ++ ) {
  3468. this.remove( arguments[ i ] );
  3469. }
  3470. return this;
  3471. }
  3472. var index = this.children.indexOf( object );
  3473. if ( index !== - 1 ) {
  3474. object.parent = null;
  3475. this.children.splice( index, 1 );
  3476. object.dispatchEvent( _removedEvent );
  3477. }
  3478. return this;
  3479. },
  3480. attach: function ( object ) {
  3481. // adds object as a child of this, while maintaining the object's world transform
  3482. this.updateWorldMatrix( true, false );
  3483. _m1$1.getInverse( this.matrixWorld );
  3484. if ( object.parent !== null ) {
  3485. object.parent.updateWorldMatrix( true, false );
  3486. _m1$1.multiply( object.parent.matrixWorld );
  3487. }
  3488. object.applyMatrix4( _m1$1 );
  3489. object.updateWorldMatrix( false, false );
  3490. this.add( object );
  3491. return this;
  3492. },
  3493. getObjectById: function ( id ) {
  3494. return this.getObjectByProperty( 'id', id );
  3495. },
  3496. getObjectByName: function ( name ) {
  3497. return this.getObjectByProperty( 'name', name );
  3498. },
  3499. getObjectByProperty: function ( name, value ) {
  3500. if ( this[ name ] === value ) { return this; }
  3501. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3502. var child = this.children[ i ];
  3503. var object = child.getObjectByProperty( name, value );
  3504. if ( object !== undefined ) {
  3505. return object;
  3506. }
  3507. }
  3508. return undefined;
  3509. },
  3510. getWorldPosition: function ( target ) {
  3511. if ( target === undefined ) {
  3512. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3513. target = new Vector3();
  3514. }
  3515. this.updateMatrixWorld( true );
  3516. return target.setFromMatrixPosition( this.matrixWorld );
  3517. },
  3518. getWorldQuaternion: function ( target ) {
  3519. if ( target === undefined ) {
  3520. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3521. target = new Quaternion();
  3522. }
  3523. this.updateMatrixWorld( true );
  3524. this.matrixWorld.decompose( _position, target, _scale );
  3525. return target;
  3526. },
  3527. getWorldScale: function ( target ) {
  3528. if ( target === undefined ) {
  3529. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3530. target = new Vector3();
  3531. }
  3532. this.updateMatrixWorld( true );
  3533. this.matrixWorld.decompose( _position, _quaternion$2, target );
  3534. return target;
  3535. },
  3536. getWorldDirection: function ( target ) {
  3537. if ( target === undefined ) {
  3538. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3539. target = new Vector3();
  3540. }
  3541. this.updateMatrixWorld( true );
  3542. var e = this.matrixWorld.elements;
  3543. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3544. },
  3545. raycast: function () {},
  3546. traverse: function ( callback ) {
  3547. callback( this );
  3548. var children = this.children;
  3549. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3550. children[ i ].traverse( callback );
  3551. }
  3552. },
  3553. traverseVisible: function ( callback ) {
  3554. if ( this.visible === false ) { return; }
  3555. callback( this );
  3556. var children = this.children;
  3557. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3558. children[ i ].traverseVisible( callback );
  3559. }
  3560. },
  3561. traverseAncestors: function ( callback ) {
  3562. var parent = this.parent;
  3563. if ( parent !== null ) {
  3564. callback( parent );
  3565. parent.traverseAncestors( callback );
  3566. }
  3567. },
  3568. updateMatrix: function () {
  3569. this.matrix.compose( this.position, this.quaternion, this.scale );
  3570. this.matrixWorldNeedsUpdate = true;
  3571. },
  3572. updateMatrixWorld: function ( force ) {
  3573. if ( this.matrixAutoUpdate ) { this.updateMatrix(); }
  3574. if ( this.matrixWorldNeedsUpdate || force ) {
  3575. if ( this.parent === null ) {
  3576. this.matrixWorld.copy( this.matrix );
  3577. } else {
  3578. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3579. }
  3580. this.matrixWorldNeedsUpdate = false;
  3581. force = true;
  3582. }
  3583. // update children
  3584. var children = this.children;
  3585. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3586. children[ i ].updateMatrixWorld( force );
  3587. }
  3588. },
  3589. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3590. var parent = this.parent;
  3591. if ( updateParents === true && parent !== null ) {
  3592. parent.updateWorldMatrix( true, false );
  3593. }
  3594. if ( this.matrixAutoUpdate ) { this.updateMatrix(); }
  3595. if ( this.parent === null ) {
  3596. this.matrixWorld.copy( this.matrix );
  3597. } else {
  3598. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3599. }
  3600. // update children
  3601. if ( updateChildren === true ) {
  3602. var children = this.children;
  3603. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3604. children[ i ].updateWorldMatrix( false, true );
  3605. }
  3606. }
  3607. },
  3608. toJSON: function ( meta ) {
  3609. // meta is a string when called from JSON.stringify
  3610. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3611. var output = {};
  3612. // meta is a hash used to collect geometries, materials.
  3613. // not providing it implies that this is the root object
  3614. // being serialized.
  3615. if ( isRootObject ) {
  3616. // initialize meta obj
  3617. meta = {
  3618. geometries: {},
  3619. materials: {},
  3620. textures: {},
  3621. images: {},
  3622. shapes: {}
  3623. };
  3624. output.metadata = {
  3625. version: 4.5,
  3626. type: 'Object',
  3627. generator: 'Object3D.toJSON'
  3628. };
  3629. }
  3630. // standard Object3D serialization
  3631. var object = {};
  3632. object.uuid = this.uuid;
  3633. object.type = this.type;
  3634. if ( this.name !== '' ) { object.name = this.name; }
  3635. if ( this.castShadow === true ) { object.castShadow = true; }
  3636. if ( this.receiveShadow === true ) { object.receiveShadow = true; }
  3637. if ( this.visible === false ) { object.visible = false; }
  3638. if ( this.frustumCulled === false ) { object.frustumCulled = false; }
  3639. if ( this.renderOrder !== 0 ) { object.renderOrder = this.renderOrder; }
  3640. if ( JSON.stringify( this.userData ) !== '{}' ) { object.userData = this.userData; }
  3641. object.layers = this.layers.mask;
  3642. object.matrix = this.matrix.toArray();
  3643. if ( this.matrixAutoUpdate === false ) { object.matrixAutoUpdate = false; }
  3644. // object specific properties
  3645. if ( this.isInstancedMesh ) {
  3646. object.type = 'InstancedMesh';
  3647. object.count = this.count;
  3648. object.instanceMatrix = this.instanceMatrix.toJSON();
  3649. }
  3650. //
  3651. function serialize( library, element ) {
  3652. if ( library[ element.uuid ] === undefined ) {
  3653. library[ element.uuid ] = element.toJSON( meta );
  3654. }
  3655. return element.uuid;
  3656. }
  3657. if ( this.isMesh || this.isLine || this.isPoints ) {
  3658. object.geometry = serialize( meta.geometries, this.geometry );
  3659. var parameters = this.geometry.parameters;
  3660. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3661. var shapes = parameters.shapes;
  3662. if ( Array.isArray( shapes ) ) {
  3663. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3664. var shape = shapes[ i ];
  3665. serialize( meta.shapes, shape );
  3666. }
  3667. } else {
  3668. serialize( meta.shapes, shapes );
  3669. }
  3670. }
  3671. }
  3672. if ( this.material !== undefined ) {
  3673. if ( Array.isArray( this.material ) ) {
  3674. var uuids = [];
  3675. for ( var i$1 = 0, l$1 = this.material.length; i$1 < l$1; i$1 ++ ) {
  3676. uuids.push( serialize( meta.materials, this.material[ i$1 ] ) );
  3677. }
  3678. object.material = uuids;
  3679. } else {
  3680. object.material = serialize( meta.materials, this.material );
  3681. }
  3682. }
  3683. //
  3684. if ( this.children.length > 0 ) {
  3685. object.children = [];
  3686. for ( var i$2 = 0; i$2 < this.children.length; i$2 ++ ) {
  3687. object.children.push( this.children[ i$2 ].toJSON( meta ).object );
  3688. }
  3689. }
  3690. if ( isRootObject ) {
  3691. var geometries = extractFromCache( meta.geometries );
  3692. var materials = extractFromCache( meta.materials );
  3693. var textures = extractFromCache( meta.textures );
  3694. var images = extractFromCache( meta.images );
  3695. var shapes$1 = extractFromCache( meta.shapes );
  3696. if ( geometries.length > 0 ) { output.geometries = geometries; }
  3697. if ( materials.length > 0 ) { output.materials = materials; }
  3698. if ( textures.length > 0 ) { output.textures = textures; }
  3699. if ( images.length > 0 ) { output.images = images; }
  3700. if ( shapes$1.length > 0 ) { output.shapes = shapes$1; }
  3701. }
  3702. output.object = object;
  3703. return output;
  3704. // extract data from the cache hash
  3705. // remove metadata on each item
  3706. // and return as array
  3707. function extractFromCache( cache ) {
  3708. var values = [];
  3709. for ( var key in cache ) {
  3710. var data = cache[ key ];
  3711. delete data.metadata;
  3712. values.push( data );
  3713. }
  3714. return values;
  3715. }
  3716. },
  3717. clone: function ( recursive ) {
  3718. return new this.constructor().copy( this, recursive );
  3719. },
  3720. copy: function ( source, recursive ) {
  3721. if ( recursive === undefined ) { recursive = true; }
  3722. this.name = source.name;
  3723. this.up.copy( source.up );
  3724. this.position.copy( source.position );
  3725. this.quaternion.copy( source.quaternion );
  3726. this.scale.copy( source.scale );
  3727. this.matrix.copy( source.matrix );
  3728. this.matrixWorld.copy( source.matrixWorld );
  3729. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3730. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3731. this.layers.mask = source.layers.mask;
  3732. this.visible = source.visible;
  3733. this.castShadow = source.castShadow;
  3734. this.receiveShadow = source.receiveShadow;
  3735. this.frustumCulled = source.frustumCulled;
  3736. this.renderOrder = source.renderOrder;
  3737. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3738. if ( recursive === true ) {
  3739. for ( var i = 0; i < source.children.length; i ++ ) {
  3740. var child = source.children[ i ];
  3741. this.add( child.clone() );
  3742. }
  3743. }
  3744. return this;
  3745. }
  3746. } );
  3747. /**
  3748. * @author mrdoob / http://mrdoob.com/
  3749. */
  3750. function Scene() {
  3751. Object3D.call( this );
  3752. this.type = 'Scene';
  3753. this.background = null;
  3754. this.environment = null;
  3755. this.fog = null;
  3756. this.overrideMaterial = null;
  3757. this.autoUpdate = true; // checked by the renderer
  3758. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3759. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3760. }
  3761. }
  3762. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3763. constructor: Scene,
  3764. isScene: true,
  3765. copy: function ( source, recursive ) {
  3766. Object3D.prototype.copy.call( this, source, recursive );
  3767. if ( source.background !== null ) { this.background = source.background.clone(); }
  3768. if ( source.environment !== null ) { this.environment = source.environment.clone(); }
  3769. if ( source.fog !== null ) { this.fog = source.fog.clone(); }
  3770. if ( source.overrideMaterial !== null ) { this.overrideMaterial = source.overrideMaterial.clone(); }
  3771. this.autoUpdate = source.autoUpdate;
  3772. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3773. return this;
  3774. },
  3775. toJSON: function ( meta ) {
  3776. var data = Object3D.prototype.toJSON.call( this, meta );
  3777. if ( this.background !== null ) { data.object.background = this.background.toJSON( meta ); }
  3778. if ( this.environment !== null ) { data.object.environment = this.environment.toJSON( meta ); }
  3779. if ( this.fog !== null ) { data.object.fog = this.fog.toJSON(); }
  3780. return data;
  3781. },
  3782. dispose: function () {
  3783. this.dispatchEvent( { type: 'dispose' } );
  3784. }
  3785. } );
  3786. var _points = [
  3787. new Vector3(),
  3788. new Vector3(),
  3789. new Vector3(),
  3790. new Vector3(),
  3791. new Vector3(),
  3792. new Vector3(),
  3793. new Vector3(),
  3794. new Vector3()
  3795. ];
  3796. var _vector$1 = new Vector3();
  3797. var _box = new Box3();
  3798. // triangle centered vertices
  3799. var _v0 = new Vector3();
  3800. var _v1$2 = new Vector3();
  3801. var _v2 = new Vector3();
  3802. // triangle edge vectors
  3803. var _f0 = new Vector3();
  3804. var _f1 = new Vector3();
  3805. var _f2 = new Vector3();
  3806. var _center = new Vector3();
  3807. var _extents = new Vector3();
  3808. var _triangleNormal = new Vector3();
  3809. var _testAxis = new Vector3();
  3810. /**
  3811. * @author bhouston / http://clara.io
  3812. * @author WestLangley / http://github.com/WestLangley
  3813. */
  3814. function Box3( min, max ) {
  3815. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3816. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3817. }
  3818. Object.assign( Box3.prototype, {
  3819. isBox3: true,
  3820. set: function ( min, max ) {
  3821. this.min.copy( min );
  3822. this.max.copy( max );
  3823. return this;
  3824. },
  3825. setFromArray: function ( array ) {
  3826. var minX = + Infinity;
  3827. var minY = + Infinity;
  3828. var minZ = + Infinity;
  3829. var maxX = - Infinity;
  3830. var maxY = - Infinity;
  3831. var maxZ = - Infinity;
  3832. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3833. var x = array[ i ];
  3834. var y = array[ i + 1 ];
  3835. var z = array[ i + 2 ];
  3836. if ( x < minX ) { minX = x; }
  3837. if ( y < minY ) { minY = y; }
  3838. if ( z < minZ ) { minZ = z; }
  3839. if ( x > maxX ) { maxX = x; }
  3840. if ( y > maxY ) { maxY = y; }
  3841. if ( z > maxZ ) { maxZ = z; }
  3842. }
  3843. this.min.set( minX, minY, minZ );
  3844. this.max.set( maxX, maxY, maxZ );
  3845. return this;
  3846. },
  3847. setFromBufferAttribute: function ( attribute ) {
  3848. var minX = + Infinity;
  3849. var minY = + Infinity;
  3850. var minZ = + Infinity;
  3851. var maxX = - Infinity;
  3852. var maxY = - Infinity;
  3853. var maxZ = - Infinity;
  3854. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3855. var x = attribute.getX( i );
  3856. var y = attribute.getY( i );
  3857. var z = attribute.getZ( i );
  3858. if ( x < minX ) { minX = x; }
  3859. if ( y < minY ) { minY = y; }
  3860. if ( z < minZ ) { minZ = z; }
  3861. if ( x > maxX ) { maxX = x; }
  3862. if ( y > maxY ) { maxY = y; }
  3863. if ( z > maxZ ) { maxZ = z; }
  3864. }
  3865. this.min.set( minX, minY, minZ );
  3866. this.max.set( maxX, maxY, maxZ );
  3867. return this;
  3868. },
  3869. setFromPoints: function ( points ) {
  3870. this.makeEmpty();
  3871. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3872. this.expandByPoint( points[ i ] );
  3873. }
  3874. return this;
  3875. },
  3876. setFromCenterAndSize: function ( center, size ) {
  3877. var halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 );
  3878. this.min.copy( center ).sub( halfSize );
  3879. this.max.copy( center ).add( halfSize );
  3880. return this;
  3881. },
  3882. setFromObject: function ( object ) {
  3883. this.makeEmpty();
  3884. return this.expandByObject( object );
  3885. },
  3886. clone: function () {
  3887. return new this.constructor().copy( this );
  3888. },
  3889. copy: function ( box ) {
  3890. this.min.copy( box.min );
  3891. this.max.copy( box.max );
  3892. return this;
  3893. },
  3894. makeEmpty: function () {
  3895. this.min.x = this.min.y = this.min.z = + Infinity;
  3896. this.max.x = this.max.y = this.max.z = - Infinity;
  3897. return this;
  3898. },
  3899. isEmpty: function () {
  3900. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3901. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3902. },
  3903. getCenter: function ( target ) {
  3904. if ( target === undefined ) {
  3905. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3906. target = new Vector3();
  3907. }
  3908. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3909. },
  3910. getSize: function ( target ) {
  3911. if ( target === undefined ) {
  3912. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3913. target = new Vector3();
  3914. }
  3915. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3916. },
  3917. expandByPoint: function ( point ) {
  3918. this.min.min( point );
  3919. this.max.max( point );
  3920. return this;
  3921. },
  3922. expandByVector: function ( vector ) {
  3923. this.min.sub( vector );
  3924. this.max.add( vector );
  3925. return this;
  3926. },
  3927. expandByScalar: function ( scalar ) {
  3928. this.min.addScalar( - scalar );
  3929. this.max.addScalar( scalar );
  3930. return this;
  3931. },
  3932. expandByObject: function ( object ) {
  3933. // Computes the world-axis-aligned bounding box of an object (including its children),
  3934. // accounting for both the object's, and children's, world transforms
  3935. object.updateWorldMatrix( false, false );
  3936. var geometry = object.geometry;
  3937. if ( geometry !== undefined ) {
  3938. if ( geometry.boundingBox === null ) {
  3939. geometry.computeBoundingBox();
  3940. }
  3941. _box.copy( geometry.boundingBox );
  3942. _box.applyMatrix4( object.matrixWorld );
  3943. this.union( _box );
  3944. }
  3945. var children = object.children;
  3946. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3947. this.expandByObject( children[ i ] );
  3948. }
  3949. return this;
  3950. },
  3951. containsPoint: function ( point ) {
  3952. return point.x < this.min.x || point.x > this.max.x ||
  3953. point.y < this.min.y || point.y > this.max.y ||
  3954. point.z < this.min.z || point.z > this.max.z ? false : true;
  3955. },
  3956. containsBox: function ( box ) {
  3957. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3958. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3959. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3960. },
  3961. getParameter: function ( point, target ) {
  3962. // This can potentially have a divide by zero if the box
  3963. // has a size dimension of 0.
  3964. if ( target === undefined ) {
  3965. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3966. target = new Vector3();
  3967. }
  3968. return target.set(
  3969. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3970. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3971. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3972. );
  3973. },
  3974. intersectsBox: function ( box ) {
  3975. // using 6 splitting planes to rule out intersections.
  3976. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3977. box.max.y < this.min.y || box.min.y > this.max.y ||
  3978. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3979. },
  3980. intersectsSphere: function ( sphere ) {
  3981. // Find the point on the AABB closest to the sphere center.
  3982. this.clampPoint( sphere.center, _vector$1 );
  3983. // If that point is inside the sphere, the AABB and sphere intersect.
  3984. return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3985. },
  3986. intersectsPlane: function ( plane ) {
  3987. // We compute the minimum and maximum dot product values. If those values
  3988. // are on the same side (back or front) of the plane, then there is no intersection.
  3989. var min, max;
  3990. if ( plane.normal.x > 0 ) {
  3991. min = plane.normal.x * this.min.x;
  3992. max = plane.normal.x * this.max.x;
  3993. } else {
  3994. min = plane.normal.x * this.max.x;
  3995. max = plane.normal.x * this.min.x;
  3996. }
  3997. if ( plane.normal.y > 0 ) {
  3998. min += plane.normal.y * this.min.y;
  3999. max += plane.normal.y * this.max.y;
  4000. } else {
  4001. min += plane.normal.y * this.max.y;
  4002. max += plane.normal.y * this.min.y;
  4003. }
  4004. if ( plane.normal.z > 0 ) {
  4005. min += plane.normal.z * this.min.z;
  4006. max += plane.normal.z * this.max.z;
  4007. } else {
  4008. min += plane.normal.z * this.max.z;
  4009. max += plane.normal.z * this.min.z;
  4010. }
  4011. return ( min <= - plane.constant && max >= - plane.constant );
  4012. },
  4013. intersectsTriangle: function ( triangle ) {
  4014. if ( this.isEmpty() ) {
  4015. return false;
  4016. }
  4017. // compute box center and extents
  4018. this.getCenter( _center );
  4019. _extents.subVectors( this.max, _center );
  4020. // translate triangle to aabb origin
  4021. _v0.subVectors( triangle.a, _center );
  4022. _v1$2.subVectors( triangle.b, _center );
  4023. _v2.subVectors( triangle.c, _center );
  4024. // compute edge vectors for triangle
  4025. _f0.subVectors( _v1$2, _v0 );
  4026. _f1.subVectors( _v2, _v1$2 );
  4027. _f2.subVectors( _v0, _v2 );
  4028. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  4029. // 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
  4030. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  4031. var axes = [
  4032. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  4033. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  4034. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  4035. ];
  4036. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  4037. return false;
  4038. }
  4039. // test 3 face normals from the aabb
  4040. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  4041. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  4042. return false;
  4043. }
  4044. // finally testing the face normal of the triangle
  4045. // use already existing triangle edge vectors here
  4046. _triangleNormal.crossVectors( _f0, _f1 );
  4047. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  4048. return satForAxes( axes, _v0, _v1$2, _v2, _extents );
  4049. },
  4050. clampPoint: function ( point, target ) {
  4051. if ( target === undefined ) {
  4052. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  4053. target = new Vector3();
  4054. }
  4055. return target.copy( point ).clamp( this.min, this.max );
  4056. },
  4057. distanceToPoint: function ( point ) {
  4058. var clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max );
  4059. return clampedPoint.sub( point ).length();
  4060. },
  4061. getBoundingSphere: function ( target ) {
  4062. if ( target === undefined ) {
  4063. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  4064. //target = new Sphere(); // removed to avoid cyclic dependency
  4065. }
  4066. this.getCenter( target.center );
  4067. target.radius = this.getSize( _vector$1 ).length() * 0.5;
  4068. return target;
  4069. },
  4070. intersect: function ( box ) {
  4071. this.min.max( box.min );
  4072. this.max.min( box.max );
  4073. // 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.
  4074. if ( this.isEmpty() ) { this.makeEmpty(); }
  4075. return this;
  4076. },
  4077. union: function ( box ) {
  4078. this.min.min( box.min );
  4079. this.max.max( box.max );
  4080. return this;
  4081. },
  4082. applyMatrix4: function ( matrix ) {
  4083. // transform of empty box is an empty box.
  4084. if ( this.isEmpty() ) { return this; }
  4085. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4086. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4087. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4088. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4089. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4090. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4091. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4092. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4093. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4094. this.setFromPoints( _points );
  4095. return this;
  4096. },
  4097. translate: function ( offset ) {
  4098. this.min.add( offset );
  4099. this.max.add( offset );
  4100. return this;
  4101. },
  4102. equals: function ( box ) {
  4103. return box.min.equals( this.min ) && box.max.equals( this.max );
  4104. }
  4105. } );
  4106. function satForAxes( axes, v0, v1, v2, extents ) {
  4107. for ( var i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  4108. _testAxis.fromArray( axes, i );
  4109. // project the aabb onto the seperating axis
  4110. var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  4111. // project all 3 vertices of the triangle onto the seperating axis
  4112. var p0 = v0.dot( _testAxis );
  4113. var p1 = v1.dot( _testAxis );
  4114. var p2 = v2.dot( _testAxis );
  4115. // actual test, basically see if either of the most extreme of the triangle points intersects r
  4116. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  4117. // points of the projected triangle are outside the projected half-length of the aabb
  4118. // the axis is seperating and we can exit
  4119. return false;
  4120. }
  4121. }
  4122. return true;
  4123. }
  4124. var _box$1 = new Box3();
  4125. /**
  4126. * @author bhouston / http://clara.io
  4127. * @author mrdoob / http://mrdoob.com/
  4128. */
  4129. function Sphere( center, radius ) {
  4130. this.center = ( center !== undefined ) ? center : new Vector3();
  4131. this.radius = ( radius !== undefined ) ? radius : - 1;
  4132. }
  4133. Object.assign( Sphere.prototype, {
  4134. set: function ( center, radius ) {
  4135. this.center.copy( center );
  4136. this.radius = radius;
  4137. return this;
  4138. },
  4139. setFromPoints: function ( points, optionalCenter ) {
  4140. var center = this.center;
  4141. if ( optionalCenter !== undefined ) {
  4142. center.copy( optionalCenter );
  4143. } else {
  4144. _box$1.setFromPoints( points ).getCenter( center );
  4145. }
  4146. var maxRadiusSq = 0;
  4147. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4148. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4149. }
  4150. this.radius = Math.sqrt( maxRadiusSq );
  4151. return this;
  4152. },
  4153. clone: function () {
  4154. return new this.constructor().copy( this );
  4155. },
  4156. copy: function ( sphere ) {
  4157. this.center.copy( sphere.center );
  4158. this.radius = sphere.radius;
  4159. return this;
  4160. },
  4161. isEmpty: function () {
  4162. return ( this.radius < 0 );
  4163. },
  4164. makeEmpty: function () {
  4165. this.center.set( 0, 0, 0 );
  4166. this.radius = - 1;
  4167. return this;
  4168. },
  4169. containsPoint: function ( point ) {
  4170. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4171. },
  4172. distanceToPoint: function ( point ) {
  4173. return ( point.distanceTo( this.center ) - this.radius );
  4174. },
  4175. intersectsSphere: function ( sphere ) {
  4176. var radiusSum = this.radius + sphere.radius;
  4177. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4178. },
  4179. intersectsBox: function ( box ) {
  4180. return box.intersectsSphere( this );
  4181. },
  4182. intersectsPlane: function ( plane ) {
  4183. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4184. },
  4185. clampPoint: function ( point, target ) {
  4186. var deltaLengthSq = this.center.distanceToSquared( point );
  4187. if ( target === undefined ) {
  4188. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4189. target = new Vector3();
  4190. }
  4191. target.copy( point );
  4192. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4193. target.sub( this.center ).normalize();
  4194. target.multiplyScalar( this.radius ).add( this.center );
  4195. }
  4196. return target;
  4197. },
  4198. getBoundingBox: function ( target ) {
  4199. if ( target === undefined ) {
  4200. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4201. target = new Box3();
  4202. }
  4203. if ( this.isEmpty() ) {
  4204. // Empty sphere produces empty bounding box
  4205. target.makeEmpty();
  4206. return target;
  4207. }
  4208. target.set( this.center, this.center );
  4209. target.expandByScalar( this.radius );
  4210. return target;
  4211. },
  4212. applyMatrix4: function ( matrix ) {
  4213. this.center.applyMatrix4( matrix );
  4214. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4215. return this;
  4216. },
  4217. translate: function ( offset ) {
  4218. this.center.add( offset );
  4219. return this;
  4220. },
  4221. equals: function ( sphere ) {
  4222. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4223. }
  4224. } );
  4225. var _vector$2 = new Vector3();
  4226. var _segCenter = new Vector3();
  4227. var _segDir = new Vector3();
  4228. var _diff = new Vector3();
  4229. var _edge1 = new Vector3();
  4230. var _edge2 = new Vector3();
  4231. var _normal = new Vector3();
  4232. /**
  4233. * @author bhouston / http://clara.io
  4234. */
  4235. function Ray( origin, direction ) {
  4236. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4237. this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 );
  4238. }
  4239. Object.assign( Ray.prototype, {
  4240. set: function ( origin, direction ) {
  4241. this.origin.copy( origin );
  4242. this.direction.copy( direction );
  4243. return this;
  4244. },
  4245. clone: function () {
  4246. return new this.constructor().copy( this );
  4247. },
  4248. copy: function ( ray ) {
  4249. this.origin.copy( ray.origin );
  4250. this.direction.copy( ray.direction );
  4251. return this;
  4252. },
  4253. at: function ( t, target ) {
  4254. if ( target === undefined ) {
  4255. console.warn( 'THREE.Ray: .at() target is now required' );
  4256. target = new Vector3();
  4257. }
  4258. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4259. },
  4260. lookAt: function ( v ) {
  4261. this.direction.copy( v ).sub( this.origin ).normalize();
  4262. return this;
  4263. },
  4264. recast: function ( t ) {
  4265. this.origin.copy( this.at( t, _vector$2 ) );
  4266. return this;
  4267. },
  4268. closestPointToPoint: function ( point, target ) {
  4269. if ( target === undefined ) {
  4270. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4271. target = new Vector3();
  4272. }
  4273. target.subVectors( point, this.origin );
  4274. var directionDistance = target.dot( this.direction );
  4275. if ( directionDistance < 0 ) {
  4276. return target.copy( this.origin );
  4277. }
  4278. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4279. },
  4280. distanceToPoint: function ( point ) {
  4281. return Math.sqrt( this.distanceSqToPoint( point ) );
  4282. },
  4283. distanceSqToPoint: function ( point ) {
  4284. var directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction );
  4285. // point behind the ray
  4286. if ( directionDistance < 0 ) {
  4287. return this.origin.distanceToSquared( point );
  4288. }
  4289. _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4290. return _vector$2.distanceToSquared( point );
  4291. },
  4292. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4293. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4294. // It returns the min distance between the ray and the segment
  4295. // defined by v0 and v1
  4296. // It can also set two optional targets :
  4297. // - The closest point on the ray
  4298. // - The closest point on the segment
  4299. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4300. _segDir.copy( v1 ).sub( v0 ).normalize();
  4301. _diff.copy( this.origin ).sub( _segCenter );
  4302. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4303. var a01 = - this.direction.dot( _segDir );
  4304. var b0 = _diff.dot( this.direction );
  4305. var b1 = - _diff.dot( _segDir );
  4306. var c = _diff.lengthSq();
  4307. var det = Math.abs( 1 - a01 * a01 );
  4308. var s0, s1, sqrDist, extDet;
  4309. if ( det > 0 ) {
  4310. // The ray and segment are not parallel.
  4311. s0 = a01 * b1 - b0;
  4312. s1 = a01 * b0 - b1;
  4313. extDet = segExtent * det;
  4314. if ( s0 >= 0 ) {
  4315. if ( s1 >= - extDet ) {
  4316. if ( s1 <= extDet ) {
  4317. // region 0
  4318. // Minimum at interior points of ray and segment.
  4319. var invDet = 1 / det;
  4320. s0 *= invDet;
  4321. s1 *= invDet;
  4322. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4323. } else {
  4324. // region 1
  4325. s1 = segExtent;
  4326. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4327. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4328. }
  4329. } else {
  4330. // region 5
  4331. s1 = - segExtent;
  4332. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4333. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4334. }
  4335. } else {
  4336. if ( s1 <= - extDet ) {
  4337. // region 4
  4338. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4339. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4340. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4341. } else if ( s1 <= extDet ) {
  4342. // region 3
  4343. s0 = 0;
  4344. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4345. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4346. } else {
  4347. // region 2
  4348. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4349. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4350. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4351. }
  4352. }
  4353. } else {
  4354. // Ray and segment are parallel.
  4355. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4356. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4357. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4358. }
  4359. if ( optionalPointOnRay ) {
  4360. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4361. }
  4362. if ( optionalPointOnSegment ) {
  4363. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  4364. }
  4365. return sqrDist;
  4366. },
  4367. intersectSphere: function ( sphere, target ) {
  4368. _vector$2.subVectors( sphere.center, this.origin );
  4369. var tca = _vector$2.dot( this.direction );
  4370. var d2 = _vector$2.dot( _vector$2 ) - tca * tca;
  4371. var radius2 = sphere.radius * sphere.radius;
  4372. if ( d2 > radius2 ) { return null; }
  4373. var thc = Math.sqrt( radius2 - d2 );
  4374. // t0 = first intersect point - entrance on front of sphere
  4375. var t0 = tca - thc;
  4376. // t1 = second intersect point - exit point on back of sphere
  4377. var t1 = tca + thc;
  4378. // test to see if both t0 and t1 are behind the ray - if so, return null
  4379. if ( t0 < 0 && t1 < 0 ) { return null; }
  4380. // test to see if t0 is behind the ray:
  4381. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4382. // in order to always return an intersect point that is in front of the ray.
  4383. if ( t0 < 0 ) { return this.at( t1, target ); }
  4384. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4385. return this.at( t0, target );
  4386. },
  4387. intersectsSphere: function ( sphere ) {
  4388. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4389. },
  4390. distanceToPlane: function ( plane ) {
  4391. var denominator = plane.normal.dot( this.direction );
  4392. if ( denominator === 0 ) {
  4393. // line is coplanar, return origin
  4394. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4395. return 0;
  4396. }
  4397. // Null is preferable to undefined since undefined means.... it is undefined
  4398. return null;
  4399. }
  4400. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4401. // Return if the ray never intersects the plane
  4402. return t >= 0 ? t : null;
  4403. },
  4404. intersectPlane: function ( plane, target ) {
  4405. var t = this.distanceToPlane( plane );
  4406. if ( t === null ) {
  4407. return null;
  4408. }
  4409. return this.at( t, target );
  4410. },
  4411. intersectsPlane: function ( plane ) {
  4412. // check if the ray lies on the plane first
  4413. var distToPoint = plane.distanceToPoint( this.origin );
  4414. if ( distToPoint === 0 ) {
  4415. return true;
  4416. }
  4417. var denominator = plane.normal.dot( this.direction );
  4418. if ( denominator * distToPoint < 0 ) {
  4419. return true;
  4420. }
  4421. // ray origin is behind the plane (and is pointing behind it)
  4422. return false;
  4423. },
  4424. intersectBox: function ( box, target ) {
  4425. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4426. var invdirx = 1 / this.direction.x,
  4427. invdiry = 1 / this.direction.y,
  4428. invdirz = 1 / this.direction.z;
  4429. var origin = this.origin;
  4430. if ( invdirx >= 0 ) {
  4431. tmin = ( box.min.x - origin.x ) * invdirx;
  4432. tmax = ( box.max.x - origin.x ) * invdirx;
  4433. } else {
  4434. tmin = ( box.max.x - origin.x ) * invdirx;
  4435. tmax = ( box.min.x - origin.x ) * invdirx;
  4436. }
  4437. if ( invdiry >= 0 ) {
  4438. tymin = ( box.min.y - origin.y ) * invdiry;
  4439. tymax = ( box.max.y - origin.y ) * invdiry;
  4440. } else {
  4441. tymin = ( box.max.y - origin.y ) * invdiry;
  4442. tymax = ( box.min.y - origin.y ) * invdiry;
  4443. }
  4444. if ( ( tmin > tymax ) || ( tymin > tmax ) ) { return null; }
  4445. // These lines also handle the case where tmin or tmax is NaN
  4446. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4447. if ( tymin > tmin || tmin !== tmin ) { tmin = tymin; }
  4448. if ( tymax < tmax || tmax !== tmax ) { tmax = tymax; }
  4449. if ( invdirz >= 0 ) {
  4450. tzmin = ( box.min.z - origin.z ) * invdirz;
  4451. tzmax = ( box.max.z - origin.z ) * invdirz;
  4452. } else {
  4453. tzmin = ( box.max.z - origin.z ) * invdirz;
  4454. tzmax = ( box.min.z - origin.z ) * invdirz;
  4455. }
  4456. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) { return null; }
  4457. if ( tzmin > tmin || tmin !== tmin ) { tmin = tzmin; }
  4458. if ( tzmax < tmax || tmax !== tmax ) { tmax = tzmax; }
  4459. //return point closest to the ray (positive side)
  4460. if ( tmax < 0 ) { return null; }
  4461. return this.at( tmin >= 0 ? tmin : tmax, target );
  4462. },
  4463. intersectsBox: function ( box ) {
  4464. return this.intersectBox( box, _vector$2 ) !== null;
  4465. },
  4466. intersectTriangle: function ( a, b, c, backfaceCulling, target ) {
  4467. // Compute the offset origin, edges, and normal.
  4468. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4469. _edge1.subVectors( b, a );
  4470. _edge2.subVectors( c, a );
  4471. _normal.crossVectors( _edge1, _edge2 );
  4472. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4473. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4474. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4475. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4476. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4477. var DdN = this.direction.dot( _normal );
  4478. var sign;
  4479. if ( DdN > 0 ) {
  4480. if ( backfaceCulling ) { return null; }
  4481. sign = 1;
  4482. } else if ( DdN < 0 ) {
  4483. sign = - 1;
  4484. DdN = - DdN;
  4485. } else {
  4486. return null;
  4487. }
  4488. _diff.subVectors( this.origin, a );
  4489. var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  4490. // b1 < 0, no intersection
  4491. if ( DdQxE2 < 0 ) {
  4492. return null;
  4493. }
  4494. var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  4495. // b2 < 0, no intersection
  4496. if ( DdE1xQ < 0 ) {
  4497. return null;
  4498. }
  4499. // b1+b2 > 1, no intersection
  4500. if ( DdQxE2 + DdE1xQ > DdN ) {
  4501. return null;
  4502. }
  4503. // Line intersects triangle, check if ray does.
  4504. var QdN = - sign * _diff.dot( _normal );
  4505. // t < 0, no intersection
  4506. if ( QdN < 0 ) {
  4507. return null;
  4508. }
  4509. // Ray intersects triangle.
  4510. return this.at( QdN / DdN, target );
  4511. },
  4512. applyMatrix4: function ( matrix4 ) {
  4513. this.origin.applyMatrix4( matrix4 );
  4514. this.direction.transformDirection( matrix4 );
  4515. return this;
  4516. },
  4517. equals: function ( ray ) {
  4518. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4519. }
  4520. } );
  4521. /**
  4522. * @author bhouston / http://clara.io
  4523. */
  4524. var _vector1 = new Vector3();
  4525. var _vector2 = new Vector3();
  4526. var _normalMatrix = new Matrix3();
  4527. function Plane( normal, constant ) {
  4528. // normal is assumed to be normalized
  4529. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  4530. this.constant = ( constant !== undefined ) ? constant : 0;
  4531. }
  4532. Object.assign( Plane.prototype, {
  4533. isPlane: true,
  4534. set: function ( normal, constant ) {
  4535. this.normal.copy( normal );
  4536. this.constant = constant;
  4537. return this;
  4538. },
  4539. setComponents: function ( x, y, z, w ) {
  4540. this.normal.set( x, y, z );
  4541. this.constant = w;
  4542. return this;
  4543. },
  4544. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  4545. this.normal.copy( normal );
  4546. this.constant = - point.dot( this.normal );
  4547. return this;
  4548. },
  4549. setFromCoplanarPoints: function ( a, b, c ) {
  4550. var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4551. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4552. this.setFromNormalAndCoplanarPoint( normal, a );
  4553. return this;
  4554. },
  4555. clone: function () {
  4556. return new this.constructor().copy( this );
  4557. },
  4558. copy: function ( plane ) {
  4559. this.normal.copy( plane.normal );
  4560. this.constant = plane.constant;
  4561. return this;
  4562. },
  4563. normalize: function () {
  4564. // Note: will lead to a divide by zero if the plane is invalid.
  4565. var inverseNormalLength = 1.0 / this.normal.length();
  4566. this.normal.multiplyScalar( inverseNormalLength );
  4567. this.constant *= inverseNormalLength;
  4568. return this;
  4569. },
  4570. negate: function () {
  4571. this.constant *= - 1;
  4572. this.normal.negate();
  4573. return this;
  4574. },
  4575. distanceToPoint: function ( point ) {
  4576. return this.normal.dot( point ) + this.constant;
  4577. },
  4578. distanceToSphere: function ( sphere ) {
  4579. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4580. },
  4581. projectPoint: function ( point, target ) {
  4582. if ( target === undefined ) {
  4583. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4584. target = new Vector3();
  4585. }
  4586. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4587. },
  4588. intersectLine: function ( line, target ) {
  4589. if ( target === undefined ) {
  4590. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4591. target = new Vector3();
  4592. }
  4593. var direction = line.delta( _vector1 );
  4594. var denominator = this.normal.dot( direction );
  4595. if ( denominator === 0 ) {
  4596. // line is coplanar, return origin
  4597. if ( this.distanceToPoint( line.start ) === 0 ) {
  4598. return target.copy( line.start );
  4599. }
  4600. // Unsure if this is the correct method to handle this case.
  4601. return undefined;
  4602. }
  4603. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4604. if ( t < 0 || t > 1 ) {
  4605. return undefined;
  4606. }
  4607. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4608. },
  4609. intersectsLine: function ( line ) {
  4610. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4611. var startSign = this.distanceToPoint( line.start );
  4612. var endSign = this.distanceToPoint( line.end );
  4613. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4614. },
  4615. intersectsBox: function ( box ) {
  4616. return box.intersectsPlane( this );
  4617. },
  4618. intersectsSphere: function ( sphere ) {
  4619. return sphere.intersectsPlane( this );
  4620. },
  4621. coplanarPoint: function ( target ) {
  4622. if ( target === undefined ) {
  4623. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4624. target = new Vector3();
  4625. }
  4626. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4627. },
  4628. applyMatrix4: function ( matrix, optionalNormalMatrix ) {
  4629. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4630. var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4631. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4632. this.constant = - referencePoint.dot( normal );
  4633. return this;
  4634. },
  4635. translate: function ( offset ) {
  4636. this.constant -= offset.dot( this.normal );
  4637. return this;
  4638. },
  4639. equals: function ( plane ) {
  4640. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4641. }
  4642. } );
  4643. /**
  4644. * @author bhouston / http://clara.io
  4645. * @author mrdoob / http://mrdoob.com/
  4646. */
  4647. var _v0$1 = new Vector3();
  4648. var _v1$3 = new Vector3();
  4649. var _v2$1 = new Vector3();
  4650. var _v3 = new Vector3();
  4651. var _vab = new Vector3();
  4652. var _vac = new Vector3();
  4653. var _vbc = new Vector3();
  4654. var _vap = new Vector3();
  4655. var _vbp = new Vector3();
  4656. var _vcp = new Vector3();
  4657. function Triangle( a, b, c ) {
  4658. this.a = ( a !== undefined ) ? a : new Vector3();
  4659. this.b = ( b !== undefined ) ? b : new Vector3();
  4660. this.c = ( c !== undefined ) ? c : new Vector3();
  4661. }
  4662. Object.assign( Triangle, {
  4663. getNormal: function ( a, b, c, target ) {
  4664. if ( target === undefined ) {
  4665. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4666. target = new Vector3();
  4667. }
  4668. target.subVectors( c, b );
  4669. _v0$1.subVectors( a, b );
  4670. target.cross( _v0$1 );
  4671. var targetLengthSq = target.lengthSq();
  4672. if ( targetLengthSq > 0 ) {
  4673. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4674. }
  4675. return target.set( 0, 0, 0 );
  4676. },
  4677. // static/instance method to calculate barycentric coordinates
  4678. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4679. getBarycoord: function ( point, a, b, c, target ) {
  4680. _v0$1.subVectors( c, a );
  4681. _v1$3.subVectors( b, a );
  4682. _v2$1.subVectors( point, a );
  4683. var dot00 = _v0$1.dot( _v0$1 );
  4684. var dot01 = _v0$1.dot( _v1$3 );
  4685. var dot02 = _v0$1.dot( _v2$1 );
  4686. var dot11 = _v1$3.dot( _v1$3 );
  4687. var dot12 = _v1$3.dot( _v2$1 );
  4688. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4689. if ( target === undefined ) {
  4690. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4691. target = new Vector3();
  4692. }
  4693. // collinear or singular triangle
  4694. if ( denom === 0 ) {
  4695. // arbitrary location outside of triangle?
  4696. // not sure if this is the best idea, maybe should be returning undefined
  4697. return target.set( - 2, - 1, - 1 );
  4698. }
  4699. var invDenom = 1 / denom;
  4700. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4701. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4702. // barycentric coordinates must always sum to 1
  4703. return target.set( 1 - u - v, v, u );
  4704. },
  4705. containsPoint: function ( point, a, b, c ) {
  4706. Triangle.getBarycoord( point, a, b, c, _v3 );
  4707. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4708. },
  4709. getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4710. this.getBarycoord( point, p1, p2, p3, _v3 );
  4711. target.set( 0, 0 );
  4712. target.addScaledVector( uv1, _v3.x );
  4713. target.addScaledVector( uv2, _v3.y );
  4714. target.addScaledVector( uv3, _v3.z );
  4715. return target;
  4716. },
  4717. isFrontFacing: function ( a, b, c, direction ) {
  4718. _v0$1.subVectors( c, b );
  4719. _v1$3.subVectors( a, b );
  4720. // strictly front facing
  4721. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4722. }
  4723. } );
  4724. Object.assign( Triangle.prototype, {
  4725. set: function ( a, b, c ) {
  4726. this.a.copy( a );
  4727. this.b.copy( b );
  4728. this.c.copy( c );
  4729. return this;
  4730. },
  4731. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4732. this.a.copy( points[ i0 ] );
  4733. this.b.copy( points[ i1 ] );
  4734. this.c.copy( points[ i2 ] );
  4735. return this;
  4736. },
  4737. clone: function () {
  4738. return new this.constructor().copy( this );
  4739. },
  4740. copy: function ( triangle ) {
  4741. this.a.copy( triangle.a );
  4742. this.b.copy( triangle.b );
  4743. this.c.copy( triangle.c );
  4744. return this;
  4745. },
  4746. getArea: function () {
  4747. _v0$1.subVectors( this.c, this.b );
  4748. _v1$3.subVectors( this.a, this.b );
  4749. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4750. },
  4751. getMidpoint: function ( target ) {
  4752. if ( target === undefined ) {
  4753. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4754. target = new Vector3();
  4755. }
  4756. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4757. },
  4758. getNormal: function ( target ) {
  4759. return Triangle.getNormal( this.a, this.b, this.c, target );
  4760. },
  4761. getPlane: function ( target ) {
  4762. if ( target === undefined ) {
  4763. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4764. target = new Plane();
  4765. }
  4766. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4767. },
  4768. getBarycoord: function ( point, target ) {
  4769. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4770. },
  4771. getUV: function ( point, uv1, uv2, uv3, target ) {
  4772. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4773. },
  4774. containsPoint: function ( point ) {
  4775. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4776. },
  4777. isFrontFacing: function ( direction ) {
  4778. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4779. },
  4780. intersectsBox: function ( box ) {
  4781. return box.intersectsTriangle( this );
  4782. },
  4783. closestPointToPoint: function ( p, target ) {
  4784. if ( target === undefined ) {
  4785. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4786. target = new Vector3();
  4787. }
  4788. var a = this.a, b = this.b, c = this.c;
  4789. var v, w;
  4790. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4791. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4792. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4793. // basically, we're distinguishing which of the voronoi regions of the triangle
  4794. // the point lies in with the minimum amount of redundant computation.
  4795. _vab.subVectors( b, a );
  4796. _vac.subVectors( c, a );
  4797. _vap.subVectors( p, a );
  4798. var d1 = _vab.dot( _vap );
  4799. var d2 = _vac.dot( _vap );
  4800. if ( d1 <= 0 && d2 <= 0 ) {
  4801. // vertex region of A; barycentric coords (1, 0, 0)
  4802. return target.copy( a );
  4803. }
  4804. _vbp.subVectors( p, b );
  4805. var d3 = _vab.dot( _vbp );
  4806. var d4 = _vac.dot( _vbp );
  4807. if ( d3 >= 0 && d4 <= d3 ) {
  4808. // vertex region of B; barycentric coords (0, 1, 0)
  4809. return target.copy( b );
  4810. }
  4811. var vc = d1 * d4 - d3 * d2;
  4812. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4813. v = d1 / ( d1 - d3 );
  4814. // edge region of AB; barycentric coords (1-v, v, 0)
  4815. return target.copy( a ).addScaledVector( _vab, v );
  4816. }
  4817. _vcp.subVectors( p, c );
  4818. var d5 = _vab.dot( _vcp );
  4819. var d6 = _vac.dot( _vcp );
  4820. if ( d6 >= 0 && d5 <= d6 ) {
  4821. // vertex region of C; barycentric coords (0, 0, 1)
  4822. return target.copy( c );
  4823. }
  4824. var vb = d5 * d2 - d1 * d6;
  4825. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4826. w = d2 / ( d2 - d6 );
  4827. // edge region of AC; barycentric coords (1-w, 0, w)
  4828. return target.copy( a ).addScaledVector( _vac, w );
  4829. }
  4830. var va = d3 * d6 - d5 * d4;
  4831. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4832. _vbc.subVectors( c, b );
  4833. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4834. // edge region of BC; barycentric coords (0, 1-w, w)
  4835. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4836. }
  4837. // face region
  4838. var denom = 1 / ( va + vb + vc );
  4839. // u = va * denom
  4840. v = vb * denom;
  4841. w = vc * denom;
  4842. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4843. },
  4844. equals: function ( triangle ) {
  4845. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4846. }
  4847. } );
  4848. /**
  4849. * @author mrdoob / http://mrdoob.com/
  4850. */
  4851. var _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4852. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4853. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4854. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4855. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4856. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4857. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4858. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4859. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4860. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4861. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4862. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4863. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4864. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4865. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4866. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4867. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4868. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4869. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4870. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4871. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4872. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4873. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4874. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4875. var _hslA = { h: 0, s: 0, l: 0 };
  4876. var _hslB = { h: 0, s: 0, l: 0 };
  4877. function Color( r, g, b ) {
  4878. if ( g === undefined && b === undefined ) {
  4879. // r is THREE.Color, hex or string
  4880. return this.set( r );
  4881. }
  4882. return this.setRGB( r, g, b );
  4883. }
  4884. function hue2rgb( p, q, t ) {
  4885. if ( t < 0 ) { t += 1; }
  4886. if ( t > 1 ) { t -= 1; }
  4887. if ( t < 1 / 6 ) { return p + ( q - p ) * 6 * t; }
  4888. if ( t < 1 / 2 ) { return q; }
  4889. if ( t < 2 / 3 ) { return p + ( q - p ) * 6 * ( 2 / 3 - t ); }
  4890. return p;
  4891. }
  4892. function SRGBToLinear( c ) {
  4893. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4894. }
  4895. function LinearToSRGB( c ) {
  4896. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4897. }
  4898. Object.assign( Color.prototype, {
  4899. isColor: true,
  4900. r: 1, g: 1, b: 1,
  4901. set: function ( value ) {
  4902. if ( value && value.isColor ) {
  4903. this.copy( value );
  4904. } else if ( typeof value === 'number' ) {
  4905. this.setHex( value );
  4906. } else if ( typeof value === 'string' ) {
  4907. this.setStyle( value );
  4908. }
  4909. return this;
  4910. },
  4911. setScalar: function ( scalar ) {
  4912. this.r = scalar;
  4913. this.g = scalar;
  4914. this.b = scalar;
  4915. return this;
  4916. },
  4917. setHex: function ( hex ) {
  4918. hex = Math.floor( hex );
  4919. this.r = ( hex >> 16 & 255 ) / 255;
  4920. this.g = ( hex >> 8 & 255 ) / 255;
  4921. this.b = ( hex & 255 ) / 255;
  4922. return this;
  4923. },
  4924. setRGB: function ( r, g, b ) {
  4925. this.r = r;
  4926. this.g = g;
  4927. this.b = b;
  4928. return this;
  4929. },
  4930. setHSL: function ( h, s, l ) {
  4931. // h,s,l ranges are in 0.0 - 1.0
  4932. h = MathUtils.euclideanModulo( h, 1 );
  4933. s = MathUtils.clamp( s, 0, 1 );
  4934. l = MathUtils.clamp( l, 0, 1 );
  4935. if ( s === 0 ) {
  4936. this.r = this.g = this.b = l;
  4937. } else {
  4938. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4939. var q = ( 2 * l ) - p;
  4940. this.r = hue2rgb( q, p, h + 1 / 3 );
  4941. this.g = hue2rgb( q, p, h );
  4942. this.b = hue2rgb( q, p, h - 1 / 3 );
  4943. }
  4944. return this;
  4945. },
  4946. setStyle: function ( style ) {
  4947. function handleAlpha( string ) {
  4948. if ( string === undefined ) { return; }
  4949. if ( parseFloat( string ) < 1 ) {
  4950. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4951. }
  4952. }
  4953. var m;
  4954. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4955. // rgb / hsl
  4956. var color;
  4957. var name = m[ 1 ];
  4958. var components = m[ 2 ];
  4959. switch ( name ) {
  4960. case 'rgb':
  4961. case 'rgba':
  4962. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4963. // rgb(255,0,0) rgba(255,0,0,0.5)
  4964. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4965. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4966. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4967. handleAlpha( color[ 5 ] );
  4968. return this;
  4969. }
  4970. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4971. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4972. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4973. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4974. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4975. handleAlpha( color[ 5 ] );
  4976. return this;
  4977. }
  4978. break;
  4979. case 'hsl':
  4980. case 'hsla':
  4981. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4982. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4983. var h = parseFloat( color[ 1 ] ) / 360;
  4984. var s = parseInt( color[ 2 ], 10 ) / 100;
  4985. var l = parseInt( color[ 3 ], 10 ) / 100;
  4986. handleAlpha( color[ 5 ] );
  4987. return this.setHSL( h, s, l );
  4988. }
  4989. break;
  4990. }
  4991. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4992. // hex color
  4993. var hex = m[ 1 ];
  4994. var size = hex.length;
  4995. if ( size === 3 ) {
  4996. // #ff0
  4997. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4998. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4999. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  5000. return this;
  5001. } else if ( size === 6 ) {
  5002. // #ff0000
  5003. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  5004. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  5005. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  5006. return this;
  5007. }
  5008. }
  5009. if ( style && style.length > 0 ) {
  5010. return this.setColorName( style );
  5011. }
  5012. return this;
  5013. },
  5014. setColorName: function ( style ) {
  5015. // color keywords
  5016. var hex = _colorKeywords[ style ];
  5017. if ( hex !== undefined ) {
  5018. // red
  5019. this.setHex( hex );
  5020. } else {
  5021. // unknown color
  5022. console.warn( 'THREE.Color: Unknown color ' + style );
  5023. }
  5024. return this;
  5025. },
  5026. clone: function () {
  5027. return new this.constructor( this.r, this.g, this.b );
  5028. },
  5029. copy: function ( color ) {
  5030. this.r = color.r;
  5031. this.g = color.g;
  5032. this.b = color.b;
  5033. return this;
  5034. },
  5035. copyGammaToLinear: function ( color, gammaFactor ) {
  5036. if ( gammaFactor === undefined ) { gammaFactor = 2.0; }
  5037. this.r = Math.pow( color.r, gammaFactor );
  5038. this.g = Math.pow( color.g, gammaFactor );
  5039. this.b = Math.pow( color.b, gammaFactor );
  5040. return this;
  5041. },
  5042. copyLinearToGamma: function ( color, gammaFactor ) {
  5043. if ( gammaFactor === undefined ) { gammaFactor = 2.0; }
  5044. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  5045. this.r = Math.pow( color.r, safeInverse );
  5046. this.g = Math.pow( color.g, safeInverse );
  5047. this.b = Math.pow( color.b, safeInverse );
  5048. return this;
  5049. },
  5050. convertGammaToLinear: function ( gammaFactor ) {
  5051. this.copyGammaToLinear( this, gammaFactor );
  5052. return this;
  5053. },
  5054. convertLinearToGamma: function ( gammaFactor ) {
  5055. this.copyLinearToGamma( this, gammaFactor );
  5056. return this;
  5057. },
  5058. copySRGBToLinear: function ( color ) {
  5059. this.r = SRGBToLinear( color.r );
  5060. this.g = SRGBToLinear( color.g );
  5061. this.b = SRGBToLinear( color.b );
  5062. return this;
  5063. },
  5064. copyLinearToSRGB: function ( color ) {
  5065. this.r = LinearToSRGB( color.r );
  5066. this.g = LinearToSRGB( color.g );
  5067. this.b = LinearToSRGB( color.b );
  5068. return this;
  5069. },
  5070. convertSRGBToLinear: function () {
  5071. this.copySRGBToLinear( this );
  5072. return this;
  5073. },
  5074. convertLinearToSRGB: function () {
  5075. this.copyLinearToSRGB( this );
  5076. return this;
  5077. },
  5078. getHex: function () {
  5079. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  5080. },
  5081. getHexString: function () {
  5082. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  5083. },
  5084. getHSL: function ( target ) {
  5085. // h,s,l ranges are in 0.0 - 1.0
  5086. if ( target === undefined ) {
  5087. console.warn( 'THREE.Color: .getHSL() target is now required' );
  5088. target = { h: 0, s: 0, l: 0 };
  5089. }
  5090. var r = this.r, g = this.g, b = this.b;
  5091. var max = Math.max( r, g, b );
  5092. var min = Math.min( r, g, b );
  5093. var hue, saturation;
  5094. var lightness = ( min + max ) / 2.0;
  5095. if ( min === max ) {
  5096. hue = 0;
  5097. saturation = 0;
  5098. } else {
  5099. var delta = max - min;
  5100. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5101. switch ( max ) {
  5102. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5103. case g: hue = ( b - r ) / delta + 2; break;
  5104. case b: hue = ( r - g ) / delta + 4; break;
  5105. }
  5106. hue /= 6;
  5107. }
  5108. target.h = hue;
  5109. target.s = saturation;
  5110. target.l = lightness;
  5111. return target;
  5112. },
  5113. getStyle: function () {
  5114. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  5115. },
  5116. offsetHSL: function ( h, s, l ) {
  5117. this.getHSL( _hslA );
  5118. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  5119. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  5120. return this;
  5121. },
  5122. add: function ( color ) {
  5123. this.r += color.r;
  5124. this.g += color.g;
  5125. this.b += color.b;
  5126. return this;
  5127. },
  5128. addColors: function ( color1, color2 ) {
  5129. this.r = color1.r + color2.r;
  5130. this.g = color1.g + color2.g;
  5131. this.b = color1.b + color2.b;
  5132. return this;
  5133. },
  5134. addScalar: function ( s ) {
  5135. this.r += s;
  5136. this.g += s;
  5137. this.b += s;
  5138. return this;
  5139. },
  5140. sub: function ( color ) {
  5141. this.r = Math.max( 0, this.r - color.r );
  5142. this.g = Math.max( 0, this.g - color.g );
  5143. this.b = Math.max( 0, this.b - color.b );
  5144. return this;
  5145. },
  5146. multiply: function ( color ) {
  5147. this.r *= color.r;
  5148. this.g *= color.g;
  5149. this.b *= color.b;
  5150. return this;
  5151. },
  5152. multiplyScalar: function ( s ) {
  5153. this.r *= s;
  5154. this.g *= s;
  5155. this.b *= s;
  5156. return this;
  5157. },
  5158. lerp: function ( color, alpha ) {
  5159. this.r += ( color.r - this.r ) * alpha;
  5160. this.g += ( color.g - this.g ) * alpha;
  5161. this.b += ( color.b - this.b ) * alpha;
  5162. return this;
  5163. },
  5164. lerpHSL: function ( color, alpha ) {
  5165. this.getHSL( _hslA );
  5166. color.getHSL( _hslB );
  5167. var h = MathUtils.lerp( _hslA.h, _hslB.h, alpha );
  5168. var s = MathUtils.lerp( _hslA.s, _hslB.s, alpha );
  5169. var l = MathUtils.lerp( _hslA.l, _hslB.l, alpha );
  5170. this.setHSL( h, s, l );
  5171. return this;
  5172. },
  5173. equals: function ( c ) {
  5174. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5175. },
  5176. fromArray: function ( array, offset ) {
  5177. if ( offset === undefined ) { offset = 0; }
  5178. this.r = array[ offset ];
  5179. this.g = array[ offset + 1 ];
  5180. this.b = array[ offset + 2 ];
  5181. return this;
  5182. },
  5183. toArray: function ( array, offset ) {
  5184. if ( array === undefined ) { array = []; }
  5185. if ( offset === undefined ) { offset = 0; }
  5186. array[ offset ] = this.r;
  5187. array[ offset + 1 ] = this.g;
  5188. array[ offset + 2 ] = this.b;
  5189. return array;
  5190. },
  5191. fromBufferAttribute: function ( attribute, index ) {
  5192. this.r = attribute.getX( index );
  5193. this.g = attribute.getY( index );
  5194. this.b = attribute.getZ( index );
  5195. if ( attribute.normalized === true ) {
  5196. // assuming Uint8Array
  5197. this.r /= 255;
  5198. this.g /= 255;
  5199. this.b /= 255;
  5200. }
  5201. return this;
  5202. },
  5203. toJSON: function () {
  5204. return this.getHex();
  5205. }
  5206. } );
  5207. Color.NAMES = _colorKeywords;
  5208. /**
  5209. * @author mrdoob / http://mrdoob.com/
  5210. * @author alteredq / http://alteredqualia.com/
  5211. */
  5212. function Face3( a, b, c, normal, color, materialIndex ) {
  5213. this.a = a;
  5214. this.b = b;
  5215. this.c = c;
  5216. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5217. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5218. this.color = ( color && color.isColor ) ? color : new Color();
  5219. this.vertexColors = Array.isArray( color ) ? color : [];
  5220. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5221. }
  5222. Object.assign( Face3.prototype, {
  5223. clone: function () {
  5224. return new this.constructor().copy( this );
  5225. },
  5226. copy: function ( source ) {
  5227. this.a = source.a;
  5228. this.b = source.b;
  5229. this.c = source.c;
  5230. this.normal.copy( source.normal );
  5231. this.color.copy( source.color );
  5232. this.materialIndex = source.materialIndex;
  5233. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5234. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5235. }
  5236. for ( var i$1 = 0, il$1 = source.vertexColors.length; i$1 < il$1; i$1 ++ ) {
  5237. this.vertexColors[ i$1 ] = source.vertexColors[ i$1 ].clone();
  5238. }
  5239. return this;
  5240. }
  5241. } );
  5242. /**
  5243. * @author mrdoob / http://mrdoob.com/
  5244. * @author alteredq / http://alteredqualia.com/
  5245. */
  5246. var materialId = 0;
  5247. function Material() {
  5248. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5249. this.uuid = MathUtils.generateUUID();
  5250. this.name = '';
  5251. this.type = 'Material';
  5252. this.fog = true;
  5253. this.blending = NormalBlending;
  5254. this.side = FrontSide;
  5255. this.flatShading = false;
  5256. this.vertexColors = false;
  5257. this.opacity = 1;
  5258. this.transparent = false;
  5259. this.blendSrc = SrcAlphaFactor;
  5260. this.blendDst = OneMinusSrcAlphaFactor;
  5261. this.blendEquation = AddEquation;
  5262. this.blendSrcAlpha = null;
  5263. this.blendDstAlpha = null;
  5264. this.blendEquationAlpha = null;
  5265. this.depthFunc = LessEqualDepth;
  5266. this.depthTest = true;
  5267. this.depthWrite = true;
  5268. this.stencilWriteMask = 0xff;
  5269. this.stencilFunc = AlwaysStencilFunc;
  5270. this.stencilRef = 0;
  5271. this.stencilFuncMask = 0xff;
  5272. this.stencilFail = KeepStencilOp;
  5273. this.stencilZFail = KeepStencilOp;
  5274. this.stencilZPass = KeepStencilOp;
  5275. this.stencilWrite = false;
  5276. this.clippingPlanes = null;
  5277. this.clipIntersection = false;
  5278. this.clipShadows = false;
  5279. this.shadowSide = null;
  5280. this.colorWrite = true;
  5281. this.precision = null; // override the renderer's default precision for this material
  5282. this.polygonOffset = false;
  5283. this.polygonOffsetFactor = 0;
  5284. this.polygonOffsetUnits = 0;
  5285. this.dithering = false;
  5286. this.alphaTest = 0;
  5287. this.premultipliedAlpha = false;
  5288. this.visible = true;
  5289. this.toneMapped = true;
  5290. this.userData = {};
  5291. this.version = 0;
  5292. }
  5293. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5294. constructor: Material,
  5295. isMaterial: true,
  5296. onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
  5297. customProgramCacheKey: function () {
  5298. return this.onBeforeCompile.toString();
  5299. },
  5300. setValues: function ( values ) {
  5301. if ( values === undefined ) { return; }
  5302. for ( var key in values ) {
  5303. var newValue = values[ key ];
  5304. if ( newValue === undefined ) {
  5305. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5306. continue;
  5307. }
  5308. // for backward compatability if shading is set in the constructor
  5309. if ( key === 'shading' ) {
  5310. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5311. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5312. continue;
  5313. }
  5314. var currentValue = this[ key ];
  5315. if ( currentValue === undefined ) {
  5316. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5317. continue;
  5318. }
  5319. if ( currentValue && currentValue.isColor ) {
  5320. currentValue.set( newValue );
  5321. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5322. currentValue.copy( newValue );
  5323. } else {
  5324. this[ key ] = newValue;
  5325. }
  5326. }
  5327. },
  5328. toJSON: function ( meta ) {
  5329. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5330. if ( isRoot ) {
  5331. meta = {
  5332. textures: {},
  5333. images: {}
  5334. };
  5335. }
  5336. var data = {
  5337. metadata: {
  5338. version: 4.5,
  5339. type: 'Material',
  5340. generator: 'Material.toJSON'
  5341. }
  5342. };
  5343. // standard Material serialization
  5344. data.uuid = this.uuid;
  5345. data.type = this.type;
  5346. if ( this.name !== '' ) { data.name = this.name; }
  5347. if ( this.color && this.color.isColor ) { data.color = this.color.getHex(); }
  5348. if ( this.roughness !== undefined ) { data.roughness = this.roughness; }
  5349. if ( this.metalness !== undefined ) { data.metalness = this.metalness; }
  5350. if ( this.sheen && this.sheen.isColor ) { data.sheen = this.sheen.getHex(); }
  5351. if ( this.emissive && this.emissive.isColor ) { data.emissive = this.emissive.getHex(); }
  5352. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) { data.emissiveIntensity = this.emissiveIntensity; }
  5353. if ( this.specular && this.specular.isColor ) { data.specular = this.specular.getHex(); }
  5354. if ( this.shininess !== undefined ) { data.shininess = this.shininess; }
  5355. if ( this.clearcoat !== undefined ) { data.clearcoat = this.clearcoat; }
  5356. if ( this.clearcoatRoughness !== undefined ) { data.clearcoatRoughness = this.clearcoatRoughness; }
  5357. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5358. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5359. }
  5360. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5361. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5362. }
  5363. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5364. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5365. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5366. }
  5367. if ( this.map && this.map.isTexture ) { data.map = this.map.toJSON( meta ).uuid; }
  5368. if ( this.matcap && this.matcap.isTexture ) { data.matcap = this.matcap.toJSON( meta ).uuid; }
  5369. if ( this.alphaMap && this.alphaMap.isTexture ) { data.alphaMap = this.alphaMap.toJSON( meta ).uuid; }
  5370. if ( this.lightMap && this.lightMap.isTexture ) { data.lightMap = this.lightMap.toJSON( meta ).uuid; }
  5371. if ( this.aoMap && this.aoMap.isTexture ) {
  5372. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5373. data.aoMapIntensity = this.aoMapIntensity;
  5374. }
  5375. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5376. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5377. data.bumpScale = this.bumpScale;
  5378. }
  5379. if ( this.normalMap && this.normalMap.isTexture ) {
  5380. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5381. data.normalMapType = this.normalMapType;
  5382. data.normalScale = this.normalScale.toArray();
  5383. }
  5384. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5385. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5386. data.displacementScale = this.displacementScale;
  5387. data.displacementBias = this.displacementBias;
  5388. }
  5389. if ( this.roughnessMap && this.roughnessMap.isTexture ) { data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid; }
  5390. if ( this.metalnessMap && this.metalnessMap.isTexture ) { data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid; }
  5391. if ( this.emissiveMap && this.emissiveMap.isTexture ) { data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid; }
  5392. if ( this.specularMap && this.specularMap.isTexture ) { data.specularMap = this.specularMap.toJSON( meta ).uuid; }
  5393. if ( this.envMap && this.envMap.isTexture ) {
  5394. data.envMap = this.envMap.toJSON( meta ).uuid;
  5395. data.reflectivity = this.reflectivity; // Scale behind envMap
  5396. data.refractionRatio = this.refractionRatio;
  5397. if ( this.combine !== undefined ) { data.combine = this.combine; }
  5398. if ( this.envMapIntensity !== undefined ) { data.envMapIntensity = this.envMapIntensity; }
  5399. }
  5400. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5401. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5402. }
  5403. if ( this.size !== undefined ) { data.size = this.size; }
  5404. if ( this.sizeAttenuation !== undefined ) { data.sizeAttenuation = this.sizeAttenuation; }
  5405. if ( this.blending !== NormalBlending ) { data.blending = this.blending; }
  5406. if ( this.flatShading === true ) { data.flatShading = this.flatShading; }
  5407. if ( this.side !== FrontSide ) { data.side = this.side; }
  5408. if ( this.vertexColors ) { data.vertexColors = true; }
  5409. if ( this.opacity < 1 ) { data.opacity = this.opacity; }
  5410. if ( this.transparent === true ) { data.transparent = this.transparent; }
  5411. data.depthFunc = this.depthFunc;
  5412. data.depthTest = this.depthTest;
  5413. data.depthWrite = this.depthWrite;
  5414. data.stencilWrite = this.stencilWrite;
  5415. data.stencilWriteMask = this.stencilWriteMask;
  5416. data.stencilFunc = this.stencilFunc;
  5417. data.stencilRef = this.stencilRef;
  5418. data.stencilFuncMask = this.stencilFuncMask;
  5419. data.stencilFail = this.stencilFail;
  5420. data.stencilZFail = this.stencilZFail;
  5421. data.stencilZPass = this.stencilZPass;
  5422. // rotation (SpriteMaterial)
  5423. if ( this.rotation && this.rotation !== 0 ) { data.rotation = this.rotation; }
  5424. if ( this.polygonOffset === true ) { data.polygonOffset = true; }
  5425. if ( this.polygonOffsetFactor !== 0 ) { data.polygonOffsetFactor = this.polygonOffsetFactor; }
  5426. if ( this.polygonOffsetUnits !== 0 ) { data.polygonOffsetUnits = this.polygonOffsetUnits; }
  5427. if ( this.linewidth && this.linewidth !== 1 ) { data.linewidth = this.linewidth; }
  5428. if ( this.dashSize !== undefined ) { data.dashSize = this.dashSize; }
  5429. if ( this.gapSize !== undefined ) { data.gapSize = this.gapSize; }
  5430. if ( this.scale !== undefined ) { data.scale = this.scale; }
  5431. if ( this.dithering === true ) { data.dithering = true; }
  5432. if ( this.alphaTest > 0 ) { data.alphaTest = this.alphaTest; }
  5433. if ( this.premultipliedAlpha === true ) { data.premultipliedAlpha = this.premultipliedAlpha; }
  5434. if ( this.wireframe === true ) { data.wireframe = this.wireframe; }
  5435. if ( this.wireframeLinewidth > 1 ) { data.wireframeLinewidth = this.wireframeLinewidth; }
  5436. if ( this.wireframeLinecap !== 'round' ) { data.wireframeLinecap = this.wireframeLinecap; }
  5437. if ( this.wireframeLinejoin !== 'round' ) { data.wireframeLinejoin = this.wireframeLinejoin; }
  5438. if ( this.morphTargets === true ) { data.morphTargets = true; }
  5439. if ( this.morphNormals === true ) { data.morphNormals = true; }
  5440. if ( this.skinning === true ) { data.skinning = true; }
  5441. if ( this.visible === false ) { data.visible = false; }
  5442. if ( this.toneMapped === false ) { data.toneMapped = false; }
  5443. if ( JSON.stringify( this.userData ) !== '{}' ) { data.userData = this.userData; }
  5444. // TODO: Copied from Object3D.toJSON
  5445. function extractFromCache( cache ) {
  5446. var values = [];
  5447. for ( var key in cache ) {
  5448. var data = cache[ key ];
  5449. delete data.metadata;
  5450. values.push( data );
  5451. }
  5452. return values;
  5453. }
  5454. if ( isRoot ) {
  5455. var textures = extractFromCache( meta.textures );
  5456. var images = extractFromCache( meta.images );
  5457. if ( textures.length > 0 ) { data.textures = textures; }
  5458. if ( images.length > 0 ) { data.images = images; }
  5459. }
  5460. return data;
  5461. },
  5462. clone: function () {
  5463. return new this.constructor().copy( this );
  5464. },
  5465. copy: function ( source ) {
  5466. this.name = source.name;
  5467. this.fog = source.fog;
  5468. this.blending = source.blending;
  5469. this.side = source.side;
  5470. this.flatShading = source.flatShading;
  5471. this.vertexColors = source.vertexColors;
  5472. this.opacity = source.opacity;
  5473. this.transparent = source.transparent;
  5474. this.blendSrc = source.blendSrc;
  5475. this.blendDst = source.blendDst;
  5476. this.blendEquation = source.blendEquation;
  5477. this.blendSrcAlpha = source.blendSrcAlpha;
  5478. this.blendDstAlpha = source.blendDstAlpha;
  5479. this.blendEquationAlpha = source.blendEquationAlpha;
  5480. this.depthFunc = source.depthFunc;
  5481. this.depthTest = source.depthTest;
  5482. this.depthWrite = source.depthWrite;
  5483. this.stencilWriteMask = source.stencilWriteMask;
  5484. this.stencilFunc = source.stencilFunc;
  5485. this.stencilRef = source.stencilRef;
  5486. this.stencilFuncMask = source.stencilFuncMask;
  5487. this.stencilFail = source.stencilFail;
  5488. this.stencilZFail = source.stencilZFail;
  5489. this.stencilZPass = source.stencilZPass;
  5490. this.stencilWrite = source.stencilWrite;
  5491. var srcPlanes = source.clippingPlanes;
  5492. var dstPlanes = null;
  5493. if ( srcPlanes !== null ) {
  5494. var n = srcPlanes.length;
  5495. dstPlanes = new Array( n );
  5496. for ( var i = 0; i !== n; ++ i ) {
  5497. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5498. }
  5499. }
  5500. this.clippingPlanes = dstPlanes;
  5501. this.clipIntersection = source.clipIntersection;
  5502. this.clipShadows = source.clipShadows;
  5503. this.shadowSide = source.shadowSide;
  5504. this.colorWrite = source.colorWrite;
  5505. this.precision = source.precision;
  5506. this.polygonOffset = source.polygonOffset;
  5507. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5508. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5509. this.dithering = source.dithering;
  5510. this.alphaTest = source.alphaTest;
  5511. this.premultipliedAlpha = source.premultipliedAlpha;
  5512. this.visible = source.visible;
  5513. this.toneMapped = source.toneMapped;
  5514. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5515. return this;
  5516. },
  5517. dispose: function () {
  5518. this.dispatchEvent( { type: 'dispose' } );
  5519. }
  5520. } );
  5521. Object.defineProperty( Material.prototype, 'needsUpdate', {
  5522. set: function ( value ) {
  5523. if ( value === true ) { this.version ++; }
  5524. }
  5525. } );
  5526. /**
  5527. * @author mrdoob / http://mrdoob.com/
  5528. * @author alteredq / http://alteredqualia.com/
  5529. *
  5530. * parameters = {
  5531. * color: <hex>,
  5532. * opacity: <float>,
  5533. * map: new THREE.Texture( <Image> ),
  5534. *
  5535. * lightMap: new THREE.Texture( <Image> ),
  5536. * lightMapIntensity: <float>
  5537. *
  5538. * aoMap: new THREE.Texture( <Image> ),
  5539. * aoMapIntensity: <float>
  5540. *
  5541. * specularMap: new THREE.Texture( <Image> ),
  5542. *
  5543. * alphaMap: new THREE.Texture( <Image> ),
  5544. *
  5545. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5546. * combine: THREE.Multiply,
  5547. * reflectivity: <float>,
  5548. * refractionRatio: <float>,
  5549. *
  5550. * depthTest: <bool>,
  5551. * depthWrite: <bool>,
  5552. *
  5553. * wireframe: <boolean>,
  5554. * wireframeLinewidth: <float>,
  5555. *
  5556. * skinning: <bool>,
  5557. * morphTargets: <bool>
  5558. * }
  5559. */
  5560. function MeshBasicMaterial( parameters ) {
  5561. Material.call( this );
  5562. this.type = 'MeshBasicMaterial';
  5563. this.color = new Color( 0xffffff ); // emissive
  5564. this.map = null;
  5565. this.lightMap = null;
  5566. this.lightMapIntensity = 1.0;
  5567. this.aoMap = null;
  5568. this.aoMapIntensity = 1.0;
  5569. this.specularMap = null;
  5570. this.alphaMap = null;
  5571. this.envMap = null;
  5572. this.combine = MultiplyOperation;
  5573. this.reflectivity = 1;
  5574. this.refractionRatio = 0.98;
  5575. this.wireframe = false;
  5576. this.wireframeLinewidth = 1;
  5577. this.wireframeLinecap = 'round';
  5578. this.wireframeLinejoin = 'round';
  5579. this.skinning = false;
  5580. this.morphTargets = false;
  5581. this.setValues( parameters );
  5582. }
  5583. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5584. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5585. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5586. MeshBasicMaterial.prototype.copy = function ( source ) {
  5587. Material.prototype.copy.call( this, source );
  5588. this.color.copy( source.color );
  5589. this.map = source.map;
  5590. this.lightMap = source.lightMap;
  5591. this.lightMapIntensity = source.lightMapIntensity;
  5592. this.aoMap = source.aoMap;
  5593. this.aoMapIntensity = source.aoMapIntensity;
  5594. this.specularMap = source.specularMap;
  5595. this.alphaMap = source.alphaMap;
  5596. this.envMap = source.envMap;
  5597. this.combine = source.combine;
  5598. this.reflectivity = source.reflectivity;
  5599. this.refractionRatio = source.refractionRatio;
  5600. this.wireframe = source.wireframe;
  5601. this.wireframeLinewidth = source.wireframeLinewidth;
  5602. this.wireframeLinecap = source.wireframeLinecap;
  5603. this.wireframeLinejoin = source.wireframeLinejoin;
  5604. this.skinning = source.skinning;
  5605. this.morphTargets = source.morphTargets;
  5606. return this;
  5607. };
  5608. /**
  5609. * @author mrdoob / http://mrdoob.com/
  5610. */
  5611. var _vector$3 = new Vector3();
  5612. var _vector2$1 = new Vector2();
  5613. function BufferAttribute( array, itemSize, normalized ) {
  5614. if ( Array.isArray( array ) ) {
  5615. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5616. }
  5617. this.name = '';
  5618. this.array = array;
  5619. this.itemSize = itemSize;
  5620. this.count = array !== undefined ? array.length / itemSize : 0;
  5621. this.normalized = normalized === true;
  5622. this.usage = StaticDrawUsage;
  5623. this.updateRange = { offset: 0, count: - 1 };
  5624. this.version = 0;
  5625. }
  5626. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5627. set: function ( value ) {
  5628. if ( value === true ) { this.version ++; }
  5629. }
  5630. } );
  5631. Object.assign( BufferAttribute.prototype, {
  5632. isBufferAttribute: true,
  5633. onUploadCallback: function () {},
  5634. setUsage: function ( value ) {
  5635. this.usage = value;
  5636. return this;
  5637. },
  5638. copy: function ( source ) {
  5639. this.name = source.name;
  5640. this.array = new source.array.constructor( source.array );
  5641. this.itemSize = source.itemSize;
  5642. this.count = source.count;
  5643. this.normalized = source.normalized;
  5644. this.usage = source.usage;
  5645. return this;
  5646. },
  5647. copyAt: function ( index1, attribute, index2 ) {
  5648. index1 *= this.itemSize;
  5649. index2 *= attribute.itemSize;
  5650. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5651. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5652. }
  5653. return this;
  5654. },
  5655. copyArray: function ( array ) {
  5656. this.array.set( array );
  5657. return this;
  5658. },
  5659. copyColorsArray: function ( colors ) {
  5660. var array = this.array;
  5661. var offset = 0;
  5662. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5663. var color = colors[ i ];
  5664. if ( color === undefined ) {
  5665. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5666. color = new Color();
  5667. }
  5668. array[ offset ++ ] = color.r;
  5669. array[ offset ++ ] = color.g;
  5670. array[ offset ++ ] = color.b;
  5671. }
  5672. return this;
  5673. },
  5674. copyVector2sArray: function ( vectors ) {
  5675. var array = this.array;
  5676. var offset = 0;
  5677. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5678. var vector = vectors[ i ];
  5679. if ( vector === undefined ) {
  5680. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5681. vector = new Vector2();
  5682. }
  5683. array[ offset ++ ] = vector.x;
  5684. array[ offset ++ ] = vector.y;
  5685. }
  5686. return this;
  5687. },
  5688. copyVector3sArray: function ( vectors ) {
  5689. var array = this.array;
  5690. var offset = 0;
  5691. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5692. var vector = vectors[ i ];
  5693. if ( vector === undefined ) {
  5694. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5695. vector = new Vector3();
  5696. }
  5697. array[ offset ++ ] = vector.x;
  5698. array[ offset ++ ] = vector.y;
  5699. array[ offset ++ ] = vector.z;
  5700. }
  5701. return this;
  5702. },
  5703. copyVector4sArray: function ( vectors ) {
  5704. var array = this.array;
  5705. var offset = 0;
  5706. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5707. var vector = vectors[ i ];
  5708. if ( vector === undefined ) {
  5709. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5710. vector = new Vector4();
  5711. }
  5712. array[ offset ++ ] = vector.x;
  5713. array[ offset ++ ] = vector.y;
  5714. array[ offset ++ ] = vector.z;
  5715. array[ offset ++ ] = vector.w;
  5716. }
  5717. return this;
  5718. },
  5719. applyMatrix3: function ( m ) {
  5720. if ( this.itemSize === 2 ) {
  5721. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5722. _vector2$1.fromBufferAttribute( this, i );
  5723. _vector2$1.applyMatrix3( m );
  5724. this.setXY( i, _vector2$1.x, _vector2$1.y );
  5725. }
  5726. } else if ( this.itemSize === 3 ) {
  5727. for ( var i$1 = 0, l$1 = this.count; i$1 < l$1; i$1 ++ ) {
  5728. _vector$3.fromBufferAttribute( this, i$1 );
  5729. _vector$3.applyMatrix3( m );
  5730. this.setXYZ( i$1, _vector$3.x, _vector$3.y, _vector$3.z );
  5731. }
  5732. }
  5733. return this;
  5734. },
  5735. applyMatrix4: function ( m ) {
  5736. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5737. _vector$3.x = this.getX( i );
  5738. _vector$3.y = this.getY( i );
  5739. _vector$3.z = this.getZ( i );
  5740. _vector$3.applyMatrix4( m );
  5741. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5742. }
  5743. return this;
  5744. },
  5745. applyNormalMatrix: function ( m ) {
  5746. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5747. _vector$3.x = this.getX( i );
  5748. _vector$3.y = this.getY( i );
  5749. _vector$3.z = this.getZ( i );
  5750. _vector$3.applyNormalMatrix( m );
  5751. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5752. }
  5753. return this;
  5754. },
  5755. transformDirection: function ( m ) {
  5756. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5757. _vector$3.x = this.getX( i );
  5758. _vector$3.y = this.getY( i );
  5759. _vector$3.z = this.getZ( i );
  5760. _vector$3.transformDirection( m );
  5761. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5762. }
  5763. return this;
  5764. },
  5765. set: function ( value, offset ) {
  5766. if ( offset === undefined ) { offset = 0; }
  5767. this.array.set( value, offset );
  5768. return this;
  5769. },
  5770. getX: function ( index ) {
  5771. return this.array[ index * this.itemSize ];
  5772. },
  5773. setX: function ( index, x ) {
  5774. this.array[ index * this.itemSize ] = x;
  5775. return this;
  5776. },
  5777. getY: function ( index ) {
  5778. return this.array[ index * this.itemSize + 1 ];
  5779. },
  5780. setY: function ( index, y ) {
  5781. this.array[ index * this.itemSize + 1 ] = y;
  5782. return this;
  5783. },
  5784. getZ: function ( index ) {
  5785. return this.array[ index * this.itemSize + 2 ];
  5786. },
  5787. setZ: function ( index, z ) {
  5788. this.array[ index * this.itemSize + 2 ] = z;
  5789. return this;
  5790. },
  5791. getW: function ( index ) {
  5792. return this.array[ index * this.itemSize + 3 ];
  5793. },
  5794. setW: function ( index, w ) {
  5795. this.array[ index * this.itemSize + 3 ] = w;
  5796. return this;
  5797. },
  5798. setXY: function ( index, x, y ) {
  5799. index *= this.itemSize;
  5800. this.array[ index + 0 ] = x;
  5801. this.array[ index + 1 ] = y;
  5802. return this;
  5803. },
  5804. setXYZ: function ( index, x, y, z ) {
  5805. index *= this.itemSize;
  5806. this.array[ index + 0 ] = x;
  5807. this.array[ index + 1 ] = y;
  5808. this.array[ index + 2 ] = z;
  5809. return this;
  5810. },
  5811. setXYZW: function ( index, x, y, z, w ) {
  5812. index *= this.itemSize;
  5813. this.array[ index + 0 ] = x;
  5814. this.array[ index + 1 ] = y;
  5815. this.array[ index + 2 ] = z;
  5816. this.array[ index + 3 ] = w;
  5817. return this;
  5818. },
  5819. onUpload: function ( callback ) {
  5820. this.onUploadCallback = callback;
  5821. return this;
  5822. },
  5823. clone: function () {
  5824. return new this.constructor( this.array, this.itemSize ).copy( this );
  5825. },
  5826. toJSON: function () {
  5827. return {
  5828. itemSize: this.itemSize,
  5829. type: this.array.constructor.name,
  5830. array: Array.prototype.slice.call( this.array ),
  5831. normalized: this.normalized
  5832. };
  5833. }
  5834. } );
  5835. //
  5836. function Int8BufferAttribute( array, itemSize, normalized ) {
  5837. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5838. }
  5839. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5840. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5841. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5842. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5843. }
  5844. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5845. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5846. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5847. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5848. }
  5849. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5850. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5851. function Int16BufferAttribute( array, itemSize, normalized ) {
  5852. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5853. }
  5854. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5855. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5856. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5857. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5858. }
  5859. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5860. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5861. function Int32BufferAttribute( array, itemSize, normalized ) {
  5862. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5863. }
  5864. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5865. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5866. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5867. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5868. }
  5869. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5870. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5871. function Float32BufferAttribute( array, itemSize, normalized ) {
  5872. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5873. }
  5874. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5875. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5876. function Float64BufferAttribute( array, itemSize, normalized ) {
  5877. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5878. }
  5879. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5880. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5881. /**
  5882. * @author mrdoob / http://mrdoob.com/
  5883. */
  5884. function DirectGeometry() {
  5885. this.vertices = [];
  5886. this.normals = [];
  5887. this.colors = [];
  5888. this.uvs = [];
  5889. this.uvs2 = [];
  5890. this.groups = [];
  5891. this.morphTargets = {};
  5892. this.skinWeights = [];
  5893. this.skinIndices = [];
  5894. // this.lineDistances = [];
  5895. this.boundingBox = null;
  5896. this.boundingSphere = null;
  5897. // update flags
  5898. this.verticesNeedUpdate = false;
  5899. this.normalsNeedUpdate = false;
  5900. this.colorsNeedUpdate = false;
  5901. this.uvsNeedUpdate = false;
  5902. this.groupsNeedUpdate = false;
  5903. }
  5904. Object.assign( DirectGeometry.prototype, {
  5905. computeGroups: function ( geometry ) {
  5906. var groups = [];
  5907. var group, i;
  5908. var materialIndex = undefined;
  5909. var faces = geometry.faces;
  5910. for ( i = 0; i < faces.length; i ++ ) {
  5911. var face = faces[ i ];
  5912. // materials
  5913. if ( face.materialIndex !== materialIndex ) {
  5914. materialIndex = face.materialIndex;
  5915. if ( group !== undefined ) {
  5916. group.count = ( i * 3 ) - group.start;
  5917. groups.push( group );
  5918. }
  5919. group = {
  5920. start: i * 3,
  5921. materialIndex: materialIndex
  5922. };
  5923. }
  5924. }
  5925. if ( group !== undefined ) {
  5926. group.count = ( i * 3 ) - group.start;
  5927. groups.push( group );
  5928. }
  5929. this.groups = groups;
  5930. },
  5931. fromGeometry: function ( geometry ) {
  5932. var faces = geometry.faces;
  5933. var vertices = geometry.vertices;
  5934. var faceVertexUvs = geometry.faceVertexUvs;
  5935. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5936. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5937. // morphs
  5938. var morphTargets = geometry.morphTargets;
  5939. var morphTargetsLength = morphTargets.length;
  5940. var morphTargetsPosition;
  5941. if ( morphTargetsLength > 0 ) {
  5942. morphTargetsPosition = [];
  5943. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5944. morphTargetsPosition[ i ] = {
  5945. name: morphTargets[ i ].name,
  5946. data: []
  5947. };
  5948. }
  5949. this.morphTargets.position = morphTargetsPosition;
  5950. }
  5951. var morphNormals = geometry.morphNormals;
  5952. var morphNormalsLength = morphNormals.length;
  5953. var morphTargetsNormal;
  5954. if ( morphNormalsLength > 0 ) {
  5955. morphTargetsNormal = [];
  5956. for ( var i$1 = 0; i$1 < morphNormalsLength; i$1 ++ ) {
  5957. morphTargetsNormal[ i$1 ] = {
  5958. name: morphNormals[ i$1 ].name,
  5959. data: []
  5960. };
  5961. }
  5962. this.morphTargets.normal = morphTargetsNormal;
  5963. }
  5964. // skins
  5965. var skinIndices = geometry.skinIndices;
  5966. var skinWeights = geometry.skinWeights;
  5967. var hasSkinIndices = skinIndices.length === vertices.length;
  5968. var hasSkinWeights = skinWeights.length === vertices.length;
  5969. //
  5970. if ( vertices.length > 0 && faces.length === 0 ) {
  5971. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5972. }
  5973. for ( var i$2 = 0; i$2 < faces.length; i$2 ++ ) {
  5974. var face = faces[ i$2 ];
  5975. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5976. var vertexNormals = face.vertexNormals;
  5977. if ( vertexNormals.length === 3 ) {
  5978. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5979. } else {
  5980. var normal = face.normal;
  5981. this.normals.push( normal, normal, normal );
  5982. }
  5983. var vertexColors = face.vertexColors;
  5984. if ( vertexColors.length === 3 ) {
  5985. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5986. } else {
  5987. var color = face.color;
  5988. this.colors.push( color, color, color );
  5989. }
  5990. if ( hasFaceVertexUv === true ) {
  5991. var vertexUvs = faceVertexUvs[ 0 ][ i$2 ];
  5992. if ( vertexUvs !== undefined ) {
  5993. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5994. } else {
  5995. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i$2 );
  5996. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5997. }
  5998. }
  5999. if ( hasFaceVertexUv2 === true ) {
  6000. var vertexUvs$1 = faceVertexUvs[ 1 ][ i$2 ];
  6001. if ( vertexUvs$1 !== undefined ) {
  6002. this.uvs2.push( vertexUvs$1[ 0 ], vertexUvs$1[ 1 ], vertexUvs$1[ 2 ] );
  6003. } else {
  6004. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i$2 );
  6005. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6006. }
  6007. }
  6008. // morphs
  6009. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6010. var morphTarget = morphTargets[ j ].vertices;
  6011. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6012. }
  6013. for ( var j$1 = 0; j$1 < morphNormalsLength; j$1 ++ ) {
  6014. var morphNormal = morphNormals[ j$1 ].vertexNormals[ i$2 ];
  6015. morphTargetsNormal[ j$1 ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6016. }
  6017. // skins
  6018. if ( hasSkinIndices ) {
  6019. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6020. }
  6021. if ( hasSkinWeights ) {
  6022. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6023. }
  6024. }
  6025. this.computeGroups( geometry );
  6026. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6027. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6028. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6029. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6030. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6031. if ( geometry.boundingSphere !== null ) {
  6032. this.boundingSphere = geometry.boundingSphere.clone();
  6033. }
  6034. if ( geometry.boundingBox !== null ) {
  6035. this.boundingBox = geometry.boundingBox.clone();
  6036. }
  6037. return this;
  6038. }
  6039. } );
  6040. /**
  6041. * @author mrdoob / http://mrdoob.com/
  6042. */
  6043. function arrayMax( array ) {
  6044. if ( array.length === 0 ) { return - Infinity; }
  6045. var max = array[ 0 ];
  6046. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6047. if ( array[ i ] > max ) { max = array[ i ]; }
  6048. }
  6049. return max;
  6050. }
  6051. /**
  6052. * @author alteredq / http://alteredqualia.com/
  6053. * @author mrdoob / http://mrdoob.com/
  6054. */
  6055. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6056. var _m1$2 = new Matrix4();
  6057. var _obj = new Object3D();
  6058. var _offset = new Vector3();
  6059. var _box$2 = new Box3();
  6060. var _boxMorphTargets = new Box3();
  6061. var _vector$4 = new Vector3();
  6062. function BufferGeometry() {
  6063. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  6064. this.uuid = MathUtils.generateUUID();
  6065. this.name = '';
  6066. this.type = 'BufferGeometry';
  6067. this.index = null;
  6068. this.attributes = {};
  6069. this.morphAttributes = {};
  6070. this.morphTargetsRelative = false;
  6071. this.groups = [];
  6072. this.boundingBox = null;
  6073. this.boundingSphere = null;
  6074. this.drawRange = { start: 0, count: Infinity };
  6075. this.userData = {};
  6076. }
  6077. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6078. constructor: BufferGeometry,
  6079. isBufferGeometry: true,
  6080. getIndex: function () {
  6081. return this.index;
  6082. },
  6083. setIndex: function ( index ) {
  6084. if ( Array.isArray( index ) ) {
  6085. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6086. } else {
  6087. this.index = index;
  6088. }
  6089. },
  6090. getAttribute: function ( name ) {
  6091. return this.attributes[ name ];
  6092. },
  6093. setAttribute: function ( name, attribute ) {
  6094. this.attributes[ name ] = attribute;
  6095. return this;
  6096. },
  6097. deleteAttribute: function ( name ) {
  6098. delete this.attributes[ name ];
  6099. return this;
  6100. },
  6101. addGroup: function ( start, count, materialIndex ) {
  6102. this.groups.push( {
  6103. start: start,
  6104. count: count,
  6105. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6106. } );
  6107. },
  6108. clearGroups: function () {
  6109. this.groups = [];
  6110. },
  6111. setDrawRange: function ( start, count ) {
  6112. this.drawRange.start = start;
  6113. this.drawRange.count = count;
  6114. },
  6115. applyMatrix4: function ( matrix ) {
  6116. var position = this.attributes.position;
  6117. if ( position !== undefined ) {
  6118. position.applyMatrix4( matrix );
  6119. position.needsUpdate = true;
  6120. }
  6121. var normal = this.attributes.normal;
  6122. if ( normal !== undefined ) {
  6123. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6124. normal.applyNormalMatrix( normalMatrix );
  6125. normal.needsUpdate = true;
  6126. }
  6127. var tangent = this.attributes.tangent;
  6128. if ( tangent !== undefined ) {
  6129. tangent.transformDirection( matrix );
  6130. tangent.needsUpdate = true;
  6131. }
  6132. if ( this.boundingBox !== null ) {
  6133. this.computeBoundingBox();
  6134. }
  6135. if ( this.boundingSphere !== null ) {
  6136. this.computeBoundingSphere();
  6137. }
  6138. return this;
  6139. },
  6140. rotateX: function ( angle ) {
  6141. // rotate geometry around world x-axis
  6142. _m1$2.makeRotationX( angle );
  6143. this.applyMatrix4( _m1$2 );
  6144. return this;
  6145. },
  6146. rotateY: function ( angle ) {
  6147. // rotate geometry around world y-axis
  6148. _m1$2.makeRotationY( angle );
  6149. this.applyMatrix4( _m1$2 );
  6150. return this;
  6151. },
  6152. rotateZ: function ( angle ) {
  6153. // rotate geometry around world z-axis
  6154. _m1$2.makeRotationZ( angle );
  6155. this.applyMatrix4( _m1$2 );
  6156. return this;
  6157. },
  6158. translate: function ( x, y, z ) {
  6159. // translate geometry
  6160. _m1$2.makeTranslation( x, y, z );
  6161. this.applyMatrix4( _m1$2 );
  6162. return this;
  6163. },
  6164. scale: function ( x, y, z ) {
  6165. // scale geometry
  6166. _m1$2.makeScale( x, y, z );
  6167. this.applyMatrix4( _m1$2 );
  6168. return this;
  6169. },
  6170. lookAt: function ( vector ) {
  6171. _obj.lookAt( vector );
  6172. _obj.updateMatrix();
  6173. this.applyMatrix4( _obj.matrix );
  6174. return this;
  6175. },
  6176. center: function () {
  6177. this.computeBoundingBox();
  6178. this.boundingBox.getCenter( _offset ).negate();
  6179. this.translate( _offset.x, _offset.y, _offset.z );
  6180. return this;
  6181. },
  6182. setFromObject: function ( object ) {
  6183. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6184. var geometry = object.geometry;
  6185. if ( object.isPoints || object.isLine ) {
  6186. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6187. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6188. this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6189. this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6190. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6191. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6192. this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6193. }
  6194. if ( geometry.boundingSphere !== null ) {
  6195. this.boundingSphere = geometry.boundingSphere.clone();
  6196. }
  6197. if ( geometry.boundingBox !== null ) {
  6198. this.boundingBox = geometry.boundingBox.clone();
  6199. }
  6200. } else if ( object.isMesh ) {
  6201. if ( geometry && geometry.isGeometry ) {
  6202. this.fromGeometry( geometry );
  6203. }
  6204. }
  6205. return this;
  6206. },
  6207. setFromPoints: function ( points ) {
  6208. var position = [];
  6209. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6210. var point = points[ i ];
  6211. position.push( point.x, point.y, point.z || 0 );
  6212. }
  6213. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6214. return this;
  6215. },
  6216. updateFromObject: function ( object ) {
  6217. var geometry = object.geometry;
  6218. if ( object.isMesh ) {
  6219. var direct = geometry.__directGeometry;
  6220. if ( geometry.elementsNeedUpdate === true ) {
  6221. direct = undefined;
  6222. geometry.elementsNeedUpdate = false;
  6223. }
  6224. if ( direct === undefined ) {
  6225. return this.fromGeometry( geometry );
  6226. }
  6227. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6228. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6229. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6230. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6231. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6232. geometry.verticesNeedUpdate = false;
  6233. geometry.normalsNeedUpdate = false;
  6234. geometry.colorsNeedUpdate = false;
  6235. geometry.uvsNeedUpdate = false;
  6236. geometry.groupsNeedUpdate = false;
  6237. geometry = direct;
  6238. }
  6239. if ( geometry.verticesNeedUpdate === true ) {
  6240. var attribute = this.attributes.position;
  6241. if ( attribute !== undefined ) {
  6242. attribute.copyVector3sArray( geometry.vertices );
  6243. attribute.needsUpdate = true;
  6244. }
  6245. geometry.verticesNeedUpdate = false;
  6246. }
  6247. if ( geometry.normalsNeedUpdate === true ) {
  6248. var attribute$1 = this.attributes.normal;
  6249. if ( attribute$1 !== undefined ) {
  6250. attribute$1.copyVector3sArray( geometry.normals );
  6251. attribute$1.needsUpdate = true;
  6252. }
  6253. geometry.normalsNeedUpdate = false;
  6254. }
  6255. if ( geometry.colorsNeedUpdate === true ) {
  6256. var attribute$2 = this.attributes.color;
  6257. if ( attribute$2 !== undefined ) {
  6258. attribute$2.copyColorsArray( geometry.colors );
  6259. attribute$2.needsUpdate = true;
  6260. }
  6261. geometry.colorsNeedUpdate = false;
  6262. }
  6263. if ( geometry.uvsNeedUpdate ) {
  6264. var attribute$3 = this.attributes.uv;
  6265. if ( attribute$3 !== undefined ) {
  6266. attribute$3.copyVector2sArray( geometry.uvs );
  6267. attribute$3.needsUpdate = true;
  6268. }
  6269. geometry.uvsNeedUpdate = false;
  6270. }
  6271. if ( geometry.lineDistancesNeedUpdate ) {
  6272. var attribute$4 = this.attributes.lineDistance;
  6273. if ( attribute$4 !== undefined ) {
  6274. attribute$4.copyArray( geometry.lineDistances );
  6275. attribute$4.needsUpdate = true;
  6276. }
  6277. geometry.lineDistancesNeedUpdate = false;
  6278. }
  6279. if ( geometry.groupsNeedUpdate ) {
  6280. geometry.computeGroups( object.geometry );
  6281. this.groups = geometry.groups;
  6282. geometry.groupsNeedUpdate = false;
  6283. }
  6284. return this;
  6285. },
  6286. fromGeometry: function ( geometry ) {
  6287. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6288. return this.fromDirectGeometry( geometry.__directGeometry );
  6289. },
  6290. fromDirectGeometry: function ( geometry ) {
  6291. var positions = new Float32Array( geometry.vertices.length * 3 );
  6292. this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6293. if ( geometry.normals.length > 0 ) {
  6294. var normals = new Float32Array( geometry.normals.length * 3 );
  6295. this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6296. }
  6297. if ( geometry.colors.length > 0 ) {
  6298. var colors = new Float32Array( geometry.colors.length * 3 );
  6299. this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6300. }
  6301. if ( geometry.uvs.length > 0 ) {
  6302. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6303. this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6304. }
  6305. if ( geometry.uvs2.length > 0 ) {
  6306. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6307. this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6308. }
  6309. // groups
  6310. this.groups = geometry.groups;
  6311. // morphs
  6312. for ( var name in geometry.morphTargets ) {
  6313. var array = [];
  6314. var morphTargets = geometry.morphTargets[ name ];
  6315. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6316. var morphTarget = morphTargets[ i ];
  6317. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6318. attribute.name = morphTarget.name;
  6319. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6320. }
  6321. this.morphAttributes[ name ] = array;
  6322. }
  6323. // skinning
  6324. if ( geometry.skinIndices.length > 0 ) {
  6325. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6326. this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6327. }
  6328. if ( geometry.skinWeights.length > 0 ) {
  6329. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6330. this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6331. }
  6332. //
  6333. if ( geometry.boundingSphere !== null ) {
  6334. this.boundingSphere = geometry.boundingSphere.clone();
  6335. }
  6336. if ( geometry.boundingBox !== null ) {
  6337. this.boundingBox = geometry.boundingBox.clone();
  6338. }
  6339. return this;
  6340. },
  6341. computeBoundingBox: function () {
  6342. if ( this.boundingBox === null ) {
  6343. this.boundingBox = new Box3();
  6344. }
  6345. var position = this.attributes.position;
  6346. var morphAttributesPosition = this.morphAttributes.position;
  6347. if ( position !== undefined ) {
  6348. this.boundingBox.setFromBufferAttribute( position );
  6349. // process morph attributes if present
  6350. if ( morphAttributesPosition ) {
  6351. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6352. var morphAttribute = morphAttributesPosition[ i ];
  6353. _box$2.setFromBufferAttribute( morphAttribute );
  6354. if ( this.morphTargetsRelative ) {
  6355. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  6356. this.boundingBox.expandByPoint( _vector$4 );
  6357. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  6358. this.boundingBox.expandByPoint( _vector$4 );
  6359. } else {
  6360. this.boundingBox.expandByPoint( _box$2.min );
  6361. this.boundingBox.expandByPoint( _box$2.max );
  6362. }
  6363. }
  6364. }
  6365. } else {
  6366. this.boundingBox.makeEmpty();
  6367. }
  6368. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6369. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6370. }
  6371. },
  6372. computeBoundingSphere: function () {
  6373. if ( this.boundingSphere === null ) {
  6374. this.boundingSphere = new Sphere();
  6375. }
  6376. var position = this.attributes.position;
  6377. var morphAttributesPosition = this.morphAttributes.position;
  6378. if ( position ) {
  6379. // first, find the center of the bounding sphere
  6380. var center = this.boundingSphere.center;
  6381. _box$2.setFromBufferAttribute( position );
  6382. // process morph attributes if present
  6383. if ( morphAttributesPosition ) {
  6384. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6385. var morphAttribute = morphAttributesPosition[ i ];
  6386. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6387. if ( this.morphTargetsRelative ) {
  6388. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  6389. _box$2.expandByPoint( _vector$4 );
  6390. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  6391. _box$2.expandByPoint( _vector$4 );
  6392. } else {
  6393. _box$2.expandByPoint( _boxMorphTargets.min );
  6394. _box$2.expandByPoint( _boxMorphTargets.max );
  6395. }
  6396. }
  6397. }
  6398. _box$2.getCenter( center );
  6399. // second, try to find a boundingSphere with a radius smaller than the
  6400. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6401. var maxRadiusSq = 0;
  6402. for ( var i$1 = 0, il$1 = position.count; i$1 < il$1; i$1 ++ ) {
  6403. _vector$4.fromBufferAttribute( position, i$1 );
  6404. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6405. }
  6406. // process morph attributes if present
  6407. if ( morphAttributesPosition ) {
  6408. for ( var i$2 = 0, il$2 = morphAttributesPosition.length; i$2 < il$2; i$2 ++ ) {
  6409. var morphAttribute$1 = morphAttributesPosition[ i$2 ];
  6410. var morphTargetsRelative = this.morphTargetsRelative;
  6411. for ( var j = 0, jl = morphAttribute$1.count; j < jl; j ++ ) {
  6412. _vector$4.fromBufferAttribute( morphAttribute$1, j );
  6413. if ( morphTargetsRelative ) {
  6414. _offset.fromBufferAttribute( position, j );
  6415. _vector$4.add( _offset );
  6416. }
  6417. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6418. }
  6419. }
  6420. }
  6421. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6422. if ( isNaN( this.boundingSphere.radius ) ) {
  6423. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6424. }
  6425. }
  6426. },
  6427. computeFaceNormals: function () {
  6428. // backwards compatibility
  6429. },
  6430. computeVertexNormals: function () {
  6431. var index = this.index;
  6432. var positionAttribute = this.getAttribute( 'position' );
  6433. if ( positionAttribute !== undefined ) {
  6434. var normalAttribute = this.getAttribute( 'normal' );
  6435. if ( normalAttribute === undefined ) {
  6436. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6437. this.setAttribute( 'normal', normalAttribute );
  6438. } else {
  6439. // reset existing normals to zero
  6440. for ( var i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6441. normalAttribute.setXYZ( i, 0, 0, 0 );
  6442. }
  6443. }
  6444. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6445. var nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6446. var cb = new Vector3(), ab = new Vector3();
  6447. // indexed elements
  6448. if ( index ) {
  6449. for ( var i$1 = 0, il$1 = index.count; i$1 < il$1; i$1 += 3 ) {
  6450. var vA = index.getX( i$1 + 0 );
  6451. var vB = index.getX( i$1 + 1 );
  6452. var vC = index.getX( i$1 + 2 );
  6453. pA.fromBufferAttribute( positionAttribute, vA );
  6454. pB.fromBufferAttribute( positionAttribute, vB );
  6455. pC.fromBufferAttribute( positionAttribute, vC );
  6456. cb.subVectors( pC, pB );
  6457. ab.subVectors( pA, pB );
  6458. cb.cross( ab );
  6459. nA.fromBufferAttribute( normalAttribute, vA );
  6460. nB.fromBufferAttribute( normalAttribute, vB );
  6461. nC.fromBufferAttribute( normalAttribute, vC );
  6462. nA.add( cb );
  6463. nB.add( cb );
  6464. nC.add( cb );
  6465. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6466. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6467. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6468. }
  6469. } else {
  6470. // non-indexed elements (unconnected triangle soup)
  6471. for ( var i$2 = 0, il$2 = positionAttribute.count; i$2 < il$2; i$2 += 3 ) {
  6472. pA.fromBufferAttribute( positionAttribute, i$2 + 0 );
  6473. pB.fromBufferAttribute( positionAttribute, i$2 + 1 );
  6474. pC.fromBufferAttribute( positionAttribute, i$2 + 2 );
  6475. cb.subVectors( pC, pB );
  6476. ab.subVectors( pA, pB );
  6477. cb.cross( ab );
  6478. normalAttribute.setXYZ( i$2 + 0, cb.x, cb.y, cb.z );
  6479. normalAttribute.setXYZ( i$2 + 1, cb.x, cb.y, cb.z );
  6480. normalAttribute.setXYZ( i$2 + 2, cb.x, cb.y, cb.z );
  6481. }
  6482. }
  6483. this.normalizeNormals();
  6484. normalAttribute.needsUpdate = true;
  6485. }
  6486. },
  6487. merge: function ( geometry, offset ) {
  6488. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6489. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6490. return;
  6491. }
  6492. if ( offset === undefined ) {
  6493. offset = 0;
  6494. console.warn(
  6495. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6496. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6497. );
  6498. }
  6499. var attributes = this.attributes;
  6500. for ( var key in attributes ) {
  6501. if ( geometry.attributes[ key ] === undefined ) { continue; }
  6502. var attribute1 = attributes[ key ];
  6503. var attributeArray1 = attribute1.array;
  6504. var attribute2 = geometry.attributes[ key ];
  6505. var attributeArray2 = attribute2.array;
  6506. var attributeOffset = attribute2.itemSize * offset;
  6507. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6508. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6509. attributeArray1[ j ] = attributeArray2[ i ];
  6510. }
  6511. }
  6512. return this;
  6513. },
  6514. normalizeNormals: function () {
  6515. var normals = this.attributes.normal;
  6516. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6517. _vector$4.fromBufferAttribute( normals, i );
  6518. _vector$4.normalize();
  6519. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6520. }
  6521. },
  6522. toNonIndexed: function () {
  6523. function convertBufferAttribute( attribute, indices ) {
  6524. var array = attribute.array;
  6525. var itemSize = attribute.itemSize;
  6526. var normalized = attribute.normalized;
  6527. var array2 = new array.constructor( indices.length * itemSize );
  6528. var index = 0, index2 = 0;
  6529. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6530. index = indices[ i ] * itemSize;
  6531. for ( var j = 0; j < itemSize; j ++ ) {
  6532. array2[ index2 ++ ] = array[ index ++ ];
  6533. }
  6534. }
  6535. return new BufferAttribute( array2, itemSize, normalized );
  6536. }
  6537. //
  6538. if ( this.index === null ) {
  6539. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6540. return this;
  6541. }
  6542. var geometry2 = new BufferGeometry();
  6543. var indices = this.index.array;
  6544. var attributes = this.attributes;
  6545. // attributes
  6546. for ( var name in attributes ) {
  6547. var attribute = attributes[ name ];
  6548. var newAttribute = convertBufferAttribute( attribute, indices );
  6549. geometry2.setAttribute( name, newAttribute );
  6550. }
  6551. // morph attributes
  6552. var morphAttributes = this.morphAttributes;
  6553. for ( var name$1 in morphAttributes ) {
  6554. var morphArray = [];
  6555. var morphAttribute = morphAttributes[ name$1 ]; // morphAttribute: array of Float32BufferAttributes
  6556. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6557. var attribute$1 = morphAttribute[ i ];
  6558. var newAttribute$1 = convertBufferAttribute( attribute$1, indices );
  6559. morphArray.push( newAttribute$1 );
  6560. }
  6561. geometry2.morphAttributes[ name$1 ] = morphArray;
  6562. }
  6563. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6564. // groups
  6565. var groups = this.groups;
  6566. for ( var i$1 = 0, l = groups.length; i$1 < l; i$1 ++ ) {
  6567. var group = groups[ i$1 ];
  6568. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6569. }
  6570. return geometry2;
  6571. },
  6572. toJSON: function () {
  6573. var data = {
  6574. metadata: {
  6575. version: 4.5,
  6576. type: 'BufferGeometry',
  6577. generator: 'BufferGeometry.toJSON'
  6578. }
  6579. };
  6580. // standard BufferGeometry serialization
  6581. data.uuid = this.uuid;
  6582. data.type = this.type;
  6583. if ( this.name !== '' ) { data.name = this.name; }
  6584. if ( Object.keys( this.userData ).length > 0 ) { data.userData = this.userData; }
  6585. if ( this.parameters !== undefined ) {
  6586. var parameters = this.parameters;
  6587. for ( var key in parameters ) {
  6588. if ( parameters[ key ] !== undefined ) { data[ key ] = parameters[ key ]; }
  6589. }
  6590. return data;
  6591. }
  6592. data.data = { attributes: {} };
  6593. var index = this.index;
  6594. if ( index !== null ) {
  6595. data.data.index = {
  6596. type: index.array.constructor.name,
  6597. array: Array.prototype.slice.call( index.array )
  6598. };
  6599. }
  6600. var attributes = this.attributes;
  6601. for ( var key$1 in attributes ) {
  6602. var attribute = attributes[ key$1 ];
  6603. var attributeData = attribute.toJSON( data.data );
  6604. if ( attribute.name !== '' ) { attributeData.name = attribute.name; }
  6605. data.data.attributes[ key$1 ] = attributeData;
  6606. }
  6607. var morphAttributes = {};
  6608. var hasMorphAttributes = false;
  6609. for ( var key$2 in this.morphAttributes ) {
  6610. var attributeArray = this.morphAttributes[ key$2 ];
  6611. var array = [];
  6612. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6613. var attribute$1 = attributeArray[ i ];
  6614. var attributeData$1 = attribute$1.toJSON( data.data );
  6615. if ( attribute$1.name !== '' ) { attributeData$1.name = attribute$1.name; }
  6616. array.push( attributeData$1 );
  6617. }
  6618. if ( array.length > 0 ) {
  6619. morphAttributes[ key$2 ] = array;
  6620. hasMorphAttributes = true;
  6621. }
  6622. }
  6623. if ( hasMorphAttributes ) {
  6624. data.data.morphAttributes = morphAttributes;
  6625. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6626. }
  6627. var groups = this.groups;
  6628. if ( groups.length > 0 ) {
  6629. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6630. }
  6631. var boundingSphere = this.boundingSphere;
  6632. if ( boundingSphere !== null ) {
  6633. data.data.boundingSphere = {
  6634. center: boundingSphere.center.toArray(),
  6635. radius: boundingSphere.radius
  6636. };
  6637. }
  6638. return data;
  6639. },
  6640. clone: function () {
  6641. /*
  6642. // Handle primitives
  6643. const parameters = this.parameters;
  6644. if ( parameters !== undefined ) {
  6645. const values = [];
  6646. for ( const key in parameters ) {
  6647. values.push( parameters[ key ] );
  6648. }
  6649. const geometry = Object.create( this.constructor.prototype );
  6650. this.constructor.apply( geometry, values );
  6651. return geometry;
  6652. }
  6653. return new this.constructor().copy( this );
  6654. */
  6655. return new BufferGeometry().copy( this );
  6656. },
  6657. copy: function ( source ) {
  6658. // reset
  6659. this.index = null;
  6660. this.attributes = {};
  6661. this.morphAttributes = {};
  6662. this.groups = [];
  6663. this.boundingBox = null;
  6664. this.boundingSphere = null;
  6665. // used for storing cloned, shared data
  6666. var data = {};
  6667. // name
  6668. this.name = source.name;
  6669. // index
  6670. var index = source.index;
  6671. if ( index !== null ) {
  6672. this.setIndex( index.clone( data ) );
  6673. }
  6674. // attributes
  6675. var attributes = source.attributes;
  6676. for ( var name in attributes ) {
  6677. var attribute = attributes[ name ];
  6678. this.setAttribute( name, attribute.clone( data ) );
  6679. }
  6680. // morph attributes
  6681. var morphAttributes = source.morphAttributes;
  6682. for ( var name$1 in morphAttributes ) {
  6683. var array = [];
  6684. var morphAttribute = morphAttributes[ name$1 ]; // morphAttribute: array of Float32BufferAttributes
  6685. for ( var i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6686. array.push( morphAttribute[ i ].clone( data ) );
  6687. }
  6688. this.morphAttributes[ name$1 ] = array;
  6689. }
  6690. this.morphTargetsRelative = source.morphTargetsRelative;
  6691. // groups
  6692. var groups = source.groups;
  6693. for ( var i$1 = 0, l$1 = groups.length; i$1 < l$1; i$1 ++ ) {
  6694. var group = groups[ i$1 ];
  6695. this.addGroup( group.start, group.count, group.materialIndex );
  6696. }
  6697. // bounding box
  6698. var boundingBox = source.boundingBox;
  6699. if ( boundingBox !== null ) {
  6700. this.boundingBox = boundingBox.clone();
  6701. }
  6702. // bounding sphere
  6703. var boundingSphere = source.boundingSphere;
  6704. if ( boundingSphere !== null ) {
  6705. this.boundingSphere = boundingSphere.clone();
  6706. }
  6707. // draw range
  6708. this.drawRange.start = source.drawRange.start;
  6709. this.drawRange.count = source.drawRange.count;
  6710. // user data
  6711. this.userData = source.userData;
  6712. return this;
  6713. },
  6714. dispose: function () {
  6715. this.dispatchEvent( { type: 'dispose' } );
  6716. }
  6717. } );
  6718. /**
  6719. * @author mrdoob / http://mrdoob.com/
  6720. * @author alteredq / http://alteredqualia.com/
  6721. * @author mikael emtinger / http://gomo.se/
  6722. * @author jonobr1 / http://jonobr1.com/
  6723. */
  6724. var _inverseMatrix = new Matrix4();
  6725. var _ray = new Ray();
  6726. var _sphere = new Sphere();
  6727. var _vA = new Vector3();
  6728. var _vB = new Vector3();
  6729. var _vC = new Vector3();
  6730. var _tempA = new Vector3();
  6731. var _tempB = new Vector3();
  6732. var _tempC = new Vector3();
  6733. var _morphA = new Vector3();
  6734. var _morphB = new Vector3();
  6735. var _morphC = new Vector3();
  6736. var _uvA = new Vector2();
  6737. var _uvB = new Vector2();
  6738. var _uvC = new Vector2();
  6739. var _intersectionPoint = new Vector3();
  6740. var _intersectionPointWorld = new Vector3();
  6741. function Mesh( geometry, material ) {
  6742. Object3D.call( this );
  6743. this.type = 'Mesh';
  6744. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6745. this.material = material !== undefined ? material : new MeshBasicMaterial();
  6746. this.updateMorphTargets();
  6747. }
  6748. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6749. constructor: Mesh,
  6750. isMesh: true,
  6751. copy: function ( source ) {
  6752. Object3D.prototype.copy.call( this, source );
  6753. if ( source.morphTargetInfluences !== undefined ) {
  6754. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6755. }
  6756. if ( source.morphTargetDictionary !== undefined ) {
  6757. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6758. }
  6759. this.material = source.material;
  6760. this.geometry = source.geometry;
  6761. return this;
  6762. },
  6763. updateMorphTargets: function () {
  6764. var geometry = this.geometry;
  6765. if ( geometry.isBufferGeometry ) {
  6766. var morphAttributes = geometry.morphAttributes;
  6767. var keys = Object.keys( morphAttributes );
  6768. if ( keys.length > 0 ) {
  6769. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6770. if ( morphAttribute !== undefined ) {
  6771. this.morphTargetInfluences = [];
  6772. this.morphTargetDictionary = {};
  6773. for ( var m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6774. var name = morphAttribute[ m ].name || String( m );
  6775. this.morphTargetInfluences.push( 0 );
  6776. this.morphTargetDictionary[ name ] = m;
  6777. }
  6778. }
  6779. }
  6780. } else {
  6781. var morphTargets = geometry.morphTargets;
  6782. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6783. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6784. }
  6785. }
  6786. },
  6787. raycast: function ( raycaster, intersects ) {
  6788. var geometry = this.geometry;
  6789. var material = this.material;
  6790. var matrixWorld = this.matrixWorld;
  6791. if ( material === undefined ) { return; }
  6792. // Checking boundingSphere distance to ray
  6793. if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); }
  6794. _sphere.copy( geometry.boundingSphere );
  6795. _sphere.applyMatrix4( matrixWorld );
  6796. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) { return; }
  6797. //
  6798. _inverseMatrix.getInverse( matrixWorld );
  6799. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6800. // Check boundingBox before continuing
  6801. if ( geometry.boundingBox !== null ) {
  6802. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) { return; }
  6803. }
  6804. var intersection;
  6805. if ( geometry.isBufferGeometry ) {
  6806. var index = geometry.index;
  6807. var position = geometry.attributes.position;
  6808. var morphPosition = geometry.morphAttributes.position;
  6809. var morphTargetsRelative = geometry.morphTargetsRelative;
  6810. var uv = geometry.attributes.uv;
  6811. var uv2 = geometry.attributes.uv2;
  6812. var groups = geometry.groups;
  6813. var drawRange = geometry.drawRange;
  6814. if ( index !== null ) {
  6815. // indexed buffer geometry
  6816. if ( Array.isArray( material ) ) {
  6817. for ( var i = 0, il = groups.length; i < il; i ++ ) {
  6818. var group = groups[ i ];
  6819. var groupMaterial = material[ group.materialIndex ];
  6820. var start = Math.max( group.start, drawRange.start );
  6821. var end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6822. for ( var j = start, jl = end; j < jl; j += 3 ) {
  6823. var a = index.getX( j );
  6824. var b = index.getX( j + 1 );
  6825. var c = index.getX( j + 2 );
  6826. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6827. if ( intersection ) {
  6828. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6829. intersection.face.materialIndex = group.materialIndex;
  6830. intersects.push( intersection );
  6831. }
  6832. }
  6833. }
  6834. } else {
  6835. var start$1 = Math.max( 0, drawRange.start );
  6836. var end$1 = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6837. for ( var i$1 = start$1, il$1 = end$1; i$1 < il$1; i$1 += 3 ) {
  6838. var a$1 = index.getX( i$1 );
  6839. var b$1 = index.getX( i$1 + 1 );
  6840. var c$1 = index.getX( i$1 + 2 );
  6841. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a$1, b$1, c$1 );
  6842. if ( intersection ) {
  6843. intersection.faceIndex = Math.floor( i$1 / 3 ); // triangle number in indexed buffer semantics
  6844. intersects.push( intersection );
  6845. }
  6846. }
  6847. }
  6848. } else if ( position !== undefined ) {
  6849. // non-indexed buffer geometry
  6850. if ( Array.isArray( material ) ) {
  6851. for ( var i$2 = 0, il$2 = groups.length; i$2 < il$2; i$2 ++ ) {
  6852. var group$1 = groups[ i$2 ];
  6853. var groupMaterial$1 = material[ group$1.materialIndex ];
  6854. var start$2 = Math.max( group$1.start, drawRange.start );
  6855. var end$2 = Math.min( ( group$1.start + group$1.count ), ( drawRange.start + drawRange.count ) );
  6856. for ( var j$1 = start$2, jl$1 = end$2; j$1 < jl$1; j$1 += 3 ) {
  6857. var a$2 = j$1;
  6858. var b$2 = j$1 + 1;
  6859. var c$2 = j$1 + 2;
  6860. intersection = checkBufferGeometryIntersection( this, groupMaterial$1, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a$2, b$2, c$2 );
  6861. if ( intersection ) {
  6862. intersection.faceIndex = Math.floor( j$1 / 3 ); // triangle number in non-indexed buffer semantics
  6863. intersection.face.materialIndex = group$1.materialIndex;
  6864. intersects.push( intersection );
  6865. }
  6866. }
  6867. }
  6868. } else {
  6869. var start$3 = Math.max( 0, drawRange.start );
  6870. var end$3 = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6871. for ( var i$3 = start$3, il$3 = end$3; i$3 < il$3; i$3 += 3 ) {
  6872. var a$3 = i$3;
  6873. var b$3 = i$3 + 1;
  6874. var c$3 = i$3 + 2;
  6875. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a$3, b$3, c$3 );
  6876. if ( intersection ) {
  6877. intersection.faceIndex = Math.floor( i$3 / 3 ); // triangle number in non-indexed buffer semantics
  6878. intersects.push( intersection );
  6879. }
  6880. }
  6881. }
  6882. }
  6883. } else if ( geometry.isGeometry ) {
  6884. var isMultiMaterial = Array.isArray( material );
  6885. var vertices = geometry.vertices;
  6886. var faces = geometry.faces;
  6887. var uvs;
  6888. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6889. if ( faceVertexUvs.length > 0 ) { uvs = faceVertexUvs; }
  6890. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6891. var face = faces[ f ];
  6892. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6893. if ( faceMaterial === undefined ) { continue; }
  6894. var fvA = vertices[ face.a ];
  6895. var fvB = vertices[ face.b ];
  6896. var fvC = vertices[ face.c ];
  6897. intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
  6898. if ( intersection ) {
  6899. if ( uvs && uvs[ f ] ) {
  6900. var uvs_f = uvs[ f ];
  6901. _uvA.copy( uvs_f[ 0 ] );
  6902. _uvB.copy( uvs_f[ 1 ] );
  6903. _uvC.copy( uvs_f[ 2 ] );
  6904. intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
  6905. }
  6906. intersection.face = face;
  6907. intersection.faceIndex = f;
  6908. intersects.push( intersection );
  6909. }
  6910. }
  6911. }
  6912. }
  6913. } );
  6914. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6915. var intersect;
  6916. if ( material.side === BackSide ) {
  6917. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6918. } else {
  6919. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6920. }
  6921. if ( intersect === null ) { return null; }
  6922. _intersectionPointWorld.copy( point );
  6923. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6924. var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6925. if ( distance < raycaster.near || distance > raycaster.far ) { return null; }
  6926. return {
  6927. distance: distance,
  6928. point: _intersectionPointWorld.clone(),
  6929. object: object
  6930. };
  6931. }
  6932. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6933. _vA.fromBufferAttribute( position, a );
  6934. _vB.fromBufferAttribute( position, b );
  6935. _vC.fromBufferAttribute( position, c );
  6936. var morphInfluences = object.morphTargetInfluences;
  6937. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6938. _morphA.set( 0, 0, 0 );
  6939. _morphB.set( 0, 0, 0 );
  6940. _morphC.set( 0, 0, 0 );
  6941. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6942. var influence = morphInfluences[ i ];
  6943. var morphAttribute = morphPosition[ i ];
  6944. if ( influence === 0 ) { continue; }
  6945. _tempA.fromBufferAttribute( morphAttribute, a );
  6946. _tempB.fromBufferAttribute( morphAttribute, b );
  6947. _tempC.fromBufferAttribute( morphAttribute, c );
  6948. if ( morphTargetsRelative ) {
  6949. _morphA.addScaledVector( _tempA, influence );
  6950. _morphB.addScaledVector( _tempB, influence );
  6951. _morphC.addScaledVector( _tempC, influence );
  6952. } else {
  6953. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6954. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6955. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6956. }
  6957. }
  6958. _vA.add( _morphA );
  6959. _vB.add( _morphB );
  6960. _vC.add( _morphC );
  6961. }
  6962. if ( object.isSkinnedMesh ) {
  6963. object.boneTransform( a, _vA );
  6964. object.boneTransform( b, _vB );
  6965. object.boneTransform( c, _vC );
  6966. }
  6967. var intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6968. if ( intersection ) {
  6969. if ( uv ) {
  6970. _uvA.fromBufferAttribute( uv, a );
  6971. _uvB.fromBufferAttribute( uv, b );
  6972. _uvC.fromBufferAttribute( uv, c );
  6973. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6974. }
  6975. if ( uv2 ) {
  6976. _uvA.fromBufferAttribute( uv2, a );
  6977. _uvB.fromBufferAttribute( uv2, b );
  6978. _uvC.fromBufferAttribute( uv2, c );
  6979. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6980. }
  6981. var face = new Face3( a, b, c );
  6982. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6983. intersection.face = face;
  6984. }
  6985. return intersection;
  6986. }
  6987. /**
  6988. * @author mrdoob / http://mrdoob.com/
  6989. * @author kile / http://kile.stravaganza.org/
  6990. * @author alteredq / http://alteredqualia.com/
  6991. * @author mikael emtinger / http://gomo.se/
  6992. * @author zz85 / http://www.lab4games.net/zz85/blog
  6993. * @author bhouston / http://clara.io
  6994. */
  6995. var _geometryId = 0; // Geometry uses even numbers as Id
  6996. var _m1$3 = new Matrix4();
  6997. var _obj$1 = new Object3D();
  6998. var _offset$1 = new Vector3();
  6999. function Geometry() {
  7000. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  7001. this.uuid = MathUtils.generateUUID();
  7002. this.name = '';
  7003. this.type = 'Geometry';
  7004. this.vertices = [];
  7005. this.colors = [];
  7006. this.faces = [];
  7007. this.faceVertexUvs = [[]];
  7008. this.morphTargets = [];
  7009. this.morphNormals = [];
  7010. this.skinWeights = [];
  7011. this.skinIndices = [];
  7012. this.lineDistances = [];
  7013. this.boundingBox = null;
  7014. this.boundingSphere = null;
  7015. // update flags
  7016. this.elementsNeedUpdate = false;
  7017. this.verticesNeedUpdate = false;
  7018. this.uvsNeedUpdate = false;
  7019. this.normalsNeedUpdate = false;
  7020. this.colorsNeedUpdate = false;
  7021. this.lineDistancesNeedUpdate = false;
  7022. this.groupsNeedUpdate = false;
  7023. }
  7024. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7025. constructor: Geometry,
  7026. isGeometry: true,
  7027. applyMatrix4: function ( matrix ) {
  7028. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7029. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  7030. var vertex = this.vertices[ i ];
  7031. vertex.applyMatrix4( matrix );
  7032. }
  7033. for ( var i$1 = 0, il$1 = this.faces.length; i$1 < il$1; i$1 ++ ) {
  7034. var face = this.faces[ i$1 ];
  7035. face.normal.applyMatrix3( normalMatrix ).normalize();
  7036. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  7037. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  7038. }
  7039. }
  7040. if ( this.boundingBox !== null ) {
  7041. this.computeBoundingBox();
  7042. }
  7043. if ( this.boundingSphere !== null ) {
  7044. this.computeBoundingSphere();
  7045. }
  7046. this.verticesNeedUpdate = true;
  7047. this.normalsNeedUpdate = true;
  7048. return this;
  7049. },
  7050. rotateX: function ( angle ) {
  7051. // rotate geometry around world x-axis
  7052. _m1$3.makeRotationX( angle );
  7053. this.applyMatrix4( _m1$3 );
  7054. return this;
  7055. },
  7056. rotateY: function ( angle ) {
  7057. // rotate geometry around world y-axis
  7058. _m1$3.makeRotationY( angle );
  7059. this.applyMatrix4( _m1$3 );
  7060. return this;
  7061. },
  7062. rotateZ: function ( angle ) {
  7063. // rotate geometry around world z-axis
  7064. _m1$3.makeRotationZ( angle );
  7065. this.applyMatrix4( _m1$3 );
  7066. return this;
  7067. },
  7068. translate: function ( x, y, z ) {
  7069. // translate geometry
  7070. _m1$3.makeTranslation( x, y, z );
  7071. this.applyMatrix4( _m1$3 );
  7072. return this;
  7073. },
  7074. scale: function ( x, y, z ) {
  7075. // scale geometry
  7076. _m1$3.makeScale( x, y, z );
  7077. this.applyMatrix4( _m1$3 );
  7078. return this;
  7079. },
  7080. lookAt: function ( vector ) {
  7081. _obj$1.lookAt( vector );
  7082. _obj$1.updateMatrix();
  7083. this.applyMatrix4( _obj$1.matrix );
  7084. return this;
  7085. },
  7086. fromBufferGeometry: function ( geometry ) {
  7087. var scope = this;
  7088. var index = geometry.index !== null ? geometry.index : undefined;
  7089. var attributes = geometry.attributes;
  7090. if ( attributes.position === undefined ) {
  7091. console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
  7092. return this;
  7093. }
  7094. var position = attributes.position;
  7095. var normal = attributes.normal;
  7096. var color = attributes.color;
  7097. var uv = attributes.uv;
  7098. var uv2 = attributes.uv2;
  7099. if ( uv2 !== undefined ) { this.faceVertexUvs[ 1 ] = []; }
  7100. for ( var i = 0; i < position.count; i ++ ) {
  7101. scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
  7102. if ( color !== undefined ) {
  7103. scope.colors.push( new Color().fromBufferAttribute( color, i ) );
  7104. }
  7105. }
  7106. function addFace( a, b, c, materialIndex ) {
  7107. var vertexColors = ( color === undefined ) ? [] : [
  7108. scope.colors[ a ].clone(),
  7109. scope.colors[ b ].clone(),
  7110. scope.colors[ c ].clone()
  7111. ];
  7112. var vertexNormals = ( normal === undefined ) ? [] : [
  7113. new Vector3().fromBufferAttribute( normal, a ),
  7114. new Vector3().fromBufferAttribute( normal, b ),
  7115. new Vector3().fromBufferAttribute( normal, c )
  7116. ];
  7117. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7118. scope.faces.push( face );
  7119. if ( uv !== undefined ) {
  7120. scope.faceVertexUvs[ 0 ].push( [
  7121. new Vector2().fromBufferAttribute( uv, a ),
  7122. new Vector2().fromBufferAttribute( uv, b ),
  7123. new Vector2().fromBufferAttribute( uv, c )
  7124. ] );
  7125. }
  7126. if ( uv2 !== undefined ) {
  7127. scope.faceVertexUvs[ 1 ].push( [
  7128. new Vector2().fromBufferAttribute( uv2, a ),
  7129. new Vector2().fromBufferAttribute( uv2, b ),
  7130. new Vector2().fromBufferAttribute( uv2, c )
  7131. ] );
  7132. }
  7133. }
  7134. var groups = geometry.groups;
  7135. if ( groups.length > 0 ) {
  7136. for ( var i$1 = 0; i$1 < groups.length; i$1 ++ ) {
  7137. var group = groups[ i$1 ];
  7138. var start = group.start;
  7139. var count = group.count;
  7140. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  7141. if ( index !== undefined ) {
  7142. addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
  7143. } else {
  7144. addFace( j, j + 1, j + 2, group.materialIndex );
  7145. }
  7146. }
  7147. }
  7148. } else {
  7149. if ( index !== undefined ) {
  7150. for ( var i$2 = 0; i$2 < index.count; i$2 += 3 ) {
  7151. addFace( index.getX( i$2 ), index.getX( i$2 + 1 ), index.getX( i$2 + 2 ) );
  7152. }
  7153. } else {
  7154. for ( var i$3 = 0; i$3 < position.count; i$3 += 3 ) {
  7155. addFace( i$3, i$3 + 1, i$3 + 2 );
  7156. }
  7157. }
  7158. }
  7159. this.computeFaceNormals();
  7160. if ( geometry.boundingBox !== null ) {
  7161. this.boundingBox = geometry.boundingBox.clone();
  7162. }
  7163. if ( geometry.boundingSphere !== null ) {
  7164. this.boundingSphere = geometry.boundingSphere.clone();
  7165. }
  7166. return this;
  7167. },
  7168. center: function () {
  7169. this.computeBoundingBox();
  7170. this.boundingBox.getCenter( _offset$1 ).negate();
  7171. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  7172. return this;
  7173. },
  7174. normalize: function () {
  7175. this.computeBoundingSphere();
  7176. var center = this.boundingSphere.center;
  7177. var radius = this.boundingSphere.radius;
  7178. var s = radius === 0 ? 1 : 1.0 / radius;
  7179. var matrix = new Matrix4();
  7180. matrix.set(
  7181. s, 0, 0, - s * center.x,
  7182. 0, s, 0, - s * center.y,
  7183. 0, 0, s, - s * center.z,
  7184. 0, 0, 0, 1
  7185. );
  7186. this.applyMatrix4( matrix );
  7187. return this;
  7188. },
  7189. computeFaceNormals: function () {
  7190. var cb = new Vector3(), ab = new Vector3();
  7191. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7192. var face = this.faces[ f ];
  7193. var vA = this.vertices[ face.a ];
  7194. var vB = this.vertices[ face.b ];
  7195. var vC = this.vertices[ face.c ];
  7196. cb.subVectors( vC, vB );
  7197. ab.subVectors( vA, vB );
  7198. cb.cross( ab );
  7199. cb.normalize();
  7200. face.normal.copy( cb );
  7201. }
  7202. },
  7203. computeVertexNormals: function ( areaWeighted ) {
  7204. if ( areaWeighted === undefined ) { areaWeighted = true; }
  7205. var vertices = new Array( this.vertices.length );
  7206. for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7207. vertices[ v ] = new Vector3();
  7208. }
  7209. if ( areaWeighted ) {
  7210. // vertex normals weighted by triangle areas
  7211. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7212. var cb = new Vector3(), ab = new Vector3();
  7213. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7214. var face = this.faces[ f ];
  7215. var vA = this.vertices[ face.a ];
  7216. var vB = this.vertices[ face.b ];
  7217. var vC = this.vertices[ face.c ];
  7218. cb.subVectors( vC, vB );
  7219. ab.subVectors( vA, vB );
  7220. cb.cross( ab );
  7221. vertices[ face.a ].add( cb );
  7222. vertices[ face.b ].add( cb );
  7223. vertices[ face.c ].add( cb );
  7224. }
  7225. } else {
  7226. this.computeFaceNormals();
  7227. for ( var f$1 = 0, fl$1 = this.faces.length; f$1 < fl$1; f$1 ++ ) {
  7228. var face$1 = this.faces[ f$1 ];
  7229. vertices[ face$1.a ].add( face$1.normal );
  7230. vertices[ face$1.b ].add( face$1.normal );
  7231. vertices[ face$1.c ].add( face$1.normal );
  7232. }
  7233. }
  7234. for ( var v$1 = 0, vl$1 = this.vertices.length; v$1 < vl$1; v$1 ++ ) {
  7235. vertices[ v$1 ].normalize();
  7236. }
  7237. for ( var f$2 = 0, fl$2 = this.faces.length; f$2 < fl$2; f$2 ++ ) {
  7238. var face$2 = this.faces[ f$2 ];
  7239. var vertexNormals = face$2.vertexNormals;
  7240. if ( vertexNormals.length === 3 ) {
  7241. vertexNormals[ 0 ].copy( vertices[ face$2.a ] );
  7242. vertexNormals[ 1 ].copy( vertices[ face$2.b ] );
  7243. vertexNormals[ 2 ].copy( vertices[ face$2.c ] );
  7244. } else {
  7245. vertexNormals[ 0 ] = vertices[ face$2.a ].clone();
  7246. vertexNormals[ 1 ] = vertices[ face$2.b ].clone();
  7247. vertexNormals[ 2 ] = vertices[ face$2.c ].clone();
  7248. }
  7249. }
  7250. if ( this.faces.length > 0 ) {
  7251. this.normalsNeedUpdate = true;
  7252. }
  7253. },
  7254. computeFlatVertexNormals: function () {
  7255. this.computeFaceNormals();
  7256. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7257. var face = this.faces[ f ];
  7258. var vertexNormals = face.vertexNormals;
  7259. if ( vertexNormals.length === 3 ) {
  7260. vertexNormals[ 0 ].copy( face.normal );
  7261. vertexNormals[ 1 ].copy( face.normal );
  7262. vertexNormals[ 2 ].copy( face.normal );
  7263. } else {
  7264. vertexNormals[ 0 ] = face.normal.clone();
  7265. vertexNormals[ 1 ] = face.normal.clone();
  7266. vertexNormals[ 2 ] = face.normal.clone();
  7267. }
  7268. }
  7269. if ( this.faces.length > 0 ) {
  7270. this.normalsNeedUpdate = true;
  7271. }
  7272. },
  7273. computeMorphNormals: function () {
  7274. // save original normals
  7275. // - create temp variables on first access
  7276. // otherwise just copy (for faster repeated calls)
  7277. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7278. var face = this.faces[ f ];
  7279. if ( ! face.__originalFaceNormal ) {
  7280. face.__originalFaceNormal = face.normal.clone();
  7281. } else {
  7282. face.__originalFaceNormal.copy( face.normal );
  7283. }
  7284. if ( ! face.__originalVertexNormals ) { face.__originalVertexNormals = []; }
  7285. for ( var i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7286. if ( ! face.__originalVertexNormals[ i ] ) {
  7287. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7288. } else {
  7289. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7290. }
  7291. }
  7292. }
  7293. // use temp geometry to compute face and vertex normals for each morph
  7294. var tmpGeo = new Geometry();
  7295. tmpGeo.faces = this.faces;
  7296. for ( var i$1 = 0, il$1 = this.morphTargets.length; i$1 < il$1; i$1 ++ ) {
  7297. // create on first access
  7298. if ( ! this.morphNormals[ i$1 ] ) {
  7299. this.morphNormals[ i$1 ] = {};
  7300. this.morphNormals[ i$1 ].faceNormals = [];
  7301. this.morphNormals[ i$1 ].vertexNormals = [];
  7302. var dstNormalsFace = this.morphNormals[ i$1 ].faceNormals;
  7303. var dstNormalsVertex = this.morphNormals[ i$1 ].vertexNormals;
  7304. for ( var f$1 = 0, fl$1 = this.faces.length; f$1 < fl$1; f$1 ++ ) {
  7305. var faceNormal = new Vector3();
  7306. var vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7307. dstNormalsFace.push( faceNormal );
  7308. dstNormalsVertex.push( vertexNormals );
  7309. }
  7310. }
  7311. var morphNormals = this.morphNormals[ i$1 ];
  7312. // set vertices to morph target
  7313. tmpGeo.vertices = this.morphTargets[ i$1 ].vertices;
  7314. // compute morph normals
  7315. tmpGeo.computeFaceNormals();
  7316. tmpGeo.computeVertexNormals();
  7317. // store morph normals
  7318. for ( var f$2 = 0, fl$2 = this.faces.length; f$2 < fl$2; f$2 ++ ) {
  7319. var face$1 = this.faces[ f$2 ];
  7320. var faceNormal$1 = morphNormals.faceNormals[ f$2 ];
  7321. var vertexNormals$1 = morphNormals.vertexNormals[ f$2 ];
  7322. faceNormal$1.copy( face$1.normal );
  7323. vertexNormals$1.a.copy( face$1.vertexNormals[ 0 ] );
  7324. vertexNormals$1.b.copy( face$1.vertexNormals[ 1 ] );
  7325. vertexNormals$1.c.copy( face$1.vertexNormals[ 2 ] );
  7326. }
  7327. }
  7328. // restore original normals
  7329. for ( var f$3 = 0, fl$3 = this.faces.length; f$3 < fl$3; f$3 ++ ) {
  7330. var face$2 = this.faces[ f$3 ];
  7331. face$2.normal = face$2.__originalFaceNormal;
  7332. face$2.vertexNormals = face$2.__originalVertexNormals;
  7333. }
  7334. },
  7335. computeBoundingBox: function () {
  7336. if ( this.boundingBox === null ) {
  7337. this.boundingBox = new Box3();
  7338. }
  7339. this.boundingBox.setFromPoints( this.vertices );
  7340. },
  7341. computeBoundingSphere: function () {
  7342. if ( this.boundingSphere === null ) {
  7343. this.boundingSphere = new Sphere();
  7344. }
  7345. this.boundingSphere.setFromPoints( this.vertices );
  7346. },
  7347. merge: function ( geometry, matrix, materialIndexOffset ) {
  7348. if ( ! ( geometry && geometry.isGeometry ) ) {
  7349. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7350. return;
  7351. }
  7352. var normalMatrix,
  7353. vertexOffset = this.vertices.length,
  7354. vertices1 = this.vertices,
  7355. vertices2 = geometry.vertices,
  7356. faces1 = this.faces,
  7357. faces2 = geometry.faces,
  7358. colors1 = this.colors,
  7359. colors2 = geometry.colors;
  7360. if ( materialIndexOffset === undefined ) { materialIndexOffset = 0; }
  7361. if ( matrix !== undefined ) {
  7362. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7363. }
  7364. // vertices
  7365. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7366. var vertex = vertices2[ i ];
  7367. var vertexCopy = vertex.clone();
  7368. if ( matrix !== undefined ) { vertexCopy.applyMatrix4( matrix ); }
  7369. vertices1.push( vertexCopy );
  7370. }
  7371. // colors
  7372. for ( var i$1 = 0, il$1 = colors2.length; i$1 < il$1; i$1 ++ ) {
  7373. colors1.push( colors2[ i$1 ].clone() );
  7374. }
  7375. // faces
  7376. for ( var i$2 = 0, il$2 = faces2.length; i$2 < il$2; i$2 ++ ) {
  7377. var face = faces2[ i$2 ], faceCopy = (void 0), normal = (void 0), color = (void 0),
  7378. faceVertexNormals = face.vertexNormals,
  7379. faceVertexColors = face.vertexColors;
  7380. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7381. faceCopy.normal.copy( face.normal );
  7382. if ( normalMatrix !== undefined ) {
  7383. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7384. }
  7385. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7386. normal = faceVertexNormals[ j ].clone();
  7387. if ( normalMatrix !== undefined ) {
  7388. normal.applyMatrix3( normalMatrix ).normalize();
  7389. }
  7390. faceCopy.vertexNormals.push( normal );
  7391. }
  7392. faceCopy.color.copy( face.color );
  7393. for ( var j$1 = 0, jl$1 = faceVertexColors.length; j$1 < jl$1; j$1 ++ ) {
  7394. color = faceVertexColors[ j$1 ];
  7395. faceCopy.vertexColors.push( color.clone() );
  7396. }
  7397. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7398. faces1.push( faceCopy );
  7399. }
  7400. // uvs
  7401. for ( var i$3 = 0, il$3 = geometry.faceVertexUvs.length; i$3 < il$3; i$3 ++ ) {
  7402. var faceVertexUvs2 = geometry.faceVertexUvs[ i$3 ];
  7403. if ( this.faceVertexUvs[ i$3 ] === undefined ) { this.faceVertexUvs[ i$3 ] = []; }
  7404. for ( var j$2 = 0, jl$2 = faceVertexUvs2.length; j$2 < jl$2; j$2 ++ ) {
  7405. var uvs2 = faceVertexUvs2[ j$2 ], uvsCopy = [];
  7406. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7407. uvsCopy.push( uvs2[ k ].clone() );
  7408. }
  7409. this.faceVertexUvs[ i$3 ].push( uvsCopy );
  7410. }
  7411. }
  7412. },
  7413. mergeMesh: function ( mesh ) {
  7414. if ( ! ( mesh && mesh.isMesh ) ) {
  7415. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7416. return;
  7417. }
  7418. if ( mesh.matrixAutoUpdate ) { mesh.updateMatrix(); }
  7419. this.merge( mesh.geometry, mesh.matrix );
  7420. },
  7421. /*
  7422. * Checks for duplicate vertices with hashmap.
  7423. * Duplicated vertices are removed
  7424. * and faces' vertices are updated.
  7425. */
  7426. mergeVertices: function () {
  7427. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7428. var unique = [], changes = [];
  7429. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7430. var precision = Math.pow( 10, precisionPoints );
  7431. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  7432. var v = this.vertices[ i ];
  7433. var key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7434. if ( verticesMap[ key ] === undefined ) {
  7435. verticesMap[ key ] = i;
  7436. unique.push( this.vertices[ i ] );
  7437. changes[ i ] = unique.length - 1;
  7438. } else {
  7439. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7440. changes[ i ] = changes[ verticesMap[ key ] ];
  7441. }
  7442. }
  7443. // if faces are completely degenerate after merging vertices, we
  7444. // have to remove them from the geometry.
  7445. var faceIndicesToRemove = [];
  7446. for ( var i$1 = 0, il$1 = this.faces.length; i$1 < il$1; i$1 ++ ) {
  7447. var face = this.faces[ i$1 ];
  7448. face.a = changes[ face.a ];
  7449. face.b = changes[ face.b ];
  7450. face.c = changes[ face.c ];
  7451. var indices = [ face.a, face.b, face.c ];
  7452. // if any duplicate vertices are found in a Face3
  7453. // we have to remove the face as nothing can be saved
  7454. for ( var n = 0; n < 3; n ++ ) {
  7455. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7456. faceIndicesToRemove.push( i$1 );
  7457. break;
  7458. }
  7459. }
  7460. }
  7461. for ( var i$2 = faceIndicesToRemove.length - 1; i$2 >= 0; i$2 -- ) {
  7462. var idx = faceIndicesToRemove[ i$2 ];
  7463. this.faces.splice( idx, 1 );
  7464. for ( var j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7465. this.faceVertexUvs[ j ].splice( idx, 1 );
  7466. }
  7467. }
  7468. // Use unique set of vertices
  7469. var diff = this.vertices.length - unique.length;
  7470. this.vertices = unique;
  7471. return diff;
  7472. },
  7473. setFromPoints: function ( points ) {
  7474. this.vertices = [];
  7475. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7476. var point = points[ i ];
  7477. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7478. }
  7479. return this;
  7480. },
  7481. sortFacesByMaterialIndex: function () {
  7482. var faces = this.faces;
  7483. var length = faces.length;
  7484. // tag faces
  7485. for ( var i = 0; i < length; i ++ ) {
  7486. faces[ i ]._id = i;
  7487. }
  7488. // sort faces
  7489. function materialIndexSort( a, b ) {
  7490. return a.materialIndex - b.materialIndex;
  7491. }
  7492. faces.sort( materialIndexSort );
  7493. // sort uvs
  7494. var uvs1 = this.faceVertexUvs[ 0 ];
  7495. var uvs2 = this.faceVertexUvs[ 1 ];
  7496. var newUvs1, newUvs2;
  7497. if ( uvs1 && uvs1.length === length ) { newUvs1 = []; }
  7498. if ( uvs2 && uvs2.length === length ) { newUvs2 = []; }
  7499. for ( var i$1 = 0; i$1 < length; i$1 ++ ) {
  7500. var id = faces[ i$1 ]._id;
  7501. if ( newUvs1 ) { newUvs1.push( uvs1[ id ] ); }
  7502. if ( newUvs2 ) { newUvs2.push( uvs2[ id ] ); }
  7503. }
  7504. if ( newUvs1 ) { this.faceVertexUvs[ 0 ] = newUvs1; }
  7505. if ( newUvs2 ) { this.faceVertexUvs[ 1 ] = newUvs2; }
  7506. },
  7507. toJSON: function () {
  7508. var data = {
  7509. metadata: {
  7510. version: 4.5,
  7511. type: 'Geometry',
  7512. generator: 'Geometry.toJSON'
  7513. }
  7514. };
  7515. // standard Geometry serialization
  7516. data.uuid = this.uuid;
  7517. data.type = this.type;
  7518. if ( this.name !== '' ) { data.name = this.name; }
  7519. if ( this.parameters !== undefined ) {
  7520. var parameters = this.parameters;
  7521. for ( var key in parameters ) {
  7522. if ( parameters[ key ] !== undefined ) { data[ key ] = parameters[ key ]; }
  7523. }
  7524. return data;
  7525. }
  7526. var vertices = [];
  7527. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7528. var vertex = this.vertices[ i ];
  7529. vertices.push( vertex.x, vertex.y, vertex.z );
  7530. }
  7531. var faces = [];
  7532. var normals = [];
  7533. var normalsHash = {};
  7534. var colors = [];
  7535. var colorsHash = {};
  7536. var uvs = [];
  7537. var uvsHash = {};
  7538. for ( var i$1 = 0; i$1 < this.faces.length; i$1 ++ ) {
  7539. var face = this.faces[ i$1 ];
  7540. var hasMaterial = true;
  7541. var hasFaceUv = false; // deprecated
  7542. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i$1 ] !== undefined;
  7543. var hasFaceNormal = face.normal.length() > 0;
  7544. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7545. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7546. var hasFaceVertexColor = face.vertexColors.length > 0;
  7547. var faceType = 0;
  7548. faceType = setBit( faceType, 0, 0 ); // isQuad
  7549. faceType = setBit( faceType, 1, hasMaterial );
  7550. faceType = setBit( faceType, 2, hasFaceUv );
  7551. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7552. faceType = setBit( faceType, 4, hasFaceNormal );
  7553. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7554. faceType = setBit( faceType, 6, hasFaceColor );
  7555. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7556. faces.push( faceType );
  7557. faces.push( face.a, face.b, face.c );
  7558. faces.push( face.materialIndex );
  7559. if ( hasFaceVertexUv ) {
  7560. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i$1 ];
  7561. faces.push(
  7562. getUvIndex( faceVertexUvs[ 0 ] ),
  7563. getUvIndex( faceVertexUvs[ 1 ] ),
  7564. getUvIndex( faceVertexUvs[ 2 ] )
  7565. );
  7566. }
  7567. if ( hasFaceNormal ) {
  7568. faces.push( getNormalIndex( face.normal ) );
  7569. }
  7570. if ( hasFaceVertexNormal ) {
  7571. var vertexNormals = face.vertexNormals;
  7572. faces.push(
  7573. getNormalIndex( vertexNormals[ 0 ] ),
  7574. getNormalIndex( vertexNormals[ 1 ] ),
  7575. getNormalIndex( vertexNormals[ 2 ] )
  7576. );
  7577. }
  7578. if ( hasFaceColor ) {
  7579. faces.push( getColorIndex( face.color ) );
  7580. }
  7581. if ( hasFaceVertexColor ) {
  7582. var vertexColors = face.vertexColors;
  7583. faces.push(
  7584. getColorIndex( vertexColors[ 0 ] ),
  7585. getColorIndex( vertexColors[ 1 ] ),
  7586. getColorIndex( vertexColors[ 2 ] )
  7587. );
  7588. }
  7589. }
  7590. function setBit( value, position, enabled ) {
  7591. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7592. }
  7593. function getNormalIndex( normal ) {
  7594. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7595. if ( normalsHash[ hash ] !== undefined ) {
  7596. return normalsHash[ hash ];
  7597. }
  7598. normalsHash[ hash ] = normals.length / 3;
  7599. normals.push( normal.x, normal.y, normal.z );
  7600. return normalsHash[ hash ];
  7601. }
  7602. function getColorIndex( color ) {
  7603. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7604. if ( colorsHash[ hash ] !== undefined ) {
  7605. return colorsHash[ hash ];
  7606. }
  7607. colorsHash[ hash ] = colors.length;
  7608. colors.push( color.getHex() );
  7609. return colorsHash[ hash ];
  7610. }
  7611. function getUvIndex( uv ) {
  7612. var hash = uv.x.toString() + uv.y.toString();
  7613. if ( uvsHash[ hash ] !== undefined ) {
  7614. return uvsHash[ hash ];
  7615. }
  7616. uvsHash[ hash ] = uvs.length / 2;
  7617. uvs.push( uv.x, uv.y );
  7618. return uvsHash[ hash ];
  7619. }
  7620. data.data = {};
  7621. data.data.vertices = vertices;
  7622. data.data.normals = normals;
  7623. if ( colors.length > 0 ) { data.data.colors = colors; }
  7624. if ( uvs.length > 0 ) { data.data.uvs = [ uvs ]; } // temporal backward compatibility
  7625. data.data.faces = faces;
  7626. return data;
  7627. },
  7628. clone: function () {
  7629. /*
  7630. // Handle primitives
  7631. const parameters = this.parameters;
  7632. if ( parameters !== undefined ) {
  7633. const values = [];
  7634. for ( const key in parameters ) {
  7635. values.push( parameters[ key ] );
  7636. }
  7637. const geometry = Object.create( this.constructor.prototype );
  7638. this.constructor.apply( geometry, values );
  7639. return geometry;
  7640. }
  7641. return new this.constructor().copy( this );
  7642. */
  7643. return new Geometry().copy( this );
  7644. },
  7645. copy: function ( source ) {
  7646. // reset
  7647. this.vertices = [];
  7648. this.colors = [];
  7649. this.faces = [];
  7650. this.faceVertexUvs = [[]];
  7651. this.morphTargets = [];
  7652. this.morphNormals = [];
  7653. this.skinWeights = [];
  7654. this.skinIndices = [];
  7655. this.lineDistances = [];
  7656. this.boundingBox = null;
  7657. this.boundingSphere = null;
  7658. // name
  7659. this.name = source.name;
  7660. // vertices
  7661. var vertices = source.vertices;
  7662. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  7663. this.vertices.push( vertices[ i ].clone() );
  7664. }
  7665. // colors
  7666. var colors = source.colors;
  7667. for ( var i$1 = 0, il$1 = colors.length; i$1 < il$1; i$1 ++ ) {
  7668. this.colors.push( colors[ i$1 ].clone() );
  7669. }
  7670. // faces
  7671. var faces = source.faces;
  7672. for ( var i$2 = 0, il$2 = faces.length; i$2 < il$2; i$2 ++ ) {
  7673. this.faces.push( faces[ i$2 ].clone() );
  7674. }
  7675. // face vertex uvs
  7676. for ( var i$3 = 0, il$3 = source.faceVertexUvs.length; i$3 < il$3; i$3 ++ ) {
  7677. var faceVertexUvs = source.faceVertexUvs[ i$3 ];
  7678. if ( this.faceVertexUvs[ i$3 ] === undefined ) {
  7679. this.faceVertexUvs[ i$3 ] = [];
  7680. }
  7681. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7682. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7683. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  7684. var uv = uvs[ k ];
  7685. uvsCopy.push( uv.clone() );
  7686. }
  7687. this.faceVertexUvs[ i$3 ].push( uvsCopy );
  7688. }
  7689. }
  7690. // morph targets
  7691. var morphTargets = source.morphTargets;
  7692. for ( var i$4 = 0, il$4 = morphTargets.length; i$4 < il$4; i$4 ++ ) {
  7693. var morphTarget = {};
  7694. morphTarget.name = morphTargets[ i$4 ].name;
  7695. // vertices
  7696. if ( morphTargets[ i$4 ].vertices !== undefined ) {
  7697. morphTarget.vertices = [];
  7698. for ( var j$1 = 0, jl$1 = morphTargets[ i$4 ].vertices.length; j$1 < jl$1; j$1 ++ ) {
  7699. morphTarget.vertices.push( morphTargets[ i$4 ].vertices[ j$1 ].clone() );
  7700. }
  7701. }
  7702. // normals
  7703. if ( morphTargets[ i$4 ].normals !== undefined ) {
  7704. morphTarget.normals = [];
  7705. for ( var j$2 = 0, jl$2 = morphTargets[ i$4 ].normals.length; j$2 < jl$2; j$2 ++ ) {
  7706. morphTarget.normals.push( morphTargets[ i$4 ].normals[ j$2 ].clone() );
  7707. }
  7708. }
  7709. this.morphTargets.push( morphTarget );
  7710. }
  7711. // morph normals
  7712. var morphNormals = source.morphNormals;
  7713. for ( var i$5 = 0, il$5 = morphNormals.length; i$5 < il$5; i$5 ++ ) {
  7714. var morphNormal = {};
  7715. // vertex normals
  7716. if ( morphNormals[ i$5 ].vertexNormals !== undefined ) {
  7717. morphNormal.vertexNormals = [];
  7718. for ( var j$3 = 0, jl$3 = morphNormals[ i$5 ].vertexNormals.length; j$3 < jl$3; j$3 ++ ) {
  7719. var srcVertexNormal = morphNormals[ i$5 ].vertexNormals[ j$3 ];
  7720. var destVertexNormal = {};
  7721. destVertexNormal.a = srcVertexNormal.a.clone();
  7722. destVertexNormal.b = srcVertexNormal.b.clone();
  7723. destVertexNormal.c = srcVertexNormal.c.clone();
  7724. morphNormal.vertexNormals.push( destVertexNormal );
  7725. }
  7726. }
  7727. // face normals
  7728. if ( morphNormals[ i$5 ].faceNormals !== undefined ) {
  7729. morphNormal.faceNormals = [];
  7730. for ( var j$4 = 0, jl$4 = morphNormals[ i$5 ].faceNormals.length; j$4 < jl$4; j$4 ++ ) {
  7731. morphNormal.faceNormals.push( morphNormals[ i$5 ].faceNormals[ j$4 ].clone() );
  7732. }
  7733. }
  7734. this.morphNormals.push( morphNormal );
  7735. }
  7736. // skin weights
  7737. var skinWeights = source.skinWeights;
  7738. for ( var i$6 = 0, il$6 = skinWeights.length; i$6 < il$6; i$6 ++ ) {
  7739. this.skinWeights.push( skinWeights[ i$6 ].clone() );
  7740. }
  7741. // skin indices
  7742. var skinIndices = source.skinIndices;
  7743. for ( var i$7 = 0, il$7 = skinIndices.length; i$7 < il$7; i$7 ++ ) {
  7744. this.skinIndices.push( skinIndices[ i$7 ].clone() );
  7745. }
  7746. // line distances
  7747. var lineDistances = source.lineDistances;
  7748. for ( var i$8 = 0, il$8 = lineDistances.length; i$8 < il$8; i$8 ++ ) {
  7749. this.lineDistances.push( lineDistances[ i$8 ] );
  7750. }
  7751. // bounding box
  7752. var boundingBox = source.boundingBox;
  7753. if ( boundingBox !== null ) {
  7754. this.boundingBox = boundingBox.clone();
  7755. }
  7756. // bounding sphere
  7757. var boundingSphere = source.boundingSphere;
  7758. if ( boundingSphere !== null ) {
  7759. this.boundingSphere = boundingSphere.clone();
  7760. }
  7761. // update flags
  7762. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7763. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7764. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7765. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7766. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7767. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7768. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7769. return this;
  7770. },
  7771. dispose: function () {
  7772. this.dispatchEvent( { type: 'dispose' } );
  7773. }
  7774. } );
  7775. /**
  7776. * @author mrdoob / http://mrdoob.com/
  7777. * @author Mugen87 / https://github.com/Mugen87
  7778. */
  7779. // BoxGeometry
  7780. var BoxGeometry = /*@__PURE__*/(function (Geometry) {
  7781. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7782. Geometry.call(this);
  7783. this.type = 'BoxGeometry';
  7784. this.parameters = {
  7785. width: width,
  7786. height: height,
  7787. depth: depth,
  7788. widthSegments: widthSegments,
  7789. heightSegments: heightSegments,
  7790. depthSegments: depthSegments
  7791. };
  7792. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7793. this.mergeVertices();
  7794. }
  7795. if ( Geometry ) BoxGeometry.__proto__ = Geometry;
  7796. BoxGeometry.prototype = Object.create( Geometry && Geometry.prototype );
  7797. BoxGeometry.prototype.constructor = BoxGeometry;
  7798. return BoxGeometry;
  7799. }(Geometry));
  7800. // BoxBufferGeometry
  7801. var BoxBufferGeometry = /*@__PURE__*/(function (BufferGeometry) {
  7802. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7803. BufferGeometry.call(this);
  7804. this.type = 'BoxBufferGeometry';
  7805. this.parameters = {
  7806. width: width,
  7807. height: height,
  7808. depth: depth,
  7809. widthSegments: widthSegments,
  7810. heightSegments: heightSegments,
  7811. depthSegments: depthSegments
  7812. };
  7813. var scope = this;
  7814. width = width || 1;
  7815. height = height || 1;
  7816. depth = depth || 1;
  7817. // segments
  7818. widthSegments = Math.floor( widthSegments ) || 1;
  7819. heightSegments = Math.floor( heightSegments ) || 1;
  7820. depthSegments = Math.floor( depthSegments ) || 1;
  7821. // buffers
  7822. var indices = [];
  7823. var vertices = [];
  7824. var normals = [];
  7825. var uvs = [];
  7826. // helper variables
  7827. var numberOfVertices = 0;
  7828. var groupStart = 0;
  7829. // build each side of the box geometry
  7830. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7831. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7832. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7833. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7834. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7835. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7836. // build geometry
  7837. this.setIndex( indices );
  7838. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7839. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7840. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7841. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7842. var segmentWidth = width / gridX;
  7843. var segmentHeight = height / gridY;
  7844. var widthHalf = width / 2;
  7845. var heightHalf = height / 2;
  7846. var depthHalf = depth / 2;
  7847. var gridX1 = gridX + 1;
  7848. var gridY1 = gridY + 1;
  7849. var vertexCounter = 0;
  7850. var groupCount = 0;
  7851. var vector = new Vector3();
  7852. // generate vertices, normals and uvs
  7853. for ( var iy = 0; iy < gridY1; iy ++ ) {
  7854. var y = iy * segmentHeight - heightHalf;
  7855. for ( var ix = 0; ix < gridX1; ix ++ ) {
  7856. var x = ix * segmentWidth - widthHalf;
  7857. // set values to correct vector component
  7858. vector[ u ] = x * udir;
  7859. vector[ v ] = y * vdir;
  7860. vector[ w ] = depthHalf;
  7861. // now apply vector to vertex buffer
  7862. vertices.push( vector.x, vector.y, vector.z );
  7863. // set values to correct vector component
  7864. vector[ u ] = 0;
  7865. vector[ v ] = 0;
  7866. vector[ w ] = depth > 0 ? 1 : - 1;
  7867. // now apply vector to normal buffer
  7868. normals.push( vector.x, vector.y, vector.z );
  7869. // uvs
  7870. uvs.push( ix / gridX );
  7871. uvs.push( 1 - ( iy / gridY ) );
  7872. // counters
  7873. vertexCounter += 1;
  7874. }
  7875. }
  7876. // indices
  7877. // 1. you need three indices to draw a single face
  7878. // 2. a single segment consists of two faces
  7879. // 3. so we need to generate six (2*3) indices per segment
  7880. for ( var iy$1 = 0; iy$1 < gridY; iy$1 ++ ) {
  7881. for ( var ix$1 = 0; ix$1 < gridX; ix$1 ++ ) {
  7882. var a = numberOfVertices + ix$1 + gridX1 * iy$1;
  7883. var b = numberOfVertices + ix$1 + gridX1 * ( iy$1 + 1 );
  7884. var c = numberOfVertices + ( ix$1 + 1 ) + gridX1 * ( iy$1 + 1 );
  7885. var d = numberOfVertices + ( ix$1 + 1 ) + gridX1 * iy$1;
  7886. // faces
  7887. indices.push( a, b, d );
  7888. indices.push( b, c, d );
  7889. // increase counter
  7890. groupCount += 6;
  7891. }
  7892. }
  7893. // add a group to the geometry. this will ensure multi material support
  7894. scope.addGroup( groupStart, groupCount, materialIndex );
  7895. // calculate new start value for groups
  7896. groupStart += groupCount;
  7897. // update total number of vertices
  7898. numberOfVertices += vertexCounter;
  7899. }
  7900. }
  7901. if ( BufferGeometry ) BoxBufferGeometry.__proto__ = BufferGeometry;
  7902. BoxBufferGeometry.prototype = Object.create( BufferGeometry && BufferGeometry.prototype );
  7903. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7904. return BoxBufferGeometry;
  7905. }(BufferGeometry));
  7906. /**
  7907. * Uniform Utilities
  7908. */
  7909. function cloneUniforms( src ) {
  7910. var dst = {};
  7911. for ( var u in src ) {
  7912. dst[ u ] = {};
  7913. for ( var p in src[ u ] ) {
  7914. var property = src[ u ][ p ];
  7915. if ( property && ( property.isColor ||
  7916. property.isMatrix3 || property.isMatrix4 ||
  7917. property.isVector2 || property.isVector3 || property.isVector4 ||
  7918. property.isTexture ) ) {
  7919. dst[ u ][ p ] = property.clone();
  7920. } else if ( Array.isArray( property ) ) {
  7921. dst[ u ][ p ] = property.slice();
  7922. } else {
  7923. dst[ u ][ p ] = property;
  7924. }
  7925. }
  7926. }
  7927. return dst;
  7928. }
  7929. function mergeUniforms( uniforms ) {
  7930. var merged = {};
  7931. for ( var u = 0; u < uniforms.length; u ++ ) {
  7932. var tmp = cloneUniforms( uniforms[ u ] );
  7933. for ( var p in tmp ) {
  7934. merged[ p ] = tmp[ p ];
  7935. }
  7936. }
  7937. return merged;
  7938. }
  7939. // Legacy
  7940. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7941. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7942. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7943. /**
  7944. * @author alteredq / http://alteredqualia.com/
  7945. *
  7946. * parameters = {
  7947. * defines: { "label" : "value" },
  7948. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7949. *
  7950. * fragmentShader: <string>,
  7951. * vertexShader: <string>,
  7952. *
  7953. * wireframe: <boolean>,
  7954. * wireframeLinewidth: <float>,
  7955. *
  7956. * lights: <bool>,
  7957. *
  7958. * skinning: <bool>,
  7959. * morphTargets: <bool>,
  7960. * morphNormals: <bool>
  7961. * }
  7962. */
  7963. function ShaderMaterial( parameters ) {
  7964. Material.call( this );
  7965. this.type = 'ShaderMaterial';
  7966. this.defines = {};
  7967. this.uniforms = {};
  7968. this.vertexShader = default_vertex;
  7969. this.fragmentShader = default_fragment;
  7970. this.linewidth = 1;
  7971. this.wireframe = false;
  7972. this.wireframeLinewidth = 1;
  7973. this.fog = false; // set to use scene fog
  7974. this.lights = false; // set to use scene lights
  7975. this.clipping = false; // set to use user-defined clipping planes
  7976. this.skinning = false; // set to use skinning attribute streams
  7977. this.morphTargets = false; // set to use morph targets
  7978. this.morphNormals = false; // set to use morph normals
  7979. this.extensions = {
  7980. derivatives: false, // set to use derivatives
  7981. fragDepth: false, // set to use fragment depth values
  7982. drawBuffers: false, // set to use draw buffers
  7983. shaderTextureLOD: false // set to use shader texture LOD
  7984. };
  7985. // When rendered geometry doesn't include these attributes but the material does,
  7986. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7987. this.defaultAttributeValues = {
  7988. 'color': [ 1, 1, 1 ],
  7989. 'uv': [ 0, 0 ],
  7990. 'uv2': [ 0, 0 ]
  7991. };
  7992. this.index0AttributeName = undefined;
  7993. this.uniformsNeedUpdate = false;
  7994. if ( parameters !== undefined ) {
  7995. if ( parameters.attributes !== undefined ) {
  7996. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7997. }
  7998. this.setValues( parameters );
  7999. }
  8000. }
  8001. ShaderMaterial.prototype = Object.create( Material.prototype );
  8002. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8003. ShaderMaterial.prototype.isShaderMaterial = true;
  8004. ShaderMaterial.prototype.copy = function ( source ) {
  8005. Material.prototype.copy.call( this, source );
  8006. this.fragmentShader = source.fragmentShader;
  8007. this.vertexShader = source.vertexShader;
  8008. this.uniforms = cloneUniforms( source.uniforms );
  8009. this.defines = Object.assign( {}, source.defines );
  8010. this.wireframe = source.wireframe;
  8011. this.wireframeLinewidth = source.wireframeLinewidth;
  8012. this.lights = source.lights;
  8013. this.clipping = source.clipping;
  8014. this.skinning = source.skinning;
  8015. this.morphTargets = source.morphTargets;
  8016. this.morphNormals = source.morphNormals;
  8017. this.extensions = Object.assign( {}, source.extensions );
  8018. return this;
  8019. };
  8020. ShaderMaterial.prototype.toJSON = function ( meta ) {
  8021. var data = Material.prototype.toJSON.call( this, meta );
  8022. data.uniforms = {};
  8023. for ( var name in this.uniforms ) {
  8024. var uniform = this.uniforms[ name ];
  8025. var value = uniform.value;
  8026. if ( value && value.isTexture ) {
  8027. data.uniforms[ name ] = {
  8028. type: 't',
  8029. value: value.toJSON( meta ).uuid
  8030. };
  8031. } else if ( value && value.isColor ) {
  8032. data.uniforms[ name ] = {
  8033. type: 'c',
  8034. value: value.getHex()
  8035. };
  8036. } else if ( value && value.isVector2 ) {
  8037. data.uniforms[ name ] = {
  8038. type: 'v2',
  8039. value: value.toArray()
  8040. };
  8041. } else if ( value && value.isVector3 ) {
  8042. data.uniforms[ name ] = {
  8043. type: 'v3',
  8044. value: value.toArray()
  8045. };
  8046. } else if ( value && value.isVector4 ) {
  8047. data.uniforms[ name ] = {
  8048. type: 'v4',
  8049. value: value.toArray()
  8050. };
  8051. } else if ( value && value.isMatrix3 ) {
  8052. data.uniforms[ name ] = {
  8053. type: 'm3',
  8054. value: value.toArray()
  8055. };
  8056. } else if ( value && value.isMatrix4 ) {
  8057. data.uniforms[ name ] = {
  8058. type: 'm4',
  8059. value: value.toArray()
  8060. };
  8061. } else {
  8062. data.uniforms[ name ] = {
  8063. value: value
  8064. };
  8065. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8066. }
  8067. }
  8068. if ( Object.keys( this.defines ).length > 0 ) { data.defines = this.defines; }
  8069. data.vertexShader = this.vertexShader;
  8070. data.fragmentShader = this.fragmentShader;
  8071. var extensions = {};
  8072. for ( var key in this.extensions ) {
  8073. if ( this.extensions[ key ] === true ) { extensions[ key ] = true; }
  8074. }
  8075. if ( Object.keys( extensions ).length > 0 ) { data.extensions = extensions; }
  8076. return data;
  8077. };
  8078. /**
  8079. * @author mrdoob / http://mrdoob.com/
  8080. * @author mikael emtinger / http://gomo.se/
  8081. * @author WestLangley / http://github.com/WestLangley
  8082. */
  8083. function Camera() {
  8084. Object3D.call( this );
  8085. this.type = 'Camera';
  8086. this.matrixWorldInverse = new Matrix4();
  8087. this.projectionMatrix = new Matrix4();
  8088. this.projectionMatrixInverse = new Matrix4();
  8089. }
  8090. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8091. constructor: Camera,
  8092. isCamera: true,
  8093. copy: function ( source, recursive ) {
  8094. Object3D.prototype.copy.call( this, source, recursive );
  8095. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8096. this.projectionMatrix.copy( source.projectionMatrix );
  8097. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  8098. return this;
  8099. },
  8100. getWorldDirection: function ( target ) {
  8101. if ( target === undefined ) {
  8102. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  8103. target = new Vector3();
  8104. }
  8105. this.updateMatrixWorld( true );
  8106. var e = this.matrixWorld.elements;
  8107. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  8108. },
  8109. updateMatrixWorld: function ( force ) {
  8110. Object3D.prototype.updateMatrixWorld.call( this, force );
  8111. this.matrixWorldInverse.getInverse( this.matrixWorld );
  8112. },
  8113. updateWorldMatrix: function ( updateParents, updateChildren ) {
  8114. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  8115. this.matrixWorldInverse.getInverse( this.matrixWorld );
  8116. },
  8117. clone: function () {
  8118. return new this.constructor().copy( this );
  8119. }
  8120. } );
  8121. /**
  8122. * @author mrdoob / http://mrdoob.com/
  8123. * @author greggman / http://games.greggman.com/
  8124. * @author zz85 / http://www.lab4games.net/zz85/blog
  8125. * @author tschw
  8126. */
  8127. function PerspectiveCamera( fov, aspect, near, far ) {
  8128. Camera.call( this );
  8129. this.type = 'PerspectiveCamera';
  8130. this.fov = fov !== undefined ? fov : 50;
  8131. this.zoom = 1;
  8132. this.near = near !== undefined ? near : 0.1;
  8133. this.far = far !== undefined ? far : 2000;
  8134. this.focus = 10;
  8135. this.aspect = aspect !== undefined ? aspect : 1;
  8136. this.view = null;
  8137. this.filmGauge = 35; // width of the film (default in millimeters)
  8138. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8139. this.updateProjectionMatrix();
  8140. }
  8141. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  8142. constructor: PerspectiveCamera,
  8143. isPerspectiveCamera: true,
  8144. copy: function ( source, recursive ) {
  8145. Camera.prototype.copy.call( this, source, recursive );
  8146. this.fov = source.fov;
  8147. this.zoom = source.zoom;
  8148. this.near = source.near;
  8149. this.far = source.far;
  8150. this.focus = source.focus;
  8151. this.aspect = source.aspect;
  8152. this.view = source.view === null ? null : Object.assign( {}, source.view );
  8153. this.filmGauge = source.filmGauge;
  8154. this.filmOffset = source.filmOffset;
  8155. return this;
  8156. },
  8157. /**
  8158. * Sets the FOV by focal length in respect to the current .filmGauge.
  8159. *
  8160. * The default film gauge is 35, so that the focal length can be specified for
  8161. * a 35mm (full frame) camera.
  8162. *
  8163. * Values for focal length and film gauge must have the same unit.
  8164. */
  8165. setFocalLength: function ( focalLength ) {
  8166. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  8167. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8168. this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
  8169. this.updateProjectionMatrix();
  8170. },
  8171. /**
  8172. * Calculates the focal length from the current .fov and .filmGauge.
  8173. */
  8174. getFocalLength: function () {
  8175. var vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
  8176. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8177. },
  8178. getEffectiveFOV: function () {
  8179. return MathUtils.RAD2DEG * 2 * Math.atan(
  8180. Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  8181. },
  8182. getFilmWidth: function () {
  8183. // film not completely covered in portrait format (aspect < 1)
  8184. return this.filmGauge * Math.min( this.aspect, 1 );
  8185. },
  8186. getFilmHeight: function () {
  8187. // film not completely covered in landscape format (aspect > 1)
  8188. return this.filmGauge / Math.max( this.aspect, 1 );
  8189. },
  8190. /**
  8191. * Sets an offset in a larger frustum. This is useful for multi-window or
  8192. * multi-monitor/multi-machine setups.
  8193. *
  8194. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8195. * the monitors are in grid like this
  8196. *
  8197. * +---+---+---+
  8198. * | A | B | C |
  8199. * +---+---+---+
  8200. * | D | E | F |
  8201. * +---+---+---+
  8202. *
  8203. * then for each monitor you would call it like this
  8204. *
  8205. * const w = 1920;
  8206. * const h = 1080;
  8207. * const fullWidth = w * 3;
  8208. * const fullHeight = h * 2;
  8209. *
  8210. * --A--
  8211. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8212. * --B--
  8213. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8214. * --C--
  8215. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8216. * --D--
  8217. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8218. * --E--
  8219. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8220. * --F--
  8221. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8222. *
  8223. * Note there is no reason monitors have to be the same size or in a grid.
  8224. */
  8225. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8226. this.aspect = fullWidth / fullHeight;
  8227. if ( this.view === null ) {
  8228. this.view = {
  8229. enabled: true,
  8230. fullWidth: 1,
  8231. fullHeight: 1,
  8232. offsetX: 0,
  8233. offsetY: 0,
  8234. width: 1,
  8235. height: 1
  8236. };
  8237. }
  8238. this.view.enabled = true;
  8239. this.view.fullWidth = fullWidth;
  8240. this.view.fullHeight = fullHeight;
  8241. this.view.offsetX = x;
  8242. this.view.offsetY = y;
  8243. this.view.width = width;
  8244. this.view.height = height;
  8245. this.updateProjectionMatrix();
  8246. },
  8247. clearViewOffset: function () {
  8248. if ( this.view !== null ) {
  8249. this.view.enabled = false;
  8250. }
  8251. this.updateProjectionMatrix();
  8252. },
  8253. updateProjectionMatrix: function () {
  8254. var near = this.near,
  8255. top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8256. height = 2 * top,
  8257. width = this.aspect * height,
  8258. left = - 0.5 * width,
  8259. view = this.view;
  8260. if ( this.view !== null && this.view.enabled ) {
  8261. var fullWidth = view.fullWidth,
  8262. fullHeight = view.fullHeight;
  8263. left += view.offsetX * width / fullWidth;
  8264. top -= view.offsetY * height / fullHeight;
  8265. width *= view.width / fullWidth;
  8266. height *= view.height / fullHeight;
  8267. }
  8268. var skew = this.filmOffset;
  8269. if ( skew !== 0 ) { left += near * skew / this.getFilmWidth(); }
  8270. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8271. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8272. },
  8273. toJSON: function ( meta ) {
  8274. var data = Object3D.prototype.toJSON.call( this, meta );
  8275. data.object.fov = this.fov;
  8276. data.object.zoom = this.zoom;
  8277. data.object.near = this.near;
  8278. data.object.far = this.far;
  8279. data.object.focus = this.focus;
  8280. data.object.aspect = this.aspect;
  8281. if ( this.view !== null ) { data.object.view = Object.assign( {}, this.view ); }
  8282. data.object.filmGauge = this.filmGauge;
  8283. data.object.filmOffset = this.filmOffset;
  8284. return data;
  8285. }
  8286. } );
  8287. /**
  8288. * Camera for rendering cube maps
  8289. * - renders scene into axis-aligned cube
  8290. *
  8291. * @author alteredq / http://alteredqualia.com/
  8292. */
  8293. var fov = 90, aspect = 1;
  8294. function CubeCamera( near, far, renderTarget ) {
  8295. Object3D.call( this );
  8296. this.type = 'CubeCamera';
  8297. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  8298. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  8299. return;
  8300. }
  8301. this.renderTarget = renderTarget;
  8302. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8303. cameraPX.layers = this.layers;
  8304. cameraPX.up.set( 0, - 1, 0 );
  8305. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8306. this.add( cameraPX );
  8307. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8308. cameraNX.layers = this.layers;
  8309. cameraNX.up.set( 0, - 1, 0 );
  8310. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8311. this.add( cameraNX );
  8312. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8313. cameraPY.layers = this.layers;
  8314. cameraPY.up.set( 0, 0, 1 );
  8315. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8316. this.add( cameraPY );
  8317. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8318. cameraNY.layers = this.layers;
  8319. cameraNY.up.set( 0, 0, - 1 );
  8320. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8321. this.add( cameraNY );
  8322. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8323. cameraPZ.layers = this.layers;
  8324. cameraPZ.up.set( 0, - 1, 0 );
  8325. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8326. this.add( cameraPZ );
  8327. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8328. cameraNZ.layers = this.layers;
  8329. cameraNZ.up.set( 0, - 1, 0 );
  8330. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8331. this.add( cameraNZ );
  8332. this.update = function ( renderer, scene ) {
  8333. if ( this.parent === null ) { this.updateMatrixWorld(); }
  8334. var currentXrEnabled = renderer.xr.enabled;
  8335. var currentRenderTarget = renderer.getRenderTarget();
  8336. renderer.xr.enabled = false;
  8337. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8338. renderTarget.texture.generateMipmaps = false;
  8339. renderer.setRenderTarget( renderTarget, 0 );
  8340. renderer.render( scene, cameraPX );
  8341. renderer.setRenderTarget( renderTarget, 1 );
  8342. renderer.render( scene, cameraNX );
  8343. renderer.setRenderTarget( renderTarget, 2 );
  8344. renderer.render( scene, cameraPY );
  8345. renderer.setRenderTarget( renderTarget, 3 );
  8346. renderer.render( scene, cameraNY );
  8347. renderer.setRenderTarget( renderTarget, 4 );
  8348. renderer.render( scene, cameraPZ );
  8349. renderTarget.texture.generateMipmaps = generateMipmaps;
  8350. renderer.setRenderTarget( renderTarget, 5 );
  8351. renderer.render( scene, cameraNZ );
  8352. renderer.setRenderTarget( currentRenderTarget );
  8353. renderer.xr.enabled = currentXrEnabled;
  8354. };
  8355. this.clear = function ( renderer, color, depth, stencil ) {
  8356. var currentRenderTarget = renderer.getRenderTarget();
  8357. for ( var i = 0; i < 6; i ++ ) {
  8358. renderer.setRenderTarget( renderTarget, i );
  8359. renderer.clear( color, depth, stencil );
  8360. }
  8361. renderer.setRenderTarget( currentRenderTarget );
  8362. };
  8363. }
  8364. CubeCamera.prototype = Object.create( Object3D.prototype );
  8365. CubeCamera.prototype.constructor = CubeCamera;
  8366. /**
  8367. * @author alteredq / http://alteredqualia.com
  8368. * @author WestLangley / http://github.com/WestLangley
  8369. */
  8370. function WebGLCubeRenderTarget( size, options, dummy ) {
  8371. if ( Number.isInteger( options ) ) {
  8372. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  8373. options = dummy;
  8374. }
  8375. WebGLRenderTarget.call( this, size, size, options );
  8376. }
  8377. WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
  8378. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  8379. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  8380. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8381. this.texture.type = texture.type;
  8382. this.texture.format = texture.format;
  8383. this.texture.encoding = texture.encoding;
  8384. var scene = new Scene();
  8385. var shader = {
  8386. uniforms: {
  8387. tEquirect: { value: null },
  8388. },
  8389. vertexShader: [
  8390. "varying vec3 vWorldDirection;",
  8391. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8392. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8393. "}",
  8394. "void main() {",
  8395. " vWorldDirection = transformDirection( position, modelMatrix );",
  8396. " #include <begin_vertex>",
  8397. " #include <project_vertex>",
  8398. "}"
  8399. ].join( '\n' ),
  8400. fragmentShader: [
  8401. "uniform sampler2D tEquirect;",
  8402. "varying vec3 vWorldDirection;",
  8403. "#include <common>",
  8404. "void main() {",
  8405. " vec3 direction = normalize( vWorldDirection );",
  8406. " vec2 sampleUV = equirectUv( direction );",
  8407. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8408. "}"
  8409. ].join( '\n' ),
  8410. };
  8411. var material = new ShaderMaterial( {
  8412. name: 'CubemapFromEquirect',
  8413. uniforms: cloneUniforms( shader.uniforms ),
  8414. vertexShader: shader.vertexShader,
  8415. fragmentShader: shader.fragmentShader,
  8416. side: BackSide,
  8417. blending: NoBlending
  8418. } );
  8419. material.uniforms.tEquirect.value = texture;
  8420. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8421. scene.add( mesh );
  8422. var camera = new CubeCamera( 1, 10, this );
  8423. camera.update( renderer, scene );
  8424. mesh.geometry.dispose();
  8425. mesh.material.dispose();
  8426. return this;
  8427. };
  8428. /**
  8429. * @author alteredq / http://alteredqualia.com/
  8430. */
  8431. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8432. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8433. this.image = { data: data || null, width: width || 1, height: height || 1 };
  8434. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8435. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8436. this.generateMipmaps = false;
  8437. this.flipY = false;
  8438. this.unpackAlignment = 1;
  8439. this.needsUpdate = true;
  8440. }
  8441. DataTexture.prototype = Object.create( Texture.prototype );
  8442. DataTexture.prototype.constructor = DataTexture;
  8443. DataTexture.prototype.isDataTexture = true;
  8444. /**
  8445. * @author mrdoob / http://mrdoob.com/
  8446. * @author alteredq / http://alteredqualia.com/
  8447. * @author bhouston / http://clara.io
  8448. */
  8449. var _sphere$1 = new Sphere();
  8450. var _vector$5 = new Vector3();
  8451. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8452. this.planes = [
  8453. ( p0 !== undefined ) ? p0 : new Plane(),
  8454. ( p1 !== undefined ) ? p1 : new Plane(),
  8455. ( p2 !== undefined ) ? p2 : new Plane(),
  8456. ( p3 !== undefined ) ? p3 : new Plane(),
  8457. ( p4 !== undefined ) ? p4 : new Plane(),
  8458. ( p5 !== undefined ) ? p5 : new Plane()
  8459. ];
  8460. }
  8461. Object.assign( Frustum.prototype, {
  8462. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8463. var planes = this.planes;
  8464. planes[ 0 ].copy( p0 );
  8465. planes[ 1 ].copy( p1 );
  8466. planes[ 2 ].copy( p2 );
  8467. planes[ 3 ].copy( p3 );
  8468. planes[ 4 ].copy( p4 );
  8469. planes[ 5 ].copy( p5 );
  8470. return this;
  8471. },
  8472. clone: function () {
  8473. return new this.constructor().copy( this );
  8474. },
  8475. copy: function ( frustum ) {
  8476. var planes = this.planes;
  8477. for ( var i = 0; i < 6; i ++ ) {
  8478. planes[ i ].copy( frustum.planes[ i ] );
  8479. }
  8480. return this;
  8481. },
  8482. setFromProjectionMatrix: function ( m ) {
  8483. var planes = this.planes;
  8484. var me = m.elements;
  8485. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8486. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8487. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8488. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8489. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8490. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8491. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8492. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8493. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8494. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8495. return this;
  8496. },
  8497. intersectsObject: function ( object ) {
  8498. var geometry = object.geometry;
  8499. if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); }
  8500. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  8501. return this.intersectsSphere( _sphere$1 );
  8502. },
  8503. intersectsSprite: function ( sprite ) {
  8504. _sphere$1.center.set( 0, 0, 0 );
  8505. _sphere$1.radius = 0.7071067811865476;
  8506. _sphere$1.applyMatrix4( sprite.matrixWorld );
  8507. return this.intersectsSphere( _sphere$1 );
  8508. },
  8509. intersectsSphere: function ( sphere ) {
  8510. var planes = this.planes;
  8511. var center = sphere.center;
  8512. var negRadius = - sphere.radius;
  8513. for ( var i = 0; i < 6; i ++ ) {
  8514. var distance = planes[ i ].distanceToPoint( center );
  8515. if ( distance < negRadius ) {
  8516. return false;
  8517. }
  8518. }
  8519. return true;
  8520. },
  8521. intersectsBox: function ( box ) {
  8522. var planes = this.planes;
  8523. for ( var i = 0; i < 6; i ++ ) {
  8524. var plane = planes[ i ];
  8525. // corner at max distance
  8526. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8527. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8528. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8529. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  8530. return false;
  8531. }
  8532. }
  8533. return true;
  8534. },
  8535. containsPoint: function ( point ) {
  8536. var planes = this.planes;
  8537. for ( var i = 0; i < 6; i ++ ) {
  8538. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8539. return false;
  8540. }
  8541. }
  8542. return true;
  8543. }
  8544. } );
  8545. /**
  8546. * Uniforms library for shared webgl shaders
  8547. */
  8548. var UniformsLib = {
  8549. common: {
  8550. diffuse: { value: new Color( 0xeeeeee ) },
  8551. opacity: { value: 1.0 },
  8552. map: { value: null },
  8553. uvTransform: { value: new Matrix3() },
  8554. uv2Transform: { value: new Matrix3() },
  8555. alphaMap: { value: null },
  8556. },
  8557. specularmap: {
  8558. specularMap: { value: null },
  8559. },
  8560. envmap: {
  8561. envMap: { value: null },
  8562. flipEnvMap: { value: - 1 },
  8563. reflectivity: { value: 1.0 },
  8564. refractionRatio: { value: 0.98 },
  8565. maxMipLevel: { value: 0 }
  8566. },
  8567. aomap: {
  8568. aoMap: { value: null },
  8569. aoMapIntensity: { value: 1 }
  8570. },
  8571. lightmap: {
  8572. lightMap: { value: null },
  8573. lightMapIntensity: { value: 1 }
  8574. },
  8575. emissivemap: {
  8576. emissiveMap: { value: null }
  8577. },
  8578. bumpmap: {
  8579. bumpMap: { value: null },
  8580. bumpScale: { value: 1 }
  8581. },
  8582. normalmap: {
  8583. normalMap: { value: null },
  8584. normalScale: { value: new Vector2( 1, 1 ) }
  8585. },
  8586. displacementmap: {
  8587. displacementMap: { value: null },
  8588. displacementScale: { value: 1 },
  8589. displacementBias: { value: 0 }
  8590. },
  8591. roughnessmap: {
  8592. roughnessMap: { value: null }
  8593. },
  8594. metalnessmap: {
  8595. metalnessMap: { value: null }
  8596. },
  8597. gradientmap: {
  8598. gradientMap: { value: null }
  8599. },
  8600. fog: {
  8601. fogDensity: { value: 0.00025 },
  8602. fogNear: { value: 1 },
  8603. fogFar: { value: 2000 },
  8604. fogColor: { value: new Color( 0xffffff ) }
  8605. },
  8606. lights: {
  8607. ambientLightColor: { value: [] },
  8608. lightProbe: { value: [] },
  8609. directionalLights: { value: [], properties: {
  8610. direction: {},
  8611. color: {}
  8612. } },
  8613. directionalLightShadows: { value: [], properties: {
  8614. shadowBias: {},
  8615. shadowNormalBias: {},
  8616. shadowRadius: {},
  8617. shadowMapSize: {}
  8618. } },
  8619. directionalShadowMap: { value: [] },
  8620. directionalShadowMatrix: { value: [] },
  8621. spotLights: { value: [], properties: {
  8622. color: {},
  8623. position: {},
  8624. direction: {},
  8625. distance: {},
  8626. coneCos: {},
  8627. penumbraCos: {},
  8628. decay: {}
  8629. } },
  8630. spotLightShadows: { value: [], properties: {
  8631. shadowBias: {},
  8632. shadowNormalBias: {},
  8633. shadowRadius: {},
  8634. shadowMapSize: {}
  8635. } },
  8636. spotShadowMap: { value: [] },
  8637. spotShadowMatrix: { value: [] },
  8638. pointLights: { value: [], properties: {
  8639. color: {},
  8640. position: {},
  8641. decay: {},
  8642. distance: {}
  8643. } },
  8644. pointLightShadows: { value: [], properties: {
  8645. shadowBias: {},
  8646. shadowNormalBias: {},
  8647. shadowRadius: {},
  8648. shadowMapSize: {},
  8649. shadowCameraNear: {},
  8650. shadowCameraFar: {}
  8651. } },
  8652. pointShadowMap: { value: [] },
  8653. pointShadowMatrix: { value: [] },
  8654. hemisphereLights: { value: [], properties: {
  8655. direction: {},
  8656. skyColor: {},
  8657. groundColor: {}
  8658. } },
  8659. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8660. rectAreaLights: { value: [], properties: {
  8661. color: {},
  8662. position: {},
  8663. width: {},
  8664. height: {}
  8665. } }
  8666. },
  8667. points: {
  8668. diffuse: { value: new Color( 0xeeeeee ) },
  8669. opacity: { value: 1.0 },
  8670. size: { value: 1.0 },
  8671. scale: { value: 1.0 },
  8672. map: { value: null },
  8673. alphaMap: { value: null },
  8674. uvTransform: { value: new Matrix3() }
  8675. },
  8676. sprite: {
  8677. diffuse: { value: new Color( 0xeeeeee ) },
  8678. opacity: { value: 1.0 },
  8679. center: { value: new Vector2( 0.5, 0.5 ) },
  8680. rotation: { value: 0.0 },
  8681. map: { value: null },
  8682. alphaMap: { value: null },
  8683. uvTransform: { value: new Matrix3() }
  8684. }
  8685. };
  8686. /**
  8687. * @author mrdoob / http://mrdoob.com/
  8688. */
  8689. function WebGLAnimation() {
  8690. var context = null;
  8691. var isAnimating = false;
  8692. var animationLoop = null;
  8693. var requestId = null;
  8694. function onAnimationFrame( time, frame ) {
  8695. animationLoop( time, frame );
  8696. requestId = context.requestAnimationFrame( onAnimationFrame );
  8697. }
  8698. return {
  8699. start: function () {
  8700. if ( isAnimating === true ) { return; }
  8701. if ( animationLoop === null ) { return; }
  8702. requestId = context.requestAnimationFrame( onAnimationFrame );
  8703. isAnimating = true;
  8704. },
  8705. stop: function () {
  8706. context.cancelAnimationFrame( requestId );
  8707. isAnimating = false;
  8708. },
  8709. setAnimationLoop: function ( callback ) {
  8710. animationLoop = callback;
  8711. },
  8712. setContext: function ( value ) {
  8713. context = value;
  8714. }
  8715. };
  8716. }
  8717. /**
  8718. * @author mrdoob / http://mrdoob.com/
  8719. */
  8720. function WebGLAttributes( gl, capabilities ) {
  8721. var isWebGL2 = capabilities.isWebGL2;
  8722. var buffers = new WeakMap();
  8723. function createBuffer( attribute, bufferType ) {
  8724. var array = attribute.array;
  8725. var usage = attribute.usage;
  8726. var buffer = gl.createBuffer();
  8727. gl.bindBuffer( bufferType, buffer );
  8728. gl.bufferData( bufferType, array, usage );
  8729. attribute.onUploadCallback();
  8730. var type = 5126;
  8731. if ( array instanceof Float32Array ) {
  8732. type = 5126;
  8733. } else if ( array instanceof Float64Array ) {
  8734. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  8735. } else if ( array instanceof Uint16Array ) {
  8736. type = 5123;
  8737. } else if ( array instanceof Int16Array ) {
  8738. type = 5122;
  8739. } else if ( array instanceof Uint32Array ) {
  8740. type = 5125;
  8741. } else if ( array instanceof Int32Array ) {
  8742. type = 5124;
  8743. } else if ( array instanceof Int8Array ) {
  8744. type = 5120;
  8745. } else if ( array instanceof Uint8Array ) {
  8746. type = 5121;
  8747. }
  8748. return {
  8749. buffer: buffer,
  8750. type: type,
  8751. bytesPerElement: array.BYTES_PER_ELEMENT,
  8752. version: attribute.version
  8753. };
  8754. }
  8755. function updateBuffer( buffer, attribute, bufferType ) {
  8756. var array = attribute.array;
  8757. var updateRange = attribute.updateRange;
  8758. gl.bindBuffer( bufferType, buffer );
  8759. if ( updateRange.count === - 1 ) {
  8760. // Not using update ranges
  8761. gl.bufferSubData( bufferType, 0, array );
  8762. } else {
  8763. if ( isWebGL2 ) {
  8764. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  8765. array, updateRange.offset, updateRange.count );
  8766. } else {
  8767. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  8768. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  8769. }
  8770. updateRange.count = - 1; // reset range
  8771. }
  8772. }
  8773. //
  8774. function get( attribute ) {
  8775. if ( attribute.isInterleavedBufferAttribute ) { attribute = attribute.data; }
  8776. return buffers.get( attribute );
  8777. }
  8778. function remove( attribute ) {
  8779. if ( attribute.isInterleavedBufferAttribute ) { attribute = attribute.data; }
  8780. var data = buffers.get( attribute );
  8781. if ( data ) {
  8782. gl.deleteBuffer( data.buffer );
  8783. buffers.delete( attribute );
  8784. }
  8785. }
  8786. function update( attribute, bufferType ) {
  8787. if ( attribute.isInterleavedBufferAttribute ) { attribute = attribute.data; }
  8788. var data = buffers.get( attribute );
  8789. if ( data === undefined ) {
  8790. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  8791. } else if ( data.version < attribute.version ) {
  8792. updateBuffer( data.buffer, attribute, bufferType );
  8793. data.version = attribute.version;
  8794. }
  8795. }
  8796. return {
  8797. get: get,
  8798. remove: remove,
  8799. update: update
  8800. };
  8801. }
  8802. /**
  8803. * @author mrdoob / http://mrdoob.com/
  8804. * @author Mugen87 / https://github.com/Mugen87
  8805. */
  8806. // PlaneGeometry
  8807. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  8808. Geometry.call( this );
  8809. this.type = 'PlaneGeometry';
  8810. this.parameters = {
  8811. width: width,
  8812. height: height,
  8813. widthSegments: widthSegments,
  8814. heightSegments: heightSegments
  8815. };
  8816. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  8817. this.mergeVertices();
  8818. }
  8819. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  8820. PlaneGeometry.prototype.constructor = PlaneGeometry;
  8821. // PlaneBufferGeometry
  8822. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  8823. BufferGeometry.call( this );
  8824. this.type = 'PlaneBufferGeometry';
  8825. this.parameters = {
  8826. width: width,
  8827. height: height,
  8828. widthSegments: widthSegments,
  8829. heightSegments: heightSegments
  8830. };
  8831. width = width || 1;
  8832. height = height || 1;
  8833. var width_half = width / 2;
  8834. var height_half = height / 2;
  8835. var gridX = Math.floor( widthSegments ) || 1;
  8836. var gridY = Math.floor( heightSegments ) || 1;
  8837. var gridX1 = gridX + 1;
  8838. var gridY1 = gridY + 1;
  8839. var segment_width = width / gridX;
  8840. var segment_height = height / gridY;
  8841. // buffers
  8842. var indices = [];
  8843. var vertices = [];
  8844. var normals = [];
  8845. var uvs = [];
  8846. // generate vertices, normals and uvs
  8847. for ( var iy = 0; iy < gridY1; iy ++ ) {
  8848. var y = iy * segment_height - height_half;
  8849. for ( var ix = 0; ix < gridX1; ix ++ ) {
  8850. var x = ix * segment_width - width_half;
  8851. vertices.push( x, - y, 0 );
  8852. normals.push( 0, 0, 1 );
  8853. uvs.push( ix / gridX );
  8854. uvs.push( 1 - ( iy / gridY ) );
  8855. }
  8856. }
  8857. // indices
  8858. for ( var iy$1 = 0; iy$1 < gridY; iy$1 ++ ) {
  8859. for ( var ix$1 = 0; ix$1 < gridX; ix$1 ++ ) {
  8860. var a = ix$1 + gridX1 * iy$1;
  8861. var b = ix$1 + gridX1 * ( iy$1 + 1 );
  8862. var c = ( ix$1 + 1 ) + gridX1 * ( iy$1 + 1 );
  8863. var d = ( ix$1 + 1 ) + gridX1 * iy$1;
  8864. // faces
  8865. indices.push( a, b, d );
  8866. indices.push( b, c, d );
  8867. }
  8868. }
  8869. // build geometry
  8870. this.setIndex( indices );
  8871. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  8872. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  8873. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  8874. }
  8875. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  8876. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  8877. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8878. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8879. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8880. 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";
  8881. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8882. var begin_vertex = "vec3 transformed = vec3( position );";
  8883. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8884. 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";
  8885. 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";
  8886. 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";
  8887. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8888. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8889. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8890. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8891. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8892. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8893. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8894. 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 return 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}";
  8895. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_maxMipLevel 8.0\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_maxTileSize 256.0\n#define cubeUV_minTileSize 16.0\nfloat getFace(vec3 direction) {\n vec3 absDirection = abs(direction);\n float face = -1.0;\n if (absDirection.x > absDirection.z) {\n if (absDirection.x > absDirection.y)\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if (absDirection.z > absDirection.y)\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n}\nvec2 getUV(vec3 direction, float face) {\n vec2 uv;\n if (face == 0.0) {\n uv = vec2(direction.z, direction.y) / abs(direction.x); } else if (face == 1.0) {\n uv = vec2(-direction.x, -direction.z) / abs(direction.y); } else if (face == 2.0) {\n uv = vec2(-direction.x, direction.y) / abs(direction.z); } else if (face == 3.0) {\n uv = vec2(-direction.z, direction.y) / abs(direction.x); } else if (face == 4.0) {\n uv = vec2(-direction.x, direction.z) / abs(direction.y); } else {\n uv = vec2(direction.x, direction.y) / abs(direction.z); }\n return 0.5 * (uv + 1.0);\n}\nvec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {\n float face = getFace(direction);\n float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);\n mipInt = max(mipInt, cubeUV_minMipLevel);\n float faceSize = exp2(mipInt);\n float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);\n vec2 uv = getUV(direction, face) * (faceSize - 1.0);\n vec2 f = fract(uv);\n uv += 0.5 - f;\n if (face > 2.0) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n if(mipInt < cubeUV_maxMipLevel){\n uv.y += 2.0 * cubeUV_maxTileSize;\n }\n uv.y += filterInt * 2.0 * cubeUV_minTileSize;\n uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);\n uv *= texelSize;\n vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x += texelSize;\n vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.y += texelSize;\n vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x -= texelSize;\n vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n vec3 tm = mix(tl, tr, f.x);\n vec3 bm = mix(bl, br, f.x);\n return mix(tm, bm, f.y);\n}\n#define r0 1.0\n#define v0 0.339\n#define m0 -2.0\n#define r1 0.8\n#define v1 0.276\n#define m1 -1.0\n#define r4 0.4\n#define v4 0.046\n#define m4 2.0\n#define r5 0.305\n#define v5 0.016\n#define m5 3.0\n#define r6 0.21\n#define v6 0.0038\n#define m6 4.0\nfloat roughnessToMip(float roughness) {\n float mip = 0.0;\n if (roughness >= r1) {\n mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;\n } else if (roughness >= r4) {\n mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;\n } else if (roughness >= r5) {\n mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;\n } else if (roughness >= r6) {\n mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;\n } else {\n mip = -2.0 * log2(1.16 * roughness); }\n return mip;\n}\nvec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {\n float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);\n float mipF = fract(mip);\n float mipInt = floor(mip);\n vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);\n if (mipF == 0.0) {\n return vec4(color0, 1.0);\n } else {\n vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);\n return vec4(mix(color0, color1, mipF), 1.0);\n }\n}\n#endif";
  8896. 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";
  8897. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8898. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8899. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8900. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8901. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8902. 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}";
  8903. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\t\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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\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";
  8904. 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";
  8905. 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";
  8906. 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";
  8907. 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";
  8908. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8909. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8910. 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";
  8911. 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";
  8912. 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}";
  8913. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8914. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8915. 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";
  8916. 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";
  8917. 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 vec3 reflectVec = reflect( -viewDir, normal );\n\t\t reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t vec3 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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  8918. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8919. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3\tdiffuseColor;\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)";
  8920. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8921. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\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)";
  8922. 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";
  8923. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\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}";
  8924. 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";
  8925. 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";
  8926. 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";
  8927. 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";
  8928. 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";
  8929. 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";
  8930. 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";
  8931. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8932. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8933. 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";
  8934. 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";
  8935. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8936. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8937. 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";
  8938. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  8939. 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\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  8940. 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;";
  8941. 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";
  8942. 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";
  8943. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8944. 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";
  8945. 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";
  8946. 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}";
  8947. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8948. 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;";
  8949. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8950. 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";
  8951. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8952. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8953. 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";
  8954. 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";
  8955. 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";
  8956. 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}";
  8957. 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";
  8958. 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";
  8959. 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";
  8960. 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";
  8961. 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";
  8962. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8963. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8964. 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; }";
  8965. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8966. 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";
  8967. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8968. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8969. 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";
  8970. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8971. 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";
  8972. 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}";
  8973. 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}";
  8974. 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}";
  8975. 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}";
  8976. 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}";
  8977. 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}";
  8978. 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}";
  8979. 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}";
  8980. 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}";
  8981. 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}";
  8982. 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}";
  8983. 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}";
  8984. 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}";
  8985. 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}";
  8986. 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}";
  8987. 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}";
  8988. 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}";
  8989. 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}";
  8990. 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}";
  8991. 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}";
  8992. 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}";
  8993. 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}";
  8994. var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSPARENCY\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSPARENCY\n\tuniform float transparency;\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 <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#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 <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 TRANSPARENCY\n\t\tdiffuseColor.a *= saturate( 1. - transparency + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) );\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}";
  8995. 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}";
  8996. 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}";
  8997. 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}";
  8998. 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}";
  8999. 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}";
  9000. 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}";
  9001. 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}";
  9002. 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}";
  9003. 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}";
  9004. var ShaderChunk = {
  9005. alphamap_fragment: alphamap_fragment,
  9006. alphamap_pars_fragment: alphamap_pars_fragment,
  9007. alphatest_fragment: alphatest_fragment,
  9008. aomap_fragment: aomap_fragment,
  9009. aomap_pars_fragment: aomap_pars_fragment,
  9010. begin_vertex: begin_vertex,
  9011. beginnormal_vertex: beginnormal_vertex,
  9012. bsdfs: bsdfs,
  9013. bumpmap_pars_fragment: bumpmap_pars_fragment,
  9014. clipping_planes_fragment: clipping_planes_fragment,
  9015. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  9016. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  9017. clipping_planes_vertex: clipping_planes_vertex,
  9018. color_fragment: color_fragment,
  9019. color_pars_fragment: color_pars_fragment,
  9020. color_pars_vertex: color_pars_vertex,
  9021. color_vertex: color_vertex,
  9022. common: common,
  9023. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  9024. defaultnormal_vertex: defaultnormal_vertex,
  9025. displacementmap_pars_vertex: displacementmap_pars_vertex,
  9026. displacementmap_vertex: displacementmap_vertex,
  9027. emissivemap_fragment: emissivemap_fragment,
  9028. emissivemap_pars_fragment: emissivemap_pars_fragment,
  9029. encodings_fragment: encodings_fragment,
  9030. encodings_pars_fragment: encodings_pars_fragment,
  9031. envmap_fragment: envmap_fragment,
  9032. envmap_common_pars_fragment: envmap_common_pars_fragment,
  9033. envmap_pars_fragment: envmap_pars_fragment,
  9034. envmap_pars_vertex: envmap_pars_vertex,
  9035. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9036. envmap_vertex: envmap_vertex,
  9037. fog_vertex: fog_vertex,
  9038. fog_pars_vertex: fog_pars_vertex,
  9039. fog_fragment: fog_fragment,
  9040. fog_pars_fragment: fog_pars_fragment,
  9041. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9042. lightmap_fragment: lightmap_fragment,
  9043. lightmap_pars_fragment: lightmap_pars_fragment,
  9044. lights_lambert_vertex: lights_lambert_vertex,
  9045. lights_pars_begin: lights_pars_begin,
  9046. lights_toon_fragment: lights_toon_fragment,
  9047. lights_toon_pars_fragment: lights_toon_pars_fragment,
  9048. lights_phong_fragment: lights_phong_fragment,
  9049. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9050. lights_physical_fragment: lights_physical_fragment,
  9051. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9052. lights_fragment_begin: lights_fragment_begin,
  9053. lights_fragment_maps: lights_fragment_maps,
  9054. lights_fragment_end: lights_fragment_end,
  9055. logdepthbuf_fragment: logdepthbuf_fragment,
  9056. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9057. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9058. logdepthbuf_vertex: logdepthbuf_vertex,
  9059. map_fragment: map_fragment,
  9060. map_pars_fragment: map_pars_fragment,
  9061. map_particle_fragment: map_particle_fragment,
  9062. map_particle_pars_fragment: map_particle_pars_fragment,
  9063. metalnessmap_fragment: metalnessmap_fragment,
  9064. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9065. morphnormal_vertex: morphnormal_vertex,
  9066. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9067. morphtarget_vertex: morphtarget_vertex,
  9068. normal_fragment_begin: normal_fragment_begin,
  9069. normal_fragment_maps: normal_fragment_maps,
  9070. normalmap_pars_fragment: normalmap_pars_fragment,
  9071. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9072. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9073. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9074. packing: packing,
  9075. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9076. project_vertex: project_vertex,
  9077. dithering_fragment: dithering_fragment,
  9078. dithering_pars_fragment: dithering_pars_fragment,
  9079. roughnessmap_fragment: roughnessmap_fragment,
  9080. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9081. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9082. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9083. shadowmap_vertex: shadowmap_vertex,
  9084. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9085. skinbase_vertex: skinbase_vertex,
  9086. skinning_pars_vertex: skinning_pars_vertex,
  9087. skinning_vertex: skinning_vertex,
  9088. skinnormal_vertex: skinnormal_vertex,
  9089. specularmap_fragment: specularmap_fragment,
  9090. specularmap_pars_fragment: specularmap_pars_fragment,
  9091. tonemapping_fragment: tonemapping_fragment,
  9092. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9093. uv_pars_fragment: uv_pars_fragment,
  9094. uv_pars_vertex: uv_pars_vertex,
  9095. uv_vertex: uv_vertex,
  9096. uv2_pars_fragment: uv2_pars_fragment,
  9097. uv2_pars_vertex: uv2_pars_vertex,
  9098. uv2_vertex: uv2_vertex,
  9099. worldpos_vertex: worldpos_vertex,
  9100. background_frag: background_frag,
  9101. background_vert: background_vert,
  9102. cube_frag: cube_frag,
  9103. cube_vert: cube_vert,
  9104. depth_frag: depth_frag,
  9105. depth_vert: depth_vert,
  9106. distanceRGBA_frag: distanceRGBA_frag,
  9107. distanceRGBA_vert: distanceRGBA_vert,
  9108. equirect_frag: equirect_frag,
  9109. equirect_vert: equirect_vert,
  9110. linedashed_frag: linedashed_frag,
  9111. linedashed_vert: linedashed_vert,
  9112. meshbasic_frag: meshbasic_frag,
  9113. meshbasic_vert: meshbasic_vert,
  9114. meshlambert_frag: meshlambert_frag,
  9115. meshlambert_vert: meshlambert_vert,
  9116. meshmatcap_frag: meshmatcap_frag,
  9117. meshmatcap_vert: meshmatcap_vert,
  9118. meshtoon_frag: meshtoon_frag,
  9119. meshtoon_vert: meshtoon_vert,
  9120. meshphong_frag: meshphong_frag,
  9121. meshphong_vert: meshphong_vert,
  9122. meshphysical_frag: meshphysical_frag,
  9123. meshphysical_vert: meshphysical_vert,
  9124. normal_frag: normal_frag,
  9125. normal_vert: normal_vert,
  9126. points_frag: points_frag,
  9127. points_vert: points_vert,
  9128. shadow_frag: shadow_frag,
  9129. shadow_vert: shadow_vert,
  9130. sprite_frag: sprite_frag,
  9131. sprite_vert: sprite_vert
  9132. };
  9133. /**
  9134. * @author alteredq / http://alteredqualia.com/
  9135. * @author mrdoob / http://mrdoob.com/
  9136. * @author mikael emtinger / http://gomo.se/
  9137. */
  9138. var ShaderLib = {
  9139. basic: {
  9140. uniforms: mergeUniforms( [
  9141. UniformsLib.common,
  9142. UniformsLib.specularmap,
  9143. UniformsLib.envmap,
  9144. UniformsLib.aomap,
  9145. UniformsLib.lightmap,
  9146. UniformsLib.fog
  9147. ] ),
  9148. vertexShader: ShaderChunk.meshbasic_vert,
  9149. fragmentShader: ShaderChunk.meshbasic_frag
  9150. },
  9151. lambert: {
  9152. uniforms: mergeUniforms( [
  9153. UniformsLib.common,
  9154. UniformsLib.specularmap,
  9155. UniformsLib.envmap,
  9156. UniformsLib.aomap,
  9157. UniformsLib.lightmap,
  9158. UniformsLib.emissivemap,
  9159. UniformsLib.fog,
  9160. UniformsLib.lights,
  9161. {
  9162. emissive: { value: new Color( 0x000000 ) }
  9163. }
  9164. ] ),
  9165. vertexShader: ShaderChunk.meshlambert_vert,
  9166. fragmentShader: ShaderChunk.meshlambert_frag
  9167. },
  9168. phong: {
  9169. uniforms: mergeUniforms( [
  9170. UniformsLib.common,
  9171. UniformsLib.specularmap,
  9172. UniformsLib.envmap,
  9173. UniformsLib.aomap,
  9174. UniformsLib.lightmap,
  9175. UniformsLib.emissivemap,
  9176. UniformsLib.bumpmap,
  9177. UniformsLib.normalmap,
  9178. UniformsLib.displacementmap,
  9179. UniformsLib.fog,
  9180. UniformsLib.lights,
  9181. {
  9182. emissive: { value: new Color( 0x000000 ) },
  9183. specular: { value: new Color( 0x111111 ) },
  9184. shininess: { value: 30 }
  9185. }
  9186. ] ),
  9187. vertexShader: ShaderChunk.meshphong_vert,
  9188. fragmentShader: ShaderChunk.meshphong_frag
  9189. },
  9190. standard: {
  9191. uniforms: mergeUniforms( [
  9192. UniformsLib.common,
  9193. UniformsLib.envmap,
  9194. UniformsLib.aomap,
  9195. UniformsLib.lightmap,
  9196. UniformsLib.emissivemap,
  9197. UniformsLib.bumpmap,
  9198. UniformsLib.normalmap,
  9199. UniformsLib.displacementmap,
  9200. UniformsLib.roughnessmap,
  9201. UniformsLib.metalnessmap,
  9202. UniformsLib.fog,
  9203. UniformsLib.lights,
  9204. {
  9205. emissive: { value: new Color( 0x000000 ) },
  9206. roughness: { value: 1.0 },
  9207. metalness: { value: 0.0 },
  9208. envMapIntensity: { value: 1 } // temporary
  9209. }
  9210. ] ),
  9211. vertexShader: ShaderChunk.meshphysical_vert,
  9212. fragmentShader: ShaderChunk.meshphysical_frag
  9213. },
  9214. toon: {
  9215. uniforms: mergeUniforms( [
  9216. UniformsLib.common,
  9217. UniformsLib.aomap,
  9218. UniformsLib.lightmap,
  9219. UniformsLib.emissivemap,
  9220. UniformsLib.bumpmap,
  9221. UniformsLib.normalmap,
  9222. UniformsLib.displacementmap,
  9223. UniformsLib.gradientmap,
  9224. UniformsLib.fog,
  9225. UniformsLib.lights,
  9226. {
  9227. emissive: { value: new Color( 0x000000 ) }
  9228. }
  9229. ] ),
  9230. vertexShader: ShaderChunk.meshtoon_vert,
  9231. fragmentShader: ShaderChunk.meshtoon_frag
  9232. },
  9233. matcap: {
  9234. uniforms: mergeUniforms( [
  9235. UniformsLib.common,
  9236. UniformsLib.bumpmap,
  9237. UniformsLib.normalmap,
  9238. UniformsLib.displacementmap,
  9239. UniformsLib.fog,
  9240. {
  9241. matcap: { value: null }
  9242. }
  9243. ] ),
  9244. vertexShader: ShaderChunk.meshmatcap_vert,
  9245. fragmentShader: ShaderChunk.meshmatcap_frag
  9246. },
  9247. points: {
  9248. uniforms: mergeUniforms( [
  9249. UniformsLib.points,
  9250. UniformsLib.fog
  9251. ] ),
  9252. vertexShader: ShaderChunk.points_vert,
  9253. fragmentShader: ShaderChunk.points_frag
  9254. },
  9255. dashed: {
  9256. uniforms: mergeUniforms( [
  9257. UniformsLib.common,
  9258. UniformsLib.fog,
  9259. {
  9260. scale: { value: 1 },
  9261. dashSize: { value: 1 },
  9262. totalSize: { value: 2 }
  9263. }
  9264. ] ),
  9265. vertexShader: ShaderChunk.linedashed_vert,
  9266. fragmentShader: ShaderChunk.linedashed_frag
  9267. },
  9268. depth: {
  9269. uniforms: mergeUniforms( [
  9270. UniformsLib.common,
  9271. UniformsLib.displacementmap
  9272. ] ),
  9273. vertexShader: ShaderChunk.depth_vert,
  9274. fragmentShader: ShaderChunk.depth_frag
  9275. },
  9276. normal: {
  9277. uniforms: mergeUniforms( [
  9278. UniformsLib.common,
  9279. UniformsLib.bumpmap,
  9280. UniformsLib.normalmap,
  9281. UniformsLib.displacementmap,
  9282. {
  9283. opacity: { value: 1.0 }
  9284. }
  9285. ] ),
  9286. vertexShader: ShaderChunk.normal_vert,
  9287. fragmentShader: ShaderChunk.normal_frag
  9288. },
  9289. sprite: {
  9290. uniforms: mergeUniforms( [
  9291. UniformsLib.sprite,
  9292. UniformsLib.fog
  9293. ] ),
  9294. vertexShader: ShaderChunk.sprite_vert,
  9295. fragmentShader: ShaderChunk.sprite_frag
  9296. },
  9297. background: {
  9298. uniforms: {
  9299. uvTransform: { value: new Matrix3() },
  9300. t2D: { value: null },
  9301. },
  9302. vertexShader: ShaderChunk.background_vert,
  9303. fragmentShader: ShaderChunk.background_frag
  9304. },
  9305. /* -------------------------------------------------------------------------
  9306. // Cube map shader
  9307. ------------------------------------------------------------------------- */
  9308. cube: {
  9309. uniforms: mergeUniforms( [
  9310. UniformsLib.envmap,
  9311. {
  9312. opacity: { value: 1.0 }
  9313. }
  9314. ] ),
  9315. vertexShader: ShaderChunk.cube_vert,
  9316. fragmentShader: ShaderChunk.cube_frag
  9317. },
  9318. equirect: {
  9319. uniforms: {
  9320. tEquirect: { value: null },
  9321. },
  9322. vertexShader: ShaderChunk.equirect_vert,
  9323. fragmentShader: ShaderChunk.equirect_frag
  9324. },
  9325. distanceRGBA: {
  9326. uniforms: mergeUniforms( [
  9327. UniformsLib.common,
  9328. UniformsLib.displacementmap,
  9329. {
  9330. referencePosition: { value: new Vector3() },
  9331. nearDistance: { value: 1 },
  9332. farDistance: { value: 1000 }
  9333. }
  9334. ] ),
  9335. vertexShader: ShaderChunk.distanceRGBA_vert,
  9336. fragmentShader: ShaderChunk.distanceRGBA_frag
  9337. },
  9338. shadow: {
  9339. uniforms: mergeUniforms( [
  9340. UniformsLib.lights,
  9341. UniformsLib.fog,
  9342. {
  9343. color: { value: new Color( 0x00000 ) },
  9344. opacity: { value: 1.0 }
  9345. } ] ),
  9346. vertexShader: ShaderChunk.shadow_vert,
  9347. fragmentShader: ShaderChunk.shadow_frag
  9348. }
  9349. };
  9350. ShaderLib.physical = {
  9351. uniforms: mergeUniforms( [
  9352. ShaderLib.standard.uniforms,
  9353. {
  9354. clearcoat: { value: 0 },
  9355. clearcoatMap: { value: null },
  9356. clearcoatRoughness: { value: 0 },
  9357. clearcoatRoughnessMap: { value: null },
  9358. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  9359. clearcoatNormalMap: { value: null },
  9360. sheen: { value: new Color( 0x000000 ) },
  9361. transparency: { value: 0 },
  9362. }
  9363. ] ),
  9364. vertexShader: ShaderChunk.meshphysical_vert,
  9365. fragmentShader: ShaderChunk.meshphysical_frag
  9366. };
  9367. /**
  9368. * @author mrdoob / http://mrdoob.com/
  9369. */
  9370. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9371. var clearColor = new Color( 0x000000 );
  9372. var clearAlpha = 0;
  9373. var planeMesh;
  9374. var boxMesh;
  9375. var currentBackground = null;
  9376. var currentBackgroundVersion = 0;
  9377. var currentTonemapping = null;
  9378. function render( renderList, scene, camera, forceClear ) {
  9379. var background = scene.isScene === true ? scene.background : null;
  9380. // Ignore background in AR
  9381. // TODO: Reconsider this.
  9382. var xr = renderer.xr;
  9383. var session = xr.getSession && xr.getSession();
  9384. if ( session && session.environmentBlendMode === 'additive' ) {
  9385. background = null;
  9386. }
  9387. if ( background === null ) {
  9388. setClear( clearColor, clearAlpha );
  9389. } else if ( background && background.isColor ) {
  9390. setClear( background, 1 );
  9391. forceClear = true;
  9392. }
  9393. if ( renderer.autoClear || forceClear ) {
  9394. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9395. }
  9396. if ( background && ( background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping ) ) {
  9397. if ( boxMesh === undefined ) {
  9398. boxMesh = new Mesh(
  9399. new BoxBufferGeometry( 1, 1, 1 ),
  9400. new ShaderMaterial( {
  9401. name: 'BackgroundCubeMaterial',
  9402. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9403. vertexShader: ShaderLib.cube.vertexShader,
  9404. fragmentShader: ShaderLib.cube.fragmentShader,
  9405. side: BackSide,
  9406. depthTest: false,
  9407. depthWrite: false,
  9408. fog: false
  9409. } )
  9410. );
  9411. boxMesh.geometry.deleteAttribute( 'normal' );
  9412. boxMesh.geometry.deleteAttribute( 'uv' );
  9413. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9414. this.matrixWorld.copyPosition( camera.matrixWorld );
  9415. };
  9416. // enable code injection for non-built-in material
  9417. Object.defineProperty( boxMesh.material, 'envMap', {
  9418. get: function () {
  9419. return this.uniforms.envMap.value;
  9420. }
  9421. } );
  9422. objects.update( boxMesh );
  9423. }
  9424. var texture = background.isWebGLCubeRenderTarget ? background.texture : background;
  9425. boxMesh.material.uniforms.envMap.value = texture;
  9426. boxMesh.material.uniforms.flipEnvMap.value = texture.isCubeTexture ? - 1 : 1;
  9427. if ( currentBackground !== background ||
  9428. currentBackgroundVersion !== texture.version ||
  9429. currentTonemapping !== renderer.toneMapping ) {
  9430. boxMesh.material.needsUpdate = true;
  9431. currentBackground = background;
  9432. currentBackgroundVersion = texture.version;
  9433. currentTonemapping = renderer.toneMapping;
  9434. }
  9435. // push to the pre-sorted opaque render list
  9436. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9437. } else if ( background && background.isTexture ) {
  9438. if ( planeMesh === undefined ) {
  9439. planeMesh = new Mesh(
  9440. new PlaneBufferGeometry( 2, 2 ),
  9441. new ShaderMaterial( {
  9442. name: 'BackgroundMaterial',
  9443. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9444. vertexShader: ShaderLib.background.vertexShader,
  9445. fragmentShader: ShaderLib.background.fragmentShader,
  9446. side: FrontSide,
  9447. depthTest: false,
  9448. depthWrite: false,
  9449. fog: false
  9450. } )
  9451. );
  9452. planeMesh.geometry.deleteAttribute( 'normal' );
  9453. // enable code injection for non-built-in material
  9454. Object.defineProperty( planeMesh.material, 'map', {
  9455. get: function () {
  9456. return this.uniforms.t2D.value;
  9457. }
  9458. } );
  9459. objects.update( planeMesh );
  9460. }
  9461. planeMesh.material.uniforms.t2D.value = background;
  9462. if ( background.matrixAutoUpdate === true ) {
  9463. background.updateMatrix();
  9464. }
  9465. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9466. if ( currentBackground !== background ||
  9467. currentBackgroundVersion !== background.version ||
  9468. currentTonemapping !== renderer.toneMapping ) {
  9469. planeMesh.material.needsUpdate = true;
  9470. currentBackground = background;
  9471. currentBackgroundVersion = background.version;
  9472. currentTonemapping = renderer.toneMapping;
  9473. }
  9474. // push to the pre-sorted opaque render list
  9475. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9476. }
  9477. }
  9478. function setClear( color, alpha ) {
  9479. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9480. }
  9481. return {
  9482. getClearColor: function () {
  9483. return clearColor;
  9484. },
  9485. setClearColor: function ( color, alpha ) {
  9486. clearColor.set( color );
  9487. clearAlpha = alpha !== undefined ? alpha : 1;
  9488. setClear( clearColor, clearAlpha );
  9489. },
  9490. getClearAlpha: function () {
  9491. return clearAlpha;
  9492. },
  9493. setClearAlpha: function ( alpha ) {
  9494. clearAlpha = alpha;
  9495. setClear( clearColor, clearAlpha );
  9496. },
  9497. render: render
  9498. };
  9499. }
  9500. /**
  9501. * @author Mugen87 / https://github.com/Mugen87
  9502. * @author Takahiro / https://github.com/takahirox
  9503. */
  9504. function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
  9505. var maxVertexAttributes = gl.getParameter( 34921 );
  9506. var extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
  9507. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9508. var bindingStates = {};
  9509. var defaultState = createBindingState( null );
  9510. var currentState = defaultState;
  9511. function setup( object, material, program, geometry, index ) {
  9512. var updateBuffers = false;
  9513. if ( vaoAvailable ) {
  9514. var state = getBindingState( geometry, program, material );
  9515. if ( currentState !== state ) {
  9516. currentState = state;
  9517. bindVertexArrayObject( currentState.object );
  9518. }
  9519. updateBuffers = needsUpdate( geometry );
  9520. if ( updateBuffers ) { saveCache( geometry ); }
  9521. } else {
  9522. var wireframe = ( material.wireframe === true );
  9523. if ( currentState.geometry !== geometry.id ||
  9524. currentState.program !== program.id ||
  9525. currentState.wireframe !== wireframe ) {
  9526. currentState.geometry = geometry.id;
  9527. currentState.program = program.id;
  9528. currentState.wireframe = wireframe;
  9529. updateBuffers = true;
  9530. }
  9531. }
  9532. if ( object.isInstancedMesh === true ) {
  9533. updateBuffers = true;
  9534. }
  9535. if ( index !== null ) {
  9536. attributes.update( index, 34963 );
  9537. }
  9538. if ( updateBuffers ) {
  9539. setupVertexAttributes( object, material, program, geometry );
  9540. if ( index !== null ) {
  9541. gl.bindBuffer( 34963, attributes.get( index ).buffer );
  9542. }
  9543. }
  9544. }
  9545. function createVertexArrayObject() {
  9546. if ( capabilities.isWebGL2 ) { return gl.createVertexArray(); }
  9547. return extension.createVertexArrayOES();
  9548. }
  9549. function bindVertexArrayObject( vao ) {
  9550. if ( capabilities.isWebGL2 ) { return gl.bindVertexArray( vao ); }
  9551. return extension.bindVertexArrayOES( vao );
  9552. }
  9553. function deleteVertexArrayObject( vao ) {
  9554. if ( capabilities.isWebGL2 ) { return gl.deleteVertexArray( vao ); }
  9555. return extension.deleteVertexArrayOES( vao );
  9556. }
  9557. function getBindingState( geometry, program, material ) {
  9558. var wireframe = ( material.wireframe === true );
  9559. var programMap = bindingStates[ geometry.id ];
  9560. if ( programMap === undefined ) {
  9561. programMap = {};
  9562. bindingStates[ geometry.id ] = programMap;
  9563. }
  9564. var stateMap = programMap[ program.id ];
  9565. if ( stateMap === undefined ) {
  9566. stateMap = {};
  9567. programMap[ program.id ] = stateMap;
  9568. }
  9569. var state = stateMap[ wireframe ];
  9570. if ( state === undefined ) {
  9571. state = createBindingState( createVertexArrayObject() );
  9572. stateMap[ wireframe ] = state;
  9573. }
  9574. return state;
  9575. }
  9576. function createBindingState( vao ) {
  9577. var newAttributes = [];
  9578. var enabledAttributes = [];
  9579. var attributeDivisors = [];
  9580. for ( var i = 0; i < maxVertexAttributes; i ++ ) {
  9581. newAttributes[ i ] = 0;
  9582. enabledAttributes[ i ] = 0;
  9583. attributeDivisors[ i ] = 0;
  9584. }
  9585. return {
  9586. // for backward compatibility on non-VAO support browser
  9587. geometry: null,
  9588. program: null,
  9589. wireframe: false,
  9590. newAttributes: newAttributes,
  9591. enabledAttributes: enabledAttributes,
  9592. attributeDivisors: attributeDivisors,
  9593. object: vao,
  9594. attributes: {}
  9595. };
  9596. }
  9597. function needsUpdate( geometry ) {
  9598. var cachedAttributes = currentState.attributes;
  9599. var geometryAttributes = geometry.attributes;
  9600. if ( Object.keys( cachedAttributes ).length !== Object.keys( geometryAttributes ).length ) { return true; }
  9601. for ( var key in geometryAttributes ) {
  9602. var cachedAttribute = cachedAttributes[ key ];
  9603. var geometryAttribute = geometryAttributes[ key ];
  9604. if ( cachedAttribute.attribute !== geometryAttribute ) { return true; }
  9605. if ( cachedAttribute.data !== geometryAttribute.data ) { return true; }
  9606. }
  9607. return false;
  9608. }
  9609. function saveCache( geometry ) {
  9610. var cache = {};
  9611. var attributes = geometry.attributes;
  9612. for ( var key in attributes ) {
  9613. var attribute = attributes[ key ];
  9614. var data = {};
  9615. data.attribute = attribute;
  9616. if ( attribute.data ) {
  9617. data.data = attribute.data;
  9618. }
  9619. cache[ key ] = data;
  9620. }
  9621. currentState.attributes = cache;
  9622. }
  9623. function initAttributes() {
  9624. var newAttributes = currentState.newAttributes;
  9625. for ( var i = 0, il = newAttributes.length; i < il; i ++ ) {
  9626. newAttributes[ i ] = 0;
  9627. }
  9628. }
  9629. function enableAttribute( attribute ) {
  9630. enableAttributeAndDivisor( attribute, 0 );
  9631. }
  9632. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  9633. var newAttributes = currentState.newAttributes;
  9634. var enabledAttributes = currentState.enabledAttributes;
  9635. var attributeDivisors = currentState.attributeDivisors;
  9636. newAttributes[ attribute ] = 1;
  9637. if ( enabledAttributes[ attribute ] === 0 ) {
  9638. gl.enableVertexAttribArray( attribute );
  9639. enabledAttributes[ attribute ] = 1;
  9640. }
  9641. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  9642. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  9643. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  9644. attributeDivisors[ attribute ] = meshPerAttribute;
  9645. }
  9646. }
  9647. function disableUnusedAttributes() {
  9648. var newAttributes = currentState.newAttributes;
  9649. var enabledAttributes = currentState.enabledAttributes;
  9650. for ( var i = 0, il = enabledAttributes.length; i < il; i ++ ) {
  9651. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  9652. gl.disableVertexAttribArray( i );
  9653. enabledAttributes[ i ] = 0;
  9654. }
  9655. }
  9656. }
  9657. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  9658. if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  9659. gl.vertexAttribIPointer( index, size, type, normalized, stride, offset );
  9660. } else {
  9661. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  9662. }
  9663. }
  9664. function setupVertexAttributes( object, material, program, geometry ) {
  9665. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  9666. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) { return; }
  9667. }
  9668. initAttributes();
  9669. var geometryAttributes = geometry.attributes;
  9670. var programAttributes = program.getAttributes();
  9671. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9672. for ( var name in programAttributes ) {
  9673. var programAttribute = programAttributes[ name ];
  9674. if ( programAttribute >= 0 ) {
  9675. var geometryAttribute = geometryAttributes[ name ];
  9676. if ( geometryAttribute !== undefined ) {
  9677. var normalized = geometryAttribute.normalized;
  9678. var size = geometryAttribute.itemSize;
  9679. var attribute = attributes.get( geometryAttribute );
  9680. // TODO Attribute may not be available on context restore
  9681. if ( attribute === undefined ) { continue; }
  9682. var buffer = attribute.buffer;
  9683. var type = attribute.type;
  9684. var bytesPerElement = attribute.bytesPerElement;
  9685. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  9686. var data = geometryAttribute.data;
  9687. var stride = data.stride;
  9688. var offset = geometryAttribute.offset;
  9689. if ( data && data.isInstancedInterleavedBuffer ) {
  9690. enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  9691. if ( geometry._maxInstanceCount === undefined ) {
  9692. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9693. }
  9694. } else {
  9695. enableAttribute( programAttribute );
  9696. }
  9697. gl.bindBuffer( 34962, buffer );
  9698. vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  9699. } else {
  9700. if ( geometryAttribute.isInstancedBufferAttribute ) {
  9701. enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  9702. if ( geometry._maxInstanceCount === undefined ) {
  9703. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9704. }
  9705. } else {
  9706. enableAttribute( programAttribute );
  9707. }
  9708. gl.bindBuffer( 34962, buffer );
  9709. vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  9710. }
  9711. } else if ( name === 'instanceMatrix' ) {
  9712. var attribute$1 = attributes.get( object.instanceMatrix );
  9713. // TODO Attribute may not be available on context restore
  9714. if ( attribute$1 === undefined ) { continue; }
  9715. var buffer$1 = attribute$1.buffer;
  9716. var type$1 = attribute$1.type;
  9717. enableAttributeAndDivisor( programAttribute + 0, 1 );
  9718. enableAttributeAndDivisor( programAttribute + 1, 1 );
  9719. enableAttributeAndDivisor( programAttribute + 2, 1 );
  9720. enableAttributeAndDivisor( programAttribute + 3, 1 );
  9721. gl.bindBuffer( 34962, buffer$1 );
  9722. gl.vertexAttribPointer( programAttribute + 0, 4, type$1, false, 64, 0 );
  9723. gl.vertexAttribPointer( programAttribute + 1, 4, type$1, false, 64, 16 );
  9724. gl.vertexAttribPointer( programAttribute + 2, 4, type$1, false, 64, 32 );
  9725. gl.vertexAttribPointer( programAttribute + 3, 4, type$1, false, 64, 48 );
  9726. } else if ( materialDefaultAttributeValues !== undefined ) {
  9727. var value = materialDefaultAttributeValues[ name ];
  9728. if ( value !== undefined ) {
  9729. switch ( value.length ) {
  9730. case 2:
  9731. gl.vertexAttrib2fv( programAttribute, value );
  9732. break;
  9733. case 3:
  9734. gl.vertexAttrib3fv( programAttribute, value );
  9735. break;
  9736. case 4:
  9737. gl.vertexAttrib4fv( programAttribute, value );
  9738. break;
  9739. default:
  9740. gl.vertexAttrib1fv( programAttribute, value );
  9741. }
  9742. }
  9743. }
  9744. }
  9745. }
  9746. disableUnusedAttributes();
  9747. }
  9748. function dispose() {
  9749. reset();
  9750. for ( var geometryId in bindingStates ) {
  9751. var programMap = bindingStates[ geometryId ];
  9752. for ( var programId in programMap ) {
  9753. var stateMap = programMap[ programId ];
  9754. for ( var wireframe in stateMap ) {
  9755. deleteVertexArrayObject( stateMap[ wireframe ].object );
  9756. delete stateMap[ wireframe ];
  9757. }
  9758. delete programMap[ programId ];
  9759. }
  9760. delete bindingStates[ geometryId ];
  9761. }
  9762. }
  9763. function releaseStatesOfGeometry( geometry ) {
  9764. if ( bindingStates[ geometry.id ] === undefined ) { return; }
  9765. var programMap = bindingStates[ geometry.id ];
  9766. for ( var programId in programMap ) {
  9767. var stateMap = programMap[ programId ];
  9768. for ( var wireframe in stateMap ) {
  9769. deleteVertexArrayObject( stateMap[ wireframe ].object );
  9770. delete stateMap[ wireframe ];
  9771. }
  9772. delete programMap[ programId ];
  9773. }
  9774. delete bindingStates[ geometry.id ];
  9775. }
  9776. function releaseStatesOfProgram( program ) {
  9777. for ( var geometryId in bindingStates ) {
  9778. var programMap = bindingStates[ geometryId ];
  9779. if ( programMap[ program.id ] === undefined ) { continue; }
  9780. var stateMap = programMap[ program.id ];
  9781. for ( var wireframe in stateMap ) {
  9782. deleteVertexArrayObject( stateMap[ wireframe ].object );
  9783. delete stateMap[ wireframe ];
  9784. }
  9785. delete programMap[ program.id ];
  9786. }
  9787. }
  9788. function reset() {
  9789. resetDefaultState();
  9790. if ( currentState === defaultState ) { return; }
  9791. currentState = defaultState;
  9792. bindVertexArrayObject( currentState.object );
  9793. }
  9794. // for backward-compatilibity
  9795. function resetDefaultState() {
  9796. defaultState.geometry = null;
  9797. defaultState.program = null;
  9798. defaultState.wireframe = false;
  9799. }
  9800. return {
  9801. setup: setup,
  9802. reset: reset,
  9803. resetDefaultState: resetDefaultState,
  9804. dispose: dispose,
  9805. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9806. releaseStatesOfProgram: releaseStatesOfProgram,
  9807. initAttributes: initAttributes,
  9808. enableAttribute: enableAttribute,
  9809. disableUnusedAttributes: disableUnusedAttributes
  9810. };
  9811. }
  9812. /**
  9813. * @author mrdoob / http://mrdoob.com/
  9814. */
  9815. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9816. var isWebGL2 = capabilities.isWebGL2;
  9817. var mode;
  9818. function setMode( value ) {
  9819. mode = value;
  9820. }
  9821. function render( start, count ) {
  9822. gl.drawArrays( mode, start, count );
  9823. info.update( count, mode );
  9824. }
  9825. function renderInstances( geometry, start, count, primcount ) {
  9826. if ( primcount === 0 ) { return; }
  9827. var extension, methodName;
  9828. if ( isWebGL2 ) {
  9829. extension = gl;
  9830. methodName = 'drawArraysInstanced';
  9831. } else {
  9832. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9833. methodName = 'drawArraysInstancedANGLE';
  9834. if ( extension === null ) {
  9835. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9836. return;
  9837. }
  9838. }
  9839. extension[ methodName ]( mode, start, count, primcount );
  9840. info.update( count, mode, primcount );
  9841. }
  9842. //
  9843. this.setMode = setMode;
  9844. this.render = render;
  9845. this.renderInstances = renderInstances;
  9846. }
  9847. /**
  9848. * @author mrdoob / http://mrdoob.com/
  9849. */
  9850. function WebGLCapabilities( gl, extensions, parameters ) {
  9851. var maxAnisotropy;
  9852. function getMaxAnisotropy() {
  9853. if ( maxAnisotropy !== undefined ) { return maxAnisotropy; }
  9854. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9855. if ( extension !== null ) {
  9856. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9857. } else {
  9858. maxAnisotropy = 0;
  9859. }
  9860. return maxAnisotropy;
  9861. }
  9862. function getMaxPrecision( precision ) {
  9863. if ( precision === 'highp' ) {
  9864. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9865. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9866. return 'highp';
  9867. }
  9868. precision = 'mediump';
  9869. }
  9870. if ( precision === 'mediump' ) {
  9871. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9872. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9873. return 'mediump';
  9874. }
  9875. }
  9876. return 'lowp';
  9877. }
  9878. /* eslint-disable no-undef */
  9879. var isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  9880. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  9881. /* eslint-enable no-undef */
  9882. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9883. var maxPrecision = getMaxPrecision( precision );
  9884. if ( maxPrecision !== precision ) {
  9885. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9886. precision = maxPrecision;
  9887. }
  9888. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9889. var maxTextures = gl.getParameter( 34930 );
  9890. var maxVertexTextures = gl.getParameter( 35660 );
  9891. var maxTextureSize = gl.getParameter( 3379 );
  9892. var maxCubemapSize = gl.getParameter( 34076 );
  9893. var maxAttributes = gl.getParameter( 34921 );
  9894. var maxVertexUniforms = gl.getParameter( 36347 );
  9895. var maxVaryings = gl.getParameter( 36348 );
  9896. var maxFragmentUniforms = gl.getParameter( 36349 );
  9897. var vertexTextures = maxVertexTextures > 0;
  9898. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9899. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9900. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9901. return {
  9902. isWebGL2: isWebGL2,
  9903. getMaxAnisotropy: getMaxAnisotropy,
  9904. getMaxPrecision: getMaxPrecision,
  9905. precision: precision,
  9906. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9907. maxTextures: maxTextures,
  9908. maxVertexTextures: maxVertexTextures,
  9909. maxTextureSize: maxTextureSize,
  9910. maxCubemapSize: maxCubemapSize,
  9911. maxAttributes: maxAttributes,
  9912. maxVertexUniforms: maxVertexUniforms,
  9913. maxVaryings: maxVaryings,
  9914. maxFragmentUniforms: maxFragmentUniforms,
  9915. vertexTextures: vertexTextures,
  9916. floatFragmentTextures: floatFragmentTextures,
  9917. floatVertexTextures: floatVertexTextures,
  9918. maxSamples: maxSamples
  9919. };
  9920. }
  9921. /**
  9922. * @author tschw
  9923. */
  9924. function WebGLClipping() {
  9925. var scope = this;
  9926. var globalState = null,
  9927. numGlobalPlanes = 0,
  9928. localClippingEnabled = false,
  9929. renderingShadows = false;
  9930. var plane = new Plane(),
  9931. viewNormalMatrix = new Matrix3(),
  9932. uniform = { value: null, needsUpdate: false };
  9933. this.uniform = uniform;
  9934. this.numPlanes = 0;
  9935. this.numIntersection = 0;
  9936. this.init = function ( planes, enableLocalClipping, camera ) {
  9937. var enabled =
  9938. planes.length !== 0 ||
  9939. enableLocalClipping ||
  9940. // enable state of previous frame - the clipping code has to
  9941. // run another frame in order to reset the state:
  9942. numGlobalPlanes !== 0 ||
  9943. localClippingEnabled;
  9944. localClippingEnabled = enableLocalClipping;
  9945. globalState = projectPlanes( planes, camera, 0 );
  9946. numGlobalPlanes = planes.length;
  9947. return enabled;
  9948. };
  9949. this.beginShadows = function () {
  9950. renderingShadows = true;
  9951. projectPlanes( null );
  9952. };
  9953. this.endShadows = function () {
  9954. renderingShadows = false;
  9955. resetGlobalState();
  9956. };
  9957. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9958. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9959. // there's no local clipping
  9960. if ( renderingShadows ) {
  9961. // there's no global clipping
  9962. projectPlanes( null );
  9963. } else {
  9964. resetGlobalState();
  9965. }
  9966. } else {
  9967. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9968. lGlobal = nGlobal * 4;
  9969. var dstArray = cache.clippingState || null;
  9970. uniform.value = dstArray; // ensure unique state
  9971. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9972. for ( var i = 0; i !== lGlobal; ++ i ) {
  9973. dstArray[ i ] = globalState[ i ];
  9974. }
  9975. cache.clippingState = dstArray;
  9976. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9977. this.numPlanes += nGlobal;
  9978. }
  9979. };
  9980. function resetGlobalState() {
  9981. if ( uniform.value !== globalState ) {
  9982. uniform.value = globalState;
  9983. uniform.needsUpdate = numGlobalPlanes > 0;
  9984. }
  9985. scope.numPlanes = numGlobalPlanes;
  9986. scope.numIntersection = 0;
  9987. }
  9988. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9989. var nPlanes = planes !== null ? planes.length : 0,
  9990. dstArray = null;
  9991. if ( nPlanes !== 0 ) {
  9992. dstArray = uniform.value;
  9993. if ( skipTransform !== true || dstArray === null ) {
  9994. var flatSize = dstOffset + nPlanes * 4,
  9995. viewMatrix = camera.matrixWorldInverse;
  9996. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9997. if ( dstArray === null || dstArray.length < flatSize ) {
  9998. dstArray = new Float32Array( flatSize );
  9999. }
  10000. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  10001. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  10002. plane.normal.toArray( dstArray, i4 );
  10003. dstArray[ i4 + 3 ] = plane.constant;
  10004. }
  10005. }
  10006. uniform.value = dstArray;
  10007. uniform.needsUpdate = true;
  10008. }
  10009. scope.numPlanes = nPlanes;
  10010. scope.numIntersection = 0;
  10011. return dstArray;
  10012. }
  10013. }
  10014. /**
  10015. * @author mrdoob / http://mrdoob.com/
  10016. */
  10017. function WebGLExtensions( gl ) {
  10018. var extensions = {};
  10019. return {
  10020. get: function ( name ) {
  10021. if ( extensions[ name ] !== undefined ) {
  10022. return extensions[ name ];
  10023. }
  10024. var extension;
  10025. switch ( name ) {
  10026. case 'WEBGL_depth_texture':
  10027. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  10028. break;
  10029. case 'EXT_texture_filter_anisotropic':
  10030. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  10031. break;
  10032. case 'WEBGL_compressed_texture_s3tc':
  10033. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  10034. break;
  10035. case 'WEBGL_compressed_texture_pvrtc':
  10036. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  10037. break;
  10038. default:
  10039. extension = gl.getExtension( name );
  10040. }
  10041. if ( extension === null ) {
  10042. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  10043. }
  10044. extensions[ name ] = extension;
  10045. return extension;
  10046. }
  10047. };
  10048. }
  10049. /**
  10050. * @author mrdoob / http://mrdoob.com/
  10051. */
  10052. function WebGLGeometries( gl, attributes, info, bindingStates ) {
  10053. var geometries = new WeakMap();
  10054. var wireframeAttributes = new WeakMap();
  10055. function onGeometryDispose( event ) {
  10056. var geometry = event.target;
  10057. var buffergeometry = geometries.get( geometry );
  10058. if ( buffergeometry.index !== null ) {
  10059. attributes.remove( buffergeometry.index );
  10060. }
  10061. for ( var name in buffergeometry.attributes ) {
  10062. attributes.remove( buffergeometry.attributes[ name ] );
  10063. }
  10064. geometry.removeEventListener( 'dispose', onGeometryDispose );
  10065. geometries.delete( geometry );
  10066. var attribute = wireframeAttributes.get( buffergeometry );
  10067. if ( attribute ) {
  10068. attributes.remove( attribute );
  10069. wireframeAttributes.delete( buffergeometry );
  10070. }
  10071. bindingStates.releaseStatesOfGeometry( geometry );
  10072. if ( geometry.isInstancedBufferGeometry === true ) {
  10073. delete geometry._maxInstanceCount;
  10074. }
  10075. //
  10076. info.memory.geometries --;
  10077. }
  10078. function get( object, geometry ) {
  10079. var buffergeometry = geometries.get( geometry );
  10080. if ( buffergeometry ) { return buffergeometry; }
  10081. geometry.addEventListener( 'dispose', onGeometryDispose );
  10082. if ( geometry.isBufferGeometry ) {
  10083. buffergeometry = geometry;
  10084. } else if ( geometry.isGeometry ) {
  10085. if ( geometry._bufferGeometry === undefined ) {
  10086. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  10087. }
  10088. buffergeometry = geometry._bufferGeometry;
  10089. }
  10090. geometries.set( geometry, buffergeometry );
  10091. info.memory.geometries ++;
  10092. return buffergeometry;
  10093. }
  10094. function update( geometry ) {
  10095. var geometryAttributes = geometry.attributes;
  10096. // Updating index buffer in VAO now. See WebGLBindingStates.
  10097. for ( var name in geometryAttributes ) {
  10098. attributes.update( geometryAttributes[ name ], 34962 );
  10099. }
  10100. // morph targets
  10101. var morphAttributes = geometry.morphAttributes;
  10102. for ( var name$1 in morphAttributes ) {
  10103. var array = morphAttributes[ name$1 ];
  10104. for ( var i = 0, l = array.length; i < l; i ++ ) {
  10105. attributes.update( array[ i ], 34962 );
  10106. }
  10107. }
  10108. }
  10109. function updateWireframeAttribute( geometry ) {
  10110. var indices = [];
  10111. var geometryIndex = geometry.index;
  10112. var geometryPosition = geometry.attributes.position;
  10113. var version = 0;
  10114. if ( geometryIndex !== null ) {
  10115. var array = geometryIndex.array;
  10116. version = geometryIndex.version;
  10117. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  10118. var a = array[ i + 0 ];
  10119. var b = array[ i + 1 ];
  10120. var c = array[ i + 2 ];
  10121. indices.push( a, b, b, c, c, a );
  10122. }
  10123. } else {
  10124. var array$1 = geometryPosition.array;
  10125. version = geometryPosition.version;
  10126. for ( var i$1 = 0, l$1 = ( array$1.length / 3 ) - 1; i$1 < l$1; i$1 += 3 ) {
  10127. var a$1 = i$1 + 0;
  10128. var b$1 = i$1 + 1;
  10129. var c$1 = i$1 + 2;
  10130. indices.push( a$1, b$1, b$1, c$1, c$1, a$1 );
  10131. }
  10132. }
  10133. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  10134. attribute.version = version;
  10135. // Updating index buffer in VAO now. See WebGLBindingStates
  10136. //
  10137. var previousAttribute = wireframeAttributes.get( geometry );
  10138. if ( previousAttribute ) { attributes.remove( previousAttribute ); }
  10139. //
  10140. wireframeAttributes.set( geometry, attribute );
  10141. }
  10142. function getWireframeAttribute( geometry ) {
  10143. var currentAttribute = wireframeAttributes.get( geometry );
  10144. if ( currentAttribute ) {
  10145. var geometryIndex = geometry.index;
  10146. if ( geometryIndex !== null ) {
  10147. // if the attribute is obsolete, create a new one
  10148. if ( currentAttribute.version < geometryIndex.version ) {
  10149. updateWireframeAttribute( geometry );
  10150. }
  10151. }
  10152. } else {
  10153. updateWireframeAttribute( geometry );
  10154. }
  10155. return wireframeAttributes.get( geometry );
  10156. }
  10157. return {
  10158. get: get,
  10159. update: update,
  10160. getWireframeAttribute: getWireframeAttribute
  10161. };
  10162. }
  10163. /**
  10164. * @author mrdoob / http://mrdoob.com/
  10165. */
  10166. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  10167. var isWebGL2 = capabilities.isWebGL2;
  10168. var mode;
  10169. function setMode( value ) {
  10170. mode = value;
  10171. }
  10172. var type, bytesPerElement;
  10173. function setIndex( value ) {
  10174. type = value.type;
  10175. bytesPerElement = value.bytesPerElement;
  10176. }
  10177. function render( start, count ) {
  10178. gl.drawElements( mode, count, type, start * bytesPerElement );
  10179. info.update( count, mode );
  10180. }
  10181. function renderInstances( geometry, start, count, primcount ) {
  10182. if ( primcount === 0 ) { return; }
  10183. var extension, methodName;
  10184. if ( isWebGL2 ) {
  10185. extension = gl;
  10186. methodName = 'drawElementsInstanced';
  10187. } else {
  10188. extension = extensions.get( 'ANGLE_instanced_arrays' );
  10189. methodName = 'drawElementsInstancedANGLE';
  10190. if ( extension === null ) {
  10191. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  10192. return;
  10193. }
  10194. }
  10195. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  10196. info.update( count, mode, primcount );
  10197. }
  10198. //
  10199. this.setMode = setMode;
  10200. this.setIndex = setIndex;
  10201. this.render = render;
  10202. this.renderInstances = renderInstances;
  10203. }
  10204. /**
  10205. * @author Mugen87 / https://github.com/Mugen87
  10206. */
  10207. function WebGLInfo( gl ) {
  10208. var memory = {
  10209. geometries: 0,
  10210. textures: 0
  10211. };
  10212. var render = {
  10213. frame: 0,
  10214. calls: 0,
  10215. triangles: 0,
  10216. points: 0,
  10217. lines: 0
  10218. };
  10219. function update( count, mode, instanceCount ) {
  10220. instanceCount = instanceCount || 1;
  10221. render.calls ++;
  10222. switch ( mode ) {
  10223. case 4:
  10224. render.triangles += instanceCount * ( count / 3 );
  10225. break;
  10226. case 1:
  10227. render.lines += instanceCount * ( count / 2 );
  10228. break;
  10229. case 3:
  10230. render.lines += instanceCount * ( count - 1 );
  10231. break;
  10232. case 2:
  10233. render.lines += instanceCount * count;
  10234. break;
  10235. case 0:
  10236. render.points += instanceCount * count;
  10237. break;
  10238. default:
  10239. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  10240. break;
  10241. }
  10242. }
  10243. function reset() {
  10244. render.frame ++;
  10245. render.calls = 0;
  10246. render.triangles = 0;
  10247. render.points = 0;
  10248. render.lines = 0;
  10249. }
  10250. return {
  10251. memory: memory,
  10252. render: render,
  10253. programs: null,
  10254. autoReset: true,
  10255. reset: reset,
  10256. update: update
  10257. };
  10258. }
  10259. /**
  10260. * @author mrdoob / http://mrdoob.com/
  10261. */
  10262. function numericalSort( a, b ) {
  10263. return a[ 0 ] - b[ 0 ];
  10264. }
  10265. function absNumericalSort( a, b ) {
  10266. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  10267. }
  10268. function WebGLMorphtargets( gl ) {
  10269. var influencesList = {};
  10270. var morphInfluences = new Float32Array( 8 );
  10271. var workInfluences = [];
  10272. for ( var i = 0; i < 8; i ++ ) {
  10273. workInfluences[ i ] = [ i, 0 ];
  10274. }
  10275. function update( object, geometry, material, program ) {
  10276. var objectInfluences = object.morphTargetInfluences;
  10277. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10278. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10279. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10280. var influences = influencesList[ geometry.id ];
  10281. if ( influences === undefined ) {
  10282. // initialise list
  10283. influences = [];
  10284. for ( var i = 0; i < length; i ++ ) {
  10285. influences[ i ] = [ i, 0 ];
  10286. }
  10287. influencesList[ geometry.id ] = influences;
  10288. }
  10289. // Collect influences
  10290. for ( var i$1 = 0; i$1 < length; i$1 ++ ) {
  10291. var influence = influences[ i$1 ];
  10292. influence[ 0 ] = i$1;
  10293. influence[ 1 ] = objectInfluences[ i$1 ];
  10294. }
  10295. influences.sort( absNumericalSort );
  10296. for ( var i$2 = 0; i$2 < 8; i$2 ++ ) {
  10297. if ( i$2 < length && influences[ i$2 ][ 1 ] ) {
  10298. workInfluences[ i$2 ][ 0 ] = influences[ i$2 ][ 0 ];
  10299. workInfluences[ i$2 ][ 1 ] = influences[ i$2 ][ 1 ];
  10300. } else {
  10301. workInfluences[ i$2 ][ 0 ] = Number.MAX_SAFE_INTEGER;
  10302. workInfluences[ i$2 ][ 1 ] = 0;
  10303. }
  10304. }
  10305. workInfluences.sort( numericalSort );
  10306. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10307. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10308. var morphInfluencesSum = 0;
  10309. for ( var i$3 = 0; i$3 < 8; i$3 ++ ) {
  10310. var influence$1 = workInfluences[ i$3 ];
  10311. var index = influence$1[ 0 ];
  10312. var value = influence$1[ 1 ];
  10313. if ( index !== Number.MAX_SAFE_INTEGER && value ) {
  10314. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i$3 ) !== morphTargets[ index ] ) {
  10315. geometry.setAttribute( 'morphTarget' + i$3, morphTargets[ index ] );
  10316. }
  10317. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i$3 ) !== morphNormals[ index ] ) {
  10318. geometry.setAttribute( 'morphNormal' + i$3, morphNormals[ index ] );
  10319. }
  10320. morphInfluences[ i$3 ] = value;
  10321. morphInfluencesSum += value;
  10322. } else {
  10323. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i$3 ) !== undefined ) {
  10324. geometry.deleteAttribute( 'morphTarget' + i$3 );
  10325. }
  10326. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i$3 ) !== undefined ) {
  10327. geometry.deleteAttribute( 'morphNormal' + i$3 );
  10328. }
  10329. morphInfluences[ i$3 ] = 0;
  10330. }
  10331. }
  10332. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10333. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10334. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10335. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10336. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  10337. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  10338. }
  10339. return {
  10340. update: update
  10341. };
  10342. }
  10343. /**
  10344. * @author mrdoob / http://mrdoob.com/
  10345. */
  10346. function WebGLObjects( gl, geometries, attributes, info ) {
  10347. var updateMap = new WeakMap();
  10348. function update( object ) {
  10349. var frame = info.render.frame;
  10350. var geometry = object.geometry;
  10351. var buffergeometry = geometries.get( object, geometry );
  10352. // Update once per frame
  10353. if ( updateMap.get( buffergeometry ) !== frame ) {
  10354. if ( geometry.isGeometry ) {
  10355. buffergeometry.updateFromObject( object );
  10356. }
  10357. geometries.update( buffergeometry );
  10358. updateMap.set( buffergeometry, frame );
  10359. }
  10360. if ( object.isInstancedMesh ) {
  10361. attributes.update( object.instanceMatrix, 34962 );
  10362. }
  10363. return buffergeometry;
  10364. }
  10365. function dispose() {
  10366. updateMap = new WeakMap();
  10367. }
  10368. return {
  10369. update: update,
  10370. dispose: dispose
  10371. };
  10372. }
  10373. /**
  10374. * @author mrdoob / http://mrdoob.com/
  10375. */
  10376. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  10377. images = images !== undefined ? images : [];
  10378. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  10379. format = format !== undefined ? format : RGBFormat;
  10380. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  10381. this.flipY = false;
  10382. }
  10383. CubeTexture.prototype = Object.create( Texture.prototype );
  10384. CubeTexture.prototype.constructor = CubeTexture;
  10385. CubeTexture.prototype.isCubeTexture = true;
  10386. Object.defineProperty( CubeTexture.prototype, 'images', {
  10387. get: function () {
  10388. return this.image;
  10389. },
  10390. set: function ( value ) {
  10391. this.image = value;
  10392. }
  10393. } );
  10394. /**
  10395. * @author Takahiro https://github.com/takahirox
  10396. */
  10397. function DataTexture2DArray( data, width, height, depth ) {
  10398. Texture.call( this, null );
  10399. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  10400. this.magFilter = NearestFilter;
  10401. this.minFilter = NearestFilter;
  10402. this.wrapR = ClampToEdgeWrapping;
  10403. this.generateMipmaps = false;
  10404. this.flipY = false;
  10405. this.needsUpdate = true;
  10406. }
  10407. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  10408. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10409. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10410. /**
  10411. * @author Artur Trzesiok
  10412. */
  10413. function DataTexture3D( data, width, height, depth ) {
  10414. // We're going to add .setXXX() methods for setting properties later.
  10415. // Users can still set in DataTexture3D directly.
  10416. //
  10417. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10418. // texture.anisotropy = 16;
  10419. //
  10420. // See #14839
  10421. Texture.call( this, null );
  10422. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  10423. this.magFilter = NearestFilter;
  10424. this.minFilter = NearestFilter;
  10425. this.wrapR = ClampToEdgeWrapping;
  10426. this.generateMipmaps = false;
  10427. this.flipY = false;
  10428. this.needsUpdate = true;
  10429. }
  10430. DataTexture3D.prototype = Object.create( Texture.prototype );
  10431. DataTexture3D.prototype.constructor = DataTexture3D;
  10432. DataTexture3D.prototype.isDataTexture3D = true;
  10433. /**
  10434. * @author tschw
  10435. * @author Mugen87 / https://github.com/Mugen87
  10436. * @author mrdoob / http://mrdoob.com/
  10437. *
  10438. * Uniforms of a program.
  10439. * Those form a tree structure with a special top-level container for the root,
  10440. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10441. *
  10442. *
  10443. * Properties of inner nodes including the top-level container:
  10444. *
  10445. * .seq - array of nested uniforms
  10446. * .map - nested uniforms by name
  10447. *
  10448. *
  10449. * Methods of all nodes except the top-level container:
  10450. *
  10451. * .setValue( gl, value, [textures] )
  10452. *
  10453. * uploads a uniform value(s)
  10454. * the 'textures' parameter is needed for sampler uniforms
  10455. *
  10456. *
  10457. * Static methods of the top-level container (textures factorizations):
  10458. *
  10459. * .upload( gl, seq, values, textures )
  10460. *
  10461. * sets uniforms in 'seq' to 'values[id].value'
  10462. *
  10463. * .seqWithValue( seq, values ) : filteredSeq
  10464. *
  10465. * filters 'seq' entries with corresponding entry in values
  10466. *
  10467. *
  10468. * Methods of the top-level container (textures factorizations):
  10469. *
  10470. * .setValue( gl, name, value, textures )
  10471. *
  10472. * sets uniform with name 'name' to 'value'
  10473. *
  10474. * .setOptional( gl, obj, prop )
  10475. *
  10476. * like .set for an optional property of the object
  10477. *
  10478. */
  10479. var emptyTexture = new Texture();
  10480. var emptyTexture2dArray = new DataTexture2DArray();
  10481. var emptyTexture3d = new DataTexture3D();
  10482. var emptyCubeTexture = new CubeTexture();
  10483. // --- Utilities ---
  10484. // Array Caches (provide typed arrays for temporary by size)
  10485. var arrayCacheF32 = [];
  10486. var arrayCacheI32 = [];
  10487. // Float32Array caches used for uploading Matrix uniforms
  10488. var mat4array = new Float32Array( 16 );
  10489. var mat3array = new Float32Array( 9 );
  10490. var mat2array = new Float32Array( 4 );
  10491. // Flattening for arrays of vectors and matrices
  10492. function flatten( array, nBlocks, blockSize ) {
  10493. var firstElem = array[ 0 ];
  10494. if ( firstElem <= 0 || firstElem > 0 ) { return array; }
  10495. // unoptimized: ! isNaN( firstElem )
  10496. // see http://jacksondunstan.com/articles/983
  10497. var n = nBlocks * blockSize,
  10498. r = arrayCacheF32[ n ];
  10499. if ( r === undefined ) {
  10500. r = new Float32Array( n );
  10501. arrayCacheF32[ n ] = r;
  10502. }
  10503. if ( nBlocks !== 0 ) {
  10504. firstElem.toArray( r, 0 );
  10505. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10506. offset += blockSize;
  10507. array[ i ].toArray( r, offset );
  10508. }
  10509. }
  10510. return r;
  10511. }
  10512. function arraysEqual( a, b ) {
  10513. if ( a.length !== b.length ) { return false; }
  10514. for ( var i = 0, l = a.length; i < l; i ++ ) {
  10515. if ( a[ i ] !== b[ i ] ) { return false; }
  10516. }
  10517. return true;
  10518. }
  10519. function copyArray( a, b ) {
  10520. for ( var i = 0, l = b.length; i < l; i ++ ) {
  10521. a[ i ] = b[ i ];
  10522. }
  10523. }
  10524. // Texture unit allocation
  10525. function allocTexUnits( textures, n ) {
  10526. var r = arrayCacheI32[ n ];
  10527. if ( r === undefined ) {
  10528. r = new Int32Array( n );
  10529. arrayCacheI32[ n ] = r;
  10530. }
  10531. for ( var i = 0; i !== n; ++ i ) {
  10532. r[ i ] = textures.allocateTextureUnit();
  10533. }
  10534. return r;
  10535. }
  10536. // --- Setters ---
  10537. // Note: Defining these methods externally, because they come in a bunch
  10538. // and this way their names minify.
  10539. // Single scalar
  10540. function setValueV1f( gl, v ) {
  10541. var cache = this.cache;
  10542. if ( cache[ 0 ] === v ) { return; }
  10543. gl.uniform1f( this.addr, v );
  10544. cache[ 0 ] = v;
  10545. }
  10546. // Single float vector (from flat array or THREE.VectorN)
  10547. function setValueV2f( gl, v ) {
  10548. var cache = this.cache;
  10549. if ( v.x !== undefined ) {
  10550. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10551. gl.uniform2f( this.addr, v.x, v.y );
  10552. cache[ 0 ] = v.x;
  10553. cache[ 1 ] = v.y;
  10554. }
  10555. } else {
  10556. if ( arraysEqual( cache, v ) ) { return; }
  10557. gl.uniform2fv( this.addr, v );
  10558. copyArray( cache, v );
  10559. }
  10560. }
  10561. function setValueV3f( gl, v ) {
  10562. var cache = this.cache;
  10563. if ( v.x !== undefined ) {
  10564. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10565. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10566. cache[ 0 ] = v.x;
  10567. cache[ 1 ] = v.y;
  10568. cache[ 2 ] = v.z;
  10569. }
  10570. } else if ( v.r !== undefined ) {
  10571. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10572. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10573. cache[ 0 ] = v.r;
  10574. cache[ 1 ] = v.g;
  10575. cache[ 2 ] = v.b;
  10576. }
  10577. } else {
  10578. if ( arraysEqual( cache, v ) ) { return; }
  10579. gl.uniform3fv( this.addr, v );
  10580. copyArray( cache, v );
  10581. }
  10582. }
  10583. function setValueV4f( gl, v ) {
  10584. var cache = this.cache;
  10585. if ( v.x !== undefined ) {
  10586. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10587. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10588. cache[ 0 ] = v.x;
  10589. cache[ 1 ] = v.y;
  10590. cache[ 2 ] = v.z;
  10591. cache[ 3 ] = v.w;
  10592. }
  10593. } else {
  10594. if ( arraysEqual( cache, v ) ) { return; }
  10595. gl.uniform4fv( this.addr, v );
  10596. copyArray( cache, v );
  10597. }
  10598. }
  10599. // Single matrix (from flat array or MatrixN)
  10600. function setValueM2( gl, v ) {
  10601. var cache = this.cache;
  10602. var elements = v.elements;
  10603. if ( elements === undefined ) {
  10604. if ( arraysEqual( cache, v ) ) { return; }
  10605. gl.uniformMatrix2fv( this.addr, false, v );
  10606. copyArray( cache, v );
  10607. } else {
  10608. if ( arraysEqual( cache, elements ) ) { return; }
  10609. mat2array.set( elements );
  10610. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10611. copyArray( cache, elements );
  10612. }
  10613. }
  10614. function setValueM3( gl, v ) {
  10615. var cache = this.cache;
  10616. var elements = v.elements;
  10617. if ( elements === undefined ) {
  10618. if ( arraysEqual( cache, v ) ) { return; }
  10619. gl.uniformMatrix3fv( this.addr, false, v );
  10620. copyArray( cache, v );
  10621. } else {
  10622. if ( arraysEqual( cache, elements ) ) { return; }
  10623. mat3array.set( elements );
  10624. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10625. copyArray( cache, elements );
  10626. }
  10627. }
  10628. function setValueM4( gl, v ) {
  10629. var cache = this.cache;
  10630. var elements = v.elements;
  10631. if ( elements === undefined ) {
  10632. if ( arraysEqual( cache, v ) ) { return; }
  10633. gl.uniformMatrix4fv( this.addr, false, v );
  10634. copyArray( cache, v );
  10635. } else {
  10636. if ( arraysEqual( cache, elements ) ) { return; }
  10637. mat4array.set( elements );
  10638. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10639. copyArray( cache, elements );
  10640. }
  10641. }
  10642. // Single texture (2D / Cube)
  10643. function setValueT1( gl, v, textures ) {
  10644. var cache = this.cache;
  10645. var unit = textures.allocateTextureUnit();
  10646. if ( cache[ 0 ] !== unit ) {
  10647. gl.uniform1i( this.addr, unit );
  10648. cache[ 0 ] = unit;
  10649. }
  10650. textures.safeSetTexture2D( v || emptyTexture, unit );
  10651. }
  10652. function setValueT2DArray1( gl, v, textures ) {
  10653. var cache = this.cache;
  10654. var unit = textures.allocateTextureUnit();
  10655. if ( cache[ 0 ] !== unit ) {
  10656. gl.uniform1i( this.addr, unit );
  10657. cache[ 0 ] = unit;
  10658. }
  10659. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10660. }
  10661. function setValueT3D1( gl, v, textures ) {
  10662. var cache = this.cache;
  10663. var unit = textures.allocateTextureUnit();
  10664. if ( cache[ 0 ] !== unit ) {
  10665. gl.uniform1i( this.addr, unit );
  10666. cache[ 0 ] = unit;
  10667. }
  10668. textures.setTexture3D( v || emptyTexture3d, unit );
  10669. }
  10670. function setValueT6( gl, v, textures ) {
  10671. var cache = this.cache;
  10672. var unit = textures.allocateTextureUnit();
  10673. if ( cache[ 0 ] !== unit ) {
  10674. gl.uniform1i( this.addr, unit );
  10675. cache[ 0 ] = unit;
  10676. }
  10677. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10678. }
  10679. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10680. function setValueV1i( gl, v ) {
  10681. var cache = this.cache;
  10682. if ( cache[ 0 ] === v ) { return; }
  10683. gl.uniform1i( this.addr, v );
  10684. cache[ 0 ] = v;
  10685. }
  10686. function setValueV2i( gl, v ) {
  10687. var cache = this.cache;
  10688. if ( arraysEqual( cache, v ) ) { return; }
  10689. gl.uniform2iv( this.addr, v );
  10690. copyArray( cache, v );
  10691. }
  10692. function setValueV3i( gl, v ) {
  10693. var cache = this.cache;
  10694. if ( arraysEqual( cache, v ) ) { return; }
  10695. gl.uniform3iv( this.addr, v );
  10696. copyArray( cache, v );
  10697. }
  10698. function setValueV4i( gl, v ) {
  10699. var cache = this.cache;
  10700. if ( arraysEqual( cache, v ) ) { return; }
  10701. gl.uniform4iv( this.addr, v );
  10702. copyArray( cache, v );
  10703. }
  10704. // uint
  10705. function setValueV1ui( gl, v ) {
  10706. var cache = this.cache;
  10707. if ( cache[ 0 ] === v ) { return; }
  10708. gl.uniform1ui( this.addr, v );
  10709. cache[ 0 ] = v;
  10710. }
  10711. // Helper to pick the right setter for the singular case
  10712. function getSingularSetter( type ) {
  10713. switch ( type ) {
  10714. case 0x1406: return setValueV1f; // FLOAT
  10715. case 0x8b50: return setValueV2f; // _VEC2
  10716. case 0x8b51: return setValueV3f; // _VEC3
  10717. case 0x8b52: return setValueV4f; // _VEC4
  10718. case 0x8b5a: return setValueM2; // _MAT2
  10719. case 0x8b5b: return setValueM3; // _MAT3
  10720. case 0x8b5c: return setValueM4; // _MAT4
  10721. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10722. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10723. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10724. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10725. case 0x1405: return setValueV1ui; // UINT
  10726. case 0x8b5e: // SAMPLER_2D
  10727. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10728. case 0x8dca: // INT_SAMPLER_2D
  10729. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10730. case 0x8b62: // SAMPLER_2D_SHADOW
  10731. return setValueT1;
  10732. case 0x8b5f: // SAMPLER_3D
  10733. case 0x8dcb: // INT_SAMPLER_3D
  10734. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  10735. return setValueT3D1;
  10736. case 0x8b60: // SAMPLER_CUBE
  10737. case 0x8dcc: // INT_SAMPLER_CUBE
  10738. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10739. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10740. return setValueT6;
  10741. case 0x8dc1: // SAMPLER_2D_ARRAY
  10742. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10743. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10744. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  10745. return setValueT2DArray1;
  10746. }
  10747. }
  10748. // Array of scalars
  10749. function setValueV1fArray( gl, v ) {
  10750. gl.uniform1fv( this.addr, v );
  10751. }
  10752. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10753. function setValueV1iArray( gl, v ) {
  10754. gl.uniform1iv( this.addr, v );
  10755. }
  10756. function setValueV2iArray( gl, v ) {
  10757. gl.uniform2iv( this.addr, v );
  10758. }
  10759. function setValueV3iArray( gl, v ) {
  10760. gl.uniform3iv( this.addr, v );
  10761. }
  10762. function setValueV4iArray( gl, v ) {
  10763. gl.uniform4iv( this.addr, v );
  10764. }
  10765. // Array of vectors (flat or from THREE classes)
  10766. function setValueV2fArray( gl, v ) {
  10767. var data = flatten( v, this.size, 2 );
  10768. gl.uniform2fv( this.addr, data );
  10769. }
  10770. function setValueV3fArray( gl, v ) {
  10771. var data = flatten( v, this.size, 3 );
  10772. gl.uniform3fv( this.addr, data );
  10773. }
  10774. function setValueV4fArray( gl, v ) {
  10775. var data = flatten( v, this.size, 4 );
  10776. gl.uniform4fv( this.addr, data );
  10777. }
  10778. // Array of matrices (flat or from THREE clases)
  10779. function setValueM2Array( gl, v ) {
  10780. var data = flatten( v, this.size, 4 );
  10781. gl.uniformMatrix2fv( this.addr, false, data );
  10782. }
  10783. function setValueM3Array( gl, v ) {
  10784. var data = flatten( v, this.size, 9 );
  10785. gl.uniformMatrix3fv( this.addr, false, data );
  10786. }
  10787. function setValueM4Array( gl, v ) {
  10788. var data = flatten( v, this.size, 16 );
  10789. gl.uniformMatrix4fv( this.addr, false, data );
  10790. }
  10791. // Array of textures (2D / Cube)
  10792. function setValueT1Array( gl, v, textures ) {
  10793. var n = v.length;
  10794. var units = allocTexUnits( textures, n );
  10795. gl.uniform1iv( this.addr, units );
  10796. for ( var i = 0; i !== n; ++ i ) {
  10797. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10798. }
  10799. }
  10800. function setValueT6Array( gl, v, textures ) {
  10801. var n = v.length;
  10802. var units = allocTexUnits( textures, n );
  10803. gl.uniform1iv( this.addr, units );
  10804. for ( var i = 0; i !== n; ++ i ) {
  10805. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10806. }
  10807. }
  10808. // Helper to pick the right setter for a pure (bottom-level) array
  10809. function getPureArraySetter( type ) {
  10810. switch ( type ) {
  10811. case 0x1406: return setValueV1fArray; // FLOAT
  10812. case 0x8b50: return setValueV2fArray; // _VEC2
  10813. case 0x8b51: return setValueV3fArray; // _VEC3
  10814. case 0x8b52: return setValueV4fArray; // _VEC4
  10815. case 0x8b5a: return setValueM2Array; // _MAT2
  10816. case 0x8b5b: return setValueM3Array; // _MAT3
  10817. case 0x8b5c: return setValueM4Array; // _MAT4
  10818. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10819. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10820. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10821. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10822. case 0x8b5e: // SAMPLER_2D
  10823. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10824. case 0x8dca: // INT_SAMPLER_2D
  10825. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10826. case 0x8b62: // SAMPLER_2D_SHADOW
  10827. return setValueT1Array;
  10828. case 0x8b60: // SAMPLER_CUBE
  10829. case 0x8dcc: // INT_SAMPLER_CUBE
  10830. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10831. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10832. return setValueT6Array;
  10833. }
  10834. }
  10835. // --- Uniform Classes ---
  10836. function SingleUniform( id, activeInfo, addr ) {
  10837. this.id = id;
  10838. this.addr = addr;
  10839. this.cache = [];
  10840. this.setValue = getSingularSetter( activeInfo.type );
  10841. // this.path = activeInfo.name; // DEBUG
  10842. }
  10843. function PureArrayUniform( id, activeInfo, addr ) {
  10844. this.id = id;
  10845. this.addr = addr;
  10846. this.cache = [];
  10847. this.size = activeInfo.size;
  10848. this.setValue = getPureArraySetter( activeInfo.type );
  10849. // this.path = activeInfo.name; // DEBUG
  10850. }
  10851. PureArrayUniform.prototype.updateCache = function ( data ) {
  10852. var cache = this.cache;
  10853. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10854. this.cache = new Float32Array( data.length );
  10855. }
  10856. copyArray( cache, data );
  10857. };
  10858. function StructuredUniform( id ) {
  10859. this.id = id;
  10860. this.seq = [];
  10861. this.map = {};
  10862. }
  10863. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10864. var seq = this.seq;
  10865. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10866. var u = seq[ i ];
  10867. u.setValue( gl, value[ u.id ], textures );
  10868. }
  10869. };
  10870. // --- Top-level ---
  10871. // Parser - builds up the property tree from the path strings
  10872. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10873. // extracts
  10874. // - the identifier (member name or array index)
  10875. // - followed by an optional right bracket (found when array index)
  10876. // - followed by an optional left bracket or dot (type of subscript)
  10877. //
  10878. // Note: These portions can be read in a non-overlapping fashion and
  10879. // allow straightforward parsing of the hierarchy that WebGL encodes
  10880. // in the uniform names.
  10881. function addUniform( container, uniformObject ) {
  10882. container.seq.push( uniformObject );
  10883. container.map[ uniformObject.id ] = uniformObject;
  10884. }
  10885. function parseUniform( activeInfo, addr, container ) {
  10886. var path = activeInfo.name,
  10887. pathLength = path.length;
  10888. // reset RegExp object, because of the early exit of a previous run
  10889. RePathPart.lastIndex = 0;
  10890. while ( true ) {
  10891. var match = RePathPart.exec( path ),
  10892. matchEnd = RePathPart.lastIndex;
  10893. var id = match[ 1 ],
  10894. idIsIndex = match[ 2 ] === ']',
  10895. subscript = match[ 3 ];
  10896. if ( idIsIndex ) { id = id | 0; } // convert to integer
  10897. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10898. // bare name or "pure" bottom-level array "[0]" suffix
  10899. addUniform( container, subscript === undefined ?
  10900. new SingleUniform( id, activeInfo, addr ) :
  10901. new PureArrayUniform( id, activeInfo, addr ) );
  10902. break;
  10903. } else {
  10904. // step into inner node / create it in case it doesn't exist
  10905. var map = container.map;
  10906. var next = map[ id ];
  10907. if ( next === undefined ) {
  10908. next = new StructuredUniform( id );
  10909. addUniform( container, next );
  10910. }
  10911. container = next;
  10912. }
  10913. }
  10914. }
  10915. // Root Container
  10916. function WebGLUniforms( gl, program ) {
  10917. this.seq = [];
  10918. this.map = {};
  10919. var n = gl.getProgramParameter( program, 35718 );
  10920. for ( var i = 0; i < n; ++ i ) {
  10921. var info = gl.getActiveUniform( program, i ),
  10922. addr = gl.getUniformLocation( program, info.name );
  10923. parseUniform( info, addr, this );
  10924. }
  10925. }
  10926. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10927. var u = this.map[ name ];
  10928. if ( u !== undefined ) { u.setValue( gl, value, textures ); }
  10929. };
  10930. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10931. var v = object[ name ];
  10932. if ( v !== undefined ) { this.setValue( gl, name, v ); }
  10933. };
  10934. // Static interface
  10935. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10936. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10937. var u = seq[ i ],
  10938. v = values[ u.id ];
  10939. if ( v.needsUpdate !== false ) {
  10940. // note: always updating when .needsUpdate is undefined
  10941. u.setValue( gl, v.value, textures );
  10942. }
  10943. }
  10944. };
  10945. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10946. var r = [];
  10947. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10948. var u = seq[ i ];
  10949. if ( u.id in values ) { r.push( u ); }
  10950. }
  10951. return r;
  10952. };
  10953. /**
  10954. * @author mrdoob / http://mrdoob.com/
  10955. */
  10956. function WebGLShader( gl, type, string ) {
  10957. var shader = gl.createShader( type );
  10958. gl.shaderSource( shader, string );
  10959. gl.compileShader( shader );
  10960. return shader;
  10961. }
  10962. /**
  10963. * @author mrdoob / http://mrdoob.com/
  10964. */
  10965. var programIdCount = 0;
  10966. function addLineNumbers( string ) {
  10967. var lines = string.split( '\n' );
  10968. for ( var i = 0; i < lines.length; i ++ ) {
  10969. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10970. }
  10971. return lines.join( '\n' );
  10972. }
  10973. function getEncodingComponents( encoding ) {
  10974. switch ( encoding ) {
  10975. case LinearEncoding:
  10976. return [ 'Linear', '( value )' ];
  10977. case sRGBEncoding:
  10978. return [ 'sRGB', '( value )' ];
  10979. case RGBEEncoding:
  10980. return [ 'RGBE', '( value )' ];
  10981. case RGBM7Encoding:
  10982. return [ 'RGBM', '( value, 7.0 )' ];
  10983. case RGBM16Encoding:
  10984. return [ 'RGBM', '( value, 16.0 )' ];
  10985. case RGBDEncoding:
  10986. return [ 'RGBD', '( value, 256.0 )' ];
  10987. case GammaEncoding:
  10988. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10989. case LogLuvEncoding:
  10990. return [ 'LogLuv', '( value )' ];
  10991. default:
  10992. console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
  10993. return [ 'Linear', '( value )' ];
  10994. }
  10995. }
  10996. function getShaderErrors( gl, shader, type ) {
  10997. var status = gl.getShaderParameter( shader, 35713 );
  10998. var log = gl.getShaderInfoLog( shader ).trim();
  10999. if ( status && log === '' ) { return ''; }
  11000. // --enable-privileged-webgl-extension
  11001. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11002. var source = gl.getShaderSource( shader );
  11003. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  11004. }
  11005. function getTexelDecodingFunction( functionName, encoding ) {
  11006. var components = getEncodingComponents( encoding );
  11007. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  11008. }
  11009. function getTexelEncodingFunction( functionName, encoding ) {
  11010. var components = getEncodingComponents( encoding );
  11011. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  11012. }
  11013. function getToneMappingFunction( functionName, toneMapping ) {
  11014. var toneMappingName;
  11015. switch ( toneMapping ) {
  11016. case LinearToneMapping:
  11017. toneMappingName = 'Linear';
  11018. break;
  11019. case ReinhardToneMapping:
  11020. toneMappingName = 'Reinhard';
  11021. break;
  11022. case CineonToneMapping:
  11023. toneMappingName = 'OptimizedCineon';
  11024. break;
  11025. case ACESFilmicToneMapping:
  11026. toneMappingName = 'ACESFilmic';
  11027. break;
  11028. case CustomToneMapping:
  11029. toneMappingName = 'Custom';
  11030. break;
  11031. default:
  11032. console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping );
  11033. toneMappingName = 'Linear';
  11034. }
  11035. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11036. }
  11037. function generateExtensions( parameters ) {
  11038. var chunks = [
  11039. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  11040. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  11041. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  11042. ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  11043. ];
  11044. return chunks.filter( filterEmptyLine ).join( '\n' );
  11045. }
  11046. function generateDefines( defines ) {
  11047. var chunks = [];
  11048. for ( var name in defines ) {
  11049. var value = defines[ name ];
  11050. if ( value === false ) { continue; }
  11051. chunks.push( '#define ' + name + ' ' + value );
  11052. }
  11053. return chunks.join( '\n' );
  11054. }
  11055. function fetchAttributeLocations( gl, program ) {
  11056. var attributes = {};
  11057. var n = gl.getProgramParameter( program, 35721 );
  11058. for ( var i = 0; i < n; i ++ ) {
  11059. var info = gl.getActiveAttrib( program, i );
  11060. var name = info.name;
  11061. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11062. attributes[ name ] = gl.getAttribLocation( program, name );
  11063. }
  11064. return attributes;
  11065. }
  11066. function filterEmptyLine( string ) {
  11067. return string !== '';
  11068. }
  11069. function replaceLightNums( string, parameters ) {
  11070. return string
  11071. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  11072. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  11073. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  11074. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  11075. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  11076. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  11077. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  11078. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  11079. }
  11080. function replaceClippingPlaneNums( string, parameters ) {
  11081. return string
  11082. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  11083. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  11084. }
  11085. // Resolve Includes
  11086. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11087. function resolveIncludes( string ) {
  11088. return string.replace( includePattern, includeReplacer );
  11089. }
  11090. function includeReplacer( match, include ) {
  11091. var string = ShaderChunk[ include ];
  11092. if ( string === undefined ) {
  11093. throw new Error( 'Can not resolve #include <' + include + '>' );
  11094. }
  11095. return resolveIncludes( string );
  11096. }
  11097. // Unroll Loops
  11098. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11099. var unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;
  11100. function unrollLoops( string ) {
  11101. return string
  11102. .replace( unrollLoopPattern, loopReplacer )
  11103. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  11104. }
  11105. function deprecatedLoopReplacer( match, start, end, snippet ) {
  11106. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  11107. return loopReplacer( match, start, end, snippet );
  11108. }
  11109. function loopReplacer( match, start, end, snippet ) {
  11110. var string = '';
  11111. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  11112. string += snippet
  11113. .replace( /\[ i \]/g, '[ ' + i + ' ]' )
  11114. .replace( /UNROLLED_LOOP_INDEX/g, i );
  11115. }
  11116. return string;
  11117. }
  11118. //
  11119. function generatePrecision( parameters ) {
  11120. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  11121. if ( parameters.precision === "highp" ) {
  11122. precisionstring += "\n#define HIGH_PRECISION";
  11123. } else if ( parameters.precision === "mediump" ) {
  11124. precisionstring += "\n#define MEDIUM_PRECISION";
  11125. } else if ( parameters.precision === "lowp" ) {
  11126. precisionstring += "\n#define LOW_PRECISION";
  11127. }
  11128. return precisionstring;
  11129. }
  11130. function generateShadowMapTypeDefine( parameters ) {
  11131. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11132. if ( parameters.shadowMapType === PCFShadowMap ) {
  11133. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11134. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  11135. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11136. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  11137. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11138. }
  11139. return shadowMapTypeDefine;
  11140. }
  11141. function generateEnvMapTypeDefine( parameters ) {
  11142. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11143. if ( parameters.envMap ) {
  11144. switch ( parameters.envMapMode ) {
  11145. case CubeReflectionMapping:
  11146. case CubeRefractionMapping:
  11147. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11148. break;
  11149. case CubeUVReflectionMapping:
  11150. case CubeUVRefractionMapping:
  11151. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11152. break;
  11153. case EquirectangularReflectionMapping:
  11154. case EquirectangularRefractionMapping:
  11155. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  11156. break;
  11157. }
  11158. }
  11159. return envMapTypeDefine;
  11160. }
  11161. function generateEnvMapModeDefine( parameters ) {
  11162. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11163. if ( parameters.envMap ) {
  11164. switch ( parameters.envMapMode ) {
  11165. case CubeRefractionMapping:
  11166. case EquirectangularRefractionMapping:
  11167. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11168. break;
  11169. }
  11170. }
  11171. return envMapModeDefine;
  11172. }
  11173. function generateEnvMapBlendingDefine( parameters ) {
  11174. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11175. if ( parameters.envMap ) {
  11176. switch ( parameters.combine ) {
  11177. case MultiplyOperation:
  11178. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11179. break;
  11180. case MixOperation:
  11181. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11182. break;
  11183. case AddOperation:
  11184. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11185. break;
  11186. }
  11187. }
  11188. return envMapBlendingDefine;
  11189. }
  11190. function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
  11191. var gl = renderer.getContext();
  11192. var defines = parameters.defines;
  11193. var vertexShader = parameters.vertexShader;
  11194. var fragmentShader = parameters.fragmentShader;
  11195. var shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  11196. var envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  11197. var envMapModeDefine = generateEnvMapModeDefine( parameters );
  11198. var envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  11199. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  11200. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  11201. var customDefines = generateDefines( defines );
  11202. var program = gl.createProgram();
  11203. var prefixVertex, prefixFragment;
  11204. if ( parameters.isRawShaderMaterial ) {
  11205. prefixVertex = [
  11206. customDefines
  11207. ].filter( filterEmptyLine ).join( '\n' );
  11208. if ( prefixVertex.length > 0 ) {
  11209. prefixVertex += '\n';
  11210. }
  11211. prefixFragment = [
  11212. customExtensions,
  11213. customDefines
  11214. ].filter( filterEmptyLine ).join( '\n' );
  11215. if ( prefixFragment.length > 0 ) {
  11216. prefixFragment += '\n';
  11217. }
  11218. } else {
  11219. prefixVertex = [
  11220. generatePrecision( parameters ),
  11221. '#define SHADER_NAME ' + parameters.shaderName,
  11222. customDefines,
  11223. parameters.instancing ? '#define USE_INSTANCING' : '',
  11224. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  11225. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11226. '#define MAX_BONES ' + parameters.maxBones,
  11227. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11228. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  11229. parameters.map ? '#define USE_MAP' : '',
  11230. parameters.envMap ? '#define USE_ENVMAP' : '',
  11231. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11232. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11233. parameters.aoMap ? '#define USE_AOMAP' : '',
  11234. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11235. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11236. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11237. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11238. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  11239. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  11240. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  11241. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11242. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  11243. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11244. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11245. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11246. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11247. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11248. parameters.vertexColors ? '#define USE_COLOR' : '',
  11249. parameters.vertexUvs ? '#define USE_UV' : '',
  11250. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  11251. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11252. parameters.skinning ? '#define USE_SKINNING' : '',
  11253. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  11254. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  11255. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  11256. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11257. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11258. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11259. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11260. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  11261. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11262. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11263. 'uniform mat4 modelMatrix;',
  11264. 'uniform mat4 modelViewMatrix;',
  11265. 'uniform mat4 projectionMatrix;',
  11266. 'uniform mat4 viewMatrix;',
  11267. 'uniform mat3 normalMatrix;',
  11268. 'uniform vec3 cameraPosition;',
  11269. 'uniform bool isOrthographic;',
  11270. '#ifdef USE_INSTANCING',
  11271. ' attribute mat4 instanceMatrix;',
  11272. '#endif',
  11273. 'attribute vec3 position;',
  11274. 'attribute vec3 normal;',
  11275. 'attribute vec2 uv;',
  11276. '#ifdef USE_TANGENT',
  11277. ' attribute vec4 tangent;',
  11278. '#endif',
  11279. '#ifdef USE_COLOR',
  11280. ' attribute vec3 color;',
  11281. '#endif',
  11282. '#ifdef USE_MORPHTARGETS',
  11283. ' attribute vec3 morphTarget0;',
  11284. ' attribute vec3 morphTarget1;',
  11285. ' attribute vec3 morphTarget2;',
  11286. ' attribute vec3 morphTarget3;',
  11287. ' #ifdef USE_MORPHNORMALS',
  11288. ' attribute vec3 morphNormal0;',
  11289. ' attribute vec3 morphNormal1;',
  11290. ' attribute vec3 morphNormal2;',
  11291. ' attribute vec3 morphNormal3;',
  11292. ' #else',
  11293. ' attribute vec3 morphTarget4;',
  11294. ' attribute vec3 morphTarget5;',
  11295. ' attribute vec3 morphTarget6;',
  11296. ' attribute vec3 morphTarget7;',
  11297. ' #endif',
  11298. '#endif',
  11299. '#ifdef USE_SKINNING',
  11300. ' attribute vec4 skinIndex;',
  11301. ' attribute vec4 skinWeight;',
  11302. '#endif',
  11303. '\n'
  11304. ].filter( filterEmptyLine ).join( '\n' );
  11305. prefixFragment = [
  11306. customExtensions,
  11307. generatePrecision( parameters ),
  11308. '#define SHADER_NAME ' + parameters.shaderName,
  11309. customDefines,
  11310. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  11311. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11312. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11313. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  11314. parameters.map ? '#define USE_MAP' : '',
  11315. parameters.matcap ? '#define USE_MATCAP' : '',
  11316. parameters.envMap ? '#define USE_ENVMAP' : '',
  11317. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  11318. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11319. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  11320. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11321. parameters.aoMap ? '#define USE_AOMAP' : '',
  11322. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11323. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11324. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11325. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11326. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  11327. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  11328. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  11329. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11330. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11331. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11332. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11333. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11334. parameters.sheen ? '#define USE_SHEEN' : '',
  11335. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11336. parameters.vertexColors ? '#define USE_COLOR' : '',
  11337. parameters.vertexUvs ? '#define USE_UV' : '',
  11338. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  11339. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  11340. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11341. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11342. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11343. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11344. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11345. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  11346. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  11347. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11348. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11349. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  11350. 'uniform mat4 viewMatrix;',
  11351. 'uniform vec3 cameraPosition;',
  11352. 'uniform bool isOrthographic;',
  11353. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  11354. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  11355. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  11356. parameters.dithering ? '#define DITHERING' : '',
  11357. ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
  11358. parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  11359. parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  11360. parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  11361. parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  11362. parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  11363. getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
  11364. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  11365. '\n'
  11366. ].filter( filterEmptyLine ).join( '\n' );
  11367. }
  11368. vertexShader = resolveIncludes( vertexShader );
  11369. vertexShader = replaceLightNums( vertexShader, parameters );
  11370. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  11371. fragmentShader = resolveIncludes( fragmentShader );
  11372. fragmentShader = replaceLightNums( fragmentShader, parameters );
  11373. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  11374. vertexShader = unrollLoops( vertexShader );
  11375. fragmentShader = unrollLoops( fragmentShader );
  11376. if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) {
  11377. var isGLSL3ShaderMaterial = false;
  11378. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  11379. if ( parameters.isShaderMaterial &&
  11380. vertexShader.match( versionRegex ) !== null &&
  11381. fragmentShader.match( versionRegex ) !== null ) {
  11382. isGLSL3ShaderMaterial = true;
  11383. vertexShader = vertexShader.replace( versionRegex, '' );
  11384. fragmentShader = fragmentShader.replace( versionRegex, '' );
  11385. }
  11386. // GLSL 3.0 conversion
  11387. prefixVertex = [
  11388. '#version 300 es\n',
  11389. '#define attribute in',
  11390. '#define varying out',
  11391. '#define texture2D texture'
  11392. ].join( '\n' ) + '\n' + prefixVertex;
  11393. prefixFragment = [
  11394. '#version 300 es\n',
  11395. '#define varying in',
  11396. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  11397. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  11398. '#define gl_FragDepthEXT gl_FragDepth',
  11399. '#define texture2D texture',
  11400. '#define textureCube texture',
  11401. '#define texture2DProj textureProj',
  11402. '#define texture2DLodEXT textureLod',
  11403. '#define texture2DProjLodEXT textureProjLod',
  11404. '#define textureCubeLodEXT textureLod',
  11405. '#define texture2DGradEXT textureGrad',
  11406. '#define texture2DProjGradEXT textureProjGrad',
  11407. '#define textureCubeGradEXT textureGrad'
  11408. ].join( '\n' ) + '\n' + prefixFragment;
  11409. }
  11410. var vertexGlsl = prefixVertex + vertexShader;
  11411. var fragmentGlsl = prefixFragment + fragmentShader;
  11412. // console.log( '*VERTEX*', vertexGlsl );
  11413. // console.log( '*FRAGMENT*', fragmentGlsl );
  11414. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  11415. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  11416. gl.attachShader( program, glVertexShader );
  11417. gl.attachShader( program, glFragmentShader );
  11418. // Force a particular attribute to index 0.
  11419. if ( parameters.index0AttributeName !== undefined ) {
  11420. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  11421. } else if ( parameters.morphTargets === true ) {
  11422. // programs with morphTargets displace position out of attribute 0
  11423. gl.bindAttribLocation( program, 0, 'position' );
  11424. }
  11425. gl.linkProgram( program );
  11426. // check for link errors
  11427. if ( renderer.debug.checkShaderErrors ) {
  11428. var programLog = gl.getProgramInfoLog( program ).trim();
  11429. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  11430. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  11431. var runnable = true;
  11432. var haveDiagnostics = true;
  11433. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  11434. runnable = false;
  11435. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  11436. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  11437. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  11438. } else if ( programLog !== '' ) {
  11439. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  11440. } else if ( vertexLog === '' || fragmentLog === '' ) {
  11441. haveDiagnostics = false;
  11442. }
  11443. if ( haveDiagnostics ) {
  11444. this.diagnostics = {
  11445. runnable: runnable,
  11446. programLog: programLog,
  11447. vertexShader: {
  11448. log: vertexLog,
  11449. prefix: prefixVertex
  11450. },
  11451. fragmentShader: {
  11452. log: fragmentLog,
  11453. prefix: prefixFragment
  11454. }
  11455. };
  11456. }
  11457. }
  11458. // Clean up
  11459. // Crashes in iOS9 and iOS10. #18402
  11460. // gl.detachShader( program, glVertexShader );
  11461. // gl.detachShader( program, glFragmentShader );
  11462. gl.deleteShader( glVertexShader );
  11463. gl.deleteShader( glFragmentShader );
  11464. // set up caching for uniform locations
  11465. var cachedUniforms;
  11466. this.getUniforms = function () {
  11467. if ( cachedUniforms === undefined ) {
  11468. cachedUniforms = new WebGLUniforms( gl, program );
  11469. }
  11470. return cachedUniforms;
  11471. };
  11472. // set up caching for attribute locations
  11473. var cachedAttributes;
  11474. this.getAttributes = function () {
  11475. if ( cachedAttributes === undefined ) {
  11476. cachedAttributes = fetchAttributeLocations( gl, program );
  11477. }
  11478. return cachedAttributes;
  11479. };
  11480. // free resource
  11481. this.destroy = function () {
  11482. bindingStates.releaseStatesOfProgram( this );
  11483. gl.deleteProgram( program );
  11484. this.program = undefined;
  11485. };
  11486. //
  11487. this.name = parameters.shaderName;
  11488. this.id = programIdCount ++;
  11489. this.cacheKey = cacheKey;
  11490. this.usedTimes = 1;
  11491. this.program = program;
  11492. this.vertexShader = glVertexShader;
  11493. this.fragmentShader = glFragmentShader;
  11494. return this;
  11495. }
  11496. /**
  11497. * @author mrdoob / http://mrdoob.com/
  11498. */
  11499. function WebGLPrograms( renderer, extensions, capabilities, bindingStates ) {
  11500. var programs = [];
  11501. var isWebGL2 = capabilities.isWebGL2;
  11502. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11503. var floatVertexTextures = capabilities.floatVertexTextures;
  11504. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11505. var vertexTextures = capabilities.vertexTextures;
  11506. var precision = capabilities.precision;
  11507. var shaderIDs = {
  11508. MeshDepthMaterial: 'depth',
  11509. MeshDistanceMaterial: 'distanceRGBA',
  11510. MeshNormalMaterial: 'normal',
  11511. MeshBasicMaterial: 'basic',
  11512. MeshLambertMaterial: 'lambert',
  11513. MeshPhongMaterial: 'phong',
  11514. MeshToonMaterial: 'toon',
  11515. MeshStandardMaterial: 'physical',
  11516. MeshPhysicalMaterial: 'physical',
  11517. MeshMatcapMaterial: 'matcap',
  11518. LineBasicMaterial: 'basic',
  11519. LineDashedMaterial: 'dashed',
  11520. PointsMaterial: 'points',
  11521. ShadowMaterial: 'shadow',
  11522. SpriteMaterial: 'sprite'
  11523. };
  11524. var parameterNames = [
  11525. "precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing",
  11526. "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV",
  11527. "lightMap", "lightMapEncoding", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatMap", "clearcoatRoughnessMap", "clearcoatNormalMap", "displacementMap", "specularMap",
  11528. "roughnessMap", "metalnessMap", "gradientMap",
  11529. "alphaMap", "combine", "vertexColors", "vertexTangents", "vertexUvs", "uvsVertexOnly", "fog", "useFog", "fogExp2",
  11530. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  11531. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  11532. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  11533. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  11534. "numDirLightShadows", "numPointLightShadows", "numSpotLightShadows",
  11535. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  11536. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering",
  11537. "sheen"
  11538. ];
  11539. function getShaderObject( material, shaderID ) {
  11540. var shaderobject;
  11541. if ( shaderID ) {
  11542. var shader = ShaderLib[ shaderID ];
  11543. shaderobject = {
  11544. name: material.name || material.type,
  11545. uniforms: UniformsUtils.clone( shader.uniforms ),
  11546. vertexShader: shader.vertexShader,
  11547. fragmentShader: shader.fragmentShader
  11548. };
  11549. } else {
  11550. shaderobject = {
  11551. name: material.name || material.type,
  11552. uniforms: material.uniforms,
  11553. vertexShader: material.vertexShader,
  11554. fragmentShader: material.fragmentShader
  11555. };
  11556. }
  11557. return shaderobject;
  11558. }
  11559. function allocateBones( object ) {
  11560. var skeleton = object.skeleton;
  11561. var bones = skeleton.bones;
  11562. if ( floatVertexTextures ) {
  11563. return 1024;
  11564. } else {
  11565. // default for when object is not specified
  11566. // ( for example when prebuilding shader to be used with multiple objects )
  11567. //
  11568. // - leave some extra space for other uniforms
  11569. // - limit here is ANGLE's 254 max uniform vectors
  11570. // (up to 54 should be safe)
  11571. var nVertexUniforms = maxVertexUniforms;
  11572. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  11573. var maxBones = Math.min( nVertexMatrices, bones.length );
  11574. if ( maxBones < bones.length ) {
  11575. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  11576. return 0;
  11577. }
  11578. return maxBones;
  11579. }
  11580. }
  11581. function getTextureEncodingFromMap( map ) {
  11582. var encoding;
  11583. if ( ! map ) {
  11584. encoding = LinearEncoding;
  11585. } else if ( map.isTexture ) {
  11586. encoding = map.encoding;
  11587. } else if ( map.isWebGLRenderTarget ) {
  11588. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  11589. encoding = map.texture.encoding;
  11590. }
  11591. return encoding;
  11592. }
  11593. function getParameters( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) {
  11594. var fog = scene.fog;
  11595. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11596. var envMap = material.envMap || environment;
  11597. var shaderID = shaderIDs[ material.type ];
  11598. // heuristics to create shader parameters according to lights in the scene
  11599. // (not to blow over maxLights budget)
  11600. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  11601. if ( material.precision !== null ) {
  11602. precision = capabilities.getMaxPrecision( material.precision );
  11603. if ( precision !== material.precision ) {
  11604. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11605. }
  11606. }
  11607. var shaderobject = getShaderObject( material, shaderID );
  11608. material.onBeforeCompile( shaderobject, renderer );
  11609. var currentRenderTarget = renderer.getRenderTarget();
  11610. var parameters = {
  11611. isWebGL2: isWebGL2,
  11612. shaderID: shaderID,
  11613. shaderName: shaderobject.name,
  11614. uniforms: shaderobject.uniforms,
  11615. vertexShader: shaderobject.vertexShader,
  11616. fragmentShader: shaderobject.fragmentShader,
  11617. defines: material.defines,
  11618. isRawShaderMaterial: material.isRawShaderMaterial,
  11619. isShaderMaterial: material.isShaderMaterial,
  11620. precision: precision,
  11621. instancing: object.isInstancedMesh === true,
  11622. supportsVertexTextures: vertexTextures,
  11623. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  11624. map: !! material.map,
  11625. mapEncoding: getTextureEncodingFromMap( material.map ),
  11626. matcap: !! material.matcap,
  11627. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  11628. envMap: !! envMap,
  11629. envMapMode: envMap && envMap.mapping,
  11630. envMapEncoding: getTextureEncodingFromMap( envMap ),
  11631. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  11632. lightMap: !! material.lightMap,
  11633. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  11634. aoMap: !! material.aoMap,
  11635. emissiveMap: !! material.emissiveMap,
  11636. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  11637. bumpMap: !! material.bumpMap,
  11638. normalMap: !! material.normalMap,
  11639. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11640. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11641. clearcoatMap: !! material.clearcoatMap,
  11642. clearcoatRoughnessMap: !! material.clearcoatRoughnessMap,
  11643. clearcoatNormalMap: !! material.clearcoatNormalMap,
  11644. displacementMap: !! material.displacementMap,
  11645. roughnessMap: !! material.roughnessMap,
  11646. metalnessMap: !! material.metalnessMap,
  11647. specularMap: !! material.specularMap,
  11648. alphaMap: !! material.alphaMap,
  11649. gradientMap: !! material.gradientMap,
  11650. sheen: !! material.sheen,
  11651. combine: material.combine,
  11652. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11653. vertexColors: material.vertexColors,
  11654. 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,
  11655. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap ) && !! material.displacementMap,
  11656. fog: !! fog,
  11657. useFog: material.fog,
  11658. fogExp2: ( fog && fog.isFogExp2 ),
  11659. flatShading: material.flatShading,
  11660. sizeAttenuation: material.sizeAttenuation,
  11661. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11662. skinning: material.skinning && maxBones > 0,
  11663. maxBones: maxBones,
  11664. useVertexTexture: floatVertexTextures,
  11665. morphTargets: material.morphTargets,
  11666. morphNormals: material.morphNormals,
  11667. maxMorphTargets: renderer.maxMorphTargets,
  11668. maxMorphNormals: renderer.maxMorphNormals,
  11669. numDirLights: lights.directional.length,
  11670. numPointLights: lights.point.length,
  11671. numSpotLights: lights.spot.length,
  11672. numRectAreaLights: lights.rectArea.length,
  11673. numHemiLights: lights.hemi.length,
  11674. numDirLightShadows: lights.directionalShadowMap.length,
  11675. numPointLightShadows: lights.pointShadowMap.length,
  11676. numSpotLightShadows: lights.spotShadowMap.length,
  11677. numClippingPlanes: nClipPlanes,
  11678. numClipIntersection: nClipIntersection,
  11679. dithering: material.dithering,
  11680. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11681. shadowMapType: renderer.shadowMap.type,
  11682. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11683. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11684. premultipliedAlpha: material.premultipliedAlpha,
  11685. alphaTest: material.alphaTest,
  11686. doubleSided: material.side === DoubleSide,
  11687. flipSided: material.side === BackSide,
  11688. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  11689. index0AttributeName: material.index0AttributeName,
  11690. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11691. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11692. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11693. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11694. rendererExtensionFragDepth: isWebGL2 || extensions.get( 'EXT_frag_depth' ) !== null,
  11695. rendererExtensionDrawBuffers: isWebGL2 || extensions.get( 'WEBGL_draw_buffers' ) !== null,
  11696. rendererExtensionShaderTextureLod: isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) !== null,
  11697. customProgramCacheKey: material.customProgramCacheKey()
  11698. };
  11699. return parameters;
  11700. }
  11701. function getProgramCacheKey( parameters ) {
  11702. var array = [];
  11703. if ( parameters.shaderID ) {
  11704. array.push( parameters.shaderID );
  11705. } else {
  11706. array.push( parameters.fragmentShader );
  11707. array.push( parameters.vertexShader );
  11708. }
  11709. if ( parameters.defines !== undefined ) {
  11710. for ( var name in parameters.defines ) {
  11711. array.push( name );
  11712. array.push( parameters.defines[ name ] );
  11713. }
  11714. }
  11715. if ( parameters.isRawShaderMaterial === undefined ) {
  11716. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11717. array.push( parameters[ parameterNames[ i ] ] );
  11718. }
  11719. array.push( renderer.outputEncoding );
  11720. array.push( renderer.gammaFactor );
  11721. }
  11722. array.push( parameters.customProgramCacheKey );
  11723. return array.join();
  11724. }
  11725. function acquireProgram( parameters, cacheKey ) {
  11726. var program;
  11727. // Check if code has been already compiled
  11728. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11729. var preexistingProgram = programs[ p ];
  11730. if ( preexistingProgram.cacheKey === cacheKey ) {
  11731. program = preexistingProgram;
  11732. ++ program.usedTimes;
  11733. break;
  11734. }
  11735. }
  11736. if ( program === undefined ) {
  11737. program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
  11738. programs.push( program );
  11739. }
  11740. return program;
  11741. }
  11742. function releaseProgram( program ) {
  11743. if ( -- program.usedTimes === 0 ) {
  11744. // Remove from unordered set
  11745. var i = programs.indexOf( program );
  11746. programs[ i ] = programs[ programs.length - 1 ];
  11747. programs.pop();
  11748. // Free WebGL resources
  11749. program.destroy();
  11750. }
  11751. }
  11752. return {
  11753. getParameters: getParameters,
  11754. getProgramCacheKey: getProgramCacheKey,
  11755. acquireProgram: acquireProgram,
  11756. releaseProgram: releaseProgram,
  11757. // Exposed for resource monitoring & error feedback via renderer.info:
  11758. programs: programs
  11759. };
  11760. }
  11761. /**
  11762. * @author fordacious / fordacious.github.io
  11763. */
  11764. function WebGLProperties() {
  11765. var properties = new WeakMap();
  11766. function get( object ) {
  11767. var map = properties.get( object );
  11768. if ( map === undefined ) {
  11769. map = {};
  11770. properties.set( object, map );
  11771. }
  11772. return map;
  11773. }
  11774. function remove( object ) {
  11775. properties.delete( object );
  11776. }
  11777. function update( object, key, value ) {
  11778. properties.get( object )[ key ] = value;
  11779. }
  11780. function dispose() {
  11781. properties = new WeakMap();
  11782. }
  11783. return {
  11784. get: get,
  11785. remove: remove,
  11786. update: update,
  11787. dispose: dispose
  11788. };
  11789. }
  11790. /**
  11791. * @author mrdoob / http://mrdoob.com/
  11792. */
  11793. function painterSortStable( a, b ) {
  11794. if ( a.groupOrder !== b.groupOrder ) {
  11795. return a.groupOrder - b.groupOrder;
  11796. } else if ( a.renderOrder !== b.renderOrder ) {
  11797. return a.renderOrder - b.renderOrder;
  11798. } else if ( a.program !== b.program ) {
  11799. return a.program.id - b.program.id;
  11800. } else if ( a.material.id !== b.material.id ) {
  11801. return a.material.id - b.material.id;
  11802. } else if ( a.z !== b.z ) {
  11803. return a.z - b.z;
  11804. } else {
  11805. return a.id - b.id;
  11806. }
  11807. }
  11808. function reversePainterSortStable( a, b ) {
  11809. if ( a.groupOrder !== b.groupOrder ) {
  11810. return a.groupOrder - b.groupOrder;
  11811. } else if ( a.renderOrder !== b.renderOrder ) {
  11812. return a.renderOrder - b.renderOrder;
  11813. } else if ( a.z !== b.z ) {
  11814. return b.z - a.z;
  11815. } else {
  11816. return a.id - b.id;
  11817. }
  11818. }
  11819. function WebGLRenderList() {
  11820. var renderItems = [];
  11821. var renderItemsIndex = 0;
  11822. var opaque = [];
  11823. var transparent = [];
  11824. var defaultProgram = { id: - 1 };
  11825. function init() {
  11826. renderItemsIndex = 0;
  11827. opaque.length = 0;
  11828. transparent.length = 0;
  11829. }
  11830. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11831. var renderItem = renderItems[ renderItemsIndex ];
  11832. if ( renderItem === undefined ) {
  11833. renderItem = {
  11834. id: object.id,
  11835. object: object,
  11836. geometry: geometry,
  11837. material: material,
  11838. program: material.program || defaultProgram,
  11839. groupOrder: groupOrder,
  11840. renderOrder: object.renderOrder,
  11841. z: z,
  11842. group: group
  11843. };
  11844. renderItems[ renderItemsIndex ] = renderItem;
  11845. } else {
  11846. renderItem.id = object.id;
  11847. renderItem.object = object;
  11848. renderItem.geometry = geometry;
  11849. renderItem.material = material;
  11850. renderItem.program = material.program || defaultProgram;
  11851. renderItem.groupOrder = groupOrder;
  11852. renderItem.renderOrder = object.renderOrder;
  11853. renderItem.z = z;
  11854. renderItem.group = group;
  11855. }
  11856. renderItemsIndex ++;
  11857. return renderItem;
  11858. }
  11859. function push( object, geometry, material, groupOrder, z, group ) {
  11860. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11861. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11862. }
  11863. function unshift( object, geometry, material, groupOrder, z, group ) {
  11864. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11865. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11866. }
  11867. function sort( customOpaqueSort, customTransparentSort ) {
  11868. if ( opaque.length > 1 ) { opaque.sort( customOpaqueSort || painterSortStable ); }
  11869. if ( transparent.length > 1 ) { transparent.sort( customTransparentSort || reversePainterSortStable ); }
  11870. }
  11871. function finish() {
  11872. // Clear references from inactive renderItems in the list
  11873. for ( var i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  11874. var renderItem = renderItems[ i ];
  11875. if ( renderItem.id === null ) { break; }
  11876. renderItem.id = null;
  11877. renderItem.object = null;
  11878. renderItem.geometry = null;
  11879. renderItem.material = null;
  11880. renderItem.program = null;
  11881. renderItem.group = null;
  11882. }
  11883. }
  11884. return {
  11885. opaque: opaque,
  11886. transparent: transparent,
  11887. init: init,
  11888. push: push,
  11889. unshift: unshift,
  11890. finish: finish,
  11891. sort: sort
  11892. };
  11893. }
  11894. function WebGLRenderLists() {
  11895. var lists = new WeakMap();
  11896. function onSceneDispose( event ) {
  11897. var scene = event.target;
  11898. scene.removeEventListener( 'dispose', onSceneDispose );
  11899. lists.delete( scene );
  11900. }
  11901. function get( scene, camera ) {
  11902. var cameras = lists.get( scene );
  11903. var list;
  11904. if ( cameras === undefined ) {
  11905. list = new WebGLRenderList();
  11906. lists.set( scene, new WeakMap() );
  11907. lists.get( scene ).set( camera, list );
  11908. scene.addEventListener( 'dispose', onSceneDispose );
  11909. } else {
  11910. list = cameras.get( camera );
  11911. if ( list === undefined ) {
  11912. list = new WebGLRenderList();
  11913. cameras.set( camera, list );
  11914. }
  11915. }
  11916. return list;
  11917. }
  11918. function dispose() {
  11919. lists = new WeakMap();
  11920. }
  11921. return {
  11922. get: get,
  11923. dispose: dispose
  11924. };
  11925. }
  11926. /**
  11927. * @author mrdoob / http://mrdoob.com/
  11928. */
  11929. function UniformsCache() {
  11930. var lights = {};
  11931. return {
  11932. get: function ( light ) {
  11933. if ( lights[ light.id ] !== undefined ) {
  11934. return lights[ light.id ];
  11935. }
  11936. var uniforms;
  11937. switch ( light.type ) {
  11938. case 'DirectionalLight':
  11939. uniforms = {
  11940. direction: new Vector3(),
  11941. color: new Color()
  11942. };
  11943. break;
  11944. case 'SpotLight':
  11945. uniforms = {
  11946. position: new Vector3(),
  11947. direction: new Vector3(),
  11948. color: new Color(),
  11949. distance: 0,
  11950. coneCos: 0,
  11951. penumbraCos: 0,
  11952. decay: 0
  11953. };
  11954. break;
  11955. case 'PointLight':
  11956. uniforms = {
  11957. position: new Vector3(),
  11958. color: new Color(),
  11959. distance: 0,
  11960. decay: 0
  11961. };
  11962. break;
  11963. case 'HemisphereLight':
  11964. uniforms = {
  11965. direction: new Vector3(),
  11966. skyColor: new Color(),
  11967. groundColor: new Color()
  11968. };
  11969. break;
  11970. case 'RectAreaLight':
  11971. uniforms = {
  11972. color: new Color(),
  11973. position: new Vector3(),
  11974. halfWidth: new Vector3(),
  11975. halfHeight: new Vector3()
  11976. };
  11977. break;
  11978. }
  11979. lights[ light.id ] = uniforms;
  11980. return uniforms;
  11981. }
  11982. };
  11983. }
  11984. function ShadowUniformsCache() {
  11985. var lights = {};
  11986. return {
  11987. get: function ( light ) {
  11988. if ( lights[ light.id ] !== undefined ) {
  11989. return lights[ light.id ];
  11990. }
  11991. var uniforms;
  11992. switch ( light.type ) {
  11993. case 'DirectionalLight':
  11994. uniforms = {
  11995. shadowBias: 0,
  11996. shadowNormalBias: 0,
  11997. shadowRadius: 1,
  11998. shadowMapSize: new Vector2()
  11999. };
  12000. break;
  12001. case 'SpotLight':
  12002. uniforms = {
  12003. shadowBias: 0,
  12004. shadowNormalBias: 0,
  12005. shadowRadius: 1,
  12006. shadowMapSize: new Vector2()
  12007. };
  12008. break;
  12009. case 'PointLight':
  12010. uniforms = {
  12011. shadowBias: 0,
  12012. shadowNormalBias: 0,
  12013. shadowRadius: 1,
  12014. shadowMapSize: new Vector2(),
  12015. shadowCameraNear: 1,
  12016. shadowCameraFar: 1000
  12017. };
  12018. break;
  12019. // TODO (abelnation): set RectAreaLight shadow uniforms
  12020. }
  12021. lights[ light.id ] = uniforms;
  12022. return uniforms;
  12023. }
  12024. };
  12025. }
  12026. var nextVersion = 0;
  12027. function shadowCastingLightsFirst( lightA, lightB ) {
  12028. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  12029. }
  12030. function WebGLLights() {
  12031. var cache = new UniformsCache();
  12032. var shadowCache = ShadowUniformsCache();
  12033. var state = {
  12034. version: 0,
  12035. hash: {
  12036. directionalLength: - 1,
  12037. pointLength: - 1,
  12038. spotLength: - 1,
  12039. rectAreaLength: - 1,
  12040. hemiLength: - 1,
  12041. numDirectionalShadows: - 1,
  12042. numPointShadows: - 1,
  12043. numSpotShadows: - 1
  12044. },
  12045. ambient: [ 0, 0, 0 ],
  12046. probe: [],
  12047. directional: [],
  12048. directionalShadow: [],
  12049. directionalShadowMap: [],
  12050. directionalShadowMatrix: [],
  12051. spot: [],
  12052. spotShadow: [],
  12053. spotShadowMap: [],
  12054. spotShadowMatrix: [],
  12055. rectArea: [],
  12056. point: [],
  12057. pointShadow: [],
  12058. pointShadowMap: [],
  12059. pointShadowMatrix: [],
  12060. hemi: []
  12061. };
  12062. for ( var i = 0; i < 9; i ++ ) { state.probe.push( new Vector3() ); }
  12063. var vector3 = new Vector3();
  12064. var matrix4 = new Matrix4();
  12065. var matrix42 = new Matrix4();
  12066. function setup( lights, shadows, camera ) {
  12067. var r = 0, g = 0, b = 0;
  12068. for ( var i = 0; i < 9; i ++ ) { state.probe[ i ].set( 0, 0, 0 ); }
  12069. var directionalLength = 0;
  12070. var pointLength = 0;
  12071. var spotLength = 0;
  12072. var rectAreaLength = 0;
  12073. var hemiLength = 0;
  12074. var numDirectionalShadows = 0;
  12075. var numPointShadows = 0;
  12076. var numSpotShadows = 0;
  12077. var viewMatrix = camera.matrixWorldInverse;
  12078. lights.sort( shadowCastingLightsFirst );
  12079. for ( var i$1 = 0, l = lights.length; i$1 < l; i$1 ++ ) {
  12080. var light = lights[ i$1 ];
  12081. var color = light.color;
  12082. var intensity = light.intensity;
  12083. var distance = light.distance;
  12084. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  12085. if ( light.isAmbientLight ) {
  12086. r += color.r * intensity;
  12087. g += color.g * intensity;
  12088. b += color.b * intensity;
  12089. } else if ( light.isLightProbe ) {
  12090. for ( var j = 0; j < 9; j ++ ) {
  12091. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  12092. }
  12093. } else if ( light.isDirectionalLight ) {
  12094. var uniforms = cache.get( light );
  12095. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12096. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12097. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12098. uniforms.direction.sub( vector3 );
  12099. uniforms.direction.transformDirection( viewMatrix );
  12100. if ( light.castShadow ) {
  12101. var shadow = light.shadow;
  12102. var shadowUniforms = shadowCache.get( light );
  12103. shadowUniforms.shadowBias = shadow.bias;
  12104. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12105. shadowUniforms.shadowRadius = shadow.radius;
  12106. shadowUniforms.shadowMapSize = shadow.mapSize;
  12107. state.directionalShadow[ directionalLength ] = shadowUniforms;
  12108. state.directionalShadowMap[ directionalLength ] = shadowMap;
  12109. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  12110. numDirectionalShadows ++;
  12111. }
  12112. state.directional[ directionalLength ] = uniforms;
  12113. directionalLength ++;
  12114. } else if ( light.isSpotLight ) {
  12115. var uniforms$1 = cache.get( light );
  12116. uniforms$1.position.setFromMatrixPosition( light.matrixWorld );
  12117. uniforms$1.position.applyMatrix4( viewMatrix );
  12118. uniforms$1.color.copy( color ).multiplyScalar( intensity );
  12119. uniforms$1.distance = distance;
  12120. uniforms$1.direction.setFromMatrixPosition( light.matrixWorld );
  12121. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12122. uniforms$1.direction.sub( vector3 );
  12123. uniforms$1.direction.transformDirection( viewMatrix );
  12124. uniforms$1.coneCos = Math.cos( light.angle );
  12125. uniforms$1.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  12126. uniforms$1.decay = light.decay;
  12127. if ( light.castShadow ) {
  12128. var shadow$1 = light.shadow;
  12129. var shadowUniforms$1 = shadowCache.get( light );
  12130. shadowUniforms$1.shadowBias = shadow$1.bias;
  12131. shadowUniforms$1.shadowNormalBias = shadow$1.normalBias;
  12132. shadowUniforms$1.shadowRadius = shadow$1.radius;
  12133. shadowUniforms$1.shadowMapSize = shadow$1.mapSize;
  12134. state.spotShadow[ spotLength ] = shadowUniforms$1;
  12135. state.spotShadowMap[ spotLength ] = shadowMap;
  12136. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  12137. numSpotShadows ++;
  12138. }
  12139. state.spot[ spotLength ] = uniforms$1;
  12140. spotLength ++;
  12141. } else if ( light.isRectAreaLight ) {
  12142. var uniforms$2 = cache.get( light );
  12143. // (a) intensity is the total visible light emitted
  12144. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12145. // (b) intensity is the brightness of the light
  12146. uniforms$2.color.copy( color ).multiplyScalar( intensity );
  12147. uniforms$2.position.setFromMatrixPosition( light.matrixWorld );
  12148. uniforms$2.position.applyMatrix4( viewMatrix );
  12149. // extract local rotation of light to derive width/height half vectors
  12150. matrix42.identity();
  12151. matrix4.copy( light.matrixWorld );
  12152. matrix4.premultiply( viewMatrix );
  12153. matrix42.extractRotation( matrix4 );
  12154. uniforms$2.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  12155. uniforms$2.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  12156. uniforms$2.halfWidth.applyMatrix4( matrix42 );
  12157. uniforms$2.halfHeight.applyMatrix4( matrix42 );
  12158. // TODO (abelnation): RectAreaLight distance?
  12159. // uniforms.distance = distance;
  12160. state.rectArea[ rectAreaLength ] = uniforms$2;
  12161. rectAreaLength ++;
  12162. } else if ( light.isPointLight ) {
  12163. var uniforms$3 = cache.get( light );
  12164. uniforms$3.position.setFromMatrixPosition( light.matrixWorld );
  12165. uniforms$3.position.applyMatrix4( viewMatrix );
  12166. uniforms$3.color.copy( light.color ).multiplyScalar( light.intensity );
  12167. uniforms$3.distance = light.distance;
  12168. uniforms$3.decay = light.decay;
  12169. if ( light.castShadow ) {
  12170. var shadow$2 = light.shadow;
  12171. var shadowUniforms$2 = shadowCache.get( light );
  12172. shadowUniforms$2.shadowBias = shadow$2.bias;
  12173. shadowUniforms$2.shadowNormalBias = shadow$2.normalBias;
  12174. shadowUniforms$2.shadowRadius = shadow$2.radius;
  12175. shadowUniforms$2.shadowMapSize = shadow$2.mapSize;
  12176. shadowUniforms$2.shadowCameraNear = shadow$2.camera.near;
  12177. shadowUniforms$2.shadowCameraFar = shadow$2.camera.far;
  12178. state.pointShadow[ pointLength ] = shadowUniforms$2;
  12179. state.pointShadowMap[ pointLength ] = shadowMap;
  12180. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  12181. numPointShadows ++;
  12182. }
  12183. state.point[ pointLength ] = uniforms$3;
  12184. pointLength ++;
  12185. } else if ( light.isHemisphereLight ) {
  12186. var uniforms$4 = cache.get( light );
  12187. uniforms$4.direction.setFromMatrixPosition( light.matrixWorld );
  12188. uniforms$4.direction.transformDirection( viewMatrix );
  12189. uniforms$4.direction.normalize();
  12190. uniforms$4.skyColor.copy( light.color ).multiplyScalar( intensity );
  12191. uniforms$4.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  12192. state.hemi[ hemiLength ] = uniforms$4;
  12193. hemiLength ++;
  12194. }
  12195. }
  12196. state.ambient[ 0 ] = r;
  12197. state.ambient[ 1 ] = g;
  12198. state.ambient[ 2 ] = b;
  12199. var hash = state.hash;
  12200. if ( hash.directionalLength !== directionalLength ||
  12201. hash.pointLength !== pointLength ||
  12202. hash.spotLength !== spotLength ||
  12203. hash.rectAreaLength !== rectAreaLength ||
  12204. hash.hemiLength !== hemiLength ||
  12205. hash.numDirectionalShadows !== numDirectionalShadows ||
  12206. hash.numPointShadows !== numPointShadows ||
  12207. hash.numSpotShadows !== numSpotShadows ) {
  12208. state.directional.length = directionalLength;
  12209. state.spot.length = spotLength;
  12210. state.rectArea.length = rectAreaLength;
  12211. state.point.length = pointLength;
  12212. state.hemi.length = hemiLength;
  12213. state.directionalShadow.length = numDirectionalShadows;
  12214. state.directionalShadowMap.length = numDirectionalShadows;
  12215. state.pointShadow.length = numPointShadows;
  12216. state.pointShadowMap.length = numPointShadows;
  12217. state.spotShadow.length = numSpotShadows;
  12218. state.spotShadowMap.length = numSpotShadows;
  12219. state.directionalShadowMatrix.length = numDirectionalShadows;
  12220. state.pointShadowMatrix.length = numPointShadows;
  12221. state.spotShadowMatrix.length = numSpotShadows;
  12222. hash.directionalLength = directionalLength;
  12223. hash.pointLength = pointLength;
  12224. hash.spotLength = spotLength;
  12225. hash.rectAreaLength = rectAreaLength;
  12226. hash.hemiLength = hemiLength;
  12227. hash.numDirectionalShadows = numDirectionalShadows;
  12228. hash.numPointShadows = numPointShadows;
  12229. hash.numSpotShadows = numSpotShadows;
  12230. state.version = nextVersion ++;
  12231. }
  12232. }
  12233. return {
  12234. setup: setup,
  12235. state: state
  12236. };
  12237. }
  12238. /**
  12239. * @author Mugen87 / https://github.com/Mugen87
  12240. */
  12241. function WebGLRenderState() {
  12242. var lights = new WebGLLights();
  12243. var lightsArray = [];
  12244. var shadowsArray = [];
  12245. function init() {
  12246. lightsArray.length = 0;
  12247. shadowsArray.length = 0;
  12248. }
  12249. function pushLight( light ) {
  12250. lightsArray.push( light );
  12251. }
  12252. function pushShadow( shadowLight ) {
  12253. shadowsArray.push( shadowLight );
  12254. }
  12255. function setupLights( camera ) {
  12256. lights.setup( lightsArray, shadowsArray, camera );
  12257. }
  12258. var state = {
  12259. lightsArray: lightsArray,
  12260. shadowsArray: shadowsArray,
  12261. lights: lights
  12262. };
  12263. return {
  12264. init: init,
  12265. state: state,
  12266. setupLights: setupLights,
  12267. pushLight: pushLight,
  12268. pushShadow: pushShadow
  12269. };
  12270. }
  12271. function WebGLRenderStates() {
  12272. var renderStates = new WeakMap();
  12273. function onSceneDispose( event ) {
  12274. var scene = event.target;
  12275. scene.removeEventListener( 'dispose', onSceneDispose );
  12276. renderStates.delete( scene );
  12277. }
  12278. function get( scene, camera ) {
  12279. var renderState;
  12280. if ( renderStates.has( scene ) === false ) {
  12281. renderState = new WebGLRenderState();
  12282. renderStates.set( scene, new WeakMap() );
  12283. renderStates.get( scene ).set( camera, renderState );
  12284. scene.addEventListener( 'dispose', onSceneDispose );
  12285. } else {
  12286. if ( renderStates.get( scene ).has( camera ) === false ) {
  12287. renderState = new WebGLRenderState();
  12288. renderStates.get( scene ).set( camera, renderState );
  12289. } else {
  12290. renderState = renderStates.get( scene ).get( camera );
  12291. }
  12292. }
  12293. return renderState;
  12294. }
  12295. function dispose() {
  12296. renderStates = new WeakMap();
  12297. }
  12298. return {
  12299. get: get,
  12300. dispose: dispose
  12301. };
  12302. }
  12303. /**
  12304. * @author mrdoob / http://mrdoob.com/
  12305. * @author alteredq / http://alteredqualia.com/
  12306. * @author bhouston / https://clara.io
  12307. * @author WestLangley / http://github.com/WestLangley
  12308. *
  12309. * parameters = {
  12310. *
  12311. * opacity: <float>,
  12312. *
  12313. * map: new THREE.Texture( <Image> ),
  12314. *
  12315. * alphaMap: new THREE.Texture( <Image> ),
  12316. *
  12317. * displacementMap: new THREE.Texture( <Image> ),
  12318. * displacementScale: <float>,
  12319. * displacementBias: <float>,
  12320. *
  12321. * wireframe: <boolean>,
  12322. * wireframeLinewidth: <float>
  12323. * }
  12324. */
  12325. function MeshDepthMaterial( parameters ) {
  12326. Material.call( this );
  12327. this.type = 'MeshDepthMaterial';
  12328. this.depthPacking = BasicDepthPacking;
  12329. this.skinning = false;
  12330. this.morphTargets = false;
  12331. this.map = null;
  12332. this.alphaMap = null;
  12333. this.displacementMap = null;
  12334. this.displacementScale = 1;
  12335. this.displacementBias = 0;
  12336. this.wireframe = false;
  12337. this.wireframeLinewidth = 1;
  12338. this.fog = false;
  12339. this.setValues( parameters );
  12340. }
  12341. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  12342. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12343. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12344. MeshDepthMaterial.prototype.copy = function ( source ) {
  12345. Material.prototype.copy.call( this, source );
  12346. this.depthPacking = source.depthPacking;
  12347. this.skinning = source.skinning;
  12348. this.morphTargets = source.morphTargets;
  12349. this.map = source.map;
  12350. this.alphaMap = source.alphaMap;
  12351. this.displacementMap = source.displacementMap;
  12352. this.displacementScale = source.displacementScale;
  12353. this.displacementBias = source.displacementBias;
  12354. this.wireframe = source.wireframe;
  12355. this.wireframeLinewidth = source.wireframeLinewidth;
  12356. return this;
  12357. };
  12358. /**
  12359. * @author WestLangley / http://github.com/WestLangley
  12360. *
  12361. * parameters = {
  12362. *
  12363. * referencePosition: <float>,
  12364. * nearDistance: <float>,
  12365. * farDistance: <float>,
  12366. *
  12367. * skinning: <bool>,
  12368. * morphTargets: <bool>,
  12369. *
  12370. * map: new THREE.Texture( <Image> ),
  12371. *
  12372. * alphaMap: new THREE.Texture( <Image> ),
  12373. *
  12374. * displacementMap: new THREE.Texture( <Image> ),
  12375. * displacementScale: <float>,
  12376. * displacementBias: <float>
  12377. *
  12378. * }
  12379. */
  12380. function MeshDistanceMaterial( parameters ) {
  12381. Material.call( this );
  12382. this.type = 'MeshDistanceMaterial';
  12383. this.referencePosition = new Vector3();
  12384. this.nearDistance = 1;
  12385. this.farDistance = 1000;
  12386. this.skinning = false;
  12387. this.morphTargets = false;
  12388. this.map = null;
  12389. this.alphaMap = null;
  12390. this.displacementMap = null;
  12391. this.displacementScale = 1;
  12392. this.displacementBias = 0;
  12393. this.fog = false;
  12394. this.setValues( parameters );
  12395. }
  12396. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  12397. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12398. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12399. MeshDistanceMaterial.prototype.copy = function ( source ) {
  12400. Material.prototype.copy.call( this, source );
  12401. this.referencePosition.copy( source.referencePosition );
  12402. this.nearDistance = source.nearDistance;
  12403. this.farDistance = source.farDistance;
  12404. this.skinning = source.skinning;
  12405. this.morphTargets = source.morphTargets;
  12406. this.map = source.map;
  12407. this.alphaMap = source.alphaMap;
  12408. this.displacementMap = source.displacementMap;
  12409. this.displacementScale = source.displacementScale;
  12410. this.displacementBias = source.displacementBias;
  12411. return this;
  12412. };
  12413. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n float mean = 0.0;\n float squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n for ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n #ifdef HORIZONAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean * HALF_SAMPLE_RATE;\n squared_mean = squared_mean * HALF_SAMPLE_RATE;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  12414. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12415. /**
  12416. * @author alteredq / http://alteredqualia.com/
  12417. * @author mrdoob / http://mrdoob.com/
  12418. */
  12419. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  12420. var _frustum = new Frustum();
  12421. var _shadowMapSize = new Vector2(),
  12422. _viewportSize = new Vector2(),
  12423. _viewport = new Vector4(),
  12424. _depthMaterials = [],
  12425. _distanceMaterials = [],
  12426. _materialCache = {};
  12427. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  12428. var shadowMaterialVertical = new ShaderMaterial( {
  12429. defines: {
  12430. SAMPLE_RATE: 2.0 / 8.0,
  12431. HALF_SAMPLE_RATE: 1.0 / 8.0
  12432. },
  12433. uniforms: {
  12434. shadow_pass: { value: null },
  12435. resolution: { value: new Vector2() },
  12436. radius: { value: 4.0 }
  12437. },
  12438. vertexShader: vsm_vert,
  12439. fragmentShader: vsm_frag
  12440. } );
  12441. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  12442. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  12443. var fullScreenTri = new BufferGeometry();
  12444. fullScreenTri.setAttribute(
  12445. "position",
  12446. new BufferAttribute(
  12447. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  12448. 3
  12449. )
  12450. );
  12451. var fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  12452. var scope = this;
  12453. this.enabled = false;
  12454. this.autoUpdate = true;
  12455. this.needsUpdate = false;
  12456. this.type = PCFShadowMap;
  12457. this.render = function ( lights, scene, camera ) {
  12458. if ( scope.enabled === false ) { return; }
  12459. if ( scope.autoUpdate === false && scope.needsUpdate === false ) { return; }
  12460. if ( lights.length === 0 ) { return; }
  12461. var currentRenderTarget = _renderer.getRenderTarget();
  12462. var activeCubeFace = _renderer.getActiveCubeFace();
  12463. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12464. var _state = _renderer.state;
  12465. // Set GL state for depth map.
  12466. _state.setBlending( NoBlending );
  12467. _state.buffers.color.setClear( 1, 1, 1, 1 );
  12468. _state.buffers.depth.setTest( true );
  12469. _state.setScissorTest( false );
  12470. // render depth map
  12471. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  12472. var light = lights[ i ];
  12473. var shadow = light.shadow;
  12474. if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) { continue; }
  12475. if ( shadow === undefined ) {
  12476. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  12477. continue;
  12478. }
  12479. _shadowMapSize.copy( shadow.mapSize );
  12480. var shadowFrameExtents = shadow.getFrameExtents();
  12481. _shadowMapSize.multiply( shadowFrameExtents );
  12482. _viewportSize.copy( shadow.mapSize );
  12483. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  12484. if ( _shadowMapSize.x > maxTextureSize ) {
  12485. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  12486. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12487. shadow.mapSize.x = _viewportSize.x;
  12488. }
  12489. if ( _shadowMapSize.y > maxTextureSize ) {
  12490. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  12491. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12492. shadow.mapSize.y = _viewportSize.y;
  12493. }
  12494. }
  12495. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12496. var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  12497. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12498. shadow.map.texture.name = light.name + ".shadowMap";
  12499. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12500. shadow.camera.updateProjectionMatrix();
  12501. }
  12502. if ( shadow.map === null ) {
  12503. var pars$1 = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  12504. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars$1 );
  12505. shadow.map.texture.name = light.name + ".shadowMap";
  12506. shadow.camera.updateProjectionMatrix();
  12507. }
  12508. _renderer.setRenderTarget( shadow.map );
  12509. _renderer.clear();
  12510. var viewportCount = shadow.getViewportCount();
  12511. for ( var vp = 0; vp < viewportCount; vp ++ ) {
  12512. var viewport = shadow.getViewport( vp );
  12513. _viewport.set(
  12514. _viewportSize.x * viewport.x,
  12515. _viewportSize.y * viewport.y,
  12516. _viewportSize.x * viewport.z,
  12517. _viewportSize.y * viewport.w
  12518. );
  12519. _state.viewport( _viewport );
  12520. shadow.updateMatrices( light, vp );
  12521. _frustum = shadow.getFrustum();
  12522. renderObject( scene, camera, shadow.camera, light, this.type );
  12523. }
  12524. // do blur pass for VSM
  12525. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12526. VSMPass( shadow, camera );
  12527. }
  12528. shadow.needsUpdate = false;
  12529. }
  12530. scope.needsUpdate = false;
  12531. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  12532. };
  12533. function VSMPass( shadow, camera ) {
  12534. var geometry = _objects.update( fullScreenMesh );
  12535. // vertical pass
  12536. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12537. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12538. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12539. _renderer.setRenderTarget( shadow.mapPass );
  12540. _renderer.clear();
  12541. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  12542. // horizonal pass
  12543. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12544. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  12545. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  12546. _renderer.setRenderTarget( shadow.map );
  12547. _renderer.clear();
  12548. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null );
  12549. }
  12550. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  12551. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12552. var material = _depthMaterials[ index ];
  12553. if ( material === undefined ) {
  12554. material = new MeshDepthMaterial( {
  12555. depthPacking: RGBADepthPacking,
  12556. morphTargets: useMorphing,
  12557. skinning: useSkinning
  12558. } );
  12559. _depthMaterials[ index ] = material;
  12560. }
  12561. return material;
  12562. }
  12563. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  12564. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12565. var material = _distanceMaterials[ index ];
  12566. if ( material === undefined ) {
  12567. material = new MeshDistanceMaterial( {
  12568. morphTargets: useMorphing,
  12569. skinning: useSkinning
  12570. } );
  12571. _distanceMaterials[ index ] = material;
  12572. }
  12573. return material;
  12574. }
  12575. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  12576. var result = null;
  12577. var getMaterialVariant = getDepthMaterialVariant;
  12578. var customMaterial = object.customDepthMaterial;
  12579. if ( light.isPointLight === true ) {
  12580. getMaterialVariant = getDistanceMaterialVariant;
  12581. customMaterial = object.customDistanceMaterial;
  12582. }
  12583. if ( customMaterial === undefined ) {
  12584. var useMorphing = false;
  12585. if ( material.morphTargets === true ) {
  12586. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12587. }
  12588. var useSkinning = false;
  12589. if ( object.isSkinnedMesh === true ) {
  12590. if ( material.skinning === true ) {
  12591. useSkinning = true;
  12592. } else {
  12593. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  12594. }
  12595. }
  12596. var useInstancing = object.isInstancedMesh === true;
  12597. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  12598. } else {
  12599. result = customMaterial;
  12600. }
  12601. if ( _renderer.localClippingEnabled &&
  12602. material.clipShadows === true &&
  12603. material.clippingPlanes.length !== 0 ) {
  12604. // in this case we need a unique material instance reflecting the
  12605. // appropriate state
  12606. var keyA = result.uuid, keyB = material.uuid;
  12607. var materialsForVariant = _materialCache[ keyA ];
  12608. if ( materialsForVariant === undefined ) {
  12609. materialsForVariant = {};
  12610. _materialCache[ keyA ] = materialsForVariant;
  12611. }
  12612. var cachedMaterial = materialsForVariant[ keyB ];
  12613. if ( cachedMaterial === undefined ) {
  12614. cachedMaterial = result.clone();
  12615. materialsForVariant[ keyB ] = cachedMaterial;
  12616. }
  12617. result = cachedMaterial;
  12618. }
  12619. result.visible = material.visible;
  12620. result.wireframe = material.wireframe;
  12621. if ( type === VSMShadowMap ) {
  12622. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  12623. } else {
  12624. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  12625. }
  12626. result.clipShadows = material.clipShadows;
  12627. result.clippingPlanes = material.clippingPlanes;
  12628. result.clipIntersection = material.clipIntersection;
  12629. result.wireframeLinewidth = material.wireframeLinewidth;
  12630. result.linewidth = material.linewidth;
  12631. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  12632. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  12633. result.nearDistance = shadowCameraNear;
  12634. result.farDistance = shadowCameraFar;
  12635. }
  12636. return result;
  12637. }
  12638. function renderObject( object, camera, shadowCamera, light, type ) {
  12639. if ( object.visible === false ) { return; }
  12640. var visible = object.layers.test( camera.layers );
  12641. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  12642. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  12643. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  12644. var geometry = _objects.update( object );
  12645. var material = object.material;
  12646. if ( Array.isArray( material ) ) {
  12647. var groups = geometry.groups;
  12648. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  12649. var group = groups[ k ];
  12650. var groupMaterial = material[ group.materialIndex ];
  12651. if ( groupMaterial && groupMaterial.visible ) {
  12652. var depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  12653. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  12654. }
  12655. }
  12656. } else if ( material.visible ) {
  12657. var depthMaterial$1 = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  12658. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial$1, object, null );
  12659. }
  12660. }
  12661. }
  12662. var children = object.children;
  12663. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12664. renderObject( children[ i ], camera, shadowCamera, light, type );
  12665. }
  12666. }
  12667. }
  12668. /**
  12669. * @author mrdoob / http://mrdoob.com/
  12670. */
  12671. function WebGLState( gl, extensions, capabilities ) {
  12672. var isWebGL2 = capabilities.isWebGL2;
  12673. function ColorBuffer() {
  12674. var locked = false;
  12675. var color = new Vector4();
  12676. var currentColorMask = null;
  12677. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  12678. return {
  12679. setMask: function ( colorMask ) {
  12680. if ( currentColorMask !== colorMask && ! locked ) {
  12681. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  12682. currentColorMask = colorMask;
  12683. }
  12684. },
  12685. setLocked: function ( lock ) {
  12686. locked = lock;
  12687. },
  12688. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  12689. if ( premultipliedAlpha === true ) {
  12690. r *= a; g *= a; b *= a;
  12691. }
  12692. color.set( r, g, b, a );
  12693. if ( currentColorClear.equals( color ) === false ) {
  12694. gl.clearColor( r, g, b, a );
  12695. currentColorClear.copy( color );
  12696. }
  12697. },
  12698. reset: function () {
  12699. locked = false;
  12700. currentColorMask = null;
  12701. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12702. }
  12703. };
  12704. }
  12705. function DepthBuffer() {
  12706. var locked = false;
  12707. var currentDepthMask = null;
  12708. var currentDepthFunc = null;
  12709. var currentDepthClear = null;
  12710. return {
  12711. setTest: function ( depthTest ) {
  12712. if ( depthTest ) {
  12713. enable( 2929 );
  12714. } else {
  12715. disable( 2929 );
  12716. }
  12717. },
  12718. setMask: function ( depthMask ) {
  12719. if ( currentDepthMask !== depthMask && ! locked ) {
  12720. gl.depthMask( depthMask );
  12721. currentDepthMask = depthMask;
  12722. }
  12723. },
  12724. setFunc: function ( depthFunc ) {
  12725. if ( currentDepthFunc !== depthFunc ) {
  12726. if ( depthFunc ) {
  12727. switch ( depthFunc ) {
  12728. case NeverDepth:
  12729. gl.depthFunc( 512 );
  12730. break;
  12731. case AlwaysDepth:
  12732. gl.depthFunc( 519 );
  12733. break;
  12734. case LessDepth:
  12735. gl.depthFunc( 513 );
  12736. break;
  12737. case LessEqualDepth:
  12738. gl.depthFunc( 515 );
  12739. break;
  12740. case EqualDepth:
  12741. gl.depthFunc( 514 );
  12742. break;
  12743. case GreaterEqualDepth:
  12744. gl.depthFunc( 518 );
  12745. break;
  12746. case GreaterDepth:
  12747. gl.depthFunc( 516 );
  12748. break;
  12749. case NotEqualDepth:
  12750. gl.depthFunc( 517 );
  12751. break;
  12752. default:
  12753. gl.depthFunc( 515 );
  12754. }
  12755. } else {
  12756. gl.depthFunc( 515 );
  12757. }
  12758. currentDepthFunc = depthFunc;
  12759. }
  12760. },
  12761. setLocked: function ( lock ) {
  12762. locked = lock;
  12763. },
  12764. setClear: function ( depth ) {
  12765. if ( currentDepthClear !== depth ) {
  12766. gl.clearDepth( depth );
  12767. currentDepthClear = depth;
  12768. }
  12769. },
  12770. reset: function () {
  12771. locked = false;
  12772. currentDepthMask = null;
  12773. currentDepthFunc = null;
  12774. currentDepthClear = null;
  12775. }
  12776. };
  12777. }
  12778. function StencilBuffer() {
  12779. var locked = false;
  12780. var currentStencilMask = null;
  12781. var currentStencilFunc = null;
  12782. var currentStencilRef = null;
  12783. var currentStencilFuncMask = null;
  12784. var currentStencilFail = null;
  12785. var currentStencilZFail = null;
  12786. var currentStencilZPass = null;
  12787. var currentStencilClear = null;
  12788. return {
  12789. setTest: function ( stencilTest ) {
  12790. if ( ! locked ) {
  12791. if ( stencilTest ) {
  12792. enable( 2960 );
  12793. } else {
  12794. disable( 2960 );
  12795. }
  12796. }
  12797. },
  12798. setMask: function ( stencilMask ) {
  12799. if ( currentStencilMask !== stencilMask && ! locked ) {
  12800. gl.stencilMask( stencilMask );
  12801. currentStencilMask = stencilMask;
  12802. }
  12803. },
  12804. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12805. if ( currentStencilFunc !== stencilFunc ||
  12806. currentStencilRef !== stencilRef ||
  12807. currentStencilFuncMask !== stencilMask ) {
  12808. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12809. currentStencilFunc = stencilFunc;
  12810. currentStencilRef = stencilRef;
  12811. currentStencilFuncMask = stencilMask;
  12812. }
  12813. },
  12814. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12815. if ( currentStencilFail !== stencilFail ||
  12816. currentStencilZFail !== stencilZFail ||
  12817. currentStencilZPass !== stencilZPass ) {
  12818. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12819. currentStencilFail = stencilFail;
  12820. currentStencilZFail = stencilZFail;
  12821. currentStencilZPass = stencilZPass;
  12822. }
  12823. },
  12824. setLocked: function ( lock ) {
  12825. locked = lock;
  12826. },
  12827. setClear: function ( stencil ) {
  12828. if ( currentStencilClear !== stencil ) {
  12829. gl.clearStencil( stencil );
  12830. currentStencilClear = stencil;
  12831. }
  12832. },
  12833. reset: function () {
  12834. locked = false;
  12835. currentStencilMask = null;
  12836. currentStencilFunc = null;
  12837. currentStencilRef = null;
  12838. currentStencilFuncMask = null;
  12839. currentStencilFail = null;
  12840. currentStencilZFail = null;
  12841. currentStencilZPass = null;
  12842. currentStencilClear = null;
  12843. }
  12844. };
  12845. }
  12846. //
  12847. var colorBuffer = new ColorBuffer();
  12848. var depthBuffer = new DepthBuffer();
  12849. var stencilBuffer = new StencilBuffer();
  12850. var enabledCapabilities = {};
  12851. var currentProgram = null;
  12852. var currentBlendingEnabled = null;
  12853. var currentBlending = null;
  12854. var currentBlendEquation = null;
  12855. var currentBlendSrc = null;
  12856. var currentBlendDst = null;
  12857. var currentBlendEquationAlpha = null;
  12858. var currentBlendSrcAlpha = null;
  12859. var currentBlendDstAlpha = null;
  12860. var currentPremultipledAlpha = false;
  12861. var currentFlipSided = null;
  12862. var currentCullFace = null;
  12863. var currentLineWidth = null;
  12864. var currentPolygonOffsetFactor = null;
  12865. var currentPolygonOffsetUnits = null;
  12866. var maxTextures = gl.getParameter( 35661 );
  12867. var lineWidthAvailable = false;
  12868. var version = 0;
  12869. var glVersion = gl.getParameter( 7938 );
  12870. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12871. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12872. lineWidthAvailable = ( version >= 1.0 );
  12873. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12874. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12875. lineWidthAvailable = ( version >= 2.0 );
  12876. }
  12877. var currentTextureSlot = null;
  12878. var currentBoundTextures = {};
  12879. var currentScissor = new Vector4();
  12880. var currentViewport = new Vector4();
  12881. function createTexture( type, target, count ) {
  12882. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12883. var texture = gl.createTexture();
  12884. gl.bindTexture( type, texture );
  12885. gl.texParameteri( type, 10241, 9728 );
  12886. gl.texParameteri( type, 10240, 9728 );
  12887. for ( var i = 0; i < count; i ++ ) {
  12888. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12889. }
  12890. return texture;
  12891. }
  12892. var emptyTextures = {};
  12893. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12894. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12895. // init
  12896. colorBuffer.setClear( 0, 0, 0, 1 );
  12897. depthBuffer.setClear( 1 );
  12898. stencilBuffer.setClear( 0 );
  12899. enable( 2929 );
  12900. depthBuffer.setFunc( LessEqualDepth );
  12901. setFlipSided( false );
  12902. setCullFace( CullFaceBack );
  12903. enable( 2884 );
  12904. setBlending( NoBlending );
  12905. //
  12906. function enable( id ) {
  12907. if ( enabledCapabilities[ id ] !== true ) {
  12908. gl.enable( id );
  12909. enabledCapabilities[ id ] = true;
  12910. }
  12911. }
  12912. function disable( id ) {
  12913. if ( enabledCapabilities[ id ] !== false ) {
  12914. gl.disable( id );
  12915. enabledCapabilities[ id ] = false;
  12916. }
  12917. }
  12918. function useProgram( program ) {
  12919. if ( currentProgram !== program ) {
  12920. gl.useProgram( program );
  12921. currentProgram = program;
  12922. return true;
  12923. }
  12924. return false;
  12925. }
  12926. var equationToGL = {};
  12927. equationToGL[ AddEquation ] = 32774;
  12928. equationToGL[ SubtractEquation ] = 32778;
  12929. equationToGL[ ReverseSubtractEquation ] = 32779;
  12930. if ( isWebGL2 ) {
  12931. equationToGL[ MinEquation ] = 32775;
  12932. equationToGL[ MaxEquation ] = 32776;
  12933. } else {
  12934. var extension = extensions.get( 'EXT_blend_minmax' );
  12935. if ( extension !== null ) {
  12936. equationToGL[ MinEquation ] = extension.MIN_EXT;
  12937. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  12938. }
  12939. }
  12940. var factorToGL = {};
  12941. factorToGL[ ZeroFactor ] = 0;
  12942. factorToGL[ OneFactor ] = 1;
  12943. factorToGL[ SrcColorFactor ] = 768;
  12944. factorToGL[ SrcAlphaFactor ] = 770;
  12945. factorToGL[ SrcAlphaSaturateFactor ] = 776;
  12946. factorToGL[ DstColorFactor ] = 774;
  12947. factorToGL[ DstAlphaFactor ] = 772;
  12948. factorToGL[ OneMinusSrcColorFactor ] = 769;
  12949. factorToGL[ OneMinusSrcAlphaFactor ] = 771;
  12950. factorToGL[ OneMinusDstColorFactor ] = 775;
  12951. factorToGL[ OneMinusDstAlphaFactor ] = 773;
  12952. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12953. if ( blending === NoBlending ) {
  12954. if ( currentBlendingEnabled ) {
  12955. disable( 3042 );
  12956. currentBlendingEnabled = false;
  12957. }
  12958. return;
  12959. }
  12960. if ( ! currentBlendingEnabled ) {
  12961. enable( 3042 );
  12962. currentBlendingEnabled = true;
  12963. }
  12964. if ( blending !== CustomBlending ) {
  12965. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12966. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12967. gl.blendEquation( 32774 );
  12968. currentBlendEquation = AddEquation;
  12969. currentBlendEquationAlpha = AddEquation;
  12970. }
  12971. if ( premultipliedAlpha ) {
  12972. switch ( blending ) {
  12973. case NormalBlending:
  12974. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12975. break;
  12976. case AdditiveBlending:
  12977. gl.blendFunc( 1, 1 );
  12978. break;
  12979. case SubtractiveBlending:
  12980. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12981. break;
  12982. case MultiplyBlending:
  12983. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12984. break;
  12985. default:
  12986. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12987. break;
  12988. }
  12989. } else {
  12990. switch ( blending ) {
  12991. case NormalBlending:
  12992. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12993. break;
  12994. case AdditiveBlending:
  12995. gl.blendFunc( 770, 1 );
  12996. break;
  12997. case SubtractiveBlending:
  12998. gl.blendFunc( 0, 769 );
  12999. break;
  13000. case MultiplyBlending:
  13001. gl.blendFunc( 0, 768 );
  13002. break;
  13003. default:
  13004. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  13005. break;
  13006. }
  13007. }
  13008. currentBlendSrc = null;
  13009. currentBlendDst = null;
  13010. currentBlendSrcAlpha = null;
  13011. currentBlendDstAlpha = null;
  13012. currentBlending = blending;
  13013. currentPremultipledAlpha = premultipliedAlpha;
  13014. }
  13015. return;
  13016. }
  13017. // custom blending
  13018. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13019. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13020. blendDstAlpha = blendDstAlpha || blendDst;
  13021. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  13022. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  13023. currentBlendEquation = blendEquation;
  13024. currentBlendEquationAlpha = blendEquationAlpha;
  13025. }
  13026. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  13027. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  13028. currentBlendSrc = blendSrc;
  13029. currentBlendDst = blendDst;
  13030. currentBlendSrcAlpha = blendSrcAlpha;
  13031. currentBlendDstAlpha = blendDstAlpha;
  13032. }
  13033. currentBlending = blending;
  13034. currentPremultipledAlpha = null;
  13035. }
  13036. function setMaterial( material, frontFaceCW ) {
  13037. material.side === DoubleSide
  13038. ? disable( 2884 )
  13039. : enable( 2884 );
  13040. var flipSided = ( material.side === BackSide );
  13041. if ( frontFaceCW ) { flipSided = ! flipSided; }
  13042. setFlipSided( flipSided );
  13043. ( material.blending === NormalBlending && material.transparent === false )
  13044. ? setBlending( NoBlending )
  13045. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  13046. depthBuffer.setFunc( material.depthFunc );
  13047. depthBuffer.setTest( material.depthTest );
  13048. depthBuffer.setMask( material.depthWrite );
  13049. colorBuffer.setMask( material.colorWrite );
  13050. var stencilWrite = material.stencilWrite;
  13051. stencilBuffer.setTest( stencilWrite );
  13052. if ( stencilWrite ) {
  13053. stencilBuffer.setMask( material.stencilWriteMask );
  13054. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  13055. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  13056. }
  13057. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13058. }
  13059. //
  13060. function setFlipSided( flipSided ) {
  13061. if ( currentFlipSided !== flipSided ) {
  13062. if ( flipSided ) {
  13063. gl.frontFace( 2304 );
  13064. } else {
  13065. gl.frontFace( 2305 );
  13066. }
  13067. currentFlipSided = flipSided;
  13068. }
  13069. }
  13070. function setCullFace( cullFace ) {
  13071. if ( cullFace !== CullFaceNone ) {
  13072. enable( 2884 );
  13073. if ( cullFace !== currentCullFace ) {
  13074. if ( cullFace === CullFaceBack ) {
  13075. gl.cullFace( 1029 );
  13076. } else if ( cullFace === CullFaceFront ) {
  13077. gl.cullFace( 1028 );
  13078. } else {
  13079. gl.cullFace( 1032 );
  13080. }
  13081. }
  13082. } else {
  13083. disable( 2884 );
  13084. }
  13085. currentCullFace = cullFace;
  13086. }
  13087. function setLineWidth( width ) {
  13088. if ( width !== currentLineWidth ) {
  13089. if ( lineWidthAvailable ) { gl.lineWidth( width ); }
  13090. currentLineWidth = width;
  13091. }
  13092. }
  13093. function setPolygonOffset( polygonOffset, factor, units ) {
  13094. if ( polygonOffset ) {
  13095. enable( 32823 );
  13096. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  13097. gl.polygonOffset( factor, units );
  13098. currentPolygonOffsetFactor = factor;
  13099. currentPolygonOffsetUnits = units;
  13100. }
  13101. } else {
  13102. disable( 32823 );
  13103. }
  13104. }
  13105. function setScissorTest( scissorTest ) {
  13106. if ( scissorTest ) {
  13107. enable( 3089 );
  13108. } else {
  13109. disable( 3089 );
  13110. }
  13111. }
  13112. // texture
  13113. function activeTexture( webglSlot ) {
  13114. if ( webglSlot === undefined ) { webglSlot = 33984 + maxTextures - 1; }
  13115. if ( currentTextureSlot !== webglSlot ) {
  13116. gl.activeTexture( webglSlot );
  13117. currentTextureSlot = webglSlot;
  13118. }
  13119. }
  13120. function bindTexture( webglType, webglTexture ) {
  13121. if ( currentTextureSlot === null ) {
  13122. activeTexture();
  13123. }
  13124. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  13125. if ( boundTexture === undefined ) {
  13126. boundTexture = { type: undefined, texture: undefined };
  13127. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  13128. }
  13129. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  13130. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  13131. boundTexture.type = webglType;
  13132. boundTexture.texture = webglTexture;
  13133. }
  13134. }
  13135. function unbindTexture() {
  13136. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  13137. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  13138. gl.bindTexture( boundTexture.type, null );
  13139. boundTexture.type = undefined;
  13140. boundTexture.texture = undefined;
  13141. }
  13142. }
  13143. function compressedTexImage2D() {
  13144. try {
  13145. gl.compressedTexImage2D.apply( gl, arguments );
  13146. } catch ( error ) {
  13147. console.error( 'THREE.WebGLState:', error );
  13148. }
  13149. }
  13150. function texImage2D() {
  13151. try {
  13152. gl.texImage2D.apply( gl, arguments );
  13153. } catch ( error ) {
  13154. console.error( 'THREE.WebGLState:', error );
  13155. }
  13156. }
  13157. function texImage3D() {
  13158. try {
  13159. gl.texImage3D.apply( gl, arguments );
  13160. } catch ( error ) {
  13161. console.error( 'THREE.WebGLState:', error );
  13162. }
  13163. }
  13164. //
  13165. function scissor( scissor ) {
  13166. if ( currentScissor.equals( scissor ) === false ) {
  13167. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  13168. currentScissor.copy( scissor );
  13169. }
  13170. }
  13171. function viewport( viewport ) {
  13172. if ( currentViewport.equals( viewport ) === false ) {
  13173. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  13174. currentViewport.copy( viewport );
  13175. }
  13176. }
  13177. //
  13178. function reset() {
  13179. enabledCapabilities = {};
  13180. currentTextureSlot = null;
  13181. currentBoundTextures = {};
  13182. currentProgram = null;
  13183. currentBlending = null;
  13184. currentFlipSided = null;
  13185. currentCullFace = null;
  13186. colorBuffer.reset();
  13187. depthBuffer.reset();
  13188. stencilBuffer.reset();
  13189. }
  13190. return {
  13191. buffers: {
  13192. color: colorBuffer,
  13193. depth: depthBuffer,
  13194. stencil: stencilBuffer
  13195. },
  13196. enable: enable,
  13197. disable: disable,
  13198. useProgram: useProgram,
  13199. setBlending: setBlending,
  13200. setMaterial: setMaterial,
  13201. setFlipSided: setFlipSided,
  13202. setCullFace: setCullFace,
  13203. setLineWidth: setLineWidth,
  13204. setPolygonOffset: setPolygonOffset,
  13205. setScissorTest: setScissorTest,
  13206. activeTexture: activeTexture,
  13207. bindTexture: bindTexture,
  13208. unbindTexture: unbindTexture,
  13209. compressedTexImage2D: compressedTexImage2D,
  13210. texImage2D: texImage2D,
  13211. texImage3D: texImage3D,
  13212. scissor: scissor,
  13213. viewport: viewport,
  13214. reset: reset
  13215. };
  13216. }
  13217. /**
  13218. * @author mrdoob / http://mrdoob.com/
  13219. */
  13220. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  13221. var isWebGL2 = capabilities.isWebGL2;
  13222. var maxTextures = capabilities.maxTextures;
  13223. var maxCubemapSize = capabilities.maxCubemapSize;
  13224. var maxTextureSize = capabilities.maxTextureSize;
  13225. var maxSamples = capabilities.maxSamples;
  13226. var _videoTextures = new WeakMap();
  13227. var _canvas;
  13228. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13229. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13230. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13231. var useOffscreenCanvas = false;
  13232. try {
  13233. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  13234. && ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null;
  13235. } catch ( err ) {
  13236. // Ignore any errors
  13237. }
  13238. function createCanvas( width, height ) {
  13239. // Use OffscreenCanvas when available. Specially needed in web workers
  13240. return useOffscreenCanvas ?
  13241. new OffscreenCanvas( width, height ) :
  13242. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13243. }
  13244. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  13245. var scale = 1;
  13246. // handle case if texture exceeds max size
  13247. if ( image.width > maxSize || image.height > maxSize ) {
  13248. scale = maxSize / Math.max( image.width, image.height );
  13249. }
  13250. // only perform resize if necessary
  13251. if ( scale < 1 || needsPowerOfTwo === true ) {
  13252. // only perform resize for certain image types
  13253. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  13254. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  13255. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  13256. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13257. var width = floor( scale * image.width );
  13258. var height = floor( scale * image.height );
  13259. if ( _canvas === undefined ) { _canvas = createCanvas( width, height ); }
  13260. // cube textures can't reuse the same canvas
  13261. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  13262. canvas.width = width;
  13263. canvas.height = height;
  13264. var context = canvas.getContext( '2d' );
  13265. context.drawImage( image, 0, 0, width, height );
  13266. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  13267. return canvas;
  13268. } else {
  13269. if ( 'data' in image ) {
  13270. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  13271. }
  13272. return image;
  13273. }
  13274. }
  13275. return image;
  13276. }
  13277. function isPowerOfTwo( image ) {
  13278. return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height );
  13279. }
  13280. function textureNeedsPowerOfTwo( texture ) {
  13281. if ( isWebGL2 ) { return false; }
  13282. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  13283. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  13284. }
  13285. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  13286. return texture.generateMipmaps && supportsMips &&
  13287. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13288. }
  13289. function generateMipmap( target, texture, width, height ) {
  13290. _gl.generateMipmap( target );
  13291. var textureProperties = properties.get( texture );
  13292. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13293. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  13294. }
  13295. function getInternalFormat( internalFormatName, glFormat, glType ) {
  13296. if ( isWebGL2 === false ) { return glFormat; }
  13297. if ( internalFormatName !== null ) {
  13298. if ( _gl[ internalFormatName ] !== undefined ) { return _gl[ internalFormatName ]; }
  13299. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  13300. }
  13301. var internalFormat = glFormat;
  13302. if ( glFormat === 6403 ) {
  13303. if ( glType === 5126 ) { internalFormat = 33326; }
  13304. if ( glType === 5131 ) { internalFormat = 33325; }
  13305. if ( glType === 5121 ) { internalFormat = 33321; }
  13306. }
  13307. if ( glFormat === 6407 ) {
  13308. if ( glType === 5126 ) { internalFormat = 34837; }
  13309. if ( glType === 5131 ) { internalFormat = 34843; }
  13310. if ( glType === 5121 ) { internalFormat = 32849; }
  13311. }
  13312. if ( glFormat === 6408 ) {
  13313. if ( glType === 5126 ) { internalFormat = 34836; }
  13314. if ( glType === 5131 ) { internalFormat = 34842; }
  13315. if ( glType === 5121 ) { internalFormat = 32856; }
  13316. }
  13317. if ( internalFormat === 33325 || internalFormat === 33326 ||
  13318. internalFormat === 34842 || internalFormat === 34836 ) {
  13319. extensions.get( 'EXT_color_buffer_float' );
  13320. }
  13321. return internalFormat;
  13322. }
  13323. // Fallback filters for non-power-of-2 textures
  13324. function filterFallback( f ) {
  13325. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  13326. return 9728;
  13327. }
  13328. return 9729;
  13329. }
  13330. //
  13331. function onTextureDispose( event ) {
  13332. var texture = event.target;
  13333. texture.removeEventListener( 'dispose', onTextureDispose );
  13334. deallocateTexture( texture );
  13335. if ( texture.isVideoTexture ) {
  13336. _videoTextures.delete( texture );
  13337. }
  13338. info.memory.textures --;
  13339. }
  13340. function onRenderTargetDispose( event ) {
  13341. var renderTarget = event.target;
  13342. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13343. deallocateRenderTarget( renderTarget );
  13344. info.memory.textures --;
  13345. }
  13346. //
  13347. function deallocateTexture( texture ) {
  13348. var textureProperties = properties.get( texture );
  13349. if ( textureProperties.__webglInit === undefined ) { return; }
  13350. _gl.deleteTexture( textureProperties.__webglTexture );
  13351. properties.remove( texture );
  13352. }
  13353. function deallocateRenderTarget( renderTarget ) {
  13354. var renderTargetProperties = properties.get( renderTarget );
  13355. var textureProperties = properties.get( renderTarget.texture );
  13356. if ( ! renderTarget ) { return; }
  13357. if ( textureProperties.__webglTexture !== undefined ) {
  13358. _gl.deleteTexture( textureProperties.__webglTexture );
  13359. }
  13360. if ( renderTarget.depthTexture ) {
  13361. renderTarget.depthTexture.dispose();
  13362. }
  13363. if ( renderTarget.isWebGLCubeRenderTarget ) {
  13364. for ( var i = 0; i < 6; i ++ ) {
  13365. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13366. if ( renderTargetProperties.__webglDepthbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] ); }
  13367. }
  13368. } else {
  13369. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13370. if ( renderTargetProperties.__webglDepthbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer ); }
  13371. if ( renderTargetProperties.__webglMultisampledFramebuffer ) { _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer ); }
  13372. if ( renderTargetProperties.__webglColorRenderbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer ); }
  13373. if ( renderTargetProperties.__webglDepthRenderbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer ); }
  13374. }
  13375. properties.remove( renderTarget.texture );
  13376. properties.remove( renderTarget );
  13377. }
  13378. //
  13379. var textureUnits = 0;
  13380. function resetTextureUnits() {
  13381. textureUnits = 0;
  13382. }
  13383. function allocateTextureUnit() {
  13384. var textureUnit = textureUnits;
  13385. if ( textureUnit >= maxTextures ) {
  13386. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  13387. }
  13388. textureUnits += 1;
  13389. return textureUnit;
  13390. }
  13391. //
  13392. function setTexture2D( texture, slot ) {
  13393. var textureProperties = properties.get( texture );
  13394. if ( texture.isVideoTexture ) { updateVideoTexture( texture ); }
  13395. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13396. var image = texture.image;
  13397. if ( image === undefined ) {
  13398. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  13399. } else if ( image.complete === false ) {
  13400. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  13401. } else {
  13402. uploadTexture( textureProperties, texture, slot );
  13403. return;
  13404. }
  13405. }
  13406. state.activeTexture( 33984 + slot );
  13407. state.bindTexture( 3553, textureProperties.__webglTexture );
  13408. }
  13409. function setTexture2DArray( texture, slot ) {
  13410. var textureProperties = properties.get( texture );
  13411. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13412. uploadTexture( textureProperties, texture, slot );
  13413. return;
  13414. }
  13415. state.activeTexture( 33984 + slot );
  13416. state.bindTexture( 35866, textureProperties.__webglTexture );
  13417. }
  13418. function setTexture3D( texture, slot ) {
  13419. var textureProperties = properties.get( texture );
  13420. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13421. uploadTexture( textureProperties, texture, slot );
  13422. return;
  13423. }
  13424. state.activeTexture( 33984 + slot );
  13425. state.bindTexture( 32879, textureProperties.__webglTexture );
  13426. }
  13427. function setTextureCube( texture, slot ) {
  13428. if ( texture.image.length !== 6 ) { return; }
  13429. var textureProperties = properties.get( texture );
  13430. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13431. initTexture( textureProperties, texture );
  13432. state.activeTexture( 33984 + slot );
  13433. state.bindTexture( 34067, textureProperties.__webglTexture );
  13434. _gl.pixelStorei( 37440, texture.flipY );
  13435. var isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  13436. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  13437. var cubeImage = [];
  13438. for ( var i = 0; i < 6; i ++ ) {
  13439. if ( ! isCompressed && ! isDataTexture ) {
  13440. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  13441. } else {
  13442. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13443. }
  13444. }
  13445. var image = cubeImage[ 0 ],
  13446. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  13447. glFormat = utils.convert( texture.format ),
  13448. glType = utils.convert( texture.type ),
  13449. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13450. setTextureParameters( 34067, texture, supportsMips );
  13451. var mipmaps;
  13452. if ( isCompressed ) {
  13453. for ( var i$1 = 0; i$1 < 6; i$1 ++ ) {
  13454. mipmaps = cubeImage[ i$1 ].mipmaps;
  13455. for ( var j = 0; j < mipmaps.length; j ++ ) {
  13456. var mipmap = mipmaps[ j ];
  13457. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13458. if ( glFormat !== null ) {
  13459. state.compressedTexImage2D( 34069 + i$1, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13460. } else {
  13461. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  13462. }
  13463. } else {
  13464. state.texImage2D( 34069 + i$1, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13465. }
  13466. }
  13467. }
  13468. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13469. } else {
  13470. mipmaps = texture.mipmaps;
  13471. for ( var i$2 = 0; i$2 < 6; i$2 ++ ) {
  13472. if ( isDataTexture ) {
  13473. state.texImage2D( 34069 + i$2, 0, glInternalFormat, cubeImage[ i$2 ].width, cubeImage[ i$2 ].height, 0, glFormat, glType, cubeImage[ i$2 ].data );
  13474. for ( var j$1 = 0; j$1 < mipmaps.length; j$1 ++ ) {
  13475. var mipmap$1 = mipmaps[ j$1 ];
  13476. var mipmapImage = mipmap$1.image[ i$2 ].image;
  13477. state.texImage2D( 34069 + i$2, j$1 + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  13478. }
  13479. } else {
  13480. state.texImage2D( 34069 + i$2, 0, glInternalFormat, glFormat, glType, cubeImage[ i$2 ] );
  13481. for ( var j$2 = 0; j$2 < mipmaps.length; j$2 ++ ) {
  13482. var mipmap$2 = mipmaps[ j$2 ];
  13483. state.texImage2D( 34069 + i$2, j$2 + 1, glInternalFormat, glFormat, glType, mipmap$2.image[ i$2 ] );
  13484. }
  13485. }
  13486. }
  13487. textureProperties.__maxMipLevel = mipmaps.length;
  13488. }
  13489. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13490. // We assume images for cube map have the same size.
  13491. generateMipmap( 34067, texture, image.width, image.height );
  13492. }
  13493. textureProperties.__version = texture.version;
  13494. if ( texture.onUpdate ) { texture.onUpdate( texture ); }
  13495. } else {
  13496. state.activeTexture( 33984 + slot );
  13497. state.bindTexture( 34067, textureProperties.__webglTexture );
  13498. }
  13499. }
  13500. function setTextureCubeDynamic( texture, slot ) {
  13501. state.activeTexture( 33984 + slot );
  13502. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  13503. }
  13504. var wrappingToGL = {};
  13505. wrappingToGL[ RepeatWrapping ] = 10497;
  13506. wrappingToGL[ ClampToEdgeWrapping ] = 33071;
  13507. wrappingToGL[ MirroredRepeatWrapping ] = 33648;
  13508. var filterToGL = {};
  13509. filterToGL[ NearestFilter ] = 9728;
  13510. filterToGL[ NearestMipmapNearestFilter ] = 9984;
  13511. filterToGL[ NearestMipmapLinearFilter ] = 9986;
  13512. filterToGL[ LinearFilter ] = 9729;
  13513. filterToGL[ LinearMipmapNearestFilter ] = 9985;
  13514. filterToGL[ LinearMipmapLinearFilter ] = 9987;
  13515. function setTextureParameters( textureType, texture, supportsMips ) {
  13516. if ( supportsMips ) {
  13517. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  13518. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  13519. if ( textureType === 32879 || textureType === 35866 ) {
  13520. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  13521. }
  13522. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  13523. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  13524. } else {
  13525. _gl.texParameteri( textureType, 10242, 33071 );
  13526. _gl.texParameteri( textureType, 10243, 33071 );
  13527. if ( textureType === 32879 || textureType === 35866 ) {
  13528. _gl.texParameteri( textureType, 32882, 33071 );
  13529. }
  13530. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  13531. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  13532. }
  13533. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  13534. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  13535. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  13536. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  13537. }
  13538. }
  13539. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13540. if ( extension ) {
  13541. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) { return; }
  13542. if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) { return; }
  13543. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13544. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  13545. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13546. }
  13547. }
  13548. }
  13549. function initTexture( textureProperties, texture ) {
  13550. if ( textureProperties.__webglInit === undefined ) {
  13551. textureProperties.__webglInit = true;
  13552. texture.addEventListener( 'dispose', onTextureDispose );
  13553. textureProperties.__webglTexture = _gl.createTexture();
  13554. info.memory.textures ++;
  13555. }
  13556. }
  13557. function uploadTexture( textureProperties, texture, slot ) {
  13558. var textureType = 3553;
  13559. if ( texture.isDataTexture2DArray ) { textureType = 35866; }
  13560. if ( texture.isDataTexture3D ) { textureType = 32879; }
  13561. initTexture( textureProperties, texture );
  13562. state.activeTexture( 33984 + slot );
  13563. state.bindTexture( textureType, textureProperties.__webglTexture );
  13564. _gl.pixelStorei( 37440, texture.flipY );
  13565. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  13566. _gl.pixelStorei( 3317, texture.unpackAlignment );
  13567. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  13568. var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  13569. var supportsMips = isPowerOfTwo( image ) || isWebGL2,
  13570. glFormat = utils.convert( texture.format );
  13571. var glType = utils.convert( texture.type ),
  13572. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13573. setTextureParameters( textureType, texture, supportsMips );
  13574. var mipmap;
  13575. var mipmaps = texture.mipmaps;
  13576. if ( texture.isDepthTexture ) {
  13577. // populate depth texture with dummy data
  13578. glInternalFormat = 6402;
  13579. if ( isWebGL2 ) {
  13580. if ( texture.type === FloatType ) {
  13581. glInternalFormat = 36012;
  13582. } else if ( texture.type === UnsignedIntType ) {
  13583. glInternalFormat = 33190;
  13584. } else if ( texture.type === UnsignedInt248Type ) {
  13585. glInternalFormat = 35056;
  13586. } else {
  13587. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13588. }
  13589. } else {
  13590. if ( texture.type === FloatType ) {
  13591. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  13592. }
  13593. }
  13594. // validation checks for WebGL 1
  13595. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  13596. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13597. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13598. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13599. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  13600. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  13601. texture.type = UnsignedShortType;
  13602. glType = utils.convert( texture.type );
  13603. }
  13604. }
  13605. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  13606. // Depth stencil textures need the DEPTH_STENCIL internal format
  13607. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13608. glInternalFormat = 34041;
  13609. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13610. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13611. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13612. if ( texture.type !== UnsignedInt248Type ) {
  13613. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  13614. texture.type = UnsignedInt248Type;
  13615. glType = utils.convert( texture.type );
  13616. }
  13617. }
  13618. //
  13619. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  13620. } else if ( texture.isDataTexture ) {
  13621. // use manually created mipmaps if available
  13622. // if there are no manual mipmaps
  13623. // set 0 level mipmap and then use GL to generate other mipmap levels
  13624. if ( mipmaps.length > 0 && supportsMips ) {
  13625. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13626. mipmap = mipmaps[ i ];
  13627. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13628. }
  13629. texture.generateMipmaps = false;
  13630. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13631. } else {
  13632. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13633. textureProperties.__maxMipLevel = 0;
  13634. }
  13635. } else if ( texture.isCompressedTexture ) {
  13636. for ( var i$1 = 0, il$1 = mipmaps.length; i$1 < il$1; i$1 ++ ) {
  13637. mipmap = mipmaps[ i$1 ];
  13638. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13639. if ( glFormat !== null ) {
  13640. state.compressedTexImage2D( 3553, i$1, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13641. } else {
  13642. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  13643. }
  13644. } else {
  13645. state.texImage2D( 3553, i$1, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13646. }
  13647. }
  13648. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13649. } else if ( texture.isDataTexture2DArray ) {
  13650. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13651. textureProperties.__maxMipLevel = 0;
  13652. } else if ( texture.isDataTexture3D ) {
  13653. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13654. textureProperties.__maxMipLevel = 0;
  13655. } else {
  13656. // regular Texture (image, video, canvas)
  13657. // use manually created mipmaps if available
  13658. // if there are no manual mipmaps
  13659. // set 0 level mipmap and then use GL to generate other mipmap levels
  13660. if ( mipmaps.length > 0 && supportsMips ) {
  13661. for ( var i$2 = 0, il$2 = mipmaps.length; i$2 < il$2; i$2 ++ ) {
  13662. mipmap = mipmaps[ i$2 ];
  13663. state.texImage2D( 3553, i$2, glInternalFormat, glFormat, glType, mipmap );
  13664. }
  13665. texture.generateMipmaps = false;
  13666. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13667. } else {
  13668. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  13669. textureProperties.__maxMipLevel = 0;
  13670. }
  13671. }
  13672. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13673. generateMipmap( textureType, texture, image.width, image.height );
  13674. }
  13675. textureProperties.__version = texture.version;
  13676. if ( texture.onUpdate ) { texture.onUpdate( texture ); }
  13677. }
  13678. // Render targets
  13679. // Setup storage for target texture and bind it to correct framebuffer
  13680. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  13681. var glFormat = utils.convert( renderTarget.texture.format );
  13682. var glType = utils.convert( renderTarget.texture.type );
  13683. var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13684. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13685. _gl.bindFramebuffer( 36160, framebuffer );
  13686. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  13687. _gl.bindFramebuffer( 36160, null );
  13688. }
  13689. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13690. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  13691. _gl.bindRenderbuffer( 36161, renderbuffer );
  13692. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13693. var glInternalFormat = 33189;
  13694. if ( isMultisample ) {
  13695. var depthTexture = renderTarget.depthTexture;
  13696. if ( depthTexture && depthTexture.isDepthTexture ) {
  13697. if ( depthTexture.type === FloatType ) {
  13698. glInternalFormat = 36012;
  13699. } else if ( depthTexture.type === UnsignedIntType ) {
  13700. glInternalFormat = 33190;
  13701. }
  13702. }
  13703. var samples = getRenderTargetSamples( renderTarget );
  13704. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13705. } else {
  13706. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13707. }
  13708. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  13709. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13710. if ( isMultisample ) {
  13711. var samples$1 = getRenderTargetSamples( renderTarget );
  13712. _gl.renderbufferStorageMultisample( 36161, samples$1, 35056, renderTarget.width, renderTarget.height );
  13713. } else {
  13714. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  13715. }
  13716. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  13717. } else {
  13718. var glFormat = utils.convert( renderTarget.texture.format );
  13719. var glType = utils.convert( renderTarget.texture.type );
  13720. var glInternalFormat$1 = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13721. if ( isMultisample ) {
  13722. var samples$2 = getRenderTargetSamples( renderTarget );
  13723. _gl.renderbufferStorageMultisample( 36161, samples$2, glInternalFormat$1, renderTarget.width, renderTarget.height );
  13724. } else {
  13725. _gl.renderbufferStorage( 36161, glInternalFormat$1, renderTarget.width, renderTarget.height );
  13726. }
  13727. }
  13728. _gl.bindRenderbuffer( 36161, null );
  13729. }
  13730. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13731. function setupDepthTexture( framebuffer, renderTarget ) {
  13732. var isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  13733. if ( isCube ) { throw new Error( 'Depth Texture with cube render targets is not supported' ); }
  13734. _gl.bindFramebuffer( 36160, framebuffer );
  13735. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13736. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13737. }
  13738. // upload an empty depth texture with framebuffer size
  13739. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13740. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13741. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13742. renderTarget.depthTexture.image.width = renderTarget.width;
  13743. renderTarget.depthTexture.image.height = renderTarget.height;
  13744. renderTarget.depthTexture.needsUpdate = true;
  13745. }
  13746. setTexture2D( renderTarget.depthTexture, 0 );
  13747. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13748. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13749. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13750. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13751. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13752. } else {
  13753. throw new Error( 'Unknown depthTexture format' );
  13754. }
  13755. }
  13756. // Setup GL resources for a non-texture depth buffer
  13757. function setupDepthRenderbuffer( renderTarget ) {
  13758. var renderTargetProperties = properties.get( renderTarget );
  13759. var isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13760. if ( renderTarget.depthTexture ) {
  13761. if ( isCube ) { throw new Error( 'target.depthTexture not supported in Cube render targets' ); }
  13762. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13763. } else {
  13764. if ( isCube ) {
  13765. renderTargetProperties.__webglDepthbuffer = [];
  13766. for ( var i = 0; i < 6; i ++ ) {
  13767. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13768. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13769. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  13770. }
  13771. } else {
  13772. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13773. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13774. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  13775. }
  13776. }
  13777. _gl.bindFramebuffer( 36160, null );
  13778. }
  13779. // Set up GL resources for the render target
  13780. function setupRenderTarget( renderTarget ) {
  13781. var renderTargetProperties = properties.get( renderTarget );
  13782. var textureProperties = properties.get( renderTarget.texture );
  13783. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13784. textureProperties.__webglTexture = _gl.createTexture();
  13785. info.memory.textures ++;
  13786. var isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13787. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13788. var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13789. // Handles WebGL2 RGBFormat fallback - #18858
  13790. if ( isWebGL2 && renderTarget.texture.format === RGBFormat && ( renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType ) ) {
  13791. renderTarget.texture.format = RGBAFormat;
  13792. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  13793. }
  13794. // Setup framebuffer
  13795. if ( isCube ) {
  13796. renderTargetProperties.__webglFramebuffer = [];
  13797. for ( var i = 0; i < 6; i ++ ) {
  13798. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13799. }
  13800. } else {
  13801. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13802. if ( isMultisample ) {
  13803. if ( isWebGL2 ) {
  13804. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13805. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13806. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13807. var glFormat = utils.convert( renderTarget.texture.format );
  13808. var glType = utils.convert( renderTarget.texture.type );
  13809. var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13810. var samples = getRenderTargetSamples( renderTarget );
  13811. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13812. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13813. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13814. _gl.bindRenderbuffer( 36161, null );
  13815. if ( renderTarget.depthBuffer ) {
  13816. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13817. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13818. }
  13819. _gl.bindFramebuffer( 36160, null );
  13820. } else {
  13821. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13822. }
  13823. }
  13824. }
  13825. // Setup color buffer
  13826. if ( isCube ) {
  13827. state.bindTexture( 34067, textureProperties.__webglTexture );
  13828. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13829. for ( var i$1 = 0; i$1 < 6; i$1 ++ ) {
  13830. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i$1 ], renderTarget, 36064, 34069 + i$1 );
  13831. }
  13832. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13833. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13834. }
  13835. state.bindTexture( 34067, null );
  13836. } else {
  13837. state.bindTexture( 3553, textureProperties.__webglTexture );
  13838. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13839. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13840. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13841. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13842. }
  13843. state.bindTexture( 3553, null );
  13844. }
  13845. // Setup depth and stencil buffers
  13846. if ( renderTarget.depthBuffer ) {
  13847. setupDepthRenderbuffer( renderTarget );
  13848. }
  13849. }
  13850. function updateRenderTargetMipmap( renderTarget ) {
  13851. var texture = renderTarget.texture;
  13852. var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13853. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13854. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13855. var webglTexture = properties.get( texture ).__webglTexture;
  13856. state.bindTexture( target, webglTexture );
  13857. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13858. state.bindTexture( target, null );
  13859. }
  13860. }
  13861. function updateMultisampleRenderTarget( renderTarget ) {
  13862. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13863. if ( isWebGL2 ) {
  13864. var renderTargetProperties = properties.get( renderTarget );
  13865. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13866. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13867. var width = renderTarget.width;
  13868. var height = renderTarget.height;
  13869. var mask = 16384;
  13870. if ( renderTarget.depthBuffer ) { mask |= 256; }
  13871. if ( renderTarget.stencilBuffer ) { mask |= 1024; }
  13872. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13873. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905
  13874. } else {
  13875. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13876. }
  13877. }
  13878. }
  13879. function getRenderTargetSamples( renderTarget ) {
  13880. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13881. Math.min( maxSamples, renderTarget.samples ) : 0;
  13882. }
  13883. function updateVideoTexture( texture ) {
  13884. var frame = info.render.frame;
  13885. // Check the last frame we updated the VideoTexture
  13886. if ( _videoTextures.get( texture ) !== frame ) {
  13887. _videoTextures.set( texture, frame );
  13888. texture.update();
  13889. }
  13890. }
  13891. // backwards compatibility
  13892. var warnedTexture2D = false;
  13893. var warnedTextureCube = false;
  13894. function safeSetTexture2D( texture, slot ) {
  13895. if ( texture && texture.isWebGLRenderTarget ) {
  13896. if ( warnedTexture2D === false ) {
  13897. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13898. warnedTexture2D = true;
  13899. }
  13900. texture = texture.texture;
  13901. }
  13902. setTexture2D( texture, slot );
  13903. }
  13904. function safeSetTextureCube( texture, slot ) {
  13905. if ( texture && texture.isWebGLCubeRenderTarget ) {
  13906. if ( warnedTextureCube === false ) {
  13907. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13908. warnedTextureCube = true;
  13909. }
  13910. texture = texture.texture;
  13911. }
  13912. // currently relying on the fact that WebGLCubeRenderTarget.texture is a Texture and NOT a CubeTexture
  13913. // TODO: unify these code paths
  13914. if ( ( texture && texture.isCubeTexture ) ||
  13915. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13916. // CompressedTexture can have Array in image :/
  13917. // this function alone should take care of cube textures
  13918. setTextureCube( texture, slot );
  13919. } else {
  13920. // assumed: texture property of THREE.WebGLCubeRenderTarget
  13921. setTextureCubeDynamic( texture, slot );
  13922. }
  13923. }
  13924. //
  13925. this.allocateTextureUnit = allocateTextureUnit;
  13926. this.resetTextureUnits = resetTextureUnits;
  13927. this.setTexture2D = setTexture2D;
  13928. this.setTexture2DArray = setTexture2DArray;
  13929. this.setTexture3D = setTexture3D;
  13930. this.setTextureCube = setTextureCube;
  13931. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13932. this.setupRenderTarget = setupRenderTarget;
  13933. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13934. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13935. this.safeSetTexture2D = safeSetTexture2D;
  13936. this.safeSetTextureCube = safeSetTextureCube;
  13937. }
  13938. /**
  13939. * @author thespite / http://www.twitter.com/thespite
  13940. */
  13941. function WebGLUtils( gl, extensions, capabilities ) {
  13942. var isWebGL2 = capabilities.isWebGL2;
  13943. function convert( p ) {
  13944. var extension;
  13945. if ( p === UnsignedByteType ) { return 5121; }
  13946. if ( p === UnsignedShort4444Type ) { return 32819; }
  13947. if ( p === UnsignedShort5551Type ) { return 32820; }
  13948. if ( p === UnsignedShort565Type ) { return 33635; }
  13949. if ( p === ByteType ) { return 5120; }
  13950. if ( p === ShortType ) { return 5122; }
  13951. if ( p === UnsignedShortType ) { return 5123; }
  13952. if ( p === IntType ) { return 5124; }
  13953. if ( p === UnsignedIntType ) { return 5125; }
  13954. if ( p === FloatType ) { return 5126; }
  13955. if ( p === HalfFloatType ) {
  13956. if ( isWebGL2 ) { return 5131; }
  13957. extension = extensions.get( 'OES_texture_half_float' );
  13958. if ( extension !== null ) {
  13959. return extension.HALF_FLOAT_OES;
  13960. } else {
  13961. return null;
  13962. }
  13963. }
  13964. if ( p === AlphaFormat ) { return 6406; }
  13965. if ( p === RGBFormat ) { return 6407; }
  13966. if ( p === RGBAFormat ) { return 6408; }
  13967. if ( p === LuminanceFormat ) { return 6409; }
  13968. if ( p === LuminanceAlphaFormat ) { return 6410; }
  13969. if ( p === DepthFormat ) { return 6402; }
  13970. if ( p === DepthStencilFormat ) { return 34041; }
  13971. if ( p === RedFormat ) { return 6403; }
  13972. // WebGL2 formats.
  13973. if ( p === RedIntegerFormat ) { return 36244; }
  13974. if ( p === RGFormat ) { return 33319; }
  13975. if ( p === RGIntegerFormat ) { return 33320; }
  13976. if ( p === RGBIntegerFormat ) { return 36248; }
  13977. if ( p === RGBAIntegerFormat ) { return 36249; }
  13978. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13979. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13980. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13981. if ( extension !== null ) {
  13982. if ( p === RGB_S3TC_DXT1_Format ) { return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; }
  13983. if ( p === RGBA_S3TC_DXT1_Format ) { return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; }
  13984. if ( p === RGBA_S3TC_DXT3_Format ) { return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; }
  13985. if ( p === RGBA_S3TC_DXT5_Format ) { return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; }
  13986. } else {
  13987. return null;
  13988. }
  13989. }
  13990. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13991. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13992. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13993. if ( extension !== null ) {
  13994. if ( p === RGB_PVRTC_4BPPV1_Format ) { return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; }
  13995. if ( p === RGB_PVRTC_2BPPV1_Format ) { return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; }
  13996. if ( p === RGBA_PVRTC_4BPPV1_Format ) { return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; }
  13997. if ( p === RGBA_PVRTC_2BPPV1_Format ) { return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; }
  13998. } else {
  13999. return null;
  14000. }
  14001. }
  14002. if ( p === RGB_ETC1_Format ) {
  14003. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  14004. if ( extension !== null ) {
  14005. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  14006. } else {
  14007. return null;
  14008. }
  14009. }
  14010. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  14011. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  14012. if ( extension !== null ) {
  14013. if ( p === RGB_ETC2_Format ) { return extension.COMPRESSED_RGB8_ETC2; }
  14014. if ( p === RGBA_ETC2_EAC_Format ) { return extension.COMPRESSED_RGBA8_ETC2_EAC; }
  14015. }
  14016. }
  14017. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  14018. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  14019. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  14020. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  14021. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  14022. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  14023. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  14024. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  14025. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  14026. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  14027. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  14028. if ( extension !== null ) {
  14029. // TODO Complete?
  14030. return p;
  14031. } else {
  14032. return null;
  14033. }
  14034. }
  14035. if ( p === RGBA_BPTC_Format ) {
  14036. extension = extensions.get( 'EXT_texture_compression_bptc' );
  14037. if ( extension !== null ) {
  14038. // TODO Complete?
  14039. return p;
  14040. } else {
  14041. return null;
  14042. }
  14043. }
  14044. if ( p === UnsignedInt248Type ) {
  14045. if ( isWebGL2 ) { return 34042; }
  14046. extension = extensions.get( 'WEBGL_depth_texture' );
  14047. if ( extension !== null ) {
  14048. return extension.UNSIGNED_INT_24_8_WEBGL;
  14049. } else {
  14050. return null;
  14051. }
  14052. }
  14053. }
  14054. return { convert: convert };
  14055. }
  14056. /**
  14057. * @author mrdoob / http://mrdoob.com/
  14058. */
  14059. function ArrayCamera( array ) {
  14060. PerspectiveCamera.call( this );
  14061. this.cameras = array || [];
  14062. }
  14063. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  14064. constructor: ArrayCamera,
  14065. isArrayCamera: true
  14066. } );
  14067. /**
  14068. * @author mrdoob / http://mrdoob.com/
  14069. */
  14070. function Group() {
  14071. Object3D.call( this );
  14072. this.type = 'Group';
  14073. }
  14074. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14075. constructor: Group,
  14076. isGroup: true
  14077. } );
  14078. /**
  14079. * @author Mugen87 / https://github.com/Mugen87
  14080. */
  14081. function WebXRController() {
  14082. this._targetRay = null;
  14083. this._grip = null;
  14084. }
  14085. Object.assign( WebXRController.prototype, {
  14086. constructor: WebXRController,
  14087. getTargetRaySpace: function () {
  14088. if ( this._targetRay === null ) {
  14089. this._targetRay = new Group();
  14090. this._targetRay.matrixAutoUpdate = false;
  14091. this._targetRay.visible = false;
  14092. }
  14093. return this._targetRay;
  14094. },
  14095. getGripSpace: function () {
  14096. if ( this._grip === null ) {
  14097. this._grip = new Group();
  14098. this._grip.matrixAutoUpdate = false;
  14099. this._grip.visible = false;
  14100. }
  14101. return this._grip;
  14102. },
  14103. dispatchEvent: function ( event ) {
  14104. if ( this._targetRay !== null ) {
  14105. this._targetRay.dispatchEvent( event );
  14106. }
  14107. if ( this._grip !== null ) {
  14108. this._grip.dispatchEvent( event );
  14109. }
  14110. return this;
  14111. },
  14112. disconnect: function ( inputSource ) {
  14113. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  14114. if ( this._targetRay !== null ) {
  14115. this._targetRay.visible = false;
  14116. }
  14117. if ( this._grip !== null ) {
  14118. this._grip.visible = false;
  14119. }
  14120. return this;
  14121. },
  14122. update: function ( inputSource, frame, referenceSpace ) {
  14123. var inputPose = null;
  14124. var gripPose = null;
  14125. var targetRay = this._targetRay;
  14126. var grip = this._grip;
  14127. if ( inputSource ) {
  14128. if ( targetRay !== null ) {
  14129. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  14130. if ( inputPose !== null ) {
  14131. targetRay.matrix.fromArray( inputPose.transform.matrix );
  14132. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  14133. }
  14134. }
  14135. if ( grip !== null && inputSource.gripSpace ) {
  14136. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  14137. if ( gripPose !== null ) {
  14138. grip.matrix.fromArray( gripPose.transform.matrix );
  14139. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  14140. }
  14141. }
  14142. }
  14143. if ( targetRay !== null ) {
  14144. targetRay.visible = ( inputPose !== null );
  14145. }
  14146. if ( grip !== null ) {
  14147. grip.visible = ( gripPose !== null );
  14148. }
  14149. return this;
  14150. }
  14151. } );
  14152. /**
  14153. * @author mrdoob / http://mrdoob.com/
  14154. */
  14155. function WebXRManager( renderer, gl ) {
  14156. var scope = this;
  14157. var session = null;
  14158. var framebufferScaleFactor = 1.0;
  14159. var referenceSpace = null;
  14160. var referenceSpaceType = 'local-floor';
  14161. var pose = null;
  14162. var controllers = [];
  14163. var inputSourcesMap = new Map();
  14164. //
  14165. var cameraL = new PerspectiveCamera();
  14166. cameraL.layers.enable( 1 );
  14167. cameraL.viewport = new Vector4();
  14168. var cameraR = new PerspectiveCamera();
  14169. cameraR.layers.enable( 2 );
  14170. cameraR.viewport = new Vector4();
  14171. var cameras = [ cameraL, cameraR ];
  14172. var cameraVR = new ArrayCamera();
  14173. cameraVR.layers.enable( 1 );
  14174. cameraVR.layers.enable( 2 );
  14175. var _currentDepthNear = null;
  14176. var _currentDepthFar = null;
  14177. //
  14178. this.enabled = false;
  14179. this.isPresenting = false;
  14180. this.getController = function ( index ) {
  14181. var controller = controllers[ index ];
  14182. if ( controller === undefined ) {
  14183. controller = new WebXRController();
  14184. controllers[ index ] = controller;
  14185. }
  14186. return controller.getTargetRaySpace();
  14187. };
  14188. this.getControllerGrip = function ( index ) {
  14189. var controller = controllers[ index ];
  14190. if ( controller === undefined ) {
  14191. controller = new WebXRController();
  14192. controllers[ index ] = controller;
  14193. }
  14194. return controller.getGripSpace();
  14195. };
  14196. //
  14197. function onSessionEvent( event ) {
  14198. var controller = inputSourcesMap.get( event.inputSource );
  14199. if ( controller ) {
  14200. controller.dispatchEvent( { type: event.type } );
  14201. }
  14202. }
  14203. function onSessionEnd() {
  14204. inputSourcesMap.forEach( function ( controller, inputSource ) {
  14205. controller.disconnect( inputSource );
  14206. } );
  14207. inputSourcesMap.clear();
  14208. //
  14209. renderer.setFramebuffer( null );
  14210. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  14211. animation.stop();
  14212. scope.isPresenting = false;
  14213. scope.dispatchEvent( { type: 'sessionend' } );
  14214. }
  14215. function onRequestReferenceSpace( value ) {
  14216. referenceSpace = value;
  14217. animation.setContext( session );
  14218. animation.start();
  14219. scope.isPresenting = true;
  14220. scope.dispatchEvent( { type: 'sessionstart' } );
  14221. }
  14222. this.setFramebufferScaleFactor = function ( value ) {
  14223. framebufferScaleFactor = value;
  14224. if ( scope.isPresenting === true ) {
  14225. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  14226. }
  14227. };
  14228. this.setReferenceSpaceType = function ( value ) {
  14229. referenceSpaceType = value;
  14230. if ( scope.isPresenting === true ) {
  14231. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  14232. }
  14233. };
  14234. this.getReferenceSpace = function () {
  14235. return referenceSpace;
  14236. };
  14237. this.getSession = function () {
  14238. return session;
  14239. };
  14240. this.setSession = function ( value ) {
  14241. session = value;
  14242. if ( session !== null ) {
  14243. session.addEventListener( 'select', onSessionEvent );
  14244. session.addEventListener( 'selectstart', onSessionEvent );
  14245. session.addEventListener( 'selectend', onSessionEvent );
  14246. session.addEventListener( 'squeeze', onSessionEvent );
  14247. session.addEventListener( 'squeezestart', onSessionEvent );
  14248. session.addEventListener( 'squeezeend', onSessionEvent );
  14249. session.addEventListener( 'end', onSessionEnd );
  14250. var attributes = gl.getContextAttributes();
  14251. if ( attributes.xrCompatible !== true ) {
  14252. gl.makeXRCompatible();
  14253. }
  14254. var layerInit = {
  14255. antialias: attributes.antialias,
  14256. alpha: attributes.alpha,
  14257. depth: attributes.depth,
  14258. stencil: attributes.stencil,
  14259. framebufferScaleFactor: framebufferScaleFactor
  14260. };
  14261. // eslint-disable-next-line no-undef
  14262. var baseLayer = new XRWebGLLayer( session, gl, layerInit );
  14263. session.updateRenderState( { baseLayer: baseLayer } );
  14264. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  14265. //
  14266. session.addEventListener( 'inputsourceschange', updateInputSources );
  14267. }
  14268. };
  14269. function updateInputSources( event ) {
  14270. var inputSources = session.inputSources;
  14271. // Assign inputSources to available controllers
  14272. for ( var i = 0; i < controllers.length; i ++ ) {
  14273. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  14274. }
  14275. // Notify disconnected
  14276. for ( var i$1 = 0; i$1 < event.removed.length; i$1 ++ ) {
  14277. var inputSource = event.removed[ i$1 ];
  14278. var controller = inputSourcesMap.get( inputSource );
  14279. if ( controller ) {
  14280. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  14281. inputSourcesMap.delete( inputSource );
  14282. }
  14283. }
  14284. // Notify connected
  14285. for ( var i$2 = 0; i$2 < event.added.length; i$2 ++ ) {
  14286. var inputSource$1 = event.added[ i$2 ];
  14287. var controller$1 = inputSourcesMap.get( inputSource$1 );
  14288. if ( controller$1 ) {
  14289. controller$1.dispatchEvent( { type: 'connected', data: inputSource$1 } );
  14290. }
  14291. }
  14292. }
  14293. //
  14294. var cameraLPos = new Vector3();
  14295. var cameraRPos = new Vector3();
  14296. /**
  14297. * @author jsantell / https://www.jsantell.com/
  14298. *
  14299. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14300. * the cameras' projection and world matrices have already been set.
  14301. * And that near and far planes are identical for both cameras.
  14302. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14303. */
  14304. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  14305. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  14306. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  14307. var ipd = cameraLPos.distanceTo( cameraRPos );
  14308. var projL = cameraL.projectionMatrix.elements;
  14309. var projR = cameraR.projectionMatrix.elements;
  14310. // VR systems will have identical far and near planes, and
  14311. // most likely identical top and bottom frustum extents.
  14312. // Use the left camera for these values.
  14313. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  14314. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  14315. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  14316. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  14317. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  14318. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  14319. var left = near * leftFov;
  14320. var right = near * rightFov;
  14321. // Calculate the new camera's position offset from the
  14322. // left camera. xOffset should be roughly half `ipd`.
  14323. var zOffset = ipd / ( - leftFov + rightFov );
  14324. var xOffset = zOffset * - leftFov;
  14325. // TODO: Better way to apply this offset?
  14326. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  14327. camera.translateX( xOffset );
  14328. camera.translateZ( zOffset );
  14329. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  14330. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14331. // Find the union of the frustum values of the cameras and scale
  14332. // the values so that the near plane's position does not change in world space,
  14333. // although must now be relative to the new union camera.
  14334. var near2 = near + zOffset;
  14335. var far2 = far + zOffset;
  14336. var left2 = left - xOffset;
  14337. var right2 = right + ( ipd - xOffset );
  14338. var top2 = topFov * far / far2 * near2;
  14339. var bottom2 = bottomFov * far / far2 * near2;
  14340. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  14341. }
  14342. function updateCamera( camera, parent ) {
  14343. if ( parent === null ) {
  14344. camera.matrixWorld.copy( camera.matrix );
  14345. } else {
  14346. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  14347. }
  14348. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14349. }
  14350. this.getCamera = function ( camera ) {
  14351. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14352. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14353. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  14354. // Note that the new renderState won't apply until the next frame. See #18320
  14355. session.updateRenderState( {
  14356. depthNear: cameraVR.near,
  14357. depthFar: cameraVR.far
  14358. } );
  14359. _currentDepthNear = cameraVR.near;
  14360. _currentDepthFar = cameraVR.far;
  14361. }
  14362. var parent = camera.parent;
  14363. var cameras = cameraVR.cameras;
  14364. updateCamera( cameraVR, parent );
  14365. for ( var i = 0; i < cameras.length; i ++ ) {
  14366. updateCamera( cameras[ i ], parent );
  14367. }
  14368. // update camera and its children
  14369. camera.matrixWorld.copy( cameraVR.matrixWorld );
  14370. var children = camera.children;
  14371. for ( var i$1 = 0, l = children.length; i$1 < l; i$1 ++ ) {
  14372. children[ i$1 ].updateMatrixWorld( true );
  14373. }
  14374. // update projection matrix for proper view frustum culling
  14375. if ( cameras.length === 2 ) {
  14376. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14377. } else {
  14378. // assume single camera setup (AR)
  14379. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  14380. }
  14381. return cameraVR;
  14382. };
  14383. // Animation Loop
  14384. var onAnimationFrameCallback = null;
  14385. function onAnimationFrame( time, frame ) {
  14386. pose = frame.getViewerPose( referenceSpace );
  14387. if ( pose !== null ) {
  14388. var views = pose.views;
  14389. var baseLayer = session.renderState.baseLayer;
  14390. renderer.setFramebuffer( baseLayer.framebuffer );
  14391. var cameraVRNeedsUpdate = false;
  14392. // check if it's necessary to rebuild cameraVR's camera list
  14393. if ( views.length !== cameraVR.cameras.length ) {
  14394. cameraVR.cameras.length = 0;
  14395. cameraVRNeedsUpdate = true;
  14396. }
  14397. for ( var i = 0; i < views.length; i ++ ) {
  14398. var view = views[ i ];
  14399. var viewport = baseLayer.getViewport( view );
  14400. var camera = cameras[ i ];
  14401. camera.matrix.fromArray( view.transform.matrix );
  14402. camera.projectionMatrix.fromArray( view.projectionMatrix );
  14403. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  14404. if ( i === 0 ) {
  14405. cameraVR.matrix.copy( camera.matrix );
  14406. }
  14407. if ( cameraVRNeedsUpdate === true ) {
  14408. cameraVR.cameras.push( camera );
  14409. }
  14410. }
  14411. }
  14412. //
  14413. var inputSources = session.inputSources;
  14414. for ( var i$1 = 0; i$1 < controllers.length; i$1 ++ ) {
  14415. var controller = controllers[ i$1 ];
  14416. var inputSource = inputSources[ i$1 ];
  14417. controller.update( inputSource, frame, referenceSpace );
  14418. }
  14419. if ( onAnimationFrameCallback ) { onAnimationFrameCallback( time, frame ); }
  14420. }
  14421. var animation = new WebGLAnimation();
  14422. animation.setAnimationLoop( onAnimationFrame );
  14423. this.setAnimationLoop = function ( callback ) {
  14424. onAnimationFrameCallback = callback;
  14425. };
  14426. this.dispose = function () {};
  14427. }
  14428. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  14429. /**
  14430. * @author mrdoob / http://mrdoob.com/
  14431. */
  14432. function WebGLMaterials( properties ) {
  14433. function refreshFogUniforms( uniforms, fog ) {
  14434. uniforms.fogColor.value.copy( fog.color );
  14435. if ( fog.isFog ) {
  14436. uniforms.fogNear.value = fog.near;
  14437. uniforms.fogFar.value = fog.far;
  14438. } else if ( fog.isFogExp2 ) {
  14439. uniforms.fogDensity.value = fog.density;
  14440. }
  14441. }
  14442. function refreshMaterialUniforms( uniforms, material, environment, pixelRatio, height ) {
  14443. if ( material.isMeshBasicMaterial ) {
  14444. refreshUniformsCommon( uniforms, material );
  14445. } else if ( material.isMeshLambertMaterial ) {
  14446. refreshUniformsCommon( uniforms, material );
  14447. refreshUniformsLambert( uniforms, material );
  14448. } else if ( material.isMeshToonMaterial ) {
  14449. refreshUniformsCommon( uniforms, material );
  14450. refreshUniformsToon( uniforms, material );
  14451. } else if ( material.isMeshPhongMaterial ) {
  14452. refreshUniformsCommon( uniforms, material );
  14453. refreshUniformsPhong( uniforms, material );
  14454. } else if ( material.isMeshStandardMaterial ) {
  14455. refreshUniformsCommon( uniforms, material, environment );
  14456. if ( material.isMeshPhysicalMaterial ) {
  14457. refreshUniformsPhysical( uniforms, material, environment );
  14458. } else {
  14459. refreshUniformsStandard( uniforms, material, environment );
  14460. }
  14461. } else if ( material.isMeshMatcapMaterial ) {
  14462. refreshUniformsCommon( uniforms, material );
  14463. refreshUniformsMatcap( uniforms, material );
  14464. } else if ( material.isMeshDepthMaterial ) {
  14465. refreshUniformsCommon( uniforms, material );
  14466. refreshUniformsDepth( uniforms, material );
  14467. } else if ( material.isMeshDistanceMaterial ) {
  14468. refreshUniformsCommon( uniforms, material );
  14469. refreshUniformsDistance( uniforms, material );
  14470. } else if ( material.isMeshNormalMaterial ) {
  14471. refreshUniformsCommon( uniforms, material );
  14472. refreshUniformsNormal( uniforms, material );
  14473. } else if ( material.isLineBasicMaterial ) {
  14474. refreshUniformsLine( uniforms, material );
  14475. if ( material.isLineDashedMaterial ) {
  14476. refreshUniformsDash( uniforms, material );
  14477. }
  14478. } else if ( material.isPointsMaterial ) {
  14479. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  14480. } else if ( material.isSpriteMaterial ) {
  14481. refreshUniformsSprites( uniforms, material );
  14482. } else if ( material.isShadowMaterial ) {
  14483. uniforms.color.value.copy( material.color );
  14484. uniforms.opacity.value = material.opacity;
  14485. } else if ( material.isShaderMaterial ) {
  14486. material.uniformsNeedUpdate = false; // #15581
  14487. }
  14488. }
  14489. function refreshUniformsCommon( uniforms, material, environment ) {
  14490. uniforms.opacity.value = material.opacity;
  14491. if ( material.color ) {
  14492. uniforms.diffuse.value.copy( material.color );
  14493. }
  14494. if ( material.emissive ) {
  14495. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14496. }
  14497. if ( material.map ) {
  14498. uniforms.map.value = material.map;
  14499. }
  14500. if ( material.alphaMap ) {
  14501. uniforms.alphaMap.value = material.alphaMap;
  14502. }
  14503. if ( material.specularMap ) {
  14504. uniforms.specularMap.value = material.specularMap;
  14505. }
  14506. var envMap = material.envMap || environment;
  14507. if ( envMap ) {
  14508. uniforms.envMap.value = envMap;
  14509. uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1;
  14510. uniforms.reflectivity.value = material.reflectivity;
  14511. uniforms.refractionRatio.value = material.refractionRatio;
  14512. uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel;
  14513. }
  14514. if ( material.lightMap ) {
  14515. uniforms.lightMap.value = material.lightMap;
  14516. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14517. }
  14518. if ( material.aoMap ) {
  14519. uniforms.aoMap.value = material.aoMap;
  14520. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14521. }
  14522. // uv repeat and offset setting priorities
  14523. // 1. color map
  14524. // 2. specular map
  14525. // 3. normal map
  14526. // 4. bump map
  14527. // 5. alpha map
  14528. // 6. emissive map
  14529. var uvScaleMap;
  14530. if ( material.map ) {
  14531. uvScaleMap = material.map;
  14532. } else if ( material.specularMap ) {
  14533. uvScaleMap = material.specularMap;
  14534. } else if ( material.displacementMap ) {
  14535. uvScaleMap = material.displacementMap;
  14536. } else if ( material.normalMap ) {
  14537. uvScaleMap = material.normalMap;
  14538. } else if ( material.bumpMap ) {
  14539. uvScaleMap = material.bumpMap;
  14540. } else if ( material.roughnessMap ) {
  14541. uvScaleMap = material.roughnessMap;
  14542. } else if ( material.metalnessMap ) {
  14543. uvScaleMap = material.metalnessMap;
  14544. } else if ( material.alphaMap ) {
  14545. uvScaleMap = material.alphaMap;
  14546. } else if ( material.emissiveMap ) {
  14547. uvScaleMap = material.emissiveMap;
  14548. }
  14549. if ( uvScaleMap !== undefined ) {
  14550. // backwards compatibility
  14551. if ( uvScaleMap.isWebGLRenderTarget ) {
  14552. uvScaleMap = uvScaleMap.texture;
  14553. }
  14554. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14555. uvScaleMap.updateMatrix();
  14556. }
  14557. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14558. }
  14559. // uv repeat and offset setting priorities for uv2
  14560. // 1. ao map
  14561. // 2. light map
  14562. var uv2ScaleMap;
  14563. if ( material.aoMap ) {
  14564. uv2ScaleMap = material.aoMap;
  14565. } else if ( material.lightMap ) {
  14566. uv2ScaleMap = material.lightMap;
  14567. }
  14568. if ( uv2ScaleMap !== undefined ) {
  14569. // backwards compatibility
  14570. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  14571. uv2ScaleMap = uv2ScaleMap.texture;
  14572. }
  14573. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  14574. uv2ScaleMap.updateMatrix();
  14575. }
  14576. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  14577. }
  14578. }
  14579. function refreshUniformsLine( uniforms, material ) {
  14580. uniforms.diffuse.value.copy( material.color );
  14581. uniforms.opacity.value = material.opacity;
  14582. }
  14583. function refreshUniformsDash( uniforms, material ) {
  14584. uniforms.dashSize.value = material.dashSize;
  14585. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14586. uniforms.scale.value = material.scale;
  14587. }
  14588. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  14589. uniforms.diffuse.value.copy( material.color );
  14590. uniforms.opacity.value = material.opacity;
  14591. uniforms.size.value = material.size * pixelRatio;
  14592. uniforms.scale.value = height * 0.5;
  14593. if ( material.map ) {
  14594. uniforms.map.value = material.map;
  14595. }
  14596. if ( material.alphaMap ) {
  14597. uniforms.alphaMap.value = material.alphaMap;
  14598. }
  14599. // uv repeat and offset setting priorities
  14600. // 1. color map
  14601. // 2. alpha map
  14602. var uvScaleMap;
  14603. if ( material.map ) {
  14604. uvScaleMap = material.map;
  14605. } else if ( material.alphaMap ) {
  14606. uvScaleMap = material.alphaMap;
  14607. }
  14608. if ( uvScaleMap !== undefined ) {
  14609. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14610. uvScaleMap.updateMatrix();
  14611. }
  14612. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14613. }
  14614. }
  14615. function refreshUniformsSprites( uniforms, material ) {
  14616. uniforms.diffuse.value.copy( material.color );
  14617. uniforms.opacity.value = material.opacity;
  14618. uniforms.rotation.value = material.rotation;
  14619. if ( material.map ) {
  14620. uniforms.map.value = material.map;
  14621. }
  14622. if ( material.alphaMap ) {
  14623. uniforms.alphaMap.value = material.alphaMap;
  14624. }
  14625. // uv repeat and offset setting priorities
  14626. // 1. color map
  14627. // 2. alpha map
  14628. var uvScaleMap;
  14629. if ( material.map ) {
  14630. uvScaleMap = material.map;
  14631. } else if ( material.alphaMap ) {
  14632. uvScaleMap = material.alphaMap;
  14633. }
  14634. if ( uvScaleMap !== undefined ) {
  14635. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14636. uvScaleMap.updateMatrix();
  14637. }
  14638. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14639. }
  14640. }
  14641. function refreshUniformsLambert( uniforms, material ) {
  14642. if ( material.emissiveMap ) {
  14643. uniforms.emissiveMap.value = material.emissiveMap;
  14644. }
  14645. }
  14646. function refreshUniformsPhong( uniforms, material ) {
  14647. uniforms.specular.value.copy( material.specular );
  14648. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14649. if ( material.emissiveMap ) {
  14650. uniforms.emissiveMap.value = material.emissiveMap;
  14651. }
  14652. if ( material.bumpMap ) {
  14653. uniforms.bumpMap.value = material.bumpMap;
  14654. uniforms.bumpScale.value = material.bumpScale;
  14655. if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; }
  14656. }
  14657. if ( material.normalMap ) {
  14658. uniforms.normalMap.value = material.normalMap;
  14659. uniforms.normalScale.value.copy( material.normalScale );
  14660. if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); }
  14661. }
  14662. if ( material.displacementMap ) {
  14663. uniforms.displacementMap.value = material.displacementMap;
  14664. uniforms.displacementScale.value = material.displacementScale;
  14665. uniforms.displacementBias.value = material.displacementBias;
  14666. }
  14667. }
  14668. function refreshUniformsToon( uniforms, material ) {
  14669. if ( material.gradientMap ) {
  14670. uniforms.gradientMap.value = material.gradientMap;
  14671. }
  14672. if ( material.emissiveMap ) {
  14673. uniforms.emissiveMap.value = material.emissiveMap;
  14674. }
  14675. if ( material.bumpMap ) {
  14676. uniforms.bumpMap.value = material.bumpMap;
  14677. uniforms.bumpScale.value = material.bumpScale;
  14678. if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; }
  14679. }
  14680. if ( material.normalMap ) {
  14681. uniforms.normalMap.value = material.normalMap;
  14682. uniforms.normalScale.value.copy( material.normalScale );
  14683. if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); }
  14684. }
  14685. if ( material.displacementMap ) {
  14686. uniforms.displacementMap.value = material.displacementMap;
  14687. uniforms.displacementScale.value = material.displacementScale;
  14688. uniforms.displacementBias.value = material.displacementBias;
  14689. }
  14690. }
  14691. function refreshUniformsStandard( uniforms, material, environment ) {
  14692. uniforms.roughness.value = material.roughness;
  14693. uniforms.metalness.value = material.metalness;
  14694. if ( material.roughnessMap ) {
  14695. uniforms.roughnessMap.value = material.roughnessMap;
  14696. }
  14697. if ( material.metalnessMap ) {
  14698. uniforms.metalnessMap.value = material.metalnessMap;
  14699. }
  14700. if ( material.emissiveMap ) {
  14701. uniforms.emissiveMap.value = material.emissiveMap;
  14702. }
  14703. if ( material.bumpMap ) {
  14704. uniforms.bumpMap.value = material.bumpMap;
  14705. uniforms.bumpScale.value = material.bumpScale;
  14706. if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; }
  14707. }
  14708. if ( material.normalMap ) {
  14709. uniforms.normalMap.value = material.normalMap;
  14710. uniforms.normalScale.value.copy( material.normalScale );
  14711. if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); }
  14712. }
  14713. if ( material.displacementMap ) {
  14714. uniforms.displacementMap.value = material.displacementMap;
  14715. uniforms.displacementScale.value = material.displacementScale;
  14716. uniforms.displacementBias.value = material.displacementBias;
  14717. }
  14718. if ( material.envMap || environment ) {
  14719. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14720. uniforms.envMapIntensity.value = material.envMapIntensity;
  14721. }
  14722. }
  14723. function refreshUniformsPhysical( uniforms, material, environment ) {
  14724. refreshUniformsStandard( uniforms, material, environment );
  14725. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14726. uniforms.clearcoat.value = material.clearcoat;
  14727. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14728. if ( material.sheen ) { uniforms.sheen.value.copy( material.sheen ); }
  14729. if ( material.clearcoatMap ) {
  14730. uniforms.clearcoatMap.value = material.clearcoatMap;
  14731. }
  14732. if ( material.clearcoatRoughnessMap ) {
  14733. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14734. }
  14735. if ( material.clearcoatNormalMap ) {
  14736. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  14737. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14738. if ( material.side === BackSide ) {
  14739. uniforms.clearcoatNormalScale.value.negate();
  14740. }
  14741. }
  14742. uniforms.transparency.value = material.transparency;
  14743. }
  14744. function refreshUniformsMatcap( uniforms, material ) {
  14745. if ( material.matcap ) {
  14746. uniforms.matcap.value = material.matcap;
  14747. }
  14748. if ( material.bumpMap ) {
  14749. uniforms.bumpMap.value = material.bumpMap;
  14750. uniforms.bumpScale.value = material.bumpScale;
  14751. if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; }
  14752. }
  14753. if ( material.normalMap ) {
  14754. uniforms.normalMap.value = material.normalMap;
  14755. uniforms.normalScale.value.copy( material.normalScale );
  14756. if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); }
  14757. }
  14758. if ( material.displacementMap ) {
  14759. uniforms.displacementMap.value = material.displacementMap;
  14760. uniforms.displacementScale.value = material.displacementScale;
  14761. uniforms.displacementBias.value = material.displacementBias;
  14762. }
  14763. }
  14764. function refreshUniformsDepth( uniforms, material ) {
  14765. if ( material.displacementMap ) {
  14766. uniforms.displacementMap.value = material.displacementMap;
  14767. uniforms.displacementScale.value = material.displacementScale;
  14768. uniforms.displacementBias.value = material.displacementBias;
  14769. }
  14770. }
  14771. function refreshUniformsDistance( uniforms, material ) {
  14772. if ( material.displacementMap ) {
  14773. uniforms.displacementMap.value = material.displacementMap;
  14774. uniforms.displacementScale.value = material.displacementScale;
  14775. uniforms.displacementBias.value = material.displacementBias;
  14776. }
  14777. uniforms.referencePosition.value.copy( material.referencePosition );
  14778. uniforms.nearDistance.value = material.nearDistance;
  14779. uniforms.farDistance.value = material.farDistance;
  14780. }
  14781. function refreshUniformsNormal( uniforms, material ) {
  14782. if ( material.bumpMap ) {
  14783. uniforms.bumpMap.value = material.bumpMap;
  14784. uniforms.bumpScale.value = material.bumpScale;
  14785. if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; }
  14786. }
  14787. if ( material.normalMap ) {
  14788. uniforms.normalMap.value = material.normalMap;
  14789. uniforms.normalScale.value.copy( material.normalScale );
  14790. if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); }
  14791. }
  14792. if ( material.displacementMap ) {
  14793. uniforms.displacementMap.value = material.displacementMap;
  14794. uniforms.displacementScale.value = material.displacementScale;
  14795. uniforms.displacementBias.value = material.displacementBias;
  14796. }
  14797. }
  14798. return {
  14799. refreshFogUniforms: refreshFogUniforms,
  14800. refreshMaterialUniforms: refreshMaterialUniforms
  14801. };
  14802. }
  14803. /**
  14804. * @author supereggbert / http://www.paulbrunt.co.uk/
  14805. * @author mrdoob / http://mrdoob.com/
  14806. * @author alteredq / http://alteredqualia.com/
  14807. * @author szimek / https://github.com/szimek/
  14808. * @author tschw
  14809. */
  14810. function WebGLRenderer( parameters ) {
  14811. parameters = parameters || {};
  14812. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14813. _context = parameters.context !== undefined ? parameters.context : null,
  14814. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14815. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14816. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14817. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14818. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14819. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14820. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14821. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14822. var currentRenderList = null;
  14823. var currentRenderState = null;
  14824. // public properties
  14825. this.domElement = _canvas;
  14826. // Debug configuration container
  14827. this.debug = {
  14828. /**
  14829. * Enables error checking and reporting when shader programs are being compiled
  14830. * @type {boolean}
  14831. */
  14832. checkShaderErrors: true
  14833. };
  14834. // clearing
  14835. this.autoClear = true;
  14836. this.autoClearColor = true;
  14837. this.autoClearDepth = true;
  14838. this.autoClearStencil = true;
  14839. // scene graph
  14840. this.sortObjects = true;
  14841. // user-defined clipping
  14842. this.clippingPlanes = [];
  14843. this.localClippingEnabled = false;
  14844. // physically based shading
  14845. this.gammaFactor = 2.0; // for backwards compatibility
  14846. this.outputEncoding = LinearEncoding;
  14847. // physical lights
  14848. this.physicallyCorrectLights = false;
  14849. // tone mapping
  14850. this.toneMapping = NoToneMapping;
  14851. this.toneMappingExposure = 1.0;
  14852. // morphs
  14853. this.maxMorphTargets = 8;
  14854. this.maxMorphNormals = 4;
  14855. // internal properties
  14856. var _this = this;
  14857. var _isContextLost = false;
  14858. // internal state cache
  14859. var _framebuffer = null;
  14860. var _currentActiveCubeFace = 0;
  14861. var _currentActiveMipmapLevel = 0;
  14862. var _currentRenderTarget = null;
  14863. var _currentFramebuffer = null;
  14864. var _currentMaterialId = - 1;
  14865. var _currentCamera = null;
  14866. var _currentArrayCamera = null;
  14867. var _currentViewport = new Vector4();
  14868. var _currentScissor = new Vector4();
  14869. var _currentScissorTest = null;
  14870. //
  14871. var _width = _canvas.width;
  14872. var _height = _canvas.height;
  14873. var _pixelRatio = 1;
  14874. var _opaqueSort = null;
  14875. var _transparentSort = null;
  14876. var _viewport = new Vector4( 0, 0, _width, _height );
  14877. var _scissor = new Vector4( 0, 0, _width, _height );
  14878. var _scissorTest = false;
  14879. // frustum
  14880. var _frustum = new Frustum();
  14881. // clipping
  14882. var _clipping = new WebGLClipping();
  14883. var _clippingEnabled = false;
  14884. var _localClippingEnabled = false;
  14885. // camera matrices cache
  14886. var _projScreenMatrix = new Matrix4();
  14887. var _vector3 = new Vector3();
  14888. var _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
  14889. function getTargetPixelRatio() {
  14890. return _currentRenderTarget === null ? _pixelRatio : 1;
  14891. }
  14892. // initialize
  14893. var _gl = _context;
  14894. function getContext( contextNames, contextAttributes ) {
  14895. for ( var i = 0; i < contextNames.length; i ++ ) {
  14896. var contextName = contextNames[ i ];
  14897. var context = _canvas.getContext( contextName, contextAttributes );
  14898. if ( context !== null ) { return context; }
  14899. }
  14900. return null;
  14901. }
  14902. try {
  14903. var contextAttributes = {
  14904. alpha: _alpha,
  14905. depth: _depth,
  14906. stencil: _stencil,
  14907. antialias: _antialias,
  14908. premultipliedAlpha: _premultipliedAlpha,
  14909. preserveDrawingBuffer: _preserveDrawingBuffer,
  14910. powerPreference: _powerPreference,
  14911. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14912. };
  14913. // event listeners must be registered before WebGL context is created, see #12753
  14914. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14915. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  14916. if ( _gl === null ) {
  14917. var contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
  14918. if ( _this.isWebGL1Renderer === true ) {
  14919. contextNames.shift();
  14920. }
  14921. _gl = getContext( contextNames, contextAttributes );
  14922. if ( _gl === null ) {
  14923. if ( getContext( contextNames ) ) {
  14924. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14925. } else {
  14926. throw new Error( 'Error creating WebGL context.' );
  14927. }
  14928. }
  14929. }
  14930. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14931. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14932. _gl.getShaderPrecisionFormat = function () {
  14933. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14934. };
  14935. }
  14936. } catch ( error ) {
  14937. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14938. throw error;
  14939. }
  14940. var extensions, capabilities, state, info;
  14941. var properties, textures, attributes, geometries, objects;
  14942. var programCache, materials, renderLists, renderStates;
  14943. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14944. var utils, bindingStates;
  14945. function initGLContext() {
  14946. extensions = new WebGLExtensions( _gl );
  14947. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14948. if ( capabilities.isWebGL2 === false ) {
  14949. extensions.get( 'WEBGL_depth_texture' );
  14950. extensions.get( 'OES_texture_float' );
  14951. extensions.get( 'OES_texture_half_float' );
  14952. extensions.get( 'OES_texture_half_float_linear' );
  14953. extensions.get( 'OES_standard_derivatives' );
  14954. extensions.get( 'OES_element_index_uint' );
  14955. extensions.get( 'OES_vertex_array_object' );
  14956. extensions.get( 'ANGLE_instanced_arrays' );
  14957. }
  14958. extensions.get( 'OES_texture_float_linear' );
  14959. utils = new WebGLUtils( _gl, extensions, capabilities );
  14960. state = new WebGLState( _gl, extensions, capabilities );
  14961. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14962. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14963. info = new WebGLInfo( _gl );
  14964. properties = new WebGLProperties();
  14965. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14966. attributes = new WebGLAttributes( _gl, capabilities );
  14967. bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
  14968. geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
  14969. objects = new WebGLObjects( _gl, geometries, attributes, info );
  14970. morphtargets = new WebGLMorphtargets( _gl );
  14971. programCache = new WebGLPrograms( _this, extensions, capabilities, bindingStates );
  14972. materials = new WebGLMaterials( properties );
  14973. renderLists = new WebGLRenderLists();
  14974. renderStates = new WebGLRenderStates();
  14975. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  14976. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14977. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14978. info.programs = programCache.programs;
  14979. _this.capabilities = capabilities;
  14980. _this.extensions = extensions;
  14981. _this.properties = properties;
  14982. _this.renderLists = renderLists;
  14983. _this.state = state;
  14984. _this.info = info;
  14985. }
  14986. initGLContext();
  14987. // xr
  14988. var xr = new WebXRManager( _this, _gl );
  14989. this.xr = xr;
  14990. // shadow map
  14991. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14992. this.shadowMap = shadowMap;
  14993. // API
  14994. this.getContext = function () {
  14995. return _gl;
  14996. };
  14997. this.getContextAttributes = function () {
  14998. return _gl.getContextAttributes();
  14999. };
  15000. this.forceContextLoss = function () {
  15001. var extension = extensions.get( 'WEBGL_lose_context' );
  15002. if ( extension ) { extension.loseContext(); }
  15003. };
  15004. this.forceContextRestore = function () {
  15005. var extension = extensions.get( 'WEBGL_lose_context' );
  15006. if ( extension ) { extension.restoreContext(); }
  15007. };
  15008. this.getPixelRatio = function () {
  15009. return _pixelRatio;
  15010. };
  15011. this.setPixelRatio = function ( value ) {
  15012. if ( value === undefined ) { return; }
  15013. _pixelRatio = value;
  15014. this.setSize( _width, _height, false );
  15015. };
  15016. this.getSize = function ( target ) {
  15017. if ( target === undefined ) {
  15018. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  15019. target = new Vector2();
  15020. }
  15021. return target.set( _width, _height );
  15022. };
  15023. this.setSize = function ( width, height, updateStyle ) {
  15024. if ( xr.isPresenting ) {
  15025. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  15026. return;
  15027. }
  15028. _width = width;
  15029. _height = height;
  15030. _canvas.width = Math.floor( width * _pixelRatio );
  15031. _canvas.height = Math.floor( height * _pixelRatio );
  15032. if ( updateStyle !== false ) {
  15033. _canvas.style.width = width + 'px';
  15034. _canvas.style.height = height + 'px';
  15035. }
  15036. this.setViewport( 0, 0, width, height );
  15037. };
  15038. this.getDrawingBufferSize = function ( target ) {
  15039. if ( target === undefined ) {
  15040. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  15041. target = new Vector2();
  15042. }
  15043. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  15044. };
  15045. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  15046. _width = width;
  15047. _height = height;
  15048. _pixelRatio = pixelRatio;
  15049. _canvas.width = Math.floor( width * pixelRatio );
  15050. _canvas.height = Math.floor( height * pixelRatio );
  15051. this.setViewport( 0, 0, width, height );
  15052. };
  15053. this.getCurrentViewport = function ( target ) {
  15054. if ( target === undefined ) {
  15055. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  15056. target = new Vector4();
  15057. }
  15058. return target.copy( _currentViewport );
  15059. };
  15060. this.getViewport = function ( target ) {
  15061. return target.copy( _viewport );
  15062. };
  15063. this.setViewport = function ( x, y, width, height ) {
  15064. if ( x.isVector4 ) {
  15065. _viewport.set( x.x, x.y, x.z, x.w );
  15066. } else {
  15067. _viewport.set( x, y, width, height );
  15068. }
  15069. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  15070. };
  15071. this.getScissor = function ( target ) {
  15072. return target.copy( _scissor );
  15073. };
  15074. this.setScissor = function ( x, y, width, height ) {
  15075. if ( x.isVector4 ) {
  15076. _scissor.set( x.x, x.y, x.z, x.w );
  15077. } else {
  15078. _scissor.set( x, y, width, height );
  15079. }
  15080. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  15081. };
  15082. this.getScissorTest = function () {
  15083. return _scissorTest;
  15084. };
  15085. this.setScissorTest = function ( boolean ) {
  15086. state.setScissorTest( _scissorTest = boolean );
  15087. };
  15088. this.setOpaqueSort = function ( method ) {
  15089. _opaqueSort = method;
  15090. };
  15091. this.setTransparentSort = function ( method ) {
  15092. _transparentSort = method;
  15093. };
  15094. // Clearing
  15095. this.getClearColor = function () {
  15096. return background.getClearColor();
  15097. };
  15098. this.setClearColor = function () {
  15099. background.setClearColor.apply( background, arguments );
  15100. };
  15101. this.getClearAlpha = function () {
  15102. return background.getClearAlpha();
  15103. };
  15104. this.setClearAlpha = function () {
  15105. background.setClearAlpha.apply( background, arguments );
  15106. };
  15107. this.clear = function ( color, depth, stencil ) {
  15108. var bits = 0;
  15109. if ( color === undefined || color ) { bits |= 16384; }
  15110. if ( depth === undefined || depth ) { bits |= 256; }
  15111. if ( stencil === undefined || stencil ) { bits |= 1024; }
  15112. _gl.clear( bits );
  15113. };
  15114. this.clearColor = function () {
  15115. this.clear( true, false, false );
  15116. };
  15117. this.clearDepth = function () {
  15118. this.clear( false, true, false );
  15119. };
  15120. this.clearStencil = function () {
  15121. this.clear( false, false, true );
  15122. };
  15123. //
  15124. this.dispose = function () {
  15125. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  15126. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  15127. renderLists.dispose();
  15128. renderStates.dispose();
  15129. properties.dispose();
  15130. objects.dispose();
  15131. bindingStates.dispose();
  15132. xr.dispose();
  15133. animation.stop();
  15134. };
  15135. // Events
  15136. function onContextLost( event ) {
  15137. event.preventDefault();
  15138. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  15139. _isContextLost = true;
  15140. }
  15141. function onContextRestore( /* event */ ) {
  15142. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  15143. _isContextLost = false;
  15144. initGLContext();
  15145. }
  15146. function onMaterialDispose( event ) {
  15147. var material = event.target;
  15148. material.removeEventListener( 'dispose', onMaterialDispose );
  15149. deallocateMaterial( material );
  15150. }
  15151. // Buffer deallocation
  15152. function deallocateMaterial( material ) {
  15153. releaseMaterialProgramReference( material );
  15154. properties.remove( material );
  15155. }
  15156. function releaseMaterialProgramReference( material ) {
  15157. var programInfo = properties.get( material ).program;
  15158. material.program = undefined;
  15159. if ( programInfo !== undefined ) {
  15160. programCache.releaseProgram( programInfo );
  15161. }
  15162. }
  15163. // Buffer rendering
  15164. function renderObjectImmediate( object, program ) {
  15165. object.render( function ( object ) {
  15166. _this.renderBufferImmediate( object, program );
  15167. } );
  15168. }
  15169. this.renderBufferImmediate = function ( object, program ) {
  15170. bindingStates.initAttributes();
  15171. var buffers = properties.get( object );
  15172. if ( object.hasPositions && ! buffers.position ) { buffers.position = _gl.createBuffer(); }
  15173. if ( object.hasNormals && ! buffers.normal ) { buffers.normal = _gl.createBuffer(); }
  15174. if ( object.hasUvs && ! buffers.uv ) { buffers.uv = _gl.createBuffer(); }
  15175. if ( object.hasColors && ! buffers.color ) { buffers.color = _gl.createBuffer(); }
  15176. var programAttributes = program.getAttributes();
  15177. if ( object.hasPositions ) {
  15178. _gl.bindBuffer( 34962, buffers.position );
  15179. _gl.bufferData( 34962, object.positionArray, 35048 );
  15180. bindingStates.enableAttribute( programAttributes.position );
  15181. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  15182. }
  15183. if ( object.hasNormals ) {
  15184. _gl.bindBuffer( 34962, buffers.normal );
  15185. _gl.bufferData( 34962, object.normalArray, 35048 );
  15186. bindingStates.enableAttribute( programAttributes.normal );
  15187. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  15188. }
  15189. if ( object.hasUvs ) {
  15190. _gl.bindBuffer( 34962, buffers.uv );
  15191. _gl.bufferData( 34962, object.uvArray, 35048 );
  15192. bindingStates.enableAttribute( programAttributes.uv );
  15193. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  15194. }
  15195. if ( object.hasColors ) {
  15196. _gl.bindBuffer( 34962, buffers.color );
  15197. _gl.bufferData( 34962, object.colorArray, 35048 );
  15198. bindingStates.enableAttribute( programAttributes.color );
  15199. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  15200. }
  15201. bindingStates.disableUnusedAttributes();
  15202. _gl.drawArrays( 4, 0, object.count );
  15203. object.count = 0;
  15204. };
  15205. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  15206. if ( scene === null ) { scene = _emptyScene; } // renderBufferDirect second parameter used to be fog (could be null)
  15207. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  15208. var program = setProgram( camera, scene, material, object );
  15209. state.setMaterial( material, frontFaceCW );
  15210. //
  15211. var index = geometry.index;
  15212. var position = geometry.attributes.position;
  15213. //
  15214. if ( index === null ) {
  15215. if ( position === undefined || position.count === 0 ) { return; }
  15216. } else if ( index.count === 0 ) {
  15217. return;
  15218. }
  15219. //
  15220. var rangeFactor = 1;
  15221. if ( material.wireframe === true ) {
  15222. index = geometries.getWireframeAttribute( geometry );
  15223. rangeFactor = 2;
  15224. }
  15225. if ( material.morphTargets || material.morphNormals ) {
  15226. morphtargets.update( object, geometry, material, program );
  15227. }
  15228. bindingStates.setup( object, material, program, geometry, index );
  15229. var attribute;
  15230. var renderer = bufferRenderer;
  15231. if ( index !== null ) {
  15232. attribute = attributes.get( index );
  15233. renderer = indexedBufferRenderer;
  15234. renderer.setIndex( attribute );
  15235. }
  15236. //
  15237. var dataCount = ( index !== null ) ? index.count : position.count;
  15238. var rangeStart = geometry.drawRange.start * rangeFactor;
  15239. var rangeCount = geometry.drawRange.count * rangeFactor;
  15240. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15241. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15242. var drawStart = Math.max( rangeStart, groupStart );
  15243. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15244. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15245. if ( drawCount === 0 ) { return; }
  15246. //
  15247. if ( object.isMesh ) {
  15248. if ( material.wireframe === true ) {
  15249. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15250. renderer.setMode( 1 );
  15251. } else {
  15252. renderer.setMode( 4 );
  15253. }
  15254. } else if ( object.isLine ) {
  15255. var lineWidth = material.linewidth;
  15256. if ( lineWidth === undefined ) { lineWidth = 1; } // Not using Line*Material
  15257. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15258. if ( object.isLineSegments ) {
  15259. renderer.setMode( 1 );
  15260. } else if ( object.isLineLoop ) {
  15261. renderer.setMode( 2 );
  15262. } else {
  15263. renderer.setMode( 3 );
  15264. }
  15265. } else if ( object.isPoints ) {
  15266. renderer.setMode( 0 );
  15267. } else if ( object.isSprite ) {
  15268. renderer.setMode( 4 );
  15269. }
  15270. if ( object.isInstancedMesh ) {
  15271. renderer.renderInstances( geometry, drawStart, drawCount, object.count );
  15272. } else if ( geometry.isInstancedBufferGeometry ) {
  15273. var instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  15274. renderer.renderInstances( geometry, drawStart, drawCount, instanceCount );
  15275. } else {
  15276. renderer.render( drawStart, drawCount );
  15277. }
  15278. };
  15279. // Compile
  15280. this.compile = function ( scene, camera ) {
  15281. currentRenderState = renderStates.get( scene, camera );
  15282. currentRenderState.init();
  15283. scene.traverse( function ( object ) {
  15284. if ( object.isLight ) {
  15285. currentRenderState.pushLight( object );
  15286. if ( object.castShadow ) {
  15287. currentRenderState.pushShadow( object );
  15288. }
  15289. }
  15290. } );
  15291. currentRenderState.setupLights( camera );
  15292. var compiled = new WeakMap();
  15293. scene.traverse( function ( object ) {
  15294. var material = object.material;
  15295. if ( material ) {
  15296. if ( Array.isArray( material ) ) {
  15297. for ( var i = 0; i < material.length; i ++ ) {
  15298. var material2 = material[ i ];
  15299. if ( compiled.has( material2 ) === false ) {
  15300. initMaterial( material2, scene, object );
  15301. compiled.set( material2 );
  15302. }
  15303. }
  15304. } else if ( compiled.has( material ) === false ) {
  15305. initMaterial( material, scene, object );
  15306. compiled.set( material );
  15307. }
  15308. }
  15309. } );
  15310. };
  15311. // Animation Loop
  15312. var onAnimationFrameCallback = null;
  15313. function onAnimationFrame( time ) {
  15314. if ( xr.isPresenting ) { return; }
  15315. if ( onAnimationFrameCallback ) { onAnimationFrameCallback( time ); }
  15316. }
  15317. var animation = new WebGLAnimation();
  15318. animation.setAnimationLoop( onAnimationFrame );
  15319. if ( typeof window !== 'undefined' ) { animation.setContext( window ); }
  15320. this.setAnimationLoop = function ( callback ) {
  15321. onAnimationFrameCallback = callback;
  15322. xr.setAnimationLoop( callback );
  15323. ( callback === null ) ? animation.stop() : animation.start();
  15324. };
  15325. // Rendering
  15326. this.render = function ( scene, camera ) {
  15327. var renderTarget, forceClear;
  15328. if ( arguments[ 2 ] !== undefined ) {
  15329. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  15330. renderTarget = arguments[ 2 ];
  15331. }
  15332. if ( arguments[ 3 ] !== undefined ) {
  15333. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  15334. forceClear = arguments[ 3 ];
  15335. }
  15336. if ( camera !== undefined && camera.isCamera !== true ) {
  15337. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15338. return;
  15339. }
  15340. if ( _isContextLost === true ) { return; }
  15341. // reset caching for this frame
  15342. bindingStates.resetDefaultState();
  15343. _currentMaterialId = - 1;
  15344. _currentCamera = null;
  15345. // update scene graph
  15346. if ( scene.autoUpdate === true ) { scene.updateMatrixWorld(); }
  15347. // update camera matrices and frustum
  15348. if ( camera.parent === null ) { camera.updateMatrixWorld(); }
  15349. if ( xr.enabled === true && xr.isPresenting === true ) {
  15350. camera = xr.getCamera( camera );
  15351. }
  15352. //
  15353. if ( scene.isScene === true ) { scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget ); }
  15354. currentRenderState = renderStates.get( scene, camera );
  15355. currentRenderState.init();
  15356. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15357. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  15358. _localClippingEnabled = this.localClippingEnabled;
  15359. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15360. currentRenderList = renderLists.get( scene, camera );
  15361. currentRenderList.init();
  15362. projectObject( scene, camera, 0, _this.sortObjects );
  15363. currentRenderList.finish();
  15364. if ( _this.sortObjects === true ) {
  15365. currentRenderList.sort( _opaqueSort, _transparentSort );
  15366. }
  15367. //
  15368. if ( _clippingEnabled === true ) { _clipping.beginShadows(); }
  15369. var shadowsArray = currentRenderState.state.shadowsArray;
  15370. shadowMap.render( shadowsArray, scene, camera );
  15371. currentRenderState.setupLights( camera );
  15372. if ( _clippingEnabled === true ) { _clipping.endShadows(); }
  15373. //
  15374. if ( this.info.autoReset === true ) { this.info.reset(); }
  15375. if ( renderTarget !== undefined ) {
  15376. this.setRenderTarget( renderTarget );
  15377. }
  15378. //
  15379. background.render( currentRenderList, scene, camera, forceClear );
  15380. // render scene
  15381. var opaqueObjects = currentRenderList.opaque;
  15382. var transparentObjects = currentRenderList.transparent;
  15383. if ( opaqueObjects.length > 0 ) { renderObjects( opaqueObjects, scene, camera ); }
  15384. if ( transparentObjects.length > 0 ) { renderObjects( transparentObjects, scene, camera ); }
  15385. //
  15386. if ( scene.isScene === true ) { scene.onAfterRender( _this, scene, camera ); }
  15387. //
  15388. if ( _currentRenderTarget !== null ) {
  15389. // Generate mipmap if we're using any kind of mipmap filtering
  15390. textures.updateRenderTargetMipmap( _currentRenderTarget );
  15391. // resolve multisample renderbuffers to a single-sample texture if necessary
  15392. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  15393. }
  15394. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15395. state.buffers.depth.setTest( true );
  15396. state.buffers.depth.setMask( true );
  15397. state.buffers.color.setMask( true );
  15398. state.setPolygonOffset( false );
  15399. // _gl.finish();
  15400. currentRenderList = null;
  15401. currentRenderState = null;
  15402. };
  15403. function projectObject( object, camera, groupOrder, sortObjects ) {
  15404. if ( object.visible === false ) { return; }
  15405. var visible = object.layers.test( camera.layers );
  15406. if ( visible ) {
  15407. if ( object.isGroup ) {
  15408. groupOrder = object.renderOrder;
  15409. } else if ( object.isLOD ) {
  15410. if ( object.autoUpdate === true ) { object.update( camera ); }
  15411. } else if ( object.isLight ) {
  15412. currentRenderState.pushLight( object );
  15413. if ( object.castShadow ) {
  15414. currentRenderState.pushShadow( object );
  15415. }
  15416. } else if ( object.isSprite ) {
  15417. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  15418. if ( sortObjects ) {
  15419. _vector3.setFromMatrixPosition( object.matrixWorld )
  15420. .applyMatrix4( _projScreenMatrix );
  15421. }
  15422. var geometry = objects.update( object );
  15423. var material = object.material;
  15424. if ( material.visible ) {
  15425. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15426. }
  15427. }
  15428. } else if ( object.isImmediateRenderObject ) {
  15429. if ( sortObjects ) {
  15430. _vector3.setFromMatrixPosition( object.matrixWorld )
  15431. .applyMatrix4( _projScreenMatrix );
  15432. }
  15433. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  15434. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  15435. if ( object.isSkinnedMesh ) {
  15436. // update skeleton only once in a frame
  15437. if ( object.skeleton.frame !== info.render.frame ) {
  15438. object.skeleton.update();
  15439. object.skeleton.frame = info.render.frame;
  15440. }
  15441. }
  15442. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  15443. if ( sortObjects ) {
  15444. _vector3.setFromMatrixPosition( object.matrixWorld )
  15445. .applyMatrix4( _projScreenMatrix );
  15446. }
  15447. var geometry$1 = objects.update( object );
  15448. var material$1 = object.material;
  15449. if ( Array.isArray( material$1 ) ) {
  15450. var groups = geometry$1.groups;
  15451. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15452. var group = groups[ i ];
  15453. var groupMaterial = material$1[ group.materialIndex ];
  15454. if ( groupMaterial && groupMaterial.visible ) {
  15455. currentRenderList.push( object, geometry$1, groupMaterial, groupOrder, _vector3.z, group );
  15456. }
  15457. }
  15458. } else if ( material$1.visible ) {
  15459. currentRenderList.push( object, geometry$1, material$1, groupOrder, _vector3.z, null );
  15460. }
  15461. }
  15462. }
  15463. }
  15464. var children = object.children;
  15465. for ( var i$1 = 0, l$1 = children.length; i$1 < l$1; i$1 ++ ) {
  15466. projectObject( children[ i$1 ], camera, groupOrder, sortObjects );
  15467. }
  15468. }
  15469. function renderObjects( renderList, scene, camera ) {
  15470. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15471. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15472. var renderItem = renderList[ i ];
  15473. var object = renderItem.object;
  15474. var geometry = renderItem.geometry;
  15475. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15476. var group = renderItem.group;
  15477. if ( camera.isArrayCamera ) {
  15478. _currentArrayCamera = camera;
  15479. var cameras = camera.cameras;
  15480. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  15481. var camera2 = cameras[ j ];
  15482. if ( object.layers.test( camera2.layers ) ) {
  15483. state.viewport( _currentViewport.copy( camera2.viewport ) );
  15484. currentRenderState.setupLights( camera2 );
  15485. renderObject( object, scene, camera2, geometry, material, group );
  15486. }
  15487. }
  15488. } else {
  15489. _currentArrayCamera = null;
  15490. renderObject( object, scene, camera, geometry, material, group );
  15491. }
  15492. }
  15493. }
  15494. function renderObject( object, scene, camera, geometry, material, group ) {
  15495. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  15496. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15497. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15498. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15499. if ( object.isImmediateRenderObject ) {
  15500. var program = setProgram( camera, scene, material, object );
  15501. state.setMaterial( material );
  15502. bindingStates.reset();
  15503. renderObjectImmediate( object, program );
  15504. } else {
  15505. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  15506. }
  15507. object.onAfterRender( _this, scene, camera, geometry, material, group );
  15508. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15509. }
  15510. function initMaterial( material, scene, object ) {
  15511. if ( scene.isScene !== true ) { scene = _emptyScene; } // scene could be a Mesh, Line, Points, ...
  15512. var materialProperties = properties.get( material );
  15513. var lights = currentRenderState.state.lights;
  15514. var shadowsArray = currentRenderState.state.shadowsArray;
  15515. var lightsStateVersion = lights.state.version;
  15516. var parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object );
  15517. var programCacheKey = programCache.getProgramCacheKey( parameters );
  15518. var program = materialProperties.program;
  15519. var programChange = true;
  15520. if ( program === undefined ) {
  15521. // new material
  15522. material.addEventListener( 'dispose', onMaterialDispose );
  15523. } else if ( program.cacheKey !== programCacheKey ) {
  15524. // changed glsl or parameters
  15525. releaseMaterialProgramReference( material );
  15526. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  15527. materialProperties.lightsStateVersion = lightsStateVersion;
  15528. programChange = false;
  15529. } else if ( parameters.shaderID !== undefined ) {
  15530. // same glsl and uniform list
  15531. return;
  15532. } else {
  15533. // only rebuild uniform list
  15534. programChange = false;
  15535. }
  15536. if ( programChange ) {
  15537. program = programCache.acquireProgram( parameters, programCacheKey );
  15538. materialProperties.program = program;
  15539. materialProperties.uniforms = parameters.uniforms;
  15540. materialProperties.outputEncoding = parameters.outputEncoding;
  15541. material.program = program;
  15542. }
  15543. var programAttributes = program.getAttributes();
  15544. if ( material.morphTargets ) {
  15545. material.numSupportedMorphTargets = 0;
  15546. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15547. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  15548. material.numSupportedMorphTargets ++;
  15549. }
  15550. }
  15551. }
  15552. if ( material.morphNormals ) {
  15553. material.numSupportedMorphNormals = 0;
  15554. for ( var i$1 = 0; i$1 < _this.maxMorphNormals; i$1 ++ ) {
  15555. if ( programAttributes[ 'morphNormal' + i$1 ] >= 0 ) {
  15556. material.numSupportedMorphNormals ++;
  15557. }
  15558. }
  15559. }
  15560. var uniforms = materialProperties.uniforms;
  15561. if ( ! material.isShaderMaterial &&
  15562. ! material.isRawShaderMaterial ||
  15563. material.clipping === true ) {
  15564. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15565. materialProperties.numIntersection = _clipping.numIntersection;
  15566. uniforms.clippingPlanes = _clipping.uniform;
  15567. }
  15568. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15569. materialProperties.fog = scene.fog;
  15570. // store the light setup it was created for
  15571. materialProperties.needsLights = materialNeedsLights( material );
  15572. materialProperties.lightsStateVersion = lightsStateVersion;
  15573. if ( materialProperties.needsLights ) {
  15574. // wire up the material to this renderer's lighting state
  15575. uniforms.ambientLightColor.value = lights.state.ambient;
  15576. uniforms.lightProbe.value = lights.state.probe;
  15577. uniforms.directionalLights.value = lights.state.directional;
  15578. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15579. uniforms.spotLights.value = lights.state.spot;
  15580. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15581. uniforms.rectAreaLights.value = lights.state.rectArea;
  15582. uniforms.pointLights.value = lights.state.point;
  15583. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15584. uniforms.hemisphereLights.value = lights.state.hemi;
  15585. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15586. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15587. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15588. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15589. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15590. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  15591. // TODO (abelnation): add area lights shadow info to uniforms
  15592. }
  15593. var progUniforms = materialProperties.program.getUniforms(),
  15594. uniformsList =
  15595. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15596. materialProperties.uniformsList = uniformsList;
  15597. }
  15598. function setProgram( camera, scene, material, object ) {
  15599. if ( scene.isScene !== true ) { scene = _emptyScene; } // scene could be a Mesh, Line, Points, ...
  15600. textures.resetTextureUnits();
  15601. var fog = scene.fog;
  15602. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15603. var encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15604. var materialProperties = properties.get( material );
  15605. var lights = currentRenderState.state.lights;
  15606. if ( _clippingEnabled === true ) {
  15607. if ( _localClippingEnabled === true || camera !== _currentCamera ) {
  15608. var useCache =
  15609. camera === _currentCamera &&
  15610. material.id === _currentMaterialId;
  15611. // we might want to call this function with some ClippingGroup
  15612. // object instead of the material, once it becomes feasible
  15613. // (#8465, #8379)
  15614. _clipping.setState(
  15615. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  15616. camera, materialProperties, useCache );
  15617. }
  15618. }
  15619. if ( material.version === materialProperties.__version ) {
  15620. if ( materialProperties.program === undefined ) {
  15621. initMaterial( material, scene, object );
  15622. } else if ( material.fog && materialProperties.fog !== fog ) {
  15623. initMaterial( material, scene, object );
  15624. } else if ( materialProperties.environment !== environment ) {
  15625. initMaterial( material, scene, object );
  15626. } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  15627. initMaterial( material, scene, object );
  15628. } else if ( materialProperties.numClippingPlanes !== undefined &&
  15629. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  15630. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  15631. initMaterial( material, scene, object );
  15632. } else if ( materialProperties.outputEncoding !== encoding ) {
  15633. initMaterial( material, scene, object );
  15634. }
  15635. } else {
  15636. initMaterial( material, scene, object );
  15637. materialProperties.__version = material.version;
  15638. }
  15639. var refreshProgram = false;
  15640. var refreshMaterial = false;
  15641. var refreshLights = false;
  15642. var program = materialProperties.program,
  15643. p_uniforms = program.getUniforms(),
  15644. m_uniforms = materialProperties.uniforms;
  15645. if ( state.useProgram( program.program ) ) {
  15646. refreshProgram = true;
  15647. refreshMaterial = true;
  15648. refreshLights = true;
  15649. }
  15650. if ( material.id !== _currentMaterialId ) {
  15651. _currentMaterialId = material.id;
  15652. refreshMaterial = true;
  15653. }
  15654. if ( refreshProgram || _currentCamera !== camera ) {
  15655. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  15656. if ( capabilities.logarithmicDepthBuffer ) {
  15657. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15658. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15659. }
  15660. if ( _currentCamera !== camera ) {
  15661. _currentCamera = camera;
  15662. // lighting uniforms depend on the camera so enforce an update
  15663. // now, in case this material supports lights - or later, when
  15664. // the next material that does gets activated:
  15665. refreshMaterial = true; // set to true on material change
  15666. refreshLights = true; // remains set until update done
  15667. }
  15668. // load material specific uniforms
  15669. // (shader material also gets them for the sake of genericity)
  15670. if ( material.isShaderMaterial ||
  15671. material.isMeshPhongMaterial ||
  15672. material.isMeshToonMaterial ||
  15673. material.isMeshStandardMaterial ||
  15674. material.envMap ) {
  15675. var uCamPos = p_uniforms.map.cameraPosition;
  15676. if ( uCamPos !== undefined ) {
  15677. uCamPos.setValue( _gl,
  15678. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15679. }
  15680. }
  15681. if ( material.isMeshPhongMaterial ||
  15682. material.isMeshToonMaterial ||
  15683. material.isMeshLambertMaterial ||
  15684. material.isMeshBasicMaterial ||
  15685. material.isMeshStandardMaterial ||
  15686. material.isShaderMaterial ) {
  15687. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  15688. }
  15689. if ( material.isMeshPhongMaterial ||
  15690. material.isMeshToonMaterial ||
  15691. material.isMeshLambertMaterial ||
  15692. material.isMeshBasicMaterial ||
  15693. material.isMeshStandardMaterial ||
  15694. material.isShaderMaterial ||
  15695. material.isShadowMaterial ||
  15696. material.skinning ) {
  15697. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15698. }
  15699. }
  15700. // skinning uniforms must be set even if material didn't change
  15701. // auto-setting of texture unit for bone texture must go before other textures
  15702. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15703. if ( material.skinning ) {
  15704. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15705. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15706. var skeleton = object.skeleton;
  15707. if ( skeleton ) {
  15708. var bones = skeleton.bones;
  15709. if ( capabilities.floatVertexTextures ) {
  15710. if ( skeleton.boneTexture === undefined ) {
  15711. // layout (1 matrix = 4 pixels)
  15712. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15713. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15714. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15715. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15716. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15717. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  15718. size = MathUtils.ceilPowerOfTwo( size );
  15719. size = Math.max( size, 4 );
  15720. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  15721. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  15722. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  15723. skeleton.boneMatrices = boneMatrices;
  15724. skeleton.boneTexture = boneTexture;
  15725. skeleton.boneTextureSize = size;
  15726. }
  15727. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  15728. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  15729. } else {
  15730. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15731. }
  15732. }
  15733. }
  15734. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  15735. materialProperties.receiveShadow = object.receiveShadow;
  15736. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  15737. }
  15738. if ( refreshMaterial ) {
  15739. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  15740. if ( materialProperties.needsLights ) {
  15741. // the current material requires lighting info
  15742. // note: all lighting uniforms are always set correctly
  15743. // they simply reference the renderer's state for their
  15744. // values
  15745. //
  15746. // use the current material's .needsUpdate flags to set
  15747. // the GL state when required
  15748. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15749. }
  15750. // refresh uniforms common to several materials
  15751. if ( fog && material.fog ) {
  15752. materials.refreshFogUniforms( m_uniforms, fog );
  15753. }
  15754. materials.refreshMaterialUniforms( m_uniforms, material, environment, _pixelRatio, _height );
  15755. // RectAreaLight Texture
  15756. // TODO (mrdoob): Find a nicer implementation
  15757. if ( m_uniforms.ltc_1 !== undefined ) { m_uniforms.ltc_1.value = UniformsLib.LTC_1; }
  15758. if ( m_uniforms.ltc_2 !== undefined ) { m_uniforms.ltc_2.value = UniformsLib.LTC_2; }
  15759. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15760. }
  15761. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  15762. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15763. material.uniformsNeedUpdate = false;
  15764. }
  15765. if ( material.isSpriteMaterial ) {
  15766. p_uniforms.setValue( _gl, 'center', object.center );
  15767. }
  15768. // common matrices
  15769. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  15770. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  15771. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15772. return program;
  15773. }
  15774. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15775. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15776. uniforms.ambientLightColor.needsUpdate = value;
  15777. uniforms.lightProbe.needsUpdate = value;
  15778. uniforms.directionalLights.needsUpdate = value;
  15779. uniforms.directionalLightShadows.needsUpdate = value;
  15780. uniforms.pointLights.needsUpdate = value;
  15781. uniforms.pointLightShadows.needsUpdate = value;
  15782. uniforms.spotLights.needsUpdate = value;
  15783. uniforms.spotLightShadows.needsUpdate = value;
  15784. uniforms.rectAreaLights.needsUpdate = value;
  15785. uniforms.hemisphereLights.needsUpdate = value;
  15786. }
  15787. function materialNeedsLights( material ) {
  15788. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  15789. material.isMeshStandardMaterial || material.isShadowMaterial ||
  15790. ( material.isShaderMaterial && material.lights === true );
  15791. }
  15792. //
  15793. this.setFramebuffer = function ( value ) {
  15794. if ( _framebuffer !== value && _currentRenderTarget === null ) { _gl.bindFramebuffer( 36160, value ); }
  15795. _framebuffer = value;
  15796. };
  15797. this.getActiveCubeFace = function () {
  15798. return _currentActiveCubeFace;
  15799. };
  15800. this.getActiveMipmapLevel = function () {
  15801. return _currentActiveMipmapLevel;
  15802. };
  15803. this.getRenderTarget = function () {
  15804. return _currentRenderTarget;
  15805. };
  15806. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15807. _currentRenderTarget = renderTarget;
  15808. _currentActiveCubeFace = activeCubeFace;
  15809. _currentActiveMipmapLevel = activeMipmapLevel;
  15810. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15811. textures.setupRenderTarget( renderTarget );
  15812. }
  15813. var framebuffer = _framebuffer;
  15814. var isCube = false;
  15815. if ( renderTarget ) {
  15816. var _webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15817. if ( renderTarget.isWebGLCubeRenderTarget ) {
  15818. framebuffer = _webglFramebuffer[ activeCubeFace || 0 ];
  15819. isCube = true;
  15820. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15821. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15822. } else {
  15823. framebuffer = _webglFramebuffer;
  15824. }
  15825. _currentViewport.copy( renderTarget.viewport );
  15826. _currentScissor.copy( renderTarget.scissor );
  15827. _currentScissorTest = renderTarget.scissorTest;
  15828. } else {
  15829. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15830. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15831. _currentScissorTest = _scissorTest;
  15832. }
  15833. if ( _currentFramebuffer !== framebuffer ) {
  15834. _gl.bindFramebuffer( 36160, framebuffer );
  15835. _currentFramebuffer = framebuffer;
  15836. }
  15837. state.viewport( _currentViewport );
  15838. state.scissor( _currentScissor );
  15839. state.setScissorTest( _currentScissorTest );
  15840. if ( isCube ) {
  15841. var textureProperties = properties.get( renderTarget.texture );
  15842. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15843. }
  15844. };
  15845. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15846. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15847. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15848. return;
  15849. }
  15850. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15851. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  15852. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15853. }
  15854. if ( framebuffer ) {
  15855. var restore = false;
  15856. if ( framebuffer !== _currentFramebuffer ) {
  15857. _gl.bindFramebuffer( 36160, framebuffer );
  15858. restore = true;
  15859. }
  15860. try {
  15861. var texture = renderTarget.texture;
  15862. var textureFormat = texture.format;
  15863. var textureType = texture.type;
  15864. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15865. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15866. return;
  15867. }
  15868. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15869. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15870. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15871. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15872. return;
  15873. }
  15874. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15875. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15876. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15877. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15878. }
  15879. } else {
  15880. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15881. }
  15882. } finally {
  15883. if ( restore ) {
  15884. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15885. }
  15886. }
  15887. }
  15888. };
  15889. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15890. if ( level === undefined ) { level = 0; }
  15891. var levelScale = Math.pow( 2, - level );
  15892. var width = Math.floor( texture.image.width * levelScale );
  15893. var height = Math.floor( texture.image.height * levelScale );
  15894. var glFormat = utils.convert( texture.format );
  15895. textures.setTexture2D( texture, 0 );
  15896. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  15897. state.unbindTexture();
  15898. };
  15899. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15900. if ( level === undefined ) { level = 0; }
  15901. var width = srcTexture.image.width;
  15902. var height = srcTexture.image.height;
  15903. var glFormat = utils.convert( dstTexture.format );
  15904. var glType = utils.convert( dstTexture.type );
  15905. textures.setTexture2D( dstTexture, 0 );
  15906. // As another texture upload may have changed pixelStorei
  15907. // parameters, make sure they are correct for the dstTexture
  15908. _gl.pixelStorei( 37440, dstTexture.flipY );
  15909. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  15910. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  15911. if ( srcTexture.isDataTexture ) {
  15912. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15913. } else {
  15914. if ( srcTexture.isCompressedTexture ) {
  15915. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  15916. } else {
  15917. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  15918. }
  15919. }
  15920. // Generate mipmaps only when copying level 0
  15921. if ( level === 0 && dstTexture.generateMipmaps ) { _gl.generateMipmap( 3553 ); }
  15922. state.unbindTexture();
  15923. };
  15924. this.initTexture = function ( texture ) {
  15925. textures.setTexture2D( texture, 0 );
  15926. state.unbindTexture();
  15927. };
  15928. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15929. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15930. }
  15931. }
  15932. /**
  15933. * @author Mugen87 / https://github.com/Mugen87
  15934. */
  15935. function WebGL1Renderer( parameters ) {
  15936. WebGLRenderer.call( this, parameters );
  15937. }
  15938. WebGL1Renderer.prototype = Object.assign( Object.create( WebGLRenderer.prototype ), {
  15939. constructor: WebGL1Renderer,
  15940. isWebGL1Renderer: true
  15941. } );
  15942. /**
  15943. * @author mrdoob / http://mrdoob.com/
  15944. * @author alteredq / http://alteredqualia.com/
  15945. */
  15946. function FogExp2( color, density ) {
  15947. this.name = '';
  15948. this.color = new Color( color );
  15949. this.density = ( density !== undefined ) ? density : 0.00025;
  15950. }
  15951. Object.assign( FogExp2.prototype, {
  15952. isFogExp2: true,
  15953. clone: function () {
  15954. return new FogExp2( this.color, this.density );
  15955. },
  15956. toJSON: function ( /* meta */ ) {
  15957. return {
  15958. type: 'FogExp2',
  15959. color: this.color.getHex(),
  15960. density: this.density
  15961. };
  15962. }
  15963. } );
  15964. /**
  15965. * @author mrdoob / http://mrdoob.com/
  15966. * @author alteredq / http://alteredqualia.com/
  15967. */
  15968. function Fog( color, near, far ) {
  15969. this.name = '';
  15970. this.color = new Color( color );
  15971. this.near = ( near !== undefined ) ? near : 1;
  15972. this.far = ( far !== undefined ) ? far : 1000;
  15973. }
  15974. Object.assign( Fog.prototype, {
  15975. isFog: true,
  15976. clone: function () {
  15977. return new Fog( this.color, this.near, this.far );
  15978. },
  15979. toJSON: function ( /* meta */ ) {
  15980. return {
  15981. type: 'Fog',
  15982. color: this.color.getHex(),
  15983. near: this.near,
  15984. far: this.far
  15985. };
  15986. }
  15987. } );
  15988. /**
  15989. * @author benaadams / https://twitter.com/ben_a_adams
  15990. */
  15991. function InterleavedBuffer( array, stride ) {
  15992. this.array = array;
  15993. this.stride = stride;
  15994. this.count = array !== undefined ? array.length / stride : 0;
  15995. this.usage = StaticDrawUsage;
  15996. this.updateRange = { offset: 0, count: - 1 };
  15997. this.version = 0;
  15998. this.uuid = MathUtils.generateUUID();
  15999. }
  16000. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  16001. set: function ( value ) {
  16002. if ( value === true ) { this.version ++; }
  16003. }
  16004. } );
  16005. Object.assign( InterleavedBuffer.prototype, {
  16006. isInterleavedBuffer: true,
  16007. onUploadCallback: function () {},
  16008. setUsage: function ( value ) {
  16009. this.usage = value;
  16010. return this;
  16011. },
  16012. copy: function ( source ) {
  16013. this.array = new source.array.constructor( source.array );
  16014. this.count = source.count;
  16015. this.stride = source.stride;
  16016. this.usage = source.usage;
  16017. return this;
  16018. },
  16019. copyAt: function ( index1, attribute, index2 ) {
  16020. index1 *= this.stride;
  16021. index2 *= attribute.stride;
  16022. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  16023. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  16024. }
  16025. return this;
  16026. },
  16027. set: function ( value, offset ) {
  16028. if ( offset === undefined ) { offset = 0; }
  16029. this.array.set( value, offset );
  16030. return this;
  16031. },
  16032. clone: function ( data ) {
  16033. if ( data.arrayBuffers === undefined ) {
  16034. data.arrayBuffers = {};
  16035. }
  16036. if ( this.array.buffer._uuid === undefined ) {
  16037. this.array.buffer._uuid = MathUtils.generateUUID();
  16038. }
  16039. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  16040. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  16041. }
  16042. var array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  16043. var ib = new InterleavedBuffer( array, this.stride );
  16044. ib.setUsage( this.usage );
  16045. return ib;
  16046. },
  16047. onUpload: function ( callback ) {
  16048. this.onUploadCallback = callback;
  16049. return this;
  16050. },
  16051. toJSON: function ( data ) {
  16052. if ( data.arrayBuffers === undefined ) {
  16053. data.arrayBuffers = {};
  16054. }
  16055. // generate UUID for array buffer if necessary
  16056. if ( this.array.buffer._uuid === undefined ) {
  16057. this.array.buffer._uuid = MathUtils.generateUUID();
  16058. }
  16059. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  16060. data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
  16061. }
  16062. //
  16063. return {
  16064. uuid: this.uuid,
  16065. buffer: this.array.buffer._uuid,
  16066. type: this.array.constructor.name,
  16067. stride: this.stride
  16068. };
  16069. }
  16070. } );
  16071. /**
  16072. * @author benaadams / https://twitter.com/ben_a_adams
  16073. */
  16074. var _vector$6 = new Vector3();
  16075. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  16076. this.name = '';
  16077. this.data = interleavedBuffer;
  16078. this.itemSize = itemSize;
  16079. this.offset = offset;
  16080. this.normalized = normalized === true;
  16081. }
  16082. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  16083. count: {
  16084. get: function () {
  16085. return this.data.count;
  16086. }
  16087. },
  16088. array: {
  16089. get: function () {
  16090. return this.data.array;
  16091. }
  16092. }
  16093. } );
  16094. Object.assign( InterleavedBufferAttribute.prototype, {
  16095. isInterleavedBufferAttribute: true,
  16096. applyMatrix4: function ( m ) {
  16097. for ( var i = 0, l = this.data.count; i < l; i ++ ) {
  16098. _vector$6.x = this.getX( i );
  16099. _vector$6.y = this.getY( i );
  16100. _vector$6.z = this.getZ( i );
  16101. _vector$6.applyMatrix4( m );
  16102. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  16103. }
  16104. return this;
  16105. },
  16106. setX: function ( index, x ) {
  16107. this.data.array[ index * this.data.stride + this.offset ] = x;
  16108. return this;
  16109. },
  16110. setY: function ( index, y ) {
  16111. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  16112. return this;
  16113. },
  16114. setZ: function ( index, z ) {
  16115. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  16116. return this;
  16117. },
  16118. setW: function ( index, w ) {
  16119. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  16120. return this;
  16121. },
  16122. getX: function ( index ) {
  16123. return this.data.array[ index * this.data.stride + this.offset ];
  16124. },
  16125. getY: function ( index ) {
  16126. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  16127. },
  16128. getZ: function ( index ) {
  16129. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  16130. },
  16131. getW: function ( index ) {
  16132. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  16133. },
  16134. setXY: function ( index, x, y ) {
  16135. index = index * this.data.stride + this.offset;
  16136. this.data.array[ index + 0 ] = x;
  16137. this.data.array[ index + 1 ] = y;
  16138. return this;
  16139. },
  16140. setXYZ: function ( index, x, y, z ) {
  16141. index = index * this.data.stride + this.offset;
  16142. this.data.array[ index + 0 ] = x;
  16143. this.data.array[ index + 1 ] = y;
  16144. this.data.array[ index + 2 ] = z;
  16145. return this;
  16146. },
  16147. setXYZW: function ( index, x, y, z, w ) {
  16148. index = index * this.data.stride + this.offset;
  16149. this.data.array[ index + 0 ] = x;
  16150. this.data.array[ index + 1 ] = y;
  16151. this.data.array[ index + 2 ] = z;
  16152. this.data.array[ index + 3 ] = w;
  16153. return this;
  16154. },
  16155. clone: function ( data ) {
  16156. if ( data === undefined ) {
  16157. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  16158. var array = [];
  16159. for ( var i = 0; i < this.count; i ++ ) {
  16160. var index = i * this.data.stride + this.offset;
  16161. for ( var j = 0; j < this.itemSize; j ++ ) {
  16162. array.push( this.data.array[ index + j ] );
  16163. }
  16164. }
  16165. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  16166. } else {
  16167. if ( data.interleavedBuffers === undefined ) {
  16168. data.interleavedBuffers = {};
  16169. }
  16170. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  16171. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  16172. }
  16173. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  16174. }
  16175. },
  16176. toJSON: function ( data ) {
  16177. if ( data === undefined ) {
  16178. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  16179. var array = [];
  16180. for ( var i = 0; i < this.count; i ++ ) {
  16181. var index = i * this.data.stride + this.offset;
  16182. for ( var j = 0; j < this.itemSize; j ++ ) {
  16183. array.push( this.data.array[ index + j ] );
  16184. }
  16185. }
  16186. // deinterleave data and save it as an ordinary buffer attribute for now
  16187. return {
  16188. itemSize: this.itemSize,
  16189. type: this.array.constructor.name,
  16190. array: array,
  16191. normalized: this.normalized
  16192. };
  16193. } else {
  16194. // save as true interlaved attribtue
  16195. if ( data.interleavedBuffers === undefined ) {
  16196. data.interleavedBuffers = {};
  16197. }
  16198. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  16199. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  16200. }
  16201. return {
  16202. isInterleavedBufferAttribute: true,
  16203. itemSize: this.itemSize,
  16204. data: this.data.uuid,
  16205. offset: this.offset,
  16206. normalized: this.normalized
  16207. };
  16208. }
  16209. }
  16210. } );
  16211. /**
  16212. * @author alteredq / http://alteredqualia.com/
  16213. *
  16214. * parameters = {
  16215. * color: <hex>,
  16216. * map: new THREE.Texture( <Image> ),
  16217. * alphaMap: new THREE.Texture( <Image> ),
  16218. * rotation: <float>,
  16219. * sizeAttenuation: <bool>
  16220. * }
  16221. */
  16222. function SpriteMaterial( parameters ) {
  16223. Material.call( this );
  16224. this.type = 'SpriteMaterial';
  16225. this.color = new Color( 0xffffff );
  16226. this.map = null;
  16227. this.alphaMap = null;
  16228. this.rotation = 0;
  16229. this.sizeAttenuation = true;
  16230. this.transparent = true;
  16231. this.setValues( parameters );
  16232. }
  16233. SpriteMaterial.prototype = Object.create( Material.prototype );
  16234. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16235. SpriteMaterial.prototype.isSpriteMaterial = true;
  16236. SpriteMaterial.prototype.copy = function ( source ) {
  16237. Material.prototype.copy.call( this, source );
  16238. this.color.copy( source.color );
  16239. this.map = source.map;
  16240. this.alphaMap = source.alphaMap;
  16241. this.rotation = source.rotation;
  16242. this.sizeAttenuation = source.sizeAttenuation;
  16243. return this;
  16244. };
  16245. /**
  16246. * @author mikael emtinger / http://gomo.se/
  16247. * @author alteredq / http://alteredqualia.com/
  16248. */
  16249. var _geometry;
  16250. var _intersectPoint = new Vector3();
  16251. var _worldScale = new Vector3();
  16252. var _mvPosition = new Vector3();
  16253. var _alignedPosition = new Vector2();
  16254. var _rotatedPosition = new Vector2();
  16255. var _viewWorldMatrix = new Matrix4();
  16256. var _vA$1 = new Vector3();
  16257. var _vB$1 = new Vector3();
  16258. var _vC$1 = new Vector3();
  16259. var _uvA$1 = new Vector2();
  16260. var _uvB$1 = new Vector2();
  16261. var _uvC$1 = new Vector2();
  16262. function Sprite( material ) {
  16263. Object3D.call( this );
  16264. this.type = 'Sprite';
  16265. if ( _geometry === undefined ) {
  16266. _geometry = new BufferGeometry();
  16267. var float32Array = new Float32Array( [
  16268. - 0.5, - 0.5, 0, 0, 0,
  16269. 0.5, - 0.5, 0, 1, 0,
  16270. 0.5, 0.5, 0, 1, 1,
  16271. - 0.5, 0.5, 0, 0, 1
  16272. ] );
  16273. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  16274. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  16275. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  16276. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  16277. }
  16278. this.geometry = _geometry;
  16279. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  16280. this.center = new Vector2( 0.5, 0.5 );
  16281. }
  16282. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16283. constructor: Sprite,
  16284. isSprite: true,
  16285. raycast: function ( raycaster, intersects ) {
  16286. if ( raycaster.camera === null ) {
  16287. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  16288. }
  16289. _worldScale.setFromMatrixScale( this.matrixWorld );
  16290. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  16291. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  16292. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  16293. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  16294. _worldScale.multiplyScalar( - _mvPosition.z );
  16295. }
  16296. var rotation = this.material.rotation;
  16297. var sin, cos;
  16298. if ( rotation !== 0 ) {
  16299. cos = Math.cos( rotation );
  16300. sin = Math.sin( rotation );
  16301. }
  16302. var center = this.center;
  16303. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16304. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16305. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16306. _uvA$1.set( 0, 0 );
  16307. _uvB$1.set( 1, 0 );
  16308. _uvC$1.set( 1, 1 );
  16309. // check first triangle
  16310. var intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  16311. if ( intersect === null ) {
  16312. // check second triangle
  16313. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16314. _uvB$1.set( 0, 1 );
  16315. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  16316. if ( intersect === null ) {
  16317. return;
  16318. }
  16319. }
  16320. var distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  16321. if ( distance < raycaster.near || distance > raycaster.far ) { return; }
  16322. intersects.push( {
  16323. distance: distance,
  16324. point: _intersectPoint.clone(),
  16325. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  16326. face: null,
  16327. object: this
  16328. } );
  16329. },
  16330. copy: function ( source ) {
  16331. Object3D.prototype.copy.call( this, source );
  16332. if ( source.center !== undefined ) { this.center.copy( source.center ); }
  16333. this.material = source.material;
  16334. return this;
  16335. }
  16336. } );
  16337. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  16338. // compute position in camera space
  16339. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  16340. // to check if rotation is not zero
  16341. if ( sin !== undefined ) {
  16342. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  16343. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  16344. } else {
  16345. _rotatedPosition.copy( _alignedPosition );
  16346. }
  16347. vertexPosition.copy( mvPosition );
  16348. vertexPosition.x += _rotatedPosition.x;
  16349. vertexPosition.y += _rotatedPosition.y;
  16350. // transform to world space
  16351. vertexPosition.applyMatrix4( _viewWorldMatrix );
  16352. }
  16353. /**
  16354. * @author mikael emtinger / http://gomo.se/
  16355. * @author alteredq / http://alteredqualia.com/
  16356. * @author mrdoob / http://mrdoob.com/
  16357. */
  16358. var _v1$4 = new Vector3();
  16359. var _v2$2 = new Vector3();
  16360. function LOD() {
  16361. Object3D.call( this );
  16362. this._currentLevel = 0;
  16363. this.type = 'LOD';
  16364. Object.defineProperties( this, {
  16365. levels: {
  16366. enumerable: true,
  16367. value: []
  16368. }
  16369. } );
  16370. this.autoUpdate = true;
  16371. }
  16372. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16373. constructor: LOD,
  16374. isLOD: true,
  16375. copy: function ( source ) {
  16376. Object3D.prototype.copy.call( this, source, false );
  16377. var levels = source.levels;
  16378. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16379. var level = levels[ i ];
  16380. this.addLevel( level.object.clone(), level.distance );
  16381. }
  16382. this.autoUpdate = source.autoUpdate;
  16383. return this;
  16384. },
  16385. addLevel: function ( object, distance ) {
  16386. if ( distance === undefined ) { distance = 0; }
  16387. distance = Math.abs( distance );
  16388. var levels = this.levels;
  16389. var l;
  16390. for ( l = 0; l < levels.length; l ++ ) {
  16391. if ( distance < levels[ l ].distance ) {
  16392. break;
  16393. }
  16394. }
  16395. levels.splice( l, 0, { distance: distance, object: object } );
  16396. this.add( object );
  16397. return this;
  16398. },
  16399. getCurrentLevel: function () {
  16400. return this._currentLevel;
  16401. },
  16402. getObjectForDistance: function ( distance ) {
  16403. var levels = this.levels;
  16404. if ( levels.length > 0 ) {
  16405. var i, l;
  16406. for ( i = 1, l = levels.length; i < l; i ++ ) {
  16407. if ( distance < levels[ i ].distance ) {
  16408. break;
  16409. }
  16410. }
  16411. return levels[ i - 1 ].object;
  16412. }
  16413. return null;
  16414. },
  16415. raycast: function ( raycaster, intersects ) {
  16416. var levels = this.levels;
  16417. if ( levels.length > 0 ) {
  16418. _v1$4.setFromMatrixPosition( this.matrixWorld );
  16419. var distance = raycaster.ray.origin.distanceTo( _v1$4 );
  16420. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  16421. }
  16422. },
  16423. update: function ( camera ) {
  16424. var levels = this.levels;
  16425. if ( levels.length > 1 ) {
  16426. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  16427. _v2$2.setFromMatrixPosition( this.matrixWorld );
  16428. var distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom;
  16429. levels[ 0 ].object.visible = true;
  16430. var i, l;
  16431. for ( i = 1, l = levels.length; i < l; i ++ ) {
  16432. if ( distance >= levels[ i ].distance ) {
  16433. levels[ i - 1 ].object.visible = false;
  16434. levels[ i ].object.visible = true;
  16435. } else {
  16436. break;
  16437. }
  16438. }
  16439. this._currentLevel = i - 1;
  16440. for ( ; i < l; i ++ ) {
  16441. levels[ i ].object.visible = false;
  16442. }
  16443. }
  16444. },
  16445. toJSON: function ( meta ) {
  16446. var data = Object3D.prototype.toJSON.call( this, meta );
  16447. if ( this.autoUpdate === false ) { data.object.autoUpdate = false; }
  16448. data.object.levels = [];
  16449. var levels = this.levels;
  16450. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16451. var level = levels[ i ];
  16452. data.object.levels.push( {
  16453. object: level.object.uuid,
  16454. distance: level.distance
  16455. } );
  16456. }
  16457. return data;
  16458. }
  16459. } );
  16460. /**
  16461. * @author mikael emtinger / http://gomo.se/
  16462. * @author alteredq / http://alteredqualia.com/
  16463. * @author ikerr / http://verold.com
  16464. */
  16465. function SkinnedMesh( geometry, material ) {
  16466. if ( geometry && geometry.isGeometry ) {
  16467. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16468. }
  16469. Mesh.call( this, geometry, material );
  16470. this.type = 'SkinnedMesh';
  16471. this.bindMode = 'attached';
  16472. this.bindMatrix = new Matrix4();
  16473. this.bindMatrixInverse = new Matrix4();
  16474. }
  16475. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16476. constructor: SkinnedMesh,
  16477. isSkinnedMesh: true,
  16478. copy: function ( source ) {
  16479. Mesh.prototype.copy.call( this, source );
  16480. this.bindMode = source.bindMode;
  16481. this.bindMatrix.copy( source.bindMatrix );
  16482. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  16483. this.skeleton = source.skeleton;
  16484. return this;
  16485. },
  16486. bind: function ( skeleton, bindMatrix ) {
  16487. this.skeleton = skeleton;
  16488. if ( bindMatrix === undefined ) {
  16489. this.updateMatrixWorld( true );
  16490. this.skeleton.calculateInverses();
  16491. bindMatrix = this.matrixWorld;
  16492. }
  16493. this.bindMatrix.copy( bindMatrix );
  16494. this.bindMatrixInverse.getInverse( bindMatrix );
  16495. },
  16496. pose: function () {
  16497. this.skeleton.pose();
  16498. },
  16499. normalizeSkinWeights: function () {
  16500. var vector = new Vector4();
  16501. var skinWeight = this.geometry.attributes.skinWeight;
  16502. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  16503. vector.x = skinWeight.getX( i );
  16504. vector.y = skinWeight.getY( i );
  16505. vector.z = skinWeight.getZ( i );
  16506. vector.w = skinWeight.getW( i );
  16507. var scale = 1.0 / vector.manhattanLength();
  16508. if ( scale !== Infinity ) {
  16509. vector.multiplyScalar( scale );
  16510. } else {
  16511. vector.set( 1, 0, 0, 0 ); // do something reasonable
  16512. }
  16513. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  16514. }
  16515. },
  16516. updateMatrixWorld: function ( force ) {
  16517. Mesh.prototype.updateMatrixWorld.call( this, force );
  16518. if ( this.bindMode === 'attached' ) {
  16519. this.bindMatrixInverse.getInverse( this.matrixWorld );
  16520. } else if ( this.bindMode === 'detached' ) {
  16521. this.bindMatrixInverse.getInverse( this.bindMatrix );
  16522. } else {
  16523. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  16524. }
  16525. },
  16526. boneTransform: ( function () {
  16527. var basePosition = new Vector3();
  16528. var skinIndex = new Vector4();
  16529. var skinWeight = new Vector4();
  16530. var vector = new Vector3();
  16531. var matrix = new Matrix4();
  16532. return function ( index, target ) {
  16533. var skeleton = this.skeleton;
  16534. var geometry = this.geometry;
  16535. skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  16536. skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  16537. basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  16538. target.set( 0, 0, 0 );
  16539. for ( var i = 0; i < 4; i ++ ) {
  16540. var weight = skinWeight.getComponent( i );
  16541. if ( weight !== 0 ) {
  16542. var boneIndex = skinIndex.getComponent( i );
  16543. matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  16544. target.addScaledVector( vector.copy( basePosition ).applyMatrix4( matrix ), weight );
  16545. }
  16546. }
  16547. return target.applyMatrix4( this.bindMatrixInverse );
  16548. };
  16549. }() )
  16550. } );
  16551. /**
  16552. * @author mikael emtinger / http://gomo.se/
  16553. * @author alteredq / http://alteredqualia.com/
  16554. * @author michael guerrero / http://realitymeltdown.com
  16555. * @author ikerr / http://verold.com
  16556. */
  16557. var _offsetMatrix = new Matrix4();
  16558. var _identityMatrix = new Matrix4();
  16559. function Skeleton( bones, boneInverses ) {
  16560. // copy the bone array
  16561. bones = bones || [];
  16562. this.bones = bones.slice( 0 );
  16563. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  16564. this.frame = - 1;
  16565. // use the supplied bone inverses or calculate the inverses
  16566. if ( boneInverses === undefined ) {
  16567. this.calculateInverses();
  16568. } else {
  16569. if ( this.bones.length === boneInverses.length ) {
  16570. this.boneInverses = boneInverses.slice( 0 );
  16571. } else {
  16572. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  16573. this.boneInverses = [];
  16574. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16575. this.boneInverses.push( new Matrix4() );
  16576. }
  16577. }
  16578. }
  16579. }
  16580. Object.assign( Skeleton.prototype, {
  16581. calculateInverses: function () {
  16582. this.boneInverses = [];
  16583. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16584. var inverse = new Matrix4();
  16585. if ( this.bones[ i ] ) {
  16586. inverse.getInverse( this.bones[ i ].matrixWorld );
  16587. }
  16588. this.boneInverses.push( inverse );
  16589. }
  16590. },
  16591. pose: function () {
  16592. // recover the bind-time world matrices
  16593. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16594. var bone = this.bones[ i ];
  16595. if ( bone ) {
  16596. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  16597. }
  16598. }
  16599. // compute the local matrices, positions, rotations and scales
  16600. for ( var i$1 = 0, il$1 = this.bones.length; i$1 < il$1; i$1 ++ ) {
  16601. var bone$1 = this.bones[ i$1 ];
  16602. if ( bone$1 ) {
  16603. if ( bone$1.parent && bone$1.parent.isBone ) {
  16604. bone$1.matrix.getInverse( bone$1.parent.matrixWorld );
  16605. bone$1.matrix.multiply( bone$1.matrixWorld );
  16606. } else {
  16607. bone$1.matrix.copy( bone$1.matrixWorld );
  16608. }
  16609. bone$1.matrix.decompose( bone$1.position, bone$1.quaternion, bone$1.scale );
  16610. }
  16611. }
  16612. },
  16613. update: function () {
  16614. var bones = this.bones;
  16615. var boneInverses = this.boneInverses;
  16616. var boneMatrices = this.boneMatrices;
  16617. var boneTexture = this.boneTexture;
  16618. // flatten bone matrices to array
  16619. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  16620. // compute the offset between the current and the original transform
  16621. var matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  16622. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  16623. _offsetMatrix.toArray( boneMatrices, i * 16 );
  16624. }
  16625. if ( boneTexture !== undefined ) {
  16626. boneTexture.needsUpdate = true;
  16627. }
  16628. },
  16629. clone: function () {
  16630. return new Skeleton( this.bones, this.boneInverses );
  16631. },
  16632. getBoneByName: function ( name ) {
  16633. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16634. var bone = this.bones[ i ];
  16635. if ( bone.name === name ) {
  16636. return bone;
  16637. }
  16638. }
  16639. return undefined;
  16640. },
  16641. dispose: function ( ) {
  16642. if ( this.boneTexture ) {
  16643. this.boneTexture.dispose();
  16644. this.boneTexture = undefined;
  16645. }
  16646. }
  16647. } );
  16648. /**
  16649. * @author mikael emtinger / http://gomo.se/
  16650. * @author alteredq / http://alteredqualia.com/
  16651. * @author ikerr / http://verold.com
  16652. */
  16653. function Bone() {
  16654. Object3D.call( this );
  16655. this.type = 'Bone';
  16656. }
  16657. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16658. constructor: Bone,
  16659. isBone: true
  16660. } );
  16661. /**
  16662. * @author mrdoob / http://mrdoob.com/
  16663. */
  16664. var _instanceLocalMatrix = new Matrix4();
  16665. var _instanceWorldMatrix = new Matrix4();
  16666. var _instanceIntersects = [];
  16667. var _mesh = new Mesh();
  16668. function InstancedMesh( geometry, material, count ) {
  16669. Mesh.call( this, geometry, material );
  16670. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  16671. this.count = count;
  16672. this.frustumCulled = false;
  16673. }
  16674. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16675. constructor: InstancedMesh,
  16676. isInstancedMesh: true,
  16677. copy: function ( source ) {
  16678. Mesh.prototype.copy.call( this, source );
  16679. this.instanceMatrix.copy( source.instanceMatrix );
  16680. this.count = source.count;
  16681. return this;
  16682. },
  16683. getMatrixAt: function ( index, matrix ) {
  16684. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  16685. },
  16686. raycast: function ( raycaster, intersects ) {
  16687. var matrixWorld = this.matrixWorld;
  16688. var raycastTimes = this.count;
  16689. _mesh.geometry = this.geometry;
  16690. _mesh.material = this.material;
  16691. if ( _mesh.material === undefined ) { return; }
  16692. for ( var instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  16693. // calculate the world matrix for each instance
  16694. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  16695. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  16696. // the mesh represents this single instance
  16697. _mesh.matrixWorld = _instanceWorldMatrix;
  16698. _mesh.raycast( raycaster, _instanceIntersects );
  16699. // process the result of raycast
  16700. for ( var i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  16701. var intersect = _instanceIntersects[ i ];
  16702. intersect.instanceId = instanceId;
  16703. intersect.object = this;
  16704. intersects.push( intersect );
  16705. }
  16706. _instanceIntersects.length = 0;
  16707. }
  16708. },
  16709. setMatrixAt: function ( index, matrix ) {
  16710. matrix.toArray( this.instanceMatrix.array, index * 16 );
  16711. },
  16712. updateMorphTargets: function () {
  16713. }
  16714. } );
  16715. /**
  16716. * @author mrdoob / http://mrdoob.com/
  16717. * @author alteredq / http://alteredqualia.com/
  16718. *
  16719. * parameters = {
  16720. * color: <hex>,
  16721. * opacity: <float>,
  16722. *
  16723. * linewidth: <float>,
  16724. * linecap: "round",
  16725. * linejoin: "round"
  16726. * }
  16727. */
  16728. function LineBasicMaterial( parameters ) {
  16729. Material.call( this );
  16730. this.type = 'LineBasicMaterial';
  16731. this.color = new Color( 0xffffff );
  16732. this.linewidth = 1;
  16733. this.linecap = 'round';
  16734. this.linejoin = 'round';
  16735. this.morphTargets = false;
  16736. this.setValues( parameters );
  16737. }
  16738. LineBasicMaterial.prototype = Object.create( Material.prototype );
  16739. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16740. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16741. LineBasicMaterial.prototype.copy = function ( source ) {
  16742. Material.prototype.copy.call( this, source );
  16743. this.color.copy( source.color );
  16744. this.linewidth = source.linewidth;
  16745. this.linecap = source.linecap;
  16746. this.linejoin = source.linejoin;
  16747. this.morphTargets = source.morphTargets;
  16748. return this;
  16749. };
  16750. /**
  16751. * @author mrdoob / http://mrdoob.com/
  16752. */
  16753. var _start = new Vector3();
  16754. var _end = new Vector3();
  16755. var _inverseMatrix$1 = new Matrix4();
  16756. var _ray$1 = new Ray();
  16757. var _sphere$2 = new Sphere();
  16758. function Line( geometry, material, mode ) {
  16759. if ( mode === 1 ) {
  16760. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  16761. }
  16762. Object3D.call( this );
  16763. this.type = 'Line';
  16764. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16765. this.material = material !== undefined ? material : new LineBasicMaterial();
  16766. this.updateMorphTargets();
  16767. }
  16768. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16769. constructor: Line,
  16770. isLine: true,
  16771. copy: function ( source ) {
  16772. Object3D.prototype.copy.call( this, source );
  16773. this.material = source.material;
  16774. this.geometry = source.geometry;
  16775. return this;
  16776. },
  16777. computeLineDistances: function () {
  16778. var geometry = this.geometry;
  16779. if ( geometry.isBufferGeometry ) {
  16780. // we assume non-indexed geometry
  16781. if ( geometry.index === null ) {
  16782. var positionAttribute = geometry.attributes.position;
  16783. var lineDistances = [ 0 ];
  16784. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  16785. _start.fromBufferAttribute( positionAttribute, i - 1 );
  16786. _end.fromBufferAttribute( positionAttribute, i );
  16787. lineDistances[ i ] = lineDistances[ i - 1 ];
  16788. lineDistances[ i ] += _start.distanceTo( _end );
  16789. }
  16790. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16791. } else {
  16792. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16793. }
  16794. } else if ( geometry.isGeometry ) {
  16795. var vertices = geometry.vertices;
  16796. var lineDistances$1 = geometry.lineDistances;
  16797. lineDistances$1[ 0 ] = 0;
  16798. for ( var i$1 = 1, l$1 = vertices.length; i$1 < l$1; i$1 ++ ) {
  16799. lineDistances$1[ i$1 ] = lineDistances$1[ i$1 - 1 ];
  16800. lineDistances$1[ i$1 ] += vertices[ i$1 - 1 ].distanceTo( vertices[ i$1 ] );
  16801. }
  16802. }
  16803. return this;
  16804. },
  16805. raycast: function ( raycaster, intersects ) {
  16806. var geometry = this.geometry;
  16807. var matrixWorld = this.matrixWorld;
  16808. var threshold = raycaster.params.Line.threshold;
  16809. // Checking boundingSphere distance to ray
  16810. if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); }
  16811. _sphere$2.copy( geometry.boundingSphere );
  16812. _sphere$2.applyMatrix4( matrixWorld );
  16813. _sphere$2.radius += threshold;
  16814. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) { return; }
  16815. //
  16816. _inverseMatrix$1.getInverse( matrixWorld );
  16817. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  16818. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16819. var localThresholdSq = localThreshold * localThreshold;
  16820. var vStart = new Vector3();
  16821. var vEnd = new Vector3();
  16822. var interSegment = new Vector3();
  16823. var interRay = new Vector3();
  16824. var step = ( this && this.isLineSegments ) ? 2 : 1;
  16825. if ( geometry.isBufferGeometry ) {
  16826. var index = geometry.index;
  16827. var attributes = geometry.attributes;
  16828. var positions = attributes.position.array;
  16829. if ( index !== null ) {
  16830. var indices = index.array;
  16831. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  16832. var a = indices[ i ];
  16833. var b = indices[ i + 1 ];
  16834. vStart.fromArray( positions, a * 3 );
  16835. vEnd.fromArray( positions, b * 3 );
  16836. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16837. if ( distSq > localThresholdSq ) { continue; }
  16838. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16839. var distance = raycaster.ray.origin.distanceTo( interRay );
  16840. if ( distance < raycaster.near || distance > raycaster.far ) { continue; }
  16841. intersects.push( {
  16842. distance: distance,
  16843. // What do we want? intersection point on the ray or on the segment??
  16844. // point: raycaster.ray.at( distance ),
  16845. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16846. index: i,
  16847. face: null,
  16848. faceIndex: null,
  16849. object: this
  16850. } );
  16851. }
  16852. } else {
  16853. for ( var i$1 = 0, l$1 = positions.length / 3 - 1; i$1 < l$1; i$1 += step ) {
  16854. vStart.fromArray( positions, 3 * i$1 );
  16855. vEnd.fromArray( positions, 3 * i$1 + 3 );
  16856. var distSq$1 = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16857. if ( distSq$1 > localThresholdSq ) { continue; }
  16858. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16859. var distance$1 = raycaster.ray.origin.distanceTo( interRay );
  16860. if ( distance$1 < raycaster.near || distance$1 > raycaster.far ) { continue; }
  16861. intersects.push( {
  16862. distance: distance$1,
  16863. // What do we want? intersection point on the ray or on the segment??
  16864. // point: raycaster.ray.at( distance ),
  16865. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16866. index: i$1,
  16867. face: null,
  16868. faceIndex: null,
  16869. object: this
  16870. } );
  16871. }
  16872. }
  16873. } else if ( geometry.isGeometry ) {
  16874. var vertices = geometry.vertices;
  16875. var nbVertices = vertices.length;
  16876. for ( var i$2 = 0; i$2 < nbVertices - 1; i$2 += step ) {
  16877. var distSq$2 = _ray$1.distanceSqToSegment( vertices[ i$2 ], vertices[ i$2 + 1 ], interRay, interSegment );
  16878. if ( distSq$2 > localThresholdSq ) { continue; }
  16879. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16880. var distance$2 = raycaster.ray.origin.distanceTo( interRay );
  16881. if ( distance$2 < raycaster.near || distance$2 > raycaster.far ) { continue; }
  16882. intersects.push( {
  16883. distance: distance$2,
  16884. // What do we want? intersection point on the ray or on the segment??
  16885. // point: raycaster.ray.at( distance ),
  16886. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16887. index: i$2,
  16888. face: null,
  16889. faceIndex: null,
  16890. object: this
  16891. } );
  16892. }
  16893. }
  16894. },
  16895. updateMorphTargets: function () {
  16896. var geometry = this.geometry;
  16897. if ( geometry.isBufferGeometry ) {
  16898. var morphAttributes = geometry.morphAttributes;
  16899. var keys = Object.keys( morphAttributes );
  16900. if ( keys.length > 0 ) {
  16901. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16902. if ( morphAttribute !== undefined ) {
  16903. this.morphTargetInfluences = [];
  16904. this.morphTargetDictionary = {};
  16905. for ( var m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16906. var name = morphAttribute[ m ].name || String( m );
  16907. this.morphTargetInfluences.push( 0 );
  16908. this.morphTargetDictionary[ name ] = m;
  16909. }
  16910. }
  16911. }
  16912. } else {
  16913. var morphTargets = geometry.morphTargets;
  16914. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16915. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16916. }
  16917. }
  16918. }
  16919. } );
  16920. /**
  16921. * @author mrdoob / http://mrdoob.com/
  16922. */
  16923. var _start$1 = new Vector3();
  16924. var _end$1 = new Vector3();
  16925. function LineSegments( geometry, material ) {
  16926. Line.call( this, geometry, material );
  16927. this.type = 'LineSegments';
  16928. }
  16929. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16930. constructor: LineSegments,
  16931. isLineSegments: true,
  16932. computeLineDistances: function () {
  16933. var geometry = this.geometry;
  16934. if ( geometry.isBufferGeometry ) {
  16935. // we assume non-indexed geometry
  16936. if ( geometry.index === null ) {
  16937. var positionAttribute = geometry.attributes.position;
  16938. var lineDistances = [];
  16939. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16940. _start$1.fromBufferAttribute( positionAttribute, i );
  16941. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16942. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16943. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16944. }
  16945. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16946. } else {
  16947. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16948. }
  16949. } else if ( geometry.isGeometry ) {
  16950. var vertices = geometry.vertices;
  16951. var lineDistances$1 = geometry.lineDistances;
  16952. for ( var i$1 = 0, l$1 = vertices.length; i$1 < l$1; i$1 += 2 ) {
  16953. _start$1.copy( vertices[ i$1 ] );
  16954. _end$1.copy( vertices[ i$1 + 1 ] );
  16955. lineDistances$1[ i$1 ] = ( i$1 === 0 ) ? 0 : lineDistances$1[ i$1 - 1 ];
  16956. lineDistances$1[ i$1 + 1 ] = lineDistances$1[ i$1 ] + _start$1.distanceTo( _end$1 );
  16957. }
  16958. }
  16959. return this;
  16960. }
  16961. } );
  16962. /**
  16963. * @author mgreter / http://github.com/mgreter
  16964. */
  16965. function LineLoop( geometry, material ) {
  16966. Line.call( this, geometry, material );
  16967. this.type = 'LineLoop';
  16968. }
  16969. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16970. constructor: LineLoop,
  16971. isLineLoop: true,
  16972. } );
  16973. /**
  16974. * @author mrdoob / http://mrdoob.com/
  16975. * @author alteredq / http://alteredqualia.com/
  16976. *
  16977. * parameters = {
  16978. * color: <hex>,
  16979. * opacity: <float>,
  16980. * map: new THREE.Texture( <Image> ),
  16981. * alphaMap: new THREE.Texture( <Image> ),
  16982. *
  16983. * size: <float>,
  16984. * sizeAttenuation: <bool>
  16985. *
  16986. * morphTargets: <bool>
  16987. * }
  16988. */
  16989. function PointsMaterial( parameters ) {
  16990. Material.call( this );
  16991. this.type = 'PointsMaterial';
  16992. this.color = new Color( 0xffffff );
  16993. this.map = null;
  16994. this.alphaMap = null;
  16995. this.size = 1;
  16996. this.sizeAttenuation = true;
  16997. this.morphTargets = false;
  16998. this.setValues( parameters );
  16999. }
  17000. PointsMaterial.prototype = Object.create( Material.prototype );
  17001. PointsMaterial.prototype.constructor = PointsMaterial;
  17002. PointsMaterial.prototype.isPointsMaterial = true;
  17003. PointsMaterial.prototype.copy = function ( source ) {
  17004. Material.prototype.copy.call( this, source );
  17005. this.color.copy( source.color );
  17006. this.map = source.map;
  17007. this.alphaMap = source.alphaMap;
  17008. this.size = source.size;
  17009. this.sizeAttenuation = source.sizeAttenuation;
  17010. this.morphTargets = source.morphTargets;
  17011. return this;
  17012. };
  17013. /**
  17014. * @author alteredq / http://alteredqualia.com/
  17015. */
  17016. var _inverseMatrix$2 = new Matrix4();
  17017. var _ray$2 = new Ray();
  17018. var _sphere$3 = new Sphere();
  17019. var _position$1 = new Vector3();
  17020. function Points( geometry, material ) {
  17021. Object3D.call( this );
  17022. this.type = 'Points';
  17023. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  17024. this.material = material !== undefined ? material : new PointsMaterial();
  17025. this.updateMorphTargets();
  17026. }
  17027. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  17028. constructor: Points,
  17029. isPoints: true,
  17030. copy: function ( source ) {
  17031. Object3D.prototype.copy.call( this, source );
  17032. this.material = source.material;
  17033. this.geometry = source.geometry;
  17034. return this;
  17035. },
  17036. raycast: function ( raycaster, intersects ) {
  17037. var geometry = this.geometry;
  17038. var matrixWorld = this.matrixWorld;
  17039. var threshold = raycaster.params.Points.threshold;
  17040. // Checking boundingSphere distance to ray
  17041. if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); }
  17042. _sphere$3.copy( geometry.boundingSphere );
  17043. _sphere$3.applyMatrix4( matrixWorld );
  17044. _sphere$3.radius += threshold;
  17045. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) { return; }
  17046. //
  17047. _inverseMatrix$2.getInverse( matrixWorld );
  17048. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  17049. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  17050. var localThresholdSq = localThreshold * localThreshold;
  17051. if ( geometry.isBufferGeometry ) {
  17052. var index = geometry.index;
  17053. var attributes = geometry.attributes;
  17054. var positions = attributes.position.array;
  17055. if ( index !== null ) {
  17056. var indices = index.array;
  17057. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  17058. var a = indices[ i ];
  17059. _position$1.fromArray( positions, a * 3 );
  17060. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17061. }
  17062. } else {
  17063. for ( var i$1 = 0, l = positions.length / 3; i$1 < l; i$1 ++ ) {
  17064. _position$1.fromArray( positions, i$1 * 3 );
  17065. testPoint( _position$1, i$1, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17066. }
  17067. }
  17068. } else {
  17069. var vertices = geometry.vertices;
  17070. for ( var i$2 = 0, l$1 = vertices.length; i$2 < l$1; i$2 ++ ) {
  17071. testPoint( vertices[ i$2 ], i$2, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17072. }
  17073. }
  17074. },
  17075. updateMorphTargets: function () {
  17076. var geometry = this.geometry;
  17077. if ( geometry.isBufferGeometry ) {
  17078. var morphAttributes = geometry.morphAttributes;
  17079. var keys = Object.keys( morphAttributes );
  17080. if ( keys.length > 0 ) {
  17081. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  17082. if ( morphAttribute !== undefined ) {
  17083. this.morphTargetInfluences = [];
  17084. this.morphTargetDictionary = {};
  17085. for ( var m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  17086. var name = morphAttribute[ m ].name || String( m );
  17087. this.morphTargetInfluences.push( 0 );
  17088. this.morphTargetDictionary[ name ] = m;
  17089. }
  17090. }
  17091. }
  17092. } else {
  17093. var morphTargets = geometry.morphTargets;
  17094. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  17095. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17096. }
  17097. }
  17098. }
  17099. } );
  17100. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  17101. var rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  17102. if ( rayPointDistanceSq < localThresholdSq ) {
  17103. var intersectPoint = new Vector3();
  17104. _ray$2.closestPointToPoint( point, intersectPoint );
  17105. intersectPoint.applyMatrix4( matrixWorld );
  17106. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  17107. if ( distance < raycaster.near || distance > raycaster.far ) { return; }
  17108. intersects.push( {
  17109. distance: distance,
  17110. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  17111. point: intersectPoint,
  17112. index: index,
  17113. face: null,
  17114. object: object
  17115. } );
  17116. }
  17117. }
  17118. /**
  17119. * @author mrdoob / http://mrdoob.com/
  17120. */
  17121. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17122. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17123. this.format = format !== undefined ? format : RGBFormat;
  17124. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17125. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17126. this.generateMipmaps = false;
  17127. }
  17128. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  17129. constructor: VideoTexture,
  17130. isVideoTexture: true,
  17131. update: function () {
  17132. var video = this.image;
  17133. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  17134. this.needsUpdate = true;
  17135. }
  17136. }
  17137. } );
  17138. /**
  17139. * @author alteredq / http://alteredqualia.com/
  17140. */
  17141. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  17142. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  17143. this.image = { width: width, height: height };
  17144. this.mipmaps = mipmaps;
  17145. // no flipping for cube textures
  17146. // (also flipping doesn't work for compressed textures )
  17147. this.flipY = false;
  17148. // can't generate mipmaps for compressed textures
  17149. // mips must be embedded in DDS files
  17150. this.generateMipmaps = false;
  17151. }
  17152. CompressedTexture.prototype = Object.create( Texture.prototype );
  17153. CompressedTexture.prototype.constructor = CompressedTexture;
  17154. CompressedTexture.prototype.isCompressedTexture = true;
  17155. /**
  17156. * @author mrdoob / http://mrdoob.com/
  17157. */
  17158. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17159. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17160. this.needsUpdate = true;
  17161. }
  17162. CanvasTexture.prototype = Object.create( Texture.prototype );
  17163. CanvasTexture.prototype.constructor = CanvasTexture;
  17164. CanvasTexture.prototype.isCanvasTexture = true;
  17165. /**
  17166. * @author Matt DesLauriers / @mattdesl
  17167. * @author atix / arthursilber.de
  17168. */
  17169. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  17170. format = format !== undefined ? format : DepthFormat;
  17171. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  17172. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  17173. }
  17174. if ( type === undefined && format === DepthFormat ) { type = UnsignedShortType; }
  17175. if ( type === undefined && format === DepthStencilFormat ) { type = UnsignedInt248Type; }
  17176. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17177. this.image = { width: width, height: height };
  17178. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17179. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17180. this.flipY = false;
  17181. this.generateMipmaps = false;
  17182. }
  17183. DepthTexture.prototype = Object.create( Texture.prototype );
  17184. DepthTexture.prototype.constructor = DepthTexture;
  17185. DepthTexture.prototype.isDepthTexture = true;
  17186. /**
  17187. * @author mrdoob / http://mrdoob.com/
  17188. * @author Mugen87 / https://github.com/Mugen87
  17189. */
  17190. function WireframeGeometry( geometry ) {
  17191. BufferGeometry.call( this );
  17192. this.type = 'WireframeGeometry';
  17193. // buffer
  17194. var vertices = [];
  17195. // helper variables
  17196. var edge = [ 0, 0 ], edges = {};
  17197. var keys = [ 'a', 'b', 'c' ];
  17198. // different logic for Geometry and BufferGeometry
  17199. if ( geometry && geometry.isGeometry ) {
  17200. // create a data structure that contains all edges without duplicates
  17201. var faces = geometry.faces;
  17202. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  17203. var face = faces[ i ];
  17204. for ( var j = 0; j < 3; j ++ ) {
  17205. var edge1 = face[ keys[ j ] ];
  17206. var edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17207. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  17208. edge[ 1 ] = Math.max( edge1, edge2 );
  17209. var key = edge[ 0 ] + ',' + edge[ 1 ];
  17210. if ( edges[ key ] === undefined ) {
  17211. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  17212. }
  17213. }
  17214. }
  17215. // generate vertices
  17216. for ( var key$1 in edges ) {
  17217. var e = edges[ key$1 ];
  17218. var vertex = geometry.vertices[ e.index1 ];
  17219. vertices.push( vertex.x, vertex.y, vertex.z );
  17220. vertex = geometry.vertices[ e.index2 ];
  17221. vertices.push( vertex.x, vertex.y, vertex.z );
  17222. }
  17223. } else if ( geometry && geometry.isBufferGeometry ) {
  17224. var vertex$1 = new Vector3();
  17225. if ( geometry.index !== null ) {
  17226. // indexed BufferGeometry
  17227. var position = geometry.attributes.position;
  17228. var indices = geometry.index;
  17229. var groups = geometry.groups;
  17230. if ( groups.length === 0 ) {
  17231. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  17232. }
  17233. // create a data structure that contains all eges without duplicates
  17234. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  17235. var group = groups[ o ];
  17236. var start = group.start;
  17237. var count = group.count;
  17238. for ( var i$1 = start, l$1 = ( start + count ); i$1 < l$1; i$1 += 3 ) {
  17239. for ( var j$1 = 0; j$1 < 3; j$1 ++ ) {
  17240. var edge1$1 = indices.getX( i$1 + j$1 );
  17241. var edge2$1 = indices.getX( i$1 + ( j$1 + 1 ) % 3 );
  17242. edge[ 0 ] = Math.min( edge1$1, edge2$1 ); // sorting prevents duplicates
  17243. edge[ 1 ] = Math.max( edge1$1, edge2$1 );
  17244. var key$2 = edge[ 0 ] + ',' + edge[ 1 ];
  17245. if ( edges[ key$2 ] === undefined ) {
  17246. edges[ key$2 ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  17247. }
  17248. }
  17249. }
  17250. }
  17251. // generate vertices
  17252. for ( var key$3 in edges ) {
  17253. var e$1 = edges[ key$3 ];
  17254. vertex$1.fromBufferAttribute( position, e$1.index1 );
  17255. vertices.push( vertex$1.x, vertex$1.y, vertex$1.z );
  17256. vertex$1.fromBufferAttribute( position, e$1.index2 );
  17257. vertices.push( vertex$1.x, vertex$1.y, vertex$1.z );
  17258. }
  17259. } else {
  17260. // non-indexed BufferGeometry
  17261. var position$1 = geometry.attributes.position;
  17262. for ( var i$2 = 0, l$2 = ( position$1.count / 3 ); i$2 < l$2; i$2 ++ ) {
  17263. for ( var j$2 = 0; j$2 < 3; j$2 ++ ) {
  17264. // three edges per triangle, an edge is represented as (index1, index2)
  17265. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  17266. var index1 = 3 * i$2 + j$2;
  17267. vertex$1.fromBufferAttribute( position$1, index1 );
  17268. vertices.push( vertex$1.x, vertex$1.y, vertex$1.z );
  17269. var index2 = 3 * i$2 + ( ( j$2 + 1 ) % 3 );
  17270. vertex$1.fromBufferAttribute( position$1, index2 );
  17271. vertices.push( vertex$1.x, vertex$1.y, vertex$1.z );
  17272. }
  17273. }
  17274. }
  17275. }
  17276. // build geometry
  17277. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17278. }
  17279. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  17280. WireframeGeometry.prototype.constructor = WireframeGeometry;
  17281. /**
  17282. * @author zz85 / https://github.com/zz85
  17283. * @author Mugen87 / https://github.com/Mugen87
  17284. *
  17285. * Parametric Surfaces Geometry
  17286. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  17287. */
  17288. // ParametricGeometry
  17289. function ParametricGeometry( func, slices, stacks ) {
  17290. Geometry.call( this );
  17291. this.type = 'ParametricGeometry';
  17292. this.parameters = {
  17293. func: func,
  17294. slices: slices,
  17295. stacks: stacks
  17296. };
  17297. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  17298. this.mergeVertices();
  17299. }
  17300. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  17301. ParametricGeometry.prototype.constructor = ParametricGeometry;
  17302. // ParametricBufferGeometry
  17303. function ParametricBufferGeometry( func, slices, stacks ) {
  17304. BufferGeometry.call( this );
  17305. this.type = 'ParametricBufferGeometry';
  17306. this.parameters = {
  17307. func: func,
  17308. slices: slices,
  17309. stacks: stacks
  17310. };
  17311. // buffers
  17312. var indices = [];
  17313. var vertices = [];
  17314. var normals = [];
  17315. var uvs = [];
  17316. var EPS = 0.00001;
  17317. var normal = new Vector3();
  17318. var p0 = new Vector3(), p1 = new Vector3();
  17319. var pu = new Vector3(), pv = new Vector3();
  17320. if ( func.length < 3 ) {
  17321. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  17322. }
  17323. // generate vertices, normals and uvs
  17324. var sliceCount = slices + 1;
  17325. for ( var i = 0; i <= stacks; i ++ ) {
  17326. var v = i / stacks;
  17327. for ( var j = 0; j <= slices; j ++ ) {
  17328. var u = j / slices;
  17329. // vertex
  17330. func( u, v, p0 );
  17331. vertices.push( p0.x, p0.y, p0.z );
  17332. // normal
  17333. // approximate tangent vectors via finite differences
  17334. if ( u - EPS >= 0 ) {
  17335. func( u - EPS, v, p1 );
  17336. pu.subVectors( p0, p1 );
  17337. } else {
  17338. func( u + EPS, v, p1 );
  17339. pu.subVectors( p1, p0 );
  17340. }
  17341. if ( v - EPS >= 0 ) {
  17342. func( u, v - EPS, p1 );
  17343. pv.subVectors( p0, p1 );
  17344. } else {
  17345. func( u, v + EPS, p1 );
  17346. pv.subVectors( p1, p0 );
  17347. }
  17348. // cross product of tangent vectors returns surface normal
  17349. normal.crossVectors( pu, pv ).normalize();
  17350. normals.push( normal.x, normal.y, normal.z );
  17351. // uv
  17352. uvs.push( u, v );
  17353. }
  17354. }
  17355. // generate indices
  17356. for ( var i$1 = 0; i$1 < stacks; i$1 ++ ) {
  17357. for ( var j$1 = 0; j$1 < slices; j$1 ++ ) {
  17358. var a = i$1 * sliceCount + j$1;
  17359. var b = i$1 * sliceCount + j$1 + 1;
  17360. var c = ( i$1 + 1 ) * sliceCount + j$1 + 1;
  17361. var d = ( i$1 + 1 ) * sliceCount + j$1;
  17362. // faces one and two
  17363. indices.push( a, b, d );
  17364. indices.push( b, c, d );
  17365. }
  17366. }
  17367. // build geometry
  17368. this.setIndex( indices );
  17369. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17370. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17371. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17372. }
  17373. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17374. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  17375. /**
  17376. * @author clockworkgeek / https://github.com/clockworkgeek
  17377. * @author timothypratley / https://github.com/timothypratley
  17378. * @author WestLangley / http://github.com/WestLangley
  17379. * @author Mugen87 / https://github.com/Mugen87
  17380. */
  17381. // PolyhedronGeometry
  17382. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  17383. Geometry.call( this );
  17384. this.type = 'PolyhedronGeometry';
  17385. this.parameters = {
  17386. vertices: vertices,
  17387. indices: indices,
  17388. radius: radius,
  17389. detail: detail
  17390. };
  17391. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  17392. this.mergeVertices();
  17393. }
  17394. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  17395. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  17396. // PolyhedronBufferGeometry
  17397. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  17398. BufferGeometry.call( this );
  17399. this.type = 'PolyhedronBufferGeometry';
  17400. this.parameters = {
  17401. vertices: vertices,
  17402. indices: indices,
  17403. radius: radius,
  17404. detail: detail
  17405. };
  17406. radius = radius || 1;
  17407. detail = detail || 0;
  17408. // default buffer data
  17409. var vertexBuffer = [];
  17410. var uvBuffer = [];
  17411. // the subdivision creates the vertex buffer data
  17412. subdivide( detail );
  17413. // all vertices should lie on a conceptual sphere with a given radius
  17414. applyRadius( radius );
  17415. // finally, create the uv data
  17416. generateUVs();
  17417. // build non-indexed geometry
  17418. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  17419. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  17420. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  17421. if ( detail === 0 ) {
  17422. this.computeVertexNormals(); // flat normals
  17423. } else {
  17424. this.normalizeNormals(); // smooth normals
  17425. }
  17426. // helper functions
  17427. function subdivide( detail ) {
  17428. var a = new Vector3();
  17429. var b = new Vector3();
  17430. var c = new Vector3();
  17431. // iterate over all faces and apply a subdivison with the given detail value
  17432. for ( var i = 0; i < indices.length; i += 3 ) {
  17433. // get the vertices of the face
  17434. getVertexByIndex( indices[ i + 0 ], a );
  17435. getVertexByIndex( indices[ i + 1 ], b );
  17436. getVertexByIndex( indices[ i + 2 ], c );
  17437. // perform subdivision
  17438. subdivideFace( a, b, c, detail );
  17439. }
  17440. }
  17441. function subdivideFace( a, b, c, detail ) {
  17442. var cols = Math.pow( 2, detail );
  17443. // we use this multidimensional array as a data structure for creating the subdivision
  17444. var v = [];
  17445. // construct all of the vertices for this subdivision
  17446. for ( var i = 0; i <= cols; i ++ ) {
  17447. v[ i ] = [];
  17448. var aj = a.clone().lerp( c, i / cols );
  17449. var bj = b.clone().lerp( c, i / cols );
  17450. var rows = cols - i;
  17451. for ( var j = 0; j <= rows; j ++ ) {
  17452. if ( j === 0 && i === cols ) {
  17453. v[ i ][ j ] = aj;
  17454. } else {
  17455. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  17456. }
  17457. }
  17458. }
  17459. // construct all of the faces
  17460. for ( var i$1 = 0; i$1 < cols; i$1 ++ ) {
  17461. for ( var j$1 = 0; j$1 < 2 * ( cols - i$1 ) - 1; j$1 ++ ) {
  17462. var k = Math.floor( j$1 / 2 );
  17463. if ( j$1 % 2 === 0 ) {
  17464. pushVertex( v[ i$1 ][ k + 1 ] );
  17465. pushVertex( v[ i$1 + 1 ][ k ] );
  17466. pushVertex( v[ i$1 ][ k ] );
  17467. } else {
  17468. pushVertex( v[ i$1 ][ k + 1 ] );
  17469. pushVertex( v[ i$1 + 1 ][ k + 1 ] );
  17470. pushVertex( v[ i$1 + 1 ][ k ] );
  17471. }
  17472. }
  17473. }
  17474. }
  17475. function applyRadius( radius ) {
  17476. var vertex = new Vector3();
  17477. // iterate over the entire buffer and apply the radius to each vertex
  17478. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17479. vertex.x = vertexBuffer[ i + 0 ];
  17480. vertex.y = vertexBuffer[ i + 1 ];
  17481. vertex.z = vertexBuffer[ i + 2 ];
  17482. vertex.normalize().multiplyScalar( radius );
  17483. vertexBuffer[ i + 0 ] = vertex.x;
  17484. vertexBuffer[ i + 1 ] = vertex.y;
  17485. vertexBuffer[ i + 2 ] = vertex.z;
  17486. }
  17487. }
  17488. function generateUVs() {
  17489. var vertex = new Vector3();
  17490. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17491. vertex.x = vertexBuffer[ i + 0 ];
  17492. vertex.y = vertexBuffer[ i + 1 ];
  17493. vertex.z = vertexBuffer[ i + 2 ];
  17494. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17495. var v = inclination( vertex ) / Math.PI + 0.5;
  17496. uvBuffer.push( u, 1 - v );
  17497. }
  17498. correctUVs();
  17499. correctSeam();
  17500. }
  17501. function correctSeam() {
  17502. // handle case when face straddles the seam, see #3269
  17503. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  17504. // uv data of a single face
  17505. var x0 = uvBuffer[ i + 0 ];
  17506. var x1 = uvBuffer[ i + 2 ];
  17507. var x2 = uvBuffer[ i + 4 ];
  17508. var max = Math.max( x0, x1, x2 );
  17509. var min = Math.min( x0, x1, x2 );
  17510. // 0.9 is somewhat arbitrary
  17511. if ( max > 0.9 && min < 0.1 ) {
  17512. if ( x0 < 0.2 ) { uvBuffer[ i + 0 ] += 1; }
  17513. if ( x1 < 0.2 ) { uvBuffer[ i + 2 ] += 1; }
  17514. if ( x2 < 0.2 ) { uvBuffer[ i + 4 ] += 1; }
  17515. }
  17516. }
  17517. }
  17518. function pushVertex( vertex ) {
  17519. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17520. }
  17521. function getVertexByIndex( index, vertex ) {
  17522. var stride = index * 3;
  17523. vertex.x = vertices[ stride + 0 ];
  17524. vertex.y = vertices[ stride + 1 ];
  17525. vertex.z = vertices[ stride + 2 ];
  17526. }
  17527. function correctUVs() {
  17528. var a = new Vector3();
  17529. var b = new Vector3();
  17530. var c = new Vector3();
  17531. var centroid = new Vector3();
  17532. var uvA = new Vector2();
  17533. var uvB = new Vector2();
  17534. var uvC = new Vector2();
  17535. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17536. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17537. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17538. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17539. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17540. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17541. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17542. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17543. var azi = azimuth( centroid );
  17544. correctUV( uvA, j + 0, a, azi );
  17545. correctUV( uvB, j + 2, b, azi );
  17546. correctUV( uvC, j + 4, c, azi );
  17547. }
  17548. }
  17549. function correctUV( uv, stride, vector, azimuth ) {
  17550. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17551. uvBuffer[ stride ] = uv.x - 1;
  17552. }
  17553. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  17554. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  17555. }
  17556. }
  17557. // Angle around the Y axis, counter-clockwise when looking from above.
  17558. function azimuth( vector ) {
  17559. return Math.atan2( vector.z, - vector.x );
  17560. }
  17561. // Angle above the XZ plane.
  17562. function inclination( vector ) {
  17563. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  17564. }
  17565. }
  17566. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17567. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  17568. /**
  17569. * @author timothypratley / https://github.com/timothypratley
  17570. * @author Mugen87 / https://github.com/Mugen87
  17571. */
  17572. // TetrahedronGeometry
  17573. function TetrahedronGeometry( radius, detail ) {
  17574. Geometry.call( this );
  17575. this.type = 'TetrahedronGeometry';
  17576. this.parameters = {
  17577. radius: radius,
  17578. detail: detail
  17579. };
  17580. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  17581. this.mergeVertices();
  17582. }
  17583. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  17584. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  17585. // TetrahedronBufferGeometry
  17586. function TetrahedronBufferGeometry( radius, detail ) {
  17587. var vertices = [
  17588. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  17589. ];
  17590. var indices = [
  17591. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  17592. ];
  17593. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17594. this.type = 'TetrahedronBufferGeometry';
  17595. this.parameters = {
  17596. radius: radius,
  17597. detail: detail
  17598. };
  17599. }
  17600. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17601. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  17602. /**
  17603. * @author timothypratley / https://github.com/timothypratley
  17604. * @author Mugen87 / https://github.com/Mugen87
  17605. */
  17606. // OctahedronGeometry
  17607. function OctahedronGeometry( radius, detail ) {
  17608. Geometry.call( this );
  17609. this.type = 'OctahedronGeometry';
  17610. this.parameters = {
  17611. radius: radius,
  17612. detail: detail
  17613. };
  17614. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  17615. this.mergeVertices();
  17616. }
  17617. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  17618. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  17619. // OctahedronBufferGeometry
  17620. function OctahedronBufferGeometry( radius, detail ) {
  17621. var vertices = [
  17622. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17623. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17624. ];
  17625. var indices = [
  17626. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17627. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17628. 1, 3, 4, 1, 4, 2
  17629. ];
  17630. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17631. this.type = 'OctahedronBufferGeometry';
  17632. this.parameters = {
  17633. radius: radius,
  17634. detail: detail
  17635. };
  17636. }
  17637. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17638. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  17639. /**
  17640. * @author timothypratley / https://github.com/timothypratley
  17641. * @author Mugen87 / https://github.com/Mugen87
  17642. */
  17643. // IcosahedronGeometry
  17644. function IcosahedronGeometry( radius, detail ) {
  17645. Geometry.call( this );
  17646. this.type = 'IcosahedronGeometry';
  17647. this.parameters = {
  17648. radius: radius,
  17649. detail: detail
  17650. };
  17651. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  17652. this.mergeVertices();
  17653. }
  17654. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  17655. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  17656. // IcosahedronBufferGeometry
  17657. function IcosahedronBufferGeometry( radius, detail ) {
  17658. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17659. var vertices = [
  17660. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17661. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17662. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17663. ];
  17664. var indices = [
  17665. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17666. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17667. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17668. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17669. ];
  17670. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17671. this.type = 'IcosahedronBufferGeometry';
  17672. this.parameters = {
  17673. radius: radius,
  17674. detail: detail
  17675. };
  17676. }
  17677. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17678. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  17679. /**
  17680. * @author Abe Pazos / https://hamoid.com
  17681. * @author Mugen87 / https://github.com/Mugen87
  17682. */
  17683. // DodecahedronGeometry
  17684. function DodecahedronGeometry( radius, detail ) {
  17685. Geometry.call( this );
  17686. this.type = 'DodecahedronGeometry';
  17687. this.parameters = {
  17688. radius: radius,
  17689. detail: detail
  17690. };
  17691. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  17692. this.mergeVertices();
  17693. }
  17694. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  17695. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  17696. // DodecahedronBufferGeometry
  17697. function DodecahedronBufferGeometry( radius, detail ) {
  17698. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17699. var r = 1 / t;
  17700. var vertices = [
  17701. // (±1, ±1, ±1)
  17702. - 1, - 1, - 1, - 1, - 1, 1,
  17703. - 1, 1, - 1, - 1, 1, 1,
  17704. 1, - 1, - 1, 1, - 1, 1,
  17705. 1, 1, - 1, 1, 1, 1,
  17706. // (0, ±1/φ, ±φ)
  17707. 0, - r, - t, 0, - r, t,
  17708. 0, r, - t, 0, r, t,
  17709. // (±1/φ, ±φ, 0)
  17710. - r, - t, 0, - r, t, 0,
  17711. r, - t, 0, r, t, 0,
  17712. // (±φ, 0, ±1/φ)
  17713. - t, 0, - r, t, 0, - r,
  17714. - t, 0, r, t, 0, r
  17715. ];
  17716. var indices = [
  17717. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  17718. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  17719. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  17720. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  17721. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  17722. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  17723. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  17724. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  17725. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  17726. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  17727. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  17728. 1, 12, 14, 1, 14, 5, 1, 5, 9
  17729. ];
  17730. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17731. this.type = 'DodecahedronBufferGeometry';
  17732. this.parameters = {
  17733. radius: radius,
  17734. detail: detail
  17735. };
  17736. }
  17737. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17738. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  17739. /**
  17740. * @author oosmoxiecode / https://github.com/oosmoxiecode
  17741. * @author WestLangley / https://github.com/WestLangley
  17742. * @author zz85 / https://github.com/zz85
  17743. * @author miningold / https://github.com/miningold
  17744. * @author jonobr1 / https://github.com/jonobr1
  17745. * @author Mugen87 / https://github.com/Mugen87
  17746. *
  17747. */
  17748. // TubeGeometry
  17749. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  17750. Geometry.call( this );
  17751. this.type = 'TubeGeometry';
  17752. this.parameters = {
  17753. path: path,
  17754. tubularSegments: tubularSegments,
  17755. radius: radius,
  17756. radialSegments: radialSegments,
  17757. closed: closed
  17758. };
  17759. if ( taper !== undefined ) { console.warn( 'THREE.TubeGeometry: taper has been removed.' ); }
  17760. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  17761. // expose internals
  17762. this.tangents = bufferGeometry.tangents;
  17763. this.normals = bufferGeometry.normals;
  17764. this.binormals = bufferGeometry.binormals;
  17765. // create geometry
  17766. this.fromBufferGeometry( bufferGeometry );
  17767. this.mergeVertices();
  17768. }
  17769. TubeGeometry.prototype = Object.create( Geometry.prototype );
  17770. TubeGeometry.prototype.constructor = TubeGeometry;
  17771. // TubeBufferGeometry
  17772. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  17773. BufferGeometry.call( this );
  17774. this.type = 'TubeBufferGeometry';
  17775. this.parameters = {
  17776. path: path,
  17777. tubularSegments: tubularSegments,
  17778. radius: radius,
  17779. radialSegments: radialSegments,
  17780. closed: closed
  17781. };
  17782. tubularSegments = tubularSegments || 64;
  17783. radius = radius || 1;
  17784. radialSegments = radialSegments || 8;
  17785. closed = closed || false;
  17786. var frames = path.computeFrenetFrames( tubularSegments, closed );
  17787. // expose internals
  17788. this.tangents = frames.tangents;
  17789. this.normals = frames.normals;
  17790. this.binormals = frames.binormals;
  17791. // helper variables
  17792. var vertex = new Vector3();
  17793. var normal = new Vector3();
  17794. var uv = new Vector2();
  17795. var P = new Vector3();
  17796. // buffer
  17797. var vertices = [];
  17798. var normals = [];
  17799. var uvs = [];
  17800. var indices = [];
  17801. // create buffer data
  17802. generateBufferData();
  17803. // build geometry
  17804. this.setIndex( indices );
  17805. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17806. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17807. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17808. // functions
  17809. function generateBufferData() {
  17810. for ( var i = 0; i < tubularSegments; i ++ ) {
  17811. generateSegment( i );
  17812. }
  17813. // if the geometry is not closed, generate the last row of vertices and normals
  17814. // at the regular position on the given path
  17815. //
  17816. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  17817. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  17818. // uvs are generated in a separate function.
  17819. // this makes it easy compute correct values for closed geometries
  17820. generateUVs();
  17821. // finally create faces
  17822. generateIndices();
  17823. }
  17824. function generateSegment( i ) {
  17825. // we use getPointAt to sample evenly distributed points from the given path
  17826. P = path.getPointAt( i / tubularSegments, P );
  17827. // retrieve corresponding normal and binormal
  17828. var N = frames.normals[ i ];
  17829. var B = frames.binormals[ i ];
  17830. // generate normals and vertices for the current segment
  17831. for ( var j = 0; j <= radialSegments; j ++ ) {
  17832. var v = j / radialSegments * Math.PI * 2;
  17833. var sin = Math.sin( v );
  17834. var cos = - Math.cos( v );
  17835. // normal
  17836. normal.x = ( cos * N.x + sin * B.x );
  17837. normal.y = ( cos * N.y + sin * B.y );
  17838. normal.z = ( cos * N.z + sin * B.z );
  17839. normal.normalize();
  17840. normals.push( normal.x, normal.y, normal.z );
  17841. // vertex
  17842. vertex.x = P.x + radius * normal.x;
  17843. vertex.y = P.y + radius * normal.y;
  17844. vertex.z = P.z + radius * normal.z;
  17845. vertices.push( vertex.x, vertex.y, vertex.z );
  17846. }
  17847. }
  17848. function generateIndices() {
  17849. for ( var j = 1; j <= tubularSegments; j ++ ) {
  17850. for ( var i = 1; i <= radialSegments; i ++ ) {
  17851. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17852. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17853. var c = ( radialSegments + 1 ) * j + i;
  17854. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17855. // faces
  17856. indices.push( a, b, d );
  17857. indices.push( b, c, d );
  17858. }
  17859. }
  17860. }
  17861. function generateUVs() {
  17862. for ( var i = 0; i <= tubularSegments; i ++ ) {
  17863. for ( var j = 0; j <= radialSegments; j ++ ) {
  17864. uv.x = i / tubularSegments;
  17865. uv.y = j / radialSegments;
  17866. uvs.push( uv.x, uv.y );
  17867. }
  17868. }
  17869. }
  17870. }
  17871. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17872. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  17873. TubeBufferGeometry.prototype.toJSON = function () {
  17874. var data = BufferGeometry.prototype.toJSON.call( this );
  17875. data.path = this.parameters.path.toJSON();
  17876. return data;
  17877. };
  17878. /**
  17879. * @author oosmoxiecode
  17880. * @author Mugen87 / https://github.com/Mugen87
  17881. *
  17882. * based on http://www.blackpawn.com/texts/pqtorus/
  17883. */
  17884. // TorusKnotGeometry
  17885. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  17886. Geometry.call( this );
  17887. this.type = 'TorusKnotGeometry';
  17888. this.parameters = {
  17889. radius: radius,
  17890. tube: tube,
  17891. tubularSegments: tubularSegments,
  17892. radialSegments: radialSegments,
  17893. p: p,
  17894. q: q
  17895. };
  17896. if ( heightScale !== undefined ) { console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' ); }
  17897. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  17898. this.mergeVertices();
  17899. }
  17900. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  17901. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  17902. // TorusKnotBufferGeometry
  17903. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  17904. BufferGeometry.call( this );
  17905. this.type = 'TorusKnotBufferGeometry';
  17906. this.parameters = {
  17907. radius: radius,
  17908. tube: tube,
  17909. tubularSegments: tubularSegments,
  17910. radialSegments: radialSegments,
  17911. p: p,
  17912. q: q
  17913. };
  17914. radius = radius || 1;
  17915. tube = tube || 0.4;
  17916. tubularSegments = Math.floor( tubularSegments ) || 64;
  17917. radialSegments = Math.floor( radialSegments ) || 8;
  17918. p = p || 2;
  17919. q = q || 3;
  17920. // buffers
  17921. var indices = [];
  17922. var vertices = [];
  17923. var normals = [];
  17924. var uvs = [];
  17925. // helper variables
  17926. var vertex = new Vector3();
  17927. var normal = new Vector3();
  17928. var P1 = new Vector3();
  17929. var P2 = new Vector3();
  17930. var B = new Vector3();
  17931. var T = new Vector3();
  17932. var N = new Vector3();
  17933. // generate vertices, normals and uvs
  17934. for ( var i = 0; i <= tubularSegments; ++ i ) {
  17935. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17936. var u = i / tubularSegments * p * Math.PI * 2;
  17937. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17938. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17939. calculatePositionOnCurve( u, p, q, radius, P1 );
  17940. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17941. // calculate orthonormal basis
  17942. T.subVectors( P2, P1 );
  17943. N.addVectors( P2, P1 );
  17944. B.crossVectors( T, N );
  17945. N.crossVectors( B, T );
  17946. // normalize B, N. T can be ignored, we don't use it
  17947. B.normalize();
  17948. N.normalize();
  17949. for ( var j = 0; j <= radialSegments; ++ j ) {
  17950. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17951. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17952. var v = j / radialSegments * Math.PI * 2;
  17953. var cx = - tube * Math.cos( v );
  17954. var cy = tube * Math.sin( v );
  17955. // now calculate the final vertex position.
  17956. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17957. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17958. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17959. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17960. vertices.push( vertex.x, vertex.y, vertex.z );
  17961. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17962. normal.subVectors( vertex, P1 ).normalize();
  17963. normals.push( normal.x, normal.y, normal.z );
  17964. // uv
  17965. uvs.push( i / tubularSegments );
  17966. uvs.push( j / radialSegments );
  17967. }
  17968. }
  17969. // generate indices
  17970. for ( var j$1 = 1; j$1 <= tubularSegments; j$1 ++ ) {
  17971. for ( var i$1 = 1; i$1 <= radialSegments; i$1 ++ ) {
  17972. // indices
  17973. var a = ( radialSegments + 1 ) * ( j$1 - 1 ) + ( i$1 - 1 );
  17974. var b = ( radialSegments + 1 ) * j$1 + ( i$1 - 1 );
  17975. var c = ( radialSegments + 1 ) * j$1 + i$1;
  17976. var d = ( radialSegments + 1 ) * ( j$1 - 1 ) + i$1;
  17977. // faces
  17978. indices.push( a, b, d );
  17979. indices.push( b, c, d );
  17980. }
  17981. }
  17982. // build geometry
  17983. this.setIndex( indices );
  17984. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17985. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17986. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17987. // this function calculates the current position on the torus curve
  17988. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17989. var cu = Math.cos( u );
  17990. var su = Math.sin( u );
  17991. var quOverP = q / p * u;
  17992. var cs = Math.cos( quOverP );
  17993. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17994. position.y = radius * ( 2 + cs ) * su * 0.5;
  17995. position.z = radius * Math.sin( quOverP ) * 0.5;
  17996. }
  17997. }
  17998. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17999. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  18000. /**
  18001. * @author oosmoxiecode
  18002. * @author mrdoob / http://mrdoob.com/
  18003. * @author Mugen87 / https://github.com/Mugen87
  18004. */
  18005. // TorusGeometry
  18006. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  18007. Geometry.call( this );
  18008. this.type = 'TorusGeometry';
  18009. this.parameters = {
  18010. radius: radius,
  18011. tube: tube,
  18012. radialSegments: radialSegments,
  18013. tubularSegments: tubularSegments,
  18014. arc: arc
  18015. };
  18016. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  18017. this.mergeVertices();
  18018. }
  18019. TorusGeometry.prototype = Object.create( Geometry.prototype );
  18020. TorusGeometry.prototype.constructor = TorusGeometry;
  18021. // TorusBufferGeometry
  18022. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  18023. BufferGeometry.call( this );
  18024. this.type = 'TorusBufferGeometry';
  18025. this.parameters = {
  18026. radius: radius,
  18027. tube: tube,
  18028. radialSegments: radialSegments,
  18029. tubularSegments: tubularSegments,
  18030. arc: arc
  18031. };
  18032. radius = radius || 1;
  18033. tube = tube || 0.4;
  18034. radialSegments = Math.floor( radialSegments ) || 8;
  18035. tubularSegments = Math.floor( tubularSegments ) || 6;
  18036. arc = arc || Math.PI * 2;
  18037. // buffers
  18038. var indices = [];
  18039. var vertices = [];
  18040. var normals = [];
  18041. var uvs = [];
  18042. // helper variables
  18043. var center = new Vector3();
  18044. var vertex = new Vector3();
  18045. var normal = new Vector3();
  18046. // generate vertices, normals and uvs
  18047. for ( var j = 0; j <= radialSegments; j ++ ) {
  18048. for ( var i = 0; i <= tubularSegments; i ++ ) {
  18049. var u = i / tubularSegments * arc;
  18050. var v = j / radialSegments * Math.PI * 2;
  18051. // vertex
  18052. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  18053. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  18054. vertex.z = tube * Math.sin( v );
  18055. vertices.push( vertex.x, vertex.y, vertex.z );
  18056. // normal
  18057. center.x = radius * Math.cos( u );
  18058. center.y = radius * Math.sin( u );
  18059. normal.subVectors( vertex, center ).normalize();
  18060. normals.push( normal.x, normal.y, normal.z );
  18061. // uv
  18062. uvs.push( i / tubularSegments );
  18063. uvs.push( j / radialSegments );
  18064. }
  18065. }
  18066. // generate indices
  18067. for ( var j$1 = 1; j$1 <= radialSegments; j$1 ++ ) {
  18068. for ( var i$1 = 1; i$1 <= tubularSegments; i$1 ++ ) {
  18069. // indices
  18070. var a = ( tubularSegments + 1 ) * j$1 + i$1 - 1;
  18071. var b = ( tubularSegments + 1 ) * ( j$1 - 1 ) + i$1 - 1;
  18072. var c = ( tubularSegments + 1 ) * ( j$1 - 1 ) + i$1;
  18073. var d = ( tubularSegments + 1 ) * j$1 + i$1;
  18074. // faces
  18075. indices.push( a, b, d );
  18076. indices.push( b, c, d );
  18077. }
  18078. }
  18079. // build geometry
  18080. this.setIndex( indices );
  18081. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18082. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18083. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18084. }
  18085. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18086. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  18087. /**
  18088. * @author Mugen87 / https://github.com/Mugen87
  18089. * Port from https://github.com/mapbox/earcut (v2.2.2)
  18090. */
  18091. var Earcut = {
  18092. triangulate: function ( data, holeIndices, dim ) {
  18093. dim = dim || 2;
  18094. var hasHoles = holeIndices && holeIndices.length,
  18095. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  18096. outerNode = linkedList( data, 0, outerLen, dim, true ),
  18097. triangles = [];
  18098. if ( ! outerNode || outerNode.next === outerNode.prev ) { return triangles; }
  18099. var minX, minY, maxX, maxY, x, y, invSize;
  18100. if ( hasHoles ) { outerNode = eliminateHoles( data, holeIndices, outerNode, dim ); }
  18101. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  18102. if ( data.length > 80 * dim ) {
  18103. minX = maxX = data[ 0 ];
  18104. minY = maxY = data[ 1 ];
  18105. for ( var i = dim; i < outerLen; i += dim ) {
  18106. x = data[ i ];
  18107. y = data[ i + 1 ];
  18108. if ( x < minX ) { minX = x; }
  18109. if ( y < minY ) { minY = y; }
  18110. if ( x > maxX ) { maxX = x; }
  18111. if ( y > maxY ) { maxY = y; }
  18112. }
  18113. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18114. invSize = Math.max( maxX - minX, maxY - minY );
  18115. invSize = invSize !== 0 ? 1 / invSize : 0;
  18116. }
  18117. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  18118. return triangles;
  18119. }
  18120. };
  18121. // create a circular doubly linked list from polygon points in the specified winding order
  18122. function linkedList( data, start, end, dim, clockwise ) {
  18123. var i, last;
  18124. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  18125. for ( i = start; i < end; i += dim ) { last = insertNode( i, data[ i ], data[ i + 1 ], last ); }
  18126. } else {
  18127. for ( i = end - dim; i >= start; i -= dim ) { last = insertNode( i, data[ i ], data[ i + 1 ], last ); }
  18128. }
  18129. if ( last && equals( last, last.next ) ) {
  18130. removeNode( last );
  18131. last = last.next;
  18132. }
  18133. return last;
  18134. }
  18135. // eliminate colinear or duplicate points
  18136. function filterPoints( start, end ) {
  18137. if ( ! start ) { return start; }
  18138. if ( ! end ) { end = start; }
  18139. var p = start,
  18140. again;
  18141. do {
  18142. again = false;
  18143. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  18144. removeNode( p );
  18145. p = end = p.prev;
  18146. if ( p === p.next ) { break; }
  18147. again = true;
  18148. } else {
  18149. p = p.next;
  18150. }
  18151. } while ( again || p !== end );
  18152. return end;
  18153. }
  18154. // main ear slicing loop which triangulates a polygon (given as a linked list)
  18155. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  18156. if ( ! ear ) { return; }
  18157. // interlink polygon nodes in z-order
  18158. if ( ! pass && invSize ) { indexCurve( ear, minX, minY, invSize ); }
  18159. var stop = ear,
  18160. prev, next;
  18161. // iterate through ears, slicing them one by one
  18162. while ( ear.prev !== ear.next ) {
  18163. prev = ear.prev;
  18164. next = ear.next;
  18165. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  18166. // cut off the triangle
  18167. triangles.push( prev.i / dim );
  18168. triangles.push( ear.i / dim );
  18169. triangles.push( next.i / dim );
  18170. removeNode( ear );
  18171. // skipping the next vertex leads to less sliver triangles
  18172. ear = next.next;
  18173. stop = next.next;
  18174. continue;
  18175. }
  18176. ear = next;
  18177. // if we looped through the whole remaining polygon and can't find any more ears
  18178. if ( ear === stop ) {
  18179. // try filtering points and slicing again
  18180. if ( ! pass ) {
  18181. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  18182. // if this didn't work, try curing all small self-intersections locally
  18183. } else if ( pass === 1 ) {
  18184. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  18185. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  18186. // as a last resort, try splitting the remaining polygon into two
  18187. } else if ( pass === 2 ) {
  18188. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  18189. }
  18190. break;
  18191. }
  18192. }
  18193. }
  18194. // check whether a polygon node forms a valid ear with adjacent nodes
  18195. function isEar( ear ) {
  18196. var a = ear.prev,
  18197. b = ear,
  18198. c = ear.next;
  18199. if ( area( a, b, c ) >= 0 ) { return false; } // reflex, can't be an ear
  18200. // now make sure we don't have other points inside the potential ear
  18201. var p = ear.next.next;
  18202. while ( p !== ear.prev ) {
  18203. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18204. area( p.prev, p, p.next ) >= 0 ) { return false; }
  18205. p = p.next;
  18206. }
  18207. return true;
  18208. }
  18209. function isEarHashed( ear, minX, minY, invSize ) {
  18210. var a = ear.prev,
  18211. b = ear,
  18212. c = ear.next;
  18213. if ( area( a, b, c ) >= 0 ) { return false; } // reflex, can't be an ear
  18214. // triangle bbox; min & max are calculated like this for speed
  18215. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  18216. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  18217. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  18218. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  18219. // z-order range for the current triangle bbox;
  18220. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  18221. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  18222. var p = ear.prevZ,
  18223. n = ear.nextZ;
  18224. // look for points inside the triangle in both directions
  18225. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  18226. if ( p !== ear.prev && p !== ear.next &&
  18227. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18228. area( p.prev, p, p.next ) >= 0 ) { return false; }
  18229. p = p.prevZ;
  18230. if ( n !== ear.prev && n !== ear.next &&
  18231. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  18232. area( n.prev, n, n.next ) >= 0 ) { return false; }
  18233. n = n.nextZ;
  18234. }
  18235. // look for remaining points in decreasing z-order
  18236. while ( p && p.z >= minZ ) {
  18237. if ( p !== ear.prev && p !== ear.next &&
  18238. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18239. area( p.prev, p, p.next ) >= 0 ) { return false; }
  18240. p = p.prevZ;
  18241. }
  18242. // look for remaining points in increasing z-order
  18243. while ( n && n.z <= maxZ ) {
  18244. if ( n !== ear.prev && n !== ear.next &&
  18245. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  18246. area( n.prev, n, n.next ) >= 0 ) { return false; }
  18247. n = n.nextZ;
  18248. }
  18249. return true;
  18250. }
  18251. // go through all polygon nodes and cure small local self-intersections
  18252. function cureLocalIntersections( start, triangles, dim ) {
  18253. var p = start;
  18254. do {
  18255. var a = p.prev,
  18256. b = p.next.next;
  18257. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  18258. triangles.push( a.i / dim );
  18259. triangles.push( p.i / dim );
  18260. triangles.push( b.i / dim );
  18261. // remove two nodes involved
  18262. removeNode( p );
  18263. removeNode( p.next );
  18264. p = start = b;
  18265. }
  18266. p = p.next;
  18267. } while ( p !== start );
  18268. return filterPoints( p );
  18269. }
  18270. // try splitting polygon into two and triangulate them independently
  18271. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  18272. // look for a valid diagonal that divides the polygon into two
  18273. var a = start;
  18274. do {
  18275. var b = a.next.next;
  18276. while ( b !== a.prev ) {
  18277. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  18278. // split the polygon in two by the diagonal
  18279. var c = splitPolygon( a, b );
  18280. // filter colinear points around the cuts
  18281. a = filterPoints( a, a.next );
  18282. c = filterPoints( c, c.next );
  18283. // run earcut on each half
  18284. earcutLinked( a, triangles, dim, minX, minY, invSize );
  18285. earcutLinked( c, triangles, dim, minX, minY, invSize );
  18286. return;
  18287. }
  18288. b = b.next;
  18289. }
  18290. a = a.next;
  18291. } while ( a !== start );
  18292. }
  18293. // link every hole into the outer loop, producing a single-ring polygon without holes
  18294. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  18295. var queue = [],
  18296. i, len, start, end, list;
  18297. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  18298. start = holeIndices[ i ] * dim;
  18299. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  18300. list = linkedList( data, start, end, dim, false );
  18301. if ( list === list.next ) { list.steiner = true; }
  18302. queue.push( getLeftmost( list ) );
  18303. }
  18304. queue.sort( compareX );
  18305. // process holes from left to right
  18306. for ( i = 0; i < queue.length; i ++ ) {
  18307. eliminateHole( queue[ i ], outerNode );
  18308. outerNode = filterPoints( outerNode, outerNode.next );
  18309. }
  18310. return outerNode;
  18311. }
  18312. function compareX( a, b ) {
  18313. return a.x - b.x;
  18314. }
  18315. // find a bridge between vertices that connects hole with an outer ring and and link it
  18316. function eliminateHole( hole, outerNode ) {
  18317. outerNode = findHoleBridge( hole, outerNode );
  18318. if ( outerNode ) {
  18319. var b = splitPolygon( outerNode, hole );
  18320. // filter collinear points around the cuts
  18321. filterPoints( outerNode, outerNode.next );
  18322. filterPoints( b, b.next );
  18323. }
  18324. }
  18325. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18326. function findHoleBridge( hole, outerNode ) {
  18327. var p = outerNode,
  18328. hx = hole.x,
  18329. hy = hole.y,
  18330. qx = - Infinity,
  18331. m;
  18332. // find a segment intersected by a ray from the hole's leftmost point to the left;
  18333. // segment's endpoint with lesser x will be potential connection point
  18334. do {
  18335. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  18336. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  18337. if ( x <= hx && x > qx ) {
  18338. qx = x;
  18339. if ( x === hx ) {
  18340. if ( hy === p.y ) { return p; }
  18341. if ( hy === p.next.y ) { return p.next; }
  18342. }
  18343. m = p.x < p.next.x ? p : p.next;
  18344. }
  18345. }
  18346. p = p.next;
  18347. } while ( p !== outerNode );
  18348. if ( ! m ) { return null; }
  18349. if ( hx === qx ) { return m; } // hole touches outer segment; pick leftmost endpoint
  18350. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18351. // if there are no points found, we have a valid connection;
  18352. // otherwise choose the point of the minimum angle with the ray as connection point
  18353. var stop = m,
  18354. mx = m.x,
  18355. my = m.y,
  18356. tanMin = Infinity,
  18357. tan;
  18358. p = m;
  18359. do {
  18360. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  18361. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  18362. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  18363. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  18364. m = p;
  18365. tanMin = tan;
  18366. }
  18367. }
  18368. p = p.next;
  18369. } while ( p !== stop );
  18370. return m;
  18371. }
  18372. // whether sector in vertex m contains sector in vertex p in the same coordinates
  18373. function sectorContainsSector( m, p ) {
  18374. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  18375. }
  18376. // interlink polygon nodes in z-order
  18377. function indexCurve( start, minX, minY, invSize ) {
  18378. var p = start;
  18379. do {
  18380. if ( p.z === null ) { p.z = zOrder( p.x, p.y, minX, minY, invSize ); }
  18381. p.prevZ = p.prev;
  18382. p.nextZ = p.next;
  18383. p = p.next;
  18384. } while ( p !== start );
  18385. p.prevZ.nextZ = null;
  18386. p.prevZ = null;
  18387. sortLinked( p );
  18388. }
  18389. // Simon Tatham's linked list merge sort algorithm
  18390. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18391. function sortLinked( list ) {
  18392. var i, p, q, e, tail, numMerges, pSize, qSize,
  18393. inSize = 1;
  18394. do {
  18395. p = list;
  18396. list = null;
  18397. tail = null;
  18398. numMerges = 0;
  18399. while ( p ) {
  18400. numMerges ++;
  18401. q = p;
  18402. pSize = 0;
  18403. for ( i = 0; i < inSize; i ++ ) {
  18404. pSize ++;
  18405. q = q.nextZ;
  18406. if ( ! q ) { break; }
  18407. }
  18408. qSize = inSize;
  18409. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  18410. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  18411. e = p;
  18412. p = p.nextZ;
  18413. pSize --;
  18414. } else {
  18415. e = q;
  18416. q = q.nextZ;
  18417. qSize --;
  18418. }
  18419. if ( tail ) { tail.nextZ = e; }
  18420. else { list = e; }
  18421. e.prevZ = tail;
  18422. tail = e;
  18423. }
  18424. p = q;
  18425. }
  18426. tail.nextZ = null;
  18427. inSize *= 2;
  18428. } while ( numMerges > 1 );
  18429. return list;
  18430. }
  18431. // z-order of a point given coords and inverse of the longer side of data bbox
  18432. function zOrder( x, y, minX, minY, invSize ) {
  18433. // coords are transformed into non-negative 15-bit integer range
  18434. x = 32767 * ( x - minX ) * invSize;
  18435. y = 32767 * ( y - minY ) * invSize;
  18436. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  18437. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  18438. x = ( x | ( x << 2 ) ) & 0x33333333;
  18439. x = ( x | ( x << 1 ) ) & 0x55555555;
  18440. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  18441. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  18442. y = ( y | ( y << 2 ) ) & 0x33333333;
  18443. y = ( y | ( y << 1 ) ) & 0x55555555;
  18444. return x | ( y << 1 );
  18445. }
  18446. // find the leftmost node of a polygon ring
  18447. function getLeftmost( start ) {
  18448. var p = start,
  18449. leftmost = start;
  18450. do {
  18451. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) { leftmost = p; }
  18452. p = p.next;
  18453. } while ( p !== start );
  18454. return leftmost;
  18455. }
  18456. // check if a point lies within a convex triangle
  18457. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  18458. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  18459. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  18460. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  18461. }
  18462. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18463. function isValidDiagonal( a, b ) {
  18464. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  18465. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  18466. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  18467. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  18468. }
  18469. // signed area of a triangle
  18470. function area( p, q, r ) {
  18471. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  18472. }
  18473. // check if two points are equal
  18474. function equals( p1, p2 ) {
  18475. return p1.x === p2.x && p1.y === p2.y;
  18476. }
  18477. // check if two segments intersect
  18478. function intersects( p1, q1, p2, q2 ) {
  18479. var o1 = sign( area( p1, q1, p2 ) );
  18480. var o2 = sign( area( p1, q1, q2 ) );
  18481. var o3 = sign( area( p2, q2, p1 ) );
  18482. var o4 = sign( area( p2, q2, q1 ) );
  18483. if ( o1 !== o2 && o3 !== o4 ) { return true; } // general case
  18484. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) { return true; } // p1, q1 and p2 are collinear and p2 lies on p1q1
  18485. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) { return true; } // p1, q1 and q2 are collinear and q2 lies on p1q1
  18486. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) { return true; } // p2, q2 and p1 are collinear and p1 lies on p2q2
  18487. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) { return true; } // p2, q2 and q1 are collinear and q1 lies on p2q2
  18488. return false;
  18489. }
  18490. // for collinear points p, q, r, check if point q lies on segment pr
  18491. function onSegment( p, q, r ) {
  18492. 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 );
  18493. }
  18494. function sign( num ) {
  18495. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  18496. }
  18497. // check if a polygon diagonal intersects any polygon segments
  18498. function intersectsPolygon( a, b ) {
  18499. var p = a;
  18500. do {
  18501. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  18502. intersects( p, p.next, a, b ) ) { return true; }
  18503. p = p.next;
  18504. } while ( p !== a );
  18505. return false;
  18506. }
  18507. // check if a polygon diagonal is locally inside the polygon
  18508. function locallyInside( a, b ) {
  18509. return area( a.prev, a, a.next ) < 0 ?
  18510. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  18511. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  18512. }
  18513. // check if the middle point of a polygon diagonal is inside the polygon
  18514. function middleInside( a, b ) {
  18515. var p = a,
  18516. inside = false,
  18517. px = ( a.x + b.x ) / 2,
  18518. py = ( a.y + b.y ) / 2;
  18519. do {
  18520. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  18521. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  18522. { inside = ! inside; }
  18523. p = p.next;
  18524. } while ( p !== a );
  18525. return inside;
  18526. }
  18527. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18528. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18529. function splitPolygon( a, b ) {
  18530. var a2 = new Node( a.i, a.x, a.y ),
  18531. b2 = new Node( b.i, b.x, b.y ),
  18532. an = a.next,
  18533. bp = b.prev;
  18534. a.next = b;
  18535. b.prev = a;
  18536. a2.next = an;
  18537. an.prev = a2;
  18538. b2.next = a2;
  18539. a2.prev = b2;
  18540. bp.next = b2;
  18541. b2.prev = bp;
  18542. return b2;
  18543. }
  18544. // create a node and optionally link it with previous one (in a circular doubly linked list)
  18545. function insertNode( i, x, y, last ) {
  18546. var p = new Node( i, x, y );
  18547. if ( ! last ) {
  18548. p.prev = p;
  18549. p.next = p;
  18550. } else {
  18551. p.next = last.next;
  18552. p.prev = last;
  18553. last.next.prev = p;
  18554. last.next = p;
  18555. }
  18556. return p;
  18557. }
  18558. function removeNode( p ) {
  18559. p.next.prev = p.prev;
  18560. p.prev.next = p.next;
  18561. if ( p.prevZ ) { p.prevZ.nextZ = p.nextZ; }
  18562. if ( p.nextZ ) { p.nextZ.prevZ = p.prevZ; }
  18563. }
  18564. function Node( i, x, y ) {
  18565. // vertex index in coordinates array
  18566. this.i = i;
  18567. // vertex coordinates
  18568. this.x = x;
  18569. this.y = y;
  18570. // previous and next vertex nodes in a polygon ring
  18571. this.prev = null;
  18572. this.next = null;
  18573. // z-order curve value
  18574. this.z = null;
  18575. // previous and next nodes in z-order
  18576. this.prevZ = null;
  18577. this.nextZ = null;
  18578. // indicates whether this is a steiner point
  18579. this.steiner = false;
  18580. }
  18581. function signedArea( data, start, end, dim ) {
  18582. var sum = 0;
  18583. for ( var i = start, j = end - dim; i < end; i += dim ) {
  18584. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  18585. j = i;
  18586. }
  18587. return sum;
  18588. }
  18589. /**
  18590. * @author zz85 / http://www.lab4games.net/zz85/blog
  18591. */
  18592. var ShapeUtils = {
  18593. // calculate area of the contour polygon
  18594. area: function ( contour ) {
  18595. var n = contour.length;
  18596. var a = 0.0;
  18597. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  18598. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  18599. }
  18600. return a * 0.5;
  18601. },
  18602. isClockWise: function ( pts ) {
  18603. return ShapeUtils.area( pts ) < 0;
  18604. },
  18605. triangulateShape: function ( contour, holes ) {
  18606. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18607. var holeIndices = []; // array of hole indices
  18608. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18609. removeDupEndPts( contour );
  18610. addContour( vertices, contour );
  18611. //
  18612. var holeIndex = contour.length;
  18613. holes.forEach( removeDupEndPts );
  18614. for ( var i = 0; i < holes.length; i ++ ) {
  18615. holeIndices.push( holeIndex );
  18616. holeIndex += holes[ i ].length;
  18617. addContour( vertices, holes[ i ] );
  18618. }
  18619. //
  18620. var triangles = Earcut.triangulate( vertices, holeIndices );
  18621. //
  18622. for ( var i$1 = 0; i$1 < triangles.length; i$1 += 3 ) {
  18623. faces.push( triangles.slice( i$1, i$1 + 3 ) );
  18624. }
  18625. return faces;
  18626. }
  18627. };
  18628. function removeDupEndPts( points ) {
  18629. var l = points.length;
  18630. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  18631. points.pop();
  18632. }
  18633. }
  18634. function addContour( vertices, contour ) {
  18635. for ( var i = 0; i < contour.length; i ++ ) {
  18636. vertices.push( contour[ i ].x );
  18637. vertices.push( contour[ i ].y );
  18638. }
  18639. }
  18640. /**
  18641. * @author zz85 / http://www.lab4games.net/zz85/blog
  18642. *
  18643. * Creates extruded geometry from a path shape.
  18644. *
  18645. * parameters = {
  18646. *
  18647. * curveSegments: <int>, // number of points on the curves
  18648. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18649. * depth: <float>, // Depth to extrude the shape
  18650. *
  18651. * bevelEnabled: <bool>, // turn on bevel
  18652. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18653. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18654. * bevelOffset: <float>, // how far from shape outline does bevel start
  18655. * bevelSegments: <int>, // number of bevel layers
  18656. *
  18657. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18658. *
  18659. * UVGenerator: <Object> // object that provides UV generator functions
  18660. *
  18661. * }
  18662. */
  18663. // ExtrudeGeometry
  18664. function ExtrudeGeometry( shapes, options ) {
  18665. Geometry.call( this );
  18666. this.type = 'ExtrudeGeometry';
  18667. this.parameters = {
  18668. shapes: shapes,
  18669. options: options
  18670. };
  18671. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  18672. this.mergeVertices();
  18673. }
  18674. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  18675. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  18676. ExtrudeGeometry.prototype.toJSON = function () {
  18677. var data = Geometry.prototype.toJSON.call( this );
  18678. var shapes = this.parameters.shapes;
  18679. var options = this.parameters.options;
  18680. return toJSON( shapes, options, data );
  18681. };
  18682. // ExtrudeBufferGeometry
  18683. function ExtrudeBufferGeometry( shapes, options ) {
  18684. BufferGeometry.call( this );
  18685. this.type = 'ExtrudeBufferGeometry';
  18686. this.parameters = {
  18687. shapes: shapes,
  18688. options: options
  18689. };
  18690. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18691. var scope = this;
  18692. var verticesArray = [];
  18693. var uvArray = [];
  18694. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18695. var shape = shapes[ i ];
  18696. addShape( shape );
  18697. }
  18698. // build geometry
  18699. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  18700. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  18701. this.computeVertexNormals();
  18702. // functions
  18703. function addShape( shape ) {
  18704. var placeholder = [];
  18705. // options
  18706. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18707. var steps = options.steps !== undefined ? options.steps : 1;
  18708. var depth = options.depth !== undefined ? options.depth : 100;
  18709. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18710. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18711. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18712. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18713. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18714. var extrudePath = options.extrudePath;
  18715. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  18716. // deprecated options
  18717. if ( options.amount !== undefined ) {
  18718. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  18719. depth = options.amount;
  18720. }
  18721. //
  18722. var extrudePts, extrudeByPath = false;
  18723. var splineTube, binormal, normal, position2;
  18724. if ( extrudePath ) {
  18725. extrudePts = extrudePath.getSpacedPoints( steps );
  18726. extrudeByPath = true;
  18727. bevelEnabled = false; // bevels not supported for path extrusion
  18728. // SETUP TNB variables
  18729. // TODO1 - have a .isClosed in spline?
  18730. splineTube = extrudePath.computeFrenetFrames( steps, false );
  18731. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18732. binormal = new Vector3();
  18733. normal = new Vector3();
  18734. position2 = new Vector3();
  18735. }
  18736. // Safeguards if bevels are not enabled
  18737. if ( ! bevelEnabled ) {
  18738. bevelSegments = 0;
  18739. bevelThickness = 0;
  18740. bevelSize = 0;
  18741. bevelOffset = 0;
  18742. }
  18743. // Variables initialization
  18744. var shapePoints = shape.extractPoints( curveSegments );
  18745. var vertices = shapePoints.shape;
  18746. var holes = shapePoints.holes;
  18747. var reverse = ! ShapeUtils.isClockWise( vertices );
  18748. if ( reverse ) {
  18749. vertices = vertices.reverse();
  18750. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18751. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18752. var ahole = holes[ h ];
  18753. if ( ShapeUtils.isClockWise( ahole ) ) {
  18754. holes[ h ] = ahole.reverse();
  18755. }
  18756. }
  18757. }
  18758. var faces = ShapeUtils.triangulateShape( vertices, holes );
  18759. /* Vertices */
  18760. var contour = vertices; // vertices has all points but contour has only points of circumference
  18761. for ( var h$1 = 0, hl$1 = holes.length; h$1 < hl$1; h$1 ++ ) {
  18762. var ahole$1 = holes[ h$1 ];
  18763. vertices = vertices.concat( ahole$1 );
  18764. }
  18765. function scalePt2( pt, vec, size ) {
  18766. if ( ! vec ) { console.error( "THREE.ExtrudeGeometry: vec does not exist" ); }
  18767. return vec.clone().multiplyScalar( size ).add( pt );
  18768. }
  18769. var vlen = vertices.length, flen = faces.length;
  18770. // Find directions for point movement
  18771. function getBevelVec( inPt, inPrev, inNext ) {
  18772. // computes for inPt the corresponding point inPt' on a new contour
  18773. // shifted by 1 unit (length of normalized vector) to the left
  18774. // if we walk along contour clockwise, this new contour is outside the old one
  18775. //
  18776. // inPt' is the intersection of the two lines parallel to the two
  18777. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18778. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18779. // good reading for geometry algorithms (here: line-line intersection)
  18780. // http://geomalgorithms.com/a05-_intersect-1.html
  18781. var v_prev_x = inPt.x - inPrev.x,
  18782. v_prev_y = inPt.y - inPrev.y;
  18783. var v_next_x = inNext.x - inPt.x,
  18784. v_next_y = inNext.y - inPt.y;
  18785. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18786. // check for collinear edges
  18787. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18788. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  18789. // not collinear
  18790. // length of vectors for normalizing
  18791. var v_prev_len = Math.sqrt( v_prev_lensq );
  18792. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18793. // shift adjacent points by unit vectors to the left
  18794. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18795. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18796. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18797. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18798. // scaling factor for v_prev to intersection point
  18799. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18800. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18801. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18802. // vector from inPt to intersection point
  18803. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18804. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18805. // Don't normalize!, otherwise sharp corners become ugly
  18806. // but prevent crazy spikes
  18807. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18808. if ( v_trans_lensq <= 2 ) {
  18809. return new Vector2( v_trans_x, v_trans_y );
  18810. } else {
  18811. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18812. }
  18813. } else {
  18814. // handle special case of collinear edges
  18815. var direction_eq = false; // assumes: opposite
  18816. if ( v_prev_x > Number.EPSILON ) {
  18817. if ( v_next_x > Number.EPSILON ) {
  18818. direction_eq = true;
  18819. }
  18820. } else {
  18821. if ( v_prev_x < - Number.EPSILON ) {
  18822. if ( v_next_x < - Number.EPSILON ) {
  18823. direction_eq = true;
  18824. }
  18825. } else {
  18826. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18827. direction_eq = true;
  18828. }
  18829. }
  18830. }
  18831. if ( direction_eq ) {
  18832. // console.log("Warning: lines are a straight sequence");
  18833. v_trans_x = - v_prev_y;
  18834. v_trans_y = v_prev_x;
  18835. shrink_by = Math.sqrt( v_prev_lensq );
  18836. } else {
  18837. // console.log("Warning: lines are a straight spike");
  18838. v_trans_x = v_prev_x;
  18839. v_trans_y = v_prev_y;
  18840. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18841. }
  18842. }
  18843. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18844. }
  18845. var contourMovements = [];
  18846. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18847. if ( j === il ) { j = 0; }
  18848. if ( k === il ) { k = 0; }
  18849. // (j)---(i)---(k)
  18850. // console.log('i,j,k', i, j , k)
  18851. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18852. }
  18853. var holesMovements = [];
  18854. var oneHoleMovements, verticesMovements = contourMovements.concat();
  18855. for ( var h$2 = 0, hl$2 = holes.length; h$2 < hl$2; h$2 ++ ) {
  18856. var ahole$2 = holes[ h$2 ];
  18857. oneHoleMovements = [];
  18858. for ( var i$1 = 0, il$1 = ahole$2.length, j$1 = il$1 - 1, k$1 = i$1 + 1; i$1 < il$1; i$1 ++, j$1 ++, k$1 ++ ) {
  18859. if ( j$1 === il$1 ) { j$1 = 0; }
  18860. if ( k$1 === il$1 ) { k$1 = 0; }
  18861. // (j)---(i)---(k)
  18862. oneHoleMovements[ i$1 ] = getBevelVec( ahole$2[ i$1 ], ahole$2[ j$1 ], ahole$2[ k$1 ] );
  18863. }
  18864. holesMovements.push( oneHoleMovements );
  18865. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18866. }
  18867. // Loop bevelSegments, 1 for the front, 1 for the back
  18868. for ( var b = 0; b < bevelSegments; b ++ ) {
  18869. //for ( b = bevelSegments; b > 0; b -- ) {
  18870. var t = b / bevelSegments;
  18871. var z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18872. var bs$1 = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18873. // contract shape
  18874. for ( var i$2 = 0, il$2 = contour.length; i$2 < il$2; i$2 ++ ) {
  18875. var vert = scalePt2( contour[ i$2 ], contourMovements[ i$2 ], bs$1 );
  18876. v( vert.x, vert.y, - z );
  18877. }
  18878. // expand holes
  18879. for ( var h$3 = 0, hl$3 = holes.length; h$3 < hl$3; h$3 ++ ) {
  18880. var ahole$3 = holes[ h$3 ];
  18881. oneHoleMovements = holesMovements[ h$3 ];
  18882. for ( var i$3 = 0, il$3 = ahole$3.length; i$3 < il$3; i$3 ++ ) {
  18883. var vert$1 = scalePt2( ahole$3[ i$3 ], oneHoleMovements[ i$3 ], bs$1 );
  18884. v( vert$1.x, vert$1.y, - z );
  18885. }
  18886. }
  18887. }
  18888. var bs = bevelSize + bevelOffset;
  18889. // Back facing vertices
  18890. for ( var i$4 = 0; i$4 < vlen; i$4 ++ ) {
  18891. var vert$2 = bevelEnabled ? scalePt2( vertices[ i$4 ], verticesMovements[ i$4 ], bs ) : vertices[ i$4 ];
  18892. if ( ! extrudeByPath ) {
  18893. v( vert$2.x, vert$2.y, 0 );
  18894. } else {
  18895. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18896. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert$2.x );
  18897. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert$2.y );
  18898. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18899. v( position2.x, position2.y, position2.z );
  18900. }
  18901. }
  18902. // Add stepped vertices...
  18903. // Including front facing vertices
  18904. for ( var s = 1; s <= steps; s ++ ) {
  18905. for ( var i$5 = 0; i$5 < vlen; i$5 ++ ) {
  18906. var vert$3 = bevelEnabled ? scalePt2( vertices[ i$5 ], verticesMovements[ i$5 ], bs ) : vertices[ i$5 ];
  18907. if ( ! extrudeByPath ) {
  18908. v( vert$3.x, vert$3.y, depth / steps * s );
  18909. } else {
  18910. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18911. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert$3.x );
  18912. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert$3.y );
  18913. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18914. v( position2.x, position2.y, position2.z );
  18915. }
  18916. }
  18917. }
  18918. // Add bevel segments planes
  18919. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18920. for ( var b$1 = bevelSegments - 1; b$1 >= 0; b$1 -- ) {
  18921. var t$1 = b$1 / bevelSegments;
  18922. var z$1 = bevelThickness * Math.cos( t$1 * Math.PI / 2 );
  18923. var bs$2 = bevelSize * Math.sin( t$1 * Math.PI / 2 ) + bevelOffset;
  18924. // contract shape
  18925. for ( var i$6 = 0, il$4 = contour.length; i$6 < il$4; i$6 ++ ) {
  18926. var vert$4 = scalePt2( contour[ i$6 ], contourMovements[ i$6 ], bs$2 );
  18927. v( vert$4.x, vert$4.y, depth + z$1 );
  18928. }
  18929. // expand holes
  18930. for ( var h$4 = 0, hl$4 = holes.length; h$4 < hl$4; h$4 ++ ) {
  18931. var ahole$4 = holes[ h$4 ];
  18932. oneHoleMovements = holesMovements[ h$4 ];
  18933. for ( var i$7 = 0, il$5 = ahole$4.length; i$7 < il$5; i$7 ++ ) {
  18934. var vert$5 = scalePt2( ahole$4[ i$7 ], oneHoleMovements[ i$7 ], bs$2 );
  18935. if ( ! extrudeByPath ) {
  18936. v( vert$5.x, vert$5.y, depth + z$1 );
  18937. } else {
  18938. v( vert$5.x, vert$5.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z$1 );
  18939. }
  18940. }
  18941. }
  18942. }
  18943. /* Faces */
  18944. // Top and bottom faces
  18945. buildLidFaces();
  18946. // Sides faces
  18947. buildSideFaces();
  18948. ///// Internal functions
  18949. function buildLidFaces() {
  18950. var start = verticesArray.length / 3;
  18951. if ( bevelEnabled ) {
  18952. var layer = 0; // steps + 1
  18953. var offset = vlen * layer;
  18954. // Bottom faces
  18955. for ( var i = 0; i < flen; i ++ ) {
  18956. var face = faces[ i ];
  18957. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18958. }
  18959. layer = steps + bevelSegments * 2;
  18960. offset = vlen * layer;
  18961. // Top faces
  18962. for ( var i$1 = 0; i$1 < flen; i$1 ++ ) {
  18963. var face$1 = faces[ i$1 ];
  18964. f3( face$1[ 0 ] + offset, face$1[ 1 ] + offset, face$1[ 2 ] + offset );
  18965. }
  18966. } else {
  18967. // Bottom faces
  18968. for ( var i$2 = 0; i$2 < flen; i$2 ++ ) {
  18969. var face$2 = faces[ i$2 ];
  18970. f3( face$2[ 2 ], face$2[ 1 ], face$2[ 0 ] );
  18971. }
  18972. // Top faces
  18973. for ( var i$3 = 0; i$3 < flen; i$3 ++ ) {
  18974. var face$3 = faces[ i$3 ];
  18975. f3( face$3[ 0 ] + vlen * steps, face$3[ 1 ] + vlen * steps, face$3[ 2 ] + vlen * steps );
  18976. }
  18977. }
  18978. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18979. }
  18980. // Create faces for the z-sides of the shape
  18981. function buildSideFaces() {
  18982. var start = verticesArray.length / 3;
  18983. var layeroffset = 0;
  18984. sidewalls( contour, layeroffset );
  18985. layeroffset += contour.length;
  18986. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18987. var ahole = holes[ h ];
  18988. sidewalls( ahole, layeroffset );
  18989. //, true
  18990. layeroffset += ahole.length;
  18991. }
  18992. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18993. }
  18994. function sidewalls( contour, layeroffset ) {
  18995. var i = contour.length;
  18996. while ( -- i >= 0 ) {
  18997. var j = i;
  18998. var k = i - 1;
  18999. if ( k < 0 ) { k = contour.length - 1; }
  19000. //console.log('b', i,j, i-1, k,vertices.length);
  19001. for ( var s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  19002. var slen1 = vlen * s;
  19003. var slen2 = vlen * ( s + 1 );
  19004. var a = layeroffset + j + slen1,
  19005. b = layeroffset + k + slen1,
  19006. c = layeroffset + k + slen2,
  19007. d = layeroffset + j + slen2;
  19008. f4( a, b, c, d );
  19009. }
  19010. }
  19011. }
  19012. function v( x, y, z ) {
  19013. placeholder.push( x );
  19014. placeholder.push( y );
  19015. placeholder.push( z );
  19016. }
  19017. function f3( a, b, c ) {
  19018. addVertex( a );
  19019. addVertex( b );
  19020. addVertex( c );
  19021. var nextIndex = verticesArray.length / 3;
  19022. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  19023. addUV( uvs[ 0 ] );
  19024. addUV( uvs[ 1 ] );
  19025. addUV( uvs[ 2 ] );
  19026. }
  19027. function f4( a, b, c, d ) {
  19028. addVertex( a );
  19029. addVertex( b );
  19030. addVertex( d );
  19031. addVertex( b );
  19032. addVertex( c );
  19033. addVertex( d );
  19034. var nextIndex = verticesArray.length / 3;
  19035. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  19036. addUV( uvs[ 0 ] );
  19037. addUV( uvs[ 1 ] );
  19038. addUV( uvs[ 3 ] );
  19039. addUV( uvs[ 1 ] );
  19040. addUV( uvs[ 2 ] );
  19041. addUV( uvs[ 3 ] );
  19042. }
  19043. function addVertex( index ) {
  19044. verticesArray.push( placeholder[ index * 3 + 0 ] );
  19045. verticesArray.push( placeholder[ index * 3 + 1 ] );
  19046. verticesArray.push( placeholder[ index * 3 + 2 ] );
  19047. }
  19048. function addUV( vector2 ) {
  19049. uvArray.push( vector2.x );
  19050. uvArray.push( vector2.y );
  19051. }
  19052. }
  19053. }
  19054. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19055. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  19056. ExtrudeBufferGeometry.prototype.toJSON = function () {
  19057. var data = BufferGeometry.prototype.toJSON.call( this );
  19058. var shapes = this.parameters.shapes;
  19059. var options = this.parameters.options;
  19060. return toJSON( shapes, options, data );
  19061. };
  19062. //
  19063. var WorldUVGenerator = {
  19064. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  19065. var a_x = vertices[ indexA * 3 ];
  19066. var a_y = vertices[ indexA * 3 + 1 ];
  19067. var b_x = vertices[ indexB * 3 ];
  19068. var b_y = vertices[ indexB * 3 + 1 ];
  19069. var c_x = vertices[ indexC * 3 ];
  19070. var c_y = vertices[ indexC * 3 + 1 ];
  19071. return [
  19072. new Vector2( a_x, a_y ),
  19073. new Vector2( b_x, b_y ),
  19074. new Vector2( c_x, c_y )
  19075. ];
  19076. },
  19077. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  19078. var a_x = vertices[ indexA * 3 ];
  19079. var a_y = vertices[ indexA * 3 + 1 ];
  19080. var a_z = vertices[ indexA * 3 + 2 ];
  19081. var b_x = vertices[ indexB * 3 ];
  19082. var b_y = vertices[ indexB * 3 + 1 ];
  19083. var b_z = vertices[ indexB * 3 + 2 ];
  19084. var c_x = vertices[ indexC * 3 ];
  19085. var c_y = vertices[ indexC * 3 + 1 ];
  19086. var c_z = vertices[ indexC * 3 + 2 ];
  19087. var d_x = vertices[ indexD * 3 ];
  19088. var d_y = vertices[ indexD * 3 + 1 ];
  19089. var d_z = vertices[ indexD * 3 + 2 ];
  19090. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  19091. return [
  19092. new Vector2( a_x, 1 - a_z ),
  19093. new Vector2( b_x, 1 - b_z ),
  19094. new Vector2( c_x, 1 - c_z ),
  19095. new Vector2( d_x, 1 - d_z )
  19096. ];
  19097. } else {
  19098. return [
  19099. new Vector2( a_y, 1 - a_z ),
  19100. new Vector2( b_y, 1 - b_z ),
  19101. new Vector2( c_y, 1 - c_z ),
  19102. new Vector2( d_y, 1 - d_z )
  19103. ];
  19104. }
  19105. }
  19106. };
  19107. function toJSON( shapes, options, data ) {
  19108. //
  19109. data.shapes = [];
  19110. if ( Array.isArray( shapes ) ) {
  19111. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19112. var shape = shapes[ i ];
  19113. data.shapes.push( shape.uuid );
  19114. }
  19115. } else {
  19116. data.shapes.push( shapes.uuid );
  19117. }
  19118. //
  19119. if ( options.extrudePath !== undefined ) { data.options.extrudePath = options.extrudePath.toJSON(); }
  19120. return data;
  19121. }
  19122. /**
  19123. * @author zz85 / http://www.lab4games.net/zz85/blog
  19124. * @author alteredq / http://alteredqualia.com/
  19125. *
  19126. * Text = 3D Text
  19127. *
  19128. * parameters = {
  19129. * font: <THREE.Font>, // font
  19130. *
  19131. * size: <float>, // size of the text
  19132. * height: <float>, // thickness to extrude text
  19133. * curveSegments: <int>, // number of points on the curves
  19134. *
  19135. * bevelEnabled: <bool>, // turn on bevel
  19136. * bevelThickness: <float>, // how deep into text bevel goes
  19137. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  19138. * bevelOffset: <float> // how far from text outline does bevel start
  19139. * }
  19140. */
  19141. // TextGeometry
  19142. function TextGeometry( text, parameters ) {
  19143. Geometry.call( this );
  19144. this.type = 'TextGeometry';
  19145. this.parameters = {
  19146. text: text,
  19147. parameters: parameters
  19148. };
  19149. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  19150. this.mergeVertices();
  19151. }
  19152. TextGeometry.prototype = Object.create( Geometry.prototype );
  19153. TextGeometry.prototype.constructor = TextGeometry;
  19154. // TextBufferGeometry
  19155. function TextBufferGeometry( text, parameters ) {
  19156. parameters = parameters || {};
  19157. var font = parameters.font;
  19158. if ( ! ( font && font.isFont ) ) {
  19159. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  19160. return new Geometry();
  19161. }
  19162. var shapes = font.generateShapes( text, parameters.size );
  19163. // translate parameters to ExtrudeGeometry API
  19164. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  19165. // defaults
  19166. if ( parameters.bevelThickness === undefined ) { parameters.bevelThickness = 10; }
  19167. if ( parameters.bevelSize === undefined ) { parameters.bevelSize = 8; }
  19168. if ( parameters.bevelEnabled === undefined ) { parameters.bevelEnabled = false; }
  19169. ExtrudeBufferGeometry.call( this, shapes, parameters );
  19170. this.type = 'TextBufferGeometry';
  19171. }
  19172. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  19173. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  19174. /**
  19175. * @author mrdoob / http://mrdoob.com/
  19176. * @author benaadams / https://twitter.com/ben_a_adams
  19177. * @author Mugen87 / https://github.com/Mugen87
  19178. */
  19179. // SphereGeometry
  19180. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19181. Geometry.call( this );
  19182. this.type = 'SphereGeometry';
  19183. this.parameters = {
  19184. radius: radius,
  19185. widthSegments: widthSegments,
  19186. heightSegments: heightSegments,
  19187. phiStart: phiStart,
  19188. phiLength: phiLength,
  19189. thetaStart: thetaStart,
  19190. thetaLength: thetaLength
  19191. };
  19192. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  19193. this.mergeVertices();
  19194. }
  19195. SphereGeometry.prototype = Object.create( Geometry.prototype );
  19196. SphereGeometry.prototype.constructor = SphereGeometry;
  19197. // SphereBufferGeometry
  19198. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19199. BufferGeometry.call( this );
  19200. this.type = 'SphereBufferGeometry';
  19201. this.parameters = {
  19202. radius: radius,
  19203. widthSegments: widthSegments,
  19204. heightSegments: heightSegments,
  19205. phiStart: phiStart,
  19206. phiLength: phiLength,
  19207. thetaStart: thetaStart,
  19208. thetaLength: thetaLength
  19209. };
  19210. radius = radius || 1;
  19211. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19212. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19213. phiStart = phiStart !== undefined ? phiStart : 0;
  19214. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19215. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19216. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19217. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  19218. var index = 0;
  19219. var grid = [];
  19220. var vertex = new Vector3();
  19221. var normal = new Vector3();
  19222. // buffers
  19223. var indices = [];
  19224. var vertices = [];
  19225. var normals = [];
  19226. var uvs = [];
  19227. // generate vertices, normals and uvs
  19228. for ( var iy = 0; iy <= heightSegments; iy ++ ) {
  19229. var verticesRow = [];
  19230. var v = iy / heightSegments;
  19231. // special case for the poles
  19232. var uOffset = 0;
  19233. if ( iy == 0 && thetaStart == 0 ) {
  19234. uOffset = 0.5 / widthSegments;
  19235. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  19236. uOffset = - 0.5 / widthSegments;
  19237. }
  19238. for ( var ix = 0; ix <= widthSegments; ix ++ ) {
  19239. var u = ix / widthSegments;
  19240. // vertex
  19241. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19242. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19243. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19244. vertices.push( vertex.x, vertex.y, vertex.z );
  19245. // normal
  19246. normal.copy( vertex ).normalize();
  19247. normals.push( normal.x, normal.y, normal.z );
  19248. // uv
  19249. uvs.push( u + uOffset, 1 - v );
  19250. verticesRow.push( index ++ );
  19251. }
  19252. grid.push( verticesRow );
  19253. }
  19254. // indices
  19255. for ( var iy$1 = 0; iy$1 < heightSegments; iy$1 ++ ) {
  19256. for ( var ix$1 = 0; ix$1 < widthSegments; ix$1 ++ ) {
  19257. var a = grid[ iy$1 ][ ix$1 + 1 ];
  19258. var b = grid[ iy$1 ][ ix$1 ];
  19259. var c = grid[ iy$1 + 1 ][ ix$1 ];
  19260. var d = grid[ iy$1 + 1 ][ ix$1 + 1 ];
  19261. if ( iy$1 !== 0 || thetaStart > 0 ) { indices.push( a, b, d ); }
  19262. if ( iy$1 !== heightSegments - 1 || thetaEnd < Math.PI ) { indices.push( b, c, d ); }
  19263. }
  19264. }
  19265. // build geometry
  19266. this.setIndex( indices );
  19267. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19268. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19269. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19270. }
  19271. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19272. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  19273. /**
  19274. * @author Kaleb Murphy
  19275. * @author Mugen87 / https://github.com/Mugen87
  19276. */
  19277. // RingGeometry
  19278. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19279. Geometry.call( this );
  19280. this.type = 'RingGeometry';
  19281. this.parameters = {
  19282. innerRadius: innerRadius,
  19283. outerRadius: outerRadius,
  19284. thetaSegments: thetaSegments,
  19285. phiSegments: phiSegments,
  19286. thetaStart: thetaStart,
  19287. thetaLength: thetaLength
  19288. };
  19289. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  19290. this.mergeVertices();
  19291. }
  19292. RingGeometry.prototype = Object.create( Geometry.prototype );
  19293. RingGeometry.prototype.constructor = RingGeometry;
  19294. // RingBufferGeometry
  19295. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19296. BufferGeometry.call( this );
  19297. this.type = 'RingBufferGeometry';
  19298. this.parameters = {
  19299. innerRadius: innerRadius,
  19300. outerRadius: outerRadius,
  19301. thetaSegments: thetaSegments,
  19302. phiSegments: phiSegments,
  19303. thetaStart: thetaStart,
  19304. thetaLength: thetaLength
  19305. };
  19306. innerRadius = innerRadius || 0.5;
  19307. outerRadius = outerRadius || 1;
  19308. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19309. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19310. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19311. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  19312. // buffers
  19313. var indices = [];
  19314. var vertices = [];
  19315. var normals = [];
  19316. var uvs = [];
  19317. // some helper variables
  19318. var radius = innerRadius;
  19319. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19320. var vertex = new Vector3();
  19321. var uv = new Vector2();
  19322. // generate vertices, normals and uvs
  19323. for ( var j = 0; j <= phiSegments; j ++ ) {
  19324. for ( var i = 0; i <= thetaSegments; i ++ ) {
  19325. // values are generate from the inside of the ring to the outside
  19326. var segment = thetaStart + i / thetaSegments * thetaLength;
  19327. // vertex
  19328. vertex.x = radius * Math.cos( segment );
  19329. vertex.y = radius * Math.sin( segment );
  19330. vertices.push( vertex.x, vertex.y, vertex.z );
  19331. // normal
  19332. normals.push( 0, 0, 1 );
  19333. // uv
  19334. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  19335. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  19336. uvs.push( uv.x, uv.y );
  19337. }
  19338. // increase the radius for next row of vertices
  19339. radius += radiusStep;
  19340. }
  19341. // indices
  19342. for ( var j$1 = 0; j$1 < phiSegments; j$1 ++ ) {
  19343. var thetaSegmentLevel = j$1 * ( thetaSegments + 1 );
  19344. for ( var i$1 = 0; i$1 < thetaSegments; i$1 ++ ) {
  19345. var segment$1 = i$1 + thetaSegmentLevel;
  19346. var a = segment$1;
  19347. var b = segment$1 + thetaSegments + 1;
  19348. var c = segment$1 + thetaSegments + 2;
  19349. var d = segment$1 + 1;
  19350. // faces
  19351. indices.push( a, b, d );
  19352. indices.push( b, c, d );
  19353. }
  19354. }
  19355. // build geometry
  19356. this.setIndex( indices );
  19357. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19358. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19359. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19360. }
  19361. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19362. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  19363. /**
  19364. * @author zz85 / https://github.com/zz85
  19365. * @author bhouston / http://clara.io
  19366. * @author Mugen87 / https://github.com/Mugen87
  19367. */
  19368. // LatheGeometry
  19369. function LatheGeometry( points, segments, phiStart, phiLength ) {
  19370. Geometry.call( this );
  19371. this.type = 'LatheGeometry';
  19372. this.parameters = {
  19373. points: points,
  19374. segments: segments,
  19375. phiStart: phiStart,
  19376. phiLength: phiLength
  19377. };
  19378. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  19379. this.mergeVertices();
  19380. }
  19381. LatheGeometry.prototype = Object.create( Geometry.prototype );
  19382. LatheGeometry.prototype.constructor = LatheGeometry;
  19383. // LatheBufferGeometry
  19384. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  19385. BufferGeometry.call( this );
  19386. this.type = 'LatheBufferGeometry';
  19387. this.parameters = {
  19388. points: points,
  19389. segments: segments,
  19390. phiStart: phiStart,
  19391. phiLength: phiLength
  19392. };
  19393. segments = Math.floor( segments ) || 12;
  19394. phiStart = phiStart || 0;
  19395. phiLength = phiLength || Math.PI * 2;
  19396. // clamp phiLength so it's in range of [ 0, 2PI ]
  19397. phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
  19398. // buffers
  19399. var indices = [];
  19400. var vertices = [];
  19401. var uvs = [];
  19402. // helper variables
  19403. var inverseSegments = 1.0 / segments;
  19404. var vertex = new Vector3();
  19405. var uv = new Vector2();
  19406. // generate vertices and uvs
  19407. for ( var i = 0; i <= segments; i ++ ) {
  19408. var phi = phiStart + i * inverseSegments * phiLength;
  19409. var sin = Math.sin( phi );
  19410. var cos = Math.cos( phi );
  19411. for ( var j = 0; j <= ( points.length - 1 ); j ++ ) {
  19412. // vertex
  19413. vertex.x = points[ j ].x * sin;
  19414. vertex.y = points[ j ].y;
  19415. vertex.z = points[ j ].x * cos;
  19416. vertices.push( vertex.x, vertex.y, vertex.z );
  19417. // uv
  19418. uv.x = i / segments;
  19419. uv.y = j / ( points.length - 1 );
  19420. uvs.push( uv.x, uv.y );
  19421. }
  19422. }
  19423. // indices
  19424. for ( var i$1 = 0; i$1 < segments; i$1 ++ ) {
  19425. for ( var j$1 = 0; j$1 < ( points.length - 1 ); j$1 ++ ) {
  19426. var base = j$1 + i$1 * points.length;
  19427. var a = base;
  19428. var b = base + points.length;
  19429. var c = base + points.length + 1;
  19430. var d = base + 1;
  19431. // faces
  19432. indices.push( a, b, d );
  19433. indices.push( b, c, d );
  19434. }
  19435. }
  19436. // build geometry
  19437. this.setIndex( indices );
  19438. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19439. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19440. // generate normals
  19441. this.computeVertexNormals();
  19442. // if the geometry is closed, we need to average the normals along the seam.
  19443. // because the corresponding vertices are identical (but still have different UVs).
  19444. if ( phiLength === Math.PI * 2 ) {
  19445. var normals = this.attributes.normal.array;
  19446. var n1 = new Vector3();
  19447. var n2 = new Vector3();
  19448. var n = new Vector3();
  19449. // this is the buffer offset for the last line of vertices
  19450. var base$1 = segments * points.length * 3;
  19451. for ( var i$2 = 0, j$2 = 0; i$2 < points.length; i$2 ++, j$2 += 3 ) {
  19452. // select the normal of the vertex in the first line
  19453. n1.x = normals[ j$2 + 0 ];
  19454. n1.y = normals[ j$2 + 1 ];
  19455. n1.z = normals[ j$2 + 2 ];
  19456. // select the normal of the vertex in the last line
  19457. n2.x = normals[ base$1 + j$2 + 0 ];
  19458. n2.y = normals[ base$1 + j$2 + 1 ];
  19459. n2.z = normals[ base$1 + j$2 + 2 ];
  19460. // average normals
  19461. n.addVectors( n1, n2 ).normalize();
  19462. // assign the new values to both normals
  19463. normals[ j$2 + 0 ] = normals[ base$1 + j$2 + 0 ] = n.x;
  19464. normals[ j$2 + 1 ] = normals[ base$1 + j$2 + 1 ] = n.y;
  19465. normals[ j$2 + 2 ] = normals[ base$1 + j$2 + 2 ] = n.z;
  19466. }
  19467. }
  19468. }
  19469. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19470. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  19471. /**
  19472. * @author jonobr1 / http://jonobr1.com
  19473. * @author Mugen87 / https://github.com/Mugen87
  19474. */
  19475. // ShapeGeometry
  19476. function ShapeGeometry( shapes, curveSegments ) {
  19477. Geometry.call( this );
  19478. this.type = 'ShapeGeometry';
  19479. if ( typeof curveSegments === 'object' ) {
  19480. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  19481. curveSegments = curveSegments.curveSegments;
  19482. }
  19483. this.parameters = {
  19484. shapes: shapes,
  19485. curveSegments: curveSegments
  19486. };
  19487. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  19488. this.mergeVertices();
  19489. }
  19490. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  19491. ShapeGeometry.prototype.constructor = ShapeGeometry;
  19492. ShapeGeometry.prototype.toJSON = function () {
  19493. var data = Geometry.prototype.toJSON.call( this );
  19494. var shapes = this.parameters.shapes;
  19495. return toJSON$1( shapes, data );
  19496. };
  19497. // ShapeBufferGeometry
  19498. function ShapeBufferGeometry( shapes, curveSegments ) {
  19499. BufferGeometry.call( this );
  19500. this.type = 'ShapeBufferGeometry';
  19501. this.parameters = {
  19502. shapes: shapes,
  19503. curveSegments: curveSegments
  19504. };
  19505. curveSegments = curveSegments || 12;
  19506. // buffers
  19507. var indices = [];
  19508. var vertices = [];
  19509. var normals = [];
  19510. var uvs = [];
  19511. // helper variables
  19512. var groupStart = 0;
  19513. var groupCount = 0;
  19514. // allow single and array values for "shapes" parameter
  19515. if ( Array.isArray( shapes ) === false ) {
  19516. addShape( shapes );
  19517. } else {
  19518. for ( var i = 0; i < shapes.length; i ++ ) {
  19519. addShape( shapes[ i ] );
  19520. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  19521. groupStart += groupCount;
  19522. groupCount = 0;
  19523. }
  19524. }
  19525. // build geometry
  19526. this.setIndex( indices );
  19527. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19528. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19529. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19530. // helper functions
  19531. function addShape( shape ) {
  19532. var indexOffset = vertices.length / 3;
  19533. var points = shape.extractPoints( curveSegments );
  19534. var shapeVertices = points.shape;
  19535. var shapeHoles = points.holes;
  19536. // check direction of vertices
  19537. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  19538. shapeVertices = shapeVertices.reverse();
  19539. }
  19540. for ( var i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19541. var shapeHole = shapeHoles[ i ];
  19542. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  19543. shapeHoles[ i ] = shapeHole.reverse();
  19544. }
  19545. }
  19546. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  19547. // join vertices of inner and outer paths to a single array
  19548. for ( var i$1 = 0, l$1 = shapeHoles.length; i$1 < l$1; i$1 ++ ) {
  19549. var shapeHole$1 = shapeHoles[ i$1 ];
  19550. shapeVertices = shapeVertices.concat( shapeHole$1 );
  19551. }
  19552. // vertices, normals, uvs
  19553. for ( var i$2 = 0, l$2 = shapeVertices.length; i$2 < l$2; i$2 ++ ) {
  19554. var vertex = shapeVertices[ i$2 ];
  19555. vertices.push( vertex.x, vertex.y, 0 );
  19556. normals.push( 0, 0, 1 );
  19557. uvs.push( vertex.x, vertex.y ); // world uvs
  19558. }
  19559. // incides
  19560. for ( var i$3 = 0, l$3 = faces.length; i$3 < l$3; i$3 ++ ) {
  19561. var face = faces[ i$3 ];
  19562. var a = face[ 0 ] + indexOffset;
  19563. var b = face[ 1 ] + indexOffset;
  19564. var c = face[ 2 ] + indexOffset;
  19565. indices.push( a, b, c );
  19566. groupCount += 3;
  19567. }
  19568. }
  19569. }
  19570. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19571. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  19572. ShapeBufferGeometry.prototype.toJSON = function () {
  19573. var data = BufferGeometry.prototype.toJSON.call( this );
  19574. var shapes = this.parameters.shapes;
  19575. return toJSON$1( shapes, data );
  19576. };
  19577. //
  19578. function toJSON$1( shapes, data ) {
  19579. data.shapes = [];
  19580. if ( Array.isArray( shapes ) ) {
  19581. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19582. var shape = shapes[ i ];
  19583. data.shapes.push( shape.uuid );
  19584. }
  19585. } else {
  19586. data.shapes.push( shapes.uuid );
  19587. }
  19588. return data;
  19589. }
  19590. /**
  19591. * @author WestLangley / http://github.com/WestLangley
  19592. * @author Mugen87 / https://github.com/Mugen87
  19593. */
  19594. function EdgesGeometry( geometry, thresholdAngle ) {
  19595. BufferGeometry.call( this );
  19596. this.type = 'EdgesGeometry';
  19597. this.parameters = {
  19598. thresholdAngle: thresholdAngle
  19599. };
  19600. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19601. // buffer
  19602. var vertices = [];
  19603. // helper variables
  19604. var thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
  19605. var edge = [ 0, 0 ], edges = {};
  19606. var edge1, edge2, key;
  19607. var keys = [ 'a', 'b', 'c' ];
  19608. // prepare source geometry
  19609. var geometry2;
  19610. if ( geometry.isBufferGeometry ) {
  19611. geometry2 = new Geometry();
  19612. geometry2.fromBufferGeometry( geometry );
  19613. } else {
  19614. geometry2 = geometry.clone();
  19615. }
  19616. geometry2.mergeVertices();
  19617. geometry2.computeFaceNormals();
  19618. var sourceVertices = geometry2.vertices;
  19619. var faces = geometry2.faces;
  19620. // now create a data structure where each entry represents an edge with its adjoining faces
  19621. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19622. var face = faces[ i ];
  19623. for ( var j = 0; j < 3; j ++ ) {
  19624. edge1 = face[ keys[ j ] ];
  19625. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  19626. edge[ 0 ] = Math.min( edge1, edge2 );
  19627. edge[ 1 ] = Math.max( edge1, edge2 );
  19628. key = edge[ 0 ] + ',' + edge[ 1 ];
  19629. if ( edges[ key ] === undefined ) {
  19630. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  19631. } else {
  19632. edges[ key ].face2 = i;
  19633. }
  19634. }
  19635. }
  19636. // generate vertices
  19637. for ( key in edges ) {
  19638. var e = edges[ key ];
  19639. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  19640. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  19641. var vertex = sourceVertices[ e.index1 ];
  19642. vertices.push( vertex.x, vertex.y, vertex.z );
  19643. vertex = sourceVertices[ e.index2 ];
  19644. vertices.push( vertex.x, vertex.y, vertex.z );
  19645. }
  19646. }
  19647. // build geometry
  19648. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19649. }
  19650. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  19651. EdgesGeometry.prototype.constructor = EdgesGeometry;
  19652. /**
  19653. * @author mrdoob / http://mrdoob.com/
  19654. * @author Mugen87 / https://github.com/Mugen87
  19655. */
  19656. // CylinderGeometry
  19657. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19658. Geometry.call( this );
  19659. this.type = 'CylinderGeometry';
  19660. this.parameters = {
  19661. radiusTop: radiusTop,
  19662. radiusBottom: radiusBottom,
  19663. height: height,
  19664. radialSegments: radialSegments,
  19665. heightSegments: heightSegments,
  19666. openEnded: openEnded,
  19667. thetaStart: thetaStart,
  19668. thetaLength: thetaLength
  19669. };
  19670. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  19671. this.mergeVertices();
  19672. }
  19673. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  19674. CylinderGeometry.prototype.constructor = CylinderGeometry;
  19675. // CylinderBufferGeometry
  19676. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19677. BufferGeometry.call( this );
  19678. this.type = 'CylinderBufferGeometry';
  19679. this.parameters = {
  19680. radiusTop: radiusTop,
  19681. radiusBottom: radiusBottom,
  19682. height: height,
  19683. radialSegments: radialSegments,
  19684. heightSegments: heightSegments,
  19685. openEnded: openEnded,
  19686. thetaStart: thetaStart,
  19687. thetaLength: thetaLength
  19688. };
  19689. var scope = this;
  19690. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  19691. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  19692. height = height || 1;
  19693. radialSegments = Math.floor( radialSegments ) || 8;
  19694. heightSegments = Math.floor( heightSegments ) || 1;
  19695. openEnded = openEnded !== undefined ? openEnded : false;
  19696. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  19697. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19698. // buffers
  19699. var indices = [];
  19700. var vertices = [];
  19701. var normals = [];
  19702. var uvs = [];
  19703. // helper variables
  19704. var index = 0;
  19705. var indexArray = [];
  19706. var halfHeight = height / 2;
  19707. var groupStart = 0;
  19708. // generate geometry
  19709. generateTorso();
  19710. if ( openEnded === false ) {
  19711. if ( radiusTop > 0 ) { generateCap( true ); }
  19712. if ( radiusBottom > 0 ) { generateCap( false ); }
  19713. }
  19714. // build geometry
  19715. this.setIndex( indices );
  19716. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19717. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19718. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19719. function generateTorso() {
  19720. var normal = new Vector3();
  19721. var vertex = new Vector3();
  19722. var groupCount = 0;
  19723. // this will be used to calculate the normal
  19724. var slope = ( radiusBottom - radiusTop ) / height;
  19725. // generate vertices, normals and uvs
  19726. for ( var y = 0; y <= heightSegments; y ++ ) {
  19727. var indexRow = [];
  19728. var v = y / heightSegments;
  19729. // calculate the radius of the current row
  19730. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19731. for ( var x = 0; x <= radialSegments; x ++ ) {
  19732. var u = x / radialSegments;
  19733. var theta = u * thetaLength + thetaStart;
  19734. var sinTheta = Math.sin( theta );
  19735. var cosTheta = Math.cos( theta );
  19736. // vertex
  19737. vertex.x = radius * sinTheta;
  19738. vertex.y = - v * height + halfHeight;
  19739. vertex.z = radius * cosTheta;
  19740. vertices.push( vertex.x, vertex.y, vertex.z );
  19741. // normal
  19742. normal.set( sinTheta, slope, cosTheta ).normalize();
  19743. normals.push( normal.x, normal.y, normal.z );
  19744. // uv
  19745. uvs.push( u, 1 - v );
  19746. // save index of vertex in respective row
  19747. indexRow.push( index ++ );
  19748. }
  19749. // now save vertices of the row in our index array
  19750. indexArray.push( indexRow );
  19751. }
  19752. // generate indices
  19753. for ( var x$1 = 0; x$1 < radialSegments; x$1 ++ ) {
  19754. for ( var y$1 = 0; y$1 < heightSegments; y$1 ++ ) {
  19755. // we use the index array to access the correct indices
  19756. var a = indexArray[ y$1 ][ x$1 ];
  19757. var b = indexArray[ y$1 + 1 ][ x$1 ];
  19758. var c = indexArray[ y$1 + 1 ][ x$1 + 1 ];
  19759. var d = indexArray[ y$1 ][ x$1 + 1 ];
  19760. // faces
  19761. indices.push( a, b, d );
  19762. indices.push( b, c, d );
  19763. // update group counter
  19764. groupCount += 6;
  19765. }
  19766. }
  19767. // add a group to the geometry. this will ensure multi material support
  19768. scope.addGroup( groupStart, groupCount, 0 );
  19769. // calculate new start value for groups
  19770. groupStart += groupCount;
  19771. }
  19772. function generateCap( top ) {
  19773. var centerIndexStart, centerIndexEnd;
  19774. var uv = new Vector2();
  19775. var vertex = new Vector3();
  19776. var groupCount = 0;
  19777. var radius = ( top === true ) ? radiusTop : radiusBottom;
  19778. var sign = ( top === true ) ? 1 : - 1;
  19779. // save the index of the first center vertex
  19780. centerIndexStart = index;
  19781. // first we generate the center vertex data of the cap.
  19782. // because the geometry needs one set of uvs per face,
  19783. // we must generate a center vertex per face/segment
  19784. for ( var x = 1; x <= radialSegments; x ++ ) {
  19785. // vertex
  19786. vertices.push( 0, halfHeight * sign, 0 );
  19787. // normal
  19788. normals.push( 0, sign, 0 );
  19789. // uv
  19790. uvs.push( 0.5, 0.5 );
  19791. // increase index
  19792. index ++;
  19793. }
  19794. // save the index of the last center vertex
  19795. centerIndexEnd = index;
  19796. // now we generate the surrounding vertices, normals and uvs
  19797. for ( var x$1 = 0; x$1 <= radialSegments; x$1 ++ ) {
  19798. var u = x$1 / radialSegments;
  19799. var theta = u * thetaLength + thetaStart;
  19800. var cosTheta = Math.cos( theta );
  19801. var sinTheta = Math.sin( theta );
  19802. // vertex
  19803. vertex.x = radius * sinTheta;
  19804. vertex.y = halfHeight * sign;
  19805. vertex.z = radius * cosTheta;
  19806. vertices.push( vertex.x, vertex.y, vertex.z );
  19807. // normal
  19808. normals.push( 0, sign, 0 );
  19809. // uv
  19810. uv.x = ( cosTheta * 0.5 ) + 0.5;
  19811. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  19812. uvs.push( uv.x, uv.y );
  19813. // increase index
  19814. index ++;
  19815. }
  19816. // generate indices
  19817. for ( var x$2 = 0; x$2 < radialSegments; x$2 ++ ) {
  19818. var c = centerIndexStart + x$2;
  19819. var i = centerIndexEnd + x$2;
  19820. if ( top === true ) {
  19821. // face top
  19822. indices.push( i, i + 1, c );
  19823. } else {
  19824. // face bottom
  19825. indices.push( i + 1, i, c );
  19826. }
  19827. groupCount += 3;
  19828. }
  19829. // add a group to the geometry. this will ensure multi material support
  19830. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  19831. // calculate new start value for groups
  19832. groupStart += groupCount;
  19833. }
  19834. }
  19835. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19836. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  19837. /**
  19838. * @author abelnation / http://github.com/abelnation
  19839. */
  19840. // ConeGeometry
  19841. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19842. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19843. this.type = 'ConeGeometry';
  19844. this.parameters = {
  19845. radius: radius,
  19846. height: height,
  19847. radialSegments: radialSegments,
  19848. heightSegments: heightSegments,
  19849. openEnded: openEnded,
  19850. thetaStart: thetaStart,
  19851. thetaLength: thetaLength
  19852. };
  19853. }
  19854. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  19855. ConeGeometry.prototype.constructor = ConeGeometry;
  19856. // ConeBufferGeometry
  19857. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19858. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19859. this.type = 'ConeBufferGeometry';
  19860. this.parameters = {
  19861. radius: radius,
  19862. height: height,
  19863. radialSegments: radialSegments,
  19864. heightSegments: heightSegments,
  19865. openEnded: openEnded,
  19866. thetaStart: thetaStart,
  19867. thetaLength: thetaLength
  19868. };
  19869. }
  19870. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  19871. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  19872. /**
  19873. * @author benaadams / https://twitter.com/ben_a_adams
  19874. * @author Mugen87 / https://github.com/Mugen87
  19875. * @author hughes
  19876. */
  19877. // CircleGeometry
  19878. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  19879. Geometry.call( this );
  19880. this.type = 'CircleGeometry';
  19881. this.parameters = {
  19882. radius: radius,
  19883. segments: segments,
  19884. thetaStart: thetaStart,
  19885. thetaLength: thetaLength
  19886. };
  19887. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  19888. this.mergeVertices();
  19889. }
  19890. CircleGeometry.prototype = Object.create( Geometry.prototype );
  19891. CircleGeometry.prototype.constructor = CircleGeometry;
  19892. // CircleBufferGeometry
  19893. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  19894. BufferGeometry.call( this );
  19895. this.type = 'CircleBufferGeometry';
  19896. this.parameters = {
  19897. radius: radius,
  19898. segments: segments,
  19899. thetaStart: thetaStart,
  19900. thetaLength: thetaLength
  19901. };
  19902. radius = radius || 1;
  19903. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19904. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19905. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19906. // buffers
  19907. var indices = [];
  19908. var vertices = [];
  19909. var normals = [];
  19910. var uvs = [];
  19911. // helper variables
  19912. var vertex = new Vector3();
  19913. var uv = new Vector2();
  19914. // center point
  19915. vertices.push( 0, 0, 0 );
  19916. normals.push( 0, 0, 1 );
  19917. uvs.push( 0.5, 0.5 );
  19918. for ( var s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  19919. var segment = thetaStart + s / segments * thetaLength;
  19920. // vertex
  19921. vertex.x = radius * Math.cos( segment );
  19922. vertex.y = radius * Math.sin( segment );
  19923. vertices.push( vertex.x, vertex.y, vertex.z );
  19924. // normal
  19925. normals.push( 0, 0, 1 );
  19926. // uvs
  19927. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19928. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19929. uvs.push( uv.x, uv.y );
  19930. }
  19931. // indices
  19932. for ( var i$1 = 1; i$1 <= segments; i$1 ++ ) {
  19933. indices.push( i$1, i$1 + 1, 0 );
  19934. }
  19935. // build geometry
  19936. this.setIndex( indices );
  19937. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19938. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19939. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19940. }
  19941. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19942. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19943. var Geometries = /*#__PURE__*/Object.freeze({
  19944. __proto__: null,
  19945. WireframeGeometry: WireframeGeometry,
  19946. ParametricGeometry: ParametricGeometry,
  19947. ParametricBufferGeometry: ParametricBufferGeometry,
  19948. TetrahedronGeometry: TetrahedronGeometry,
  19949. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19950. OctahedronGeometry: OctahedronGeometry,
  19951. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19952. IcosahedronGeometry: IcosahedronGeometry,
  19953. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19954. DodecahedronGeometry: DodecahedronGeometry,
  19955. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19956. PolyhedronGeometry: PolyhedronGeometry,
  19957. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19958. TubeGeometry: TubeGeometry,
  19959. TubeBufferGeometry: TubeBufferGeometry,
  19960. TorusKnotGeometry: TorusKnotGeometry,
  19961. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19962. TorusGeometry: TorusGeometry,
  19963. TorusBufferGeometry: TorusBufferGeometry,
  19964. TextGeometry: TextGeometry,
  19965. TextBufferGeometry: TextBufferGeometry,
  19966. SphereGeometry: SphereGeometry,
  19967. SphereBufferGeometry: SphereBufferGeometry,
  19968. RingGeometry: RingGeometry,
  19969. RingBufferGeometry: RingBufferGeometry,
  19970. PlaneGeometry: PlaneGeometry,
  19971. PlaneBufferGeometry: PlaneBufferGeometry,
  19972. LatheGeometry: LatheGeometry,
  19973. LatheBufferGeometry: LatheBufferGeometry,
  19974. ShapeGeometry: ShapeGeometry,
  19975. ShapeBufferGeometry: ShapeBufferGeometry,
  19976. ExtrudeGeometry: ExtrudeGeometry,
  19977. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19978. EdgesGeometry: EdgesGeometry,
  19979. ConeGeometry: ConeGeometry,
  19980. ConeBufferGeometry: ConeBufferGeometry,
  19981. CylinderGeometry: CylinderGeometry,
  19982. CylinderBufferGeometry: CylinderBufferGeometry,
  19983. CircleGeometry: CircleGeometry,
  19984. CircleBufferGeometry: CircleBufferGeometry,
  19985. BoxGeometry: BoxGeometry,
  19986. BoxBufferGeometry: BoxBufferGeometry
  19987. });
  19988. /**
  19989. * @author mrdoob / http://mrdoob.com/
  19990. *
  19991. * parameters = {
  19992. * color: <THREE.Color>
  19993. * }
  19994. */
  19995. function ShadowMaterial( parameters ) {
  19996. Material.call( this );
  19997. this.type = 'ShadowMaterial';
  19998. this.color = new Color( 0x000000 );
  19999. this.transparent = true;
  20000. this.setValues( parameters );
  20001. }
  20002. ShadowMaterial.prototype = Object.create( Material.prototype );
  20003. ShadowMaterial.prototype.constructor = ShadowMaterial;
  20004. ShadowMaterial.prototype.isShadowMaterial = true;
  20005. ShadowMaterial.prototype.copy = function ( source ) {
  20006. Material.prototype.copy.call( this, source );
  20007. this.color.copy( source.color );
  20008. return this;
  20009. };
  20010. /**
  20011. * @author mrdoob / http://mrdoob.com/
  20012. */
  20013. function RawShaderMaterial( parameters ) {
  20014. ShaderMaterial.call( this, parameters );
  20015. this.type = 'RawShaderMaterial';
  20016. }
  20017. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  20018. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  20019. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  20020. /**
  20021. * @author WestLangley / http://github.com/WestLangley
  20022. *
  20023. * parameters = {
  20024. * color: <hex>,
  20025. * roughness: <float>,
  20026. * metalness: <float>,
  20027. * opacity: <float>,
  20028. *
  20029. * map: new THREE.Texture( <Image> ),
  20030. *
  20031. * lightMap: new THREE.Texture( <Image> ),
  20032. * lightMapIntensity: <float>
  20033. *
  20034. * aoMap: new THREE.Texture( <Image> ),
  20035. * aoMapIntensity: <float>
  20036. *
  20037. * emissive: <hex>,
  20038. * emissiveIntensity: <float>
  20039. * emissiveMap: new THREE.Texture( <Image> ),
  20040. *
  20041. * bumpMap: new THREE.Texture( <Image> ),
  20042. * bumpScale: <float>,
  20043. *
  20044. * normalMap: new THREE.Texture( <Image> ),
  20045. * normalMapType: THREE.TangentSpaceNormalMap,
  20046. * normalScale: <Vector2>,
  20047. *
  20048. * displacementMap: new THREE.Texture( <Image> ),
  20049. * displacementScale: <float>,
  20050. * displacementBias: <float>,
  20051. *
  20052. * roughnessMap: new THREE.Texture( <Image> ),
  20053. *
  20054. * metalnessMap: new THREE.Texture( <Image> ),
  20055. *
  20056. * alphaMap: new THREE.Texture( <Image> ),
  20057. *
  20058. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20059. * envMapIntensity: <float>
  20060. *
  20061. * refractionRatio: <float>,
  20062. *
  20063. * wireframe: <boolean>,
  20064. * wireframeLinewidth: <float>,
  20065. *
  20066. * skinning: <bool>,
  20067. * morphTargets: <bool>,
  20068. * morphNormals: <bool>
  20069. * }
  20070. */
  20071. function MeshStandardMaterial( parameters ) {
  20072. Material.call( this );
  20073. this.defines = { 'STANDARD': '' };
  20074. this.type = 'MeshStandardMaterial';
  20075. this.color = new Color( 0xffffff ); // diffuse
  20076. this.roughness = 1.0;
  20077. this.metalness = 0.0;
  20078. this.map = null;
  20079. this.lightMap = null;
  20080. this.lightMapIntensity = 1.0;
  20081. this.aoMap = null;
  20082. this.aoMapIntensity = 1.0;
  20083. this.emissive = new Color( 0x000000 );
  20084. this.emissiveIntensity = 1.0;
  20085. this.emissiveMap = null;
  20086. this.bumpMap = null;
  20087. this.bumpScale = 1;
  20088. this.normalMap = null;
  20089. this.normalMapType = TangentSpaceNormalMap;
  20090. this.normalScale = new Vector2( 1, 1 );
  20091. this.displacementMap = null;
  20092. this.displacementScale = 1;
  20093. this.displacementBias = 0;
  20094. this.roughnessMap = null;
  20095. this.metalnessMap = null;
  20096. this.alphaMap = null;
  20097. this.envMap = null;
  20098. this.envMapIntensity = 1.0;
  20099. this.refractionRatio = 0.98;
  20100. this.wireframe = false;
  20101. this.wireframeLinewidth = 1;
  20102. this.wireframeLinecap = 'round';
  20103. this.wireframeLinejoin = 'round';
  20104. this.skinning = false;
  20105. this.morphTargets = false;
  20106. this.morphNormals = false;
  20107. this.vertexTangents = false;
  20108. this.setValues( parameters );
  20109. }
  20110. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  20111. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20112. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20113. MeshStandardMaterial.prototype.copy = function ( source ) {
  20114. Material.prototype.copy.call( this, source );
  20115. this.defines = { 'STANDARD': '' };
  20116. this.color.copy( source.color );
  20117. this.roughness = source.roughness;
  20118. this.metalness = source.metalness;
  20119. this.map = source.map;
  20120. this.lightMap = source.lightMap;
  20121. this.lightMapIntensity = source.lightMapIntensity;
  20122. this.aoMap = source.aoMap;
  20123. this.aoMapIntensity = source.aoMapIntensity;
  20124. this.emissive.copy( source.emissive );
  20125. this.emissiveMap = source.emissiveMap;
  20126. this.emissiveIntensity = source.emissiveIntensity;
  20127. this.bumpMap = source.bumpMap;
  20128. this.bumpScale = source.bumpScale;
  20129. this.normalMap = source.normalMap;
  20130. this.normalMapType = source.normalMapType;
  20131. this.normalScale.copy( source.normalScale );
  20132. this.displacementMap = source.displacementMap;
  20133. this.displacementScale = source.displacementScale;
  20134. this.displacementBias = source.displacementBias;
  20135. this.roughnessMap = source.roughnessMap;
  20136. this.metalnessMap = source.metalnessMap;
  20137. this.alphaMap = source.alphaMap;
  20138. this.envMap = source.envMap;
  20139. this.envMapIntensity = source.envMapIntensity;
  20140. this.refractionRatio = source.refractionRatio;
  20141. this.wireframe = source.wireframe;
  20142. this.wireframeLinewidth = source.wireframeLinewidth;
  20143. this.wireframeLinecap = source.wireframeLinecap;
  20144. this.wireframeLinejoin = source.wireframeLinejoin;
  20145. this.skinning = source.skinning;
  20146. this.morphTargets = source.morphTargets;
  20147. this.morphNormals = source.morphNormals;
  20148. this.vertexTangents = source.vertexTangents;
  20149. return this;
  20150. };
  20151. /**
  20152. * @author WestLangley / http://github.com/WestLangley
  20153. *
  20154. * parameters = {
  20155. * clearcoat: <float>,
  20156. * clearcoatMap: new THREE.Texture( <Image> ),
  20157. * clearcoatRoughness: <float>,
  20158. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20159. * clearcoatNormalScale: <Vector2>,
  20160. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20161. *
  20162. * reflectivity: <float>,
  20163. *
  20164. * sheen: <Color>,
  20165. *
  20166. * transparency: <float>
  20167. * }
  20168. */
  20169. function MeshPhysicalMaterial( parameters ) {
  20170. MeshStandardMaterial.call( this );
  20171. this.defines = {
  20172. 'STANDARD': '',
  20173. 'PHYSICAL': ''
  20174. };
  20175. this.type = 'MeshPhysicalMaterial';
  20176. this.clearcoat = 0.0;
  20177. this.clearcoatMap = null;
  20178. this.clearcoatRoughness = 0.0;
  20179. this.clearcoatRoughnessMap = null;
  20180. this.clearcoatNormalScale = new Vector2( 1, 1 );
  20181. this.clearcoatNormalMap = null;
  20182. this.reflectivity = 0.5; // maps to F0 = 0.04
  20183. this.sheen = null; // null will disable sheen bsdf
  20184. this.transparency = 0.0;
  20185. this.setValues( parameters );
  20186. }
  20187. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  20188. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20189. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20190. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  20191. MeshStandardMaterial.prototype.copy.call( this, source );
  20192. this.defines = {
  20193. 'STANDARD': '',
  20194. 'PHYSICAL': ''
  20195. };
  20196. this.clearcoat = source.clearcoat;
  20197. this.clearcoatMap = source.clearcoatMap;
  20198. this.clearcoatRoughness = source.clearcoatRoughness;
  20199. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20200. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20201. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  20202. this.reflectivity = source.reflectivity;
  20203. if ( source.sheen ) {
  20204. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  20205. } else {
  20206. this.sheen = null;
  20207. }
  20208. this.transparency = source.transparency;
  20209. return this;
  20210. };
  20211. /**
  20212. * @author mrdoob / http://mrdoob.com/
  20213. * @author alteredq / http://alteredqualia.com/
  20214. *
  20215. * parameters = {
  20216. * color: <hex>,
  20217. * specular: <hex>,
  20218. * shininess: <float>,
  20219. * opacity: <float>,
  20220. *
  20221. * map: new THREE.Texture( <Image> ),
  20222. *
  20223. * lightMap: new THREE.Texture( <Image> ),
  20224. * lightMapIntensity: <float>
  20225. *
  20226. * aoMap: new THREE.Texture( <Image> ),
  20227. * aoMapIntensity: <float>
  20228. *
  20229. * emissive: <hex>,
  20230. * emissiveIntensity: <float>
  20231. * emissiveMap: new THREE.Texture( <Image> ),
  20232. *
  20233. * bumpMap: new THREE.Texture( <Image> ),
  20234. * bumpScale: <float>,
  20235. *
  20236. * normalMap: new THREE.Texture( <Image> ),
  20237. * normalMapType: THREE.TangentSpaceNormalMap,
  20238. * normalScale: <Vector2>,
  20239. *
  20240. * displacementMap: new THREE.Texture( <Image> ),
  20241. * displacementScale: <float>,
  20242. * displacementBias: <float>,
  20243. *
  20244. * specularMap: new THREE.Texture( <Image> ),
  20245. *
  20246. * alphaMap: new THREE.Texture( <Image> ),
  20247. *
  20248. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20249. * combine: THREE.MultiplyOperation,
  20250. * reflectivity: <float>,
  20251. * refractionRatio: <float>,
  20252. *
  20253. * wireframe: <boolean>,
  20254. * wireframeLinewidth: <float>,
  20255. *
  20256. * skinning: <bool>,
  20257. * morphTargets: <bool>,
  20258. * morphNormals: <bool>
  20259. * }
  20260. */
  20261. function MeshPhongMaterial( parameters ) {
  20262. Material.call( this );
  20263. this.type = 'MeshPhongMaterial';
  20264. this.color = new Color( 0xffffff ); // diffuse
  20265. this.specular = new Color( 0x111111 );
  20266. this.shininess = 30;
  20267. this.map = null;
  20268. this.lightMap = null;
  20269. this.lightMapIntensity = 1.0;
  20270. this.aoMap = null;
  20271. this.aoMapIntensity = 1.0;
  20272. this.emissive = new Color( 0x000000 );
  20273. this.emissiveIntensity = 1.0;
  20274. this.emissiveMap = null;
  20275. this.bumpMap = null;
  20276. this.bumpScale = 1;
  20277. this.normalMap = null;
  20278. this.normalMapType = TangentSpaceNormalMap;
  20279. this.normalScale = new Vector2( 1, 1 );
  20280. this.displacementMap = null;
  20281. this.displacementScale = 1;
  20282. this.displacementBias = 0;
  20283. this.specularMap = null;
  20284. this.alphaMap = null;
  20285. this.envMap = null;
  20286. this.combine = MultiplyOperation;
  20287. this.reflectivity = 1;
  20288. this.refractionRatio = 0.98;
  20289. this.wireframe = false;
  20290. this.wireframeLinewidth = 1;
  20291. this.wireframeLinecap = 'round';
  20292. this.wireframeLinejoin = 'round';
  20293. this.skinning = false;
  20294. this.morphTargets = false;
  20295. this.morphNormals = false;
  20296. this.setValues( parameters );
  20297. }
  20298. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  20299. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20300. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20301. MeshPhongMaterial.prototype.copy = function ( source ) {
  20302. Material.prototype.copy.call( this, source );
  20303. this.color.copy( source.color );
  20304. this.specular.copy( source.specular );
  20305. this.shininess = source.shininess;
  20306. this.map = source.map;
  20307. this.lightMap = source.lightMap;
  20308. this.lightMapIntensity = source.lightMapIntensity;
  20309. this.aoMap = source.aoMap;
  20310. this.aoMapIntensity = source.aoMapIntensity;
  20311. this.emissive.copy( source.emissive );
  20312. this.emissiveMap = source.emissiveMap;
  20313. this.emissiveIntensity = source.emissiveIntensity;
  20314. this.bumpMap = source.bumpMap;
  20315. this.bumpScale = source.bumpScale;
  20316. this.normalMap = source.normalMap;
  20317. this.normalMapType = source.normalMapType;
  20318. this.normalScale.copy( source.normalScale );
  20319. this.displacementMap = source.displacementMap;
  20320. this.displacementScale = source.displacementScale;
  20321. this.displacementBias = source.displacementBias;
  20322. this.specularMap = source.specularMap;
  20323. this.alphaMap = source.alphaMap;
  20324. this.envMap = source.envMap;
  20325. this.combine = source.combine;
  20326. this.reflectivity = source.reflectivity;
  20327. this.refractionRatio = source.refractionRatio;
  20328. this.wireframe = source.wireframe;
  20329. this.wireframeLinewidth = source.wireframeLinewidth;
  20330. this.wireframeLinecap = source.wireframeLinecap;
  20331. this.wireframeLinejoin = source.wireframeLinejoin;
  20332. this.skinning = source.skinning;
  20333. this.morphTargets = source.morphTargets;
  20334. this.morphNormals = source.morphNormals;
  20335. return this;
  20336. };
  20337. /**
  20338. * @author takahirox / http://github.com/takahirox
  20339. *
  20340. * parameters = {
  20341. * color: <hex>,
  20342. *
  20343. * map: new THREE.Texture( <Image> ),
  20344. * gradientMap: new THREE.Texture( <Image> ),
  20345. *
  20346. * lightMap: new THREE.Texture( <Image> ),
  20347. * lightMapIntensity: <float>
  20348. *
  20349. * aoMap: new THREE.Texture( <Image> ),
  20350. * aoMapIntensity: <float>
  20351. *
  20352. * emissive: <hex>,
  20353. * emissiveIntensity: <float>
  20354. * emissiveMap: new THREE.Texture( <Image> ),
  20355. *
  20356. * bumpMap: new THREE.Texture( <Image> ),
  20357. * bumpScale: <float>,
  20358. *
  20359. * normalMap: new THREE.Texture( <Image> ),
  20360. * normalMapType: THREE.TangentSpaceNormalMap,
  20361. * normalScale: <Vector2>,
  20362. *
  20363. * displacementMap: new THREE.Texture( <Image> ),
  20364. * displacementScale: <float>,
  20365. * displacementBias: <float>,
  20366. *
  20367. * alphaMap: new THREE.Texture( <Image> ),
  20368. *
  20369. * wireframe: <boolean>,
  20370. * wireframeLinewidth: <float>,
  20371. *
  20372. * skinning: <bool>,
  20373. * morphTargets: <bool>,
  20374. * morphNormals: <bool>
  20375. * }
  20376. */
  20377. function MeshToonMaterial( parameters ) {
  20378. Material.call( this );
  20379. this.defines = { 'TOON': '' };
  20380. this.type = 'MeshToonMaterial';
  20381. this.color = new Color( 0xffffff );
  20382. this.map = null;
  20383. this.gradientMap = null;
  20384. this.lightMap = null;
  20385. this.lightMapIntensity = 1.0;
  20386. this.aoMap = null;
  20387. this.aoMapIntensity = 1.0;
  20388. this.emissive = new Color( 0x000000 );
  20389. this.emissiveIntensity = 1.0;
  20390. this.emissiveMap = null;
  20391. this.bumpMap = null;
  20392. this.bumpScale = 1;
  20393. this.normalMap = null;
  20394. this.normalMapType = TangentSpaceNormalMap;
  20395. this.normalScale = new Vector2( 1, 1 );
  20396. this.displacementMap = null;
  20397. this.displacementScale = 1;
  20398. this.displacementBias = 0;
  20399. this.alphaMap = null;
  20400. this.wireframe = false;
  20401. this.wireframeLinewidth = 1;
  20402. this.wireframeLinecap = 'round';
  20403. this.wireframeLinejoin = 'round';
  20404. this.skinning = false;
  20405. this.morphTargets = false;
  20406. this.morphNormals = false;
  20407. this.setValues( parameters );
  20408. }
  20409. MeshToonMaterial.prototype = Object.create( Material.prototype );
  20410. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20411. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20412. MeshToonMaterial.prototype.copy = function ( source ) {
  20413. Material.prototype.copy.call( this, source );
  20414. this.color.copy( source.color );
  20415. this.map = source.map;
  20416. this.gradientMap = source.gradientMap;
  20417. this.lightMap = source.lightMap;
  20418. this.lightMapIntensity = source.lightMapIntensity;
  20419. this.aoMap = source.aoMap;
  20420. this.aoMapIntensity = source.aoMapIntensity;
  20421. this.emissive.copy( source.emissive );
  20422. this.emissiveMap = source.emissiveMap;
  20423. this.emissiveIntensity = source.emissiveIntensity;
  20424. this.bumpMap = source.bumpMap;
  20425. this.bumpScale = source.bumpScale;
  20426. this.normalMap = source.normalMap;
  20427. this.normalMapType = source.normalMapType;
  20428. this.normalScale.copy( source.normalScale );
  20429. this.displacementMap = source.displacementMap;
  20430. this.displacementScale = source.displacementScale;
  20431. this.displacementBias = source.displacementBias;
  20432. this.alphaMap = source.alphaMap;
  20433. this.wireframe = source.wireframe;
  20434. this.wireframeLinewidth = source.wireframeLinewidth;
  20435. this.wireframeLinecap = source.wireframeLinecap;
  20436. this.wireframeLinejoin = source.wireframeLinejoin;
  20437. this.skinning = source.skinning;
  20438. this.morphTargets = source.morphTargets;
  20439. this.morphNormals = source.morphNormals;
  20440. return this;
  20441. };
  20442. /**
  20443. * @author mrdoob / http://mrdoob.com/
  20444. * @author WestLangley / http://github.com/WestLangley
  20445. *
  20446. * parameters = {
  20447. * opacity: <float>,
  20448. *
  20449. * bumpMap: new THREE.Texture( <Image> ),
  20450. * bumpScale: <float>,
  20451. *
  20452. * normalMap: new THREE.Texture( <Image> ),
  20453. * normalMapType: THREE.TangentSpaceNormalMap,
  20454. * normalScale: <Vector2>,
  20455. *
  20456. * displacementMap: new THREE.Texture( <Image> ),
  20457. * displacementScale: <float>,
  20458. * displacementBias: <float>,
  20459. *
  20460. * wireframe: <boolean>,
  20461. * wireframeLinewidth: <float>
  20462. *
  20463. * skinning: <bool>,
  20464. * morphTargets: <bool>,
  20465. * morphNormals: <bool>
  20466. * }
  20467. */
  20468. function MeshNormalMaterial( parameters ) {
  20469. Material.call( this );
  20470. this.type = 'MeshNormalMaterial';
  20471. this.bumpMap = null;
  20472. this.bumpScale = 1;
  20473. this.normalMap = null;
  20474. this.normalMapType = TangentSpaceNormalMap;
  20475. this.normalScale = new Vector2( 1, 1 );
  20476. this.displacementMap = null;
  20477. this.displacementScale = 1;
  20478. this.displacementBias = 0;
  20479. this.wireframe = false;
  20480. this.wireframeLinewidth = 1;
  20481. this.fog = false;
  20482. this.skinning = false;
  20483. this.morphTargets = false;
  20484. this.morphNormals = false;
  20485. this.setValues( parameters );
  20486. }
  20487. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  20488. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20489. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20490. MeshNormalMaterial.prototype.copy = function ( source ) {
  20491. Material.prototype.copy.call( this, source );
  20492. this.bumpMap = source.bumpMap;
  20493. this.bumpScale = source.bumpScale;
  20494. this.normalMap = source.normalMap;
  20495. this.normalMapType = source.normalMapType;
  20496. this.normalScale.copy( source.normalScale );
  20497. this.displacementMap = source.displacementMap;
  20498. this.displacementScale = source.displacementScale;
  20499. this.displacementBias = source.displacementBias;
  20500. this.wireframe = source.wireframe;
  20501. this.wireframeLinewidth = source.wireframeLinewidth;
  20502. this.skinning = source.skinning;
  20503. this.morphTargets = source.morphTargets;
  20504. this.morphNormals = source.morphNormals;
  20505. return this;
  20506. };
  20507. /**
  20508. * @author mrdoob / http://mrdoob.com/
  20509. * @author alteredq / http://alteredqualia.com/
  20510. *
  20511. * parameters = {
  20512. * color: <hex>,
  20513. * opacity: <float>,
  20514. *
  20515. * map: new THREE.Texture( <Image> ),
  20516. *
  20517. * lightMap: new THREE.Texture( <Image> ),
  20518. * lightMapIntensity: <float>
  20519. *
  20520. * aoMap: new THREE.Texture( <Image> ),
  20521. * aoMapIntensity: <float>
  20522. *
  20523. * emissive: <hex>,
  20524. * emissiveIntensity: <float>
  20525. * emissiveMap: new THREE.Texture( <Image> ),
  20526. *
  20527. * specularMap: new THREE.Texture( <Image> ),
  20528. *
  20529. * alphaMap: new THREE.Texture( <Image> ),
  20530. *
  20531. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20532. * combine: THREE.Multiply,
  20533. * reflectivity: <float>,
  20534. * refractionRatio: <float>,
  20535. *
  20536. * wireframe: <boolean>,
  20537. * wireframeLinewidth: <float>,
  20538. *
  20539. * skinning: <bool>,
  20540. * morphTargets: <bool>,
  20541. * morphNormals: <bool>
  20542. * }
  20543. */
  20544. function MeshLambertMaterial( parameters ) {
  20545. Material.call( this );
  20546. this.type = 'MeshLambertMaterial';
  20547. this.color = new Color( 0xffffff ); // diffuse
  20548. this.map = null;
  20549. this.lightMap = null;
  20550. this.lightMapIntensity = 1.0;
  20551. this.aoMap = null;
  20552. this.aoMapIntensity = 1.0;
  20553. this.emissive = new Color( 0x000000 );
  20554. this.emissiveIntensity = 1.0;
  20555. this.emissiveMap = null;
  20556. this.specularMap = null;
  20557. this.alphaMap = null;
  20558. this.envMap = null;
  20559. this.combine = MultiplyOperation;
  20560. this.reflectivity = 1;
  20561. this.refractionRatio = 0.98;
  20562. this.wireframe = false;
  20563. this.wireframeLinewidth = 1;
  20564. this.wireframeLinecap = 'round';
  20565. this.wireframeLinejoin = 'round';
  20566. this.skinning = false;
  20567. this.morphTargets = false;
  20568. this.morphNormals = false;
  20569. this.setValues( parameters );
  20570. }
  20571. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  20572. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20573. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20574. MeshLambertMaterial.prototype.copy = function ( source ) {
  20575. Material.prototype.copy.call( this, source );
  20576. this.color.copy( source.color );
  20577. this.map = source.map;
  20578. this.lightMap = source.lightMap;
  20579. this.lightMapIntensity = source.lightMapIntensity;
  20580. this.aoMap = source.aoMap;
  20581. this.aoMapIntensity = source.aoMapIntensity;
  20582. this.emissive.copy( source.emissive );
  20583. this.emissiveMap = source.emissiveMap;
  20584. this.emissiveIntensity = source.emissiveIntensity;
  20585. this.specularMap = source.specularMap;
  20586. this.alphaMap = source.alphaMap;
  20587. this.envMap = source.envMap;
  20588. this.combine = source.combine;
  20589. this.reflectivity = source.reflectivity;
  20590. this.refractionRatio = source.refractionRatio;
  20591. this.wireframe = source.wireframe;
  20592. this.wireframeLinewidth = source.wireframeLinewidth;
  20593. this.wireframeLinecap = source.wireframeLinecap;
  20594. this.wireframeLinejoin = source.wireframeLinejoin;
  20595. this.skinning = source.skinning;
  20596. this.morphTargets = source.morphTargets;
  20597. this.morphNormals = source.morphNormals;
  20598. return this;
  20599. };
  20600. /**
  20601. * @author WestLangley / http://github.com/WestLangley
  20602. *
  20603. * parameters = {
  20604. * color: <hex>,
  20605. * opacity: <float>,
  20606. *
  20607. * matcap: new THREE.Texture( <Image> ),
  20608. *
  20609. * map: new THREE.Texture( <Image> ),
  20610. *
  20611. * bumpMap: new THREE.Texture( <Image> ),
  20612. * bumpScale: <float>,
  20613. *
  20614. * normalMap: new THREE.Texture( <Image> ),
  20615. * normalMapType: THREE.TangentSpaceNormalMap,
  20616. * normalScale: <Vector2>,
  20617. *
  20618. * displacementMap: new THREE.Texture( <Image> ),
  20619. * displacementScale: <float>,
  20620. * displacementBias: <float>,
  20621. *
  20622. * alphaMap: new THREE.Texture( <Image> ),
  20623. *
  20624. * skinning: <bool>,
  20625. * morphTargets: <bool>,
  20626. * morphNormals: <bool>
  20627. * }
  20628. */
  20629. function MeshMatcapMaterial( parameters ) {
  20630. Material.call( this );
  20631. this.defines = { 'MATCAP': '' };
  20632. this.type = 'MeshMatcapMaterial';
  20633. this.color = new Color( 0xffffff ); // diffuse
  20634. this.matcap = null;
  20635. this.map = null;
  20636. this.bumpMap = null;
  20637. this.bumpScale = 1;
  20638. this.normalMap = null;
  20639. this.normalMapType = TangentSpaceNormalMap;
  20640. this.normalScale = new Vector2( 1, 1 );
  20641. this.displacementMap = null;
  20642. this.displacementScale = 1;
  20643. this.displacementBias = 0;
  20644. this.alphaMap = null;
  20645. this.skinning = false;
  20646. this.morphTargets = false;
  20647. this.morphNormals = false;
  20648. this.setValues( parameters );
  20649. }
  20650. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  20651. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20652. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20653. MeshMatcapMaterial.prototype.copy = function ( source ) {
  20654. Material.prototype.copy.call( this, source );
  20655. this.defines = { 'MATCAP': '' };
  20656. this.color.copy( source.color );
  20657. this.matcap = source.matcap;
  20658. this.map = source.map;
  20659. this.bumpMap = source.bumpMap;
  20660. this.bumpScale = source.bumpScale;
  20661. this.normalMap = source.normalMap;
  20662. this.normalMapType = source.normalMapType;
  20663. this.normalScale.copy( source.normalScale );
  20664. this.displacementMap = source.displacementMap;
  20665. this.displacementScale = source.displacementScale;
  20666. this.displacementBias = source.displacementBias;
  20667. this.alphaMap = source.alphaMap;
  20668. this.skinning = source.skinning;
  20669. this.morphTargets = source.morphTargets;
  20670. this.morphNormals = source.morphNormals;
  20671. return this;
  20672. };
  20673. /**
  20674. * @author alteredq / http://alteredqualia.com/
  20675. *
  20676. * parameters = {
  20677. * color: <hex>,
  20678. * opacity: <float>,
  20679. *
  20680. * linewidth: <float>,
  20681. *
  20682. * scale: <float>,
  20683. * dashSize: <float>,
  20684. * gapSize: <float>
  20685. * }
  20686. */
  20687. function LineDashedMaterial( parameters ) {
  20688. LineBasicMaterial.call( this );
  20689. this.type = 'LineDashedMaterial';
  20690. this.scale = 1;
  20691. this.dashSize = 3;
  20692. this.gapSize = 1;
  20693. this.setValues( parameters );
  20694. }
  20695. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  20696. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20697. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20698. LineDashedMaterial.prototype.copy = function ( source ) {
  20699. LineBasicMaterial.prototype.copy.call( this, source );
  20700. this.scale = source.scale;
  20701. this.dashSize = source.dashSize;
  20702. this.gapSize = source.gapSize;
  20703. return this;
  20704. };
  20705. var Materials = /*#__PURE__*/Object.freeze({
  20706. __proto__: null,
  20707. ShadowMaterial: ShadowMaterial,
  20708. SpriteMaterial: SpriteMaterial,
  20709. RawShaderMaterial: RawShaderMaterial,
  20710. ShaderMaterial: ShaderMaterial,
  20711. PointsMaterial: PointsMaterial,
  20712. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20713. MeshStandardMaterial: MeshStandardMaterial,
  20714. MeshPhongMaterial: MeshPhongMaterial,
  20715. MeshToonMaterial: MeshToonMaterial,
  20716. MeshNormalMaterial: MeshNormalMaterial,
  20717. MeshLambertMaterial: MeshLambertMaterial,
  20718. MeshDepthMaterial: MeshDepthMaterial,
  20719. MeshDistanceMaterial: MeshDistanceMaterial,
  20720. MeshBasicMaterial: MeshBasicMaterial,
  20721. MeshMatcapMaterial: MeshMatcapMaterial,
  20722. LineDashedMaterial: LineDashedMaterial,
  20723. LineBasicMaterial: LineBasicMaterial,
  20724. Material: Material
  20725. });
  20726. /**
  20727. * @author tschw
  20728. * @author Ben Houston / http://clara.io/
  20729. * @author David Sarno / http://lighthaus.us/
  20730. */
  20731. var AnimationUtils = {
  20732. // same as Array.prototype.slice, but also works on typed arrays
  20733. arraySlice: function ( array, from, to ) {
  20734. if ( AnimationUtils.isTypedArray( array ) ) {
  20735. // in ios9 array.subarray(from, undefined) will return empty array
  20736. // but array.subarray(from) or array.subarray(from, len) is correct
  20737. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20738. }
  20739. return array.slice( from, to );
  20740. },
  20741. // converts an array to a specific type
  20742. convertArray: function ( array, type, forceClone ) {
  20743. if ( ! array || // let 'undefined' and 'null' pass
  20744. ! forceClone && array.constructor === type ) { return array; }
  20745. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20746. return new type( array ); // create typed array
  20747. }
  20748. return Array.prototype.slice.call( array ); // create Array
  20749. },
  20750. isTypedArray: function ( object ) {
  20751. return ArrayBuffer.isView( object ) &&
  20752. ! ( object instanceof DataView );
  20753. },
  20754. // returns an array by which times and values can be sorted
  20755. getKeyframeOrder: function ( times ) {
  20756. function compareTime( i, j ) {
  20757. return times[ i ] - times[ j ];
  20758. }
  20759. var n = times.length;
  20760. var result = new Array( n );
  20761. for ( var i = 0; i !== n; ++ i ) { result[ i ] = i; }
  20762. result.sort( compareTime );
  20763. return result;
  20764. },
  20765. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20766. sortedArray: function ( values, stride, order ) {
  20767. var nValues = values.length;
  20768. var result = new values.constructor( nValues );
  20769. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20770. var srcOffset = order[ i ] * stride;
  20771. for ( var j = 0; j !== stride; ++ j ) {
  20772. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20773. }
  20774. }
  20775. return result;
  20776. },
  20777. // function for parsing AOS keyframe formats
  20778. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20779. var i = 1, key = jsonKeys[ 0 ];
  20780. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20781. key = jsonKeys[ i ++ ];
  20782. }
  20783. if ( key === undefined ) { return; } // no data
  20784. var value = key[ valuePropertyName ];
  20785. if ( value === undefined ) { return; } // no data
  20786. if ( Array.isArray( value ) ) {
  20787. do {
  20788. value = key[ valuePropertyName ];
  20789. if ( value !== undefined ) {
  20790. times.push( key.time );
  20791. values.push.apply( values, value ); // push all elements
  20792. }
  20793. key = jsonKeys[ i ++ ];
  20794. } while ( key !== undefined );
  20795. } else if ( value.toArray !== undefined ) {
  20796. // ...assume THREE.Math-ish
  20797. do {
  20798. value = key[ valuePropertyName ];
  20799. if ( value !== undefined ) {
  20800. times.push( key.time );
  20801. value.toArray( values, values.length );
  20802. }
  20803. key = jsonKeys[ i ++ ];
  20804. } while ( key !== undefined );
  20805. } else {
  20806. // otherwise push as-is
  20807. do {
  20808. value = key[ valuePropertyName ];
  20809. if ( value !== undefined ) {
  20810. times.push( key.time );
  20811. values.push( value );
  20812. }
  20813. key = jsonKeys[ i ++ ];
  20814. } while ( key !== undefined );
  20815. }
  20816. },
  20817. subclip: function ( sourceClip, name, startFrame, endFrame, fps ) {
  20818. fps = fps || 30;
  20819. var clip = sourceClip.clone();
  20820. clip.name = name;
  20821. var tracks = [];
  20822. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20823. var track = clip.tracks[ i ];
  20824. var valueSize = track.getValueSize();
  20825. var times = [];
  20826. var values = [];
  20827. for ( var j = 0; j < track.times.length; ++ j ) {
  20828. var frame = track.times[ j ] * fps;
  20829. if ( frame < startFrame || frame >= endFrame ) { continue; }
  20830. times.push( track.times[ j ] );
  20831. for ( var k = 0; k < valueSize; ++ k ) {
  20832. values.push( track.values[ j * valueSize + k ] );
  20833. }
  20834. }
  20835. if ( times.length === 0 ) { continue; }
  20836. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  20837. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  20838. tracks.push( track );
  20839. }
  20840. clip.tracks = tracks;
  20841. // find minimum .times value across all tracks in the trimmed clip
  20842. var minStartTime = Infinity;
  20843. for ( var i$1 = 0; i$1 < clip.tracks.length; ++ i$1 ) {
  20844. if ( minStartTime > clip.tracks[ i$1 ].times[ 0 ] ) {
  20845. minStartTime = clip.tracks[ i$1 ].times[ 0 ];
  20846. }
  20847. }
  20848. // shift all tracks such that clip begins at t=0
  20849. for ( var i$2 = 0; i$2 < clip.tracks.length; ++ i$2 ) {
  20850. clip.tracks[ i$2 ].shift( - 1 * minStartTime );
  20851. }
  20852. clip.resetDuration();
  20853. return clip;
  20854. },
  20855. makeClipAdditive: function ( targetClip, referenceFrame, referenceClip, fps ) {
  20856. if ( referenceFrame === undefined ) { referenceFrame = 0; }
  20857. if ( referenceClip === undefined ) { referenceClip = targetClip; }
  20858. if ( fps === undefined || fps <= 0 ) { fps = 30; }
  20859. var numTracks = targetClip.tracks.length;
  20860. var referenceTime = referenceFrame / fps;
  20861. // Make each track's values relative to the values at the reference frame
  20862. var loop = function ( i ) {
  20863. var referenceTrack = referenceClip.tracks[ i ];
  20864. var referenceTrackType = referenceTrack.ValueTypeName;
  20865. // Skip this track if it's non-numeric
  20866. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) { return; }
  20867. // Find the track in the target clip whose name and type matches the reference track
  20868. var targetTrack = targetClip.tracks.find( function ( track ) {
  20869. return track.name === referenceTrack.name
  20870. && track.ValueTypeName === referenceTrackType;
  20871. } );
  20872. if ( targetTrack === undefined ) { return; }
  20873. var valueSize = referenceTrack.getValueSize();
  20874. var lastIndex = referenceTrack.times.length - 1;
  20875. var referenceValue = (void 0);
  20876. // Find the value to subtract out of the track
  20877. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  20878. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20879. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, 0, referenceTrack.valueSize );
  20880. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  20881. // Reference frame is after the last keyframe, so just use the last keyframe
  20882. var startIndex = lastIndex * valueSize;
  20883. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex );
  20884. } else {
  20885. // Interpolate to the reference value
  20886. var interpolant = referenceTrack.createInterpolant();
  20887. interpolant.evaluate( referenceTime );
  20888. referenceValue = interpolant.resultBuffer;
  20889. }
  20890. // Conjugate the quaternion
  20891. if ( referenceTrackType === 'quaternion' ) {
  20892. var referenceQuat = new Quaternion(
  20893. referenceValue[ 0 ],
  20894. referenceValue[ 1 ],
  20895. referenceValue[ 2 ],
  20896. referenceValue[ 3 ]
  20897. ).normalize().conjugate();
  20898. referenceQuat.toArray( referenceValue );
  20899. }
  20900. // Subtract the reference value from all of the track values
  20901. var numTimes = targetTrack.times.length;
  20902. for ( var j = 0; j < numTimes; ++ j ) {
  20903. var valueStart = j * valueSize;
  20904. if ( referenceTrackType === 'quaternion' ) {
  20905. // Multiply the conjugate for quaternion track types
  20906. Quaternion.multiplyQuaternionsFlat(
  20907. targetTrack.values,
  20908. valueStart,
  20909. referenceValue,
  20910. 0,
  20911. targetTrack.values,
  20912. valueStart
  20913. );
  20914. } else {
  20915. // Subtract each value for all other numeric track types
  20916. for ( var k = 0; k < valueSize; ++ k ) {
  20917. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  20918. }
  20919. }
  20920. }
  20921. };
  20922. for ( var i = 0; i < numTracks; ++ i ) loop( i );
  20923. targetClip.blendMode = AdditiveAnimationBlendMode;
  20924. return targetClip;
  20925. }
  20926. };
  20927. /**
  20928. * Abstract base class of interpolants over parametric samples.
  20929. *
  20930. * The parameter domain is one dimensional, typically the time or a path
  20931. * along a curve defined by the data.
  20932. *
  20933. * The sample values can have any dimensionality and derived classes may
  20934. * apply special interpretations to the data.
  20935. *
  20936. * This class provides the interval seek in a Template Method, deferring
  20937. * the actual interpolation to derived classes.
  20938. *
  20939. * Time complexity is O(1) for linear access crossing at most two points
  20940. * and O(log N) for random access, where N is the number of positions.
  20941. *
  20942. * References:
  20943. *
  20944. * http://www.oodesign.com/template-method-pattern.html
  20945. *
  20946. * @author tschw
  20947. */
  20948. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20949. this.parameterPositions = parameterPositions;
  20950. this._cachedIndex = 0;
  20951. this.resultBuffer = resultBuffer !== undefined ?
  20952. resultBuffer : new sampleValues.constructor( sampleSize );
  20953. this.sampleValues = sampleValues;
  20954. this.valueSize = sampleSize;
  20955. }
  20956. Object.assign( Interpolant.prototype, {
  20957. evaluate: function ( t ) {
  20958. var pp = this.parameterPositions,
  20959. i1 = this._cachedIndex,
  20960. t1 = pp[ i1 ],
  20961. t0 = pp[ i1 - 1 ];
  20962. validate_interval: {
  20963. seek: {
  20964. var right;
  20965. linear_scan: {
  20966. //- See http://jsperf.com/comparison-to-undefined/3
  20967. //- slower code:
  20968. //-
  20969. //- if ( t >= t1 || t1 === undefined ) {
  20970. forward_scan: if ( ! ( t < t1 ) ) {
  20971. for ( var giveUpAt = i1 + 2; ; ) {
  20972. if ( t1 === undefined ) {
  20973. if ( t < t0 ) { break forward_scan; }
  20974. // after end
  20975. i1 = pp.length;
  20976. this._cachedIndex = i1;
  20977. return this.afterEnd_( i1 - 1, t, t0 );
  20978. }
  20979. if ( i1 === giveUpAt ) { break; } // this loop
  20980. t0 = t1;
  20981. t1 = pp[ ++ i1 ];
  20982. if ( t < t1 ) {
  20983. // we have arrived at the sought interval
  20984. break seek;
  20985. }
  20986. }
  20987. // prepare binary search on the right side of the index
  20988. right = pp.length;
  20989. break linear_scan;
  20990. }
  20991. //- slower code:
  20992. //- if ( t < t0 || t0 === undefined ) {
  20993. if ( ! ( t >= t0 ) ) {
  20994. // looping?
  20995. var t1global = pp[ 1 ];
  20996. if ( t < t1global ) {
  20997. i1 = 2; // + 1, using the scan for the details
  20998. t0 = t1global;
  20999. }
  21000. // linear reverse scan
  21001. for ( var giveUpAt$1 = i1 - 2; ; ) {
  21002. if ( t0 === undefined ) {
  21003. // before start
  21004. this._cachedIndex = 0;
  21005. return this.beforeStart_( 0, t, t1 );
  21006. }
  21007. if ( i1 === giveUpAt$1 ) { break; } // this loop
  21008. t1 = t0;
  21009. t0 = pp[ -- i1 - 1 ];
  21010. if ( t >= t0 ) {
  21011. // we have arrived at the sought interval
  21012. break seek;
  21013. }
  21014. }
  21015. // prepare binary search on the left side of the index
  21016. right = i1;
  21017. i1 = 0;
  21018. break linear_scan;
  21019. }
  21020. // the interval is valid
  21021. break validate_interval;
  21022. } // linear scan
  21023. // binary search
  21024. while ( i1 < right ) {
  21025. var mid = ( i1 + right ) >>> 1;
  21026. if ( t < pp[ mid ] ) {
  21027. right = mid;
  21028. } else {
  21029. i1 = mid + 1;
  21030. }
  21031. }
  21032. t1 = pp[ i1 ];
  21033. t0 = pp[ i1 - 1 ];
  21034. // check boundary cases, again
  21035. if ( t0 === undefined ) {
  21036. this._cachedIndex = 0;
  21037. return this.beforeStart_( 0, t, t1 );
  21038. }
  21039. if ( t1 === undefined ) {
  21040. i1 = pp.length;
  21041. this._cachedIndex = i1;
  21042. return this.afterEnd_( i1 - 1, t0, t );
  21043. }
  21044. } // seek
  21045. this._cachedIndex = i1;
  21046. this.intervalChanged_( i1, t0, t1 );
  21047. } // validate_interval
  21048. return this.interpolate_( i1, t0, t, t1 );
  21049. },
  21050. settings: null, // optional, subclass-specific settings structure
  21051. // Note: The indirection allows central control of many interpolants.
  21052. // --- Protected interface
  21053. DefaultSettings_: {},
  21054. getSettings_: function () {
  21055. return this.settings || this.DefaultSettings_;
  21056. },
  21057. copySampleValue_: function ( index ) {
  21058. // copies a sample value to the result buffer
  21059. var result = this.resultBuffer,
  21060. values = this.sampleValues,
  21061. stride = this.valueSize,
  21062. offset = index * stride;
  21063. for ( var i = 0; i !== stride; ++ i ) {
  21064. result[ i ] = values[ offset + i ];
  21065. }
  21066. return result;
  21067. },
  21068. // Template methods for derived classes:
  21069. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  21070. throw new Error( 'call to abstract method' );
  21071. // implementations shall return this.resultBuffer
  21072. },
  21073. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  21074. // empty
  21075. }
  21076. } );
  21077. // DECLARE ALIAS AFTER assign prototype
  21078. Object.assign( Interpolant.prototype, {
  21079. //( 0, t, t0 ), returns this.resultBuffer
  21080. beforeStart_: Interpolant.prototype.copySampleValue_,
  21081. //( N-1, tN-1, t ), returns this.resultBuffer
  21082. afterEnd_: Interpolant.prototype.copySampleValue_,
  21083. } );
  21084. /**
  21085. * Fast and simple cubic spline interpolant.
  21086. *
  21087. * It was derived from a Hermitian construction setting the first derivative
  21088. * at each sample position to the linear slope between neighboring positions
  21089. * over their parameter interval.
  21090. *
  21091. * @author tschw
  21092. */
  21093. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21094. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21095. this._weightPrev = - 0;
  21096. this._offsetPrev = - 0;
  21097. this._weightNext = - 0;
  21098. this._offsetNext = - 0;
  21099. }
  21100. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21101. constructor: CubicInterpolant,
  21102. DefaultSettings_: {
  21103. endingStart: ZeroCurvatureEnding,
  21104. endingEnd: ZeroCurvatureEnding
  21105. },
  21106. intervalChanged_: function ( i1, t0, t1 ) {
  21107. var pp = this.parameterPositions,
  21108. iPrev = i1 - 2,
  21109. iNext = i1 + 1,
  21110. tPrev = pp[ iPrev ],
  21111. tNext = pp[ iNext ];
  21112. if ( tPrev === undefined ) {
  21113. switch ( this.getSettings_().endingStart ) {
  21114. case ZeroSlopeEnding:
  21115. // f'(t0) = 0
  21116. iPrev = i1;
  21117. tPrev = 2 * t0 - t1;
  21118. break;
  21119. case WrapAroundEnding:
  21120. // use the other end of the curve
  21121. iPrev = pp.length - 2;
  21122. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  21123. break;
  21124. default: // ZeroCurvatureEnding
  21125. // f''(t0) = 0 a.k.a. Natural Spline
  21126. iPrev = i1;
  21127. tPrev = t1;
  21128. }
  21129. }
  21130. if ( tNext === undefined ) {
  21131. switch ( this.getSettings_().endingEnd ) {
  21132. case ZeroSlopeEnding:
  21133. // f'(tN) = 0
  21134. iNext = i1;
  21135. tNext = 2 * t1 - t0;
  21136. break;
  21137. case WrapAroundEnding:
  21138. // use the other end of the curve
  21139. iNext = 1;
  21140. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  21141. break;
  21142. default: // ZeroCurvatureEnding
  21143. // f''(tN) = 0, a.k.a. Natural Spline
  21144. iNext = i1 - 1;
  21145. tNext = t0;
  21146. }
  21147. }
  21148. var halfDt = ( t1 - t0 ) * 0.5,
  21149. stride = this.valueSize;
  21150. this._weightPrev = halfDt / ( t0 - tPrev );
  21151. this._weightNext = halfDt / ( tNext - t1 );
  21152. this._offsetPrev = iPrev * stride;
  21153. this._offsetNext = iNext * stride;
  21154. },
  21155. interpolate_: function ( i1, t0, t, t1 ) {
  21156. var result = this.resultBuffer,
  21157. values = this.sampleValues,
  21158. stride = this.valueSize,
  21159. o1 = i1 * stride, o0 = o1 - stride,
  21160. oP = this._offsetPrev, oN = this._offsetNext,
  21161. wP = this._weightPrev, wN = this._weightNext,
  21162. p = ( t - t0 ) / ( t1 - t0 ),
  21163. pp = p * p,
  21164. ppp = pp * p;
  21165. // evaluate polynomials
  21166. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  21167. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  21168. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  21169. var sN = wN * ppp - wN * pp;
  21170. // combine data linearly
  21171. for ( var i = 0; i !== stride; ++ i ) {
  21172. result[ i ] =
  21173. sP * values[ oP + i ] +
  21174. s0 * values[ o0 + i ] +
  21175. s1 * values[ o1 + i ] +
  21176. sN * values[ oN + i ];
  21177. }
  21178. return result;
  21179. }
  21180. } );
  21181. /**
  21182. * @author tschw
  21183. */
  21184. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21185. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21186. }
  21187. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21188. constructor: LinearInterpolant,
  21189. interpolate_: function ( i1, t0, t, t1 ) {
  21190. var result = this.resultBuffer,
  21191. values = this.sampleValues,
  21192. stride = this.valueSize,
  21193. offset1 = i1 * stride,
  21194. offset0 = offset1 - stride,
  21195. weight1 = ( t - t0 ) / ( t1 - t0 ),
  21196. weight0 = 1 - weight1;
  21197. for ( var i = 0; i !== stride; ++ i ) {
  21198. result[ i ] =
  21199. values[ offset0 + i ] * weight0 +
  21200. values[ offset1 + i ] * weight1;
  21201. }
  21202. return result;
  21203. }
  21204. } );
  21205. /**
  21206. *
  21207. * Interpolant that evaluates to the sample value at the position preceeding
  21208. * the parameter.
  21209. *
  21210. * @author tschw
  21211. */
  21212. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21213. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21214. }
  21215. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21216. constructor: DiscreteInterpolant,
  21217. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  21218. return this.copySampleValue_( i1 - 1 );
  21219. }
  21220. } );
  21221. /**
  21222. *
  21223. * A timed sequence of keyframes for a specific property.
  21224. *
  21225. *
  21226. * @author Ben Houston / http://clara.io/
  21227. * @author David Sarno / http://lighthaus.us/
  21228. * @author tschw
  21229. */
  21230. function KeyframeTrack( name, times, values, interpolation ) {
  21231. if ( name === undefined ) { throw new Error( 'THREE.KeyframeTrack: track name is undefined' ); }
  21232. if ( times === undefined || times.length === 0 ) { throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name ); }
  21233. this.name = name;
  21234. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  21235. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  21236. this.setInterpolation( interpolation || this.DefaultInterpolation );
  21237. }
  21238. // Static methods
  21239. Object.assign( KeyframeTrack, {
  21240. // Serialization (in static context, because of constructor invocation
  21241. // and automatic invocation of .toJSON):
  21242. toJSON: function ( track ) {
  21243. var trackType = track.constructor;
  21244. var json;
  21245. // derived classes can define a static toJSON method
  21246. if ( trackType.toJSON !== undefined ) {
  21247. json = trackType.toJSON( track );
  21248. } else {
  21249. // by default, we assume the data can be serialized as-is
  21250. json = {
  21251. 'name': track.name,
  21252. 'times': AnimationUtils.convertArray( track.times, Array ),
  21253. 'values': AnimationUtils.convertArray( track.values, Array )
  21254. };
  21255. var interpolation = track.getInterpolation();
  21256. if ( interpolation !== track.DefaultInterpolation ) {
  21257. json.interpolation = interpolation;
  21258. }
  21259. }
  21260. json.type = track.ValueTypeName; // mandatory
  21261. return json;
  21262. }
  21263. } );
  21264. Object.assign( KeyframeTrack.prototype, {
  21265. constructor: KeyframeTrack,
  21266. TimeBufferType: Float32Array,
  21267. ValueBufferType: Float32Array,
  21268. DefaultInterpolation: InterpolateLinear,
  21269. InterpolantFactoryMethodDiscrete: function ( result ) {
  21270. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  21271. },
  21272. InterpolantFactoryMethodLinear: function ( result ) {
  21273. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21274. },
  21275. InterpolantFactoryMethodSmooth: function ( result ) {
  21276. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21277. },
  21278. setInterpolation: function ( interpolation ) {
  21279. var factoryMethod;
  21280. switch ( interpolation ) {
  21281. case InterpolateDiscrete:
  21282. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21283. break;
  21284. case InterpolateLinear:
  21285. factoryMethod = this.InterpolantFactoryMethodLinear;
  21286. break;
  21287. case InterpolateSmooth:
  21288. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21289. break;
  21290. }
  21291. if ( factoryMethod === undefined ) {
  21292. var message = "unsupported interpolation for " +
  21293. this.ValueTypeName + " keyframe track named " + this.name;
  21294. if ( this.createInterpolant === undefined ) {
  21295. // fall back to default, unless the default itself is messed up
  21296. if ( interpolation !== this.DefaultInterpolation ) {
  21297. this.setInterpolation( this.DefaultInterpolation );
  21298. } else {
  21299. throw new Error( message ); // fatal, in this case
  21300. }
  21301. }
  21302. console.warn( 'THREE.KeyframeTrack:', message );
  21303. return this;
  21304. }
  21305. this.createInterpolant = factoryMethod;
  21306. return this;
  21307. },
  21308. getInterpolation: function () {
  21309. switch ( this.createInterpolant ) {
  21310. case this.InterpolantFactoryMethodDiscrete:
  21311. return InterpolateDiscrete;
  21312. case this.InterpolantFactoryMethodLinear:
  21313. return InterpolateLinear;
  21314. case this.InterpolantFactoryMethodSmooth:
  21315. return InterpolateSmooth;
  21316. }
  21317. },
  21318. getValueSize: function () {
  21319. return this.values.length / this.times.length;
  21320. },
  21321. // move all keyframes either forwards or backwards in time
  21322. shift: function ( timeOffset ) {
  21323. if ( timeOffset !== 0.0 ) {
  21324. var times = this.times;
  21325. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21326. times[ i ] += timeOffset;
  21327. }
  21328. }
  21329. return this;
  21330. },
  21331. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21332. scale: function ( timeScale ) {
  21333. if ( timeScale !== 1.0 ) {
  21334. var times = this.times;
  21335. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21336. times[ i ] *= timeScale;
  21337. }
  21338. }
  21339. return this;
  21340. },
  21341. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21342. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21343. trim: function ( startTime, endTime ) {
  21344. var times = this.times,
  21345. nKeys = times.length;
  21346. var from = 0,
  21347. to = nKeys - 1;
  21348. while ( from !== nKeys && times[ from ] < startTime ) {
  21349. ++ from;
  21350. }
  21351. while ( to !== - 1 && times[ to ] > endTime ) {
  21352. -- to;
  21353. }
  21354. ++ to; // inclusive -> exclusive bound
  21355. if ( from !== 0 || to !== nKeys ) {
  21356. // empty tracks are forbidden, so keep at least one keyframe
  21357. if ( from >= to ) {
  21358. to = Math.max( to, 1 );
  21359. from = to - 1;
  21360. }
  21361. var stride = this.getValueSize();
  21362. this.times = AnimationUtils.arraySlice( times, from, to );
  21363. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21364. }
  21365. return this;
  21366. },
  21367. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21368. validate: function () {
  21369. var valid = true;
  21370. var valueSize = this.getValueSize();
  21371. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21372. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21373. valid = false;
  21374. }
  21375. var times = this.times,
  21376. values = this.values,
  21377. nKeys = times.length;
  21378. if ( nKeys === 0 ) {
  21379. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21380. valid = false;
  21381. }
  21382. var prevTime = null;
  21383. for ( var i = 0; i !== nKeys; i ++ ) {
  21384. var currTime = times[ i ];
  21385. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21386. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21387. valid = false;
  21388. break;
  21389. }
  21390. if ( prevTime !== null && prevTime > currTime ) {
  21391. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21392. valid = false;
  21393. break;
  21394. }
  21395. prevTime = currTime;
  21396. }
  21397. if ( values !== undefined ) {
  21398. if ( AnimationUtils.isTypedArray( values ) ) {
  21399. for ( var i$1 = 0, n = values.length; i$1 !== n; ++ i$1 ) {
  21400. var value = values[ i$1 ];
  21401. if ( isNaN( value ) ) {
  21402. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i$1, value );
  21403. valid = false;
  21404. break;
  21405. }
  21406. }
  21407. }
  21408. }
  21409. return valid;
  21410. },
  21411. // removes equivalent sequential keys as common in morph target sequences
  21412. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21413. optimize: function () {
  21414. // times or values may be shared with other tracks, so overwriting is unsafe
  21415. var times = AnimationUtils.arraySlice( this.times ),
  21416. values = AnimationUtils.arraySlice( this.values ),
  21417. stride = this.getValueSize(),
  21418. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21419. lastIndex = times.length - 1;
  21420. var writeIndex = 1;
  21421. for ( var i = 1; i < lastIndex; ++ i ) {
  21422. var keep = false;
  21423. var time = times[ i ];
  21424. var timeNext = times[ i + 1 ];
  21425. // remove adjacent keyframes scheduled at the same time
  21426. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21427. if ( ! smoothInterpolation ) {
  21428. // remove unnecessary keyframes same as their neighbors
  21429. var offset = i * stride,
  21430. offsetP = offset - stride,
  21431. offsetN = offset + stride;
  21432. for ( var j = 0; j !== stride; ++ j ) {
  21433. var value = values[ offset + j ];
  21434. if ( value !== values[ offsetP + j ] ||
  21435. value !== values[ offsetN + j ] ) {
  21436. keep = true;
  21437. break;
  21438. }
  21439. }
  21440. } else {
  21441. keep = true;
  21442. }
  21443. }
  21444. // in-place compaction
  21445. if ( keep ) {
  21446. if ( i !== writeIndex ) {
  21447. times[ writeIndex ] = times[ i ];
  21448. var readOffset = i * stride,
  21449. writeOffset = writeIndex * stride;
  21450. for ( var j$1 = 0; j$1 !== stride; ++ j$1 ) {
  21451. values[ writeOffset + j$1 ] = values[ readOffset + j$1 ];
  21452. }
  21453. }
  21454. ++ writeIndex;
  21455. }
  21456. }
  21457. // flush last keyframe (compaction looks ahead)
  21458. if ( lastIndex > 0 ) {
  21459. times[ writeIndex ] = times[ lastIndex ];
  21460. for ( var readOffset$1 = lastIndex * stride, writeOffset$1 = writeIndex * stride, j$2 = 0; j$2 !== stride; ++ j$2 ) {
  21461. values[ writeOffset$1 + j$2 ] = values[ readOffset$1 + j$2 ];
  21462. }
  21463. ++ writeIndex;
  21464. }
  21465. if ( writeIndex !== times.length ) {
  21466. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21467. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21468. } else {
  21469. this.times = times;
  21470. this.values = values;
  21471. }
  21472. return this;
  21473. },
  21474. clone: function () {
  21475. var times = AnimationUtils.arraySlice( this.times, 0 );
  21476. var values = AnimationUtils.arraySlice( this.values, 0 );
  21477. var TypedKeyframeTrack = this.constructor;
  21478. var track = new TypedKeyframeTrack( this.name, times, values );
  21479. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21480. track.createInterpolant = this.createInterpolant;
  21481. return track;
  21482. }
  21483. } );
  21484. /**
  21485. *
  21486. * A Track of Boolean keyframe values.
  21487. *
  21488. *
  21489. * @author Ben Houston / http://clara.io/
  21490. * @author David Sarno / http://lighthaus.us/
  21491. * @author tschw
  21492. */
  21493. function BooleanKeyframeTrack( name, times, values ) {
  21494. KeyframeTrack.call( this, name, times, values );
  21495. }
  21496. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21497. constructor: BooleanKeyframeTrack,
  21498. ValueTypeName: 'bool',
  21499. ValueBufferType: Array,
  21500. DefaultInterpolation: InterpolateDiscrete,
  21501. InterpolantFactoryMethodLinear: undefined,
  21502. InterpolantFactoryMethodSmooth: undefined
  21503. // Note: Actually this track could have a optimized / compressed
  21504. // representation of a single value and a custom interpolant that
  21505. // computes "firstValue ^ isOdd( index )".
  21506. } );
  21507. /**
  21508. *
  21509. * A Track of keyframe values that represent color.
  21510. *
  21511. *
  21512. * @author Ben Houston / http://clara.io/
  21513. * @author David Sarno / http://lighthaus.us/
  21514. * @author tschw
  21515. */
  21516. function ColorKeyframeTrack( name, times, values, interpolation ) {
  21517. KeyframeTrack.call( this, name, times, values, interpolation );
  21518. }
  21519. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21520. constructor: ColorKeyframeTrack,
  21521. ValueTypeName: 'color'
  21522. // ValueBufferType is inherited
  21523. // DefaultInterpolation is inherited
  21524. // Note: Very basic implementation and nothing special yet.
  21525. // However, this is the place for color space parameterization.
  21526. } );
  21527. /**
  21528. *
  21529. * A Track of numeric keyframe values.
  21530. *
  21531. * @author Ben Houston / http://clara.io/
  21532. * @author David Sarno / http://lighthaus.us/
  21533. * @author tschw
  21534. */
  21535. function NumberKeyframeTrack( name, times, values, interpolation ) {
  21536. KeyframeTrack.call( this, name, times, values, interpolation );
  21537. }
  21538. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21539. constructor: NumberKeyframeTrack,
  21540. ValueTypeName: 'number'
  21541. // ValueBufferType is inherited
  21542. // DefaultInterpolation is inherited
  21543. } );
  21544. /**
  21545. * Spherical linear unit quaternion interpolant.
  21546. *
  21547. * @author tschw
  21548. */
  21549. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21550. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21551. }
  21552. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21553. constructor: QuaternionLinearInterpolant,
  21554. interpolate_: function ( i1, t0, t, t1 ) {
  21555. var result = this.resultBuffer,
  21556. values = this.sampleValues,
  21557. stride = this.valueSize,
  21558. alpha = ( t - t0 ) / ( t1 - t0 );
  21559. var offset = i1 * stride;
  21560. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  21561. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  21562. }
  21563. return result;
  21564. }
  21565. } );
  21566. /**
  21567. *
  21568. * A Track of quaternion keyframe values.
  21569. *
  21570. * @author Ben Houston / http://clara.io/
  21571. * @author David Sarno / http://lighthaus.us/
  21572. * @author tschw
  21573. */
  21574. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  21575. KeyframeTrack.call( this, name, times, values, interpolation );
  21576. }
  21577. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21578. constructor: QuaternionKeyframeTrack,
  21579. ValueTypeName: 'quaternion',
  21580. // ValueBufferType is inherited
  21581. DefaultInterpolation: InterpolateLinear,
  21582. InterpolantFactoryMethodLinear: function ( result ) {
  21583. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21584. },
  21585. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21586. } );
  21587. /**
  21588. *
  21589. * A Track that interpolates Strings
  21590. *
  21591. *
  21592. * @author Ben Houston / http://clara.io/
  21593. * @author David Sarno / http://lighthaus.us/
  21594. * @author tschw
  21595. */
  21596. function StringKeyframeTrack( name, times, values, interpolation ) {
  21597. KeyframeTrack.call( this, name, times, values, interpolation );
  21598. }
  21599. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21600. constructor: StringKeyframeTrack,
  21601. ValueTypeName: 'string',
  21602. ValueBufferType: Array,
  21603. DefaultInterpolation: InterpolateDiscrete,
  21604. InterpolantFactoryMethodLinear: undefined,
  21605. InterpolantFactoryMethodSmooth: undefined
  21606. } );
  21607. /**
  21608. *
  21609. * A Track of vectored keyframe values.
  21610. *
  21611. *
  21612. * @author Ben Houston / http://clara.io/
  21613. * @author David Sarno / http://lighthaus.us/
  21614. * @author tschw
  21615. */
  21616. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21617. KeyframeTrack.call( this, name, times, values, interpolation );
  21618. }
  21619. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21620. constructor: VectorKeyframeTrack,
  21621. ValueTypeName: 'vector'
  21622. // ValueBufferType is inherited
  21623. // DefaultInterpolation is inherited
  21624. } );
  21625. /**
  21626. *
  21627. * Reusable set of Tracks that represent an animation.
  21628. *
  21629. * @author Ben Houston / http://clara.io/
  21630. * @author David Sarno / http://lighthaus.us/
  21631. */
  21632. function AnimationClip( name, duration, tracks, blendMode ) {
  21633. this.name = name;
  21634. this.tracks = tracks;
  21635. this.duration = ( duration !== undefined ) ? duration : - 1;
  21636. this.blendMode = ( blendMode !== undefined ) ? blendMode : NormalAnimationBlendMode;
  21637. this.uuid = MathUtils.generateUUID();
  21638. // this means it should figure out its duration by scanning the tracks
  21639. if ( this.duration < 0 ) {
  21640. this.resetDuration();
  21641. }
  21642. }
  21643. function getTrackTypeForValueTypeName( typeName ) {
  21644. switch ( typeName.toLowerCase() ) {
  21645. case 'scalar':
  21646. case 'double':
  21647. case 'float':
  21648. case 'number':
  21649. case 'integer':
  21650. return NumberKeyframeTrack;
  21651. case 'vector':
  21652. case 'vector2':
  21653. case 'vector3':
  21654. case 'vector4':
  21655. return VectorKeyframeTrack;
  21656. case 'color':
  21657. return ColorKeyframeTrack;
  21658. case 'quaternion':
  21659. return QuaternionKeyframeTrack;
  21660. case 'bool':
  21661. case 'boolean':
  21662. return BooleanKeyframeTrack;
  21663. case 'string':
  21664. return StringKeyframeTrack;
  21665. }
  21666. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  21667. }
  21668. function parseKeyframeTrack( json ) {
  21669. if ( json.type === undefined ) {
  21670. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  21671. }
  21672. var trackType = getTrackTypeForValueTypeName( json.type );
  21673. if ( json.times === undefined ) {
  21674. var times = [], values = [];
  21675. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  21676. json.times = times;
  21677. json.values = values;
  21678. }
  21679. // derived classes can define a static parse method
  21680. if ( trackType.parse !== undefined ) {
  21681. return trackType.parse( json );
  21682. } else {
  21683. // by default, we assume a constructor compatible with the base
  21684. return new trackType( json.name, json.times, json.values, json.interpolation );
  21685. }
  21686. }
  21687. Object.assign( AnimationClip, {
  21688. parse: function ( json ) {
  21689. var tracks = [],
  21690. jsonTracks = json.tracks,
  21691. frameTime = 1.0 / ( json.fps || 1.0 );
  21692. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21693. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  21694. }
  21695. return new AnimationClip( json.name, json.duration, tracks, json.blendMode );
  21696. },
  21697. toJSON: function ( clip ) {
  21698. var tracks = [],
  21699. clipTracks = clip.tracks;
  21700. var json = {
  21701. 'name': clip.name,
  21702. 'duration': clip.duration,
  21703. 'tracks': tracks,
  21704. 'uuid': clip.uuid,
  21705. 'blendMode': clip.blendMode
  21706. };
  21707. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21708. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21709. }
  21710. return json;
  21711. },
  21712. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21713. var numMorphTargets = morphTargetSequence.length;
  21714. var tracks = [];
  21715. for ( var i = 0; i < numMorphTargets; i ++ ) {
  21716. var times = [];
  21717. var values = [];
  21718. times.push(
  21719. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21720. i,
  21721. ( i + 1 ) % numMorphTargets );
  21722. values.push( 0, 1, 0 );
  21723. var order = AnimationUtils.getKeyframeOrder( times );
  21724. times = AnimationUtils.sortedArray( times, 1, order );
  21725. values = AnimationUtils.sortedArray( values, 1, order );
  21726. // if there is a key at the first frame, duplicate it as the
  21727. // last frame as well for perfect loop.
  21728. if ( ! noLoop && times[ 0 ] === 0 ) {
  21729. times.push( numMorphTargets );
  21730. values.push( values[ 0 ] );
  21731. }
  21732. tracks.push(
  21733. new NumberKeyframeTrack(
  21734. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21735. times, values
  21736. ).scale( 1.0 / fps ) );
  21737. }
  21738. return new AnimationClip( name, - 1, tracks );
  21739. },
  21740. findByName: function ( objectOrClipArray, name ) {
  21741. var clipArray = objectOrClipArray;
  21742. if ( ! Array.isArray( objectOrClipArray ) ) {
  21743. var o = objectOrClipArray;
  21744. clipArray = o.geometry && o.geometry.animations || o.animations;
  21745. }
  21746. for ( var i = 0; i < clipArray.length; i ++ ) {
  21747. if ( clipArray[ i ].name === name ) {
  21748. return clipArray[ i ];
  21749. }
  21750. }
  21751. return null;
  21752. },
  21753. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21754. var animationToMorphTargets = {};
  21755. // tested with https://regex101.com/ on trick sequences
  21756. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21757. var pattern = /^([\w-]*?)([\d]+)$/;
  21758. // sort morph target names into animation groups based
  21759. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21760. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21761. var morphTarget = morphTargets[ i ];
  21762. var parts = morphTarget.name.match( pattern );
  21763. if ( parts && parts.length > 1 ) {
  21764. var name = parts[ 1 ];
  21765. var animationMorphTargets = animationToMorphTargets[ name ];
  21766. if ( ! animationMorphTargets ) {
  21767. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21768. }
  21769. animationMorphTargets.push( morphTarget );
  21770. }
  21771. }
  21772. var clips = [];
  21773. for ( var name$1 in animationToMorphTargets ) {
  21774. clips.push( AnimationClip.CreateFromMorphTargetSequence( name$1, animationToMorphTargets[ name$1 ], fps, noLoop ) );
  21775. }
  21776. return clips;
  21777. },
  21778. // parse the animation.hierarchy format
  21779. parseAnimation: function ( animation, bones ) {
  21780. if ( ! animation ) {
  21781. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21782. return null;
  21783. }
  21784. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21785. // only return track if there are actually keys.
  21786. if ( animationKeys.length !== 0 ) {
  21787. var times = [];
  21788. var values = [];
  21789. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21790. // empty keys are filtered out, so check again
  21791. if ( times.length !== 0 ) {
  21792. destTracks.push( new trackType( trackName, times, values ) );
  21793. }
  21794. }
  21795. };
  21796. var tracks = [];
  21797. var clipName = animation.name || 'default';
  21798. var fps = animation.fps || 30;
  21799. var blendMode = animation.blendMode;
  21800. // automatic length determination in AnimationClip.
  21801. var duration = animation.length || - 1;
  21802. var hierarchyTracks = animation.hierarchy || [];
  21803. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21804. var animationKeys = hierarchyTracks[ h ].keys;
  21805. // skip empty tracks
  21806. if ( ! animationKeys || animationKeys.length === 0 ) { continue; }
  21807. // process morph targets
  21808. if ( animationKeys[ 0 ].morphTargets ) {
  21809. // figure out all morph targets used in this track
  21810. var morphTargetNames = {};
  21811. var k = (void 0);
  21812. for ( k = 0; k < animationKeys.length; k ++ ) {
  21813. if ( animationKeys[ k ].morphTargets ) {
  21814. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21815. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21816. }
  21817. }
  21818. }
  21819. // create a track for each morph target with all zero
  21820. // morphTargetInfluences except for the keys in which
  21821. // the morphTarget is named.
  21822. for ( var morphTargetName in morphTargetNames ) {
  21823. var times = [];
  21824. var values = [];
  21825. for ( var m$1 = 0; m$1 !== animationKeys[ k ].morphTargets.length; ++ m$1 ) {
  21826. var animationKey = animationKeys[ k ];
  21827. times.push( animationKey.time );
  21828. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21829. }
  21830. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21831. }
  21832. duration = morphTargetNames.length * ( fps || 1.0 );
  21833. } else {
  21834. // ...assume skeletal animation
  21835. var boneName = '.bones[' + bones[ h ].name + ']';
  21836. addNonemptyTrack(
  21837. VectorKeyframeTrack, boneName + '.position',
  21838. animationKeys, 'pos', tracks );
  21839. addNonemptyTrack(
  21840. QuaternionKeyframeTrack, boneName + '.quaternion',
  21841. animationKeys, 'rot', tracks );
  21842. addNonemptyTrack(
  21843. VectorKeyframeTrack, boneName + '.scale',
  21844. animationKeys, 'scl', tracks );
  21845. }
  21846. }
  21847. if ( tracks.length === 0 ) {
  21848. return null;
  21849. }
  21850. var clip = new AnimationClip( clipName, duration, tracks, blendMode );
  21851. return clip;
  21852. }
  21853. } );
  21854. Object.assign( AnimationClip.prototype, {
  21855. resetDuration: function () {
  21856. var tracks = this.tracks;
  21857. var duration = 0;
  21858. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21859. var track = this.tracks[ i ];
  21860. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21861. }
  21862. this.duration = duration;
  21863. return this;
  21864. },
  21865. trim: function () {
  21866. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21867. this.tracks[ i ].trim( 0, this.duration );
  21868. }
  21869. return this;
  21870. },
  21871. validate: function () {
  21872. var valid = true;
  21873. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21874. valid = valid && this.tracks[ i ].validate();
  21875. }
  21876. return valid;
  21877. },
  21878. optimize: function () {
  21879. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21880. this.tracks[ i ].optimize();
  21881. }
  21882. return this;
  21883. },
  21884. clone: function () {
  21885. var tracks = [];
  21886. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21887. tracks.push( this.tracks[ i ].clone() );
  21888. }
  21889. return new AnimationClip( this.name, this.duration, tracks, this.blendMode );
  21890. }
  21891. } );
  21892. /**
  21893. * @author mrdoob / http://mrdoob.com/
  21894. */
  21895. var Cache = {
  21896. enabled: false,
  21897. files: {},
  21898. add: function ( key, file ) {
  21899. if ( this.enabled === false ) { return; }
  21900. // console.log( 'THREE.Cache', 'Adding key:', key );
  21901. this.files[ key ] = file;
  21902. },
  21903. get: function ( key ) {
  21904. if ( this.enabled === false ) { return; }
  21905. // console.log( 'THREE.Cache', 'Checking key:', key );
  21906. return this.files[ key ];
  21907. },
  21908. remove: function ( key ) {
  21909. delete this.files[ key ];
  21910. },
  21911. clear: function () {
  21912. this.files = {};
  21913. }
  21914. };
  21915. /**
  21916. * @author mrdoob / http://mrdoob.com/
  21917. */
  21918. function LoadingManager( onLoad, onProgress, onError ) {
  21919. var scope = this;
  21920. var isLoading = false;
  21921. var itemsLoaded = 0;
  21922. var itemsTotal = 0;
  21923. var urlModifier = undefined;
  21924. var handlers = [];
  21925. // Refer to #5689 for the reason why we don't set .onStart
  21926. // in the constructor
  21927. this.onStart = undefined;
  21928. this.onLoad = onLoad;
  21929. this.onProgress = onProgress;
  21930. this.onError = onError;
  21931. this.itemStart = function ( url ) {
  21932. itemsTotal ++;
  21933. if ( isLoading === false ) {
  21934. if ( scope.onStart !== undefined ) {
  21935. scope.onStart( url, itemsLoaded, itemsTotal );
  21936. }
  21937. }
  21938. isLoading = true;
  21939. };
  21940. this.itemEnd = function ( url ) {
  21941. itemsLoaded ++;
  21942. if ( scope.onProgress !== undefined ) {
  21943. scope.onProgress( url, itemsLoaded, itemsTotal );
  21944. }
  21945. if ( itemsLoaded === itemsTotal ) {
  21946. isLoading = false;
  21947. if ( scope.onLoad !== undefined ) {
  21948. scope.onLoad();
  21949. }
  21950. }
  21951. };
  21952. this.itemError = function ( url ) {
  21953. if ( scope.onError !== undefined ) {
  21954. scope.onError( url );
  21955. }
  21956. };
  21957. this.resolveURL = function ( url ) {
  21958. if ( urlModifier ) {
  21959. return urlModifier( url );
  21960. }
  21961. return url;
  21962. };
  21963. this.setURLModifier = function ( transform ) {
  21964. urlModifier = transform;
  21965. return this;
  21966. };
  21967. this.addHandler = function ( regex, loader ) {
  21968. handlers.push( regex, loader );
  21969. return this;
  21970. };
  21971. this.removeHandler = function ( regex ) {
  21972. var index = handlers.indexOf( regex );
  21973. if ( index !== - 1 ) {
  21974. handlers.splice( index, 2 );
  21975. }
  21976. return this;
  21977. };
  21978. this.getHandler = function ( file ) {
  21979. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21980. var regex = handlers[ i ];
  21981. var loader = handlers[ i + 1 ];
  21982. if ( regex.global ) { regex.lastIndex = 0; } // see #17920
  21983. if ( regex.test( file ) ) {
  21984. return loader;
  21985. }
  21986. }
  21987. return null;
  21988. };
  21989. }
  21990. var DefaultLoadingManager = new LoadingManager();
  21991. /**
  21992. * @author alteredq / http://alteredqualia.com/
  21993. */
  21994. function Loader( manager ) {
  21995. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21996. this.crossOrigin = 'anonymous';
  21997. this.path = '';
  21998. this.resourcePath = '';
  21999. this.requestHeader = {};
  22000. }
  22001. Object.assign( Loader.prototype, {
  22002. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  22003. loadAsync: function ( url, onProgress ) {
  22004. var scope = this;
  22005. return new Promise( function ( resolve, reject ) {
  22006. scope.load( url, resolve, onProgress, reject );
  22007. } );
  22008. },
  22009. parse: function ( /* data */ ) {},
  22010. setCrossOrigin: function ( crossOrigin ) {
  22011. this.crossOrigin = crossOrigin;
  22012. return this;
  22013. },
  22014. setPath: function ( path ) {
  22015. this.path = path;
  22016. return this;
  22017. },
  22018. setResourcePath: function ( resourcePath ) {
  22019. this.resourcePath = resourcePath;
  22020. return this;
  22021. },
  22022. setRequestHeader: function ( requestHeader ) {
  22023. this.requestHeader = requestHeader;
  22024. return this;
  22025. }
  22026. } );
  22027. /**
  22028. * @author mrdoob / http://mrdoob.com/
  22029. */
  22030. var loading = {};
  22031. function FileLoader( manager ) {
  22032. Loader.call( this, manager );
  22033. }
  22034. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22035. constructor: FileLoader,
  22036. load: function ( url, onLoad, onProgress, onError ) {
  22037. if ( url === undefined ) { url = ''; }
  22038. if ( this.path !== undefined ) { url = this.path + url; }
  22039. url = this.manager.resolveURL( url );
  22040. var scope = this;
  22041. var cached = Cache.get( url );
  22042. if ( cached !== undefined ) {
  22043. scope.manager.itemStart( url );
  22044. setTimeout( function () {
  22045. if ( onLoad ) { onLoad( cached ); }
  22046. scope.manager.itemEnd( url );
  22047. }, 0 );
  22048. return cached;
  22049. }
  22050. // Check if request is duplicate
  22051. if ( loading[ url ] !== undefined ) {
  22052. loading[ url ].push( {
  22053. onLoad: onLoad,
  22054. onProgress: onProgress,
  22055. onError: onError
  22056. } );
  22057. return;
  22058. }
  22059. // Check for data: URI
  22060. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  22061. var dataUriRegexResult = url.match( dataUriRegex );
  22062. var request;
  22063. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  22064. if ( dataUriRegexResult ) {
  22065. var mimeType = dataUriRegexResult[ 1 ];
  22066. var isBase64 = !! dataUriRegexResult[ 2 ];
  22067. var data = dataUriRegexResult[ 3 ];
  22068. data = decodeURIComponent( data );
  22069. if ( isBase64 ) { data = atob( data ); }
  22070. try {
  22071. var response;
  22072. var responseType = ( this.responseType || '' ).toLowerCase();
  22073. switch ( responseType ) {
  22074. case 'arraybuffer':
  22075. case 'blob':
  22076. var view = new Uint8Array( data.length );
  22077. for ( var i = 0; i < data.length; i ++ ) {
  22078. view[ i ] = data.charCodeAt( i );
  22079. }
  22080. if ( responseType === 'blob' ) {
  22081. response = new Blob( [ view.buffer ], { type: mimeType } );
  22082. } else {
  22083. response = view.buffer;
  22084. }
  22085. break;
  22086. case 'document':
  22087. var parser = new DOMParser();
  22088. response = parser.parseFromString( data, mimeType );
  22089. break;
  22090. case 'json':
  22091. response = JSON.parse( data );
  22092. break;
  22093. default: // 'text' or other
  22094. response = data;
  22095. break;
  22096. }
  22097. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22098. setTimeout( function () {
  22099. if ( onLoad ) { onLoad( response ); }
  22100. scope.manager.itemEnd( url );
  22101. }, 0 );
  22102. } catch ( error ) {
  22103. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22104. setTimeout( function () {
  22105. if ( onError ) { onError( error ); }
  22106. scope.manager.itemError( url );
  22107. scope.manager.itemEnd( url );
  22108. }, 0 );
  22109. }
  22110. } else {
  22111. // Initialise array for duplicate requests
  22112. loading[ url ] = [];
  22113. loading[ url ].push( {
  22114. onLoad: onLoad,
  22115. onProgress: onProgress,
  22116. onError: onError
  22117. } );
  22118. request = new XMLHttpRequest();
  22119. request.open( 'GET', url, true );
  22120. request.addEventListener( 'load', function ( event ) {
  22121. var response = this.response;
  22122. var callbacks = loading[ url ];
  22123. delete loading[ url ];
  22124. if ( this.status === 200 || this.status === 0 ) {
  22125. // Some browsers return HTTP Status 0 when using non-http protocol
  22126. // e.g. 'file://' or 'data://'. Handle as success.
  22127. if ( this.status === 0 ) { console.warn( 'THREE.FileLoader: HTTP Status 0 received.' ); }
  22128. // Add to cache only on HTTP success, so that we do not cache
  22129. // error response bodies as proper responses to requests.
  22130. Cache.add( url, response );
  22131. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  22132. var callback = callbacks[ i ];
  22133. if ( callback.onLoad ) { callback.onLoad( response ); }
  22134. }
  22135. scope.manager.itemEnd( url );
  22136. } else {
  22137. for ( var i$1 = 0, il$1 = callbacks.length; i$1 < il$1; i$1 ++ ) {
  22138. var callback$1 = callbacks[ i$1 ];
  22139. if ( callback$1.onError ) { callback$1.onError( event ); }
  22140. }
  22141. scope.manager.itemError( url );
  22142. scope.manager.itemEnd( url );
  22143. }
  22144. }, false );
  22145. request.addEventListener( 'progress', function ( event ) {
  22146. var callbacks = loading[ url ];
  22147. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  22148. var callback = callbacks[ i ];
  22149. if ( callback.onProgress ) { callback.onProgress( event ); }
  22150. }
  22151. }, false );
  22152. request.addEventListener( 'error', function ( event ) {
  22153. var callbacks = loading[ url ];
  22154. delete loading[ url ];
  22155. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  22156. var callback = callbacks[ i ];
  22157. if ( callback.onError ) { callback.onError( event ); }
  22158. }
  22159. scope.manager.itemError( url );
  22160. scope.manager.itemEnd( url );
  22161. }, false );
  22162. request.addEventListener( 'abort', function ( event ) {
  22163. var callbacks = loading[ url ];
  22164. delete loading[ url ];
  22165. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  22166. var callback = callbacks[ i ];
  22167. if ( callback.onError ) { callback.onError( event ); }
  22168. }
  22169. scope.manager.itemError( url );
  22170. scope.manager.itemEnd( url );
  22171. }, false );
  22172. if ( this.responseType !== undefined ) { request.responseType = this.responseType; }
  22173. if ( this.withCredentials !== undefined ) { request.withCredentials = this.withCredentials; }
  22174. if ( request.overrideMimeType ) { request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' ); }
  22175. for ( var header in this.requestHeader ) {
  22176. request.setRequestHeader( header, this.requestHeader[ header ] );
  22177. }
  22178. request.send( null );
  22179. }
  22180. scope.manager.itemStart( url );
  22181. return request;
  22182. },
  22183. setResponseType: function ( value ) {
  22184. this.responseType = value;
  22185. return this;
  22186. },
  22187. setWithCredentials: function ( value ) {
  22188. this.withCredentials = value;
  22189. return this;
  22190. },
  22191. setMimeType: function ( value ) {
  22192. this.mimeType = value;
  22193. return this;
  22194. }
  22195. } );
  22196. /**
  22197. * @author bhouston / http://clara.io/
  22198. */
  22199. function AnimationLoader( manager ) {
  22200. Loader.call( this, manager );
  22201. }
  22202. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22203. constructor: AnimationLoader,
  22204. load: function ( url, onLoad, onProgress, onError ) {
  22205. var scope = this;
  22206. var loader = new FileLoader( scope.manager );
  22207. loader.setPath( scope.path );
  22208. loader.load( url, function ( text ) {
  22209. try {
  22210. onLoad( scope.parse( JSON.parse( text ) ) );
  22211. } catch ( e ) {
  22212. if ( onError ) {
  22213. onError( e );
  22214. } else {
  22215. console.error( e );
  22216. }
  22217. scope.manager.itemError( url );
  22218. }
  22219. }, onProgress, onError );
  22220. },
  22221. parse: function ( json ) {
  22222. var animations = [];
  22223. for ( var i = 0; i < json.length; i ++ ) {
  22224. var clip = AnimationClip.parse( json[ i ] );
  22225. animations.push( clip );
  22226. }
  22227. return animations;
  22228. }
  22229. } );
  22230. /**
  22231. * @author mrdoob / http://mrdoob.com/
  22232. *
  22233. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22234. *
  22235. * Sub classes have to implement the parse() method which will be used in load().
  22236. */
  22237. function CompressedTextureLoader( manager ) {
  22238. Loader.call( this, manager );
  22239. }
  22240. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22241. constructor: CompressedTextureLoader,
  22242. load: function ( url, onLoad, onProgress, onError ) {
  22243. var scope = this;
  22244. var images = [];
  22245. var texture = new CompressedTexture();
  22246. texture.image = images;
  22247. var loader = new FileLoader( this.manager );
  22248. loader.setPath( this.path );
  22249. loader.setResponseType( 'arraybuffer' );
  22250. var loaded = 0;
  22251. function loadTexture( i ) {
  22252. loader.load( url[ i ], function ( buffer ) {
  22253. var texDatas = scope.parse( buffer, true );
  22254. images[ i ] = {
  22255. width: texDatas.width,
  22256. height: texDatas.height,
  22257. format: texDatas.format,
  22258. mipmaps: texDatas.mipmaps
  22259. };
  22260. loaded += 1;
  22261. if ( loaded === 6 ) {
  22262. if ( texDatas.mipmapCount === 1 )
  22263. { texture.minFilter = LinearFilter; }
  22264. texture.format = texDatas.format;
  22265. texture.needsUpdate = true;
  22266. if ( onLoad ) { onLoad( texture ); }
  22267. }
  22268. }, onProgress, onError );
  22269. }
  22270. if ( Array.isArray( url ) ) {
  22271. for ( var i = 0, il = url.length; i < il; ++ i ) {
  22272. loadTexture( i );
  22273. }
  22274. } else {
  22275. // compressed cubemap texture stored in a single DDS file
  22276. loader.load( url, function ( buffer ) {
  22277. var texDatas = scope.parse( buffer, true );
  22278. if ( texDatas.isCubemap ) {
  22279. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22280. for ( var f = 0; f < faces; f ++ ) {
  22281. images[ f ] = { mipmaps: [] };
  22282. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  22283. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  22284. images[ f ].format = texDatas.format;
  22285. images[ f ].width = texDatas.width;
  22286. images[ f ].height = texDatas.height;
  22287. }
  22288. }
  22289. } else {
  22290. texture.image.width = texDatas.width;
  22291. texture.image.height = texDatas.height;
  22292. texture.mipmaps = texDatas.mipmaps;
  22293. }
  22294. if ( texDatas.mipmapCount === 1 ) {
  22295. texture.minFilter = LinearFilter;
  22296. }
  22297. texture.format = texDatas.format;
  22298. texture.needsUpdate = true;
  22299. if ( onLoad ) { onLoad( texture ); }
  22300. }, onProgress, onError );
  22301. }
  22302. return texture;
  22303. }
  22304. } );
  22305. /**
  22306. * @author Nikos M. / https://github.com/foo123/
  22307. *
  22308. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22309. *
  22310. * Sub classes have to implement the parse() method which will be used in load().
  22311. */
  22312. function DataTextureLoader( manager ) {
  22313. Loader.call( this, manager );
  22314. }
  22315. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22316. constructor: DataTextureLoader,
  22317. load: function ( url, onLoad, onProgress, onError ) {
  22318. var scope = this;
  22319. var texture = new DataTexture();
  22320. var loader = new FileLoader( this.manager );
  22321. loader.setResponseType( 'arraybuffer' );
  22322. loader.setPath( this.path );
  22323. loader.load( url, function ( buffer ) {
  22324. var texData = scope.parse( buffer );
  22325. if ( ! texData ) { return; }
  22326. if ( texData.image !== undefined ) {
  22327. texture.image = texData.image;
  22328. } else if ( texData.data !== undefined ) {
  22329. texture.image.width = texData.width;
  22330. texture.image.height = texData.height;
  22331. texture.image.data = texData.data;
  22332. }
  22333. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22334. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22335. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22336. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22337. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22338. if ( texData.format !== undefined ) {
  22339. texture.format = texData.format;
  22340. }
  22341. if ( texData.type !== undefined ) {
  22342. texture.type = texData.type;
  22343. }
  22344. if ( texData.mipmaps !== undefined ) {
  22345. texture.mipmaps = texData.mipmaps;
  22346. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22347. }
  22348. if ( texData.mipmapCount === 1 ) {
  22349. texture.minFilter = LinearFilter;
  22350. }
  22351. texture.needsUpdate = true;
  22352. if ( onLoad ) { onLoad( texture, texData ); }
  22353. }, onProgress, onError );
  22354. return texture;
  22355. }
  22356. } );
  22357. /**
  22358. * @author mrdoob / http://mrdoob.com/
  22359. */
  22360. function ImageLoader( manager ) {
  22361. Loader.call( this, manager );
  22362. }
  22363. ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22364. constructor: ImageLoader,
  22365. load: function ( url, onLoad, onProgress, onError ) {
  22366. if ( this.path !== undefined ) { url = this.path + url; }
  22367. url = this.manager.resolveURL( url );
  22368. var scope = this;
  22369. var cached = Cache.get( url );
  22370. if ( cached !== undefined ) {
  22371. scope.manager.itemStart( url );
  22372. setTimeout( function () {
  22373. if ( onLoad ) { onLoad( cached ); }
  22374. scope.manager.itemEnd( url );
  22375. }, 0 );
  22376. return cached;
  22377. }
  22378. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  22379. function onImageLoad() {
  22380. image.removeEventListener( 'load', onImageLoad, false );
  22381. image.removeEventListener( 'error', onImageError, false );
  22382. Cache.add( url, this );
  22383. if ( onLoad ) { onLoad( this ); }
  22384. scope.manager.itemEnd( url );
  22385. }
  22386. function onImageError( event ) {
  22387. image.removeEventListener( 'load', onImageLoad, false );
  22388. image.removeEventListener( 'error', onImageError, false );
  22389. if ( onError ) { onError( event ); }
  22390. scope.manager.itemError( url );
  22391. scope.manager.itemEnd( url );
  22392. }
  22393. image.addEventListener( 'load', onImageLoad, false );
  22394. image.addEventListener( 'error', onImageError, false );
  22395. if ( url.substr( 0, 5 ) !== 'data:' ) {
  22396. if ( this.crossOrigin !== undefined ) { image.crossOrigin = this.crossOrigin; }
  22397. }
  22398. scope.manager.itemStart( url );
  22399. image.src = url;
  22400. return image;
  22401. }
  22402. } );
  22403. /**
  22404. * @author mrdoob / http://mrdoob.com/
  22405. */
  22406. function CubeTextureLoader( manager ) {
  22407. Loader.call( this, manager );
  22408. }
  22409. CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22410. constructor: CubeTextureLoader,
  22411. load: function ( urls, onLoad, onProgress, onError ) {
  22412. var texture = new CubeTexture();
  22413. var loader = new ImageLoader( this.manager );
  22414. loader.setCrossOrigin( this.crossOrigin );
  22415. loader.setPath( this.path );
  22416. var loaded = 0;
  22417. function loadTexture( i ) {
  22418. loader.load( urls[ i ], function ( image ) {
  22419. texture.images[ i ] = image;
  22420. loaded ++;
  22421. if ( loaded === 6 ) {
  22422. texture.needsUpdate = true;
  22423. if ( onLoad ) { onLoad( texture ); }
  22424. }
  22425. }, undefined, onError );
  22426. }
  22427. for ( var i = 0; i < urls.length; ++ i ) {
  22428. loadTexture( i );
  22429. }
  22430. return texture;
  22431. }
  22432. } );
  22433. /**
  22434. * @author mrdoob / http://mrdoob.com/
  22435. */
  22436. function TextureLoader( manager ) {
  22437. Loader.call( this, manager );
  22438. }
  22439. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22440. constructor: TextureLoader,
  22441. load: function ( url, onLoad, onProgress, onError ) {
  22442. var texture = new Texture();
  22443. var loader = new ImageLoader( this.manager );
  22444. loader.setCrossOrigin( this.crossOrigin );
  22445. loader.setPath( this.path );
  22446. loader.load( url, function ( image ) {
  22447. texture.image = image;
  22448. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22449. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  22450. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22451. texture.needsUpdate = true;
  22452. if ( onLoad !== undefined ) {
  22453. onLoad( texture );
  22454. }
  22455. }, onProgress, onError );
  22456. return texture;
  22457. }
  22458. } );
  22459. /**
  22460. * @author zz85 / http://www.lab4games.net/zz85/blog
  22461. * Extensible curve object
  22462. *
  22463. * Some common of curve methods:
  22464. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22465. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22466. * .getPoints(), .getSpacedPoints()
  22467. * .getLength()
  22468. * .updateArcLengths()
  22469. *
  22470. * This following curves inherit from THREE.Curve:
  22471. *
  22472. * -- 2D curves --
  22473. * THREE.ArcCurve
  22474. * THREE.CubicBezierCurve
  22475. * THREE.EllipseCurve
  22476. * THREE.LineCurve
  22477. * THREE.QuadraticBezierCurve
  22478. * THREE.SplineCurve
  22479. *
  22480. * -- 3D curves --
  22481. * THREE.CatmullRomCurve3
  22482. * THREE.CubicBezierCurve3
  22483. * THREE.LineCurve3
  22484. * THREE.QuadraticBezierCurve3
  22485. *
  22486. * A series of curves can be represented as a THREE.CurvePath.
  22487. *
  22488. **/
  22489. /**************************************************************
  22490. * Abstract Curve base class
  22491. **************************************************************/
  22492. function Curve() {
  22493. this.type = 'Curve';
  22494. this.arcLengthDivisions = 200;
  22495. }
  22496. Object.assign( Curve.prototype, {
  22497. // Virtual base class method to overwrite and implement in subclasses
  22498. // - t [0 .. 1]
  22499. getPoint: function ( /* t, optionalTarget */ ) {
  22500. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  22501. return null;
  22502. },
  22503. // Get point at relative position in curve according to arc length
  22504. // - u [0 .. 1]
  22505. getPointAt: function ( u, optionalTarget ) {
  22506. var t = this.getUtoTmapping( u );
  22507. return this.getPoint( t, optionalTarget );
  22508. },
  22509. // Get sequence of points using getPoint( t )
  22510. getPoints: function ( divisions ) {
  22511. if ( divisions === undefined ) { divisions = 5; }
  22512. var points = [];
  22513. for ( var d = 0; d <= divisions; d ++ ) {
  22514. points.push( this.getPoint( d / divisions ) );
  22515. }
  22516. return points;
  22517. },
  22518. // Get sequence of points using getPointAt( u )
  22519. getSpacedPoints: function ( divisions ) {
  22520. if ( divisions === undefined ) { divisions = 5; }
  22521. var points = [];
  22522. for ( var d = 0; d <= divisions; d ++ ) {
  22523. points.push( this.getPointAt( d / divisions ) );
  22524. }
  22525. return points;
  22526. },
  22527. // Get total curve arc length
  22528. getLength: function () {
  22529. var lengths = this.getLengths();
  22530. return lengths[ lengths.length - 1 ];
  22531. },
  22532. // Get list of cumulative segment lengths
  22533. getLengths: function ( divisions ) {
  22534. if ( divisions === undefined ) { divisions = this.arcLengthDivisions; }
  22535. if ( this.cacheArcLengths &&
  22536. ( this.cacheArcLengths.length === divisions + 1 ) &&
  22537. ! this.needsUpdate ) {
  22538. return this.cacheArcLengths;
  22539. }
  22540. this.needsUpdate = false;
  22541. var cache = [];
  22542. var current, last = this.getPoint( 0 );
  22543. var sum = 0;
  22544. cache.push( 0 );
  22545. for ( var p = 1; p <= divisions; p ++ ) {
  22546. current = this.getPoint( p / divisions );
  22547. sum += current.distanceTo( last );
  22548. cache.push( sum );
  22549. last = current;
  22550. }
  22551. this.cacheArcLengths = cache;
  22552. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22553. },
  22554. updateArcLengths: function () {
  22555. this.needsUpdate = true;
  22556. this.getLengths();
  22557. },
  22558. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22559. getUtoTmapping: function ( u, distance ) {
  22560. var arcLengths = this.getLengths();
  22561. var i = 0, il = arcLengths.length;
  22562. var targetArcLength; // The targeted u distance value to get
  22563. if ( distance ) {
  22564. targetArcLength = distance;
  22565. } else {
  22566. targetArcLength = u * arcLengths[ il - 1 ];
  22567. }
  22568. // binary search for the index with largest value smaller than target u distance
  22569. var low = 0, high = il - 1, comparison;
  22570. while ( low <= high ) {
  22571. 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
  22572. comparison = arcLengths[ i ] - targetArcLength;
  22573. if ( comparison < 0 ) {
  22574. low = i + 1;
  22575. } else if ( comparison > 0 ) {
  22576. high = i - 1;
  22577. } else {
  22578. high = i;
  22579. break;
  22580. // DONE
  22581. }
  22582. }
  22583. i = high;
  22584. if ( arcLengths[ i ] === targetArcLength ) {
  22585. return i / ( il - 1 );
  22586. }
  22587. // we could get finer grain at lengths, or use simple interpolation between two points
  22588. var lengthBefore = arcLengths[ i ];
  22589. var lengthAfter = arcLengths[ i + 1 ];
  22590. var segmentLength = lengthAfter - lengthBefore;
  22591. // determine where we are between the 'before' and 'after' points
  22592. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  22593. // add that fractional amount to t
  22594. var t = ( i + segmentFraction ) / ( il - 1 );
  22595. return t;
  22596. },
  22597. // Returns a unit vector tangent at t
  22598. // In case any sub curve does not implement its tangent derivation,
  22599. // 2 points a small delta apart will be used to find its gradient
  22600. // which seems to give a reasonable approximation
  22601. getTangent: function ( t, optionalTarget ) {
  22602. var delta = 0.0001;
  22603. var t1 = t - delta;
  22604. var t2 = t + delta;
  22605. // Capping in case of danger
  22606. if ( t1 < 0 ) { t1 = 0; }
  22607. if ( t2 > 1 ) { t2 = 1; }
  22608. var pt1 = this.getPoint( t1 );
  22609. var pt2 = this.getPoint( t2 );
  22610. var tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  22611. tangent.copy( pt2 ).sub( pt1 ).normalize();
  22612. return tangent;
  22613. },
  22614. getTangentAt: function ( u, optionalTarget ) {
  22615. var t = this.getUtoTmapping( u );
  22616. return this.getTangent( t, optionalTarget );
  22617. },
  22618. computeFrenetFrames: function ( segments, closed ) {
  22619. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22620. var normal = new Vector3();
  22621. var tangents = [];
  22622. var normals = [];
  22623. var binormals = [];
  22624. var vec = new Vector3();
  22625. var mat = new Matrix4();
  22626. // compute the tangent vectors for each segment on the curve
  22627. for ( var i = 0; i <= segments; i ++ ) {
  22628. var u = i / segments;
  22629. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  22630. tangents[ i ].normalize();
  22631. }
  22632. // select an initial normal vector perpendicular to the first tangent vector,
  22633. // and in the direction of the minimum tangent xyz component
  22634. normals[ 0 ] = new Vector3();
  22635. binormals[ 0 ] = new Vector3();
  22636. var min = Number.MAX_VALUE;
  22637. var tx = Math.abs( tangents[ 0 ].x );
  22638. var ty = Math.abs( tangents[ 0 ].y );
  22639. var tz = Math.abs( tangents[ 0 ].z );
  22640. if ( tx <= min ) {
  22641. min = tx;
  22642. normal.set( 1, 0, 0 );
  22643. }
  22644. if ( ty <= min ) {
  22645. min = ty;
  22646. normal.set( 0, 1, 0 );
  22647. }
  22648. if ( tz <= min ) {
  22649. normal.set( 0, 0, 1 );
  22650. }
  22651. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22652. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22653. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22654. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22655. for ( var i$1 = 1; i$1 <= segments; i$1 ++ ) {
  22656. normals[ i$1 ] = normals[ i$1 - 1 ].clone();
  22657. binormals[ i$1 ] = binormals[ i$1 - 1 ].clone();
  22658. vec.crossVectors( tangents[ i$1 - 1 ], tangents[ i$1 ] );
  22659. if ( vec.length() > Number.EPSILON ) {
  22660. vec.normalize();
  22661. var theta = Math.acos( MathUtils.clamp( tangents[ i$1 - 1 ].dot( tangents[ i$1 ] ), - 1, 1 ) ); // clamp for floating pt errors
  22662. normals[ i$1 ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22663. }
  22664. binormals[ i$1 ].crossVectors( tangents[ i$1 ], normals[ i$1 ] );
  22665. }
  22666. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22667. if ( closed === true ) {
  22668. var theta$1 = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  22669. theta$1 /= segments;
  22670. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  22671. theta$1 = - theta$1;
  22672. }
  22673. for ( var i$2 = 1; i$2 <= segments; i$2 ++ ) {
  22674. // twist a little...
  22675. normals[ i$2 ].applyMatrix4( mat.makeRotationAxis( tangents[ i$2 ], theta$1 * i$2 ) );
  22676. binormals[ i$2 ].crossVectors( tangents[ i$2 ], normals[ i$2 ] );
  22677. }
  22678. }
  22679. return {
  22680. tangents: tangents,
  22681. normals: normals,
  22682. binormals: binormals
  22683. };
  22684. },
  22685. clone: function () {
  22686. return new this.constructor().copy( this );
  22687. },
  22688. copy: function ( source ) {
  22689. this.arcLengthDivisions = source.arcLengthDivisions;
  22690. return this;
  22691. },
  22692. toJSON: function () {
  22693. var data = {
  22694. metadata: {
  22695. version: 4.5,
  22696. type: 'Curve',
  22697. generator: 'Curve.toJSON'
  22698. }
  22699. };
  22700. data.arcLengthDivisions = this.arcLengthDivisions;
  22701. data.type = this.type;
  22702. return data;
  22703. },
  22704. fromJSON: function ( json ) {
  22705. this.arcLengthDivisions = json.arcLengthDivisions;
  22706. return this;
  22707. }
  22708. } );
  22709. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22710. Curve.call( this );
  22711. this.type = 'EllipseCurve';
  22712. this.aX = aX || 0;
  22713. this.aY = aY || 0;
  22714. this.xRadius = xRadius || 1;
  22715. this.yRadius = yRadius || 1;
  22716. this.aStartAngle = aStartAngle || 0;
  22717. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22718. this.aClockwise = aClockwise || false;
  22719. this.aRotation = aRotation || 0;
  22720. }
  22721. EllipseCurve.prototype = Object.create( Curve.prototype );
  22722. EllipseCurve.prototype.constructor = EllipseCurve;
  22723. EllipseCurve.prototype.isEllipseCurve = true;
  22724. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22725. var point = optionalTarget || new Vector2();
  22726. var twoPi = Math.PI * 2;
  22727. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22728. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  22729. // ensures that deltaAngle is 0 .. 2 PI
  22730. while ( deltaAngle < 0 ) { deltaAngle += twoPi; }
  22731. while ( deltaAngle > twoPi ) { deltaAngle -= twoPi; }
  22732. if ( deltaAngle < Number.EPSILON ) {
  22733. if ( samePoints ) {
  22734. deltaAngle = 0;
  22735. } else {
  22736. deltaAngle = twoPi;
  22737. }
  22738. }
  22739. if ( this.aClockwise === true && ! samePoints ) {
  22740. if ( deltaAngle === twoPi ) {
  22741. deltaAngle = - twoPi;
  22742. } else {
  22743. deltaAngle = deltaAngle - twoPi;
  22744. }
  22745. }
  22746. var angle = this.aStartAngle + t * deltaAngle;
  22747. var x = this.aX + this.xRadius * Math.cos( angle );
  22748. var y = this.aY + this.yRadius * Math.sin( angle );
  22749. if ( this.aRotation !== 0 ) {
  22750. var cos = Math.cos( this.aRotation );
  22751. var sin = Math.sin( this.aRotation );
  22752. var tx = x - this.aX;
  22753. var ty = y - this.aY;
  22754. // Rotate the point about the center of the ellipse.
  22755. x = tx * cos - ty * sin + this.aX;
  22756. y = tx * sin + ty * cos + this.aY;
  22757. }
  22758. return point.set( x, y );
  22759. };
  22760. EllipseCurve.prototype.copy = function ( source ) {
  22761. Curve.prototype.copy.call( this, source );
  22762. this.aX = source.aX;
  22763. this.aY = source.aY;
  22764. this.xRadius = source.xRadius;
  22765. this.yRadius = source.yRadius;
  22766. this.aStartAngle = source.aStartAngle;
  22767. this.aEndAngle = source.aEndAngle;
  22768. this.aClockwise = source.aClockwise;
  22769. this.aRotation = source.aRotation;
  22770. return this;
  22771. };
  22772. EllipseCurve.prototype.toJSON = function () {
  22773. var data = Curve.prototype.toJSON.call( this );
  22774. data.aX = this.aX;
  22775. data.aY = this.aY;
  22776. data.xRadius = this.xRadius;
  22777. data.yRadius = this.yRadius;
  22778. data.aStartAngle = this.aStartAngle;
  22779. data.aEndAngle = this.aEndAngle;
  22780. data.aClockwise = this.aClockwise;
  22781. data.aRotation = this.aRotation;
  22782. return data;
  22783. };
  22784. EllipseCurve.prototype.fromJSON = function ( json ) {
  22785. Curve.prototype.fromJSON.call( this, json );
  22786. this.aX = json.aX;
  22787. this.aY = json.aY;
  22788. this.xRadius = json.xRadius;
  22789. this.yRadius = json.yRadius;
  22790. this.aStartAngle = json.aStartAngle;
  22791. this.aEndAngle = json.aEndAngle;
  22792. this.aClockwise = json.aClockwise;
  22793. this.aRotation = json.aRotation;
  22794. return this;
  22795. };
  22796. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22797. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22798. this.type = 'ArcCurve';
  22799. }
  22800. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  22801. ArcCurve.prototype.constructor = ArcCurve;
  22802. ArcCurve.prototype.isArcCurve = true;
  22803. /**
  22804. * @author zz85 https://github.com/zz85
  22805. *
  22806. * Centripetal CatmullRom Curve - which is useful for avoiding
  22807. * cusps and self-intersections in non-uniform catmull rom curves.
  22808. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22809. *
  22810. * curve.type accepts centripetal(default), chordal and catmullrom
  22811. * curve.tension is used for catmullrom which defaults to 0.5
  22812. */
  22813. /*
  22814. Based on an optimized c++ solution in
  22815. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22816. - http://ideone.com/NoEbVM
  22817. This CubicPoly class could be used for reusing some variables and calculations,
  22818. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22819. which can be placed in CurveUtils.
  22820. */
  22821. function CubicPoly() {
  22822. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  22823. /*
  22824. * Compute coefficients for a cubic polynomial
  22825. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22826. * such that
  22827. * p(0) = x0, p(1) = x1
  22828. * and
  22829. * p'(0) = t0, p'(1) = t1.
  22830. */
  22831. function init( x0, x1, t0, t1 ) {
  22832. c0 = x0;
  22833. c1 = t0;
  22834. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  22835. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22836. }
  22837. return {
  22838. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  22839. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  22840. },
  22841. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  22842. // compute tangents when parameterized in [t1,t2]
  22843. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  22844. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  22845. // rescale tangents for parametrization in [0,1]
  22846. t1 *= dt1;
  22847. t2 *= dt1;
  22848. init( x1, x2, t1, t2 );
  22849. },
  22850. calc: function ( t ) {
  22851. var t2 = t * t;
  22852. var t3 = t2 * t;
  22853. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22854. }
  22855. };
  22856. }
  22857. //
  22858. var tmp = new Vector3();
  22859. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  22860. function CatmullRomCurve3( points, closed, curveType, tension ) {
  22861. Curve.call( this );
  22862. this.type = 'CatmullRomCurve3';
  22863. this.points = points || [];
  22864. this.closed = closed || false;
  22865. this.curveType = curveType || 'centripetal';
  22866. this.tension = tension || 0.5;
  22867. }
  22868. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  22869. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22870. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22871. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22872. var point = optionalTarget || new Vector3();
  22873. var points = this.points;
  22874. var l = points.length;
  22875. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  22876. var intPoint = Math.floor( p );
  22877. var weight = p - intPoint;
  22878. if ( this.closed ) {
  22879. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  22880. } else if ( weight === 0 && intPoint === l - 1 ) {
  22881. intPoint = l - 2;
  22882. weight = 1;
  22883. }
  22884. var p0, p1, p2, p3; // 4 points
  22885. if ( this.closed || intPoint > 0 ) {
  22886. p0 = points[ ( intPoint - 1 ) % l ];
  22887. } else {
  22888. // extrapolate first point
  22889. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  22890. p0 = tmp;
  22891. }
  22892. p1 = points[ intPoint % l ];
  22893. p2 = points[ ( intPoint + 1 ) % l ];
  22894. if ( this.closed || intPoint + 2 < l ) {
  22895. p3 = points[ ( intPoint + 2 ) % l ];
  22896. } else {
  22897. // extrapolate last point
  22898. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  22899. p3 = tmp;
  22900. }
  22901. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  22902. // init Centripetal / Chordal Catmull-Rom
  22903. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22904. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  22905. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  22906. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  22907. // safety check for repeated points
  22908. if ( dt1 < 1e-4 ) { dt1 = 1.0; }
  22909. if ( dt0 < 1e-4 ) { dt0 = dt1; }
  22910. if ( dt2 < 1e-4 ) { dt2 = dt1; }
  22911. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  22912. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  22913. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  22914. } else if ( this.curveType === 'catmullrom' ) {
  22915. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  22916. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  22917. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  22918. }
  22919. point.set(
  22920. px.calc( weight ),
  22921. py.calc( weight ),
  22922. pz.calc( weight )
  22923. );
  22924. return point;
  22925. };
  22926. CatmullRomCurve3.prototype.copy = function ( source ) {
  22927. Curve.prototype.copy.call( this, source );
  22928. this.points = [];
  22929. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22930. var point = source.points[ i ];
  22931. this.points.push( point.clone() );
  22932. }
  22933. this.closed = source.closed;
  22934. this.curveType = source.curveType;
  22935. this.tension = source.tension;
  22936. return this;
  22937. };
  22938. CatmullRomCurve3.prototype.toJSON = function () {
  22939. var data = Curve.prototype.toJSON.call( this );
  22940. data.points = [];
  22941. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22942. var point = this.points[ i ];
  22943. data.points.push( point.toArray() );
  22944. }
  22945. data.closed = this.closed;
  22946. data.curveType = this.curveType;
  22947. data.tension = this.tension;
  22948. return data;
  22949. };
  22950. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  22951. Curve.prototype.fromJSON.call( this, json );
  22952. this.points = [];
  22953. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22954. var point = json.points[ i ];
  22955. this.points.push( new Vector3().fromArray( point ) );
  22956. }
  22957. this.closed = json.closed;
  22958. this.curveType = json.curveType;
  22959. this.tension = json.tension;
  22960. return this;
  22961. };
  22962. /**
  22963. * @author zz85 / http://www.lab4games.net/zz85/blog
  22964. *
  22965. * Bezier Curves formulas obtained from
  22966. * http://en.wikipedia.org/wiki/Bézier_curve
  22967. */
  22968. function CatmullRom( t, p0, p1, p2, p3 ) {
  22969. var v0 = ( p2 - p0 ) * 0.5;
  22970. var v1 = ( p3 - p1 ) * 0.5;
  22971. var t2 = t * t;
  22972. var t3 = t * t2;
  22973. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  22974. }
  22975. //
  22976. function QuadraticBezierP0( t, p ) {
  22977. var k = 1 - t;
  22978. return k * k * p;
  22979. }
  22980. function QuadraticBezierP1( t, p ) {
  22981. return 2 * ( 1 - t ) * t * p;
  22982. }
  22983. function QuadraticBezierP2( t, p ) {
  22984. return t * t * p;
  22985. }
  22986. function QuadraticBezier( t, p0, p1, p2 ) {
  22987. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  22988. QuadraticBezierP2( t, p2 );
  22989. }
  22990. //
  22991. function CubicBezierP0( t, p ) {
  22992. var k = 1 - t;
  22993. return k * k * k * p;
  22994. }
  22995. function CubicBezierP1( t, p ) {
  22996. var k = 1 - t;
  22997. return 3 * k * k * t * p;
  22998. }
  22999. function CubicBezierP2( t, p ) {
  23000. return 3 * ( 1 - t ) * t * t * p;
  23001. }
  23002. function CubicBezierP3( t, p ) {
  23003. return t * t * t * p;
  23004. }
  23005. function CubicBezier( t, p0, p1, p2, p3 ) {
  23006. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  23007. CubicBezierP3( t, p3 );
  23008. }
  23009. function CubicBezierCurve( v0, v1, v2, v3 ) {
  23010. Curve.call( this );
  23011. this.type = 'CubicBezierCurve';
  23012. this.v0 = v0 || new Vector2();
  23013. this.v1 = v1 || new Vector2();
  23014. this.v2 = v2 || new Vector2();
  23015. this.v3 = v3 || new Vector2();
  23016. }
  23017. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  23018. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  23019. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  23020. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23021. var point = optionalTarget || new Vector2();
  23022. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  23023. point.set(
  23024. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  23025. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  23026. );
  23027. return point;
  23028. };
  23029. CubicBezierCurve.prototype.copy = function ( source ) {
  23030. Curve.prototype.copy.call( this, source );
  23031. this.v0.copy( source.v0 );
  23032. this.v1.copy( source.v1 );
  23033. this.v2.copy( source.v2 );
  23034. this.v3.copy( source.v3 );
  23035. return this;
  23036. };
  23037. CubicBezierCurve.prototype.toJSON = function () {
  23038. var data = Curve.prototype.toJSON.call( this );
  23039. data.v0 = this.v0.toArray();
  23040. data.v1 = this.v1.toArray();
  23041. data.v2 = this.v2.toArray();
  23042. data.v3 = this.v3.toArray();
  23043. return data;
  23044. };
  23045. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  23046. Curve.prototype.fromJSON.call( this, json );
  23047. this.v0.fromArray( json.v0 );
  23048. this.v1.fromArray( json.v1 );
  23049. this.v2.fromArray( json.v2 );
  23050. this.v3.fromArray( json.v3 );
  23051. return this;
  23052. };
  23053. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  23054. Curve.call( this );
  23055. this.type = 'CubicBezierCurve3';
  23056. this.v0 = v0 || new Vector3();
  23057. this.v1 = v1 || new Vector3();
  23058. this.v2 = v2 || new Vector3();
  23059. this.v3 = v3 || new Vector3();
  23060. }
  23061. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  23062. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  23063. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  23064. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  23065. var point = optionalTarget || new Vector3();
  23066. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  23067. point.set(
  23068. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  23069. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  23070. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  23071. );
  23072. return point;
  23073. };
  23074. CubicBezierCurve3.prototype.copy = function ( source ) {
  23075. Curve.prototype.copy.call( this, source );
  23076. this.v0.copy( source.v0 );
  23077. this.v1.copy( source.v1 );
  23078. this.v2.copy( source.v2 );
  23079. this.v3.copy( source.v3 );
  23080. return this;
  23081. };
  23082. CubicBezierCurve3.prototype.toJSON = function () {
  23083. var data = Curve.prototype.toJSON.call( this );
  23084. data.v0 = this.v0.toArray();
  23085. data.v1 = this.v1.toArray();
  23086. data.v2 = this.v2.toArray();
  23087. data.v3 = this.v3.toArray();
  23088. return data;
  23089. };
  23090. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  23091. Curve.prototype.fromJSON.call( this, json );
  23092. this.v0.fromArray( json.v0 );
  23093. this.v1.fromArray( json.v1 );
  23094. this.v2.fromArray( json.v2 );
  23095. this.v3.fromArray( json.v3 );
  23096. return this;
  23097. };
  23098. function LineCurve( v1, v2 ) {
  23099. Curve.call( this );
  23100. this.type = 'LineCurve';
  23101. this.v1 = v1 || new Vector2();
  23102. this.v2 = v2 || new Vector2();
  23103. }
  23104. LineCurve.prototype = Object.create( Curve.prototype );
  23105. LineCurve.prototype.constructor = LineCurve;
  23106. LineCurve.prototype.isLineCurve = true;
  23107. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23108. var point = optionalTarget || new Vector2();
  23109. if ( t === 1 ) {
  23110. point.copy( this.v2 );
  23111. } else {
  23112. point.copy( this.v2 ).sub( this.v1 );
  23113. point.multiplyScalar( t ).add( this.v1 );
  23114. }
  23115. return point;
  23116. };
  23117. // Line curve is linear, so we can overwrite default getPointAt
  23118. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  23119. return this.getPoint( u, optionalTarget );
  23120. };
  23121. LineCurve.prototype.getTangent = function ( t, optionalTarget ) {
  23122. var tangent = optionalTarget || new Vector2();
  23123. tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  23124. return tangent;
  23125. };
  23126. LineCurve.prototype.copy = function ( source ) {
  23127. Curve.prototype.copy.call( this, source );
  23128. this.v1.copy( source.v1 );
  23129. this.v2.copy( source.v2 );
  23130. return this;
  23131. };
  23132. LineCurve.prototype.toJSON = function () {
  23133. var data = Curve.prototype.toJSON.call( this );
  23134. data.v1 = this.v1.toArray();
  23135. data.v2 = this.v2.toArray();
  23136. return data;
  23137. };
  23138. LineCurve.prototype.fromJSON = function ( json ) {
  23139. Curve.prototype.fromJSON.call( this, json );
  23140. this.v1.fromArray( json.v1 );
  23141. this.v2.fromArray( json.v2 );
  23142. return this;
  23143. };
  23144. function LineCurve3( v1, v2 ) {
  23145. Curve.call( this );
  23146. this.type = 'LineCurve3';
  23147. this.v1 = v1 || new Vector3();
  23148. this.v2 = v2 || new Vector3();
  23149. }
  23150. LineCurve3.prototype = Object.create( Curve.prototype );
  23151. LineCurve3.prototype.constructor = LineCurve3;
  23152. LineCurve3.prototype.isLineCurve3 = true;
  23153. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  23154. var point = optionalTarget || new Vector3();
  23155. if ( t === 1 ) {
  23156. point.copy( this.v2 );
  23157. } else {
  23158. point.copy( this.v2 ).sub( this.v1 );
  23159. point.multiplyScalar( t ).add( this.v1 );
  23160. }
  23161. return point;
  23162. };
  23163. // Line curve is linear, so we can overwrite default getPointAt
  23164. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  23165. return this.getPoint( u, optionalTarget );
  23166. };
  23167. LineCurve3.prototype.copy = function ( source ) {
  23168. Curve.prototype.copy.call( this, source );
  23169. this.v1.copy( source.v1 );
  23170. this.v2.copy( source.v2 );
  23171. return this;
  23172. };
  23173. LineCurve3.prototype.toJSON = function () {
  23174. var data = Curve.prototype.toJSON.call( this );
  23175. data.v1 = this.v1.toArray();
  23176. data.v2 = this.v2.toArray();
  23177. return data;
  23178. };
  23179. LineCurve3.prototype.fromJSON = function ( json ) {
  23180. Curve.prototype.fromJSON.call( this, json );
  23181. this.v1.fromArray( json.v1 );
  23182. this.v2.fromArray( json.v2 );
  23183. return this;
  23184. };
  23185. function QuadraticBezierCurve( v0, v1, v2 ) {
  23186. Curve.call( this );
  23187. this.type = 'QuadraticBezierCurve';
  23188. this.v0 = v0 || new Vector2();
  23189. this.v1 = v1 || new Vector2();
  23190. this.v2 = v2 || new Vector2();
  23191. }
  23192. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  23193. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  23194. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23195. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23196. var point = optionalTarget || new Vector2();
  23197. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  23198. point.set(
  23199. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  23200. QuadraticBezier( t, v0.y, v1.y, v2.y )
  23201. );
  23202. return point;
  23203. };
  23204. QuadraticBezierCurve.prototype.copy = function ( source ) {
  23205. Curve.prototype.copy.call( this, source );
  23206. this.v0.copy( source.v0 );
  23207. this.v1.copy( source.v1 );
  23208. this.v2.copy( source.v2 );
  23209. return this;
  23210. };
  23211. QuadraticBezierCurve.prototype.toJSON = function () {
  23212. var data = Curve.prototype.toJSON.call( this );
  23213. data.v0 = this.v0.toArray();
  23214. data.v1 = this.v1.toArray();
  23215. data.v2 = this.v2.toArray();
  23216. return data;
  23217. };
  23218. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  23219. Curve.prototype.fromJSON.call( this, json );
  23220. this.v0.fromArray( json.v0 );
  23221. this.v1.fromArray( json.v1 );
  23222. this.v2.fromArray( json.v2 );
  23223. return this;
  23224. };
  23225. function QuadraticBezierCurve3( v0, v1, v2 ) {
  23226. Curve.call( this );
  23227. this.type = 'QuadraticBezierCurve3';
  23228. this.v0 = v0 || new Vector3();
  23229. this.v1 = v1 || new Vector3();
  23230. this.v2 = v2 || new Vector3();
  23231. }
  23232. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  23233. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  23234. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23235. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  23236. var point = optionalTarget || new Vector3();
  23237. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  23238. point.set(
  23239. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  23240. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  23241. QuadraticBezier( t, v0.z, v1.z, v2.z )
  23242. );
  23243. return point;
  23244. };
  23245. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  23246. Curve.prototype.copy.call( this, source );
  23247. this.v0.copy( source.v0 );
  23248. this.v1.copy( source.v1 );
  23249. this.v2.copy( source.v2 );
  23250. return this;
  23251. };
  23252. QuadraticBezierCurve3.prototype.toJSON = function () {
  23253. var data = Curve.prototype.toJSON.call( this );
  23254. data.v0 = this.v0.toArray();
  23255. data.v1 = this.v1.toArray();
  23256. data.v2 = this.v2.toArray();
  23257. return data;
  23258. };
  23259. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  23260. Curve.prototype.fromJSON.call( this, json );
  23261. this.v0.fromArray( json.v0 );
  23262. this.v1.fromArray( json.v1 );
  23263. this.v2.fromArray( json.v2 );
  23264. return this;
  23265. };
  23266. function SplineCurve( points /* array of Vector2 */ ) {
  23267. Curve.call( this );
  23268. this.type = 'SplineCurve';
  23269. this.points = points || [];
  23270. }
  23271. SplineCurve.prototype = Object.create( Curve.prototype );
  23272. SplineCurve.prototype.constructor = SplineCurve;
  23273. SplineCurve.prototype.isSplineCurve = true;
  23274. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23275. var point = optionalTarget || new Vector2();
  23276. var points = this.points;
  23277. var p = ( points.length - 1 ) * t;
  23278. var intPoint = Math.floor( p );
  23279. var weight = p - intPoint;
  23280. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  23281. var p1 = points[ intPoint ];
  23282. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  23283. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  23284. point.set(
  23285. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  23286. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  23287. );
  23288. return point;
  23289. };
  23290. SplineCurve.prototype.copy = function ( source ) {
  23291. Curve.prototype.copy.call( this, source );
  23292. this.points = [];
  23293. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  23294. var point = source.points[ i ];
  23295. this.points.push( point.clone() );
  23296. }
  23297. return this;
  23298. };
  23299. SplineCurve.prototype.toJSON = function () {
  23300. var data = Curve.prototype.toJSON.call( this );
  23301. data.points = [];
  23302. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  23303. var point = this.points[ i ];
  23304. data.points.push( point.toArray() );
  23305. }
  23306. return data;
  23307. };
  23308. SplineCurve.prototype.fromJSON = function ( json ) {
  23309. Curve.prototype.fromJSON.call( this, json );
  23310. this.points = [];
  23311. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  23312. var point = json.points[ i ];
  23313. this.points.push( new Vector2().fromArray( point ) );
  23314. }
  23315. return this;
  23316. };
  23317. var Curves = /*#__PURE__*/Object.freeze({
  23318. __proto__: null,
  23319. ArcCurve: ArcCurve,
  23320. CatmullRomCurve3: CatmullRomCurve3,
  23321. CubicBezierCurve: CubicBezierCurve,
  23322. CubicBezierCurve3: CubicBezierCurve3,
  23323. EllipseCurve: EllipseCurve,
  23324. LineCurve: LineCurve,
  23325. LineCurve3: LineCurve3,
  23326. QuadraticBezierCurve: QuadraticBezierCurve,
  23327. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23328. SplineCurve: SplineCurve
  23329. });
  23330. /**
  23331. * @author zz85 / http://www.lab4games.net/zz85/blog
  23332. *
  23333. **/
  23334. /**************************************************************
  23335. * Curved Path - a curve path is simply a array of connected
  23336. * curves, but retains the api of a curve
  23337. **************************************************************/
  23338. function CurvePath() {
  23339. Curve.call( this );
  23340. this.type = 'CurvePath';
  23341. this.curves = [];
  23342. this.autoClose = false; // Automatically closes the path
  23343. }
  23344. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  23345. constructor: CurvePath,
  23346. add: function ( curve ) {
  23347. this.curves.push( curve );
  23348. },
  23349. closePath: function () {
  23350. // Add a line curve if start and end of lines are not connected
  23351. var startPoint = this.curves[ 0 ].getPoint( 0 );
  23352. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  23353. if ( ! startPoint.equals( endPoint ) ) {
  23354. this.curves.push( new LineCurve( endPoint, startPoint ) );
  23355. }
  23356. },
  23357. // To get accurate point with reference to
  23358. // entire path distance at time t,
  23359. // following has to be done:
  23360. // 1. Length of each sub path have to be known
  23361. // 2. Locate and identify type of curve
  23362. // 3. Get t for the curve
  23363. // 4. Return curve.getPointAt(t')
  23364. getPoint: function ( t ) {
  23365. var d = t * this.getLength();
  23366. var curveLengths = this.getCurveLengths();
  23367. var i = 0;
  23368. // To think about boundaries points.
  23369. while ( i < curveLengths.length ) {
  23370. if ( curveLengths[ i ] >= d ) {
  23371. var diff = curveLengths[ i ] - d;
  23372. var curve = this.curves[ i ];
  23373. var segmentLength = curve.getLength();
  23374. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23375. return curve.getPointAt( u );
  23376. }
  23377. i ++;
  23378. }
  23379. return null;
  23380. // loop where sum != 0, sum > d , sum+1 <d
  23381. },
  23382. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23383. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23384. // getPoint() depends on getLength
  23385. getLength: function () {
  23386. var lens = this.getCurveLengths();
  23387. return lens[ lens.length - 1 ];
  23388. },
  23389. // cacheLengths must be recalculated.
  23390. updateArcLengths: function () {
  23391. this.needsUpdate = true;
  23392. this.cacheLengths = null;
  23393. this.getCurveLengths();
  23394. },
  23395. // Compute lengths and cache them
  23396. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23397. getCurveLengths: function () {
  23398. // We use cache values if curves and cache array are same length
  23399. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  23400. return this.cacheLengths;
  23401. }
  23402. // Get length of sub-curve
  23403. // Push sums into cached array
  23404. var lengths = [];
  23405. var sums = 0;
  23406. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  23407. sums += this.curves[ i ].getLength();
  23408. lengths.push( sums );
  23409. }
  23410. this.cacheLengths = lengths;
  23411. return lengths;
  23412. },
  23413. getSpacedPoints: function ( divisions ) {
  23414. if ( divisions === undefined ) { divisions = 40; }
  23415. var points = [];
  23416. for ( var i = 0; i <= divisions; i ++ ) {
  23417. points.push( this.getPoint( i / divisions ) );
  23418. }
  23419. if ( this.autoClose ) {
  23420. points.push( points[ 0 ] );
  23421. }
  23422. return points;
  23423. },
  23424. getPoints: function ( divisions ) {
  23425. divisions = divisions || 12;
  23426. var points = [];
  23427. var last;
  23428. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  23429. var curve = curves[ i ];
  23430. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  23431. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  23432. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  23433. : divisions;
  23434. var pts = curve.getPoints( resolution );
  23435. for ( var j = 0; j < pts.length; j ++ ) {
  23436. var point = pts[ j ];
  23437. if ( last && last.equals( point ) ) { continue; } // ensures no consecutive points are duplicates
  23438. points.push( point );
  23439. last = point;
  23440. }
  23441. }
  23442. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  23443. points.push( points[ 0 ] );
  23444. }
  23445. return points;
  23446. },
  23447. copy: function ( source ) {
  23448. Curve.prototype.copy.call( this, source );
  23449. this.curves = [];
  23450. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  23451. var curve = source.curves[ i ];
  23452. this.curves.push( curve.clone() );
  23453. }
  23454. this.autoClose = source.autoClose;
  23455. return this;
  23456. },
  23457. toJSON: function () {
  23458. var data = Curve.prototype.toJSON.call( this );
  23459. data.autoClose = this.autoClose;
  23460. data.curves = [];
  23461. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  23462. var curve = this.curves[ i ];
  23463. data.curves.push( curve.toJSON() );
  23464. }
  23465. return data;
  23466. },
  23467. fromJSON: function ( json ) {
  23468. Curve.prototype.fromJSON.call( this, json );
  23469. this.autoClose = json.autoClose;
  23470. this.curves = [];
  23471. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  23472. var curve = json.curves[ i ];
  23473. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  23474. }
  23475. return this;
  23476. }
  23477. } );
  23478. /**
  23479. * @author zz85 / http://www.lab4games.net/zz85/blog
  23480. * Creates free form 2d path using series of points, lines or curves.
  23481. **/
  23482. function Path( points ) {
  23483. CurvePath.call( this );
  23484. this.type = 'Path';
  23485. this.currentPoint = new Vector2();
  23486. if ( points ) {
  23487. this.setFromPoints( points );
  23488. }
  23489. }
  23490. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  23491. constructor: Path,
  23492. setFromPoints: function ( points ) {
  23493. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  23494. for ( var i = 1, l = points.length; i < l; i ++ ) {
  23495. this.lineTo( points[ i ].x, points[ i ].y );
  23496. }
  23497. return this;
  23498. },
  23499. moveTo: function ( x, y ) {
  23500. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  23501. return this;
  23502. },
  23503. lineTo: function ( x, y ) {
  23504. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  23505. this.curves.push( curve );
  23506. this.currentPoint.set( x, y );
  23507. return this;
  23508. },
  23509. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23510. var curve = new QuadraticBezierCurve(
  23511. this.currentPoint.clone(),
  23512. new Vector2( aCPx, aCPy ),
  23513. new Vector2( aX, aY )
  23514. );
  23515. this.curves.push( curve );
  23516. this.currentPoint.set( aX, aY );
  23517. return this;
  23518. },
  23519. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23520. var curve = new CubicBezierCurve(
  23521. this.currentPoint.clone(),
  23522. new Vector2( aCP1x, aCP1y ),
  23523. new Vector2( aCP2x, aCP2y ),
  23524. new Vector2( aX, aY )
  23525. );
  23526. this.curves.push( curve );
  23527. this.currentPoint.set( aX, aY );
  23528. return this;
  23529. },
  23530. splineThru: function ( pts /*Array of Vector*/ ) {
  23531. var npts = [ this.currentPoint.clone() ].concat( pts );
  23532. var curve = new SplineCurve( npts );
  23533. this.curves.push( curve );
  23534. this.currentPoint.copy( pts[ pts.length - 1 ] );
  23535. return this;
  23536. },
  23537. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23538. var x0 = this.currentPoint.x;
  23539. var y0 = this.currentPoint.y;
  23540. this.absarc( aX + x0, aY + y0, aRadius,
  23541. aStartAngle, aEndAngle, aClockwise );
  23542. return this;
  23543. },
  23544. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23545. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  23546. return this;
  23547. },
  23548. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23549. var x0 = this.currentPoint.x;
  23550. var y0 = this.currentPoint.y;
  23551. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23552. return this;
  23553. },
  23554. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23555. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23556. if ( this.curves.length > 0 ) {
  23557. // if a previous curve is present, attempt to join
  23558. var firstPoint = curve.getPoint( 0 );
  23559. if ( ! firstPoint.equals( this.currentPoint ) ) {
  23560. this.lineTo( firstPoint.x, firstPoint.y );
  23561. }
  23562. }
  23563. this.curves.push( curve );
  23564. var lastPoint = curve.getPoint( 1 );
  23565. this.currentPoint.copy( lastPoint );
  23566. return this;
  23567. },
  23568. copy: function ( source ) {
  23569. CurvePath.prototype.copy.call( this, source );
  23570. this.currentPoint.copy( source.currentPoint );
  23571. return this;
  23572. },
  23573. toJSON: function () {
  23574. var data = CurvePath.prototype.toJSON.call( this );
  23575. data.currentPoint = this.currentPoint.toArray();
  23576. return data;
  23577. },
  23578. fromJSON: function ( json ) {
  23579. CurvePath.prototype.fromJSON.call( this, json );
  23580. this.currentPoint.fromArray( json.currentPoint );
  23581. return this;
  23582. }
  23583. } );
  23584. /**
  23585. * @author zz85 / http://www.lab4games.net/zz85/blog
  23586. * Defines a 2d shape plane using paths.
  23587. **/
  23588. // STEP 1 Create a path.
  23589. // STEP 2 Turn path into shape.
  23590. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  23591. // STEP 3a - Extract points from each shape, turn to vertices
  23592. // STEP 3b - Triangulate each shape, add faces.
  23593. function Shape( points ) {
  23594. Path.call( this, points );
  23595. this.uuid = MathUtils.generateUUID();
  23596. this.type = 'Shape';
  23597. this.holes = [];
  23598. }
  23599. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  23600. constructor: Shape,
  23601. getPointsHoles: function ( divisions ) {
  23602. var holesPts = [];
  23603. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  23604. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  23605. }
  23606. return holesPts;
  23607. },
  23608. // get points of shape and holes (keypoints based on segments parameter)
  23609. extractPoints: function ( divisions ) {
  23610. return {
  23611. shape: this.getPoints( divisions ),
  23612. holes: this.getPointsHoles( divisions )
  23613. };
  23614. },
  23615. copy: function ( source ) {
  23616. Path.prototype.copy.call( this, source );
  23617. this.holes = [];
  23618. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  23619. var hole = source.holes[ i ];
  23620. this.holes.push( hole.clone() );
  23621. }
  23622. return this;
  23623. },
  23624. toJSON: function () {
  23625. var data = Path.prototype.toJSON.call( this );
  23626. data.uuid = this.uuid;
  23627. data.holes = [];
  23628. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  23629. var hole = this.holes[ i ];
  23630. data.holes.push( hole.toJSON() );
  23631. }
  23632. return data;
  23633. },
  23634. fromJSON: function ( json ) {
  23635. Path.prototype.fromJSON.call( this, json );
  23636. this.uuid = json.uuid;
  23637. this.holes = [];
  23638. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  23639. var hole = json.holes[ i ];
  23640. this.holes.push( new Path().fromJSON( hole ) );
  23641. }
  23642. return this;
  23643. }
  23644. } );
  23645. /**
  23646. * @author mrdoob / http://mrdoob.com/
  23647. * @author alteredq / http://alteredqualia.com/
  23648. */
  23649. function Light( color, intensity ) {
  23650. Object3D.call( this );
  23651. this.type = 'Light';
  23652. this.color = new Color( color );
  23653. this.intensity = intensity !== undefined ? intensity : 1;
  23654. this.receiveShadow = undefined;
  23655. }
  23656. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23657. constructor: Light,
  23658. isLight: true,
  23659. copy: function ( source ) {
  23660. Object3D.prototype.copy.call( this, source );
  23661. this.color.copy( source.color );
  23662. this.intensity = source.intensity;
  23663. return this;
  23664. },
  23665. toJSON: function ( meta ) {
  23666. var data = Object3D.prototype.toJSON.call( this, meta );
  23667. data.object.color = this.color.getHex();
  23668. data.object.intensity = this.intensity;
  23669. if ( this.groundColor !== undefined ) { data.object.groundColor = this.groundColor.getHex(); }
  23670. if ( this.distance !== undefined ) { data.object.distance = this.distance; }
  23671. if ( this.angle !== undefined ) { data.object.angle = this.angle; }
  23672. if ( this.decay !== undefined ) { data.object.decay = this.decay; }
  23673. if ( this.penumbra !== undefined ) { data.object.penumbra = this.penumbra; }
  23674. if ( this.shadow !== undefined ) { data.object.shadow = this.shadow.toJSON(); }
  23675. return data;
  23676. }
  23677. } );
  23678. /**
  23679. * @author alteredq / http://alteredqualia.com/
  23680. */
  23681. function HemisphereLight( skyColor, groundColor, intensity ) {
  23682. Light.call( this, skyColor, intensity );
  23683. this.type = 'HemisphereLight';
  23684. this.castShadow = undefined;
  23685. this.position.copy( Object3D.DefaultUp );
  23686. this.updateMatrix();
  23687. this.groundColor = new Color( groundColor );
  23688. }
  23689. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23690. constructor: HemisphereLight,
  23691. isHemisphereLight: true,
  23692. copy: function ( source ) {
  23693. Light.prototype.copy.call( this, source );
  23694. this.groundColor.copy( source.groundColor );
  23695. return this;
  23696. }
  23697. } );
  23698. /**
  23699. * @author mrdoob / http://mrdoob.com/
  23700. */
  23701. function LightShadow( camera ) {
  23702. this.camera = camera;
  23703. this.bias = 0;
  23704. this.normalBias = 0;
  23705. this.radius = 1;
  23706. this.mapSize = new Vector2( 512, 512 );
  23707. this.map = null;
  23708. this.mapPass = null;
  23709. this.matrix = new Matrix4();
  23710. this.autoUpdate = true;
  23711. this.needsUpdate = false;
  23712. this._frustum = new Frustum();
  23713. this._frameExtents = new Vector2( 1, 1 );
  23714. this._viewportCount = 1;
  23715. this._viewports = [
  23716. new Vector4( 0, 0, 1, 1 )
  23717. ];
  23718. }
  23719. Object.assign( LightShadow.prototype, {
  23720. _projScreenMatrix: new Matrix4(),
  23721. _lightPositionWorld: new Vector3(),
  23722. _lookTarget: new Vector3(),
  23723. getViewportCount: function () {
  23724. return this._viewportCount;
  23725. },
  23726. getFrustum: function () {
  23727. return this._frustum;
  23728. },
  23729. updateMatrices: function ( light ) {
  23730. var shadowCamera = this.camera,
  23731. shadowMatrix = this.matrix,
  23732. projScreenMatrix = this._projScreenMatrix,
  23733. lookTarget = this._lookTarget,
  23734. lightPositionWorld = this._lightPositionWorld;
  23735. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23736. shadowCamera.position.copy( lightPositionWorld );
  23737. lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  23738. shadowCamera.lookAt( lookTarget );
  23739. shadowCamera.updateMatrixWorld();
  23740. projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23741. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23742. shadowMatrix.set(
  23743. 0.5, 0.0, 0.0, 0.5,
  23744. 0.0, 0.5, 0.0, 0.5,
  23745. 0.0, 0.0, 0.5, 0.5,
  23746. 0.0, 0.0, 0.0, 1.0
  23747. );
  23748. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23749. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23750. },
  23751. getViewport: function ( viewportIndex ) {
  23752. return this._viewports[ viewportIndex ];
  23753. },
  23754. getFrameExtents: function () {
  23755. return this._frameExtents;
  23756. },
  23757. copy: function ( source ) {
  23758. this.camera = source.camera.clone();
  23759. this.bias = source.bias;
  23760. this.radius = source.radius;
  23761. this.mapSize.copy( source.mapSize );
  23762. return this;
  23763. },
  23764. clone: function () {
  23765. return new this.constructor().copy( this );
  23766. },
  23767. toJSON: function () {
  23768. var object = {};
  23769. if ( this.bias !== 0 ) { object.bias = this.bias; }
  23770. if ( this.normalBias !== 0 ) { object.normalBias = this.normalBias; }
  23771. if ( this.radius !== 1 ) { object.radius = this.radius; }
  23772. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) { object.mapSize = this.mapSize.toArray(); }
  23773. object.camera = this.camera.toJSON( false ).object;
  23774. delete object.camera.matrix;
  23775. return object;
  23776. }
  23777. } );
  23778. /**
  23779. * @author mrdoob / http://mrdoob.com/
  23780. */
  23781. function SpotLightShadow() {
  23782. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23783. }
  23784. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23785. constructor: SpotLightShadow,
  23786. isSpotLightShadow: true,
  23787. updateMatrices: function ( light ) {
  23788. var camera = this.camera;
  23789. var fov = MathUtils.RAD2DEG * 2 * light.angle;
  23790. var aspect = this.mapSize.width / this.mapSize.height;
  23791. var far = light.distance || camera.far;
  23792. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23793. camera.fov = fov;
  23794. camera.aspect = aspect;
  23795. camera.far = far;
  23796. camera.updateProjectionMatrix();
  23797. }
  23798. LightShadow.prototype.updateMatrices.call( this, light );
  23799. }
  23800. } );
  23801. /**
  23802. * @author alteredq / http://alteredqualia.com/
  23803. */
  23804. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  23805. Light.call( this, color, intensity );
  23806. this.type = 'SpotLight';
  23807. this.position.copy( Object3D.DefaultUp );
  23808. this.updateMatrix();
  23809. this.target = new Object3D();
  23810. Object.defineProperty( this, 'power', {
  23811. get: function () {
  23812. // intensity = power per solid angle.
  23813. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23814. return this.intensity * Math.PI;
  23815. },
  23816. set: function ( power ) {
  23817. // intensity = power per solid angle.
  23818. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23819. this.intensity = power / Math.PI;
  23820. }
  23821. } );
  23822. this.distance = ( distance !== undefined ) ? distance : 0;
  23823. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  23824. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  23825. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23826. this.shadow = new SpotLightShadow();
  23827. }
  23828. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23829. constructor: SpotLight,
  23830. isSpotLight: true,
  23831. copy: function ( source ) {
  23832. Light.prototype.copy.call( this, source );
  23833. this.distance = source.distance;
  23834. this.angle = source.angle;
  23835. this.penumbra = source.penumbra;
  23836. this.decay = source.decay;
  23837. this.target = source.target.clone();
  23838. this.shadow = source.shadow.clone();
  23839. return this;
  23840. }
  23841. } );
  23842. function PointLightShadow() {
  23843. LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23844. this._frameExtents = new Vector2( 4, 2 );
  23845. this._viewportCount = 6;
  23846. this._viewports = [
  23847. // These viewports map a cube-map onto a 2D texture with the
  23848. // following orientation:
  23849. //
  23850. // xzXZ
  23851. // y Y
  23852. //
  23853. // X - Positive x direction
  23854. // x - Negative x direction
  23855. // Y - Positive y direction
  23856. // y - Negative y direction
  23857. // Z - Positive z direction
  23858. // z - Negative z direction
  23859. // positive X
  23860. new Vector4( 2, 1, 1, 1 ),
  23861. // negative X
  23862. new Vector4( 0, 1, 1, 1 ),
  23863. // positive Z
  23864. new Vector4( 3, 1, 1, 1 ),
  23865. // negative Z
  23866. new Vector4( 1, 1, 1, 1 ),
  23867. // positive Y
  23868. new Vector4( 3, 0, 1, 1 ),
  23869. // negative Y
  23870. new Vector4( 1, 0, 1, 1 )
  23871. ];
  23872. this._cubeDirections = [
  23873. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23874. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23875. ];
  23876. this._cubeUps = [
  23877. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23878. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23879. ];
  23880. }
  23881. PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23882. constructor: PointLightShadow,
  23883. isPointLightShadow: true,
  23884. updateMatrices: function ( light, viewportIndex ) {
  23885. if ( viewportIndex === undefined ) { viewportIndex = 0; }
  23886. var camera = this.camera,
  23887. shadowMatrix = this.matrix,
  23888. lightPositionWorld = this._lightPositionWorld,
  23889. lookTarget = this._lookTarget,
  23890. projScreenMatrix = this._projScreenMatrix;
  23891. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23892. camera.position.copy( lightPositionWorld );
  23893. lookTarget.copy( camera.position );
  23894. lookTarget.add( this._cubeDirections[ viewportIndex ] );
  23895. camera.up.copy( this._cubeUps[ viewportIndex ] );
  23896. camera.lookAt( lookTarget );
  23897. camera.updateMatrixWorld();
  23898. shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
  23899. projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  23900. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23901. }
  23902. } );
  23903. /**
  23904. * @author mrdoob / http://mrdoob.com/
  23905. */
  23906. function PointLight( color, intensity, distance, decay ) {
  23907. Light.call( this, color, intensity );
  23908. this.type = 'PointLight';
  23909. Object.defineProperty( this, 'power', {
  23910. get: function () {
  23911. // intensity = power per solid angle.
  23912. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23913. return this.intensity * 4 * Math.PI;
  23914. },
  23915. set: function ( power ) {
  23916. // intensity = power per solid angle.
  23917. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23918. this.intensity = power / ( 4 * Math.PI );
  23919. }
  23920. } );
  23921. this.distance = ( distance !== undefined ) ? distance : 0;
  23922. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23923. this.shadow = new PointLightShadow();
  23924. }
  23925. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23926. constructor: PointLight,
  23927. isPointLight: true,
  23928. copy: function ( source ) {
  23929. Light.prototype.copy.call( this, source );
  23930. this.distance = source.distance;
  23931. this.decay = source.decay;
  23932. this.shadow = source.shadow.clone();
  23933. return this;
  23934. }
  23935. } );
  23936. /**
  23937. * @author alteredq / http://alteredqualia.com/
  23938. * @author arose / http://github.com/arose
  23939. */
  23940. function OrthographicCamera( left, right, top, bottom, near, far ) {
  23941. Camera.call( this );
  23942. this.type = 'OrthographicCamera';
  23943. this.zoom = 1;
  23944. this.view = null;
  23945. this.left = ( left !== undefined ) ? left : - 1;
  23946. this.right = ( right !== undefined ) ? right : 1;
  23947. this.top = ( top !== undefined ) ? top : 1;
  23948. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  23949. this.near = ( near !== undefined ) ? near : 0.1;
  23950. this.far = ( far !== undefined ) ? far : 2000;
  23951. this.updateProjectionMatrix();
  23952. }
  23953. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  23954. constructor: OrthographicCamera,
  23955. isOrthographicCamera: true,
  23956. copy: function ( source, recursive ) {
  23957. Camera.prototype.copy.call( this, source, recursive );
  23958. this.left = source.left;
  23959. this.right = source.right;
  23960. this.top = source.top;
  23961. this.bottom = source.bottom;
  23962. this.near = source.near;
  23963. this.far = source.far;
  23964. this.zoom = source.zoom;
  23965. this.view = source.view === null ? null : Object.assign( {}, source.view );
  23966. return this;
  23967. },
  23968. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  23969. if ( this.view === null ) {
  23970. this.view = {
  23971. enabled: true,
  23972. fullWidth: 1,
  23973. fullHeight: 1,
  23974. offsetX: 0,
  23975. offsetY: 0,
  23976. width: 1,
  23977. height: 1
  23978. };
  23979. }
  23980. this.view.enabled = true;
  23981. this.view.fullWidth = fullWidth;
  23982. this.view.fullHeight = fullHeight;
  23983. this.view.offsetX = x;
  23984. this.view.offsetY = y;
  23985. this.view.width = width;
  23986. this.view.height = height;
  23987. this.updateProjectionMatrix();
  23988. },
  23989. clearViewOffset: function () {
  23990. if ( this.view !== null ) {
  23991. this.view.enabled = false;
  23992. }
  23993. this.updateProjectionMatrix();
  23994. },
  23995. updateProjectionMatrix: function () {
  23996. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  23997. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  23998. var cx = ( this.right + this.left ) / 2;
  23999. var cy = ( this.top + this.bottom ) / 2;
  24000. var left = cx - dx;
  24001. var right = cx + dx;
  24002. var top = cy + dy;
  24003. var bottom = cy - dy;
  24004. if ( this.view !== null && this.view.enabled ) {
  24005. var scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  24006. var scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  24007. left += scaleW * this.view.offsetX;
  24008. right = left + scaleW * this.view.width;
  24009. top -= scaleH * this.view.offsetY;
  24010. bottom = top - scaleH * this.view.height;
  24011. }
  24012. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  24013. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  24014. },
  24015. toJSON: function ( meta ) {
  24016. var data = Object3D.prototype.toJSON.call( this, meta );
  24017. data.object.zoom = this.zoom;
  24018. data.object.left = this.left;
  24019. data.object.right = this.right;
  24020. data.object.top = this.top;
  24021. data.object.bottom = this.bottom;
  24022. data.object.near = this.near;
  24023. data.object.far = this.far;
  24024. if ( this.view !== null ) { data.object.view = Object.assign( {}, this.view ); }
  24025. return data;
  24026. }
  24027. } );
  24028. /**
  24029. * @author mrdoob / http://mrdoob.com/
  24030. */
  24031. function DirectionalLightShadow() {
  24032. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  24033. }
  24034. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  24035. constructor: DirectionalLightShadow,
  24036. isDirectionalLightShadow: true,
  24037. updateMatrices: function ( light ) {
  24038. LightShadow.prototype.updateMatrices.call( this, light );
  24039. }
  24040. } );
  24041. /**
  24042. * @author mrdoob / http://mrdoob.com/
  24043. * @author alteredq / http://alteredqualia.com/
  24044. */
  24045. function DirectionalLight( color, intensity ) {
  24046. Light.call( this, color, intensity );
  24047. this.type = 'DirectionalLight';
  24048. this.position.copy( Object3D.DefaultUp );
  24049. this.updateMatrix();
  24050. this.target = new Object3D();
  24051. this.shadow = new DirectionalLightShadow();
  24052. }
  24053. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  24054. constructor: DirectionalLight,
  24055. isDirectionalLight: true,
  24056. copy: function ( source ) {
  24057. Light.prototype.copy.call( this, source );
  24058. this.target = source.target.clone();
  24059. this.shadow = source.shadow.clone();
  24060. return this;
  24061. }
  24062. } );
  24063. /**
  24064. * @author mrdoob / http://mrdoob.com/
  24065. */
  24066. function AmbientLight( color, intensity ) {
  24067. Light.call( this, color, intensity );
  24068. this.type = 'AmbientLight';
  24069. this.castShadow = undefined;
  24070. }
  24071. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  24072. constructor: AmbientLight,
  24073. isAmbientLight: true
  24074. } );
  24075. /**
  24076. * @author abelnation / http://github.com/abelnation
  24077. */
  24078. function RectAreaLight( color, intensity, width, height ) {
  24079. Light.call( this, color, intensity );
  24080. this.type = 'RectAreaLight';
  24081. this.width = ( width !== undefined ) ? width : 10;
  24082. this.height = ( height !== undefined ) ? height : 10;
  24083. }
  24084. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  24085. constructor: RectAreaLight,
  24086. isRectAreaLight: true,
  24087. copy: function ( source ) {
  24088. Light.prototype.copy.call( this, source );
  24089. this.width = source.width;
  24090. this.height = source.height;
  24091. return this;
  24092. },
  24093. toJSON: function ( meta ) {
  24094. var data = Light.prototype.toJSON.call( this, meta );
  24095. data.object.width = this.width;
  24096. data.object.height = this.height;
  24097. return data;
  24098. }
  24099. } );
  24100. /**
  24101. * @author bhouston / http://clara.io
  24102. * @author WestLangley / http://github.com/WestLangley
  24103. *
  24104. * Primary reference:
  24105. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24106. *
  24107. * Secondary reference:
  24108. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24109. */
  24110. // 3-band SH defined by 9 coefficients
  24111. function SphericalHarmonics3() {
  24112. this.coefficients = [];
  24113. for ( var i = 0; i < 9; i ++ ) {
  24114. this.coefficients.push( new Vector3() );
  24115. }
  24116. }
  24117. Object.assign( SphericalHarmonics3.prototype, {
  24118. isSphericalHarmonics3: true,
  24119. set: function ( coefficients ) {
  24120. for ( var i = 0; i < 9; i ++ ) {
  24121. this.coefficients[ i ].copy( coefficients[ i ] );
  24122. }
  24123. return this;
  24124. },
  24125. zero: function () {
  24126. for ( var i = 0; i < 9; i ++ ) {
  24127. this.coefficients[ i ].set( 0, 0, 0 );
  24128. }
  24129. return this;
  24130. },
  24131. // get the radiance in the direction of the normal
  24132. // target is a Vector3
  24133. getAt: function ( normal, target ) {
  24134. // normal is assumed to be unit length
  24135. var x = normal.x, y = normal.y, z = normal.z;
  24136. var coeff = this.coefficients;
  24137. // band 0
  24138. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24139. // band 1
  24140. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  24141. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  24142. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  24143. // band 2
  24144. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  24145. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  24146. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24147. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  24148. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24149. return target;
  24150. },
  24151. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24152. // target is a Vector3
  24153. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24154. getIrradianceAt: function ( normal, target ) {
  24155. // normal is assumed to be unit length
  24156. var x = normal.x, y = normal.y, z = normal.z;
  24157. var coeff = this.coefficients;
  24158. // band 0
  24159. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  24160. // band 1
  24161. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24162. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  24163. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  24164. // band 2
  24165. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24166. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24167. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24168. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24169. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24170. return target;
  24171. },
  24172. add: function ( sh ) {
  24173. for ( var i = 0; i < 9; i ++ ) {
  24174. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24175. }
  24176. return this;
  24177. },
  24178. addScaledSH: function ( sh, s ) {
  24179. for ( var i = 0; i < 9; i ++ ) {
  24180. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  24181. }
  24182. return this;
  24183. },
  24184. scale: function ( s ) {
  24185. for ( var i = 0; i < 9; i ++ ) {
  24186. this.coefficients[ i ].multiplyScalar( s );
  24187. }
  24188. return this;
  24189. },
  24190. lerp: function ( sh, alpha ) {
  24191. for ( var i = 0; i < 9; i ++ ) {
  24192. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24193. }
  24194. return this;
  24195. },
  24196. equals: function ( sh ) {
  24197. for ( var i = 0; i < 9; i ++ ) {
  24198. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24199. return false;
  24200. }
  24201. }
  24202. return true;
  24203. },
  24204. copy: function ( sh ) {
  24205. return this.set( sh.coefficients );
  24206. },
  24207. clone: function () {
  24208. return new this.constructor().copy( this );
  24209. },
  24210. fromArray: function ( array, offset ) {
  24211. if ( offset === undefined ) { offset = 0; }
  24212. var coefficients = this.coefficients;
  24213. for ( var i = 0; i < 9; i ++ ) {
  24214. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  24215. }
  24216. return this;
  24217. },
  24218. toArray: function ( array, offset ) {
  24219. if ( array === undefined ) { array = []; }
  24220. if ( offset === undefined ) { offset = 0; }
  24221. var coefficients = this.coefficients;
  24222. for ( var i = 0; i < 9; i ++ ) {
  24223. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  24224. }
  24225. return array;
  24226. }
  24227. } );
  24228. Object.assign( SphericalHarmonics3, {
  24229. // evaluate the basis functions
  24230. // shBasis is an Array[ 9 ]
  24231. getBasisAt: function ( normal, shBasis ) {
  24232. // normal is assumed to be unit length
  24233. var x = normal.x, y = normal.y, z = normal.z;
  24234. // band 0
  24235. shBasis[ 0 ] = 0.282095;
  24236. // band 1
  24237. shBasis[ 1 ] = 0.488603 * y;
  24238. shBasis[ 2 ] = 0.488603 * z;
  24239. shBasis[ 3 ] = 0.488603 * x;
  24240. // band 2
  24241. shBasis[ 4 ] = 1.092548 * x * y;
  24242. shBasis[ 5 ] = 1.092548 * y * z;
  24243. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24244. shBasis[ 7 ] = 1.092548 * x * z;
  24245. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24246. }
  24247. } );
  24248. /**
  24249. * @author WestLangley / http://github.com/WestLangley
  24250. *
  24251. * A LightProbe is a source of indirect-diffuse light
  24252. */
  24253. function LightProbe( sh, intensity ) {
  24254. Light.call( this, undefined, intensity );
  24255. this.type = 'LightProbe';
  24256. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24257. }
  24258. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24259. constructor: LightProbe,
  24260. isLightProbe: true,
  24261. copy: function ( source ) {
  24262. Light.prototype.copy.call( this, source );
  24263. this.sh.copy( source.sh );
  24264. return this;
  24265. },
  24266. fromJSON: function ( json ) {
  24267. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24268. this.sh.fromArray( json.sh );
  24269. return this;
  24270. },
  24271. toJSON: function ( meta ) {
  24272. var data = Light.prototype.toJSON.call( this, meta );
  24273. data.object.sh = this.sh.toArray();
  24274. return data;
  24275. }
  24276. } );
  24277. /**
  24278. * @author mrdoob / http://mrdoob.com/
  24279. */
  24280. function MaterialLoader( manager ) {
  24281. Loader.call( this, manager );
  24282. this.textures = {};
  24283. }
  24284. MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24285. constructor: MaterialLoader,
  24286. load: function ( url, onLoad, onProgress, onError ) {
  24287. var scope = this;
  24288. var loader = new FileLoader( scope.manager );
  24289. loader.setPath( scope.path );
  24290. loader.load( url, function ( text ) {
  24291. try {
  24292. onLoad( scope.parse( JSON.parse( text ) ) );
  24293. } catch ( e ) {
  24294. if ( onError ) {
  24295. onError( e );
  24296. } else {
  24297. console.error( e );
  24298. }
  24299. scope.manager.itemError( url );
  24300. }
  24301. }, onProgress, onError );
  24302. },
  24303. parse: function ( json ) {
  24304. var textures = this.textures;
  24305. function getTexture( name ) {
  24306. if ( textures[ name ] === undefined ) {
  24307. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  24308. }
  24309. return textures[ name ];
  24310. }
  24311. var material = new Materials[ json.type ]();
  24312. if ( json.uuid !== undefined ) { material.uuid = json.uuid; }
  24313. if ( json.name !== undefined ) { material.name = json.name; }
  24314. if ( json.color !== undefined ) { material.color.setHex( json.color ); }
  24315. if ( json.roughness !== undefined ) { material.roughness = json.roughness; }
  24316. if ( json.metalness !== undefined ) { material.metalness = json.metalness; }
  24317. if ( json.sheen !== undefined ) { material.sheen = new Color().setHex( json.sheen ); }
  24318. if ( json.emissive !== undefined ) { material.emissive.setHex( json.emissive ); }
  24319. if ( json.specular !== undefined ) { material.specular.setHex( json.specular ); }
  24320. if ( json.shininess !== undefined ) { material.shininess = json.shininess; }
  24321. if ( json.clearcoat !== undefined ) { material.clearcoat = json.clearcoat; }
  24322. if ( json.clearcoatRoughness !== undefined ) { material.clearcoatRoughness = json.clearcoatRoughness; }
  24323. if ( json.fog !== undefined ) { material.fog = json.fog; }
  24324. if ( json.flatShading !== undefined ) { material.flatShading = json.flatShading; }
  24325. if ( json.blending !== undefined ) { material.blending = json.blending; }
  24326. if ( json.combine !== undefined ) { material.combine = json.combine; }
  24327. if ( json.side !== undefined ) { material.side = json.side; }
  24328. if ( json.opacity !== undefined ) { material.opacity = json.opacity; }
  24329. if ( json.transparent !== undefined ) { material.transparent = json.transparent; }
  24330. if ( json.alphaTest !== undefined ) { material.alphaTest = json.alphaTest; }
  24331. if ( json.depthTest !== undefined ) { material.depthTest = json.depthTest; }
  24332. if ( json.depthWrite !== undefined ) { material.depthWrite = json.depthWrite; }
  24333. if ( json.colorWrite !== undefined ) { material.colorWrite = json.colorWrite; }
  24334. if ( json.stencilWrite !== undefined ) { material.stencilWrite = json.stencilWrite; }
  24335. if ( json.stencilWriteMask !== undefined ) { material.stencilWriteMask = json.stencilWriteMask; }
  24336. if ( json.stencilFunc !== undefined ) { material.stencilFunc = json.stencilFunc; }
  24337. if ( json.stencilRef !== undefined ) { material.stencilRef = json.stencilRef; }
  24338. if ( json.stencilFuncMask !== undefined ) { material.stencilFuncMask = json.stencilFuncMask; }
  24339. if ( json.stencilFail !== undefined ) { material.stencilFail = json.stencilFail; }
  24340. if ( json.stencilZFail !== undefined ) { material.stencilZFail = json.stencilZFail; }
  24341. if ( json.stencilZPass !== undefined ) { material.stencilZPass = json.stencilZPass; }
  24342. if ( json.wireframe !== undefined ) { material.wireframe = json.wireframe; }
  24343. if ( json.wireframeLinewidth !== undefined ) { material.wireframeLinewidth = json.wireframeLinewidth; }
  24344. if ( json.wireframeLinecap !== undefined ) { material.wireframeLinecap = json.wireframeLinecap; }
  24345. if ( json.wireframeLinejoin !== undefined ) { material.wireframeLinejoin = json.wireframeLinejoin; }
  24346. if ( json.rotation !== undefined ) { material.rotation = json.rotation; }
  24347. if ( json.linewidth !== 1 ) { material.linewidth = json.linewidth; }
  24348. if ( json.dashSize !== undefined ) { material.dashSize = json.dashSize; }
  24349. if ( json.gapSize !== undefined ) { material.gapSize = json.gapSize; }
  24350. if ( json.scale !== undefined ) { material.scale = json.scale; }
  24351. if ( json.polygonOffset !== undefined ) { material.polygonOffset = json.polygonOffset; }
  24352. if ( json.polygonOffsetFactor !== undefined ) { material.polygonOffsetFactor = json.polygonOffsetFactor; }
  24353. if ( json.polygonOffsetUnits !== undefined ) { material.polygonOffsetUnits = json.polygonOffsetUnits; }
  24354. if ( json.skinning !== undefined ) { material.skinning = json.skinning; }
  24355. if ( json.morphTargets !== undefined ) { material.morphTargets = json.morphTargets; }
  24356. if ( json.morphNormals !== undefined ) { material.morphNormals = json.morphNormals; }
  24357. if ( json.dithering !== undefined ) { material.dithering = json.dithering; }
  24358. if ( json.vertexTangents !== undefined ) { material.vertexTangents = json.vertexTangents; }
  24359. if ( json.visible !== undefined ) { material.visible = json.visible; }
  24360. if ( json.toneMapped !== undefined ) { material.toneMapped = json.toneMapped; }
  24361. if ( json.userData !== undefined ) { material.userData = json.userData; }
  24362. if ( json.vertexColors !== undefined ) {
  24363. if ( typeof json.vertexColors === 'number' ) {
  24364. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  24365. } else {
  24366. material.vertexColors = json.vertexColors;
  24367. }
  24368. }
  24369. // Shader Material
  24370. if ( json.uniforms !== undefined ) {
  24371. for ( var name in json.uniforms ) {
  24372. var uniform = json.uniforms[ name ];
  24373. material.uniforms[ name ] = {};
  24374. switch ( uniform.type ) {
  24375. case 't':
  24376. material.uniforms[ name ].value = getTexture( uniform.value );
  24377. break;
  24378. case 'c':
  24379. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  24380. break;
  24381. case 'v2':
  24382. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  24383. break;
  24384. case 'v3':
  24385. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  24386. break;
  24387. case 'v4':
  24388. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  24389. break;
  24390. case 'm3':
  24391. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  24392. case 'm4':
  24393. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  24394. break;
  24395. default:
  24396. material.uniforms[ name ].value = uniform.value;
  24397. }
  24398. }
  24399. }
  24400. if ( json.defines !== undefined ) { material.defines = json.defines; }
  24401. if ( json.vertexShader !== undefined ) { material.vertexShader = json.vertexShader; }
  24402. if ( json.fragmentShader !== undefined ) { material.fragmentShader = json.fragmentShader; }
  24403. if ( json.extensions !== undefined ) {
  24404. for ( var key in json.extensions ) {
  24405. material.extensions[ key ] = json.extensions[ key ];
  24406. }
  24407. }
  24408. // Deprecated
  24409. if ( json.shading !== undefined ) { material.flatShading = json.shading === 1; } // THREE.FlatShading
  24410. // for PointsMaterial
  24411. if ( json.size !== undefined ) { material.size = json.size; }
  24412. if ( json.sizeAttenuation !== undefined ) { material.sizeAttenuation = json.sizeAttenuation; }
  24413. // maps
  24414. if ( json.map !== undefined ) { material.map = getTexture( json.map ); }
  24415. if ( json.matcap !== undefined ) { material.matcap = getTexture( json.matcap ); }
  24416. if ( json.alphaMap !== undefined ) { material.alphaMap = getTexture( json.alphaMap ); }
  24417. if ( json.bumpMap !== undefined ) { material.bumpMap = getTexture( json.bumpMap ); }
  24418. if ( json.bumpScale !== undefined ) { material.bumpScale = json.bumpScale; }
  24419. if ( json.normalMap !== undefined ) { material.normalMap = getTexture( json.normalMap ); }
  24420. if ( json.normalMapType !== undefined ) { material.normalMapType = json.normalMapType; }
  24421. if ( json.normalScale !== undefined ) {
  24422. var normalScale = json.normalScale;
  24423. if ( Array.isArray( normalScale ) === false ) {
  24424. // Blender exporter used to export a scalar. See #7459
  24425. normalScale = [ normalScale, normalScale ];
  24426. }
  24427. material.normalScale = new Vector2().fromArray( normalScale );
  24428. }
  24429. if ( json.displacementMap !== undefined ) { material.displacementMap = getTexture( json.displacementMap ); }
  24430. if ( json.displacementScale !== undefined ) { material.displacementScale = json.displacementScale; }
  24431. if ( json.displacementBias !== undefined ) { material.displacementBias = json.displacementBias; }
  24432. if ( json.roughnessMap !== undefined ) { material.roughnessMap = getTexture( json.roughnessMap ); }
  24433. if ( json.metalnessMap !== undefined ) { material.metalnessMap = getTexture( json.metalnessMap ); }
  24434. if ( json.emissiveMap !== undefined ) { material.emissiveMap = getTexture( json.emissiveMap ); }
  24435. if ( json.emissiveIntensity !== undefined ) { material.emissiveIntensity = json.emissiveIntensity; }
  24436. if ( json.specularMap !== undefined ) { material.specularMap = getTexture( json.specularMap ); }
  24437. if ( json.envMap !== undefined ) { material.envMap = getTexture( json.envMap ); }
  24438. if ( json.envMapIntensity !== undefined ) { material.envMapIntensity = json.envMapIntensity; }
  24439. if ( json.reflectivity !== undefined ) { material.reflectivity = json.reflectivity; }
  24440. if ( json.refractionRatio !== undefined ) { material.refractionRatio = json.refractionRatio; }
  24441. if ( json.lightMap !== undefined ) { material.lightMap = getTexture( json.lightMap ); }
  24442. if ( json.lightMapIntensity !== undefined ) { material.lightMapIntensity = json.lightMapIntensity; }
  24443. if ( json.aoMap !== undefined ) { material.aoMap = getTexture( json.aoMap ); }
  24444. if ( json.aoMapIntensity !== undefined ) { material.aoMapIntensity = json.aoMapIntensity; }
  24445. if ( json.gradientMap !== undefined ) { material.gradientMap = getTexture( json.gradientMap ); }
  24446. if ( json.clearcoatMap !== undefined ) { material.clearcoatMap = getTexture( json.clearcoatMap ); }
  24447. if ( json.clearcoatRoughnessMap !== undefined ) { material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap ); }
  24448. if ( json.clearcoatNormalMap !== undefined ) { material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap ); }
  24449. if ( json.clearcoatNormalScale !== undefined ) { material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale ); }
  24450. return material;
  24451. },
  24452. setTextures: function ( value ) {
  24453. this.textures = value;
  24454. return this;
  24455. }
  24456. } );
  24457. /**
  24458. * @author Don McCurdy / https://www.donmccurdy.com
  24459. */
  24460. var LoaderUtils = {
  24461. decodeText: function ( array ) {
  24462. if ( typeof TextDecoder !== 'undefined' ) {
  24463. return new TextDecoder().decode( array );
  24464. }
  24465. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24466. // throws a "maximum call stack size exceeded" error for large arrays.
  24467. var s = '';
  24468. for ( var i = 0, il = array.length; i < il; i ++ ) {
  24469. // Implicitly assumes little-endian.
  24470. s += String.fromCharCode( array[ i ] );
  24471. }
  24472. try {
  24473. // merges multi-byte utf-8 characters.
  24474. return decodeURIComponent( escape( s ) );
  24475. } catch ( e ) { // see #16358
  24476. return s;
  24477. }
  24478. },
  24479. extractUrlBase: function ( url ) {
  24480. var index = url.lastIndexOf( '/' );
  24481. if ( index === - 1 ) { return './'; }
  24482. return url.substr( 0, index + 1 );
  24483. }
  24484. };
  24485. /**
  24486. * @author benaadams / https://twitter.com/ben_a_adams
  24487. */
  24488. function InstancedBufferGeometry() {
  24489. BufferGeometry.call( this );
  24490. this.type = 'InstancedBufferGeometry';
  24491. this.instanceCount = Infinity;
  24492. }
  24493. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  24494. constructor: InstancedBufferGeometry,
  24495. isInstancedBufferGeometry: true,
  24496. copy: function ( source ) {
  24497. BufferGeometry.prototype.copy.call( this, source );
  24498. this.instanceCount = source.instanceCount;
  24499. return this;
  24500. },
  24501. clone: function () {
  24502. return new this.constructor().copy( this );
  24503. },
  24504. toJSON: function () {
  24505. var data = BufferGeometry.prototype.toJSON.call( this );
  24506. data.instanceCount = this.instanceCount;
  24507. data.isInstancedBufferGeometry = true;
  24508. return data;
  24509. }
  24510. } );
  24511. /**
  24512. * @author benaadams / https://twitter.com/ben_a_adams
  24513. */
  24514. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  24515. if ( typeof ( normalized ) === 'number' ) {
  24516. meshPerAttribute = normalized;
  24517. normalized = false;
  24518. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  24519. }
  24520. BufferAttribute.call( this, array, itemSize, normalized );
  24521. this.meshPerAttribute = meshPerAttribute || 1;
  24522. }
  24523. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  24524. constructor: InstancedBufferAttribute,
  24525. isInstancedBufferAttribute: true,
  24526. copy: function ( source ) {
  24527. BufferAttribute.prototype.copy.call( this, source );
  24528. this.meshPerAttribute = source.meshPerAttribute;
  24529. return this;
  24530. },
  24531. toJSON: function () {
  24532. var data = BufferAttribute.prototype.toJSON.call( this );
  24533. data.meshPerAttribute = this.meshPerAttribute;
  24534. data.isInstancedBufferAttribute = true;
  24535. return data;
  24536. }
  24537. } );
  24538. /**
  24539. * @author mrdoob / http://mrdoob.com/
  24540. */
  24541. function BufferGeometryLoader( manager ) {
  24542. Loader.call( this, manager );
  24543. }
  24544. BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24545. constructor: BufferGeometryLoader,
  24546. load: function ( url, onLoad, onProgress, onError ) {
  24547. var scope = this;
  24548. var loader = new FileLoader( scope.manager );
  24549. loader.setPath( scope.path );
  24550. loader.load( url, function ( text ) {
  24551. try {
  24552. onLoad( scope.parse( JSON.parse( text ) ) );
  24553. } catch ( e ) {
  24554. if ( onError ) {
  24555. onError( e );
  24556. } else {
  24557. console.error( e );
  24558. }
  24559. scope.manager.itemError( url );
  24560. }
  24561. }, onProgress, onError );
  24562. },
  24563. parse: function ( json ) {
  24564. var interleavedBufferMap = {};
  24565. var arrayBufferMap = {};
  24566. function getInterleavedBuffer( json, uuid ) {
  24567. if ( interleavedBufferMap[ uuid ] !== undefined ) { return interleavedBufferMap[ uuid ]; }
  24568. var interleavedBuffers = json.interleavedBuffers;
  24569. var interleavedBuffer = interleavedBuffers[ uuid ];
  24570. var buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  24571. var array = new TYPED_ARRAYS[ interleavedBuffer.type ]( buffer );
  24572. var ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  24573. ib.uuid = interleavedBuffer.uuid;
  24574. interleavedBufferMap[ uuid ] = ib;
  24575. return ib;
  24576. }
  24577. function getArrayBuffer( json, uuid ) {
  24578. if ( arrayBufferMap[ uuid ] !== undefined ) { return arrayBufferMap[ uuid ]; }
  24579. var arrayBuffers = json.arrayBuffers;
  24580. var arrayBuffer = arrayBuffers[ uuid ];
  24581. var ab = new Uint32Array( arrayBuffer ).buffer;
  24582. arrayBufferMap[ uuid ] = ab;
  24583. return ab;
  24584. }
  24585. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24586. var index = json.data.index;
  24587. if ( index !== undefined ) {
  24588. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  24589. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  24590. }
  24591. var attributes = json.data.attributes;
  24592. for ( var key in attributes ) {
  24593. var attribute = attributes[ key ];
  24594. var bufferAttribute = (void 0);
  24595. if ( attribute.isInterleavedBufferAttribute ) {
  24596. var interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24597. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24598. } else {
  24599. var typedArray$1 = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  24600. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24601. bufferAttribute = new bufferAttributeConstr( typedArray$1, attribute.itemSize, attribute.normalized );
  24602. }
  24603. if ( attribute.name !== undefined ) { bufferAttribute.name = attribute.name; }
  24604. geometry.setAttribute( key, bufferAttribute );
  24605. }
  24606. var morphAttributes = json.data.morphAttributes;
  24607. if ( morphAttributes ) {
  24608. for ( var key$1 in morphAttributes ) {
  24609. var attributeArray = morphAttributes[ key$1 ];
  24610. var array = [];
  24611. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  24612. var attribute$1 = attributeArray[ i ];
  24613. var bufferAttribute$1 = (void 0);
  24614. if ( attribute$1.isInterleavedBufferAttribute ) {
  24615. var interleavedBuffer$1 = getInterleavedBuffer( json.data, attribute$1.data );
  24616. bufferAttribute$1 = new InterleavedBufferAttribute( interleavedBuffer$1, attribute$1.itemSize, attribute$1.offset, attribute$1.normalized );
  24617. } else {
  24618. var typedArray$2 = new TYPED_ARRAYS[ attribute$1.type ]( attribute$1.array );
  24619. bufferAttribute$1 = new BufferAttribute( typedArray$2, attribute$1.itemSize, attribute$1.normalized );
  24620. }
  24621. if ( attribute$1.name !== undefined ) { bufferAttribute$1.name = attribute$1.name; }
  24622. array.push( bufferAttribute$1 );
  24623. }
  24624. geometry.morphAttributes[ key$1 ] = array;
  24625. }
  24626. }
  24627. var morphTargetsRelative = json.data.morphTargetsRelative;
  24628. if ( morphTargetsRelative ) {
  24629. geometry.morphTargetsRelative = true;
  24630. }
  24631. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24632. if ( groups !== undefined ) {
  24633. for ( var i$1 = 0, n = groups.length; i$1 !== n; ++ i$1 ) {
  24634. var group = groups[ i$1 ];
  24635. geometry.addGroup( group.start, group.count, group.materialIndex );
  24636. }
  24637. }
  24638. var boundingSphere = json.data.boundingSphere;
  24639. if ( boundingSphere !== undefined ) {
  24640. var center = new Vector3();
  24641. if ( boundingSphere.center !== undefined ) {
  24642. center.fromArray( boundingSphere.center );
  24643. }
  24644. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  24645. }
  24646. if ( json.name ) { geometry.name = json.name; }
  24647. if ( json.userData ) { geometry.userData = json.userData; }
  24648. return geometry;
  24649. }
  24650. } );
  24651. var TYPED_ARRAYS = {
  24652. Int8Array: Int8Array,
  24653. Uint8Array: Uint8Array,
  24654. // Workaround for IE11 pre KB2929437. See #11440
  24655. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24656. Int16Array: Int16Array,
  24657. Uint16Array: Uint16Array,
  24658. Int32Array: Int32Array,
  24659. Uint32Array: Uint32Array,
  24660. Float32Array: Float32Array,
  24661. Float64Array: Float64Array
  24662. };
  24663. /**
  24664. * @author mrdoob / http://mrdoob.com/
  24665. */
  24666. function ObjectLoader( manager ) {
  24667. Loader.call( this, manager );
  24668. }
  24669. ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24670. constructor: ObjectLoader,
  24671. load: function ( url, onLoad, onProgress, onError ) {
  24672. var scope = this;
  24673. var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  24674. this.resourcePath = this.resourcePath || path;
  24675. var loader = new FileLoader( scope.manager );
  24676. loader.setPath( this.path );
  24677. loader.load( url, function ( text ) {
  24678. var json = null;
  24679. try {
  24680. json = JSON.parse( text );
  24681. } catch ( error ) {
  24682. if ( onError !== undefined ) { onError( error ); }
  24683. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  24684. return;
  24685. }
  24686. var metadata = json.metadata;
  24687. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24688. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24689. return;
  24690. }
  24691. scope.parse( json, onLoad );
  24692. }, onProgress, onError );
  24693. },
  24694. parse: function ( json, onLoad ) {
  24695. var shapes = this.parseShape( json.shapes );
  24696. var geometries = this.parseGeometries( json.geometries, shapes );
  24697. var images = this.parseImages( json.images, function () {
  24698. if ( onLoad !== undefined ) { onLoad( object ); }
  24699. } );
  24700. var textures = this.parseTextures( json.textures, images );
  24701. var materials = this.parseMaterials( json.materials, textures );
  24702. var object = this.parseObject( json.object, geometries, materials );
  24703. if ( json.animations ) {
  24704. object.animations = this.parseAnimations( json.animations );
  24705. }
  24706. if ( json.images === undefined || json.images.length === 0 ) {
  24707. if ( onLoad !== undefined ) { onLoad( object ); }
  24708. }
  24709. return object;
  24710. },
  24711. parseShape: function ( json ) {
  24712. var shapes = {};
  24713. if ( json !== undefined ) {
  24714. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24715. var shape = new Shape().fromJSON( json[ i ] );
  24716. shapes[ shape.uuid ] = shape;
  24717. }
  24718. }
  24719. return shapes;
  24720. },
  24721. parseGeometries: function ( json, shapes ) {
  24722. var geometries = {};
  24723. var geometryShapes;
  24724. if ( json !== undefined ) {
  24725. var bufferGeometryLoader = new BufferGeometryLoader();
  24726. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24727. var geometry = (void 0);
  24728. var data = json[ i ];
  24729. switch ( data.type ) {
  24730. case 'PlaneGeometry':
  24731. case 'PlaneBufferGeometry':
  24732. geometry = new Geometries[ data.type ](
  24733. data.width,
  24734. data.height,
  24735. data.widthSegments,
  24736. data.heightSegments
  24737. );
  24738. break;
  24739. case 'BoxGeometry':
  24740. case 'BoxBufferGeometry':
  24741. case 'CubeGeometry': // backwards compatible
  24742. geometry = new Geometries[ data.type ](
  24743. data.width,
  24744. data.height,
  24745. data.depth,
  24746. data.widthSegments,
  24747. data.heightSegments,
  24748. data.depthSegments
  24749. );
  24750. break;
  24751. case 'CircleGeometry':
  24752. case 'CircleBufferGeometry':
  24753. geometry = new Geometries[ data.type ](
  24754. data.radius,
  24755. data.segments,
  24756. data.thetaStart,
  24757. data.thetaLength
  24758. );
  24759. break;
  24760. case 'CylinderGeometry':
  24761. case 'CylinderBufferGeometry':
  24762. geometry = new Geometries[ data.type ](
  24763. data.radiusTop,
  24764. data.radiusBottom,
  24765. data.height,
  24766. data.radialSegments,
  24767. data.heightSegments,
  24768. data.openEnded,
  24769. data.thetaStart,
  24770. data.thetaLength
  24771. );
  24772. break;
  24773. case 'ConeGeometry':
  24774. case 'ConeBufferGeometry':
  24775. geometry = new Geometries[ data.type ](
  24776. data.radius,
  24777. data.height,
  24778. data.radialSegments,
  24779. data.heightSegments,
  24780. data.openEnded,
  24781. data.thetaStart,
  24782. data.thetaLength
  24783. );
  24784. break;
  24785. case 'SphereGeometry':
  24786. case 'SphereBufferGeometry':
  24787. geometry = new Geometries[ data.type ](
  24788. data.radius,
  24789. data.widthSegments,
  24790. data.heightSegments,
  24791. data.phiStart,
  24792. data.phiLength,
  24793. data.thetaStart,
  24794. data.thetaLength
  24795. );
  24796. break;
  24797. case 'DodecahedronGeometry':
  24798. case 'DodecahedronBufferGeometry':
  24799. case 'IcosahedronGeometry':
  24800. case 'IcosahedronBufferGeometry':
  24801. case 'OctahedronGeometry':
  24802. case 'OctahedronBufferGeometry':
  24803. case 'TetrahedronGeometry':
  24804. case 'TetrahedronBufferGeometry':
  24805. geometry = new Geometries[ data.type ](
  24806. data.radius,
  24807. data.detail
  24808. );
  24809. break;
  24810. case 'RingGeometry':
  24811. case 'RingBufferGeometry':
  24812. geometry = new Geometries[ data.type ](
  24813. data.innerRadius,
  24814. data.outerRadius,
  24815. data.thetaSegments,
  24816. data.phiSegments,
  24817. data.thetaStart,
  24818. data.thetaLength
  24819. );
  24820. break;
  24821. case 'TorusGeometry':
  24822. case 'TorusBufferGeometry':
  24823. geometry = new Geometries[ data.type ](
  24824. data.radius,
  24825. data.tube,
  24826. data.radialSegments,
  24827. data.tubularSegments,
  24828. data.arc
  24829. );
  24830. break;
  24831. case 'TorusKnotGeometry':
  24832. case 'TorusKnotBufferGeometry':
  24833. geometry = new Geometries[ data.type ](
  24834. data.radius,
  24835. data.tube,
  24836. data.tubularSegments,
  24837. data.radialSegments,
  24838. data.p,
  24839. data.q
  24840. );
  24841. break;
  24842. case 'TubeGeometry':
  24843. case 'TubeBufferGeometry':
  24844. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24845. // User defined curves or instances of CurvePath will not be deserialized.
  24846. geometry = new Geometries[ data.type ](
  24847. new Curves[ data.path.type ]().fromJSON( data.path ),
  24848. data.tubularSegments,
  24849. data.radius,
  24850. data.radialSegments,
  24851. data.closed
  24852. );
  24853. break;
  24854. case 'LatheGeometry':
  24855. case 'LatheBufferGeometry':
  24856. geometry = new Geometries[ data.type ](
  24857. data.points,
  24858. data.segments,
  24859. data.phiStart,
  24860. data.phiLength
  24861. );
  24862. break;
  24863. case 'PolyhedronGeometry':
  24864. case 'PolyhedronBufferGeometry':
  24865. geometry = new Geometries[ data.type ](
  24866. data.vertices,
  24867. data.indices,
  24868. data.radius,
  24869. data.details
  24870. );
  24871. break;
  24872. case 'ShapeGeometry':
  24873. case 'ShapeBufferGeometry':
  24874. geometryShapes = [];
  24875. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24876. var shape = shapes[ data.shapes[ j ] ];
  24877. geometryShapes.push( shape );
  24878. }
  24879. geometry = new Geometries[ data.type ](
  24880. geometryShapes,
  24881. data.curveSegments
  24882. );
  24883. break;
  24884. case 'ExtrudeGeometry':
  24885. case 'ExtrudeBufferGeometry':
  24886. geometryShapes = [];
  24887. for ( var j$1 = 0, jl$1 = data.shapes.length; j$1 < jl$1; j$1 ++ ) {
  24888. var shape$1 = shapes[ data.shapes[ j$1 ] ];
  24889. geometryShapes.push( shape$1 );
  24890. }
  24891. var extrudePath = data.options.extrudePath;
  24892. if ( extrudePath !== undefined ) {
  24893. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  24894. }
  24895. geometry = new Geometries[ data.type ](
  24896. geometryShapes,
  24897. data.options
  24898. );
  24899. break;
  24900. case 'BufferGeometry':
  24901. case 'InstancedBufferGeometry':
  24902. geometry = bufferGeometryLoader.parse( data );
  24903. break;
  24904. case 'Geometry':
  24905. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  24906. break;
  24907. default:
  24908. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  24909. continue;
  24910. }
  24911. geometry.uuid = data.uuid;
  24912. if ( data.name !== undefined ) { geometry.name = data.name; }
  24913. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) { geometry.userData = data.userData; }
  24914. geometries[ data.uuid ] = geometry;
  24915. }
  24916. }
  24917. return geometries;
  24918. },
  24919. parseMaterials: function ( json, textures ) {
  24920. var cache = {}; // MultiMaterial
  24921. var materials = {};
  24922. if ( json !== undefined ) {
  24923. var loader = new MaterialLoader();
  24924. loader.setTextures( textures );
  24925. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24926. var data = json[ i ];
  24927. if ( data.type === 'MultiMaterial' ) {
  24928. // Deprecated
  24929. var array = [];
  24930. for ( var j = 0; j < data.materials.length; j ++ ) {
  24931. var material = data.materials[ j ];
  24932. if ( cache[ material.uuid ] === undefined ) {
  24933. cache[ material.uuid ] = loader.parse( material );
  24934. }
  24935. array.push( cache[ material.uuid ] );
  24936. }
  24937. materials[ data.uuid ] = array;
  24938. } else {
  24939. if ( cache[ data.uuid ] === undefined ) {
  24940. cache[ data.uuid ] = loader.parse( data );
  24941. }
  24942. materials[ data.uuid ] = cache[ data.uuid ];
  24943. }
  24944. }
  24945. }
  24946. return materials;
  24947. },
  24948. parseAnimations: function ( json ) {
  24949. var animations = [];
  24950. for ( var i = 0; i < json.length; i ++ ) {
  24951. var data = json[ i ];
  24952. var clip = AnimationClip.parse( data );
  24953. if ( data.uuid !== undefined ) { clip.uuid = data.uuid; }
  24954. animations.push( clip );
  24955. }
  24956. return animations;
  24957. },
  24958. parseImages: function ( json, onLoad ) {
  24959. var scope = this;
  24960. var images = {};
  24961. var loader;
  24962. function loadImage( url ) {
  24963. scope.manager.itemStart( url );
  24964. return loader.load( url, function () {
  24965. scope.manager.itemEnd( url );
  24966. }, undefined, function () {
  24967. scope.manager.itemError( url );
  24968. scope.manager.itemEnd( url );
  24969. } );
  24970. }
  24971. if ( json !== undefined && json.length > 0 ) {
  24972. var manager = new LoadingManager( onLoad );
  24973. loader = new ImageLoader( manager );
  24974. loader.setCrossOrigin( this.crossOrigin );
  24975. for ( var i = 0, il = json.length; i < il; i ++ ) {
  24976. var image = json[ i ];
  24977. var url = image.url;
  24978. if ( Array.isArray( url ) ) {
  24979. // load array of images e.g CubeTexture
  24980. images[ image.uuid ] = [];
  24981. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  24982. var currentUrl = url[ j ];
  24983. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  24984. images[ image.uuid ].push( loadImage( path ) );
  24985. }
  24986. } else {
  24987. // load single image
  24988. var path$1 = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  24989. images[ image.uuid ] = loadImage( path$1 );
  24990. }
  24991. }
  24992. }
  24993. return images;
  24994. },
  24995. parseTextures: function ( json, images ) {
  24996. function parseConstant( value, type ) {
  24997. if ( typeof value === 'number' ) { return value; }
  24998. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24999. return type[ value ];
  25000. }
  25001. var textures = {};
  25002. if ( json !== undefined ) {
  25003. for ( var i = 0, l = json.length; i < l; i ++ ) {
  25004. var data = json[ i ];
  25005. if ( data.image === undefined ) {
  25006. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  25007. }
  25008. if ( images[ data.image ] === undefined ) {
  25009. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  25010. }
  25011. var texture = (void 0);
  25012. if ( Array.isArray( images[ data.image ] ) ) {
  25013. texture = new CubeTexture( images[ data.image ] );
  25014. } else {
  25015. texture = new Texture( images[ data.image ] );
  25016. }
  25017. texture.needsUpdate = true;
  25018. texture.uuid = data.uuid;
  25019. if ( data.name !== undefined ) { texture.name = data.name; }
  25020. if ( data.mapping !== undefined ) { texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING ); }
  25021. if ( data.offset !== undefined ) { texture.offset.fromArray( data.offset ); }
  25022. if ( data.repeat !== undefined ) { texture.repeat.fromArray( data.repeat ); }
  25023. if ( data.center !== undefined ) { texture.center.fromArray( data.center ); }
  25024. if ( data.rotation !== undefined ) { texture.rotation = data.rotation; }
  25025. if ( data.wrap !== undefined ) {
  25026. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  25027. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  25028. }
  25029. if ( data.format !== undefined ) { texture.format = data.format; }
  25030. if ( data.type !== undefined ) { texture.type = data.type; }
  25031. if ( data.encoding !== undefined ) { texture.encoding = data.encoding; }
  25032. if ( data.minFilter !== undefined ) { texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); }
  25033. if ( data.magFilter !== undefined ) { texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); }
  25034. if ( data.anisotropy !== undefined ) { texture.anisotropy = data.anisotropy; }
  25035. if ( data.flipY !== undefined ) { texture.flipY = data.flipY; }
  25036. if ( data.premultiplyAlpha !== undefined ) { texture.premultiplyAlpha = data.premultiplyAlpha; }
  25037. if ( data.unpackAlignment !== undefined ) { texture.unpackAlignment = data.unpackAlignment; }
  25038. textures[ data.uuid ] = texture;
  25039. }
  25040. }
  25041. return textures;
  25042. },
  25043. parseObject: function ( data, geometries, materials ) {
  25044. var object;
  25045. function getGeometry( name ) {
  25046. if ( geometries[ name ] === undefined ) {
  25047. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  25048. }
  25049. return geometries[ name ];
  25050. }
  25051. function getMaterial( name ) {
  25052. if ( name === undefined ) { return undefined; }
  25053. if ( Array.isArray( name ) ) {
  25054. var array = [];
  25055. for ( var i = 0, l = name.length; i < l; i ++ ) {
  25056. var uuid = name[ i ];
  25057. if ( materials[ uuid ] === undefined ) {
  25058. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  25059. }
  25060. array.push( materials[ uuid ] );
  25061. }
  25062. return array;
  25063. }
  25064. if ( materials[ name ] === undefined ) {
  25065. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  25066. }
  25067. return materials[ name ];
  25068. }
  25069. var geometry, material;
  25070. switch ( data.type ) {
  25071. case 'Scene':
  25072. object = new Scene();
  25073. if ( data.background !== undefined ) {
  25074. if ( Number.isInteger( data.background ) ) {
  25075. object.background = new Color( data.background );
  25076. }
  25077. }
  25078. if ( data.fog !== undefined ) {
  25079. if ( data.fog.type === 'Fog' ) {
  25080. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  25081. } else if ( data.fog.type === 'FogExp2' ) {
  25082. object.fog = new FogExp2( data.fog.color, data.fog.density );
  25083. }
  25084. }
  25085. break;
  25086. case 'PerspectiveCamera':
  25087. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  25088. if ( data.focus !== undefined ) { object.focus = data.focus; }
  25089. if ( data.zoom !== undefined ) { object.zoom = data.zoom; }
  25090. if ( data.filmGauge !== undefined ) { object.filmGauge = data.filmGauge; }
  25091. if ( data.filmOffset !== undefined ) { object.filmOffset = data.filmOffset; }
  25092. if ( data.view !== undefined ) { object.view = Object.assign( {}, data.view ); }
  25093. break;
  25094. case 'OrthographicCamera':
  25095. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  25096. if ( data.zoom !== undefined ) { object.zoom = data.zoom; }
  25097. if ( data.view !== undefined ) { object.view = Object.assign( {}, data.view ); }
  25098. break;
  25099. case 'AmbientLight':
  25100. object = new AmbientLight( data.color, data.intensity );
  25101. break;
  25102. case 'DirectionalLight':
  25103. object = new DirectionalLight( data.color, data.intensity );
  25104. break;
  25105. case 'PointLight':
  25106. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  25107. break;
  25108. case 'RectAreaLight':
  25109. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  25110. break;
  25111. case 'SpotLight':
  25112. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  25113. break;
  25114. case 'HemisphereLight':
  25115. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  25116. break;
  25117. case 'LightProbe':
  25118. object = new LightProbe().fromJSON( data );
  25119. break;
  25120. case 'SkinnedMesh':
  25121. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  25122. case 'Mesh':
  25123. geometry = getGeometry( data.geometry );
  25124. material = getMaterial( data.material );
  25125. object = new Mesh( geometry, material );
  25126. break;
  25127. case 'InstancedMesh':
  25128. geometry = getGeometry( data.geometry );
  25129. material = getMaterial( data.material );
  25130. var count = data.count;
  25131. var instanceMatrix = data.instanceMatrix;
  25132. object = new InstancedMesh( geometry, material, count );
  25133. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  25134. break;
  25135. case 'LOD':
  25136. object = new LOD();
  25137. break;
  25138. case 'Line':
  25139. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  25140. break;
  25141. case 'LineLoop':
  25142. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  25143. break;
  25144. case 'LineSegments':
  25145. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  25146. break;
  25147. case 'PointCloud':
  25148. case 'Points':
  25149. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  25150. break;
  25151. case 'Sprite':
  25152. object = new Sprite( getMaterial( data.material ) );
  25153. break;
  25154. case 'Group':
  25155. object = new Group();
  25156. break;
  25157. default:
  25158. object = new Object3D();
  25159. }
  25160. object.uuid = data.uuid;
  25161. if ( data.name !== undefined ) { object.name = data.name; }
  25162. if ( data.matrix !== undefined ) {
  25163. object.matrix.fromArray( data.matrix );
  25164. if ( data.matrixAutoUpdate !== undefined ) { object.matrixAutoUpdate = data.matrixAutoUpdate; }
  25165. if ( object.matrixAutoUpdate ) { object.matrix.decompose( object.position, object.quaternion, object.scale ); }
  25166. } else {
  25167. if ( data.position !== undefined ) { object.position.fromArray( data.position ); }
  25168. if ( data.rotation !== undefined ) { object.rotation.fromArray( data.rotation ); }
  25169. if ( data.quaternion !== undefined ) { object.quaternion.fromArray( data.quaternion ); }
  25170. if ( data.scale !== undefined ) { object.scale.fromArray( data.scale ); }
  25171. }
  25172. if ( data.castShadow !== undefined ) { object.castShadow = data.castShadow; }
  25173. if ( data.receiveShadow !== undefined ) { object.receiveShadow = data.receiveShadow; }
  25174. if ( data.shadow ) {
  25175. if ( data.shadow.bias !== undefined ) { object.shadow.bias = data.shadow.bias; }
  25176. if ( data.shadow.normalBias !== undefined ) { object.shadow.normalBias = data.shadow.normalBias; }
  25177. if ( data.shadow.radius !== undefined ) { object.shadow.radius = data.shadow.radius; }
  25178. if ( data.shadow.mapSize !== undefined ) { object.shadow.mapSize.fromArray( data.shadow.mapSize ); }
  25179. if ( data.shadow.camera !== undefined ) { object.shadow.camera = this.parseObject( data.shadow.camera ); }
  25180. }
  25181. if ( data.visible !== undefined ) { object.visible = data.visible; }
  25182. if ( data.frustumCulled !== undefined ) { object.frustumCulled = data.frustumCulled; }
  25183. if ( data.renderOrder !== undefined ) { object.renderOrder = data.renderOrder; }
  25184. if ( data.userData !== undefined ) { object.userData = data.userData; }
  25185. if ( data.layers !== undefined ) { object.layers.mask = data.layers; }
  25186. if ( data.children !== undefined ) {
  25187. var children = data.children;
  25188. for ( var i = 0; i < children.length; i ++ ) {
  25189. object.add( this.parseObject( children[ i ], geometries, materials ) );
  25190. }
  25191. }
  25192. if ( data.type === 'LOD' ) {
  25193. if ( data.autoUpdate !== undefined ) { object.autoUpdate = data.autoUpdate; }
  25194. var levels = data.levels;
  25195. for ( var l = 0; l < levels.length; l ++ ) {
  25196. var level = levels[ l ];
  25197. var child = object.getObjectByProperty( 'uuid', level.object );
  25198. if ( child !== undefined ) {
  25199. object.addLevel( child, level.distance );
  25200. }
  25201. }
  25202. }
  25203. return object;
  25204. }
  25205. } );
  25206. var TEXTURE_MAPPING = {
  25207. UVMapping: UVMapping,
  25208. CubeReflectionMapping: CubeReflectionMapping,
  25209. CubeRefractionMapping: CubeRefractionMapping,
  25210. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25211. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25212. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25213. CubeUVRefractionMapping: CubeUVRefractionMapping
  25214. };
  25215. var TEXTURE_WRAPPING = {
  25216. RepeatWrapping: RepeatWrapping,
  25217. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25218. MirroredRepeatWrapping: MirroredRepeatWrapping
  25219. };
  25220. var TEXTURE_FILTER = {
  25221. NearestFilter: NearestFilter,
  25222. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25223. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25224. LinearFilter: LinearFilter,
  25225. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25226. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25227. };
  25228. /**
  25229. * @author thespite / http://clicktorelease.com/
  25230. */
  25231. function ImageBitmapLoader( manager ) {
  25232. if ( typeof createImageBitmap === 'undefined' ) {
  25233. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  25234. }
  25235. if ( typeof fetch === 'undefined' ) {
  25236. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  25237. }
  25238. Loader.call( this, manager );
  25239. this.options = { premultiplyAlpha: 'none' };
  25240. }
  25241. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25242. constructor: ImageBitmapLoader,
  25243. isImageBitmapLoader: true,
  25244. setOptions: function setOptions( options ) {
  25245. this.options = options;
  25246. return this;
  25247. },
  25248. load: function ( url, onLoad, onProgress, onError ) {
  25249. if ( url === undefined ) { url = ''; }
  25250. if ( this.path !== undefined ) { url = this.path + url; }
  25251. url = this.manager.resolveURL( url );
  25252. var scope = this;
  25253. var cached = Cache.get( url );
  25254. if ( cached !== undefined ) {
  25255. scope.manager.itemStart( url );
  25256. setTimeout( function () {
  25257. if ( onLoad ) { onLoad( cached ); }
  25258. scope.manager.itemEnd( url );
  25259. }, 0 );
  25260. return cached;
  25261. }
  25262. fetch( url ).then( function ( res ) {
  25263. return res.blob();
  25264. } ).then( function ( blob ) {
  25265. return createImageBitmap( blob, scope.options );
  25266. } ).then( function ( imageBitmap ) {
  25267. Cache.add( url, imageBitmap );
  25268. if ( onLoad ) { onLoad( imageBitmap ); }
  25269. scope.manager.itemEnd( url );
  25270. } ).catch( function ( e ) {
  25271. if ( onError ) { onError( e ); }
  25272. scope.manager.itemError( url );
  25273. scope.manager.itemEnd( url );
  25274. } );
  25275. scope.manager.itemStart( url );
  25276. }
  25277. } );
  25278. /**
  25279. * @author zz85 / http://www.lab4games.net/zz85/blog
  25280. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  25281. **/
  25282. function ShapePath() {
  25283. this.type = 'ShapePath';
  25284. this.color = new Color();
  25285. this.subPaths = [];
  25286. this.currentPath = null;
  25287. }
  25288. Object.assign( ShapePath.prototype, {
  25289. moveTo: function ( x, y ) {
  25290. this.currentPath = new Path();
  25291. this.subPaths.push( this.currentPath );
  25292. this.currentPath.moveTo( x, y );
  25293. return this;
  25294. },
  25295. lineTo: function ( x, y ) {
  25296. this.currentPath.lineTo( x, y );
  25297. return this;
  25298. },
  25299. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  25300. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  25301. return this;
  25302. },
  25303. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  25304. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  25305. return this;
  25306. },
  25307. splineThru: function ( pts ) {
  25308. this.currentPath.splineThru( pts );
  25309. return this;
  25310. },
  25311. toShapes: function ( isCCW, noHoles ) {
  25312. function toShapesNoHoles( inSubpaths ) {
  25313. var shapes = [];
  25314. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  25315. var tmpPath = inSubpaths[ i ];
  25316. var tmpShape = new Shape();
  25317. tmpShape.curves = tmpPath.curves;
  25318. shapes.push( tmpShape );
  25319. }
  25320. return shapes;
  25321. }
  25322. function isPointInsidePolygon( inPt, inPolygon ) {
  25323. var polyLen = inPolygon.length;
  25324. // inPt on polygon contour => immediate success or
  25325. // toggling of inside/outside at every single! intersection point of an edge
  25326. // with the horizontal line through inPt, left of inPt
  25327. // not counting lowerY endpoints of edges and whole edges on that line
  25328. var inside = false;
  25329. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  25330. var edgeLowPt = inPolygon[ p ];
  25331. var edgeHighPt = inPolygon[ q ];
  25332. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25333. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25334. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  25335. // not parallel
  25336. if ( edgeDy < 0 ) {
  25337. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  25338. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  25339. }
  25340. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) { continue; }
  25341. if ( inPt.y === edgeLowPt.y ) {
  25342. if ( inPt.x === edgeLowPt.x ) { return true; } // inPt is on contour ?
  25343. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25344. } else {
  25345. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  25346. if ( perpEdge === 0 ) { return true; } // inPt is on contour ?
  25347. if ( perpEdge < 0 ) { continue; }
  25348. inside = ! inside; // true intersection left of inPt
  25349. }
  25350. } else {
  25351. // parallel or collinear
  25352. if ( inPt.y !== edgeLowPt.y ) { continue; } // parallel
  25353. // edge lies on the same horizontal line as inPt
  25354. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  25355. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) { return true; } // inPt: Point on contour !
  25356. // continue;
  25357. }
  25358. }
  25359. return inside;
  25360. }
  25361. var isClockWise = ShapeUtils.isClockWise;
  25362. var subPaths = this.subPaths;
  25363. if ( subPaths.length === 0 ) { return []; }
  25364. if ( noHoles === true ) { return toShapesNoHoles( subPaths ); }
  25365. var solid, tmpPath, tmpShape, shapes = [];
  25366. if ( subPaths.length === 1 ) {
  25367. tmpPath = subPaths[ 0 ];
  25368. tmpShape = new Shape();
  25369. tmpShape.curves = tmpPath.curves;
  25370. shapes.push( tmpShape );
  25371. return shapes;
  25372. }
  25373. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  25374. holesFirst = isCCW ? ! holesFirst : holesFirst;
  25375. // console.log("Holes first", holesFirst);
  25376. var betterShapeHoles = [];
  25377. var newShapes = [];
  25378. var newShapeHoles = [];
  25379. var mainIdx = 0;
  25380. var tmpPoints;
  25381. newShapes[ mainIdx ] = undefined;
  25382. newShapeHoles[ mainIdx ] = [];
  25383. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  25384. tmpPath = subPaths[ i ];
  25385. tmpPoints = tmpPath.getPoints();
  25386. solid = isClockWise( tmpPoints );
  25387. solid = isCCW ? ! solid : solid;
  25388. if ( solid ) {
  25389. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) { mainIdx ++; }
  25390. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  25391. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  25392. if ( holesFirst ) { mainIdx ++; }
  25393. newShapeHoles[ mainIdx ] = [];
  25394. //console.log('cw', i);
  25395. } else {
  25396. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  25397. //console.log('ccw', i);
  25398. }
  25399. }
  25400. // only Holes? -> probably all Shapes with wrong orientation
  25401. if ( ! newShapes[ 0 ] ) { return toShapesNoHoles( subPaths ); }
  25402. if ( newShapes.length > 1 ) {
  25403. var ambiguous = false;
  25404. var toChange = [];
  25405. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25406. betterShapeHoles[ sIdx ] = [];
  25407. }
  25408. for ( var sIdx$1 = 0, sLen$1 = newShapes.length; sIdx$1 < sLen$1; sIdx$1 ++ ) {
  25409. var sho = newShapeHoles[ sIdx$1 ];
  25410. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  25411. var ho = sho[ hIdx ];
  25412. var hole_unassigned = true;
  25413. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  25414. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  25415. if ( sIdx$1 !== s2Idx ) { toChange.push( { froms: sIdx$1, tos: s2Idx, hole: hIdx } ); }
  25416. if ( hole_unassigned ) {
  25417. hole_unassigned = false;
  25418. betterShapeHoles[ s2Idx ].push( ho );
  25419. } else {
  25420. ambiguous = true;
  25421. }
  25422. }
  25423. }
  25424. if ( hole_unassigned ) {
  25425. betterShapeHoles[ sIdx$1 ].push( ho );
  25426. }
  25427. }
  25428. }
  25429. // console.log("ambiguous: ", ambiguous);
  25430. if ( toChange.length > 0 ) {
  25431. // console.log("to change: ", toChange);
  25432. if ( ! ambiguous ) { newShapeHoles = betterShapeHoles; }
  25433. }
  25434. }
  25435. var tmpHoles;
  25436. for ( var i$1 = 0, il = newShapes.length; i$1 < il; i$1 ++ ) {
  25437. tmpShape = newShapes[ i$1 ].s;
  25438. shapes.push( tmpShape );
  25439. tmpHoles = newShapeHoles[ i$1 ];
  25440. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  25441. tmpShape.holes.push( tmpHoles[ j ].h );
  25442. }
  25443. }
  25444. //console.log("shape", shapes);
  25445. return shapes;
  25446. }
  25447. } );
  25448. /**
  25449. * @author zz85 / http://www.lab4games.net/zz85/blog
  25450. * @author mrdoob / http://mrdoob.com/
  25451. */
  25452. function Font( data ) {
  25453. this.type = 'Font';
  25454. this.data = data;
  25455. }
  25456. Object.assign( Font.prototype, {
  25457. isFont: true,
  25458. generateShapes: function ( text, size ) {
  25459. if ( size === undefined ) { size = 100; }
  25460. var shapes = [];
  25461. var paths = createPaths( text, size, this.data );
  25462. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  25463. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  25464. }
  25465. return shapes;
  25466. }
  25467. } );
  25468. function createPaths( text, size, data ) {
  25469. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // workaround for IE11, see #13988
  25470. var scale = size / data.resolution;
  25471. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  25472. var paths = [];
  25473. var offsetX = 0, offsetY = 0;
  25474. for ( var i = 0; i < chars.length; i ++ ) {
  25475. var char = chars[ i ];
  25476. if ( char === '\n' ) {
  25477. offsetX = 0;
  25478. offsetY -= line_height;
  25479. } else {
  25480. var ret = createPath( char, scale, offsetX, offsetY, data );
  25481. offsetX += ret.offsetX;
  25482. paths.push( ret.path );
  25483. }
  25484. }
  25485. return paths;
  25486. }
  25487. function createPath( char, scale, offsetX, offsetY, data ) {
  25488. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  25489. if ( ! glyph ) {
  25490. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  25491. return;
  25492. }
  25493. var path = new ShapePath();
  25494. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25495. if ( glyph.o ) {
  25496. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  25497. for ( var i = 0, l = outline.length; i < l; ) {
  25498. var action = outline[ i ++ ];
  25499. switch ( action ) {
  25500. case 'm': // moveTo
  25501. x = outline[ i ++ ] * scale + offsetX;
  25502. y = outline[ i ++ ] * scale + offsetY;
  25503. path.moveTo( x, y );
  25504. break;
  25505. case 'l': // lineTo
  25506. x = outline[ i ++ ] * scale + offsetX;
  25507. y = outline[ i ++ ] * scale + offsetY;
  25508. path.lineTo( x, y );
  25509. break;
  25510. case 'q': // quadraticCurveTo
  25511. cpx = outline[ i ++ ] * scale + offsetX;
  25512. cpy = outline[ i ++ ] * scale + offsetY;
  25513. cpx1 = outline[ i ++ ] * scale + offsetX;
  25514. cpy1 = outline[ i ++ ] * scale + offsetY;
  25515. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  25516. break;
  25517. case 'b': // bezierCurveTo
  25518. cpx = outline[ i ++ ] * scale + offsetX;
  25519. cpy = outline[ i ++ ] * scale + offsetY;
  25520. cpx1 = outline[ i ++ ] * scale + offsetX;
  25521. cpy1 = outline[ i ++ ] * scale + offsetY;
  25522. cpx2 = outline[ i ++ ] * scale + offsetX;
  25523. cpy2 = outline[ i ++ ] * scale + offsetY;
  25524. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  25525. break;
  25526. }
  25527. }
  25528. }
  25529. return { offsetX: glyph.ha * scale, path: path };
  25530. }
  25531. /**
  25532. * @author mrdoob / http://mrdoob.com/
  25533. */
  25534. function FontLoader( manager ) {
  25535. Loader.call( this, manager );
  25536. }
  25537. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25538. constructor: FontLoader,
  25539. load: function ( url, onLoad, onProgress, onError ) {
  25540. var scope = this;
  25541. var loader = new FileLoader( this.manager );
  25542. loader.setPath( this.path );
  25543. loader.load( url, function ( text ) {
  25544. var json;
  25545. try {
  25546. json = JSON.parse( text );
  25547. } catch ( e ) {
  25548. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  25549. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  25550. }
  25551. var font = scope.parse( json );
  25552. if ( onLoad ) { onLoad( font ); }
  25553. }, onProgress, onError );
  25554. },
  25555. parse: function ( json ) {
  25556. return new Font( json );
  25557. }
  25558. } );
  25559. /**
  25560. * @author mrdoob / http://mrdoob.com/
  25561. */
  25562. var _context;
  25563. var AudioContext = {
  25564. getContext: function () {
  25565. if ( _context === undefined ) {
  25566. _context = new ( window.AudioContext || window.webkitAudioContext )();
  25567. }
  25568. return _context;
  25569. },
  25570. setContext: function ( value ) {
  25571. _context = value;
  25572. }
  25573. };
  25574. /**
  25575. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25576. */
  25577. function AudioLoader( manager ) {
  25578. Loader.call( this, manager );
  25579. }
  25580. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25581. constructor: AudioLoader,
  25582. load: function ( url, onLoad, onProgress, onError ) {
  25583. var scope = this;
  25584. var loader = new FileLoader( scope.manager );
  25585. loader.setResponseType( 'arraybuffer' );
  25586. loader.setPath( scope.path );
  25587. loader.load( url, function ( buffer ) {
  25588. try {
  25589. // Create a copy of the buffer. The `decodeAudioData` method
  25590. // detaches the buffer when complete, preventing reuse.
  25591. var bufferCopy = buffer.slice( 0 );
  25592. var context = AudioContext.getContext();
  25593. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  25594. onLoad( audioBuffer );
  25595. } );
  25596. } catch ( e ) {
  25597. if ( onError ) {
  25598. onError( e );
  25599. } else {
  25600. console.error( e );
  25601. }
  25602. scope.manager.itemError( url );
  25603. }
  25604. }, onProgress, onError );
  25605. }
  25606. } );
  25607. /**
  25608. * @author WestLangley / http://github.com/WestLangley
  25609. */
  25610. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  25611. LightProbe.call( this, undefined, intensity );
  25612. var color1 = new Color().set( skyColor );
  25613. var color2 = new Color().set( groundColor );
  25614. var sky = new Vector3( color1.r, color1.g, color1.b );
  25615. var ground = new Vector3( color2.r, color2.g, color2.b );
  25616. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25617. var c0 = Math.sqrt( Math.PI );
  25618. var c1 = c0 * Math.sqrt( 0.75 );
  25619. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  25620. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  25621. }
  25622. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25623. constructor: HemisphereLightProbe,
  25624. isHemisphereLightProbe: true,
  25625. copy: function ( source ) { // modifying colors not currently supported
  25626. LightProbe.prototype.copy.call( this, source );
  25627. return this;
  25628. },
  25629. toJSON: function ( meta ) {
  25630. var data = LightProbe.prototype.toJSON.call( this, meta );
  25631. // data.sh = this.sh.toArray(); // todo
  25632. return data;
  25633. }
  25634. } );
  25635. /**
  25636. * @author WestLangley / http://github.com/WestLangley
  25637. */
  25638. function AmbientLightProbe( color, intensity ) {
  25639. LightProbe.call( this, undefined, intensity );
  25640. var color1 = new Color().set( color );
  25641. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25642. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  25643. }
  25644. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25645. constructor: AmbientLightProbe,
  25646. isAmbientLightProbe: true,
  25647. copy: function ( source ) { // modifying color not currently supported
  25648. LightProbe.prototype.copy.call( this, source );
  25649. return this;
  25650. },
  25651. toJSON: function ( meta ) {
  25652. var data = LightProbe.prototype.toJSON.call( this, meta );
  25653. // data.sh = this.sh.toArray(); // todo
  25654. return data;
  25655. }
  25656. } );
  25657. var _eyeRight = new Matrix4();
  25658. var _eyeLeft = new Matrix4();
  25659. /**
  25660. * @author mrdoob / http://mrdoob.com/
  25661. */
  25662. function StereoCamera() {
  25663. this.type = 'StereoCamera';
  25664. this.aspect = 1;
  25665. this.eyeSep = 0.064;
  25666. this.cameraL = new PerspectiveCamera();
  25667. this.cameraL.layers.enable( 1 );
  25668. this.cameraL.matrixAutoUpdate = false;
  25669. this.cameraR = new PerspectiveCamera();
  25670. this.cameraR.layers.enable( 2 );
  25671. this.cameraR.matrixAutoUpdate = false;
  25672. this._cache = {
  25673. focus: null,
  25674. fov: null,
  25675. aspect: null,
  25676. near: null,
  25677. far: null,
  25678. zoom: null,
  25679. eyeSep: null
  25680. };
  25681. }
  25682. Object.assign( StereoCamera.prototype, {
  25683. update: function ( camera ) {
  25684. var cache = this._cache;
  25685. var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  25686. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  25687. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  25688. if ( needsUpdate ) {
  25689. cache.focus = camera.focus;
  25690. cache.fov = camera.fov;
  25691. cache.aspect = camera.aspect * this.aspect;
  25692. cache.near = camera.near;
  25693. cache.far = camera.far;
  25694. cache.zoom = camera.zoom;
  25695. cache.eyeSep = this.eyeSep;
  25696. // Off-axis stereoscopic effect based on
  25697. // http://paulbourke.net/stereographics/stereorender/
  25698. var projectionMatrix = camera.projectionMatrix.clone();
  25699. var eyeSepHalf = cache.eyeSep / 2;
  25700. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25701. var ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  25702. var xmin, xmax;
  25703. // translate xOffset
  25704. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  25705. _eyeRight.elements[ 12 ] = eyeSepHalf;
  25706. // for left eye
  25707. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  25708. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25709. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25710. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25711. this.cameraL.projectionMatrix.copy( projectionMatrix );
  25712. // for right eye
  25713. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  25714. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25715. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25716. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25717. this.cameraR.projectionMatrix.copy( projectionMatrix );
  25718. }
  25719. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  25720. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  25721. }
  25722. } );
  25723. /**
  25724. * @author alteredq / http://alteredqualia.com/
  25725. */
  25726. function Clock( autoStart ) {
  25727. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25728. this.startTime = 0;
  25729. this.oldTime = 0;
  25730. this.elapsedTime = 0;
  25731. this.running = false;
  25732. }
  25733. Object.assign( Clock.prototype, {
  25734. start: function () {
  25735. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25736. this.oldTime = this.startTime;
  25737. this.elapsedTime = 0;
  25738. this.running = true;
  25739. },
  25740. stop: function () {
  25741. this.getElapsedTime();
  25742. this.running = false;
  25743. this.autoStart = false;
  25744. },
  25745. getElapsedTime: function () {
  25746. this.getDelta();
  25747. return this.elapsedTime;
  25748. },
  25749. getDelta: function () {
  25750. var diff = 0;
  25751. if ( this.autoStart && ! this.running ) {
  25752. this.start();
  25753. return 0;
  25754. }
  25755. if ( this.running ) {
  25756. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25757. diff = ( newTime - this.oldTime ) / 1000;
  25758. this.oldTime = newTime;
  25759. this.elapsedTime += diff;
  25760. }
  25761. return diff;
  25762. }
  25763. } );
  25764. /**
  25765. * @author mrdoob / http://mrdoob.com/
  25766. */
  25767. var _position$2 = new Vector3();
  25768. var _quaternion$3 = new Quaternion();
  25769. var _scale$1 = new Vector3();
  25770. var _orientation = new Vector3();
  25771. function AudioListener() {
  25772. Object3D.call( this );
  25773. this.type = 'AudioListener';
  25774. this.context = AudioContext.getContext();
  25775. this.gain = this.context.createGain();
  25776. this.gain.connect( this.context.destination );
  25777. this.filter = null;
  25778. this.timeDelta = 0;
  25779. // private
  25780. this._clock = new Clock();
  25781. }
  25782. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25783. constructor: AudioListener,
  25784. getInput: function () {
  25785. return this.gain;
  25786. },
  25787. removeFilter: function ( ) {
  25788. if ( this.filter !== null ) {
  25789. this.gain.disconnect( this.filter );
  25790. this.filter.disconnect( this.context.destination );
  25791. this.gain.connect( this.context.destination );
  25792. this.filter = null;
  25793. }
  25794. return this;
  25795. },
  25796. getFilter: function () {
  25797. return this.filter;
  25798. },
  25799. setFilter: function ( value ) {
  25800. if ( this.filter !== null ) {
  25801. this.gain.disconnect( this.filter );
  25802. this.filter.disconnect( this.context.destination );
  25803. } else {
  25804. this.gain.disconnect( this.context.destination );
  25805. }
  25806. this.filter = value;
  25807. this.gain.connect( this.filter );
  25808. this.filter.connect( this.context.destination );
  25809. return this;
  25810. },
  25811. getMasterVolume: function () {
  25812. return this.gain.gain.value;
  25813. },
  25814. setMasterVolume: function ( value ) {
  25815. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25816. return this;
  25817. },
  25818. updateMatrixWorld: function ( force ) {
  25819. Object3D.prototype.updateMatrixWorld.call( this, force );
  25820. var listener = this.context.listener;
  25821. var up = this.up;
  25822. this.timeDelta = this._clock.getDelta();
  25823. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  25824. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  25825. if ( listener.positionX ) {
  25826. // code path for Chrome (see #14393)
  25827. var endTime = this.context.currentTime + this.timeDelta;
  25828. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  25829. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  25830. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  25831. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  25832. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  25833. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  25834. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25835. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25836. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25837. } else {
  25838. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  25839. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  25840. }
  25841. }
  25842. } );
  25843. /**
  25844. * @author mrdoob / http://mrdoob.com/
  25845. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25846. */
  25847. function Audio( listener ) {
  25848. Object3D.call( this );
  25849. this.type = 'Audio';
  25850. this.listener = listener;
  25851. this.context = listener.context;
  25852. this.gain = this.context.createGain();
  25853. this.gain.connect( listener.getInput() );
  25854. this.autoplay = false;
  25855. this.buffer = null;
  25856. this.detune = 0;
  25857. this.loop = false;
  25858. this.loopStart = 0;
  25859. this.loopEnd = 0;
  25860. this.offset = 0;
  25861. this.duration = undefined;
  25862. this.playbackRate = 1;
  25863. this.isPlaying = false;
  25864. this.hasPlaybackControl = true;
  25865. this.sourceType = 'empty';
  25866. this._startedAt = 0;
  25867. this._progress = 0;
  25868. this.filters = [];
  25869. }
  25870. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25871. constructor: Audio,
  25872. getOutput: function () {
  25873. return this.gain;
  25874. },
  25875. setNodeSource: function ( audioNode ) {
  25876. this.hasPlaybackControl = false;
  25877. this.sourceType = 'audioNode';
  25878. this.source = audioNode;
  25879. this.connect();
  25880. return this;
  25881. },
  25882. setMediaElementSource: function ( mediaElement ) {
  25883. this.hasPlaybackControl = false;
  25884. this.sourceType = 'mediaNode';
  25885. this.source = this.context.createMediaElementSource( mediaElement );
  25886. this.connect();
  25887. return this;
  25888. },
  25889. setMediaStreamSource: function ( mediaStream ) {
  25890. this.hasPlaybackControl = false;
  25891. this.sourceType = 'mediaStreamNode';
  25892. this.source = this.context.createMediaStreamSource( mediaStream );
  25893. this.connect();
  25894. return this;
  25895. },
  25896. setBuffer: function ( audioBuffer ) {
  25897. this.buffer = audioBuffer;
  25898. this.sourceType = 'buffer';
  25899. if ( this.autoplay ) { this.play(); }
  25900. return this;
  25901. },
  25902. play: function ( delay ) {
  25903. if ( delay === undefined ) { delay = 0; }
  25904. if ( this.isPlaying === true ) {
  25905. console.warn( 'THREE.Audio: Audio is already playing.' );
  25906. return;
  25907. }
  25908. if ( this.hasPlaybackControl === false ) {
  25909. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25910. return;
  25911. }
  25912. this._startedAt = this.context.currentTime + delay;
  25913. var source = this.context.createBufferSource();
  25914. source.buffer = this.buffer;
  25915. source.loop = this.loop;
  25916. source.loopStart = this.loopStart;
  25917. source.loopEnd = this.loopEnd;
  25918. source.onended = this.onEnded.bind( this );
  25919. source.start( this._startedAt, this._progress + this.offset, this.duration );
  25920. this.isPlaying = true;
  25921. this.source = source;
  25922. this.setDetune( this.detune );
  25923. this.setPlaybackRate( this.playbackRate );
  25924. return this.connect();
  25925. },
  25926. pause: function () {
  25927. if ( this.hasPlaybackControl === false ) {
  25928. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25929. return;
  25930. }
  25931. if ( this.isPlaying === true ) {
  25932. // update current progress
  25933. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  25934. if ( this.loop === true ) {
  25935. // ensure _progress does not exceed duration with looped audios
  25936. this._progress = this._progress % ( this.duration || this.buffer.duration );
  25937. }
  25938. this.source.stop();
  25939. this.source.onended = null;
  25940. this.isPlaying = false;
  25941. }
  25942. return this;
  25943. },
  25944. stop: function () {
  25945. if ( this.hasPlaybackControl === false ) {
  25946. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25947. return;
  25948. }
  25949. this._progress = 0;
  25950. this.source.stop();
  25951. this.source.onended = null;
  25952. this.isPlaying = false;
  25953. return this;
  25954. },
  25955. connect: function () {
  25956. if ( this.filters.length > 0 ) {
  25957. this.source.connect( this.filters[ 0 ] );
  25958. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25959. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25960. }
  25961. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25962. } else {
  25963. this.source.connect( this.getOutput() );
  25964. }
  25965. return this;
  25966. },
  25967. disconnect: function () {
  25968. if ( this.filters.length > 0 ) {
  25969. this.source.disconnect( this.filters[ 0 ] );
  25970. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25971. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25972. }
  25973. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25974. } else {
  25975. this.source.disconnect( this.getOutput() );
  25976. }
  25977. return this;
  25978. },
  25979. getFilters: function () {
  25980. return this.filters;
  25981. },
  25982. setFilters: function ( value ) {
  25983. if ( ! value ) { value = []; }
  25984. if ( this.isPlaying === true ) {
  25985. this.disconnect();
  25986. this.filters = value;
  25987. this.connect();
  25988. } else {
  25989. this.filters = value;
  25990. }
  25991. return this;
  25992. },
  25993. setDetune: function ( value ) {
  25994. this.detune = value;
  25995. if ( this.source.detune === undefined ) { return; } // only set detune when available
  25996. if ( this.isPlaying === true ) {
  25997. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25998. }
  25999. return this;
  26000. },
  26001. getDetune: function () {
  26002. return this.detune;
  26003. },
  26004. getFilter: function () {
  26005. return this.getFilters()[ 0 ];
  26006. },
  26007. setFilter: function ( filter ) {
  26008. return this.setFilters( filter ? [ filter ] : [] );
  26009. },
  26010. setPlaybackRate: function ( value ) {
  26011. if ( this.hasPlaybackControl === false ) {
  26012. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  26013. return;
  26014. }
  26015. this.playbackRate = value;
  26016. if ( this.isPlaying === true ) {
  26017. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  26018. }
  26019. return this;
  26020. },
  26021. getPlaybackRate: function () {
  26022. return this.playbackRate;
  26023. },
  26024. onEnded: function () {
  26025. this.isPlaying = false;
  26026. },
  26027. getLoop: function () {
  26028. if ( this.hasPlaybackControl === false ) {
  26029. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  26030. return false;
  26031. }
  26032. return this.loop;
  26033. },
  26034. setLoop: function ( value ) {
  26035. if ( this.hasPlaybackControl === false ) {
  26036. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  26037. return;
  26038. }
  26039. this.loop = value;
  26040. if ( this.isPlaying === true ) {
  26041. this.source.loop = this.loop;
  26042. }
  26043. return this;
  26044. },
  26045. setLoopStart: function ( value ) {
  26046. this.loopStart = value;
  26047. return this;
  26048. },
  26049. setLoopEnd: function ( value ) {
  26050. this.loopEnd = value;
  26051. return this;
  26052. },
  26053. getVolume: function () {
  26054. return this.gain.gain.value;
  26055. },
  26056. setVolume: function ( value ) {
  26057. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  26058. return this;
  26059. }
  26060. } );
  26061. /**
  26062. * @author mrdoob / http://mrdoob.com/
  26063. */
  26064. var _position$3 = new Vector3();
  26065. var _quaternion$4 = new Quaternion();
  26066. var _scale$2 = new Vector3();
  26067. var _orientation$1 = new Vector3();
  26068. function PositionalAudio( listener ) {
  26069. Audio.call( this, listener );
  26070. this.panner = this.context.createPanner();
  26071. this.panner.panningModel = 'HRTF';
  26072. this.panner.connect( this.gain );
  26073. }
  26074. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  26075. constructor: PositionalAudio,
  26076. getOutput: function () {
  26077. return this.panner;
  26078. },
  26079. getRefDistance: function () {
  26080. return this.panner.refDistance;
  26081. },
  26082. setRefDistance: function ( value ) {
  26083. this.panner.refDistance = value;
  26084. return this;
  26085. },
  26086. getRolloffFactor: function () {
  26087. return this.panner.rolloffFactor;
  26088. },
  26089. setRolloffFactor: function ( value ) {
  26090. this.panner.rolloffFactor = value;
  26091. return this;
  26092. },
  26093. getDistanceModel: function () {
  26094. return this.panner.distanceModel;
  26095. },
  26096. setDistanceModel: function ( value ) {
  26097. this.panner.distanceModel = value;
  26098. return this;
  26099. },
  26100. getMaxDistance: function () {
  26101. return this.panner.maxDistance;
  26102. },
  26103. setMaxDistance: function ( value ) {
  26104. this.panner.maxDistance = value;
  26105. return this;
  26106. },
  26107. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  26108. this.panner.coneInnerAngle = coneInnerAngle;
  26109. this.panner.coneOuterAngle = coneOuterAngle;
  26110. this.panner.coneOuterGain = coneOuterGain;
  26111. return this;
  26112. },
  26113. updateMatrixWorld: function ( force ) {
  26114. Object3D.prototype.updateMatrixWorld.call( this, force );
  26115. if ( this.hasPlaybackControl === true && this.isPlaying === false ) { return; }
  26116. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  26117. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  26118. var panner = this.panner;
  26119. if ( panner.positionX ) {
  26120. // code path for Chrome and Firefox (see #14393)
  26121. var endTime = this.context.currentTime + this.listener.timeDelta;
  26122. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  26123. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  26124. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  26125. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  26126. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  26127. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  26128. } else {
  26129. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  26130. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  26131. }
  26132. }
  26133. } );
  26134. /**
  26135. * @author mrdoob / http://mrdoob.com/
  26136. */
  26137. function AudioAnalyser( audio, fftSize ) {
  26138. this.analyser = audio.context.createAnalyser();
  26139. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  26140. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  26141. audio.getOutput().connect( this.analyser );
  26142. }
  26143. Object.assign( AudioAnalyser.prototype, {
  26144. getFrequencyData: function () {
  26145. this.analyser.getByteFrequencyData( this.data );
  26146. return this.data;
  26147. },
  26148. getAverageFrequency: function () {
  26149. var value = 0;
  26150. var data = this.getFrequencyData();
  26151. for ( var i = 0; i < data.length; i ++ ) {
  26152. value += data[ i ];
  26153. }
  26154. return value / data.length;
  26155. }
  26156. } );
  26157. /**
  26158. *
  26159. * Buffered scene graph property that allows weighted accumulation.
  26160. *
  26161. *
  26162. * @author Ben Houston / http://clara.io/
  26163. * @author David Sarno / http://lighthaus.us/
  26164. * @author tschw
  26165. */
  26166. function PropertyMixer( binding, typeName, valueSize ) {
  26167. this.binding = binding;
  26168. this.valueSize = valueSize;
  26169. var mixFunction,
  26170. mixFunctionAdditive,
  26171. setIdentity;
  26172. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  26173. //
  26174. // interpolators can use .buffer as their .result
  26175. // the data then goes to 'incoming'
  26176. //
  26177. // 'accu0' and 'accu1' are used frame-interleaved for
  26178. // the cumulative result and are compared to detect
  26179. // changes
  26180. //
  26181. // 'orig' stores the original state of the property
  26182. //
  26183. // 'add' is used for additive cumulative results
  26184. //
  26185. // 'work' is optional and is only present for quaternion types. It is used
  26186. // to store intermediate quaternion multiplication results
  26187. switch ( typeName ) {
  26188. case 'quaternion':
  26189. mixFunction = this._slerp;
  26190. mixFunctionAdditive = this._slerpAdditive;
  26191. setIdentity = this._setAdditiveIdentityQuaternion;
  26192. this.buffer = new Float64Array( valueSize * 6 );
  26193. this._workIndex = 5;
  26194. break;
  26195. case 'string':
  26196. case 'bool':
  26197. mixFunction = this._select;
  26198. // Use the regular mix function and for additive on these types,
  26199. // additive is not relevant for non-numeric types
  26200. mixFunctionAdditive = this._select;
  26201. setIdentity = this._setAdditiveIdentityOther;
  26202. this.buffer = new Array( valueSize * 5 );
  26203. break;
  26204. default:
  26205. mixFunction = this._lerp;
  26206. mixFunctionAdditive = this._lerpAdditive;
  26207. setIdentity = this._setAdditiveIdentityNumeric;
  26208. this.buffer = new Float64Array( valueSize * 5 );
  26209. }
  26210. this._mixBufferRegion = mixFunction;
  26211. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26212. this._setIdentity = setIdentity;
  26213. this._origIndex = 3;
  26214. this._addIndex = 4;
  26215. this.cumulativeWeight = 0;
  26216. this.cumulativeWeightAdditive = 0;
  26217. this.useCount = 0;
  26218. this.referenceCount = 0;
  26219. }
  26220. Object.assign( PropertyMixer.prototype, {
  26221. // accumulate data in the 'incoming' region into 'accu<i>'
  26222. accumulate: function ( accuIndex, weight ) {
  26223. // note: happily accumulating nothing when weight = 0, the caller knows
  26224. // the weight and shouldn't have made the call in the first place
  26225. var buffer = this.buffer,
  26226. stride = this.valueSize,
  26227. offset = accuIndex * stride + stride;
  26228. var currentWeight = this.cumulativeWeight;
  26229. if ( currentWeight === 0 ) {
  26230. // accuN := incoming * weight
  26231. for ( var i = 0; i !== stride; ++ i ) {
  26232. buffer[ offset + i ] = buffer[ i ];
  26233. }
  26234. currentWeight = weight;
  26235. } else {
  26236. // accuN := accuN + incoming * weight
  26237. currentWeight += weight;
  26238. var mix = weight / currentWeight;
  26239. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  26240. }
  26241. this.cumulativeWeight = currentWeight;
  26242. },
  26243. // accumulate data in the 'incoming' region into 'add'
  26244. accumulateAdditive: function ( weight ) {
  26245. var buffer = this.buffer,
  26246. stride = this.valueSize,
  26247. offset = stride * this._addIndex;
  26248. if ( this.cumulativeWeightAdditive === 0 ) {
  26249. // add = identity
  26250. this._setIdentity();
  26251. }
  26252. // add := add + incoming * weight
  26253. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  26254. this.cumulativeWeightAdditive += weight;
  26255. },
  26256. // apply the state of 'accu<i>' to the binding when accus differ
  26257. apply: function ( accuIndex ) {
  26258. var stride = this.valueSize,
  26259. buffer = this.buffer,
  26260. offset = accuIndex * stride + stride,
  26261. weight = this.cumulativeWeight,
  26262. weightAdditive = this.cumulativeWeightAdditive,
  26263. binding = this.binding;
  26264. this.cumulativeWeight = 0;
  26265. this.cumulativeWeightAdditive = 0;
  26266. if ( weight < 1 ) {
  26267. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26268. var originalValueOffset = stride * this._origIndex;
  26269. this._mixBufferRegion(
  26270. buffer, offset, originalValueOffset, 1 - weight, stride );
  26271. }
  26272. if ( weightAdditive > 0 ) {
  26273. // accuN := accuN + additive accuN
  26274. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  26275. }
  26276. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  26277. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  26278. // value has changed -> update scene graph
  26279. binding.setValue( buffer, offset );
  26280. break;
  26281. }
  26282. }
  26283. },
  26284. // remember the state of the bound property and copy it to both accus
  26285. saveOriginalState: function () {
  26286. var binding = this.binding;
  26287. var buffer = this.buffer,
  26288. stride = this.valueSize,
  26289. originalValueOffset = stride * this._origIndex;
  26290. binding.getValue( buffer, originalValueOffset );
  26291. // accu[0..1] := orig -- initially detect changes against the original
  26292. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  26293. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  26294. }
  26295. // Add to identity for additive
  26296. this._setIdentity();
  26297. this.cumulativeWeight = 0;
  26298. this.cumulativeWeightAdditive = 0;
  26299. },
  26300. // apply the state previously taken via 'saveOriginalState' to the binding
  26301. restoreOriginalState: function () {
  26302. var originalValueOffset = this.valueSize * 3;
  26303. this.binding.setValue( this.buffer, originalValueOffset );
  26304. },
  26305. _setAdditiveIdentityNumeric: function () {
  26306. var startIndex = this._addIndex * this.valueSize;
  26307. var endIndex = startIndex + this.valueSize;
  26308. for ( var i = startIndex; i < endIndex; i ++ ) {
  26309. this.buffer[ i ] = 0;
  26310. }
  26311. },
  26312. _setAdditiveIdentityQuaternion: function () {
  26313. this._setAdditiveIdentityNumeric();
  26314. this.buffer[ this._addIndex * 4 + 3 ] = 1;
  26315. },
  26316. _setAdditiveIdentityOther: function () {
  26317. var startIndex = this._origIndex * this.valueSize;
  26318. var targetIndex = this._addIndex * this.valueSize;
  26319. for ( var i = 0; i < this.valueSize; i ++ ) {
  26320. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  26321. }
  26322. },
  26323. // mix functions
  26324. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26325. if ( t >= 0.5 ) {
  26326. for ( var i = 0; i !== stride; ++ i ) {
  26327. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  26328. }
  26329. }
  26330. },
  26331. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  26332. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  26333. },
  26334. _slerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26335. var workOffset = this._workIndex * stride;
  26336. // Store result in intermediate buffer offset
  26337. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  26338. // Slerp to the intermediate result
  26339. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  26340. },
  26341. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26342. var s = 1 - t;
  26343. for ( var i = 0; i !== stride; ++ i ) {
  26344. var j = dstOffset + i;
  26345. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  26346. }
  26347. },
  26348. _lerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26349. for ( var i = 0; i !== stride; ++ i ) {
  26350. var j = dstOffset + i;
  26351. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  26352. }
  26353. }
  26354. } );
  26355. /**
  26356. *
  26357. * A reference to a real property in the scene graph.
  26358. *
  26359. *
  26360. * @author Ben Houston / http://clara.io/
  26361. * @author David Sarno / http://lighthaus.us/
  26362. * @author tschw
  26363. */
  26364. // Characters [].:/ are reserved for track binding syntax.
  26365. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26366. var _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  26367. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26368. // only latin characters, and the unicode \p{L} is not yet supported. So
  26369. // instead, we exclude reserved characters and match everything else.
  26370. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26371. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  26372. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26373. // be matched to parse the rest of the track name.
  26374. var _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  26375. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26376. var _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  26377. // Object on target node, and accessor. May not contain reserved
  26378. // characters. Accessor may contain any character except closing bracket.
  26379. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  26380. // Property and accessor. May not contain reserved characters. Accessor may
  26381. // contain any non-bracket characters.
  26382. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  26383. var _trackRe = new RegExp( ''
  26384. + '^'
  26385. + _directoryRe
  26386. + _nodeRe
  26387. + _objectRe
  26388. + _propertyRe
  26389. + '$'
  26390. );
  26391. var _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  26392. function Composite( targetGroup, path, optionalParsedPath ) {
  26393. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  26394. this._targetGroup = targetGroup;
  26395. this._bindings = targetGroup.subscribe_( path, parsedPath );
  26396. }
  26397. Object.assign( Composite.prototype, {
  26398. getValue: function ( array, offset ) {
  26399. this.bind(); // bind all binding
  26400. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26401. binding = this._bindings[ firstValidIndex ];
  26402. // and only call .getValue on the first
  26403. if ( binding !== undefined ) { binding.getValue( array, offset ); }
  26404. },
  26405. setValue: function ( array, offset ) {
  26406. var bindings = this._bindings;
  26407. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26408. bindings[ i ].setValue( array, offset );
  26409. }
  26410. },
  26411. bind: function () {
  26412. var bindings = this._bindings;
  26413. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26414. bindings[ i ].bind();
  26415. }
  26416. },
  26417. unbind: function () {
  26418. var bindings = this._bindings;
  26419. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26420. bindings[ i ].unbind();
  26421. }
  26422. }
  26423. } );
  26424. function PropertyBinding( rootNode, path, parsedPath ) {
  26425. this.path = path;
  26426. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  26427. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  26428. this.rootNode = rootNode;
  26429. }
  26430. Object.assign( PropertyBinding, {
  26431. Composite: Composite,
  26432. create: function ( root, path, parsedPath ) {
  26433. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  26434. return new PropertyBinding( root, path, parsedPath );
  26435. } else {
  26436. return new PropertyBinding.Composite( root, path, parsedPath );
  26437. }
  26438. },
  26439. /**
  26440. * Replaces spaces with underscores and removes unsupported characters from
  26441. * node names, to ensure compatibility with parseTrackName().
  26442. *
  26443. * @param {string} name Node name to be sanitized.
  26444. * @return {string}
  26445. */
  26446. sanitizeNodeName: function ( name ) {
  26447. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  26448. },
  26449. parseTrackName: function ( trackName ) {
  26450. var matches = _trackRe.exec( trackName );
  26451. if ( ! matches ) {
  26452. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  26453. }
  26454. var results = {
  26455. // directoryName: matches[ 1 ], // (tschw) currently unused
  26456. nodeName: matches[ 2 ],
  26457. objectName: matches[ 3 ],
  26458. objectIndex: matches[ 4 ],
  26459. propertyName: matches[ 5 ], // required
  26460. propertyIndex: matches[ 6 ]
  26461. };
  26462. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  26463. if ( lastDot !== undefined && lastDot !== - 1 ) {
  26464. var objectName = results.nodeName.substring( lastDot + 1 );
  26465. // Object names must be checked against an allowlist. Otherwise, there
  26466. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26467. // 'bar' could be the objectName, or part of a nodeName (which can
  26468. // include '.' characters).
  26469. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  26470. results.nodeName = results.nodeName.substring( 0, lastDot );
  26471. results.objectName = objectName;
  26472. }
  26473. }
  26474. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  26475. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  26476. }
  26477. return results;
  26478. },
  26479. findNode: function ( root, nodeName ) {
  26480. if ( ! nodeName || nodeName === "" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  26481. return root;
  26482. }
  26483. // search into skeleton bones.
  26484. if ( root.skeleton ) {
  26485. var bone = root.skeleton.getBoneByName( nodeName );
  26486. if ( bone !== undefined ) {
  26487. return bone;
  26488. }
  26489. }
  26490. // search into node subtree.
  26491. if ( root.children ) {
  26492. var searchNodeSubtree = function ( children ) {
  26493. for ( var i = 0; i < children.length; i ++ ) {
  26494. var childNode = children[ i ];
  26495. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  26496. return childNode;
  26497. }
  26498. var result = searchNodeSubtree( childNode.children );
  26499. if ( result ) { return result; }
  26500. }
  26501. return null;
  26502. };
  26503. var subTreeNode = searchNodeSubtree( root.children );
  26504. if ( subTreeNode ) {
  26505. return subTreeNode;
  26506. }
  26507. }
  26508. return null;
  26509. }
  26510. } );
  26511. Object.assign( PropertyBinding.prototype, { // prototype, continued
  26512. // these are used to "bind" a nonexistent property
  26513. _getValue_unavailable: function () {},
  26514. _setValue_unavailable: function () {},
  26515. BindingType: {
  26516. Direct: 0,
  26517. EntireArray: 1,
  26518. ArrayElement: 2,
  26519. HasFromToArray: 3
  26520. },
  26521. Versioning: {
  26522. None: 0,
  26523. NeedsUpdate: 1,
  26524. MatrixWorldNeedsUpdate: 2
  26525. },
  26526. GetterByBindingType: [
  26527. function getValue_direct( buffer, offset ) {
  26528. buffer[ offset ] = this.node[ this.propertyName ];
  26529. },
  26530. function getValue_array( buffer, offset ) {
  26531. var source = this.resolvedProperty;
  26532. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  26533. buffer[ offset ++ ] = source[ i ];
  26534. }
  26535. },
  26536. function getValue_arrayElement( buffer, offset ) {
  26537. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  26538. },
  26539. function getValue_toArray( buffer, offset ) {
  26540. this.resolvedProperty.toArray( buffer, offset );
  26541. }
  26542. ],
  26543. SetterByBindingTypeAndVersioning: [
  26544. [
  26545. // Direct
  26546. function setValue_direct( buffer, offset ) {
  26547. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26548. },
  26549. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  26550. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26551. this.targetObject.needsUpdate = true;
  26552. },
  26553. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26554. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26555. this.targetObject.matrixWorldNeedsUpdate = true;
  26556. }
  26557. ], [
  26558. // EntireArray
  26559. function setValue_array( buffer, offset ) {
  26560. var dest = this.resolvedProperty;
  26561. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26562. dest[ i ] = buffer[ offset ++ ];
  26563. }
  26564. },
  26565. function setValue_array_setNeedsUpdate( buffer, offset ) {
  26566. var dest = this.resolvedProperty;
  26567. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26568. dest[ i ] = buffer[ offset ++ ];
  26569. }
  26570. this.targetObject.needsUpdate = true;
  26571. },
  26572. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26573. var dest = this.resolvedProperty;
  26574. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26575. dest[ i ] = buffer[ offset ++ ];
  26576. }
  26577. this.targetObject.matrixWorldNeedsUpdate = true;
  26578. }
  26579. ], [
  26580. // ArrayElement
  26581. function setValue_arrayElement( buffer, offset ) {
  26582. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26583. },
  26584. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  26585. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26586. this.targetObject.needsUpdate = true;
  26587. },
  26588. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26589. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26590. this.targetObject.matrixWorldNeedsUpdate = true;
  26591. }
  26592. ], [
  26593. // HasToFromArray
  26594. function setValue_fromArray( buffer, offset ) {
  26595. this.resolvedProperty.fromArray( buffer, offset );
  26596. },
  26597. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  26598. this.resolvedProperty.fromArray( buffer, offset );
  26599. this.targetObject.needsUpdate = true;
  26600. },
  26601. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26602. this.resolvedProperty.fromArray( buffer, offset );
  26603. this.targetObject.matrixWorldNeedsUpdate = true;
  26604. }
  26605. ]
  26606. ],
  26607. getValue: function getValue_unbound( targetArray, offset ) {
  26608. this.bind();
  26609. this.getValue( targetArray, offset );
  26610. // Note: This class uses a State pattern on a per-method basis:
  26611. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26612. // prototype version of these methods with one that represents
  26613. // the bound state. When the property is not found, the methods
  26614. // become no-ops.
  26615. },
  26616. setValue: function getValue_unbound( sourceArray, offset ) {
  26617. this.bind();
  26618. this.setValue( sourceArray, offset );
  26619. },
  26620. // create getter / setter pair for a property in the scene graph
  26621. bind: function () {
  26622. var targetObject = this.node,
  26623. parsedPath = this.parsedPath,
  26624. objectName = parsedPath.objectName,
  26625. propertyName = parsedPath.propertyName,
  26626. propertyIndex = parsedPath.propertyIndex;
  26627. if ( ! targetObject ) {
  26628. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  26629. this.node = targetObject;
  26630. }
  26631. // set fail state so we can just 'return' on error
  26632. this.getValue = this._getValue_unavailable;
  26633. this.setValue = this._setValue_unavailable;
  26634. // ensure there is a value node
  26635. if ( ! targetObject ) {
  26636. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  26637. return;
  26638. }
  26639. if ( objectName ) {
  26640. var objectIndex = parsedPath.objectIndex;
  26641. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26642. switch ( objectName ) {
  26643. case 'materials':
  26644. if ( ! targetObject.material ) {
  26645. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  26646. return;
  26647. }
  26648. if ( ! targetObject.material.materials ) {
  26649. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  26650. return;
  26651. }
  26652. targetObject = targetObject.material.materials;
  26653. break;
  26654. case 'bones':
  26655. if ( ! targetObject.skeleton ) {
  26656. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  26657. return;
  26658. }
  26659. // potential future optimization: skip this if propertyIndex is already an integer
  26660. // and convert the integer string to a true integer.
  26661. targetObject = targetObject.skeleton.bones;
  26662. // support resolving morphTarget names into indices.
  26663. for ( var i = 0; i < targetObject.length; i ++ ) {
  26664. if ( targetObject[ i ].name === objectIndex ) {
  26665. objectIndex = i;
  26666. break;
  26667. }
  26668. }
  26669. break;
  26670. default:
  26671. if ( targetObject[ objectName ] === undefined ) {
  26672. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  26673. return;
  26674. }
  26675. targetObject = targetObject[ objectName ];
  26676. }
  26677. if ( objectIndex !== undefined ) {
  26678. if ( targetObject[ objectIndex ] === undefined ) {
  26679. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  26680. return;
  26681. }
  26682. targetObject = targetObject[ objectIndex ];
  26683. }
  26684. }
  26685. // resolve property
  26686. var nodeProperty = targetObject[ propertyName ];
  26687. if ( nodeProperty === undefined ) {
  26688. var nodeName = parsedPath.nodeName;
  26689. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  26690. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  26691. return;
  26692. }
  26693. // determine versioning scheme
  26694. var versioning = this.Versioning.None;
  26695. this.targetObject = targetObject;
  26696. if ( targetObject.needsUpdate !== undefined ) { // material
  26697. versioning = this.Versioning.NeedsUpdate;
  26698. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  26699. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26700. }
  26701. // determine how the property gets bound
  26702. var bindingType = this.BindingType.Direct;
  26703. if ( propertyIndex !== undefined ) {
  26704. // access a sub element of the property array (only primitives are supported right now)
  26705. if ( propertyName === "morphTargetInfluences" ) {
  26706. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26707. // support resolving morphTarget names into indices.
  26708. if ( ! targetObject.geometry ) {
  26709. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  26710. return;
  26711. }
  26712. if ( targetObject.geometry.isBufferGeometry ) {
  26713. if ( ! targetObject.geometry.morphAttributes ) {
  26714. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  26715. return;
  26716. }
  26717. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  26718. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  26719. }
  26720. } else {
  26721. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  26722. return;
  26723. }
  26724. }
  26725. bindingType = this.BindingType.ArrayElement;
  26726. this.resolvedProperty = nodeProperty;
  26727. this.propertyIndex = propertyIndex;
  26728. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  26729. // must use copy for Object3D.Euler/Quaternion
  26730. bindingType = this.BindingType.HasFromToArray;
  26731. this.resolvedProperty = nodeProperty;
  26732. } else if ( Array.isArray( nodeProperty ) ) {
  26733. bindingType = this.BindingType.EntireArray;
  26734. this.resolvedProperty = nodeProperty;
  26735. } else {
  26736. this.propertyName = propertyName;
  26737. }
  26738. // select getter / setter
  26739. this.getValue = this.GetterByBindingType[ bindingType ];
  26740. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  26741. },
  26742. unbind: function () {
  26743. this.node = null;
  26744. // back to the prototype version of getValue / setValue
  26745. // note: avoiding to mutate the shape of 'this' via 'delete'
  26746. this.getValue = this._getValue_unbound;
  26747. this.setValue = this._setValue_unbound;
  26748. }
  26749. } );
  26750. // DECLARE ALIAS AFTER assign prototype
  26751. Object.assign( PropertyBinding.prototype, {
  26752. // initial state of these methods that calls 'bind'
  26753. _getValue_unbound: PropertyBinding.prototype.getValue,
  26754. _setValue_unbound: PropertyBinding.prototype.setValue,
  26755. } );
  26756. /**
  26757. *
  26758. * A group of objects that receives a shared animation state.
  26759. *
  26760. * Usage:
  26761. *
  26762. * - Add objects you would otherwise pass as 'root' to the
  26763. * constructor or the .clipAction method of AnimationMixer.
  26764. *
  26765. * - Instead pass this object as 'root'.
  26766. *
  26767. * - You can also add and remove objects later when the mixer
  26768. * is running.
  26769. *
  26770. * Note:
  26771. *
  26772. * Objects of this class appear as one object to the mixer,
  26773. * so cache control of the individual objects must be done
  26774. * on the group.
  26775. *
  26776. * Limitation:
  26777. *
  26778. * - The animated properties must be compatible among the
  26779. * all objects in the group.
  26780. *
  26781. * - A single property can either be controlled through a
  26782. * target group or directly, but not both.
  26783. *
  26784. * @author tschw
  26785. */
  26786. function AnimationObjectGroup() {
  26787. this.uuid = MathUtils.generateUUID();
  26788. // cached objects followed by the active ones
  26789. this._objects = Array.prototype.slice.call( arguments );
  26790. this.nCachedObjects_ = 0; // threshold
  26791. // note: read by PropertyBinding.Composite
  26792. var indices = {};
  26793. this._indicesByUUID = indices; // for bookkeeping
  26794. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26795. indices[ arguments[ i ].uuid ] = i;
  26796. }
  26797. this._paths = []; // inside: string
  26798. this._parsedPaths = []; // inside: { we don't care, here }
  26799. this._bindings = []; // inside: Array< PropertyBinding >
  26800. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26801. var scope = this;
  26802. this.stats = {
  26803. objects: {
  26804. get total() {
  26805. return scope._objects.length;
  26806. },
  26807. get inUse() {
  26808. return this.total - scope.nCachedObjects_;
  26809. }
  26810. },
  26811. get bindingsPerObject() {
  26812. return scope._bindings.length;
  26813. }
  26814. };
  26815. }
  26816. Object.assign( AnimationObjectGroup.prototype, {
  26817. isAnimationObjectGroup: true,
  26818. add: function () {
  26819. var objects = this._objects,
  26820. indicesByUUID = this._indicesByUUID,
  26821. paths = this._paths,
  26822. parsedPaths = this._parsedPaths,
  26823. bindings = this._bindings,
  26824. nBindings = bindings.length;
  26825. var knownObject = undefined,
  26826. nObjects = objects.length,
  26827. nCachedObjects = this.nCachedObjects_;
  26828. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26829. var object = arguments[ i ],
  26830. uuid = object.uuid;
  26831. var index = indicesByUUID[ uuid ];
  26832. if ( index === undefined ) {
  26833. // unknown object -> add it to the ACTIVE region
  26834. index = nObjects ++;
  26835. indicesByUUID[ uuid ] = index;
  26836. objects.push( object );
  26837. // accounting is done, now do the same for all bindings
  26838. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26839. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26840. }
  26841. } else if ( index < nCachedObjects ) {
  26842. knownObject = objects[ index ];
  26843. // move existing object to the ACTIVE region
  26844. var firstActiveIndex = -- nCachedObjects,
  26845. lastCachedObject = objects[ firstActiveIndex ];
  26846. indicesByUUID[ lastCachedObject.uuid ] = index;
  26847. objects[ index ] = lastCachedObject;
  26848. indicesByUUID[ uuid ] = firstActiveIndex;
  26849. objects[ firstActiveIndex ] = object;
  26850. // accounting is done, now do the same for all bindings
  26851. for ( var j$1 = 0, m$1 = nBindings; j$1 !== m$1; ++ j$1 ) {
  26852. var bindingsForPath = bindings[ j$1 ],
  26853. lastCached = bindingsForPath[ firstActiveIndex ];
  26854. var binding = bindingsForPath[ index ];
  26855. bindingsForPath[ index ] = lastCached;
  26856. if ( binding === undefined ) {
  26857. // since we do not bother to create new bindings
  26858. // for objects that are cached, the binding may
  26859. // or may not exist
  26860. binding = new PropertyBinding( object, paths[ j$1 ], parsedPaths[ j$1 ] );
  26861. }
  26862. bindingsForPath[ firstActiveIndex ] = binding;
  26863. }
  26864. } else if ( objects[ index ] !== knownObject ) {
  26865. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26866. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26867. } // else the object is already where we want it to be
  26868. } // for arguments
  26869. this.nCachedObjects_ = nCachedObjects;
  26870. },
  26871. remove: function () {
  26872. var objects = this._objects,
  26873. indicesByUUID = this._indicesByUUID,
  26874. bindings = this._bindings,
  26875. nBindings = bindings.length;
  26876. var nCachedObjects = this.nCachedObjects_;
  26877. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26878. var object = arguments[ i ],
  26879. uuid = object.uuid,
  26880. index = indicesByUUID[ uuid ];
  26881. if ( index !== undefined && index >= nCachedObjects ) {
  26882. // move existing object into the CACHED region
  26883. var lastCachedIndex = nCachedObjects ++,
  26884. firstActiveObject = objects[ lastCachedIndex ];
  26885. indicesByUUID[ firstActiveObject.uuid ] = index;
  26886. objects[ index ] = firstActiveObject;
  26887. indicesByUUID[ uuid ] = lastCachedIndex;
  26888. objects[ lastCachedIndex ] = object;
  26889. // accounting is done, now do the same for all bindings
  26890. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26891. var bindingsForPath = bindings[ j ],
  26892. firstActive = bindingsForPath[ lastCachedIndex ],
  26893. binding = bindingsForPath[ index ];
  26894. bindingsForPath[ index ] = firstActive;
  26895. bindingsForPath[ lastCachedIndex ] = binding;
  26896. }
  26897. }
  26898. } // for arguments
  26899. this.nCachedObjects_ = nCachedObjects;
  26900. },
  26901. // remove & forget
  26902. uncache: function () {
  26903. var objects = this._objects,
  26904. indicesByUUID = this._indicesByUUID,
  26905. bindings = this._bindings,
  26906. nBindings = bindings.length;
  26907. var nCachedObjects = this.nCachedObjects_,
  26908. nObjects = objects.length;
  26909. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26910. var object = arguments[ i ],
  26911. uuid = object.uuid,
  26912. index = indicesByUUID[ uuid ];
  26913. if ( index !== undefined ) {
  26914. delete indicesByUUID[ uuid ];
  26915. if ( index < nCachedObjects ) {
  26916. // object is cached, shrink the CACHED region
  26917. var firstActiveIndex = -- nCachedObjects,
  26918. lastCachedObject = objects[ firstActiveIndex ],
  26919. lastIndex = -- nObjects,
  26920. lastObject = objects[ lastIndex ];
  26921. // last cached object takes this object's place
  26922. indicesByUUID[ lastCachedObject.uuid ] = index;
  26923. objects[ index ] = lastCachedObject;
  26924. // last object goes to the activated slot and pop
  26925. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26926. objects[ firstActiveIndex ] = lastObject;
  26927. objects.pop();
  26928. // accounting is done, now do the same for all bindings
  26929. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26930. var bindingsForPath = bindings[ j ],
  26931. lastCached = bindingsForPath[ firstActiveIndex ],
  26932. last = bindingsForPath[ lastIndex ];
  26933. bindingsForPath[ index ] = lastCached;
  26934. bindingsForPath[ firstActiveIndex ] = last;
  26935. bindingsForPath.pop();
  26936. }
  26937. } else {
  26938. // object is active, just swap with the last and pop
  26939. var lastIndex$1 = -- nObjects,
  26940. lastObject$1 = objects[ lastIndex$1 ];
  26941. indicesByUUID[ lastObject$1.uuid ] = index;
  26942. objects[ index ] = lastObject$1;
  26943. objects.pop();
  26944. // accounting is done, now do the same for all bindings
  26945. for ( var j$1 = 0, m$1 = nBindings; j$1 !== m$1; ++ j$1 ) {
  26946. var bindingsForPath$1 = bindings[ j$1 ];
  26947. bindingsForPath$1[ index ] = bindingsForPath$1[ lastIndex$1 ];
  26948. bindingsForPath$1.pop();
  26949. }
  26950. } // cached or active
  26951. } // if object is known
  26952. } // for arguments
  26953. this.nCachedObjects_ = nCachedObjects;
  26954. },
  26955. // Internal interface used by befriended PropertyBinding.Composite:
  26956. subscribe_: function ( path, parsedPath ) {
  26957. // returns an array of bindings for the given path that is changed
  26958. // according to the contained objects in the group
  26959. var indicesByPath = this._bindingsIndicesByPath,
  26960. index = indicesByPath[ path ],
  26961. bindings = this._bindings;
  26962. if ( index !== undefined ) { return bindings[ index ]; }
  26963. var paths = this._paths,
  26964. parsedPaths = this._parsedPaths,
  26965. objects = this._objects,
  26966. nObjects = objects.length,
  26967. nCachedObjects = this.nCachedObjects_,
  26968. bindingsForPath = new Array( nObjects );
  26969. index = bindings.length;
  26970. indicesByPath[ path ] = index;
  26971. paths.push( path );
  26972. parsedPaths.push( parsedPath );
  26973. bindings.push( bindingsForPath );
  26974. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26975. var object = objects[ i ];
  26976. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26977. }
  26978. return bindingsForPath;
  26979. },
  26980. unsubscribe_: function ( path ) {
  26981. // tells the group to forget about a property path and no longer
  26982. // update the array previously obtained with 'subscribe_'
  26983. var indicesByPath = this._bindingsIndicesByPath,
  26984. index = indicesByPath[ path ];
  26985. if ( index !== undefined ) {
  26986. var paths = this._paths,
  26987. parsedPaths = this._parsedPaths,
  26988. bindings = this._bindings,
  26989. lastBindingsIndex = bindings.length - 1,
  26990. lastBindings = bindings[ lastBindingsIndex ],
  26991. lastBindingsPath = path[ lastBindingsIndex ];
  26992. indicesByPath[ lastBindingsPath ] = index;
  26993. bindings[ index ] = lastBindings;
  26994. bindings.pop();
  26995. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26996. parsedPaths.pop();
  26997. paths[ index ] = paths[ lastBindingsIndex ];
  26998. paths.pop();
  26999. }
  27000. }
  27001. } );
  27002. /**
  27003. *
  27004. * Action provided by AnimationMixer for scheduling clip playback on specific
  27005. * objects.
  27006. *
  27007. * @author Ben Houston / http://clara.io/
  27008. * @author David Sarno / http://lighthaus.us/
  27009. * @author tschw
  27010. *
  27011. */
  27012. function AnimationAction( mixer, clip, localRoot, blendMode ) {
  27013. this._mixer = mixer;
  27014. this._clip = clip;
  27015. this._localRoot = localRoot || null;
  27016. this.blendMode = blendMode || clip.blendMode;
  27017. var tracks = clip.tracks,
  27018. nTracks = tracks.length,
  27019. interpolants = new Array( nTracks );
  27020. var interpolantSettings = {
  27021. endingStart: ZeroCurvatureEnding,
  27022. endingEnd: ZeroCurvatureEnding
  27023. };
  27024. for ( var i = 0; i !== nTracks; ++ i ) {
  27025. var interpolant = tracks[ i ].createInterpolant( null );
  27026. interpolants[ i ] = interpolant;
  27027. interpolant.settings = interpolantSettings;
  27028. }
  27029. this._interpolantSettings = interpolantSettings;
  27030. this._interpolants = interpolants; // bound by the mixer
  27031. // inside: PropertyMixer (managed by the mixer)
  27032. this._propertyBindings = new Array( nTracks );
  27033. this._cacheIndex = null; // for the memory manager
  27034. this._byClipCacheIndex = null; // for the memory manager
  27035. this._timeScaleInterpolant = null;
  27036. this._weightInterpolant = null;
  27037. this.loop = LoopRepeat;
  27038. this._loopCount = - 1;
  27039. // global mixer time when the action is to be started
  27040. // it's set back to 'null' upon start of the action
  27041. this._startTime = null;
  27042. // scaled local time of the action
  27043. // gets clamped or wrapped to 0..clip.duration according to loop
  27044. this.time = 0;
  27045. this.timeScale = 1;
  27046. this._effectiveTimeScale = 1;
  27047. this.weight = 1;
  27048. this._effectiveWeight = 1;
  27049. this.repetitions = Infinity; // no. of repetitions when looping
  27050. this.paused = false; // true -> zero effective time scale
  27051. this.enabled = true; // false -> zero effective weight
  27052. this.clampWhenFinished = false;// keep feeding the last frame?
  27053. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  27054. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  27055. }
  27056. Object.assign( AnimationAction.prototype, {
  27057. // State & Scheduling
  27058. play: function () {
  27059. this._mixer._activateAction( this );
  27060. return this;
  27061. },
  27062. stop: function () {
  27063. this._mixer._deactivateAction( this );
  27064. return this.reset();
  27065. },
  27066. reset: function () {
  27067. this.paused = false;
  27068. this.enabled = true;
  27069. this.time = 0; // restart clip
  27070. this._loopCount = - 1;// forget previous loops
  27071. this._startTime = null;// forget scheduling
  27072. return this.stopFading().stopWarping();
  27073. },
  27074. isRunning: function () {
  27075. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  27076. this._startTime === null && this._mixer._isActiveAction( this );
  27077. },
  27078. // return true when play has been called
  27079. isScheduled: function () {
  27080. return this._mixer._isActiveAction( this );
  27081. },
  27082. startAt: function ( time ) {
  27083. this._startTime = time;
  27084. return this;
  27085. },
  27086. setLoop: function ( mode, repetitions ) {
  27087. this.loop = mode;
  27088. this.repetitions = repetitions;
  27089. return this;
  27090. },
  27091. // Weight
  27092. // set the weight stopping any scheduled fading
  27093. // although .enabled = false yields an effective weight of zero, this
  27094. // method does *not* change .enabled, because it would be confusing
  27095. setEffectiveWeight: function ( weight ) {
  27096. this.weight = weight;
  27097. // note: same logic as when updated at runtime
  27098. this._effectiveWeight = this.enabled ? weight : 0;
  27099. return this.stopFading();
  27100. },
  27101. // return the weight considering fading and .enabled
  27102. getEffectiveWeight: function () {
  27103. return this._effectiveWeight;
  27104. },
  27105. fadeIn: function ( duration ) {
  27106. return this._scheduleFading( duration, 0, 1 );
  27107. },
  27108. fadeOut: function ( duration ) {
  27109. return this._scheduleFading( duration, 1, 0 );
  27110. },
  27111. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  27112. fadeOutAction.fadeOut( duration );
  27113. this.fadeIn( duration );
  27114. if ( warp ) {
  27115. var fadeInDuration = this._clip.duration,
  27116. fadeOutDuration = fadeOutAction._clip.duration,
  27117. startEndRatio = fadeOutDuration / fadeInDuration,
  27118. endStartRatio = fadeInDuration / fadeOutDuration;
  27119. fadeOutAction.warp( 1.0, startEndRatio, duration );
  27120. this.warp( endStartRatio, 1.0, duration );
  27121. }
  27122. return this;
  27123. },
  27124. crossFadeTo: function ( fadeInAction, duration, warp ) {
  27125. return fadeInAction.crossFadeFrom( this, duration, warp );
  27126. },
  27127. stopFading: function () {
  27128. var weightInterpolant = this._weightInterpolant;
  27129. if ( weightInterpolant !== null ) {
  27130. this._weightInterpolant = null;
  27131. this._mixer._takeBackControlInterpolant( weightInterpolant );
  27132. }
  27133. return this;
  27134. },
  27135. // Time Scale Control
  27136. // set the time scale stopping any scheduled warping
  27137. // although .paused = true yields an effective time scale of zero, this
  27138. // method does *not* change .paused, because it would be confusing
  27139. setEffectiveTimeScale: function ( timeScale ) {
  27140. this.timeScale = timeScale;
  27141. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  27142. return this.stopWarping();
  27143. },
  27144. // return the time scale considering warping and .paused
  27145. getEffectiveTimeScale: function () {
  27146. return this._effectiveTimeScale;
  27147. },
  27148. setDuration: function ( duration ) {
  27149. this.timeScale = this._clip.duration / duration;
  27150. return this.stopWarping();
  27151. },
  27152. syncWith: function ( action ) {
  27153. this.time = action.time;
  27154. this.timeScale = action.timeScale;
  27155. return this.stopWarping();
  27156. },
  27157. halt: function ( duration ) {
  27158. return this.warp( this._effectiveTimeScale, 0, duration );
  27159. },
  27160. warp: function ( startTimeScale, endTimeScale, duration ) {
  27161. var mixer = this._mixer,
  27162. now = mixer.time,
  27163. timeScale = this.timeScale;
  27164. var interpolant = this._timeScaleInterpolant;
  27165. if ( interpolant === null ) {
  27166. interpolant = mixer._lendControlInterpolant();
  27167. this._timeScaleInterpolant = interpolant;
  27168. }
  27169. var times = interpolant.parameterPositions,
  27170. values = interpolant.sampleValues;
  27171. times[ 0 ] = now;
  27172. times[ 1 ] = now + duration;
  27173. values[ 0 ] = startTimeScale / timeScale;
  27174. values[ 1 ] = endTimeScale / timeScale;
  27175. return this;
  27176. },
  27177. stopWarping: function () {
  27178. var timeScaleInterpolant = this._timeScaleInterpolant;
  27179. if ( timeScaleInterpolant !== null ) {
  27180. this._timeScaleInterpolant = null;
  27181. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  27182. }
  27183. return this;
  27184. },
  27185. // Object Accessors
  27186. getMixer: function () {
  27187. return this._mixer;
  27188. },
  27189. getClip: function () {
  27190. return this._clip;
  27191. },
  27192. getRoot: function () {
  27193. return this._localRoot || this._mixer._root;
  27194. },
  27195. // Interna
  27196. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  27197. // called by the mixer
  27198. if ( ! this.enabled ) {
  27199. // call ._updateWeight() to update ._effectiveWeight
  27200. this._updateWeight( time );
  27201. return;
  27202. }
  27203. var startTime = this._startTime;
  27204. if ( startTime !== null ) {
  27205. // check for scheduled start of action
  27206. var timeRunning = ( time - startTime ) * timeDirection;
  27207. if ( timeRunning < 0 || timeDirection === 0 ) {
  27208. return; // yet to come / don't decide when delta = 0
  27209. }
  27210. // start
  27211. this._startTime = null; // unschedule
  27212. deltaTime = timeDirection * timeRunning;
  27213. }
  27214. // apply time scale and advance time
  27215. deltaTime *= this._updateTimeScale( time );
  27216. var clipTime = this._updateTime( deltaTime );
  27217. // note: _updateTime may disable the action resulting in
  27218. // an effective weight of 0
  27219. var weight = this._updateWeight( time );
  27220. if ( weight > 0 ) {
  27221. var interpolants = this._interpolants;
  27222. var propertyMixers = this._propertyBindings;
  27223. switch ( this.blendMode ) {
  27224. case AdditiveAnimationBlendMode:
  27225. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  27226. interpolants[ j ].evaluate( clipTime );
  27227. propertyMixers[ j ].accumulateAdditive( weight );
  27228. }
  27229. break;
  27230. case NormalAnimationBlendMode:
  27231. default:
  27232. for ( var j$1 = 0, m$1 = interpolants.length; j$1 !== m$1; ++ j$1 ) {
  27233. interpolants[ j$1 ].evaluate( clipTime );
  27234. propertyMixers[ j$1 ].accumulate( accuIndex, weight );
  27235. }
  27236. }
  27237. }
  27238. },
  27239. _updateWeight: function ( time ) {
  27240. var weight = 0;
  27241. if ( this.enabled ) {
  27242. weight = this.weight;
  27243. var interpolant = this._weightInterpolant;
  27244. if ( interpolant !== null ) {
  27245. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  27246. weight *= interpolantValue;
  27247. if ( time > interpolant.parameterPositions[ 1 ] ) {
  27248. this.stopFading();
  27249. if ( interpolantValue === 0 ) {
  27250. // faded out, disable
  27251. this.enabled = false;
  27252. }
  27253. }
  27254. }
  27255. }
  27256. this._effectiveWeight = weight;
  27257. return weight;
  27258. },
  27259. _updateTimeScale: function ( time ) {
  27260. var timeScale = 0;
  27261. if ( ! this.paused ) {
  27262. timeScale = this.timeScale;
  27263. var interpolant = this._timeScaleInterpolant;
  27264. if ( interpolant !== null ) {
  27265. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  27266. timeScale *= interpolantValue;
  27267. if ( time > interpolant.parameterPositions[ 1 ] ) {
  27268. this.stopWarping();
  27269. if ( timeScale === 0 ) {
  27270. // motion has halted, pause
  27271. this.paused = true;
  27272. } else {
  27273. // warp done - apply final time scale
  27274. this.timeScale = timeScale;
  27275. }
  27276. }
  27277. }
  27278. }
  27279. this._effectiveTimeScale = timeScale;
  27280. return timeScale;
  27281. },
  27282. _updateTime: function ( deltaTime ) {
  27283. var duration = this._clip.duration;
  27284. var loop = this.loop;
  27285. var time = this.time + deltaTime;
  27286. var loopCount = this._loopCount;
  27287. var pingPong = ( loop === LoopPingPong );
  27288. if ( deltaTime === 0 ) {
  27289. if ( loopCount === - 1 ) { return time; }
  27290. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  27291. }
  27292. if ( loop === LoopOnce ) {
  27293. if ( loopCount === - 1 ) {
  27294. // just started
  27295. this._loopCount = 0;
  27296. this._setEndings( true, true, false );
  27297. }
  27298. handle_stop: {
  27299. if ( time >= duration ) {
  27300. time = duration;
  27301. } else if ( time < 0 ) {
  27302. time = 0;
  27303. } else {
  27304. this.time = time;
  27305. break handle_stop;
  27306. }
  27307. if ( this.clampWhenFinished ) { this.paused = true; }
  27308. else { this.enabled = false; }
  27309. this.time = time;
  27310. this._mixer.dispatchEvent( {
  27311. type: 'finished', action: this,
  27312. direction: deltaTime < 0 ? - 1 : 1
  27313. } );
  27314. }
  27315. } else { // repetitive Repeat or PingPong
  27316. if ( loopCount === - 1 ) {
  27317. // just started
  27318. if ( deltaTime >= 0 ) {
  27319. loopCount = 0;
  27320. this._setEndings( true, this.repetitions === 0, pingPong );
  27321. } else {
  27322. // when looping in reverse direction, the initial
  27323. // transition through zero counts as a repetition,
  27324. // so leave loopCount at -1
  27325. this._setEndings( this.repetitions === 0, true, pingPong );
  27326. }
  27327. }
  27328. if ( time >= duration || time < 0 ) {
  27329. // wrap around
  27330. var loopDelta = Math.floor( time / duration ); // signed
  27331. time -= duration * loopDelta;
  27332. loopCount += Math.abs( loopDelta );
  27333. var pending = this.repetitions - loopCount;
  27334. if ( pending <= 0 ) {
  27335. // have to stop (switch state, clamp time, fire event)
  27336. if ( this.clampWhenFinished ) { this.paused = true; }
  27337. else { this.enabled = false; }
  27338. time = deltaTime > 0 ? duration : 0;
  27339. this.time = time;
  27340. this._mixer.dispatchEvent( {
  27341. type: 'finished', action: this,
  27342. direction: deltaTime > 0 ? 1 : - 1
  27343. } );
  27344. } else {
  27345. // keep running
  27346. if ( pending === 1 ) {
  27347. // entering the last round
  27348. var atStart = deltaTime < 0;
  27349. this._setEndings( atStart, ! atStart, pingPong );
  27350. } else {
  27351. this._setEndings( false, false, pingPong );
  27352. }
  27353. this._loopCount = loopCount;
  27354. this.time = time;
  27355. this._mixer.dispatchEvent( {
  27356. type: 'loop', action: this, loopDelta: loopDelta
  27357. } );
  27358. }
  27359. } else {
  27360. this.time = time;
  27361. }
  27362. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  27363. // invert time for the "pong round"
  27364. return duration - time;
  27365. }
  27366. }
  27367. return time;
  27368. },
  27369. _setEndings: function ( atStart, atEnd, pingPong ) {
  27370. var settings = this._interpolantSettings;
  27371. if ( pingPong ) {
  27372. settings.endingStart = ZeroSlopeEnding;
  27373. settings.endingEnd = ZeroSlopeEnding;
  27374. } else {
  27375. // assuming for LoopOnce atStart == atEnd == true
  27376. if ( atStart ) {
  27377. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27378. } else {
  27379. settings.endingStart = WrapAroundEnding;
  27380. }
  27381. if ( atEnd ) {
  27382. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27383. } else {
  27384. settings.endingEnd = WrapAroundEnding;
  27385. }
  27386. }
  27387. },
  27388. _scheduleFading: function ( duration, weightNow, weightThen ) {
  27389. var mixer = this._mixer, now = mixer.time;
  27390. var interpolant = this._weightInterpolant;
  27391. if ( interpolant === null ) {
  27392. interpolant = mixer._lendControlInterpolant();
  27393. this._weightInterpolant = interpolant;
  27394. }
  27395. var times = interpolant.parameterPositions,
  27396. values = interpolant.sampleValues;
  27397. times[ 0 ] = now;
  27398. values[ 0 ] = weightNow;
  27399. times[ 1 ] = now + duration;
  27400. values[ 1 ] = weightThen;
  27401. return this;
  27402. }
  27403. } );
  27404. /**
  27405. *
  27406. * Player for AnimationClips.
  27407. *
  27408. *
  27409. * @author Ben Houston / http://clara.io/
  27410. * @author David Sarno / http://lighthaus.us/
  27411. * @author tschw
  27412. */
  27413. function AnimationMixer( root ) {
  27414. this._root = root;
  27415. this._initMemoryManager();
  27416. this._accuIndex = 0;
  27417. this.time = 0;
  27418. this.timeScale = 1.0;
  27419. }
  27420. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  27421. constructor: AnimationMixer,
  27422. _bindAction: function ( action, prototypeAction ) {
  27423. var root = action._localRoot || this._root,
  27424. tracks = action._clip.tracks,
  27425. nTracks = tracks.length,
  27426. bindings = action._propertyBindings,
  27427. interpolants = action._interpolants,
  27428. rootUuid = root.uuid,
  27429. bindingsByRoot = this._bindingsByRootAndName;
  27430. var bindingsByName = bindingsByRoot[ rootUuid ];
  27431. if ( bindingsByName === undefined ) {
  27432. bindingsByName = {};
  27433. bindingsByRoot[ rootUuid ] = bindingsByName;
  27434. }
  27435. for ( var i = 0; i !== nTracks; ++ i ) {
  27436. var track = tracks[ i ],
  27437. trackName = track.name;
  27438. var binding = bindingsByName[ trackName ];
  27439. if ( binding !== undefined ) {
  27440. bindings[ i ] = binding;
  27441. } else {
  27442. binding = bindings[ i ];
  27443. if ( binding !== undefined ) {
  27444. // existing binding, make sure the cache knows
  27445. if ( binding._cacheIndex === null ) {
  27446. ++ binding.referenceCount;
  27447. this._addInactiveBinding( binding, rootUuid, trackName );
  27448. }
  27449. continue;
  27450. }
  27451. var path = prototypeAction && prototypeAction.
  27452. _propertyBindings[ i ].binding.parsedPath;
  27453. binding = new PropertyMixer(
  27454. PropertyBinding.create( root, trackName, path ),
  27455. track.ValueTypeName, track.getValueSize() );
  27456. ++ binding.referenceCount;
  27457. this._addInactiveBinding( binding, rootUuid, trackName );
  27458. bindings[ i ] = binding;
  27459. }
  27460. interpolants[ i ].resultBuffer = binding.buffer;
  27461. }
  27462. },
  27463. _activateAction: function ( action ) {
  27464. if ( ! this._isActiveAction( action ) ) {
  27465. if ( action._cacheIndex === null ) {
  27466. // this action has been forgotten by the cache, but the user
  27467. // appears to be still using it -> rebind
  27468. var rootUuid = ( action._localRoot || this._root ).uuid,
  27469. clipUuid = action._clip.uuid,
  27470. actionsForClip = this._actionsByClip[ clipUuid ];
  27471. this._bindAction( action,
  27472. actionsForClip && actionsForClip.knownActions[ 0 ] );
  27473. this._addInactiveAction( action, clipUuid, rootUuid );
  27474. }
  27475. var bindings = action._propertyBindings;
  27476. // increment reference counts / sort out state
  27477. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27478. var binding = bindings[ i ];
  27479. if ( binding.useCount ++ === 0 ) {
  27480. this._lendBinding( binding );
  27481. binding.saveOriginalState();
  27482. }
  27483. }
  27484. this._lendAction( action );
  27485. }
  27486. },
  27487. _deactivateAction: function ( action ) {
  27488. if ( this._isActiveAction( action ) ) {
  27489. var bindings = action._propertyBindings;
  27490. // decrement reference counts / sort out state
  27491. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27492. var binding = bindings[ i ];
  27493. if ( -- binding.useCount === 0 ) {
  27494. binding.restoreOriginalState();
  27495. this._takeBackBinding( binding );
  27496. }
  27497. }
  27498. this._takeBackAction( action );
  27499. }
  27500. },
  27501. // Memory manager
  27502. _initMemoryManager: function () {
  27503. this._actions = []; // 'nActiveActions' followed by inactive ones
  27504. this._nActiveActions = 0;
  27505. this._actionsByClip = {};
  27506. // inside:
  27507. // {
  27508. // knownActions: Array< AnimationAction > - used as prototypes
  27509. // actionByRoot: AnimationAction - lookup
  27510. // }
  27511. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27512. this._nActiveBindings = 0;
  27513. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27514. this._controlInterpolants = []; // same game as above
  27515. this._nActiveControlInterpolants = 0;
  27516. var scope = this;
  27517. this.stats = {
  27518. actions: {
  27519. get total() {
  27520. return scope._actions.length;
  27521. },
  27522. get inUse() {
  27523. return scope._nActiveActions;
  27524. }
  27525. },
  27526. bindings: {
  27527. get total() {
  27528. return scope._bindings.length;
  27529. },
  27530. get inUse() {
  27531. return scope._nActiveBindings;
  27532. }
  27533. },
  27534. controlInterpolants: {
  27535. get total() {
  27536. return scope._controlInterpolants.length;
  27537. },
  27538. get inUse() {
  27539. return scope._nActiveControlInterpolants;
  27540. }
  27541. }
  27542. };
  27543. },
  27544. // Memory management for AnimationAction objects
  27545. _isActiveAction: function ( action ) {
  27546. var index = action._cacheIndex;
  27547. return index !== null && index < this._nActiveActions;
  27548. },
  27549. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  27550. var actions = this._actions,
  27551. actionsByClip = this._actionsByClip;
  27552. var actionsForClip = actionsByClip[ clipUuid ];
  27553. if ( actionsForClip === undefined ) {
  27554. actionsForClip = {
  27555. knownActions: [ action ],
  27556. actionByRoot: {}
  27557. };
  27558. action._byClipCacheIndex = 0;
  27559. actionsByClip[ clipUuid ] = actionsForClip;
  27560. } else {
  27561. var knownActions = actionsForClip.knownActions;
  27562. action._byClipCacheIndex = knownActions.length;
  27563. knownActions.push( action );
  27564. }
  27565. action._cacheIndex = actions.length;
  27566. actions.push( action );
  27567. actionsForClip.actionByRoot[ rootUuid ] = action;
  27568. },
  27569. _removeInactiveAction: function ( action ) {
  27570. var actions = this._actions,
  27571. lastInactiveAction = actions[ actions.length - 1 ],
  27572. cacheIndex = action._cacheIndex;
  27573. lastInactiveAction._cacheIndex = cacheIndex;
  27574. actions[ cacheIndex ] = lastInactiveAction;
  27575. actions.pop();
  27576. action._cacheIndex = null;
  27577. var clipUuid = action._clip.uuid,
  27578. actionsByClip = this._actionsByClip,
  27579. actionsForClip = actionsByClip[ clipUuid ],
  27580. knownActionsForClip = actionsForClip.knownActions,
  27581. lastKnownAction =
  27582. knownActionsForClip[ knownActionsForClip.length - 1 ],
  27583. byClipCacheIndex = action._byClipCacheIndex;
  27584. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27585. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  27586. knownActionsForClip.pop();
  27587. action._byClipCacheIndex = null;
  27588. var actionByRoot = actionsForClip.actionByRoot,
  27589. rootUuid = ( action._localRoot || this._root ).uuid;
  27590. delete actionByRoot[ rootUuid ];
  27591. if ( knownActionsForClip.length === 0 ) {
  27592. delete actionsByClip[ clipUuid ];
  27593. }
  27594. this._removeInactiveBindingsForAction( action );
  27595. },
  27596. _removeInactiveBindingsForAction: function ( action ) {
  27597. var bindings = action._propertyBindings;
  27598. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27599. var binding = bindings[ i ];
  27600. if ( -- binding.referenceCount === 0 ) {
  27601. this._removeInactiveBinding( binding );
  27602. }
  27603. }
  27604. },
  27605. _lendAction: function ( action ) {
  27606. // [ active actions | inactive actions ]
  27607. // [ active actions >| inactive actions ]
  27608. // s a
  27609. // <-swap->
  27610. // a s
  27611. var actions = this._actions,
  27612. prevIndex = action._cacheIndex,
  27613. lastActiveIndex = this._nActiveActions ++,
  27614. firstInactiveAction = actions[ lastActiveIndex ];
  27615. action._cacheIndex = lastActiveIndex;
  27616. actions[ lastActiveIndex ] = action;
  27617. firstInactiveAction._cacheIndex = prevIndex;
  27618. actions[ prevIndex ] = firstInactiveAction;
  27619. },
  27620. _takeBackAction: function ( action ) {
  27621. // [ active actions | inactive actions ]
  27622. // [ active actions |< inactive actions ]
  27623. // a s
  27624. // <-swap->
  27625. // s a
  27626. var actions = this._actions,
  27627. prevIndex = action._cacheIndex,
  27628. firstInactiveIndex = -- this._nActiveActions,
  27629. lastActiveAction = actions[ firstInactiveIndex ];
  27630. action._cacheIndex = firstInactiveIndex;
  27631. actions[ firstInactiveIndex ] = action;
  27632. lastActiveAction._cacheIndex = prevIndex;
  27633. actions[ prevIndex ] = lastActiveAction;
  27634. },
  27635. // Memory management for PropertyMixer objects
  27636. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  27637. var bindingsByRoot = this._bindingsByRootAndName,
  27638. bindings = this._bindings;
  27639. var bindingByName = bindingsByRoot[ rootUuid ];
  27640. if ( bindingByName === undefined ) {
  27641. bindingByName = {};
  27642. bindingsByRoot[ rootUuid ] = bindingByName;
  27643. }
  27644. bindingByName[ trackName ] = binding;
  27645. binding._cacheIndex = bindings.length;
  27646. bindings.push( binding );
  27647. },
  27648. _removeInactiveBinding: function ( binding ) {
  27649. var bindings = this._bindings,
  27650. propBinding = binding.binding,
  27651. rootUuid = propBinding.rootNode.uuid,
  27652. trackName = propBinding.path,
  27653. bindingsByRoot = this._bindingsByRootAndName,
  27654. bindingByName = bindingsByRoot[ rootUuid ],
  27655. lastInactiveBinding = bindings[ bindings.length - 1 ],
  27656. cacheIndex = binding._cacheIndex;
  27657. lastInactiveBinding._cacheIndex = cacheIndex;
  27658. bindings[ cacheIndex ] = lastInactiveBinding;
  27659. bindings.pop();
  27660. delete bindingByName[ trackName ];
  27661. if ( Object.keys( bindingByName ).length === 0 ) {
  27662. delete bindingsByRoot[ rootUuid ];
  27663. }
  27664. },
  27665. _lendBinding: function ( binding ) {
  27666. var bindings = this._bindings,
  27667. prevIndex = binding._cacheIndex,
  27668. lastActiveIndex = this._nActiveBindings ++,
  27669. firstInactiveBinding = bindings[ lastActiveIndex ];
  27670. binding._cacheIndex = lastActiveIndex;
  27671. bindings[ lastActiveIndex ] = binding;
  27672. firstInactiveBinding._cacheIndex = prevIndex;
  27673. bindings[ prevIndex ] = firstInactiveBinding;
  27674. },
  27675. _takeBackBinding: function ( binding ) {
  27676. var bindings = this._bindings,
  27677. prevIndex = binding._cacheIndex,
  27678. firstInactiveIndex = -- this._nActiveBindings,
  27679. lastActiveBinding = bindings[ firstInactiveIndex ];
  27680. binding._cacheIndex = firstInactiveIndex;
  27681. bindings[ firstInactiveIndex ] = binding;
  27682. lastActiveBinding._cacheIndex = prevIndex;
  27683. bindings[ prevIndex ] = lastActiveBinding;
  27684. },
  27685. // Memory management of Interpolants for weight and time scale
  27686. _lendControlInterpolant: function () {
  27687. var interpolants = this._controlInterpolants,
  27688. lastActiveIndex = this._nActiveControlInterpolants ++;
  27689. var interpolant = interpolants[ lastActiveIndex ];
  27690. if ( interpolant === undefined ) {
  27691. interpolant = new LinearInterpolant(
  27692. new Float32Array( 2 ), new Float32Array( 2 ),
  27693. 1, this._controlInterpolantsResultBuffer );
  27694. interpolant.__cacheIndex = lastActiveIndex;
  27695. interpolants[ lastActiveIndex ] = interpolant;
  27696. }
  27697. return interpolant;
  27698. },
  27699. _takeBackControlInterpolant: function ( interpolant ) {
  27700. var interpolants = this._controlInterpolants,
  27701. prevIndex = interpolant.__cacheIndex,
  27702. firstInactiveIndex = -- this._nActiveControlInterpolants,
  27703. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  27704. interpolant.__cacheIndex = firstInactiveIndex;
  27705. interpolants[ firstInactiveIndex ] = interpolant;
  27706. lastActiveInterpolant.__cacheIndex = prevIndex;
  27707. interpolants[ prevIndex ] = lastActiveInterpolant;
  27708. },
  27709. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  27710. // return an action for a clip optionally using a custom root target
  27711. // object (this method allocates a lot of dynamic memory in case a
  27712. // previously unknown clip/root combination is specified)
  27713. clipAction: function ( clip, optionalRoot, blendMode ) {
  27714. var root = optionalRoot || this._root,
  27715. rootUuid = root.uuid;
  27716. var clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  27717. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27718. var actionsForClip = this._actionsByClip[ clipUuid ],
  27719. prototypeAction = null;
  27720. if ( blendMode === undefined ) {
  27721. if ( clipObject !== null ) {
  27722. blendMode = clipObject.blendMode;
  27723. } else {
  27724. blendMode = NormalAnimationBlendMode;
  27725. }
  27726. }
  27727. if ( actionsForClip !== undefined ) {
  27728. var existingAction = actionsForClip.actionByRoot[ rootUuid ];
  27729. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  27730. return existingAction;
  27731. }
  27732. // we know the clip, so we don't have to parse all
  27733. // the bindings again but can just copy
  27734. prototypeAction = actionsForClip.knownActions[ 0 ];
  27735. // also, take the clip from the prototype action
  27736. if ( clipObject === null )
  27737. { clipObject = prototypeAction._clip; }
  27738. }
  27739. // clip must be known when specified via string
  27740. if ( clipObject === null ) { return null; }
  27741. // allocate all resources required to run it
  27742. var newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  27743. this._bindAction( newAction, prototypeAction );
  27744. // and make the action known to the memory manager
  27745. this._addInactiveAction( newAction, clipUuid, rootUuid );
  27746. return newAction;
  27747. },
  27748. // get an existing action
  27749. existingAction: function ( clip, optionalRoot ) {
  27750. var root = optionalRoot || this._root,
  27751. rootUuid = root.uuid,
  27752. clipObject = typeof clip === 'string' ?
  27753. AnimationClip.findByName( root, clip ) : clip,
  27754. clipUuid = clipObject ? clipObject.uuid : clip,
  27755. actionsForClip = this._actionsByClip[ clipUuid ];
  27756. if ( actionsForClip !== undefined ) {
  27757. return actionsForClip.actionByRoot[ rootUuid ] || null;
  27758. }
  27759. return null;
  27760. },
  27761. // deactivates all previously scheduled actions
  27762. stopAllAction: function () {
  27763. var actions = this._actions,
  27764. nActions = this._nActiveActions;
  27765. for ( var i = nActions - 1; i >= 0; -- i ) {
  27766. actions[ i ].stop();
  27767. }
  27768. return this;
  27769. },
  27770. // advance the time and update apply the animation
  27771. update: function ( deltaTime ) {
  27772. deltaTime *= this.timeScale;
  27773. var actions = this._actions,
  27774. nActions = this._nActiveActions,
  27775. time = this.time += deltaTime,
  27776. timeDirection = Math.sign( deltaTime ),
  27777. accuIndex = this._accuIndex ^= 1;
  27778. // run active actions
  27779. for ( var i = 0; i !== nActions; ++ i ) {
  27780. var action = actions[ i ];
  27781. action._update( time, deltaTime, timeDirection, accuIndex );
  27782. }
  27783. // update scene graph
  27784. var bindings = this._bindings,
  27785. nBindings = this._nActiveBindings;
  27786. for ( var i$1 = 0; i$1 !== nBindings; ++ i$1 ) {
  27787. bindings[ i$1 ].apply( accuIndex );
  27788. }
  27789. return this;
  27790. },
  27791. // Allows you to seek to a specific time in an animation.
  27792. setTime: function ( timeInSeconds ) {
  27793. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27794. for ( var i = 0; i < this._actions.length; i ++ ) {
  27795. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27796. }
  27797. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  27798. },
  27799. // return this mixer's root target object
  27800. getRoot: function () {
  27801. return this._root;
  27802. },
  27803. // free all resources specific to a particular clip
  27804. uncacheClip: function ( clip ) {
  27805. var actions = this._actions,
  27806. clipUuid = clip.uuid,
  27807. actionsByClip = this._actionsByClip,
  27808. actionsForClip = actionsByClip[ clipUuid ];
  27809. if ( actionsForClip !== undefined ) {
  27810. // note: just calling _removeInactiveAction would mess up the
  27811. // iteration state and also require updating the state we can
  27812. // just throw away
  27813. var actionsToRemove = actionsForClip.knownActions;
  27814. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  27815. var action = actionsToRemove[ i ];
  27816. this._deactivateAction( action );
  27817. var cacheIndex = action._cacheIndex,
  27818. lastInactiveAction = actions[ actions.length - 1 ];
  27819. action._cacheIndex = null;
  27820. action._byClipCacheIndex = null;
  27821. lastInactiveAction._cacheIndex = cacheIndex;
  27822. actions[ cacheIndex ] = lastInactiveAction;
  27823. actions.pop();
  27824. this._removeInactiveBindingsForAction( action );
  27825. }
  27826. delete actionsByClip[ clipUuid ];
  27827. }
  27828. },
  27829. // free all resources specific to a particular root target object
  27830. uncacheRoot: function ( root ) {
  27831. var rootUuid = root.uuid,
  27832. actionsByClip = this._actionsByClip;
  27833. for ( var clipUuid in actionsByClip ) {
  27834. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27835. action = actionByRoot[ rootUuid ];
  27836. if ( action !== undefined ) {
  27837. this._deactivateAction( action );
  27838. this._removeInactiveAction( action );
  27839. }
  27840. }
  27841. var bindingsByRoot = this._bindingsByRootAndName,
  27842. bindingByName = bindingsByRoot[ rootUuid ];
  27843. if ( bindingByName !== undefined ) {
  27844. for ( var trackName in bindingByName ) {
  27845. var binding = bindingByName[ trackName ];
  27846. binding.restoreOriginalState();
  27847. this._removeInactiveBinding( binding );
  27848. }
  27849. }
  27850. },
  27851. // remove a targeted clip from the cache
  27852. uncacheAction: function ( clip, optionalRoot ) {
  27853. var action = this.existingAction( clip, optionalRoot );
  27854. if ( action !== null ) {
  27855. this._deactivateAction( action );
  27856. this._removeInactiveAction( action );
  27857. }
  27858. }
  27859. } );
  27860. /**
  27861. * @author mrdoob / http://mrdoob.com/
  27862. */
  27863. function Uniform( value ) {
  27864. if ( typeof value === 'string' ) {
  27865. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27866. value = arguments[ 1 ];
  27867. }
  27868. this.value = value;
  27869. }
  27870. Uniform.prototype.clone = function () {
  27871. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27872. };
  27873. /**
  27874. * @author benaadams / https://twitter.com/ben_a_adams
  27875. */
  27876. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27877. InterleavedBuffer.call( this, array, stride );
  27878. this.meshPerAttribute = meshPerAttribute || 1;
  27879. }
  27880. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27881. constructor: InstancedInterleavedBuffer,
  27882. isInstancedInterleavedBuffer: true,
  27883. copy: function ( source ) {
  27884. InterleavedBuffer.prototype.copy.call( this, source );
  27885. this.meshPerAttribute = source.meshPerAttribute;
  27886. return this;
  27887. },
  27888. clone: function ( data ) {
  27889. var ib = InterleavedBuffer.prototype.clone.call( this, data );
  27890. ib.meshPerAttribute = this.meshPerAttribute;
  27891. return ib;
  27892. },
  27893. toJSON: function ( data ) {
  27894. var json = InterleavedBuffer.prototype.toJSON.call( this, data );
  27895. json.isInstancedInterleavedBuffer = true;
  27896. json.meshPerAttribute = this.meshPerAttribute;
  27897. return json;
  27898. }
  27899. } );
  27900. /**
  27901. * @author mrdoob / http://mrdoob.com/
  27902. * @author bhouston / http://clara.io/
  27903. * @author stephomi / http://stephaneginier.com/
  27904. */
  27905. function Raycaster( origin, direction, near, far ) {
  27906. this.ray = new Ray( origin, direction );
  27907. // direction is assumed to be normalized (for accurate distance calculations)
  27908. this.near = near || 0;
  27909. this.far = far || Infinity;
  27910. this.camera = null;
  27911. this.layers = new Layers();
  27912. this.params = {
  27913. Mesh: {},
  27914. Line: { threshold: 1 },
  27915. LOD: {},
  27916. Points: { threshold: 1 },
  27917. Sprite: {}
  27918. };
  27919. Object.defineProperties( this.params, {
  27920. PointCloud: {
  27921. get: function () {
  27922. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27923. return this.Points;
  27924. }
  27925. }
  27926. } );
  27927. }
  27928. function ascSort( a, b ) {
  27929. return a.distance - b.distance;
  27930. }
  27931. function intersectObject( object, raycaster, intersects, recursive ) {
  27932. if ( object.layers.test( raycaster.layers ) ) {
  27933. object.raycast( raycaster, intersects );
  27934. }
  27935. if ( recursive === true ) {
  27936. var children = object.children;
  27937. for ( var i = 0, l = children.length; i < l; i ++ ) {
  27938. intersectObject( children[ i ], raycaster, intersects, true );
  27939. }
  27940. }
  27941. }
  27942. Object.assign( Raycaster.prototype, {
  27943. set: function ( origin, direction ) {
  27944. // direction is assumed to be normalized (for accurate distance calculations)
  27945. this.ray.set( origin, direction );
  27946. },
  27947. setFromCamera: function ( coords, camera ) {
  27948. if ( ( camera && camera.isPerspectiveCamera ) ) {
  27949. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27950. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27951. this.camera = camera;
  27952. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  27953. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27954. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27955. this.camera = camera;
  27956. } else {
  27957. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  27958. }
  27959. },
  27960. intersectObject: function ( object, recursive, optionalTarget ) {
  27961. var intersects = optionalTarget || [];
  27962. intersectObject( object, this, intersects, recursive );
  27963. intersects.sort( ascSort );
  27964. return intersects;
  27965. },
  27966. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27967. var intersects = optionalTarget || [];
  27968. if ( Array.isArray( objects ) === false ) {
  27969. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27970. return intersects;
  27971. }
  27972. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  27973. intersectObject( objects[ i ], this, intersects, recursive );
  27974. }
  27975. intersects.sort( ascSort );
  27976. return intersects;
  27977. }
  27978. } );
  27979. /**
  27980. * @author bhouston / http://clara.io
  27981. * @author WestLangley / http://github.com/WestLangley
  27982. *
  27983. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27984. *
  27985. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27986. * The azimuthal angle (theta) is measured from the positive z-axis.
  27987. */
  27988. function Spherical( radius, phi, theta ) {
  27989. this.radius = ( radius !== undefined ) ? radius : 1.0;
  27990. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  27991. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  27992. return this;
  27993. }
  27994. Object.assign( Spherical.prototype, {
  27995. set: function ( radius, phi, theta ) {
  27996. this.radius = radius;
  27997. this.phi = phi;
  27998. this.theta = theta;
  27999. return this;
  28000. },
  28001. clone: function () {
  28002. return new this.constructor().copy( this );
  28003. },
  28004. copy: function ( other ) {
  28005. this.radius = other.radius;
  28006. this.phi = other.phi;
  28007. this.theta = other.theta;
  28008. return this;
  28009. },
  28010. // restrict phi to be betwee EPS and PI-EPS
  28011. makeSafe: function () {
  28012. var EPS = 0.000001;
  28013. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  28014. return this;
  28015. },
  28016. setFromVector3: function ( v ) {
  28017. return this.setFromCartesianCoords( v.x, v.y, v.z );
  28018. },
  28019. setFromCartesianCoords: function ( x, y, z ) {
  28020. this.radius = Math.sqrt( x * x + y * y + z * z );
  28021. if ( this.radius === 0 ) {
  28022. this.theta = 0;
  28023. this.phi = 0;
  28024. } else {
  28025. this.theta = Math.atan2( x, z );
  28026. this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
  28027. }
  28028. return this;
  28029. }
  28030. } );
  28031. /**
  28032. * @author Mugen87 / https://github.com/Mugen87
  28033. *
  28034. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  28035. *
  28036. */
  28037. function Cylindrical( radius, theta, y ) {
  28038. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  28039. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  28040. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  28041. return this;
  28042. }
  28043. Object.assign( Cylindrical.prototype, {
  28044. set: function ( radius, theta, y ) {
  28045. this.radius = radius;
  28046. this.theta = theta;
  28047. this.y = y;
  28048. return this;
  28049. },
  28050. clone: function () {
  28051. return new this.constructor().copy( this );
  28052. },
  28053. copy: function ( other ) {
  28054. this.radius = other.radius;
  28055. this.theta = other.theta;
  28056. this.y = other.y;
  28057. return this;
  28058. },
  28059. setFromVector3: function ( v ) {
  28060. return this.setFromCartesianCoords( v.x, v.y, v.z );
  28061. },
  28062. setFromCartesianCoords: function ( x, y, z ) {
  28063. this.radius = Math.sqrt( x * x + z * z );
  28064. this.theta = Math.atan2( x, z );
  28065. this.y = y;
  28066. return this;
  28067. }
  28068. } );
  28069. /**
  28070. * @author bhouston / http://clara.io
  28071. */
  28072. var _vector$7 = new Vector2();
  28073. function Box2( min, max ) {
  28074. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  28075. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  28076. }
  28077. Object.assign( Box2.prototype, {
  28078. set: function ( min, max ) {
  28079. this.min.copy( min );
  28080. this.max.copy( max );
  28081. return this;
  28082. },
  28083. setFromPoints: function ( points ) {
  28084. this.makeEmpty();
  28085. for ( var i = 0, il = points.length; i < il; i ++ ) {
  28086. this.expandByPoint( points[ i ] );
  28087. }
  28088. return this;
  28089. },
  28090. setFromCenterAndSize: function ( center, size ) {
  28091. var halfSize = _vector$7.copy( size ).multiplyScalar( 0.5 );
  28092. this.min.copy( center ).sub( halfSize );
  28093. this.max.copy( center ).add( halfSize );
  28094. return this;
  28095. },
  28096. clone: function () {
  28097. return new this.constructor().copy( this );
  28098. },
  28099. copy: function ( box ) {
  28100. this.min.copy( box.min );
  28101. this.max.copy( box.max );
  28102. return this;
  28103. },
  28104. makeEmpty: function () {
  28105. this.min.x = this.min.y = + Infinity;
  28106. this.max.x = this.max.y = - Infinity;
  28107. return this;
  28108. },
  28109. isEmpty: function () {
  28110. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  28111. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  28112. },
  28113. getCenter: function ( target ) {
  28114. if ( target === undefined ) {
  28115. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  28116. target = new Vector2();
  28117. }
  28118. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  28119. },
  28120. getSize: function ( target ) {
  28121. if ( target === undefined ) {
  28122. console.warn( 'THREE.Box2: .getSize() target is now required' );
  28123. target = new Vector2();
  28124. }
  28125. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  28126. },
  28127. expandByPoint: function ( point ) {
  28128. this.min.min( point );
  28129. this.max.max( point );
  28130. return this;
  28131. },
  28132. expandByVector: function ( vector ) {
  28133. this.min.sub( vector );
  28134. this.max.add( vector );
  28135. return this;
  28136. },
  28137. expandByScalar: function ( scalar ) {
  28138. this.min.addScalar( - scalar );
  28139. this.max.addScalar( scalar );
  28140. return this;
  28141. },
  28142. containsPoint: function ( point ) {
  28143. return point.x < this.min.x || point.x > this.max.x ||
  28144. point.y < this.min.y || point.y > this.max.y ? false : true;
  28145. },
  28146. containsBox: function ( box ) {
  28147. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  28148. this.min.y <= box.min.y && box.max.y <= this.max.y;
  28149. },
  28150. getParameter: function ( point, target ) {
  28151. // This can potentially have a divide by zero if the box
  28152. // has a size dimension of 0.
  28153. if ( target === undefined ) {
  28154. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  28155. target = new Vector2();
  28156. }
  28157. return target.set(
  28158. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  28159. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  28160. );
  28161. },
  28162. intersectsBox: function ( box ) {
  28163. // using 4 splitting planes to rule out intersections
  28164. return box.max.x < this.min.x || box.min.x > this.max.x ||
  28165. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  28166. },
  28167. clampPoint: function ( point, target ) {
  28168. if ( target === undefined ) {
  28169. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  28170. target = new Vector2();
  28171. }
  28172. return target.copy( point ).clamp( this.min, this.max );
  28173. },
  28174. distanceToPoint: function ( point ) {
  28175. var clampedPoint = _vector$7.copy( point ).clamp( this.min, this.max );
  28176. return clampedPoint.sub( point ).length();
  28177. },
  28178. intersect: function ( box ) {
  28179. this.min.max( box.min );
  28180. this.max.min( box.max );
  28181. return this;
  28182. },
  28183. union: function ( box ) {
  28184. this.min.min( box.min );
  28185. this.max.max( box.max );
  28186. return this;
  28187. },
  28188. translate: function ( offset ) {
  28189. this.min.add( offset );
  28190. this.max.add( offset );
  28191. return this;
  28192. },
  28193. equals: function ( box ) {
  28194. return box.min.equals( this.min ) && box.max.equals( this.max );
  28195. }
  28196. } );
  28197. /**
  28198. * @author bhouston / http://clara.io
  28199. */
  28200. var _startP = new Vector3();
  28201. var _startEnd = new Vector3();
  28202. function Line3( start, end ) {
  28203. this.start = ( start !== undefined ) ? start : new Vector3();
  28204. this.end = ( end !== undefined ) ? end : new Vector3();
  28205. }
  28206. Object.assign( Line3.prototype, {
  28207. set: function ( start, end ) {
  28208. this.start.copy( start );
  28209. this.end.copy( end );
  28210. return this;
  28211. },
  28212. clone: function () {
  28213. return new this.constructor().copy( this );
  28214. },
  28215. copy: function ( line ) {
  28216. this.start.copy( line.start );
  28217. this.end.copy( line.end );
  28218. return this;
  28219. },
  28220. getCenter: function ( target ) {
  28221. if ( target === undefined ) {
  28222. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  28223. target = new Vector3();
  28224. }
  28225. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  28226. },
  28227. delta: function ( target ) {
  28228. if ( target === undefined ) {
  28229. console.warn( 'THREE.Line3: .delta() target is now required' );
  28230. target = new Vector3();
  28231. }
  28232. return target.subVectors( this.end, this.start );
  28233. },
  28234. distanceSq: function () {
  28235. return this.start.distanceToSquared( this.end );
  28236. },
  28237. distance: function () {
  28238. return this.start.distanceTo( this.end );
  28239. },
  28240. at: function ( t, target ) {
  28241. if ( target === undefined ) {
  28242. console.warn( 'THREE.Line3: .at() target is now required' );
  28243. target = new Vector3();
  28244. }
  28245. return this.delta( target ).multiplyScalar( t ).add( this.start );
  28246. },
  28247. closestPointToPointParameter: function ( point, clampToLine ) {
  28248. _startP.subVectors( point, this.start );
  28249. _startEnd.subVectors( this.end, this.start );
  28250. var startEnd2 = _startEnd.dot( _startEnd );
  28251. var startEnd_startP = _startEnd.dot( _startP );
  28252. var t = startEnd_startP / startEnd2;
  28253. if ( clampToLine ) {
  28254. t = MathUtils.clamp( t, 0, 1 );
  28255. }
  28256. return t;
  28257. },
  28258. closestPointToPoint: function ( point, clampToLine, target ) {
  28259. var t = this.closestPointToPointParameter( point, clampToLine );
  28260. if ( target === undefined ) {
  28261. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  28262. target = new Vector3();
  28263. }
  28264. return this.delta( target ).multiplyScalar( t ).add( this.start );
  28265. },
  28266. applyMatrix4: function ( matrix ) {
  28267. this.start.applyMatrix4( matrix );
  28268. this.end.applyMatrix4( matrix );
  28269. return this;
  28270. },
  28271. equals: function ( line ) {
  28272. return line.start.equals( this.start ) && line.end.equals( this.end );
  28273. }
  28274. } );
  28275. /**
  28276. * @author alteredq / http://alteredqualia.com/
  28277. */
  28278. function ImmediateRenderObject( material ) {
  28279. Object3D.call( this );
  28280. this.material = material;
  28281. this.render = function ( /* renderCallback */ ) {};
  28282. this.hasPositions = false;
  28283. this.hasNormals = false;
  28284. this.hasColors = false;
  28285. this.hasUvs = false;
  28286. this.positionArray = null;
  28287. this.normalArray = null;
  28288. this.colorArray = null;
  28289. this.uvArray = null;
  28290. this.count = 0;
  28291. }
  28292. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  28293. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28294. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28295. /**
  28296. * @author alteredq / http://alteredqualia.com/
  28297. * @author mrdoob / http://mrdoob.com/
  28298. * @author WestLangley / http://github.com/WestLangley
  28299. */
  28300. var _vector$8 = new Vector3();
  28301. function SpotLightHelper( light, color ) {
  28302. Object3D.call( this );
  28303. this.light = light;
  28304. this.light.updateMatrixWorld();
  28305. this.matrix = light.matrixWorld;
  28306. this.matrixAutoUpdate = false;
  28307. this.color = color;
  28308. var geometry = new BufferGeometry();
  28309. var positions = [
  28310. 0, 0, 0, 0, 0, 1,
  28311. 0, 0, 0, 1, 0, 1,
  28312. 0, 0, 0, - 1, 0, 1,
  28313. 0, 0, 0, 0, 1, 1,
  28314. 0, 0, 0, 0, - 1, 1
  28315. ];
  28316. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  28317. var p1 = ( i / l ) * Math.PI * 2;
  28318. var p2 = ( j / l ) * Math.PI * 2;
  28319. positions.push(
  28320. Math.cos( p1 ), Math.sin( p1 ), 1,
  28321. Math.cos( p2 ), Math.sin( p2 ), 1
  28322. );
  28323. }
  28324. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28325. var material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28326. this.cone = new LineSegments( geometry, material );
  28327. this.add( this.cone );
  28328. this.update();
  28329. }
  28330. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  28331. SpotLightHelper.prototype.constructor = SpotLightHelper;
  28332. SpotLightHelper.prototype.dispose = function () {
  28333. this.cone.geometry.dispose();
  28334. this.cone.material.dispose();
  28335. };
  28336. SpotLightHelper.prototype.update = function () {
  28337. this.light.updateMatrixWorld();
  28338. var coneLength = this.light.distance ? this.light.distance : 1000;
  28339. var coneWidth = coneLength * Math.tan( this.light.angle );
  28340. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  28341. _vector$8.setFromMatrixPosition( this.light.target.matrixWorld );
  28342. this.cone.lookAt( _vector$8 );
  28343. if ( this.color !== undefined ) {
  28344. this.cone.material.color.set( this.color );
  28345. } else {
  28346. this.cone.material.color.copy( this.light.color );
  28347. }
  28348. };
  28349. /**
  28350. * @author Sean Griffin / http://twitter.com/sgrif
  28351. * @author Michael Guerrero / http://realitymeltdown.com
  28352. * @author mrdoob / http://mrdoob.com/
  28353. * @author ikerr / http://verold.com
  28354. * @author Mugen87 / https://github.com/Mugen87
  28355. */
  28356. var _vector$9 = new Vector3();
  28357. var _boneMatrix = new Matrix4();
  28358. var _matrixWorldInv = new Matrix4();
  28359. function getBoneList( object ) {
  28360. var boneList = [];
  28361. if ( object && object.isBone ) {
  28362. boneList.push( object );
  28363. }
  28364. for ( var i = 0; i < object.children.length; i ++ ) {
  28365. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  28366. }
  28367. return boneList;
  28368. }
  28369. function SkeletonHelper( object ) {
  28370. var bones = getBoneList( object );
  28371. var geometry = new BufferGeometry();
  28372. var vertices = [];
  28373. var colors = [];
  28374. var color1 = new Color( 0, 0, 1 );
  28375. var color2 = new Color( 0, 1, 0 );
  28376. for ( var i = 0; i < bones.length; i ++ ) {
  28377. var bone = bones[ i ];
  28378. if ( bone.parent && bone.parent.isBone ) {
  28379. vertices.push( 0, 0, 0 );
  28380. vertices.push( 0, 0, 0 );
  28381. colors.push( color1.r, color1.g, color1.b );
  28382. colors.push( color2.r, color2.g, color2.b );
  28383. }
  28384. }
  28385. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28386. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28387. var material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  28388. LineSegments.call( this, geometry, material );
  28389. this.type = 'SkeletonHelper';
  28390. this.root = object;
  28391. this.bones = bones;
  28392. this.matrix = object.matrixWorld;
  28393. this.matrixAutoUpdate = false;
  28394. }
  28395. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  28396. SkeletonHelper.prototype.constructor = SkeletonHelper;
  28397. SkeletonHelper.prototype.isSkeletonHelper = true;
  28398. SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
  28399. var bones = this.bones;
  28400. var geometry = this.geometry;
  28401. var position = geometry.getAttribute( 'position' );
  28402. _matrixWorldInv.getInverse( this.root.matrixWorld );
  28403. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  28404. var bone = bones[ i ];
  28405. if ( bone.parent && bone.parent.isBone ) {
  28406. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  28407. _vector$9.setFromMatrixPosition( _boneMatrix );
  28408. position.setXYZ( j, _vector$9.x, _vector$9.y, _vector$9.z );
  28409. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  28410. _vector$9.setFromMatrixPosition( _boneMatrix );
  28411. position.setXYZ( j + 1, _vector$9.x, _vector$9.y, _vector$9.z );
  28412. j += 2;
  28413. }
  28414. }
  28415. geometry.getAttribute( 'position' ).needsUpdate = true;
  28416. Object3D.prototype.updateMatrixWorld.call( this, force );
  28417. };
  28418. /**
  28419. * @author alteredq / http://alteredqualia.com/
  28420. * @author mrdoob / http://mrdoob.com/
  28421. */
  28422. function PointLightHelper( light, sphereSize, color ) {
  28423. this.light = light;
  28424. this.light.updateMatrixWorld();
  28425. this.color = color;
  28426. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  28427. var material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28428. Mesh.call( this, geometry, material );
  28429. this.type = 'PointLightHelper';
  28430. this.matrix = this.light.matrixWorld;
  28431. this.matrixAutoUpdate = false;
  28432. this.update();
  28433. /*
  28434. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28435. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28436. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28437. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28438. const d = light.distance;
  28439. if ( d === 0.0 ) {
  28440. this.lightDistance.visible = false;
  28441. } else {
  28442. this.lightDistance.scale.set( d, d, d );
  28443. }
  28444. this.add( this.lightDistance );
  28445. */
  28446. }
  28447. PointLightHelper.prototype = Object.create( Mesh.prototype );
  28448. PointLightHelper.prototype.constructor = PointLightHelper;
  28449. PointLightHelper.prototype.dispose = function () {
  28450. this.geometry.dispose();
  28451. this.material.dispose();
  28452. };
  28453. PointLightHelper.prototype.update = function () {
  28454. if ( this.color !== undefined ) {
  28455. this.material.color.set( this.color );
  28456. } else {
  28457. this.material.color.copy( this.light.color );
  28458. }
  28459. /*
  28460. const d = this.light.distance;
  28461. if ( d === 0.0 ) {
  28462. this.lightDistance.visible = false;
  28463. } else {
  28464. this.lightDistance.visible = true;
  28465. this.lightDistance.scale.set( d, d, d );
  28466. }
  28467. */
  28468. };
  28469. /**
  28470. * @author alteredq / http://alteredqualia.com/
  28471. * @author mrdoob / http://mrdoob.com/
  28472. * @author Mugen87 / https://github.com/Mugen87
  28473. */
  28474. var _vector$a = new Vector3();
  28475. var _color1 = new Color();
  28476. var _color2 = new Color();
  28477. function HemisphereLightHelper( light, size, color ) {
  28478. Object3D.call( this );
  28479. this.light = light;
  28480. this.light.updateMatrixWorld();
  28481. this.matrix = light.matrixWorld;
  28482. this.matrixAutoUpdate = false;
  28483. this.color = color;
  28484. var geometry = new OctahedronBufferGeometry( size );
  28485. geometry.rotateY( Math.PI * 0.5 );
  28486. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28487. if ( this.color === undefined ) { this.material.vertexColors = true; }
  28488. var position = geometry.getAttribute( 'position' );
  28489. var colors = new Float32Array( position.count * 3 );
  28490. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  28491. this.add( new Mesh( geometry, this.material ) );
  28492. this.update();
  28493. }
  28494. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  28495. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  28496. HemisphereLightHelper.prototype.dispose = function () {
  28497. this.children[ 0 ].geometry.dispose();
  28498. this.children[ 0 ].material.dispose();
  28499. };
  28500. HemisphereLightHelper.prototype.update = function () {
  28501. var mesh = this.children[ 0 ];
  28502. if ( this.color !== undefined ) {
  28503. this.material.color.set( this.color );
  28504. } else {
  28505. var colors = mesh.geometry.getAttribute( 'color' );
  28506. _color1.copy( this.light.color );
  28507. _color2.copy( this.light.groundColor );
  28508. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  28509. var color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  28510. colors.setXYZ( i, color.r, color.g, color.b );
  28511. }
  28512. colors.needsUpdate = true;
  28513. }
  28514. mesh.lookAt( _vector$a.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  28515. };
  28516. /**
  28517. * @author mrdoob / http://mrdoob.com/
  28518. */
  28519. function GridHelper( size, divisions, color1, color2 ) {
  28520. size = size || 10;
  28521. divisions = divisions || 10;
  28522. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28523. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28524. var center = divisions / 2;
  28525. var step = size / divisions;
  28526. var halfSize = size / 2;
  28527. var vertices = [], colors = [];
  28528. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  28529. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  28530. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  28531. var color = i === center ? color1 : color2;
  28532. color.toArray( colors, j ); j += 3;
  28533. color.toArray( colors, j ); j += 3;
  28534. color.toArray( colors, j ); j += 3;
  28535. color.toArray( colors, j ); j += 3;
  28536. }
  28537. var geometry = new BufferGeometry();
  28538. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28539. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28540. var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28541. LineSegments.call( this, geometry, material );
  28542. this.type = 'GridHelper';
  28543. }
  28544. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  28545. constructor: GridHelper,
  28546. copy: function ( source ) {
  28547. LineSegments.prototype.copy.call( this, source );
  28548. this.geometry.copy( source.geometry );
  28549. this.material.copy( source.material );
  28550. return this;
  28551. },
  28552. clone: function () {
  28553. return new this.constructor().copy( this );
  28554. }
  28555. } );
  28556. /**
  28557. * @author mrdoob / http://mrdoob.com/
  28558. * @author Mugen87 / http://github.com/Mugen87
  28559. * @author Hectate / http://www.github.com/Hectate
  28560. */
  28561. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  28562. radius = radius || 10;
  28563. radials = radials || 16;
  28564. circles = circles || 8;
  28565. divisions = divisions || 64;
  28566. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28567. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28568. var vertices = [];
  28569. var colors = [];
  28570. // create the radials
  28571. for ( var i = 0; i <= radials; i ++ ) {
  28572. var v = ( i / radials ) * ( Math.PI * 2 );
  28573. var x = Math.sin( v ) * radius;
  28574. var z = Math.cos( v ) * radius;
  28575. vertices.push( 0, 0, 0 );
  28576. vertices.push( x, 0, z );
  28577. var color = ( i & 1 ) ? color1 : color2;
  28578. colors.push( color.r, color.g, color.b );
  28579. colors.push( color.r, color.g, color.b );
  28580. }
  28581. // create the circles
  28582. for ( var i$1 = 0; i$1 <= circles; i$1 ++ ) {
  28583. var color$1 = ( i$1 & 1 ) ? color1 : color2;
  28584. var r = radius - ( radius / circles * i$1 );
  28585. for ( var j = 0; j < divisions; j ++ ) {
  28586. // first vertex
  28587. var v$1 = ( j / divisions ) * ( Math.PI * 2 );
  28588. var x$1 = Math.sin( v$1 ) * r;
  28589. var z$1 = Math.cos( v$1 ) * r;
  28590. vertices.push( x$1, 0, z$1 );
  28591. colors.push( color$1.r, color$1.g, color$1.b );
  28592. // second vertex
  28593. v$1 = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  28594. x$1 = Math.sin( v$1 ) * r;
  28595. z$1 = Math.cos( v$1 ) * r;
  28596. vertices.push( x$1, 0, z$1 );
  28597. colors.push( color$1.r, color$1.g, color$1.b );
  28598. }
  28599. }
  28600. var geometry = new BufferGeometry();
  28601. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28602. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28603. var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28604. LineSegments.call( this, geometry, material );
  28605. this.type = 'PolarGridHelper';
  28606. }
  28607. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  28608. PolarGridHelper.prototype.constructor = PolarGridHelper;
  28609. /**
  28610. * @author alteredq / http://alteredqualia.com/
  28611. * @author mrdoob / http://mrdoob.com/
  28612. * @author WestLangley / http://github.com/WestLangley
  28613. */
  28614. var _v1$5 = new Vector3();
  28615. var _v2$3 = new Vector3();
  28616. var _v3$1 = new Vector3();
  28617. function DirectionalLightHelper( light, size, color ) {
  28618. Object3D.call( this );
  28619. this.light = light;
  28620. this.light.updateMatrixWorld();
  28621. this.matrix = light.matrixWorld;
  28622. this.matrixAutoUpdate = false;
  28623. this.color = color;
  28624. if ( size === undefined ) { size = 1; }
  28625. var geometry = new BufferGeometry();
  28626. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  28627. - size, size, 0,
  28628. size, size, 0,
  28629. size, - size, 0,
  28630. - size, - size, 0,
  28631. - size, size, 0
  28632. ], 3 ) );
  28633. var material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28634. this.lightPlane = new Line( geometry, material );
  28635. this.add( this.lightPlane );
  28636. geometry = new BufferGeometry();
  28637. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28638. this.targetLine = new Line( geometry, material );
  28639. this.add( this.targetLine );
  28640. this.update();
  28641. }
  28642. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  28643. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  28644. DirectionalLightHelper.prototype.dispose = function () {
  28645. this.lightPlane.geometry.dispose();
  28646. this.lightPlane.material.dispose();
  28647. this.targetLine.geometry.dispose();
  28648. this.targetLine.material.dispose();
  28649. };
  28650. DirectionalLightHelper.prototype.update = function () {
  28651. _v1$5.setFromMatrixPosition( this.light.matrixWorld );
  28652. _v2$3.setFromMatrixPosition( this.light.target.matrixWorld );
  28653. _v3$1.subVectors( _v2$3, _v1$5 );
  28654. this.lightPlane.lookAt( _v2$3 );
  28655. if ( this.color !== undefined ) {
  28656. this.lightPlane.material.color.set( this.color );
  28657. this.targetLine.material.color.set( this.color );
  28658. } else {
  28659. this.lightPlane.material.color.copy( this.light.color );
  28660. this.targetLine.material.color.copy( this.light.color );
  28661. }
  28662. this.targetLine.lookAt( _v2$3 );
  28663. this.targetLine.scale.z = _v3$1.length();
  28664. };
  28665. /**
  28666. * @author alteredq / http://alteredqualia.com/
  28667. * @author Mugen87 / https://github.com/Mugen87
  28668. *
  28669. * - shows frustum, line of sight and up of the camera
  28670. * - suitable for fast updates
  28671. * - based on frustum visualization in lightgl.js shadowmap example
  28672. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28673. */
  28674. var _vector$b = new Vector3();
  28675. var _camera = new Camera();
  28676. function CameraHelper( camera ) {
  28677. var geometry = new BufferGeometry();
  28678. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  28679. var vertices = [];
  28680. var colors = [];
  28681. var pointMap = {};
  28682. // colors
  28683. var colorFrustum = new Color( 0xffaa00 );
  28684. var colorCone = new Color( 0xff0000 );
  28685. var colorUp = new Color( 0x00aaff );
  28686. var colorTarget = new Color( 0xffffff );
  28687. var colorCross = new Color( 0x333333 );
  28688. // near
  28689. addLine( 'n1', 'n2', colorFrustum );
  28690. addLine( 'n2', 'n4', colorFrustum );
  28691. addLine( 'n4', 'n3', colorFrustum );
  28692. addLine( 'n3', 'n1', colorFrustum );
  28693. // far
  28694. addLine( 'f1', 'f2', colorFrustum );
  28695. addLine( 'f2', 'f4', colorFrustum );
  28696. addLine( 'f4', 'f3', colorFrustum );
  28697. addLine( 'f3', 'f1', colorFrustum );
  28698. // sides
  28699. addLine( 'n1', 'f1', colorFrustum );
  28700. addLine( 'n2', 'f2', colorFrustum );
  28701. addLine( 'n3', 'f3', colorFrustum );
  28702. addLine( 'n4', 'f4', colorFrustum );
  28703. // cone
  28704. addLine( 'p', 'n1', colorCone );
  28705. addLine( 'p', 'n2', colorCone );
  28706. addLine( 'p', 'n3', colorCone );
  28707. addLine( 'p', 'n4', colorCone );
  28708. // up
  28709. addLine( 'u1', 'u2', colorUp );
  28710. addLine( 'u2', 'u3', colorUp );
  28711. addLine( 'u3', 'u1', colorUp );
  28712. // target
  28713. addLine( 'c', 't', colorTarget );
  28714. addLine( 'p', 'c', colorCross );
  28715. // cross
  28716. addLine( 'cn1', 'cn2', colorCross );
  28717. addLine( 'cn3', 'cn4', colorCross );
  28718. addLine( 'cf1', 'cf2', colorCross );
  28719. addLine( 'cf3', 'cf4', colorCross );
  28720. function addLine( a, b, color ) {
  28721. addPoint( a, color );
  28722. addPoint( b, color );
  28723. }
  28724. function addPoint( id, color ) {
  28725. vertices.push( 0, 0, 0 );
  28726. colors.push( color.r, color.g, color.b );
  28727. if ( pointMap[ id ] === undefined ) {
  28728. pointMap[ id ] = [];
  28729. }
  28730. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28731. }
  28732. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28733. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28734. LineSegments.call( this, geometry, material );
  28735. this.type = 'CameraHelper';
  28736. this.camera = camera;
  28737. if ( this.camera.updateProjectionMatrix ) { this.camera.updateProjectionMatrix(); }
  28738. this.matrix = camera.matrixWorld;
  28739. this.matrixAutoUpdate = false;
  28740. this.pointMap = pointMap;
  28741. this.update();
  28742. }
  28743. CameraHelper.prototype = Object.create( LineSegments.prototype );
  28744. CameraHelper.prototype.constructor = CameraHelper;
  28745. CameraHelper.prototype.update = function () {
  28746. var geometry = this.geometry;
  28747. var pointMap = this.pointMap;
  28748. var w = 1, h = 1;
  28749. // we need just camera projection matrix inverse
  28750. // world matrix must be identity
  28751. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28752. // center / target
  28753. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  28754. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  28755. // near
  28756. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  28757. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  28758. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  28759. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  28760. // far
  28761. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  28762. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  28763. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  28764. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  28765. // up
  28766. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  28767. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  28768. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  28769. // cross
  28770. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  28771. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  28772. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  28773. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  28774. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  28775. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  28776. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  28777. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  28778. geometry.getAttribute( 'position' ).needsUpdate = true;
  28779. };
  28780. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  28781. _vector$b.set( x, y, z ).unproject( camera );
  28782. var points = pointMap[ point ];
  28783. if ( points !== undefined ) {
  28784. var position = geometry.getAttribute( 'position' );
  28785. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28786. position.setXYZ( points[ i ], _vector$b.x, _vector$b.y, _vector$b.z );
  28787. }
  28788. }
  28789. }
  28790. /**
  28791. * @author mrdoob / http://mrdoob.com/
  28792. * @author Mugen87 / http://github.com/Mugen87
  28793. */
  28794. var _box$3 = new Box3();
  28795. function BoxHelper( object, color ) {
  28796. this.object = object;
  28797. if ( color === undefined ) { color = 0xffff00; }
  28798. 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 ] );
  28799. var positions = new Float32Array( 8 * 3 );
  28800. var geometry = new BufferGeometry();
  28801. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28802. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28803. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28804. this.type = 'BoxHelper';
  28805. this.matrixAutoUpdate = false;
  28806. this.update();
  28807. }
  28808. BoxHelper.prototype = Object.create( LineSegments.prototype );
  28809. BoxHelper.prototype.constructor = BoxHelper;
  28810. BoxHelper.prototype.update = function ( object ) {
  28811. if ( object !== undefined ) {
  28812. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28813. }
  28814. if ( this.object !== undefined ) {
  28815. _box$3.setFromObject( this.object );
  28816. }
  28817. if ( _box$3.isEmpty() ) { return; }
  28818. var min = _box$3.min;
  28819. var max = _box$3.max;
  28820. /*
  28821. 5____4
  28822. 1/___0/|
  28823. | 6__|_7
  28824. 2/___3/
  28825. 0: max.x, max.y, max.z
  28826. 1: min.x, max.y, max.z
  28827. 2: min.x, min.y, max.z
  28828. 3: max.x, min.y, max.z
  28829. 4: max.x, max.y, min.z
  28830. 5: min.x, max.y, min.z
  28831. 6: min.x, min.y, min.z
  28832. 7: max.x, min.y, min.z
  28833. */
  28834. var position = this.geometry.attributes.position;
  28835. var array = position.array;
  28836. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28837. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28838. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28839. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28840. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28841. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28842. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28843. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28844. position.needsUpdate = true;
  28845. this.geometry.computeBoundingSphere();
  28846. };
  28847. BoxHelper.prototype.setFromObject = function ( object ) {
  28848. this.object = object;
  28849. this.update();
  28850. return this;
  28851. };
  28852. BoxHelper.prototype.copy = function ( source ) {
  28853. LineSegments.prototype.copy.call( this, source );
  28854. this.object = source.object;
  28855. return this;
  28856. };
  28857. BoxHelper.prototype.clone = function () {
  28858. return new this.constructor().copy( this );
  28859. };
  28860. /**
  28861. * @author WestLangley / http://github.com/WestLangley
  28862. */
  28863. function Box3Helper( box, color ) {
  28864. this.type = 'Box3Helper';
  28865. this.box = box;
  28866. color = color || 0xffff00;
  28867. 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 ] );
  28868. 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 ];
  28869. var geometry = new BufferGeometry();
  28870. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28871. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28872. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28873. this.type = 'Box3Helper';
  28874. this.geometry.computeBoundingSphere();
  28875. }
  28876. Box3Helper.prototype = Object.create( LineSegments.prototype );
  28877. Box3Helper.prototype.constructor = Box3Helper;
  28878. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  28879. var box = this.box;
  28880. if ( box.isEmpty() ) { return; }
  28881. box.getCenter( this.position );
  28882. box.getSize( this.scale );
  28883. this.scale.multiplyScalar( 0.5 );
  28884. Object3D.prototype.updateMatrixWorld.call( this, force );
  28885. };
  28886. /**
  28887. * @author WestLangley / http://github.com/WestLangley
  28888. */
  28889. function PlaneHelper( plane, size, hex ) {
  28890. this.plane = plane;
  28891. this.size = ( size === undefined ) ? 1 : size;
  28892. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28893. 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 ];
  28894. var geometry = new BufferGeometry();
  28895. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28896. geometry.computeBoundingSphere();
  28897. Line.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28898. this.type = 'PlaneHelper';
  28899. //
  28900. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28901. var geometry2 = new BufferGeometry();
  28902. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28903. geometry2.computeBoundingSphere();
  28904. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  28905. }
  28906. PlaneHelper.prototype = Object.create( Line.prototype );
  28907. PlaneHelper.prototype.constructor = PlaneHelper;
  28908. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  28909. var scale = - this.plane.constant;
  28910. if ( Math.abs( scale ) < 1e-8 ) { scale = 1e-8; } // sign does not matter
  28911. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28912. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28913. this.lookAt( this.plane.normal );
  28914. Object3D.prototype.updateMatrixWorld.call( this, force );
  28915. };
  28916. /**
  28917. * @author WestLangley / http://github.com/WestLangley
  28918. * @author zz85 / http://github.com/zz85
  28919. * @author bhouston / http://clara.io
  28920. *
  28921. * Creates an arrow for visualizing directions
  28922. *
  28923. * Parameters:
  28924. * dir - Vector3
  28925. * origin - Vector3
  28926. * length - Number
  28927. * color - color in hex value
  28928. * headLength - Number
  28929. * headWidth - Number
  28930. */
  28931. var _axis = new Vector3();
  28932. var _lineGeometry, _coneGeometry;
  28933. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28934. // dir is assumed to be normalized
  28935. Object3D.call( this );
  28936. this.type = 'ArrowHelper';
  28937. if ( dir === undefined ) { dir = new Vector3( 0, 0, 1 ); }
  28938. if ( origin === undefined ) { origin = new Vector3( 0, 0, 0 ); }
  28939. if ( length === undefined ) { length = 1; }
  28940. if ( color === undefined ) { color = 0xffff00; }
  28941. if ( headLength === undefined ) { headLength = 0.2 * length; }
  28942. if ( headWidth === undefined ) { headWidth = 0.2 * headLength; }
  28943. if ( _lineGeometry === undefined ) {
  28944. _lineGeometry = new BufferGeometry();
  28945. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28946. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28947. _coneGeometry.translate( 0, - 0.5, 0 );
  28948. }
  28949. this.position.copy( origin );
  28950. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28951. this.line.matrixAutoUpdate = false;
  28952. this.add( this.line );
  28953. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  28954. this.cone.matrixAutoUpdate = false;
  28955. this.add( this.cone );
  28956. this.setDirection( dir );
  28957. this.setLength( length, headLength, headWidth );
  28958. }
  28959. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28960. ArrowHelper.prototype.constructor = ArrowHelper;
  28961. ArrowHelper.prototype.setDirection = function ( dir ) {
  28962. // dir is assumed to be normalized
  28963. if ( dir.y > 0.99999 ) {
  28964. this.quaternion.set( 0, 0, 0, 1 );
  28965. } else if ( dir.y < - 0.99999 ) {
  28966. this.quaternion.set( 1, 0, 0, 0 );
  28967. } else {
  28968. _axis.set( dir.z, 0, - dir.x ).normalize();
  28969. var radians = Math.acos( dir.y );
  28970. this.quaternion.setFromAxisAngle( _axis, radians );
  28971. }
  28972. };
  28973. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28974. if ( headLength === undefined ) { headLength = 0.2 * length; }
  28975. if ( headWidth === undefined ) { headWidth = 0.2 * headLength; }
  28976. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28977. this.line.updateMatrix();
  28978. this.cone.scale.set( headWidth, headLength, headWidth );
  28979. this.cone.position.y = length;
  28980. this.cone.updateMatrix();
  28981. };
  28982. ArrowHelper.prototype.setColor = function ( color ) {
  28983. this.line.material.color.set( color );
  28984. this.cone.material.color.set( color );
  28985. };
  28986. ArrowHelper.prototype.copy = function ( source ) {
  28987. Object3D.prototype.copy.call( this, source, false );
  28988. this.line.copy( source.line );
  28989. this.cone.copy( source.cone );
  28990. return this;
  28991. };
  28992. ArrowHelper.prototype.clone = function () {
  28993. return new this.constructor().copy( this );
  28994. };
  28995. /**
  28996. * @author sroucheray / http://sroucheray.org/
  28997. * @author mrdoob / http://mrdoob.com/
  28998. */
  28999. function AxesHelper( size ) {
  29000. size = size || 1;
  29001. var vertices = [
  29002. 0, 0, 0, size, 0, 0,
  29003. 0, 0, 0, 0, size, 0,
  29004. 0, 0, 0, 0, 0, size
  29005. ];
  29006. var colors = [
  29007. 1, 0, 0, 1, 0.6, 0,
  29008. 0, 1, 0, 0.6, 1, 0,
  29009. 0, 0, 1, 0, 0.6, 1
  29010. ];
  29011. var geometry = new BufferGeometry();
  29012. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29013. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  29014. var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  29015. LineSegments.call( this, geometry, material );
  29016. this.type = 'AxesHelper';
  29017. }
  29018. AxesHelper.prototype = Object.create( LineSegments.prototype );
  29019. AxesHelper.prototype.constructor = AxesHelper;
  29020. /**
  29021. * @author Emmett Lalish / elalish
  29022. *
  29023. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  29024. * (PMREM) from a cubeMap environment texture. This allows different levels of
  29025. * blur to be quickly accessed based on material roughness. It is packed into a
  29026. * special CubeUV format that allows us to perform custom interpolation so that
  29027. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  29028. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  29029. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  29030. * higher roughness levels. In this way we maintain resolution to smoothly
  29031. * interpolate diffuse lighting while limiting sampling computation.
  29032. */
  29033. var LOD_MIN = 4;
  29034. var LOD_MAX = 8;
  29035. var SIZE_MAX = Math.pow( 2, LOD_MAX );
  29036. // The standard deviations (radians) associated with the extra mips. These are
  29037. // chosen to approximate a Trowbridge-Reitz distribution function times the
  29038. // geometric shadowing function. These sigma values squared must match the
  29039. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  29040. var EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  29041. var TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  29042. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  29043. // samples and exit early, but not recompile the shader.
  29044. var MAX_SAMPLES = 20;
  29045. var ENCODINGS = {};
  29046. ENCODINGS[ LinearEncoding ] = 0;
  29047. ENCODINGS[ sRGBEncoding ] = 1;
  29048. ENCODINGS[ RGBEEncoding ] = 2;
  29049. ENCODINGS[ RGBM7Encoding ] = 3;
  29050. ENCODINGS[ RGBM16Encoding ] = 4;
  29051. ENCODINGS[ RGBDEncoding ] = 5;
  29052. ENCODINGS[ GammaEncoding ] = 6;
  29053. var _flatCamera = new OrthographicCamera();
  29054. var ref = _createPlanes();
  29055. var _lodPlanes = ref._lodPlanes;
  29056. var _sizeLods = ref._sizeLods;
  29057. var _sigmas = ref._sigmas;
  29058. var _oldTarget = null;
  29059. // Golden Ratio
  29060. var PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  29061. var INV_PHI = 1 / PHI;
  29062. // Vertices of a dodecahedron (except the opposites, which represent the
  29063. // same axis), used as axis directions evenly spread on a sphere.
  29064. var _axisDirections = [
  29065. new Vector3( 1, 1, 1 ),
  29066. new Vector3( - 1, 1, 1 ),
  29067. new Vector3( 1, 1, - 1 ),
  29068. new Vector3( - 1, 1, - 1 ),
  29069. new Vector3( 0, PHI, INV_PHI ),
  29070. new Vector3( 0, PHI, - INV_PHI ),
  29071. new Vector3( INV_PHI, 0, PHI ),
  29072. new Vector3( - INV_PHI, 0, PHI ),
  29073. new Vector3( PHI, INV_PHI, 0 ),
  29074. new Vector3( - PHI, INV_PHI, 0 ) ];
  29075. function PMREMGenerator( renderer ) {
  29076. this._renderer = renderer;
  29077. this._pingPongRenderTarget = null;
  29078. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  29079. this._equirectShader = null;
  29080. this._cubemapShader = null;
  29081. this._compileMaterial( this._blurMaterial );
  29082. }
  29083. PMREMGenerator.prototype = {
  29084. constructor: PMREMGenerator,
  29085. /**
  29086. * Generates a PMREM from a supplied Scene, which can be faster than using an
  29087. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  29088. * in radians to be applied to the scene before PMREM generation. Optional near
  29089. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  29090. * is placed at the origin).
  29091. */
  29092. fromScene: function ( scene, sigma, near, far ) {
  29093. if ( sigma === void 0 ) sigma = 0;
  29094. if ( near === void 0 ) near = 0.1;
  29095. if ( far === void 0 ) far = 100;
  29096. _oldTarget = this._renderer.getRenderTarget();
  29097. var cubeUVRenderTarget = this._allocateTargets();
  29098. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  29099. if ( sigma > 0 ) {
  29100. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  29101. }
  29102. this._applyPMREM( cubeUVRenderTarget );
  29103. this._cleanup( cubeUVRenderTarget );
  29104. return cubeUVRenderTarget;
  29105. },
  29106. /**
  29107. * Generates a PMREM from an equirectangular texture, which can be either LDR
  29108. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  29109. * as this matches best with the 256 x 256 cubemap output.
  29110. */
  29111. fromEquirectangular: function ( equirectangular ) {
  29112. return this._fromTexture( equirectangular );
  29113. },
  29114. /**
  29115. * Generates a PMREM from an cubemap texture, which can be either LDR
  29116. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  29117. * as this matches best with the 256 x 256 cubemap output.
  29118. */
  29119. fromCubemap: function ( cubemap ) {
  29120. return this._fromTexture( cubemap );
  29121. },
  29122. /**
  29123. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  29124. * your texture's network fetch for increased concurrency.
  29125. */
  29126. compileCubemapShader: function () {
  29127. if ( this._cubemapShader === null ) {
  29128. this._cubemapShader = _getCubemapShader();
  29129. this._compileMaterial( this._cubemapShader );
  29130. }
  29131. },
  29132. /**
  29133. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  29134. * your texture's network fetch for increased concurrency.
  29135. */
  29136. compileEquirectangularShader: function () {
  29137. if ( this._equirectShader === null ) {
  29138. this._equirectShader = _getEquirectShader();
  29139. this._compileMaterial( this._equirectShader );
  29140. }
  29141. },
  29142. /**
  29143. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29144. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29145. * one of them will cause any others to also become unusable.
  29146. */
  29147. dispose: function () {
  29148. this._blurMaterial.dispose();
  29149. if ( this._cubemapShader !== null ) { this._cubemapShader.dispose(); }
  29150. if ( this._equirectShader !== null ) { this._equirectShader.dispose(); }
  29151. for ( var i = 0; i < _lodPlanes.length; i ++ ) {
  29152. _lodPlanes[ i ].dispose();
  29153. }
  29154. },
  29155. // private interface
  29156. _cleanup: function ( outputTarget ) {
  29157. this._pingPongRenderTarget.dispose();
  29158. this._renderer.setRenderTarget( _oldTarget );
  29159. outputTarget.scissorTest = false;
  29160. _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
  29161. },
  29162. _fromTexture: function ( texture ) {
  29163. _oldTarget = this._renderer.getRenderTarget();
  29164. var cubeUVRenderTarget = this._allocateTargets( texture );
  29165. this._textureToCubeUV( texture, cubeUVRenderTarget );
  29166. this._applyPMREM( cubeUVRenderTarget );
  29167. this._cleanup( cubeUVRenderTarget );
  29168. return cubeUVRenderTarget;
  29169. },
  29170. _allocateTargets: function ( texture ) { // warning: null texture is valid
  29171. var params = {
  29172. magFilter: NearestFilter,
  29173. minFilter: NearestFilter,
  29174. generateMipmaps: false,
  29175. type: UnsignedByteType,
  29176. format: RGBEFormat,
  29177. encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
  29178. depthBuffer: false,
  29179. stencilBuffer: false
  29180. };
  29181. var cubeUVRenderTarget = _createRenderTarget( params );
  29182. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29183. this._pingPongRenderTarget = _createRenderTarget( params );
  29184. return cubeUVRenderTarget;
  29185. },
  29186. _compileMaterial: function ( material ) {
  29187. var tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  29188. this._renderer.compile( tmpMesh, _flatCamera );
  29189. },
  29190. _sceneToCubeUV: function ( scene, near, far, cubeUVRenderTarget ) {
  29191. var fov = 90;
  29192. var aspect = 1;
  29193. var cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  29194. var upSign = [ 1, - 1, 1, 1, 1, 1 ];
  29195. var forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  29196. var renderer = this._renderer;
  29197. var outputEncoding = renderer.outputEncoding;
  29198. var toneMapping = renderer.toneMapping;
  29199. var clearColor = renderer.getClearColor();
  29200. var clearAlpha = renderer.getClearAlpha();
  29201. renderer.toneMapping = NoToneMapping;
  29202. renderer.outputEncoding = LinearEncoding;
  29203. var background = scene.background;
  29204. if ( background && background.isColor ) {
  29205. background.convertSRGBToLinear();
  29206. // Convert linear to RGBE
  29207. var maxComponent = Math.max( background.r, background.g, background.b );
  29208. var fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
  29209. background = background.multiplyScalar( Math.pow( 2.0, - fExp ) );
  29210. var alpha = ( fExp + 128.0 ) / 255.0;
  29211. renderer.setClearColor( background, alpha );
  29212. scene.background = null;
  29213. }
  29214. for ( var i = 0; i < 6; i ++ ) {
  29215. var col = i % 3;
  29216. if ( col == 0 ) {
  29217. cubeCamera.up.set( 0, upSign[ i ], 0 );
  29218. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  29219. } else if ( col == 1 ) {
  29220. cubeCamera.up.set( 0, 0, upSign[ i ] );
  29221. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  29222. } else {
  29223. cubeCamera.up.set( 0, upSign[ i ], 0 );
  29224. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  29225. }
  29226. _setViewport( cubeUVRenderTarget,
  29227. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  29228. renderer.setRenderTarget( cubeUVRenderTarget );
  29229. renderer.render( scene, cubeCamera );
  29230. }
  29231. renderer.toneMapping = toneMapping;
  29232. renderer.outputEncoding = outputEncoding;
  29233. renderer.setClearColor( clearColor, clearAlpha );
  29234. },
  29235. _textureToCubeUV: function ( texture, cubeUVRenderTarget ) {
  29236. var renderer = this._renderer;
  29237. if ( texture.isCubeTexture ) {
  29238. if ( this._cubemapShader == null ) {
  29239. this._cubemapShader = _getCubemapShader();
  29240. }
  29241. } else {
  29242. if ( this._equirectShader == null ) {
  29243. this._equirectShader = _getEquirectShader();
  29244. }
  29245. }
  29246. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29247. var mesh = new Mesh( _lodPlanes[ 0 ], material );
  29248. var uniforms = material.uniforms;
  29249. uniforms[ 'envMap' ].value = texture;
  29250. if ( ! texture.isCubeTexture ) {
  29251. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  29252. }
  29253. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  29254. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  29255. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  29256. renderer.setRenderTarget( cubeUVRenderTarget );
  29257. renderer.render( mesh, _flatCamera );
  29258. },
  29259. _applyPMREM: function ( cubeUVRenderTarget ) {
  29260. var renderer = this._renderer;
  29261. var autoClear = renderer.autoClear;
  29262. renderer.autoClear = false;
  29263. for ( var i = 1; i < TOTAL_LODS; i ++ ) {
  29264. var sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  29265. var poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  29266. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  29267. }
  29268. renderer.autoClear = autoClear;
  29269. },
  29270. /**
  29271. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29272. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29273. * the blur latitudinally (around the poles), and then longitudinally (towards
  29274. * the poles) to approximate the orthogonally-separable blur. It is least
  29275. * accurate at the poles, but still does a decent job.
  29276. */
  29277. _blur: function ( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  29278. var pingPongRenderTarget = this._pingPongRenderTarget;
  29279. this._halfBlur(
  29280. cubeUVRenderTarget,
  29281. pingPongRenderTarget,
  29282. lodIn,
  29283. lodOut,
  29284. sigma,
  29285. 'latitudinal',
  29286. poleAxis );
  29287. this._halfBlur(
  29288. pingPongRenderTarget,
  29289. cubeUVRenderTarget,
  29290. lodOut,
  29291. lodOut,
  29292. sigma,
  29293. 'longitudinal',
  29294. poleAxis );
  29295. },
  29296. _halfBlur: function ( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  29297. var renderer = this._renderer;
  29298. var blurMaterial = this._blurMaterial;
  29299. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  29300. console.error(
  29301. 'blur direction must be either latitudinal or longitudinal!' );
  29302. }
  29303. // Number of standard deviations at which to cut off the discrete approximation.
  29304. var STANDARD_DEVIATIONS = 3;
  29305. var blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  29306. var blurUniforms = blurMaterial.uniforms;
  29307. var pixels = _sizeLods[ lodIn ] - 1;
  29308. var radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  29309. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29310. var samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  29311. if ( samples > MAX_SAMPLES ) {
  29312. console.warn( ("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES) );
  29313. }
  29314. var weights = [];
  29315. var sum = 0;
  29316. for ( var i = 0; i < MAX_SAMPLES; ++ i ) {
  29317. var x$1 = i / sigmaPixels;
  29318. var weight = Math.exp( - x$1 * x$1 / 2 );
  29319. weights.push( weight );
  29320. if ( i == 0 ) {
  29321. sum += weight;
  29322. } else if ( i < samples ) {
  29323. sum += 2 * weight;
  29324. }
  29325. }
  29326. for ( var i$1 = 0; i$1 < weights.length; i$1 ++ ) {
  29327. weights[ i$1 ] = weights[ i$1 ] / sum;
  29328. }
  29329. blurUniforms[ 'envMap' ].value = targetIn.texture;
  29330. blurUniforms[ 'samples' ].value = samples;
  29331. blurUniforms[ 'weights' ].value = weights;
  29332. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  29333. if ( poleAxis ) {
  29334. blurUniforms[ 'poleAxis' ].value = poleAxis;
  29335. }
  29336. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  29337. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  29338. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  29339. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  29340. var outputSize = _sizeLods[ lodOut ];
  29341. var x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  29342. var y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  29343. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  29344. renderer.setRenderTarget( targetOut );
  29345. renderer.render( blurMesh, _flatCamera );
  29346. }
  29347. };
  29348. function _isLDR( texture ) {
  29349. if ( texture === undefined || texture.type !== UnsignedByteType ) { return false; }
  29350. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29351. }
  29352. function _createPlanes() {
  29353. var _lodPlanes = [];
  29354. var _sizeLods = [];
  29355. var _sigmas = [];
  29356. var lod = LOD_MAX;
  29357. for ( var i = 0; i < TOTAL_LODS; i ++ ) {
  29358. var sizeLod = Math.pow( 2, lod );
  29359. _sizeLods.push( sizeLod );
  29360. var sigma = 1.0 / sizeLod;
  29361. if ( i > LOD_MAX - LOD_MIN ) {
  29362. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  29363. } else if ( i == 0 ) {
  29364. sigma = 0;
  29365. }
  29366. _sigmas.push( sigma );
  29367. var texelSize = 1.0 / ( sizeLod - 1 );
  29368. var min = - texelSize / 2;
  29369. var max = 1 + texelSize / 2;
  29370. var uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  29371. var cubeFaces = 6;
  29372. var vertices = 6;
  29373. var positionSize = 3;
  29374. var uvSize = 2;
  29375. var faceIndexSize = 1;
  29376. var position = new Float32Array( positionSize * vertices * cubeFaces );
  29377. var uv = new Float32Array( uvSize * vertices * cubeFaces );
  29378. var faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  29379. for ( var face = 0; face < cubeFaces; face ++ ) {
  29380. var x = ( face % 3 ) * 2 / 3 - 1;
  29381. var y = face > 2 ? 0 : - 1;
  29382. var coordinates = [
  29383. x, y, 0,
  29384. x + 2 / 3, y, 0,
  29385. x + 2 / 3, y + 1, 0,
  29386. x, y, 0,
  29387. x + 2 / 3, y + 1, 0,
  29388. x, y + 1, 0
  29389. ];
  29390. position.set( coordinates, positionSize * vertices * face );
  29391. uv.set( uv1, uvSize * vertices * face );
  29392. var fill = [ face, face, face, face, face, face ];
  29393. faceIndex.set( fill, faceIndexSize * vertices * face );
  29394. }
  29395. var planes = new BufferGeometry();
  29396. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  29397. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  29398. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  29399. _lodPlanes.push( planes );
  29400. if ( lod > LOD_MIN ) {
  29401. lod --;
  29402. }
  29403. }
  29404. return { _lodPlanes: _lodPlanes, _sizeLods: _sizeLods, _sigmas: _sigmas };
  29405. }
  29406. function _createRenderTarget( params ) {
  29407. var cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  29408. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29409. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29410. cubeUVRenderTarget.scissorTest = true;
  29411. return cubeUVRenderTarget;
  29412. }
  29413. function _setViewport( target, x, y, width, height ) {
  29414. target.viewport.set( x, y, width, height );
  29415. target.scissor.set( x, y, width, height );
  29416. }
  29417. function _getBlurShader( maxSamples ) {
  29418. var weights = new Float32Array( maxSamples );
  29419. var poleAxis = new Vector3( 0, 1, 0 );
  29420. var shaderMaterial = new RawShaderMaterial( {
  29421. name: 'SphericalGaussianBlur',
  29422. defines: { 'n': maxSamples },
  29423. uniforms: {
  29424. 'envMap': { value: null },
  29425. 'samples': { value: 1 },
  29426. 'weights': { value: weights },
  29427. 'latitudinal': { value: false },
  29428. 'dTheta': { value: 0 },
  29429. 'mipInt': { value: 0 },
  29430. 'poleAxis': { value: poleAxis },
  29431. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29432. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29433. },
  29434. vertexShader: _getCommonVertexShader(),
  29435. fragmentShader: ("\nprecision mediump float;\nprecision mediump int;\nvarying vec3 vOutputDirection;\nuniform sampler2D envMap;\nuniform int samples;\nuniform float weights[n];\nuniform bool latitudinal;\nuniform float dTheta;\nuniform float mipInt;\nuniform vec3 poleAxis;\n\n" + (_getEncodings()) + "\n\n#define ENVMAP_TYPE_CUBE_UV\n#include <cube_uv_reflection_fragment>\n\nvec3 getSample(float theta, vec3 axis) {\n\tfloat cosTheta = cos(theta);\n\t// Rodrigues' axis-angle rotation\n\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t+ cross(axis, vOutputDirection) * sin(theta)\n\t\t+ axis * dot(axis, vOutputDirection) * (1.0 - cosTheta);\n\treturn bilinearCubeUV(envMap, sampleDirection, mipInt);\n}\n\nvoid main() {\n\tvec3 axis = latitudinal ? poleAxis : cross(poleAxis, vOutputDirection);\n\tif (all(equal(axis, vec3(0.0))))\n\t\taxis = vec3(vOutputDirection.z, 0.0, - vOutputDirection.x);\n\taxis = normalize(axis);\n\tgl_FragColor = vec4(0.0);\n\tgl_FragColor.rgb += weights[0] * getSample(0.0, axis);\n\tfor (int i = 1; i < n; i++) {\n\t\tif (i >= samples)\n\t\t\tbreak;\n\t\tfloat theta = dTheta * float(i);\n\t\tgl_FragColor.rgb += weights[i] * getSample(-1.0 * theta, axis);\n\t\tgl_FragColor.rgb += weights[i] * getSample(theta, axis);\n\t}\n\tgl_FragColor = linearToOutputTexel(gl_FragColor);\n}\n\t\t"),
  29436. blending: NoBlending,
  29437. depthTest: false,
  29438. depthWrite: false
  29439. } );
  29440. return shaderMaterial;
  29441. }
  29442. function _getEquirectShader() {
  29443. var texelSize = new Vector2( 1, 1 );
  29444. var shaderMaterial = new RawShaderMaterial( {
  29445. name: 'EquirectangularToCubeUV',
  29446. uniforms: {
  29447. 'envMap': { value: null },
  29448. 'texelSize': { value: texelSize },
  29449. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29450. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29451. },
  29452. vertexShader: _getCommonVertexShader(),
  29453. fragmentShader: ("\nprecision mediump float;\nprecision mediump int;\nvarying vec3 vOutputDirection;\nuniform sampler2D envMap;\nuniform vec2 texelSize;\n\n" + (_getEncodings()) + "\n\n#include <common>\n\nvoid main() {\n\tgl_FragColor = vec4(0.0);\n\tvec3 outputDirection = normalize(vOutputDirection);\n\tvec2 uv = equirectUv( outputDirection );\n\tvec2 f = fract(uv / texelSize - 0.5);\n\tuv -= f * texelSize;\n\tvec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tuv.x += texelSize.x;\n\tvec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tuv.y += texelSize.y;\n\tvec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tuv.x -= texelSize.x;\n\tvec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tvec3 tm = mix(tl, tr, f.x);\n\tvec3 bm = mix(bl, br, f.x);\n\tgl_FragColor.rgb = mix(tm, bm, f.y);\n\tgl_FragColor = linearToOutputTexel(gl_FragColor);\n}\n\t\t"),
  29454. blending: NoBlending,
  29455. depthTest: false,
  29456. depthWrite: false
  29457. } );
  29458. return shaderMaterial;
  29459. }
  29460. function _getCubemapShader() {
  29461. var shaderMaterial = new RawShaderMaterial( {
  29462. name: 'CubemapToCubeUV',
  29463. uniforms: {
  29464. 'envMap': { value: null },
  29465. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29466. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29467. },
  29468. vertexShader: _getCommonVertexShader(),
  29469. fragmentShader: ("\nprecision mediump float;\nprecision mediump int;\nvarying vec3 vOutputDirection;\nuniform samplerCube envMap;\n\n" + (_getEncodings()) + "\n\nvoid main() {\n\tgl_FragColor = vec4(0.0);\n\tgl_FragColor.rgb = envMapTexelToLinear(textureCube(envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ))).rgb;\n\tgl_FragColor = linearToOutputTexel(gl_FragColor);\n}\n\t\t"),
  29470. blending: NoBlending,
  29471. depthTest: false,
  29472. depthWrite: false
  29473. } );
  29474. return shaderMaterial;
  29475. }
  29476. function _getCommonVertexShader() {
  29477. return "\nprecision mediump float;\nprecision mediump int;\nattribute vec3 position;\nattribute vec2 uv;\nattribute float faceIndex;\nvarying vec3 vOutputDirection;\n\n// RH coordinate system; PMREM face-indexing convention\nvec3 getDirection(vec2 uv, float face) {\n\tuv = 2.0 * uv - 1.0;\n\tvec3 direction = vec3(uv, 1.0);\n\tif (face == 0.0) {\n\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\t} else if (face == 1.0) {\n\t\tdirection = direction.xzy;\n\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\t} else if (face == 2.0) {\n\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\t} else if (face == 3.0) {\n\t\tdirection = direction.zyx;\n\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\t} else if (face == 4.0) {\n\t\tdirection = direction.xzy;\n\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\t} else if (face == 5.0) {\n\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\t}\n\treturn direction;\n}\n\nvoid main() {\n\tvOutputDirection = getDirection(uv, faceIndex);\n\tgl_Position = vec4( position, 1.0 );\n}\n\t";
  29478. }
  29479. function _getEncodings() {
  29480. return "\nuniform int inputEncoding;\nuniform int outputEncoding;\n\n#include <encodings_pars_fragment>\n\nvec4 inputTexelToLinear(vec4 value){\n\tif(inputEncoding == 0){\n\t\treturn value;\n\t}else if(inputEncoding == 1){\n\t\treturn sRGBToLinear(value);\n\t}else if(inputEncoding == 2){\n\t\treturn RGBEToLinear(value);\n\t}else if(inputEncoding == 3){\n\t\treturn RGBMToLinear(value, 7.0);\n\t}else if(inputEncoding == 4){\n\t\treturn RGBMToLinear(value, 16.0);\n\t}else if(inputEncoding == 5){\n\t\treturn RGBDToLinear(value, 256.0);\n\t}else{\n\t\treturn GammaToLinear(value, 2.2);\n\t}\n}\n\nvec4 linearToOutputTexel(vec4 value){\n\tif(outputEncoding == 0){\n\t\treturn value;\n\t}else if(outputEncoding == 1){\n\t\treturn LinearTosRGB(value);\n\t}else if(outputEncoding == 2){\n\t\treturn LinearToRGBE(value);\n\t}else if(outputEncoding == 3){\n\t\treturn LinearToRGBM(value, 7.0);\n\t}else if(outputEncoding == 4){\n\t\treturn LinearToRGBM(value, 16.0);\n\t}else if(outputEncoding == 5){\n\t\treturn LinearToRGBD(value, 256.0);\n\t}else{\n\t\treturn LinearToGamma(value, 2.2);\n\t}\n}\n\nvec4 envMapTexelToLinear(vec4 color) {\n\treturn inputTexelToLinear(color);\n}\n\t";
  29481. }
  29482. /**
  29483. * @author mrdoob / http://mrdoob.com/
  29484. */
  29485. function Face4( a, b, c, d, normal, color, materialIndex ) {
  29486. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  29487. return new Face3( a, b, c, normal, color, materialIndex );
  29488. }
  29489. var LineStrip = 0;
  29490. var LinePieces = 1;
  29491. var NoColors = 0;
  29492. var FaceColors = 1;
  29493. var VertexColors = 2;
  29494. function MeshFaceMaterial( materials ) {
  29495. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  29496. return materials;
  29497. }
  29498. function MultiMaterial( materials ) {
  29499. if ( materials === undefined ) { materials = []; }
  29500. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  29501. materials.isMultiMaterial = true;
  29502. materials.materials = materials;
  29503. materials.clone = function () {
  29504. return materials.slice();
  29505. };
  29506. return materials;
  29507. }
  29508. function PointCloud( geometry, material ) {
  29509. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  29510. return new Points( geometry, material );
  29511. }
  29512. function Particle( material ) {
  29513. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  29514. return new Sprite( material );
  29515. }
  29516. function ParticleSystem( geometry, material ) {
  29517. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  29518. return new Points( geometry, material );
  29519. }
  29520. function PointCloudMaterial( parameters ) {
  29521. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  29522. return new PointsMaterial( parameters );
  29523. }
  29524. function ParticleBasicMaterial( parameters ) {
  29525. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  29526. return new PointsMaterial( parameters );
  29527. }
  29528. function ParticleSystemMaterial( parameters ) {
  29529. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  29530. return new PointsMaterial( parameters );
  29531. }
  29532. function Vertex( x, y, z ) {
  29533. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  29534. return new Vector3( x, y, z );
  29535. }
  29536. //
  29537. function DynamicBufferAttribute( array, itemSize ) {
  29538. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  29539. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  29540. }
  29541. function Int8Attribute( array, itemSize ) {
  29542. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  29543. return new Int8BufferAttribute( array, itemSize );
  29544. }
  29545. function Uint8Attribute( array, itemSize ) {
  29546. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  29547. return new Uint8BufferAttribute( array, itemSize );
  29548. }
  29549. function Uint8ClampedAttribute( array, itemSize ) {
  29550. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  29551. return new Uint8ClampedBufferAttribute( array, itemSize );
  29552. }
  29553. function Int16Attribute( array, itemSize ) {
  29554. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  29555. return new Int16BufferAttribute( array, itemSize );
  29556. }
  29557. function Uint16Attribute( array, itemSize ) {
  29558. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  29559. return new Uint16BufferAttribute( array, itemSize );
  29560. }
  29561. function Int32Attribute( array, itemSize ) {
  29562. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  29563. return new Int32BufferAttribute( array, itemSize );
  29564. }
  29565. function Uint32Attribute( array, itemSize ) {
  29566. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  29567. return new Uint32BufferAttribute( array, itemSize );
  29568. }
  29569. function Float32Attribute( array, itemSize ) {
  29570. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  29571. return new Float32BufferAttribute( array, itemSize );
  29572. }
  29573. function Float64Attribute( array, itemSize ) {
  29574. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  29575. return new Float64BufferAttribute( array, itemSize );
  29576. }
  29577. //
  29578. Curve.create = function ( construct, getPoint ) {
  29579. console.log( 'THREE.Curve.create() has been deprecated' );
  29580. construct.prototype = Object.create( Curve.prototype );
  29581. construct.prototype.constructor = construct;
  29582. construct.prototype.getPoint = getPoint;
  29583. return construct;
  29584. };
  29585. //
  29586. Object.assign( CurvePath.prototype, {
  29587. createPointsGeometry: function ( divisions ) {
  29588. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29589. // generate geometry from path points (for Line or Points objects)
  29590. var pts = this.getPoints( divisions );
  29591. return this.createGeometry( pts );
  29592. },
  29593. createSpacedPointsGeometry: function ( divisions ) {
  29594. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29595. // generate geometry from equidistant sampling along the path
  29596. var pts = this.getSpacedPoints( divisions );
  29597. return this.createGeometry( pts );
  29598. },
  29599. createGeometry: function ( points ) {
  29600. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29601. var geometry = new Geometry();
  29602. for ( var i = 0, l = points.length; i < l; i ++ ) {
  29603. var point = points[ i ];
  29604. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  29605. }
  29606. return geometry;
  29607. }
  29608. } );
  29609. //
  29610. Object.assign( Path.prototype, {
  29611. fromPoints: function ( points ) {
  29612. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  29613. return this.setFromPoints( points );
  29614. }
  29615. } );
  29616. //
  29617. function ClosedSplineCurve3( points ) {
  29618. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29619. CatmullRomCurve3.call( this, points );
  29620. this.type = 'catmullrom';
  29621. this.closed = true;
  29622. }
  29623. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29624. //
  29625. function SplineCurve3( points ) {
  29626. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29627. CatmullRomCurve3.call( this, points );
  29628. this.type = 'catmullrom';
  29629. }
  29630. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29631. //
  29632. function Spline( points ) {
  29633. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  29634. CatmullRomCurve3.call( this, points );
  29635. this.type = 'catmullrom';
  29636. }
  29637. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  29638. Object.assign( Spline.prototype, {
  29639. initFromArray: function ( /* a */ ) {
  29640. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  29641. },
  29642. getControlPointsArray: function ( /* optionalTarget */ ) {
  29643. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  29644. },
  29645. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  29646. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  29647. }
  29648. } );
  29649. //
  29650. function AxisHelper( size ) {
  29651. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  29652. return new AxesHelper( size );
  29653. }
  29654. function BoundingBoxHelper( object, color ) {
  29655. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  29656. return new BoxHelper( object, color );
  29657. }
  29658. function EdgesHelper( object, hex ) {
  29659. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  29660. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29661. }
  29662. GridHelper.prototype.setColors = function () {
  29663. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  29664. };
  29665. SkeletonHelper.prototype.update = function () {
  29666. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  29667. };
  29668. function WireframeHelper( object, hex ) {
  29669. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  29670. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29671. }
  29672. //
  29673. Object.assign( Loader.prototype, {
  29674. extractUrlBase: function ( url ) {
  29675. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  29676. return LoaderUtils.extractUrlBase( url );
  29677. }
  29678. } );
  29679. Loader.Handlers = {
  29680. add: function ( /* regex, loader */ ) {
  29681. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  29682. },
  29683. get: function ( /* file */ ) {
  29684. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  29685. }
  29686. };
  29687. function XHRLoader( manager ) {
  29688. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  29689. return new FileLoader( manager );
  29690. }
  29691. function BinaryTextureLoader( manager ) {
  29692. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  29693. return new DataTextureLoader( manager );
  29694. }
  29695. Object.assign( ObjectLoader.prototype, {
  29696. setTexturePath: function ( value ) {
  29697. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  29698. return this.setResourcePath( value );
  29699. }
  29700. } );
  29701. //
  29702. Object.assign( Box2.prototype, {
  29703. center: function ( optionalTarget ) {
  29704. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  29705. return this.getCenter( optionalTarget );
  29706. },
  29707. empty: function () {
  29708. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  29709. return this.isEmpty();
  29710. },
  29711. isIntersectionBox: function ( box ) {
  29712. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29713. return this.intersectsBox( box );
  29714. },
  29715. size: function ( optionalTarget ) {
  29716. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  29717. return this.getSize( optionalTarget );
  29718. }
  29719. } );
  29720. Object.assign( Box3.prototype, {
  29721. center: function ( optionalTarget ) {
  29722. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  29723. return this.getCenter( optionalTarget );
  29724. },
  29725. empty: function () {
  29726. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  29727. return this.isEmpty();
  29728. },
  29729. isIntersectionBox: function ( box ) {
  29730. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29731. return this.intersectsBox( box );
  29732. },
  29733. isIntersectionSphere: function ( sphere ) {
  29734. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29735. return this.intersectsSphere( sphere );
  29736. },
  29737. size: function ( optionalTarget ) {
  29738. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  29739. return this.getSize( optionalTarget );
  29740. }
  29741. } );
  29742. Object.assign( Sphere.prototype, {
  29743. empty: function () {
  29744. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  29745. return this.isEmpty();
  29746. },
  29747. } );
  29748. Frustum.prototype.setFromMatrix = function ( m ) {
  29749. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  29750. return this.setFromProjectionMatrix( m );
  29751. };
  29752. Line3.prototype.center = function ( optionalTarget ) {
  29753. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  29754. return this.getCenter( optionalTarget );
  29755. };
  29756. Object.assign( MathUtils, {
  29757. random16: function () {
  29758. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  29759. return Math.random();
  29760. },
  29761. nearestPowerOfTwo: function ( value ) {
  29762. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  29763. return MathUtils.floorPowerOfTwo( value );
  29764. },
  29765. nextPowerOfTwo: function ( value ) {
  29766. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  29767. return MathUtils.ceilPowerOfTwo( value );
  29768. }
  29769. } );
  29770. Object.assign( Matrix3.prototype, {
  29771. flattenToArrayOffset: function ( array, offset ) {
  29772. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29773. return this.toArray( array, offset );
  29774. },
  29775. multiplyVector3: function ( vector ) {
  29776. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  29777. return vector.applyMatrix3( this );
  29778. },
  29779. multiplyVector3Array: function ( /* a */ ) {
  29780. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  29781. },
  29782. applyToBufferAttribute: function ( attribute ) {
  29783. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  29784. return attribute.applyMatrix3( this );
  29785. },
  29786. applyToVector3Array: function ( /* array, offset, length */ ) {
  29787. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  29788. }
  29789. } );
  29790. Object.assign( Matrix4.prototype, {
  29791. extractPosition: function ( m ) {
  29792. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  29793. return this.copyPosition( m );
  29794. },
  29795. flattenToArrayOffset: function ( array, offset ) {
  29796. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29797. return this.toArray( array, offset );
  29798. },
  29799. getPosition: function () {
  29800. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  29801. return new Vector3().setFromMatrixColumn( this, 3 );
  29802. },
  29803. setRotationFromQuaternion: function ( q ) {
  29804. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  29805. return this.makeRotationFromQuaternion( q );
  29806. },
  29807. multiplyToArray: function () {
  29808. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  29809. },
  29810. multiplyVector3: function ( vector ) {
  29811. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29812. return vector.applyMatrix4( this );
  29813. },
  29814. multiplyVector4: function ( vector ) {
  29815. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29816. return vector.applyMatrix4( this );
  29817. },
  29818. multiplyVector3Array: function ( /* a */ ) {
  29819. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  29820. },
  29821. rotateAxis: function ( v ) {
  29822. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  29823. v.transformDirection( this );
  29824. },
  29825. crossVector: function ( vector ) {
  29826. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29827. return vector.applyMatrix4( this );
  29828. },
  29829. translate: function () {
  29830. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  29831. },
  29832. rotateX: function () {
  29833. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  29834. },
  29835. rotateY: function () {
  29836. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  29837. },
  29838. rotateZ: function () {
  29839. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  29840. },
  29841. rotateByAxis: function () {
  29842. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  29843. },
  29844. applyToBufferAttribute: function ( attribute ) {
  29845. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  29846. return attribute.applyMatrix4( this );
  29847. },
  29848. applyToVector3Array: function ( /* array, offset, length */ ) {
  29849. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  29850. },
  29851. makeFrustum: function ( left, right, bottom, top, near, far ) {
  29852. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  29853. return this.makePerspective( left, right, top, bottom, near, far );
  29854. }
  29855. } );
  29856. Plane.prototype.isIntersectionLine = function ( line ) {
  29857. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  29858. return this.intersectsLine( line );
  29859. };
  29860. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  29861. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  29862. return vector.applyQuaternion( this );
  29863. };
  29864. Object.assign( Ray.prototype, {
  29865. isIntersectionBox: function ( box ) {
  29866. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29867. return this.intersectsBox( box );
  29868. },
  29869. isIntersectionPlane: function ( plane ) {
  29870. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  29871. return this.intersectsPlane( plane );
  29872. },
  29873. isIntersectionSphere: function ( sphere ) {
  29874. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29875. return this.intersectsSphere( sphere );
  29876. }
  29877. } );
  29878. Object.assign( Triangle.prototype, {
  29879. area: function () {
  29880. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  29881. return this.getArea();
  29882. },
  29883. barycoordFromPoint: function ( point, target ) {
  29884. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29885. return this.getBarycoord( point, target );
  29886. },
  29887. midpoint: function ( target ) {
  29888. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  29889. return this.getMidpoint( target );
  29890. },
  29891. normal: function ( target ) {
  29892. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29893. return this.getNormal( target );
  29894. },
  29895. plane: function ( target ) {
  29896. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  29897. return this.getPlane( target );
  29898. }
  29899. } );
  29900. Object.assign( Triangle, {
  29901. barycoordFromPoint: function ( point, a, b, c, target ) {
  29902. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29903. return Triangle.getBarycoord( point, a, b, c, target );
  29904. },
  29905. normal: function ( a, b, c, target ) {
  29906. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29907. return Triangle.getNormal( a, b, c, target );
  29908. }
  29909. } );
  29910. Object.assign( Shape.prototype, {
  29911. extractAllPoints: function ( divisions ) {
  29912. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  29913. return this.extractPoints( divisions );
  29914. },
  29915. extrude: function ( options ) {
  29916. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  29917. return new ExtrudeGeometry( this, options );
  29918. },
  29919. makeGeometry: function ( options ) {
  29920. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  29921. return new ShapeGeometry( this, options );
  29922. }
  29923. } );
  29924. Object.assign( Vector2.prototype, {
  29925. fromAttribute: function ( attribute, index, offset ) {
  29926. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29927. return this.fromBufferAttribute( attribute, index, offset );
  29928. },
  29929. distanceToManhattan: function ( v ) {
  29930. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29931. return this.manhattanDistanceTo( v );
  29932. },
  29933. lengthManhattan: function () {
  29934. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  29935. return this.manhattanLength();
  29936. }
  29937. } );
  29938. Object.assign( Vector3.prototype, {
  29939. setEulerFromRotationMatrix: function () {
  29940. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  29941. },
  29942. setEulerFromQuaternion: function () {
  29943. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  29944. },
  29945. getPositionFromMatrix: function ( m ) {
  29946. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  29947. return this.setFromMatrixPosition( m );
  29948. },
  29949. getScaleFromMatrix: function ( m ) {
  29950. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  29951. return this.setFromMatrixScale( m );
  29952. },
  29953. getColumnFromMatrix: function ( index, matrix ) {
  29954. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  29955. return this.setFromMatrixColumn( matrix, index );
  29956. },
  29957. applyProjection: function ( m ) {
  29958. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  29959. return this.applyMatrix4( m );
  29960. },
  29961. fromAttribute: function ( attribute, index, offset ) {
  29962. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29963. return this.fromBufferAttribute( attribute, index, offset );
  29964. },
  29965. distanceToManhattan: function ( v ) {
  29966. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29967. return this.manhattanDistanceTo( v );
  29968. },
  29969. lengthManhattan: function () {
  29970. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  29971. return this.manhattanLength();
  29972. }
  29973. } );
  29974. Object.assign( Vector4.prototype, {
  29975. fromAttribute: function ( attribute, index, offset ) {
  29976. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29977. return this.fromBufferAttribute( attribute, index, offset );
  29978. },
  29979. lengthManhattan: function () {
  29980. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  29981. return this.manhattanLength();
  29982. }
  29983. } );
  29984. //
  29985. Object.assign( Geometry.prototype, {
  29986. computeTangents: function () {
  29987. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  29988. },
  29989. computeLineDistances: function () {
  29990. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  29991. },
  29992. applyMatrix: function ( matrix ) {
  29993. console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  29994. return this.applyMatrix4( matrix );
  29995. }
  29996. } );
  29997. Object.assign( Object3D.prototype, {
  29998. getChildByName: function ( name ) {
  29999. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  30000. return this.getObjectByName( name );
  30001. },
  30002. renderDepth: function () {
  30003. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  30004. },
  30005. translate: function ( distance, axis ) {
  30006. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  30007. return this.translateOnAxis( axis, distance );
  30008. },
  30009. getWorldRotation: function () {
  30010. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  30011. },
  30012. applyMatrix: function ( matrix ) {
  30013. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  30014. return this.applyMatrix4( matrix );
  30015. }
  30016. } );
  30017. Object.defineProperties( Object3D.prototype, {
  30018. eulerOrder: {
  30019. get: function () {
  30020. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  30021. return this.rotation.order;
  30022. },
  30023. set: function ( value ) {
  30024. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  30025. this.rotation.order = value;
  30026. }
  30027. },
  30028. useQuaternion: {
  30029. get: function () {
  30030. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  30031. },
  30032. set: function () {
  30033. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  30034. }
  30035. }
  30036. } );
  30037. Object.assign( Mesh.prototype, {
  30038. setDrawMode: function () {
  30039. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  30040. },
  30041. } );
  30042. Object.defineProperties( Mesh.prototype, {
  30043. drawMode: {
  30044. get: function () {
  30045. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  30046. return TrianglesDrawMode;
  30047. },
  30048. set: function () {
  30049. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  30050. }
  30051. }
  30052. } );
  30053. Object.defineProperties( LOD.prototype, {
  30054. objects: {
  30055. get: function () {
  30056. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  30057. return this.levels;
  30058. }
  30059. }
  30060. } );
  30061. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  30062. get: function () {
  30063. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  30064. },
  30065. set: function () {
  30066. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  30067. }
  30068. } );
  30069. SkinnedMesh.prototype.initBones = function () {
  30070. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  30071. };
  30072. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  30073. get: function () {
  30074. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  30075. return this.arcLengthDivisions;
  30076. },
  30077. set: function ( value ) {
  30078. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  30079. this.arcLengthDivisions = value;
  30080. }
  30081. } );
  30082. //
  30083. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  30084. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  30085. "Use .setFocalLength and .filmGauge for a photographic setup." );
  30086. if ( filmGauge !== undefined ) { this.filmGauge = filmGauge; }
  30087. this.setFocalLength( focalLength );
  30088. };
  30089. //
  30090. Object.defineProperties( Light.prototype, {
  30091. onlyShadow: {
  30092. set: function () {
  30093. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  30094. }
  30095. },
  30096. shadowCameraFov: {
  30097. set: function ( value ) {
  30098. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  30099. this.shadow.camera.fov = value;
  30100. }
  30101. },
  30102. shadowCameraLeft: {
  30103. set: function ( value ) {
  30104. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  30105. this.shadow.camera.left = value;
  30106. }
  30107. },
  30108. shadowCameraRight: {
  30109. set: function ( value ) {
  30110. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  30111. this.shadow.camera.right = value;
  30112. }
  30113. },
  30114. shadowCameraTop: {
  30115. set: function ( value ) {
  30116. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  30117. this.shadow.camera.top = value;
  30118. }
  30119. },
  30120. shadowCameraBottom: {
  30121. set: function ( value ) {
  30122. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  30123. this.shadow.camera.bottom = value;
  30124. }
  30125. },
  30126. shadowCameraNear: {
  30127. set: function ( value ) {
  30128. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  30129. this.shadow.camera.near = value;
  30130. }
  30131. },
  30132. shadowCameraFar: {
  30133. set: function ( value ) {
  30134. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  30135. this.shadow.camera.far = value;
  30136. }
  30137. },
  30138. shadowCameraVisible: {
  30139. set: function () {
  30140. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  30141. }
  30142. },
  30143. shadowBias: {
  30144. set: function ( value ) {
  30145. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  30146. this.shadow.bias = value;
  30147. }
  30148. },
  30149. shadowDarkness: {
  30150. set: function () {
  30151. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  30152. }
  30153. },
  30154. shadowMapWidth: {
  30155. set: function ( value ) {
  30156. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  30157. this.shadow.mapSize.width = value;
  30158. }
  30159. },
  30160. shadowMapHeight: {
  30161. set: function ( value ) {
  30162. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  30163. this.shadow.mapSize.height = value;
  30164. }
  30165. }
  30166. } );
  30167. //
  30168. Object.defineProperties( BufferAttribute.prototype, {
  30169. length: {
  30170. get: function () {
  30171. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  30172. return this.array.length;
  30173. }
  30174. },
  30175. dynamic: {
  30176. get: function () {
  30177. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  30178. return this.usage === DynamicDrawUsage;
  30179. },
  30180. set: function ( /* value */ ) {
  30181. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  30182. this.setUsage( DynamicDrawUsage );
  30183. }
  30184. }
  30185. } );
  30186. Object.assign( BufferAttribute.prototype, {
  30187. setDynamic: function ( value ) {
  30188. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30189. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30190. return this;
  30191. },
  30192. copyIndicesArray: function ( /* indices */ ) {
  30193. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  30194. },
  30195. setArray: function ( /* array */ ) {
  30196. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30197. }
  30198. } );
  30199. Object.assign( BufferGeometry.prototype, {
  30200. addIndex: function ( index ) {
  30201. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  30202. this.setIndex( index );
  30203. },
  30204. addAttribute: function ( name, attribute ) {
  30205. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  30206. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  30207. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  30208. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  30209. }
  30210. if ( name === 'index' ) {
  30211. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  30212. this.setIndex( attribute );
  30213. return this;
  30214. }
  30215. return this.setAttribute( name, attribute );
  30216. },
  30217. addDrawCall: function ( start, count, indexOffset ) {
  30218. if ( indexOffset !== undefined ) {
  30219. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  30220. }
  30221. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  30222. this.addGroup( start, count );
  30223. },
  30224. clearDrawCalls: function () {
  30225. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  30226. this.clearGroups();
  30227. },
  30228. computeTangents: function () {
  30229. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  30230. },
  30231. computeOffsets: function () {
  30232. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  30233. },
  30234. removeAttribute: function ( name ) {
  30235. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  30236. return this.deleteAttribute( name );
  30237. },
  30238. applyMatrix: function ( matrix ) {
  30239. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  30240. return this.applyMatrix4( matrix );
  30241. }
  30242. } );
  30243. Object.defineProperties( BufferGeometry.prototype, {
  30244. drawcalls: {
  30245. get: function () {
  30246. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  30247. return this.groups;
  30248. }
  30249. },
  30250. offsets: {
  30251. get: function () {
  30252. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  30253. return this.groups;
  30254. }
  30255. }
  30256. } );
  30257. Object.defineProperties( InstancedBufferGeometry.prototype, {
  30258. maxInstancedCount: {
  30259. get: function () {
  30260. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30261. return this.instanceCount;
  30262. },
  30263. set: function ( value ) {
  30264. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30265. this.instanceCount = value;
  30266. }
  30267. }
  30268. } );
  30269. Object.defineProperties( Raycaster.prototype, {
  30270. linePrecision: {
  30271. get: function () {
  30272. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30273. return this.params.Line.threshold;
  30274. },
  30275. set: function ( value ) {
  30276. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30277. this.params.Line.threshold = value;
  30278. }
  30279. }
  30280. } );
  30281. Object.defineProperties( InterleavedBuffer.prototype, {
  30282. dynamic: {
  30283. get: function () {
  30284. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30285. return this.usage === DynamicDrawUsage;
  30286. },
  30287. set: function ( value ) {
  30288. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30289. this.setUsage( value );
  30290. }
  30291. }
  30292. } );
  30293. Object.assign( InterleavedBuffer.prototype, {
  30294. setDynamic: function ( value ) {
  30295. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30296. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30297. return this;
  30298. },
  30299. setArray: function ( /* array */ ) {
  30300. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30301. }
  30302. } );
  30303. //
  30304. Object.assign( ExtrudeBufferGeometry.prototype, {
  30305. getArrays: function () {
  30306. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  30307. },
  30308. addShapeList: function () {
  30309. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  30310. },
  30311. addShape: function () {
  30312. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  30313. }
  30314. } );
  30315. //
  30316. Object.defineProperties( Uniform.prototype, {
  30317. dynamic: {
  30318. set: function () {
  30319. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  30320. }
  30321. },
  30322. onUpdate: {
  30323. value: function () {
  30324. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  30325. return this;
  30326. }
  30327. }
  30328. } );
  30329. //
  30330. Object.defineProperties( Material.prototype, {
  30331. wrapAround: {
  30332. get: function () {
  30333. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30334. },
  30335. set: function () {
  30336. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30337. }
  30338. },
  30339. overdraw: {
  30340. get: function () {
  30341. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30342. },
  30343. set: function () {
  30344. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30345. }
  30346. },
  30347. wrapRGB: {
  30348. get: function () {
  30349. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  30350. return new Color();
  30351. }
  30352. },
  30353. shading: {
  30354. get: function () {
  30355. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30356. },
  30357. set: function ( value ) {
  30358. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30359. this.flatShading = ( value === FlatShading );
  30360. }
  30361. },
  30362. stencilMask: {
  30363. get: function () {
  30364. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30365. return this.stencilFuncMask;
  30366. },
  30367. set: function ( value ) {
  30368. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30369. this.stencilFuncMask = value;
  30370. }
  30371. }
  30372. } );
  30373. Object.defineProperties( MeshPhongMaterial.prototype, {
  30374. metal: {
  30375. get: function () {
  30376. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  30377. return false;
  30378. },
  30379. set: function () {
  30380. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  30381. }
  30382. }
  30383. } );
  30384. Object.defineProperties( ShaderMaterial.prototype, {
  30385. derivatives: {
  30386. get: function () {
  30387. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30388. return this.extensions.derivatives;
  30389. },
  30390. set: function ( value ) {
  30391. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30392. this.extensions.derivatives = value;
  30393. }
  30394. }
  30395. } );
  30396. //
  30397. Object.assign( WebGLRenderer.prototype, {
  30398. clearTarget: function ( renderTarget, color, depth, stencil ) {
  30399. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  30400. this.setRenderTarget( renderTarget );
  30401. this.clear( color, depth, stencil );
  30402. },
  30403. animate: function ( callback ) {
  30404. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  30405. this.setAnimationLoop( callback );
  30406. },
  30407. getCurrentRenderTarget: function () {
  30408. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  30409. return this.getRenderTarget();
  30410. },
  30411. getMaxAnisotropy: function () {
  30412. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  30413. return this.capabilities.getMaxAnisotropy();
  30414. },
  30415. getPrecision: function () {
  30416. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  30417. return this.capabilities.precision;
  30418. },
  30419. resetGLState: function () {
  30420. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  30421. return this.state.reset();
  30422. },
  30423. supportsFloatTextures: function () {
  30424. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  30425. return this.extensions.get( 'OES_texture_float' );
  30426. },
  30427. supportsHalfFloatTextures: function () {
  30428. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  30429. return this.extensions.get( 'OES_texture_half_float' );
  30430. },
  30431. supportsStandardDerivatives: function () {
  30432. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  30433. return this.extensions.get( 'OES_standard_derivatives' );
  30434. },
  30435. supportsCompressedTextureS3TC: function () {
  30436. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  30437. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  30438. },
  30439. supportsCompressedTexturePVRTC: function () {
  30440. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  30441. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  30442. },
  30443. supportsBlendMinMax: function () {
  30444. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  30445. return this.extensions.get( 'EXT_blend_minmax' );
  30446. },
  30447. supportsVertexTextures: function () {
  30448. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  30449. return this.capabilities.vertexTextures;
  30450. },
  30451. supportsInstancedArrays: function () {
  30452. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  30453. return this.extensions.get( 'ANGLE_instanced_arrays' );
  30454. },
  30455. enableScissorTest: function ( boolean ) {
  30456. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  30457. this.setScissorTest( boolean );
  30458. },
  30459. initMaterial: function () {
  30460. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  30461. },
  30462. addPrePlugin: function () {
  30463. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  30464. },
  30465. addPostPlugin: function () {
  30466. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  30467. },
  30468. updateShadowMap: function () {
  30469. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  30470. },
  30471. setFaceCulling: function () {
  30472. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  30473. },
  30474. allocTextureUnit: function () {
  30475. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  30476. },
  30477. setTexture: function () {
  30478. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  30479. },
  30480. setTexture2D: function () {
  30481. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  30482. },
  30483. setTextureCube: function () {
  30484. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  30485. },
  30486. getActiveMipMapLevel: function () {
  30487. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  30488. return this.getActiveMipmapLevel();
  30489. }
  30490. } );
  30491. Object.defineProperties( WebGLRenderer.prototype, {
  30492. shadowMapEnabled: {
  30493. get: function () {
  30494. return this.shadowMap.enabled;
  30495. },
  30496. set: function ( value ) {
  30497. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  30498. this.shadowMap.enabled = value;
  30499. }
  30500. },
  30501. shadowMapType: {
  30502. get: function () {
  30503. return this.shadowMap.type;
  30504. },
  30505. set: function ( value ) {
  30506. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  30507. this.shadowMap.type = value;
  30508. }
  30509. },
  30510. shadowMapCullFace: {
  30511. get: function () {
  30512. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30513. return undefined;
  30514. },
  30515. set: function ( /* value */ ) {
  30516. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30517. }
  30518. },
  30519. context: {
  30520. get: function () {
  30521. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  30522. return this.getContext();
  30523. }
  30524. },
  30525. vr: {
  30526. get: function () {
  30527. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  30528. return this.xr;
  30529. }
  30530. },
  30531. gammaInput: {
  30532. get: function () {
  30533. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30534. return false;
  30535. },
  30536. set: function () {
  30537. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30538. }
  30539. },
  30540. gammaOutput: {
  30541. get: function () {
  30542. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30543. return false;
  30544. },
  30545. set: function ( value ) {
  30546. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30547. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  30548. }
  30549. },
  30550. toneMappingWhitePoint: {
  30551. get: function () {
  30552. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  30553. return 1.0;
  30554. },
  30555. set: function () {
  30556. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  30557. }
  30558. },
  30559. } );
  30560. Object.defineProperties( WebGLShadowMap.prototype, {
  30561. cullFace: {
  30562. get: function () {
  30563. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30564. return undefined;
  30565. },
  30566. set: function ( /* cullFace */ ) {
  30567. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30568. }
  30569. },
  30570. renderReverseSided: {
  30571. get: function () {
  30572. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30573. return undefined;
  30574. },
  30575. set: function () {
  30576. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30577. }
  30578. },
  30579. renderSingleSided: {
  30580. get: function () {
  30581. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30582. return undefined;
  30583. },
  30584. set: function () {
  30585. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30586. }
  30587. }
  30588. } );
  30589. function WebGLRenderTargetCube( width, height, options ) {
  30590. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  30591. return new WebGLCubeRenderTarget( width, options );
  30592. }
  30593. //
  30594. Object.defineProperties( WebGLRenderTarget.prototype, {
  30595. wrapS: {
  30596. get: function () {
  30597. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30598. return this.texture.wrapS;
  30599. },
  30600. set: function ( value ) {
  30601. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30602. this.texture.wrapS = value;
  30603. }
  30604. },
  30605. wrapT: {
  30606. get: function () {
  30607. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30608. return this.texture.wrapT;
  30609. },
  30610. set: function ( value ) {
  30611. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30612. this.texture.wrapT = value;
  30613. }
  30614. },
  30615. magFilter: {
  30616. get: function () {
  30617. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30618. return this.texture.magFilter;
  30619. },
  30620. set: function ( value ) {
  30621. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30622. this.texture.magFilter = value;
  30623. }
  30624. },
  30625. minFilter: {
  30626. get: function () {
  30627. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30628. return this.texture.minFilter;
  30629. },
  30630. set: function ( value ) {
  30631. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30632. this.texture.minFilter = value;
  30633. }
  30634. },
  30635. anisotropy: {
  30636. get: function () {
  30637. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30638. return this.texture.anisotropy;
  30639. },
  30640. set: function ( value ) {
  30641. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30642. this.texture.anisotropy = value;
  30643. }
  30644. },
  30645. offset: {
  30646. get: function () {
  30647. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30648. return this.texture.offset;
  30649. },
  30650. set: function ( value ) {
  30651. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30652. this.texture.offset = value;
  30653. }
  30654. },
  30655. repeat: {
  30656. get: function () {
  30657. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30658. return this.texture.repeat;
  30659. },
  30660. set: function ( value ) {
  30661. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30662. this.texture.repeat = value;
  30663. }
  30664. },
  30665. format: {
  30666. get: function () {
  30667. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30668. return this.texture.format;
  30669. },
  30670. set: function ( value ) {
  30671. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30672. this.texture.format = value;
  30673. }
  30674. },
  30675. type: {
  30676. get: function () {
  30677. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30678. return this.texture.type;
  30679. },
  30680. set: function ( value ) {
  30681. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30682. this.texture.type = value;
  30683. }
  30684. },
  30685. generateMipmaps: {
  30686. get: function () {
  30687. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30688. return this.texture.generateMipmaps;
  30689. },
  30690. set: function ( value ) {
  30691. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30692. this.texture.generateMipmaps = value;
  30693. }
  30694. }
  30695. } );
  30696. //
  30697. Object.defineProperties( Audio.prototype, {
  30698. load: {
  30699. value: function ( file ) {
  30700. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  30701. var scope = this;
  30702. var audioLoader = new AudioLoader();
  30703. audioLoader.load( file, function ( buffer ) {
  30704. scope.setBuffer( buffer );
  30705. } );
  30706. return this;
  30707. }
  30708. },
  30709. startTime: {
  30710. set: function () {
  30711. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  30712. }
  30713. }
  30714. } );
  30715. AudioAnalyser.prototype.getData = function () {
  30716. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  30717. return this.getFrequencyData();
  30718. };
  30719. //
  30720. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  30721. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  30722. return this.update( renderer, scene );
  30723. };
  30724. //
  30725. var GeometryUtils = {
  30726. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  30727. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  30728. var matrix;
  30729. if ( geometry2.isMesh ) {
  30730. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30731. matrix = geometry2.matrix;
  30732. geometry2 = geometry2.geometry;
  30733. }
  30734. geometry1.merge( geometry2, matrix, materialIndexOffset );
  30735. },
  30736. center: function ( geometry ) {
  30737. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  30738. return geometry.center();
  30739. }
  30740. };
  30741. ImageUtils.crossOrigin = undefined;
  30742. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  30743. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  30744. var loader = new TextureLoader();
  30745. loader.setCrossOrigin( this.crossOrigin );
  30746. var texture = loader.load( url, onLoad, undefined, onError );
  30747. if ( mapping ) { texture.mapping = mapping; }
  30748. return texture;
  30749. };
  30750. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  30751. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  30752. var loader = new CubeTextureLoader();
  30753. loader.setCrossOrigin( this.crossOrigin );
  30754. var texture = loader.load( urls, onLoad, undefined, onError );
  30755. if ( mapping ) { texture.mapping = mapping; }
  30756. return texture;
  30757. };
  30758. ImageUtils.loadCompressedTexture = function () {
  30759. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  30760. };
  30761. ImageUtils.loadCompressedTextureCube = function () {
  30762. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  30763. };
  30764. //
  30765. function CanvasRenderer() {
  30766. console.error( 'THREE.CanvasRenderer has been removed' );
  30767. }
  30768. //
  30769. function JSONLoader() {
  30770. console.error( 'THREE.JSONLoader has been removed.' );
  30771. }
  30772. //
  30773. var SceneUtils = {
  30774. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  30775. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30776. },
  30777. detach: function ( /* child, parent, scene */ ) {
  30778. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30779. },
  30780. attach: function ( /* child, scene, parent */ ) {
  30781. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30782. }
  30783. };
  30784. //
  30785. function LensFlare() {
  30786. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  30787. }
  30788. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  30789. /* eslint-disable no-undef */
  30790. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  30791. revision: REVISION,
  30792. } } ) );
  30793. /* eslint-enable no-undef */
  30794. }
  30795. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30796. exports.AddEquation = AddEquation;
  30797. exports.AddOperation = AddOperation;
  30798. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30799. exports.AdditiveBlending = AdditiveBlending;
  30800. exports.AlphaFormat = AlphaFormat;
  30801. exports.AlwaysDepth = AlwaysDepth;
  30802. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30803. exports.AmbientLight = AmbientLight;
  30804. exports.AmbientLightProbe = AmbientLightProbe;
  30805. exports.AnimationClip = AnimationClip;
  30806. exports.AnimationLoader = AnimationLoader;
  30807. exports.AnimationMixer = AnimationMixer;
  30808. exports.AnimationObjectGroup = AnimationObjectGroup;
  30809. exports.AnimationUtils = AnimationUtils;
  30810. exports.ArcCurve = ArcCurve;
  30811. exports.ArrayCamera = ArrayCamera;
  30812. exports.ArrowHelper = ArrowHelper;
  30813. exports.Audio = Audio;
  30814. exports.AudioAnalyser = AudioAnalyser;
  30815. exports.AudioContext = AudioContext;
  30816. exports.AudioListener = AudioListener;
  30817. exports.AudioLoader = AudioLoader;
  30818. exports.AxesHelper = AxesHelper;
  30819. exports.AxisHelper = AxisHelper;
  30820. exports.BackSide = BackSide;
  30821. exports.BasicDepthPacking = BasicDepthPacking;
  30822. exports.BasicShadowMap = BasicShadowMap;
  30823. exports.BinaryTextureLoader = BinaryTextureLoader;
  30824. exports.Bone = Bone;
  30825. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30826. exports.BoundingBoxHelper = BoundingBoxHelper;
  30827. exports.Box2 = Box2;
  30828. exports.Box3 = Box3;
  30829. exports.Box3Helper = Box3Helper;
  30830. exports.BoxBufferGeometry = BoxBufferGeometry;
  30831. exports.BoxGeometry = BoxGeometry;
  30832. exports.BoxHelper = BoxHelper;
  30833. exports.BufferAttribute = BufferAttribute;
  30834. exports.BufferGeometry = BufferGeometry;
  30835. exports.BufferGeometryLoader = BufferGeometryLoader;
  30836. exports.ByteType = ByteType;
  30837. exports.Cache = Cache;
  30838. exports.Camera = Camera;
  30839. exports.CameraHelper = CameraHelper;
  30840. exports.CanvasRenderer = CanvasRenderer;
  30841. exports.CanvasTexture = CanvasTexture;
  30842. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30843. exports.CineonToneMapping = CineonToneMapping;
  30844. exports.CircleBufferGeometry = CircleBufferGeometry;
  30845. exports.CircleGeometry = CircleGeometry;
  30846. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30847. exports.Clock = Clock;
  30848. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30849. exports.Color = Color;
  30850. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30851. exports.CompressedTexture = CompressedTexture;
  30852. exports.CompressedTextureLoader = CompressedTextureLoader;
  30853. exports.ConeBufferGeometry = ConeBufferGeometry;
  30854. exports.ConeGeometry = ConeGeometry;
  30855. exports.CubeCamera = CubeCamera;
  30856. exports.CubeGeometry = BoxGeometry;
  30857. exports.CubeReflectionMapping = CubeReflectionMapping;
  30858. exports.CubeRefractionMapping = CubeRefractionMapping;
  30859. exports.CubeTexture = CubeTexture;
  30860. exports.CubeTextureLoader = CubeTextureLoader;
  30861. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30862. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30863. exports.CubicBezierCurve = CubicBezierCurve;
  30864. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30865. exports.CubicInterpolant = CubicInterpolant;
  30866. exports.CullFaceBack = CullFaceBack;
  30867. exports.CullFaceFront = CullFaceFront;
  30868. exports.CullFaceFrontBack = CullFaceFrontBack;
  30869. exports.CullFaceNone = CullFaceNone;
  30870. exports.Curve = Curve;
  30871. exports.CurvePath = CurvePath;
  30872. exports.CustomBlending = CustomBlending;
  30873. exports.CustomToneMapping = CustomToneMapping;
  30874. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  30875. exports.CylinderGeometry = CylinderGeometry;
  30876. exports.Cylindrical = Cylindrical;
  30877. exports.DataTexture = DataTexture;
  30878. exports.DataTexture2DArray = DataTexture2DArray;
  30879. exports.DataTexture3D = DataTexture3D;
  30880. exports.DataTextureLoader = DataTextureLoader;
  30881. exports.DecrementStencilOp = DecrementStencilOp;
  30882. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30883. exports.DefaultLoadingManager = DefaultLoadingManager;
  30884. exports.DepthFormat = DepthFormat;
  30885. exports.DepthStencilFormat = DepthStencilFormat;
  30886. exports.DepthTexture = DepthTexture;
  30887. exports.DirectionalLight = DirectionalLight;
  30888. exports.DirectionalLightHelper = DirectionalLightHelper;
  30889. exports.DirectionalLightShadow = DirectionalLightShadow;
  30890. exports.DiscreteInterpolant = DiscreteInterpolant;
  30891. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  30892. exports.DodecahedronGeometry = DodecahedronGeometry;
  30893. exports.DoubleSide = DoubleSide;
  30894. exports.DstAlphaFactor = DstAlphaFactor;
  30895. exports.DstColorFactor = DstColorFactor;
  30896. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30897. exports.DynamicCopyUsage = DynamicCopyUsage;
  30898. exports.DynamicDrawUsage = DynamicDrawUsage;
  30899. exports.DynamicReadUsage = DynamicReadUsage;
  30900. exports.EdgesGeometry = EdgesGeometry;
  30901. exports.EdgesHelper = EdgesHelper;
  30902. exports.EllipseCurve = EllipseCurve;
  30903. exports.EqualDepth = EqualDepth;
  30904. exports.EqualStencilFunc = EqualStencilFunc;
  30905. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30906. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30907. exports.Euler = Euler;
  30908. exports.EventDispatcher = EventDispatcher;
  30909. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  30910. exports.ExtrudeGeometry = ExtrudeGeometry;
  30911. exports.Face3 = Face3;
  30912. exports.Face4 = Face4;
  30913. exports.FaceColors = FaceColors;
  30914. exports.FileLoader = FileLoader;
  30915. exports.FlatShading = FlatShading;
  30916. exports.Float32Attribute = Float32Attribute;
  30917. exports.Float32BufferAttribute = Float32BufferAttribute;
  30918. exports.Float64Attribute = Float64Attribute;
  30919. exports.Float64BufferAttribute = Float64BufferAttribute;
  30920. exports.FloatType = FloatType;
  30921. exports.Fog = Fog;
  30922. exports.FogExp2 = FogExp2;
  30923. exports.Font = Font;
  30924. exports.FontLoader = FontLoader;
  30925. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  30926. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  30927. exports.FrontSide = FrontSide;
  30928. exports.Frustum = Frustum;
  30929. exports.GammaEncoding = GammaEncoding;
  30930. exports.Geometry = Geometry;
  30931. exports.GeometryUtils = GeometryUtils;
  30932. exports.GreaterDepth = GreaterDepth;
  30933. exports.GreaterEqualDepth = GreaterEqualDepth;
  30934. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30935. exports.GreaterStencilFunc = GreaterStencilFunc;
  30936. exports.GridHelper = GridHelper;
  30937. exports.Group = Group;
  30938. exports.HalfFloatType = HalfFloatType;
  30939. exports.HemisphereLight = HemisphereLight;
  30940. exports.HemisphereLightHelper = HemisphereLightHelper;
  30941. exports.HemisphereLightProbe = HemisphereLightProbe;
  30942. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  30943. exports.IcosahedronGeometry = IcosahedronGeometry;
  30944. exports.ImageBitmapLoader = ImageBitmapLoader;
  30945. exports.ImageLoader = ImageLoader;
  30946. exports.ImageUtils = ImageUtils;
  30947. exports.ImmediateRenderObject = ImmediateRenderObject;
  30948. exports.IncrementStencilOp = IncrementStencilOp;
  30949. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30950. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30951. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30952. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30953. exports.InstancedMesh = InstancedMesh;
  30954. exports.Int16Attribute = Int16Attribute;
  30955. exports.Int16BufferAttribute = Int16BufferAttribute;
  30956. exports.Int32Attribute = Int32Attribute;
  30957. exports.Int32BufferAttribute = Int32BufferAttribute;
  30958. exports.Int8Attribute = Int8Attribute;
  30959. exports.Int8BufferAttribute = Int8BufferAttribute;
  30960. exports.IntType = IntType;
  30961. exports.InterleavedBuffer = InterleavedBuffer;
  30962. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30963. exports.Interpolant = Interpolant;
  30964. exports.InterpolateDiscrete = InterpolateDiscrete;
  30965. exports.InterpolateLinear = InterpolateLinear;
  30966. exports.InterpolateSmooth = InterpolateSmooth;
  30967. exports.InvertStencilOp = InvertStencilOp;
  30968. exports.JSONLoader = JSONLoader;
  30969. exports.KeepStencilOp = KeepStencilOp;
  30970. exports.KeyframeTrack = KeyframeTrack;
  30971. exports.LOD = LOD;
  30972. exports.LatheBufferGeometry = LatheBufferGeometry;
  30973. exports.LatheGeometry = LatheGeometry;
  30974. exports.Layers = Layers;
  30975. exports.LensFlare = LensFlare;
  30976. exports.LessDepth = LessDepth;
  30977. exports.LessEqualDepth = LessEqualDepth;
  30978. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30979. exports.LessStencilFunc = LessStencilFunc;
  30980. exports.Light = Light;
  30981. exports.LightProbe = LightProbe;
  30982. exports.LightShadow = LightShadow;
  30983. exports.Line = Line;
  30984. exports.Line3 = Line3;
  30985. exports.LineBasicMaterial = LineBasicMaterial;
  30986. exports.LineCurve = LineCurve;
  30987. exports.LineCurve3 = LineCurve3;
  30988. exports.LineDashedMaterial = LineDashedMaterial;
  30989. exports.LineLoop = LineLoop;
  30990. exports.LinePieces = LinePieces;
  30991. exports.LineSegments = LineSegments;
  30992. exports.LineStrip = LineStrip;
  30993. exports.LinearEncoding = LinearEncoding;
  30994. exports.LinearFilter = LinearFilter;
  30995. exports.LinearInterpolant = LinearInterpolant;
  30996. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30997. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30998. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30999. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  31000. exports.LinearToneMapping = LinearToneMapping;
  31001. exports.Loader = Loader;
  31002. exports.LoaderUtils = LoaderUtils;
  31003. exports.LoadingManager = LoadingManager;
  31004. exports.LogLuvEncoding = LogLuvEncoding;
  31005. exports.LoopOnce = LoopOnce;
  31006. exports.LoopPingPong = LoopPingPong;
  31007. exports.LoopRepeat = LoopRepeat;
  31008. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  31009. exports.LuminanceFormat = LuminanceFormat;
  31010. exports.MOUSE = MOUSE;
  31011. exports.Material = Material;
  31012. exports.MaterialLoader = MaterialLoader;
  31013. exports.Math = MathUtils;
  31014. exports.MathUtils = MathUtils;
  31015. exports.Matrix3 = Matrix3;
  31016. exports.Matrix4 = Matrix4;
  31017. exports.MaxEquation = MaxEquation;
  31018. exports.Mesh = Mesh;
  31019. exports.MeshBasicMaterial = MeshBasicMaterial;
  31020. exports.MeshDepthMaterial = MeshDepthMaterial;
  31021. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  31022. exports.MeshFaceMaterial = MeshFaceMaterial;
  31023. exports.MeshLambertMaterial = MeshLambertMaterial;
  31024. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  31025. exports.MeshNormalMaterial = MeshNormalMaterial;
  31026. exports.MeshPhongMaterial = MeshPhongMaterial;
  31027. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  31028. exports.MeshStandardMaterial = MeshStandardMaterial;
  31029. exports.MeshToonMaterial = MeshToonMaterial;
  31030. exports.MinEquation = MinEquation;
  31031. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  31032. exports.MixOperation = MixOperation;
  31033. exports.MultiMaterial = MultiMaterial;
  31034. exports.MultiplyBlending = MultiplyBlending;
  31035. exports.MultiplyOperation = MultiplyOperation;
  31036. exports.NearestFilter = NearestFilter;
  31037. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  31038. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  31039. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  31040. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  31041. exports.NeverDepth = NeverDepth;
  31042. exports.NeverStencilFunc = NeverStencilFunc;
  31043. exports.NoBlending = NoBlending;
  31044. exports.NoColors = NoColors;
  31045. exports.NoToneMapping = NoToneMapping;
  31046. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  31047. exports.NormalBlending = NormalBlending;
  31048. exports.NotEqualDepth = NotEqualDepth;
  31049. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  31050. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  31051. exports.Object3D = Object3D;
  31052. exports.ObjectLoader = ObjectLoader;
  31053. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  31054. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  31055. exports.OctahedronGeometry = OctahedronGeometry;
  31056. exports.OneFactor = OneFactor;
  31057. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  31058. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  31059. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  31060. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  31061. exports.OrthographicCamera = OrthographicCamera;
  31062. exports.PCFShadowMap = PCFShadowMap;
  31063. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  31064. exports.PMREMGenerator = PMREMGenerator;
  31065. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  31066. exports.ParametricGeometry = ParametricGeometry;
  31067. exports.Particle = Particle;
  31068. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  31069. exports.ParticleSystem = ParticleSystem;
  31070. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  31071. exports.Path = Path;
  31072. exports.PerspectiveCamera = PerspectiveCamera;
  31073. exports.Plane = Plane;
  31074. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  31075. exports.PlaneGeometry = PlaneGeometry;
  31076. exports.PlaneHelper = PlaneHelper;
  31077. exports.PointCloud = PointCloud;
  31078. exports.PointCloudMaterial = PointCloudMaterial;
  31079. exports.PointLight = PointLight;
  31080. exports.PointLightHelper = PointLightHelper;
  31081. exports.Points = Points;
  31082. exports.PointsMaterial = PointsMaterial;
  31083. exports.PolarGridHelper = PolarGridHelper;
  31084. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  31085. exports.PolyhedronGeometry = PolyhedronGeometry;
  31086. exports.PositionalAudio = PositionalAudio;
  31087. exports.PropertyBinding = PropertyBinding;
  31088. exports.PropertyMixer = PropertyMixer;
  31089. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  31090. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  31091. exports.Quaternion = Quaternion;
  31092. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  31093. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  31094. exports.REVISION = REVISION;
  31095. exports.RGBADepthPacking = RGBADepthPacking;
  31096. exports.RGBAFormat = RGBAFormat;
  31097. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  31098. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  31099. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  31100. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  31101. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  31102. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  31103. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  31104. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  31105. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  31106. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  31107. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  31108. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  31109. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  31110. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  31111. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  31112. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  31113. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  31114. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  31115. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  31116. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  31117. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  31118. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  31119. exports.RGBDEncoding = RGBDEncoding;
  31120. exports.RGBEEncoding = RGBEEncoding;
  31121. exports.RGBEFormat = RGBEFormat;
  31122. exports.RGBFormat = RGBFormat;
  31123. exports.RGBIntegerFormat = RGBIntegerFormat;
  31124. exports.RGBM16Encoding = RGBM16Encoding;
  31125. exports.RGBM7Encoding = RGBM7Encoding;
  31126. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  31127. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  31128. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  31129. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  31130. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  31131. exports.RGFormat = RGFormat;
  31132. exports.RGIntegerFormat = RGIntegerFormat;
  31133. exports.RawShaderMaterial = RawShaderMaterial;
  31134. exports.Ray = Ray;
  31135. exports.Raycaster = Raycaster;
  31136. exports.RectAreaLight = RectAreaLight;
  31137. exports.RedFormat = RedFormat;
  31138. exports.RedIntegerFormat = RedIntegerFormat;
  31139. exports.ReinhardToneMapping = ReinhardToneMapping;
  31140. exports.RepeatWrapping = RepeatWrapping;
  31141. exports.ReplaceStencilOp = ReplaceStencilOp;
  31142. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  31143. exports.RingBufferGeometry = RingBufferGeometry;
  31144. exports.RingGeometry = RingGeometry;
  31145. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  31146. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  31147. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  31148. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  31149. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  31150. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  31151. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  31152. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  31153. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  31154. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  31155. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  31156. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  31157. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  31158. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  31159. exports.Scene = Scene;
  31160. exports.SceneUtils = SceneUtils;
  31161. exports.ShaderChunk = ShaderChunk;
  31162. exports.ShaderLib = ShaderLib;
  31163. exports.ShaderMaterial = ShaderMaterial;
  31164. exports.ShadowMaterial = ShadowMaterial;
  31165. exports.Shape = Shape;
  31166. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  31167. exports.ShapeGeometry = ShapeGeometry;
  31168. exports.ShapePath = ShapePath;
  31169. exports.ShapeUtils = ShapeUtils;
  31170. exports.ShortType = ShortType;
  31171. exports.Skeleton = Skeleton;
  31172. exports.SkeletonHelper = SkeletonHelper;
  31173. exports.SkinnedMesh = SkinnedMesh;
  31174. exports.SmoothShading = SmoothShading;
  31175. exports.Sphere = Sphere;
  31176. exports.SphereBufferGeometry = SphereBufferGeometry;
  31177. exports.SphereGeometry = SphereGeometry;
  31178. exports.Spherical = Spherical;
  31179. exports.SphericalHarmonics3 = SphericalHarmonics3;
  31180. exports.Spline = Spline;
  31181. exports.SplineCurve = SplineCurve;
  31182. exports.SplineCurve3 = SplineCurve3;
  31183. exports.SpotLight = SpotLight;
  31184. exports.SpotLightHelper = SpotLightHelper;
  31185. exports.SpotLightShadow = SpotLightShadow;
  31186. exports.Sprite = Sprite;
  31187. exports.SpriteMaterial = SpriteMaterial;
  31188. exports.SrcAlphaFactor = SrcAlphaFactor;
  31189. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  31190. exports.SrcColorFactor = SrcColorFactor;
  31191. exports.StaticCopyUsage = StaticCopyUsage;
  31192. exports.StaticDrawUsage = StaticDrawUsage;
  31193. exports.StaticReadUsage = StaticReadUsage;
  31194. exports.StereoCamera = StereoCamera;
  31195. exports.StreamCopyUsage = StreamCopyUsage;
  31196. exports.StreamDrawUsage = StreamDrawUsage;
  31197. exports.StreamReadUsage = StreamReadUsage;
  31198. exports.StringKeyframeTrack = StringKeyframeTrack;
  31199. exports.SubtractEquation = SubtractEquation;
  31200. exports.SubtractiveBlending = SubtractiveBlending;
  31201. exports.TOUCH = TOUCH;
  31202. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31203. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  31204. exports.TetrahedronGeometry = TetrahedronGeometry;
  31205. exports.TextBufferGeometry = TextBufferGeometry;
  31206. exports.TextGeometry = TextGeometry;
  31207. exports.Texture = Texture;
  31208. exports.TextureLoader = TextureLoader;
  31209. exports.TorusBufferGeometry = TorusBufferGeometry;
  31210. exports.TorusGeometry = TorusGeometry;
  31211. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  31212. exports.TorusKnotGeometry = TorusKnotGeometry;
  31213. exports.Triangle = Triangle;
  31214. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31215. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31216. exports.TrianglesDrawMode = TrianglesDrawMode;
  31217. exports.TubeBufferGeometry = TubeBufferGeometry;
  31218. exports.TubeGeometry = TubeGeometry;
  31219. exports.UVMapping = UVMapping;
  31220. exports.Uint16Attribute = Uint16Attribute;
  31221. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31222. exports.Uint32Attribute = Uint32Attribute;
  31223. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31224. exports.Uint8Attribute = Uint8Attribute;
  31225. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31226. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31227. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31228. exports.Uniform = Uniform;
  31229. exports.UniformsLib = UniformsLib;
  31230. exports.UniformsUtils = UniformsUtils;
  31231. exports.UnsignedByteType = UnsignedByteType;
  31232. exports.UnsignedInt248Type = UnsignedInt248Type;
  31233. exports.UnsignedIntType = UnsignedIntType;
  31234. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31235. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31236. exports.UnsignedShort565Type = UnsignedShort565Type;
  31237. exports.UnsignedShortType = UnsignedShortType;
  31238. exports.VSMShadowMap = VSMShadowMap;
  31239. exports.Vector2 = Vector2;
  31240. exports.Vector3 = Vector3;
  31241. exports.Vector4 = Vector4;
  31242. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31243. exports.Vertex = Vertex;
  31244. exports.VertexColors = VertexColors;
  31245. exports.VideoTexture = VideoTexture;
  31246. exports.WebGL1Renderer = WebGL1Renderer;
  31247. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31248. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31249. exports.WebGLRenderTarget = WebGLRenderTarget;
  31250. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31251. exports.WebGLRenderer = WebGLRenderer;
  31252. exports.WebGLUtils = WebGLUtils;
  31253. exports.WireframeGeometry = WireframeGeometry;
  31254. exports.WireframeHelper = WireframeHelper;
  31255. exports.WrapAroundEnding = WrapAroundEnding;
  31256. exports.XHRLoader = XHRLoader;
  31257. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31258. exports.ZeroFactor = ZeroFactor;
  31259. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31260. exports.ZeroStencilOp = ZeroStencilOp;
  31261. exports.sRGBEncoding = sRGBEncoding;
  31262. Object.defineProperty(exports, '__esModule', { value: true });
  31263. })));