three.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494
  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. ( function () {
  37. Object.assign = function ( target ) {
  38. if ( target === undefined || target === null ) {
  39. throw new TypeError( 'Cannot convert undefined or null to object' );
  40. }
  41. var output = Object( target );
  42. for ( var index = 1; index < arguments.length; index ++ ) {
  43. var source = arguments[ index ];
  44. if ( source !== undefined && source !== null ) {
  45. for ( var nextKey in source ) {
  46. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  47. output[ nextKey ] = source[ nextKey ];
  48. }
  49. }
  50. }
  51. }
  52. return output;
  53. };
  54. } )();
  55. }
  56. /**
  57. * https://github.com/mrdoob/eventdispatcher.js/
  58. */
  59. function EventDispatcher() {}
  60. Object.assign( EventDispatcher.prototype, {
  61. addEventListener: function ( type, listener ) {
  62. if ( this._listeners === undefined ) this._listeners = {};
  63. var listeners = this._listeners;
  64. if ( listeners[ type ] === undefined ) {
  65. listeners[ type ] = [];
  66. }
  67. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  68. listeners[ type ].push( listener );
  69. }
  70. },
  71. hasEventListener: function ( type, listener ) {
  72. if ( this._listeners === undefined ) return false;
  73. var listeners = this._listeners;
  74. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  75. },
  76. removeEventListener: function ( type, listener ) {
  77. if ( this._listeners === undefined ) return;
  78. var listeners = this._listeners;
  79. var listenerArray = listeners[ type ];
  80. if ( listenerArray !== undefined ) {
  81. var index = listenerArray.indexOf( listener );
  82. if ( index !== - 1 ) {
  83. listenerArray.splice( index, 1 );
  84. }
  85. }
  86. },
  87. dispatchEvent: function ( event ) {
  88. if ( this._listeners === undefined ) return;
  89. var listeners = this._listeners;
  90. var listenerArray = listeners[ event.type ];
  91. if ( listenerArray !== undefined ) {
  92. event.target = this;
  93. var array = listenerArray.slice( 0 );
  94. for ( var i = 0, l = array.length; i < l; i ++ ) {
  95. array[ i ].call( this, event );
  96. }
  97. }
  98. }
  99. } );
  100. var REVISION = '104dev';
  101. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  102. var CullFaceNone = 0;
  103. var CullFaceBack = 1;
  104. var CullFaceFront = 2;
  105. var CullFaceFrontBack = 3;
  106. var FrontFaceDirectionCW = 0;
  107. var FrontFaceDirectionCCW = 1;
  108. var BasicShadowMap = 0;
  109. var PCFShadowMap = 1;
  110. var PCFSoftShadowMap = 2;
  111. var FrontSide = 0;
  112. var BackSide = 1;
  113. var DoubleSide = 2;
  114. var FlatShading = 1;
  115. var SmoothShading = 2;
  116. var NoColors = 0;
  117. var FaceColors = 1;
  118. var VertexColors = 2;
  119. var NoBlending = 0;
  120. var NormalBlending = 1;
  121. var AdditiveBlending = 2;
  122. var SubtractiveBlending = 3;
  123. var MultiplyBlending = 4;
  124. var CustomBlending = 5;
  125. var AddEquation = 100;
  126. var SubtractEquation = 101;
  127. var ReverseSubtractEquation = 102;
  128. var MinEquation = 103;
  129. var MaxEquation = 104;
  130. var ZeroFactor = 200;
  131. var OneFactor = 201;
  132. var SrcColorFactor = 202;
  133. var OneMinusSrcColorFactor = 203;
  134. var SrcAlphaFactor = 204;
  135. var OneMinusSrcAlphaFactor = 205;
  136. var DstAlphaFactor = 206;
  137. var OneMinusDstAlphaFactor = 207;
  138. var DstColorFactor = 208;
  139. var OneMinusDstColorFactor = 209;
  140. var SrcAlphaSaturateFactor = 210;
  141. var NeverDepth = 0;
  142. var AlwaysDepth = 1;
  143. var LessDepth = 2;
  144. var LessEqualDepth = 3;
  145. var EqualDepth = 4;
  146. var GreaterEqualDepth = 5;
  147. var GreaterDepth = 6;
  148. var NotEqualDepth = 7;
  149. var MultiplyOperation = 0;
  150. var MixOperation = 1;
  151. var AddOperation = 2;
  152. var NoToneMapping = 0;
  153. var LinearToneMapping = 1;
  154. var ReinhardToneMapping = 2;
  155. var Uncharted2ToneMapping = 3;
  156. var CineonToneMapping = 4;
  157. var ACESFilmicToneMapping = 5;
  158. var UVMapping = 300;
  159. var CubeReflectionMapping = 301;
  160. var CubeRefractionMapping = 302;
  161. var EquirectangularReflectionMapping = 303;
  162. var EquirectangularRefractionMapping = 304;
  163. var SphericalReflectionMapping = 305;
  164. var CubeUVReflectionMapping = 306;
  165. var CubeUVRefractionMapping = 307;
  166. var RepeatWrapping = 1000;
  167. var ClampToEdgeWrapping = 1001;
  168. var MirroredRepeatWrapping = 1002;
  169. var NearestFilter = 1003;
  170. var NearestMipMapNearestFilter = 1004;
  171. var NearestMipMapLinearFilter = 1005;
  172. var LinearFilter = 1006;
  173. var LinearMipMapNearestFilter = 1007;
  174. var LinearMipMapLinearFilter = 1008;
  175. var UnsignedByteType = 1009;
  176. var ByteType = 1010;
  177. var ShortType = 1011;
  178. var UnsignedShortType = 1012;
  179. var IntType = 1013;
  180. var UnsignedIntType = 1014;
  181. var FloatType = 1015;
  182. var HalfFloatType = 1016;
  183. var UnsignedShort4444Type = 1017;
  184. var UnsignedShort5551Type = 1018;
  185. var UnsignedShort565Type = 1019;
  186. var UnsignedInt248Type = 1020;
  187. var AlphaFormat = 1021;
  188. var RGBFormat = 1022;
  189. var RGBAFormat = 1023;
  190. var LuminanceFormat = 1024;
  191. var LuminanceAlphaFormat = 1025;
  192. var RGBEFormat = RGBAFormat;
  193. var DepthFormat = 1026;
  194. var DepthStencilFormat = 1027;
  195. var RedFormat = 1028;
  196. var RGB_S3TC_DXT1_Format = 33776;
  197. var RGBA_S3TC_DXT1_Format = 33777;
  198. var RGBA_S3TC_DXT3_Format = 33778;
  199. var RGBA_S3TC_DXT5_Format = 33779;
  200. var RGB_PVRTC_4BPPV1_Format = 35840;
  201. var RGB_PVRTC_2BPPV1_Format = 35841;
  202. var RGBA_PVRTC_4BPPV1_Format = 35842;
  203. var RGBA_PVRTC_2BPPV1_Format = 35843;
  204. var RGB_ETC1_Format = 36196;
  205. var RGBA_ASTC_4x4_Format = 37808;
  206. var RGBA_ASTC_5x4_Format = 37809;
  207. var RGBA_ASTC_5x5_Format = 37810;
  208. var RGBA_ASTC_6x5_Format = 37811;
  209. var RGBA_ASTC_6x6_Format = 37812;
  210. var RGBA_ASTC_8x5_Format = 37813;
  211. var RGBA_ASTC_8x6_Format = 37814;
  212. var RGBA_ASTC_8x8_Format = 37815;
  213. var RGBA_ASTC_10x5_Format = 37816;
  214. var RGBA_ASTC_10x6_Format = 37817;
  215. var RGBA_ASTC_10x8_Format = 37818;
  216. var RGBA_ASTC_10x10_Format = 37819;
  217. var RGBA_ASTC_12x10_Format = 37820;
  218. var RGBA_ASTC_12x12_Format = 37821;
  219. var LoopOnce = 2200;
  220. var LoopRepeat = 2201;
  221. var LoopPingPong = 2202;
  222. var InterpolateDiscrete = 2300;
  223. var InterpolateLinear = 2301;
  224. var InterpolateSmooth = 2302;
  225. var ZeroCurvatureEnding = 2400;
  226. var ZeroSlopeEnding = 2401;
  227. var WrapAroundEnding = 2402;
  228. var TrianglesDrawMode = 0;
  229. var TriangleStripDrawMode = 1;
  230. var TriangleFanDrawMode = 2;
  231. var LinearEncoding = 3000;
  232. var sRGBEncoding = 3001;
  233. var GammaEncoding = 3007;
  234. var RGBEEncoding = 3002;
  235. var LogLuvEncoding = 3003;
  236. var RGBM7Encoding = 3004;
  237. var RGBM16Encoding = 3005;
  238. var RGBDEncoding = 3006;
  239. var BasicDepthPacking = 3200;
  240. var RGBADepthPacking = 3201;
  241. var TangentSpaceNormalMap = 0;
  242. var ObjectSpaceNormalMap = 1;
  243. /**
  244. * @author alteredq / http://alteredqualia.com/
  245. * @author mrdoob / http://mrdoob.com/
  246. */
  247. var _Math = {
  248. DEG2RAD: Math.PI / 180,
  249. RAD2DEG: 180 / Math.PI,
  250. generateUUID: ( function () {
  251. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  252. var lut = [];
  253. for ( var i = 0; i < 256; i ++ ) {
  254. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  255. }
  256. return function generateUUID() {
  257. var d0 = Math.random() * 0xffffffff | 0;
  258. var d1 = Math.random() * 0xffffffff | 0;
  259. var d2 = Math.random() * 0xffffffff | 0;
  260. var d3 = Math.random() * 0xffffffff | 0;
  261. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  262. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  263. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  264. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  265. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  266. return uuid.toUpperCase();
  267. };
  268. } )(),
  269. clamp: function ( value, min, max ) {
  270. return Math.max( min, Math.min( max, value ) );
  271. },
  272. // compute euclidian modulo of m % n
  273. // https://en.wikipedia.org/wiki/Modulo_operation
  274. euclideanModulo: function ( n, m ) {
  275. return ( ( n % m ) + m ) % m;
  276. },
  277. // Linear mapping from range <a1, a2> to range <b1, b2>
  278. mapLinear: function ( x, a1, a2, b1, b2 ) {
  279. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  280. },
  281. // https://en.wikipedia.org/wiki/Linear_interpolation
  282. lerp: function ( x, y, t ) {
  283. return ( 1 - t ) * x + t * y;
  284. },
  285. // http://en.wikipedia.org/wiki/Smoothstep
  286. smoothstep: function ( x, min, max ) {
  287. if ( x <= min ) return 0;
  288. if ( x >= max ) return 1;
  289. x = ( x - min ) / ( max - min );
  290. return x * x * ( 3 - 2 * x );
  291. },
  292. smootherstep: function ( x, min, max ) {
  293. if ( x <= min ) return 0;
  294. if ( x >= max ) return 1;
  295. x = ( x - min ) / ( max - min );
  296. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  297. },
  298. // Random integer from <low, high> interval
  299. randInt: function ( low, high ) {
  300. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  301. },
  302. // Random float from <low, high> interval
  303. randFloat: function ( low, high ) {
  304. return low + Math.random() * ( high - low );
  305. },
  306. // Random float from <-range/2, range/2> interval
  307. randFloatSpread: function ( range ) {
  308. return range * ( 0.5 - Math.random() );
  309. },
  310. degToRad: function ( degrees ) {
  311. return degrees * _Math.DEG2RAD;
  312. },
  313. radToDeg: function ( radians ) {
  314. return radians * _Math.RAD2DEG;
  315. },
  316. isPowerOfTwo: function ( value ) {
  317. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  318. },
  319. ceilPowerOfTwo: function ( value ) {
  320. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  321. },
  322. floorPowerOfTwo: function ( value ) {
  323. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  324. }
  325. };
  326. /**
  327. * @author mrdoob / http://mrdoob.com/
  328. * @author philogb / http://blog.thejit.org/
  329. * @author egraether / http://egraether.com/
  330. * @author zz85 / http://www.lab4games.net/zz85/blog
  331. */
  332. function Vector2( x, y ) {
  333. this.x = x || 0;
  334. this.y = y || 0;
  335. }
  336. Object.defineProperties( Vector2.prototype, {
  337. "width": {
  338. get: function () {
  339. return this.x;
  340. },
  341. set: function ( value ) {
  342. this.x = value;
  343. }
  344. },
  345. "height": {
  346. get: function () {
  347. return this.y;
  348. },
  349. set: function ( value ) {
  350. this.y = value;
  351. }
  352. }
  353. } );
  354. Object.assign( Vector2.prototype, {
  355. isVector2: true,
  356. set: function ( x, y ) {
  357. this.x = x;
  358. this.y = y;
  359. return this;
  360. },
  361. setScalar: function ( scalar ) {
  362. this.x = scalar;
  363. this.y = scalar;
  364. return this;
  365. },
  366. setX: function ( x ) {
  367. this.x = x;
  368. return this;
  369. },
  370. setY: function ( y ) {
  371. this.y = y;
  372. return this;
  373. },
  374. setComponent: function ( index, value ) {
  375. switch ( index ) {
  376. case 0: this.x = value; break;
  377. case 1: this.y = value; break;
  378. default: throw new Error( 'index is out of range: ' + index );
  379. }
  380. return this;
  381. },
  382. getComponent: function ( index ) {
  383. switch ( index ) {
  384. case 0: return this.x;
  385. case 1: return this.y;
  386. default: throw new Error( 'index is out of range: ' + index );
  387. }
  388. },
  389. clone: function () {
  390. return new this.constructor( this.x, this.y );
  391. },
  392. copy: function ( v ) {
  393. this.x = v.x;
  394. this.y = v.y;
  395. return this;
  396. },
  397. add: function ( v, w ) {
  398. if ( w !== undefined ) {
  399. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  400. return this.addVectors( v, w );
  401. }
  402. this.x += v.x;
  403. this.y += v.y;
  404. return this;
  405. },
  406. addScalar: function ( s ) {
  407. this.x += s;
  408. this.y += s;
  409. return this;
  410. },
  411. addVectors: function ( a, b ) {
  412. this.x = a.x + b.x;
  413. this.y = a.y + b.y;
  414. return this;
  415. },
  416. addScaledVector: function ( v, s ) {
  417. this.x += v.x * s;
  418. this.y += v.y * s;
  419. return this;
  420. },
  421. sub: function ( v, w ) {
  422. if ( w !== undefined ) {
  423. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  424. return this.subVectors( v, w );
  425. }
  426. this.x -= v.x;
  427. this.y -= v.y;
  428. return this;
  429. },
  430. subScalar: function ( s ) {
  431. this.x -= s;
  432. this.y -= s;
  433. return this;
  434. },
  435. subVectors: function ( a, b ) {
  436. this.x = a.x - b.x;
  437. this.y = a.y - b.y;
  438. return this;
  439. },
  440. multiply: function ( v ) {
  441. this.x *= v.x;
  442. this.y *= v.y;
  443. return this;
  444. },
  445. multiplyScalar: function ( scalar ) {
  446. this.x *= scalar;
  447. this.y *= scalar;
  448. return this;
  449. },
  450. divide: function ( v ) {
  451. this.x /= v.x;
  452. this.y /= v.y;
  453. return this;
  454. },
  455. divideScalar: function ( scalar ) {
  456. return this.multiplyScalar( 1 / scalar );
  457. },
  458. applyMatrix3: function ( m ) {
  459. var x = this.x, y = this.y;
  460. var e = m.elements;
  461. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  462. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  463. return this;
  464. },
  465. min: function ( v ) {
  466. this.x = Math.min( this.x, v.x );
  467. this.y = Math.min( this.y, v.y );
  468. return this;
  469. },
  470. max: function ( v ) {
  471. this.x = Math.max( this.x, v.x );
  472. this.y = Math.max( this.y, v.y );
  473. return this;
  474. },
  475. clamp: function ( min, max ) {
  476. // assumes min < max, componentwise
  477. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  478. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  479. return this;
  480. },
  481. clampScalar: function () {
  482. var min = new Vector2();
  483. var max = new Vector2();
  484. return function clampScalar( minVal, maxVal ) {
  485. min.set( minVal, minVal );
  486. max.set( maxVal, maxVal );
  487. return this.clamp( min, max );
  488. };
  489. }(),
  490. clampLength: function ( min, max ) {
  491. var length = this.length();
  492. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  493. },
  494. floor: function () {
  495. this.x = Math.floor( this.x );
  496. this.y = Math.floor( this.y );
  497. return this;
  498. },
  499. ceil: function () {
  500. this.x = Math.ceil( this.x );
  501. this.y = Math.ceil( this.y );
  502. return this;
  503. },
  504. round: function () {
  505. this.x = Math.round( this.x );
  506. this.y = Math.round( this.y );
  507. return this;
  508. },
  509. roundToZero: function () {
  510. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  511. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  512. return this;
  513. },
  514. negate: function () {
  515. this.x = - this.x;
  516. this.y = - this.y;
  517. return this;
  518. },
  519. dot: function ( v ) {
  520. return this.x * v.x + this.y * v.y;
  521. },
  522. cross: function ( v ) {
  523. return this.x * v.y - this.y * v.x;
  524. },
  525. lengthSq: function () {
  526. return this.x * this.x + this.y * this.y;
  527. },
  528. length: function () {
  529. return Math.sqrt( this.x * this.x + this.y * this.y );
  530. },
  531. manhattanLength: function () {
  532. return Math.abs( this.x ) + Math.abs( this.y );
  533. },
  534. normalize: function () {
  535. return this.divideScalar( this.length() || 1 );
  536. },
  537. angle: function () {
  538. // computes the angle in radians with respect to the positive x-axis
  539. var angle = Math.atan2( this.y, this.x );
  540. if ( angle < 0 ) angle += 2 * Math.PI;
  541. return angle;
  542. },
  543. distanceTo: function ( v ) {
  544. return Math.sqrt( this.distanceToSquared( v ) );
  545. },
  546. distanceToSquared: function ( v ) {
  547. var dx = this.x - v.x, dy = this.y - v.y;
  548. return dx * dx + dy * dy;
  549. },
  550. manhattanDistanceTo: function ( v ) {
  551. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  552. },
  553. setLength: function ( length ) {
  554. return this.normalize().multiplyScalar( length );
  555. },
  556. lerp: function ( v, alpha ) {
  557. this.x += ( v.x - this.x ) * alpha;
  558. this.y += ( v.y - this.y ) * alpha;
  559. return this;
  560. },
  561. lerpVectors: function ( v1, v2, alpha ) {
  562. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  563. },
  564. equals: function ( v ) {
  565. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  566. },
  567. fromArray: function ( array, offset ) {
  568. if ( offset === undefined ) offset = 0;
  569. this.x = array[ offset ];
  570. this.y = array[ offset + 1 ];
  571. return this;
  572. },
  573. toArray: function ( array, offset ) {
  574. if ( array === undefined ) array = [];
  575. if ( offset === undefined ) offset = 0;
  576. array[ offset ] = this.x;
  577. array[ offset + 1 ] = this.y;
  578. return array;
  579. },
  580. fromBufferAttribute: function ( attribute, index, offset ) {
  581. if ( offset !== undefined ) {
  582. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  583. }
  584. this.x = attribute.getX( index );
  585. this.y = attribute.getY( index );
  586. return this;
  587. },
  588. rotateAround: function ( center, angle ) {
  589. var c = Math.cos( angle ), s = Math.sin( angle );
  590. var x = this.x - center.x;
  591. var y = this.y - center.y;
  592. this.x = x * c - y * s + center.x;
  593. this.y = x * s + y * c + center.y;
  594. return this;
  595. }
  596. } );
  597. /**
  598. * @author mikael emtinger / http://gomo.se/
  599. * @author alteredq / http://alteredqualia.com/
  600. * @author WestLangley / http://github.com/WestLangley
  601. * @author bhouston / http://clara.io
  602. */
  603. function Quaternion( x, y, z, w ) {
  604. this._x = x || 0;
  605. this._y = y || 0;
  606. this._z = z || 0;
  607. this._w = ( w !== undefined ) ? w : 1;
  608. }
  609. Object.assign( Quaternion, {
  610. slerp: function ( qa, qb, qm, t ) {
  611. return qm.copy( qa ).slerp( qb, t );
  612. },
  613. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  614. // fuzz-free, array-based Quaternion SLERP operation
  615. var x0 = src0[ srcOffset0 + 0 ],
  616. y0 = src0[ srcOffset0 + 1 ],
  617. z0 = src0[ srcOffset0 + 2 ],
  618. w0 = src0[ srcOffset0 + 3 ],
  619. x1 = src1[ srcOffset1 + 0 ],
  620. y1 = src1[ srcOffset1 + 1 ],
  621. z1 = src1[ srcOffset1 + 2 ],
  622. w1 = src1[ srcOffset1 + 3 ];
  623. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  624. var s = 1 - t,
  625. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  626. dir = ( cos >= 0 ? 1 : - 1 ),
  627. sqrSin = 1 - cos * cos;
  628. // Skip the Slerp for tiny steps to avoid numeric problems:
  629. if ( sqrSin > Number.EPSILON ) {
  630. var sin = Math.sqrt( sqrSin ),
  631. len = Math.atan2( sin, cos * dir );
  632. s = Math.sin( s * len ) / sin;
  633. t = Math.sin( t * len ) / sin;
  634. }
  635. var tDir = t * dir;
  636. x0 = x0 * s + x1 * tDir;
  637. y0 = y0 * s + y1 * tDir;
  638. z0 = z0 * s + z1 * tDir;
  639. w0 = w0 * s + w1 * tDir;
  640. // Normalize in case we just did a lerp:
  641. if ( s === 1 - t ) {
  642. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  643. x0 *= f;
  644. y0 *= f;
  645. z0 *= f;
  646. w0 *= f;
  647. }
  648. }
  649. dst[ dstOffset ] = x0;
  650. dst[ dstOffset + 1 ] = y0;
  651. dst[ dstOffset + 2 ] = z0;
  652. dst[ dstOffset + 3 ] = w0;
  653. }
  654. } );
  655. Object.defineProperties( Quaternion.prototype, {
  656. x: {
  657. get: function () {
  658. return this._x;
  659. },
  660. set: function ( value ) {
  661. this._x = value;
  662. this.onChangeCallback();
  663. }
  664. },
  665. y: {
  666. get: function () {
  667. return this._y;
  668. },
  669. set: function ( value ) {
  670. this._y = value;
  671. this.onChangeCallback();
  672. }
  673. },
  674. z: {
  675. get: function () {
  676. return this._z;
  677. },
  678. set: function ( value ) {
  679. this._z = value;
  680. this.onChangeCallback();
  681. }
  682. },
  683. w: {
  684. get: function () {
  685. return this._w;
  686. },
  687. set: function ( value ) {
  688. this._w = value;
  689. this.onChangeCallback();
  690. }
  691. }
  692. } );
  693. Object.assign( Quaternion.prototype, {
  694. isQuaternion: true,
  695. set: function ( x, y, z, w ) {
  696. this._x = x;
  697. this._y = y;
  698. this._z = z;
  699. this._w = w;
  700. this.onChangeCallback();
  701. return this;
  702. },
  703. clone: function () {
  704. return new this.constructor( this._x, this._y, this._z, this._w );
  705. },
  706. copy: function ( quaternion ) {
  707. this._x = quaternion.x;
  708. this._y = quaternion.y;
  709. this._z = quaternion.z;
  710. this._w = quaternion.w;
  711. this.onChangeCallback();
  712. return this;
  713. },
  714. setFromEuler: function ( euler, update ) {
  715. if ( ! ( euler && euler.isEuler ) ) {
  716. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  717. }
  718. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  719. // http://www.mathworks.com/matlabcentral/fileexchange/
  720. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  721. // content/SpinCalc.m
  722. var cos = Math.cos;
  723. var sin = Math.sin;
  724. var c1 = cos( x / 2 );
  725. var c2 = cos( y / 2 );
  726. var c3 = cos( z / 2 );
  727. var s1 = sin( x / 2 );
  728. var s2 = sin( y / 2 );
  729. var s3 = sin( z / 2 );
  730. if ( order === 'XYZ' ) {
  731. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  732. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  733. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  734. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  735. } else if ( order === 'YXZ' ) {
  736. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  737. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  738. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  739. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  740. } else if ( order === 'ZXY' ) {
  741. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  742. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  743. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  744. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  745. } else if ( order === 'ZYX' ) {
  746. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  747. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  748. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  749. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  750. } else if ( order === 'YZX' ) {
  751. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  752. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  753. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  754. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  755. } else if ( order === 'XZY' ) {
  756. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  757. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  758. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  759. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  760. }
  761. if ( update !== false ) this.onChangeCallback();
  762. return this;
  763. },
  764. setFromAxisAngle: function ( axis, angle ) {
  765. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  766. // assumes axis is normalized
  767. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  768. this._x = axis.x * s;
  769. this._y = axis.y * s;
  770. this._z = axis.z * s;
  771. this._w = Math.cos( halfAngle );
  772. this.onChangeCallback();
  773. return this;
  774. },
  775. setFromRotationMatrix: function ( m ) {
  776. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  777. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  778. var te = m.elements,
  779. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  780. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  781. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  782. trace = m11 + m22 + m33,
  783. s;
  784. if ( trace > 0 ) {
  785. s = 0.5 / Math.sqrt( trace + 1.0 );
  786. this._w = 0.25 / s;
  787. this._x = ( m32 - m23 ) * s;
  788. this._y = ( m13 - m31 ) * s;
  789. this._z = ( m21 - m12 ) * s;
  790. } else if ( m11 > m22 && m11 > m33 ) {
  791. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  792. this._w = ( m32 - m23 ) / s;
  793. this._x = 0.25 * s;
  794. this._y = ( m12 + m21 ) / s;
  795. this._z = ( m13 + m31 ) / s;
  796. } else if ( m22 > m33 ) {
  797. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  798. this._w = ( m13 - m31 ) / s;
  799. this._x = ( m12 + m21 ) / s;
  800. this._y = 0.25 * s;
  801. this._z = ( m23 + m32 ) / s;
  802. } else {
  803. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  804. this._w = ( m21 - m12 ) / s;
  805. this._x = ( m13 + m31 ) / s;
  806. this._y = ( m23 + m32 ) / s;
  807. this._z = 0.25 * s;
  808. }
  809. this.onChangeCallback();
  810. return this;
  811. },
  812. setFromUnitVectors: function ( vFrom, vTo ) {
  813. // assumes direction vectors vFrom and vTo are normalized
  814. var EPS = 0.000001;
  815. var r = vFrom.dot( vTo ) + 1;
  816. if ( r < EPS ) {
  817. r = 0;
  818. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  819. this._x = - vFrom.y;
  820. this._y = vFrom.x;
  821. this._z = 0;
  822. this._w = r;
  823. } else {
  824. this._x = 0;
  825. this._y = - vFrom.z;
  826. this._z = vFrom.y;
  827. this._w = r;
  828. }
  829. } else {
  830. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  831. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  832. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  833. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  834. this._w = r;
  835. }
  836. return this.normalize();
  837. },
  838. angleTo: function ( q ) {
  839. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  840. },
  841. rotateTowards: function ( q, step ) {
  842. var angle = this.angleTo( q );
  843. if ( angle === 0 ) return this;
  844. var t = Math.min( 1, step / angle );
  845. this.slerp( q, t );
  846. return this;
  847. },
  848. inverse: function () {
  849. // quaternion is assumed to have unit length
  850. return this.conjugate();
  851. },
  852. conjugate: function () {
  853. this._x *= - 1;
  854. this._y *= - 1;
  855. this._z *= - 1;
  856. this.onChangeCallback();
  857. return this;
  858. },
  859. dot: function ( v ) {
  860. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  861. },
  862. lengthSq: function () {
  863. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  864. },
  865. length: function () {
  866. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  867. },
  868. normalize: function () {
  869. var l = this.length();
  870. if ( l === 0 ) {
  871. this._x = 0;
  872. this._y = 0;
  873. this._z = 0;
  874. this._w = 1;
  875. } else {
  876. l = 1 / l;
  877. this._x = this._x * l;
  878. this._y = this._y * l;
  879. this._z = this._z * l;
  880. this._w = this._w * l;
  881. }
  882. this.onChangeCallback();
  883. return this;
  884. },
  885. multiply: function ( q, p ) {
  886. if ( p !== undefined ) {
  887. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  888. return this.multiplyQuaternions( q, p );
  889. }
  890. return this.multiplyQuaternions( this, q );
  891. },
  892. premultiply: function ( q ) {
  893. return this.multiplyQuaternions( q, this );
  894. },
  895. multiplyQuaternions: function ( a, b ) {
  896. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  897. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  898. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  899. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  900. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  901. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  902. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  903. this.onChangeCallback();
  904. return this;
  905. },
  906. slerp: function ( qb, t ) {
  907. if ( t === 0 ) return this;
  908. if ( t === 1 ) return this.copy( qb );
  909. var x = this._x, y = this._y, z = this._z, w = this._w;
  910. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  911. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  912. if ( cosHalfTheta < 0 ) {
  913. this._w = - qb._w;
  914. this._x = - qb._x;
  915. this._y = - qb._y;
  916. this._z = - qb._z;
  917. cosHalfTheta = - cosHalfTheta;
  918. } else {
  919. this.copy( qb );
  920. }
  921. if ( cosHalfTheta >= 1.0 ) {
  922. this._w = w;
  923. this._x = x;
  924. this._y = y;
  925. this._z = z;
  926. return this;
  927. }
  928. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  929. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  930. var s = 1 - t;
  931. this._w = s * w + t * this._w;
  932. this._x = s * x + t * this._x;
  933. this._y = s * y + t * this._y;
  934. this._z = s * z + t * this._z;
  935. return this.normalize();
  936. }
  937. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  938. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  939. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  940. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  941. this._w = ( w * ratioA + this._w * ratioB );
  942. this._x = ( x * ratioA + this._x * ratioB );
  943. this._y = ( y * ratioA + this._y * ratioB );
  944. this._z = ( z * ratioA + this._z * ratioB );
  945. this.onChangeCallback();
  946. return this;
  947. },
  948. equals: function ( quaternion ) {
  949. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  950. },
  951. fromArray: function ( array, offset ) {
  952. if ( offset === undefined ) offset = 0;
  953. this._x = array[ offset ];
  954. this._y = array[ offset + 1 ];
  955. this._z = array[ offset + 2 ];
  956. this._w = array[ offset + 3 ];
  957. this.onChangeCallback();
  958. return this;
  959. },
  960. toArray: function ( array, offset ) {
  961. if ( array === undefined ) array = [];
  962. if ( offset === undefined ) offset = 0;
  963. array[ offset ] = this._x;
  964. array[ offset + 1 ] = this._y;
  965. array[ offset + 2 ] = this._z;
  966. array[ offset + 3 ] = this._w;
  967. return array;
  968. },
  969. onChange: function ( callback ) {
  970. this.onChangeCallback = callback;
  971. return this;
  972. },
  973. onChangeCallback: function () {}
  974. } );
  975. /**
  976. * @author mrdoob / http://mrdoob.com/
  977. * @author kile / http://kile.stravaganza.org/
  978. * @author philogb / http://blog.thejit.org/
  979. * @author mikael emtinger / http://gomo.se/
  980. * @author egraether / http://egraether.com/
  981. * @author WestLangley / http://github.com/WestLangley
  982. */
  983. function Vector3( x, y, z ) {
  984. this.x = x || 0;
  985. this.y = y || 0;
  986. this.z = z || 0;
  987. }
  988. Object.assign( Vector3.prototype, {
  989. isVector3: true,
  990. set: function ( x, y, z ) {
  991. this.x = x;
  992. this.y = y;
  993. this.z = z;
  994. return this;
  995. },
  996. setScalar: function ( scalar ) {
  997. this.x = scalar;
  998. this.y = scalar;
  999. this.z = scalar;
  1000. return this;
  1001. },
  1002. setX: function ( x ) {
  1003. this.x = x;
  1004. return this;
  1005. },
  1006. setY: function ( y ) {
  1007. this.y = y;
  1008. return this;
  1009. },
  1010. setZ: function ( z ) {
  1011. this.z = z;
  1012. return this;
  1013. },
  1014. setComponent: function ( index, value ) {
  1015. switch ( index ) {
  1016. case 0: this.x = value; break;
  1017. case 1: this.y = value; break;
  1018. case 2: this.z = value; break;
  1019. default: throw new Error( 'index is out of range: ' + index );
  1020. }
  1021. return this;
  1022. },
  1023. getComponent: function ( index ) {
  1024. switch ( index ) {
  1025. case 0: return this.x;
  1026. case 1: return this.y;
  1027. case 2: return this.z;
  1028. default: throw new Error( 'index is out of range: ' + index );
  1029. }
  1030. },
  1031. clone: function () {
  1032. return new this.constructor( this.x, this.y, this.z );
  1033. },
  1034. copy: function ( v ) {
  1035. this.x = v.x;
  1036. this.y = v.y;
  1037. this.z = v.z;
  1038. return this;
  1039. },
  1040. add: function ( v, w ) {
  1041. if ( w !== undefined ) {
  1042. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1043. return this.addVectors( v, w );
  1044. }
  1045. this.x += v.x;
  1046. this.y += v.y;
  1047. this.z += v.z;
  1048. return this;
  1049. },
  1050. addScalar: function ( s ) {
  1051. this.x += s;
  1052. this.y += s;
  1053. this.z += s;
  1054. return this;
  1055. },
  1056. addVectors: function ( a, b ) {
  1057. this.x = a.x + b.x;
  1058. this.y = a.y + b.y;
  1059. this.z = a.z + b.z;
  1060. return this;
  1061. },
  1062. addScaledVector: function ( v, s ) {
  1063. this.x += v.x * s;
  1064. this.y += v.y * s;
  1065. this.z += v.z * s;
  1066. return this;
  1067. },
  1068. sub: function ( v, w ) {
  1069. if ( w !== undefined ) {
  1070. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1071. return this.subVectors( v, w );
  1072. }
  1073. this.x -= v.x;
  1074. this.y -= v.y;
  1075. this.z -= v.z;
  1076. return this;
  1077. },
  1078. subScalar: function ( s ) {
  1079. this.x -= s;
  1080. this.y -= s;
  1081. this.z -= s;
  1082. return this;
  1083. },
  1084. subVectors: function ( a, b ) {
  1085. this.x = a.x - b.x;
  1086. this.y = a.y - b.y;
  1087. this.z = a.z - b.z;
  1088. return this;
  1089. },
  1090. multiply: function ( v, w ) {
  1091. if ( w !== undefined ) {
  1092. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1093. return this.multiplyVectors( v, w );
  1094. }
  1095. this.x *= v.x;
  1096. this.y *= v.y;
  1097. this.z *= v.z;
  1098. return this;
  1099. },
  1100. multiplyScalar: function ( scalar ) {
  1101. this.x *= scalar;
  1102. this.y *= scalar;
  1103. this.z *= scalar;
  1104. return this;
  1105. },
  1106. multiplyVectors: function ( a, b ) {
  1107. this.x = a.x * b.x;
  1108. this.y = a.y * b.y;
  1109. this.z = a.z * b.z;
  1110. return this;
  1111. },
  1112. applyEuler: function () {
  1113. var quaternion = new Quaternion();
  1114. return function applyEuler( euler ) {
  1115. if ( ! ( euler && euler.isEuler ) ) {
  1116. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1117. }
  1118. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1119. };
  1120. }(),
  1121. applyAxisAngle: function () {
  1122. var quaternion = new Quaternion();
  1123. return function applyAxisAngle( axis, angle ) {
  1124. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1125. };
  1126. }(),
  1127. applyMatrix3: function ( m ) {
  1128. var x = this.x, y = this.y, z = this.z;
  1129. var e = m.elements;
  1130. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1131. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1132. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1133. return this;
  1134. },
  1135. applyMatrix4: function ( m ) {
  1136. var x = this.x, y = this.y, z = this.z;
  1137. var e = m.elements;
  1138. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1139. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1140. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1141. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1142. return this;
  1143. },
  1144. applyQuaternion: function ( q ) {
  1145. var x = this.x, y = this.y, z = this.z;
  1146. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1147. // calculate quat * vector
  1148. var ix = qw * x + qy * z - qz * y;
  1149. var iy = qw * y + qz * x - qx * z;
  1150. var iz = qw * z + qx * y - qy * x;
  1151. var iw = - qx * x - qy * y - qz * z;
  1152. // calculate result * inverse quat
  1153. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1154. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1155. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1156. return this;
  1157. },
  1158. project: function ( camera ) {
  1159. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1160. },
  1161. unproject: function ( camera ) {
  1162. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1163. },
  1164. transformDirection: function ( m ) {
  1165. // input: THREE.Matrix4 affine matrix
  1166. // vector interpreted as a direction
  1167. var x = this.x, y = this.y, z = this.z;
  1168. var e = m.elements;
  1169. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1170. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1171. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1172. return this.normalize();
  1173. },
  1174. divide: function ( v ) {
  1175. this.x /= v.x;
  1176. this.y /= v.y;
  1177. this.z /= v.z;
  1178. return this;
  1179. },
  1180. divideScalar: function ( scalar ) {
  1181. return this.multiplyScalar( 1 / scalar );
  1182. },
  1183. min: function ( v ) {
  1184. this.x = Math.min( this.x, v.x );
  1185. this.y = Math.min( this.y, v.y );
  1186. this.z = Math.min( this.z, v.z );
  1187. return this;
  1188. },
  1189. max: function ( v ) {
  1190. this.x = Math.max( this.x, v.x );
  1191. this.y = Math.max( this.y, v.y );
  1192. this.z = Math.max( this.z, v.z );
  1193. return this;
  1194. },
  1195. clamp: function ( min, max ) {
  1196. // assumes min < max, componentwise
  1197. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1198. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1199. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1200. return this;
  1201. },
  1202. clampScalar: function () {
  1203. var min = new Vector3();
  1204. var max = new Vector3();
  1205. return function clampScalar( minVal, maxVal ) {
  1206. min.set( minVal, minVal, minVal );
  1207. max.set( maxVal, maxVal, maxVal );
  1208. return this.clamp( min, max );
  1209. };
  1210. }(),
  1211. clampLength: function ( min, max ) {
  1212. var length = this.length();
  1213. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1214. },
  1215. floor: function () {
  1216. this.x = Math.floor( this.x );
  1217. this.y = Math.floor( this.y );
  1218. this.z = Math.floor( this.z );
  1219. return this;
  1220. },
  1221. ceil: function () {
  1222. this.x = Math.ceil( this.x );
  1223. this.y = Math.ceil( this.y );
  1224. this.z = Math.ceil( this.z );
  1225. return this;
  1226. },
  1227. round: function () {
  1228. this.x = Math.round( this.x );
  1229. this.y = Math.round( this.y );
  1230. this.z = Math.round( this.z );
  1231. return this;
  1232. },
  1233. roundToZero: function () {
  1234. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1235. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1236. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1237. return this;
  1238. },
  1239. negate: function () {
  1240. this.x = - this.x;
  1241. this.y = - this.y;
  1242. this.z = - this.z;
  1243. return this;
  1244. },
  1245. dot: function ( v ) {
  1246. return this.x * v.x + this.y * v.y + this.z * v.z;
  1247. },
  1248. // TODO lengthSquared?
  1249. lengthSq: function () {
  1250. return this.x * this.x + this.y * this.y + this.z * this.z;
  1251. },
  1252. length: function () {
  1253. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1254. },
  1255. manhattanLength: function () {
  1256. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1257. },
  1258. normalize: function () {
  1259. return this.divideScalar( this.length() || 1 );
  1260. },
  1261. setLength: function ( length ) {
  1262. return this.normalize().multiplyScalar( length );
  1263. },
  1264. lerp: function ( v, alpha ) {
  1265. this.x += ( v.x - this.x ) * alpha;
  1266. this.y += ( v.y - this.y ) * alpha;
  1267. this.z += ( v.z - this.z ) * alpha;
  1268. return this;
  1269. },
  1270. lerpVectors: function ( v1, v2, alpha ) {
  1271. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1272. },
  1273. cross: function ( v, w ) {
  1274. if ( w !== undefined ) {
  1275. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1276. return this.crossVectors( v, w );
  1277. }
  1278. return this.crossVectors( this, v );
  1279. },
  1280. crossVectors: function ( a, b ) {
  1281. var ax = a.x, ay = a.y, az = a.z;
  1282. var bx = b.x, by = b.y, bz = b.z;
  1283. this.x = ay * bz - az * by;
  1284. this.y = az * bx - ax * bz;
  1285. this.z = ax * by - ay * bx;
  1286. return this;
  1287. },
  1288. projectOnVector: function ( vector ) {
  1289. var scalar = vector.dot( this ) / vector.lengthSq();
  1290. return this.copy( vector ).multiplyScalar( scalar );
  1291. },
  1292. projectOnPlane: function () {
  1293. var v1 = new Vector3();
  1294. return function projectOnPlane( planeNormal ) {
  1295. v1.copy( this ).projectOnVector( planeNormal );
  1296. return this.sub( v1 );
  1297. };
  1298. }(),
  1299. reflect: function () {
  1300. // reflect incident vector off plane orthogonal to normal
  1301. // normal is assumed to have unit length
  1302. var v1 = new Vector3();
  1303. return function reflect( normal ) {
  1304. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1305. };
  1306. }(),
  1307. angleTo: function ( v ) {
  1308. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1309. // clamp, to handle numerical problems
  1310. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1311. },
  1312. distanceTo: function ( v ) {
  1313. return Math.sqrt( this.distanceToSquared( v ) );
  1314. },
  1315. distanceToSquared: function ( v ) {
  1316. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1317. return dx * dx + dy * dy + dz * dz;
  1318. },
  1319. manhattanDistanceTo: function ( v ) {
  1320. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1321. },
  1322. setFromSpherical: function ( s ) {
  1323. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1324. },
  1325. setFromSphericalCoords: function ( radius, phi, theta ) {
  1326. var sinPhiRadius = Math.sin( phi ) * radius;
  1327. this.x = sinPhiRadius * Math.sin( theta );
  1328. this.y = Math.cos( phi ) * radius;
  1329. this.z = sinPhiRadius * Math.cos( theta );
  1330. return this;
  1331. },
  1332. setFromCylindrical: function ( c ) {
  1333. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1334. },
  1335. setFromCylindricalCoords: function ( radius, theta, y ) {
  1336. this.x = radius * Math.sin( theta );
  1337. this.y = y;
  1338. this.z = radius * Math.cos( theta );
  1339. return this;
  1340. },
  1341. setFromMatrixPosition: function ( m ) {
  1342. var e = m.elements;
  1343. this.x = e[ 12 ];
  1344. this.y = e[ 13 ];
  1345. this.z = e[ 14 ];
  1346. return this;
  1347. },
  1348. setFromMatrixScale: function ( m ) {
  1349. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1350. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1351. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1352. this.x = sx;
  1353. this.y = sy;
  1354. this.z = sz;
  1355. return this;
  1356. },
  1357. setFromMatrixColumn: function ( m, index ) {
  1358. return this.fromArray( m.elements, index * 4 );
  1359. },
  1360. equals: function ( v ) {
  1361. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1362. },
  1363. fromArray: function ( array, offset ) {
  1364. if ( offset === undefined ) offset = 0;
  1365. this.x = array[ offset ];
  1366. this.y = array[ offset + 1 ];
  1367. this.z = array[ offset + 2 ];
  1368. return this;
  1369. },
  1370. toArray: function ( array, offset ) {
  1371. if ( array === undefined ) array = [];
  1372. if ( offset === undefined ) offset = 0;
  1373. array[ offset ] = this.x;
  1374. array[ offset + 1 ] = this.y;
  1375. array[ offset + 2 ] = this.z;
  1376. return array;
  1377. },
  1378. fromBufferAttribute: function ( attribute, index, offset ) {
  1379. if ( offset !== undefined ) {
  1380. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1381. }
  1382. this.x = attribute.getX( index );
  1383. this.y = attribute.getY( index );
  1384. this.z = attribute.getZ( index );
  1385. return this;
  1386. }
  1387. } );
  1388. /**
  1389. * @author alteredq / http://alteredqualia.com/
  1390. * @author WestLangley / http://github.com/WestLangley
  1391. * @author bhouston / http://clara.io
  1392. * @author tschw
  1393. */
  1394. function Matrix3() {
  1395. this.elements = [
  1396. 1, 0, 0,
  1397. 0, 1, 0,
  1398. 0, 0, 1
  1399. ];
  1400. if ( arguments.length > 0 ) {
  1401. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1402. }
  1403. }
  1404. Object.assign( Matrix3.prototype, {
  1405. isMatrix3: true,
  1406. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1407. var te = this.elements;
  1408. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1409. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1410. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1411. return this;
  1412. },
  1413. identity: function () {
  1414. this.set(
  1415. 1, 0, 0,
  1416. 0, 1, 0,
  1417. 0, 0, 1
  1418. );
  1419. return this;
  1420. },
  1421. clone: function () {
  1422. return new this.constructor().fromArray( this.elements );
  1423. },
  1424. copy: function ( m ) {
  1425. var te = this.elements;
  1426. var me = m.elements;
  1427. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1428. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1429. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1430. return this;
  1431. },
  1432. setFromMatrix4: function ( m ) {
  1433. var me = m.elements;
  1434. this.set(
  1435. me[ 0 ], me[ 4 ], me[ 8 ],
  1436. me[ 1 ], me[ 5 ], me[ 9 ],
  1437. me[ 2 ], me[ 6 ], me[ 10 ]
  1438. );
  1439. return this;
  1440. },
  1441. applyToBufferAttribute: function () {
  1442. var v1 = new Vector3();
  1443. return function applyToBufferAttribute( attribute ) {
  1444. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1445. v1.x = attribute.getX( i );
  1446. v1.y = attribute.getY( i );
  1447. v1.z = attribute.getZ( i );
  1448. v1.applyMatrix3( this );
  1449. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  1450. }
  1451. return attribute;
  1452. };
  1453. }(),
  1454. multiply: function ( m ) {
  1455. return this.multiplyMatrices( this, m );
  1456. },
  1457. premultiply: function ( m ) {
  1458. return this.multiplyMatrices( m, this );
  1459. },
  1460. multiplyMatrices: function ( a, b ) {
  1461. var ae = a.elements;
  1462. var be = b.elements;
  1463. var te = this.elements;
  1464. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1465. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1466. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1467. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1468. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1469. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1470. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1471. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1472. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1473. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1474. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1475. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1476. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1477. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1478. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1479. return this;
  1480. },
  1481. multiplyScalar: function ( s ) {
  1482. var te = this.elements;
  1483. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1484. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1485. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1486. return this;
  1487. },
  1488. determinant: function () {
  1489. var te = this.elements;
  1490. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1491. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1492. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1493. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1494. },
  1495. getInverse: function ( matrix, throwOnDegenerate ) {
  1496. if ( matrix && matrix.isMatrix4 ) {
  1497. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1498. }
  1499. var me = matrix.elements,
  1500. te = this.elements,
  1501. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1502. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1503. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1504. t11 = n33 * n22 - n32 * n23,
  1505. t12 = n32 * n13 - n33 * n12,
  1506. t13 = n23 * n12 - n22 * n13,
  1507. det = n11 * t11 + n21 * t12 + n31 * t13;
  1508. if ( det === 0 ) {
  1509. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1510. if ( throwOnDegenerate === true ) {
  1511. throw new Error( msg );
  1512. } else {
  1513. console.warn( msg );
  1514. }
  1515. return this.identity();
  1516. }
  1517. var detInv = 1 / det;
  1518. te[ 0 ] = t11 * detInv;
  1519. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1520. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1521. te[ 3 ] = t12 * detInv;
  1522. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1523. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1524. te[ 6 ] = t13 * detInv;
  1525. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1526. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1527. return this;
  1528. },
  1529. transpose: function () {
  1530. var tmp, m = this.elements;
  1531. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1532. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1533. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1534. return this;
  1535. },
  1536. getNormalMatrix: function ( matrix4 ) {
  1537. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1538. },
  1539. transposeIntoArray: function ( r ) {
  1540. var m = this.elements;
  1541. r[ 0 ] = m[ 0 ];
  1542. r[ 1 ] = m[ 3 ];
  1543. r[ 2 ] = m[ 6 ];
  1544. r[ 3 ] = m[ 1 ];
  1545. r[ 4 ] = m[ 4 ];
  1546. r[ 5 ] = m[ 7 ];
  1547. r[ 6 ] = m[ 2 ];
  1548. r[ 7 ] = m[ 5 ];
  1549. r[ 8 ] = m[ 8 ];
  1550. return this;
  1551. },
  1552. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1553. var c = Math.cos( rotation );
  1554. var s = Math.sin( rotation );
  1555. this.set(
  1556. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1557. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1558. 0, 0, 1
  1559. );
  1560. },
  1561. scale: function ( sx, sy ) {
  1562. var te = this.elements;
  1563. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1564. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1565. return this;
  1566. },
  1567. rotate: function ( theta ) {
  1568. var c = Math.cos( theta );
  1569. var s = Math.sin( theta );
  1570. var te = this.elements;
  1571. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1572. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1573. te[ 0 ] = c * a11 + s * a21;
  1574. te[ 3 ] = c * a12 + s * a22;
  1575. te[ 6 ] = c * a13 + s * a23;
  1576. te[ 1 ] = - s * a11 + c * a21;
  1577. te[ 4 ] = - s * a12 + c * a22;
  1578. te[ 7 ] = - s * a13 + c * a23;
  1579. return this;
  1580. },
  1581. translate: function ( tx, ty ) {
  1582. var te = this.elements;
  1583. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1584. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1585. return this;
  1586. },
  1587. equals: function ( matrix ) {
  1588. var te = this.elements;
  1589. var me = matrix.elements;
  1590. for ( var i = 0; i < 9; i ++ ) {
  1591. if ( te[ i ] !== me[ i ] ) return false;
  1592. }
  1593. return true;
  1594. },
  1595. fromArray: function ( array, offset ) {
  1596. if ( offset === undefined ) offset = 0;
  1597. for ( var i = 0; i < 9; i ++ ) {
  1598. this.elements[ i ] = array[ i + offset ];
  1599. }
  1600. return this;
  1601. },
  1602. toArray: function ( array, offset ) {
  1603. if ( array === undefined ) array = [];
  1604. if ( offset === undefined ) offset = 0;
  1605. var te = this.elements;
  1606. array[ offset ] = te[ 0 ];
  1607. array[ offset + 1 ] = te[ 1 ];
  1608. array[ offset + 2 ] = te[ 2 ];
  1609. array[ offset + 3 ] = te[ 3 ];
  1610. array[ offset + 4 ] = te[ 4 ];
  1611. array[ offset + 5 ] = te[ 5 ];
  1612. array[ offset + 6 ] = te[ 6 ];
  1613. array[ offset + 7 ] = te[ 7 ];
  1614. array[ offset + 8 ] = te[ 8 ];
  1615. return array;
  1616. }
  1617. } );
  1618. /**
  1619. * @author mrdoob / http://mrdoob.com/
  1620. * @author alteredq / http://alteredqualia.com/
  1621. * @author szimek / https://github.com/szimek/
  1622. */
  1623. var _canvas;
  1624. var ImageUtils = {
  1625. getDataURL: function ( image ) {
  1626. var canvas;
  1627. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1628. return image.src;
  1629. } else if ( image instanceof HTMLCanvasElement ) {
  1630. canvas = image;
  1631. } else {
  1632. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1633. _canvas.width = image.width;
  1634. _canvas.height = image.height;
  1635. var context = _canvas.getContext( '2d' );
  1636. if ( image instanceof ImageData ) {
  1637. context.putImageData( image, 0, 0 );
  1638. } else {
  1639. context.drawImage( image, 0, 0, image.width, image.height );
  1640. }
  1641. canvas = _canvas;
  1642. }
  1643. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1644. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1645. } else {
  1646. return canvas.toDataURL( 'image/png' );
  1647. }
  1648. }
  1649. };
  1650. /**
  1651. * @author mrdoob / http://mrdoob.com/
  1652. * @author alteredq / http://alteredqualia.com/
  1653. * @author szimek / https://github.com/szimek/
  1654. */
  1655. var textureId = 0;
  1656. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1657. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1658. this.uuid = _Math.generateUUID();
  1659. this.name = '';
  1660. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1661. this.mipmaps = [];
  1662. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1663. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1664. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1665. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1666. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  1667. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1668. this.format = format !== undefined ? format : RGBAFormat;
  1669. this.type = type !== undefined ? type : UnsignedByteType;
  1670. this.offset = new Vector2( 0, 0 );
  1671. this.repeat = new Vector2( 1, 1 );
  1672. this.center = new Vector2( 0, 0 );
  1673. this.rotation = 0;
  1674. this.matrixAutoUpdate = true;
  1675. this.matrix = new Matrix3();
  1676. this.generateMipmaps = true;
  1677. this.premultiplyAlpha = false;
  1678. this.flipY = true;
  1679. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1680. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1681. //
  1682. // Also changing the encoding after already used by a Material will not automatically make the Material
  1683. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1684. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1685. this.version = 0;
  1686. this.onUpdate = null;
  1687. }
  1688. Texture.DEFAULT_IMAGE = undefined;
  1689. Texture.DEFAULT_MAPPING = UVMapping;
  1690. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1691. constructor: Texture,
  1692. isTexture: true,
  1693. updateMatrix: function () {
  1694. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1695. },
  1696. clone: function () {
  1697. return new this.constructor().copy( this );
  1698. },
  1699. copy: function ( source ) {
  1700. this.name = source.name;
  1701. this.image = source.image;
  1702. this.mipmaps = source.mipmaps.slice( 0 );
  1703. this.mapping = source.mapping;
  1704. this.wrapS = source.wrapS;
  1705. this.wrapT = source.wrapT;
  1706. this.magFilter = source.magFilter;
  1707. this.minFilter = source.minFilter;
  1708. this.anisotropy = source.anisotropy;
  1709. this.format = source.format;
  1710. this.type = source.type;
  1711. this.offset.copy( source.offset );
  1712. this.repeat.copy( source.repeat );
  1713. this.center.copy( source.center );
  1714. this.rotation = source.rotation;
  1715. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1716. this.matrix.copy( source.matrix );
  1717. this.generateMipmaps = source.generateMipmaps;
  1718. this.premultiplyAlpha = source.premultiplyAlpha;
  1719. this.flipY = source.flipY;
  1720. this.unpackAlignment = source.unpackAlignment;
  1721. this.encoding = source.encoding;
  1722. return this;
  1723. },
  1724. toJSON: function ( meta ) {
  1725. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1726. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1727. return meta.textures[ this.uuid ];
  1728. }
  1729. var output = {
  1730. metadata: {
  1731. version: 4.5,
  1732. type: 'Texture',
  1733. generator: 'Texture.toJSON'
  1734. },
  1735. uuid: this.uuid,
  1736. name: this.name,
  1737. mapping: this.mapping,
  1738. repeat: [ this.repeat.x, this.repeat.y ],
  1739. offset: [ this.offset.x, this.offset.y ],
  1740. center: [ this.center.x, this.center.y ],
  1741. rotation: this.rotation,
  1742. wrap: [ this.wrapS, this.wrapT ],
  1743. format: this.format,
  1744. type: this.type,
  1745. encoding: this.encoding,
  1746. minFilter: this.minFilter,
  1747. magFilter: this.magFilter,
  1748. anisotropy: this.anisotropy,
  1749. flipY: this.flipY,
  1750. premultiplyAlpha: this.premultiplyAlpha,
  1751. unpackAlignment: this.unpackAlignment
  1752. };
  1753. if ( this.image !== undefined ) {
  1754. // TODO: Move to THREE.Image
  1755. var image = this.image;
  1756. if ( image.uuid === undefined ) {
  1757. image.uuid = _Math.generateUUID(); // UGH
  1758. }
  1759. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1760. var url;
  1761. if ( Array.isArray( image ) ) {
  1762. // process array of images e.g. CubeTexture
  1763. url = [];
  1764. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1765. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1766. }
  1767. } else {
  1768. // process single image
  1769. url = ImageUtils.getDataURL( image );
  1770. }
  1771. meta.images[ image.uuid ] = {
  1772. uuid: image.uuid,
  1773. url: url
  1774. };
  1775. }
  1776. output.image = image.uuid;
  1777. }
  1778. if ( ! isRootObject ) {
  1779. meta.textures[ this.uuid ] = output;
  1780. }
  1781. return output;
  1782. },
  1783. dispose: function () {
  1784. this.dispatchEvent( { type: 'dispose' } );
  1785. },
  1786. transformUv: function ( uv ) {
  1787. if ( this.mapping !== UVMapping ) return uv;
  1788. uv.applyMatrix3( this.matrix );
  1789. if ( uv.x < 0 || uv.x > 1 ) {
  1790. switch ( this.wrapS ) {
  1791. case RepeatWrapping:
  1792. uv.x = uv.x - Math.floor( uv.x );
  1793. break;
  1794. case ClampToEdgeWrapping:
  1795. uv.x = uv.x < 0 ? 0 : 1;
  1796. break;
  1797. case MirroredRepeatWrapping:
  1798. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1799. uv.x = Math.ceil( uv.x ) - uv.x;
  1800. } else {
  1801. uv.x = uv.x - Math.floor( uv.x );
  1802. }
  1803. break;
  1804. }
  1805. }
  1806. if ( uv.y < 0 || uv.y > 1 ) {
  1807. switch ( this.wrapT ) {
  1808. case RepeatWrapping:
  1809. uv.y = uv.y - Math.floor( uv.y );
  1810. break;
  1811. case ClampToEdgeWrapping:
  1812. uv.y = uv.y < 0 ? 0 : 1;
  1813. break;
  1814. case MirroredRepeatWrapping:
  1815. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1816. uv.y = Math.ceil( uv.y ) - uv.y;
  1817. } else {
  1818. uv.y = uv.y - Math.floor( uv.y );
  1819. }
  1820. break;
  1821. }
  1822. }
  1823. if ( this.flipY ) {
  1824. uv.y = 1 - uv.y;
  1825. }
  1826. return uv;
  1827. }
  1828. } );
  1829. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1830. set: function ( value ) {
  1831. if ( value === true ) this.version ++;
  1832. }
  1833. } );
  1834. /**
  1835. * @author supereggbert / http://www.paulbrunt.co.uk/
  1836. * @author philogb / http://blog.thejit.org/
  1837. * @author mikael emtinger / http://gomo.se/
  1838. * @author egraether / http://egraether.com/
  1839. * @author WestLangley / http://github.com/WestLangley
  1840. */
  1841. function Vector4( x, y, z, w ) {
  1842. this.x = x || 0;
  1843. this.y = y || 0;
  1844. this.z = z || 0;
  1845. this.w = ( w !== undefined ) ? w : 1;
  1846. }
  1847. Object.assign( Vector4.prototype, {
  1848. isVector4: true,
  1849. set: function ( x, y, z, w ) {
  1850. this.x = x;
  1851. this.y = y;
  1852. this.z = z;
  1853. this.w = w;
  1854. return this;
  1855. },
  1856. setScalar: function ( scalar ) {
  1857. this.x = scalar;
  1858. this.y = scalar;
  1859. this.z = scalar;
  1860. this.w = scalar;
  1861. return this;
  1862. },
  1863. setX: function ( x ) {
  1864. this.x = x;
  1865. return this;
  1866. },
  1867. setY: function ( y ) {
  1868. this.y = y;
  1869. return this;
  1870. },
  1871. setZ: function ( z ) {
  1872. this.z = z;
  1873. return this;
  1874. },
  1875. setW: function ( w ) {
  1876. this.w = w;
  1877. return this;
  1878. },
  1879. setComponent: function ( index, value ) {
  1880. switch ( index ) {
  1881. case 0: this.x = value; break;
  1882. case 1: this.y = value; break;
  1883. case 2: this.z = value; break;
  1884. case 3: this.w = value; break;
  1885. default: throw new Error( 'index is out of range: ' + index );
  1886. }
  1887. return this;
  1888. },
  1889. getComponent: function ( index ) {
  1890. switch ( index ) {
  1891. case 0: return this.x;
  1892. case 1: return this.y;
  1893. case 2: return this.z;
  1894. case 3: return this.w;
  1895. default: throw new Error( 'index is out of range: ' + index );
  1896. }
  1897. },
  1898. clone: function () {
  1899. return new this.constructor( this.x, this.y, this.z, this.w );
  1900. },
  1901. copy: function ( v ) {
  1902. this.x = v.x;
  1903. this.y = v.y;
  1904. this.z = v.z;
  1905. this.w = ( v.w !== undefined ) ? v.w : 1;
  1906. return this;
  1907. },
  1908. add: function ( v, w ) {
  1909. if ( w !== undefined ) {
  1910. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1911. return this.addVectors( v, w );
  1912. }
  1913. this.x += v.x;
  1914. this.y += v.y;
  1915. this.z += v.z;
  1916. this.w += v.w;
  1917. return this;
  1918. },
  1919. addScalar: function ( s ) {
  1920. this.x += s;
  1921. this.y += s;
  1922. this.z += s;
  1923. this.w += s;
  1924. return this;
  1925. },
  1926. addVectors: function ( a, b ) {
  1927. this.x = a.x + b.x;
  1928. this.y = a.y + b.y;
  1929. this.z = a.z + b.z;
  1930. this.w = a.w + b.w;
  1931. return this;
  1932. },
  1933. addScaledVector: function ( v, s ) {
  1934. this.x += v.x * s;
  1935. this.y += v.y * s;
  1936. this.z += v.z * s;
  1937. this.w += v.w * s;
  1938. return this;
  1939. },
  1940. sub: function ( v, w ) {
  1941. if ( w !== undefined ) {
  1942. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1943. return this.subVectors( v, w );
  1944. }
  1945. this.x -= v.x;
  1946. this.y -= v.y;
  1947. this.z -= v.z;
  1948. this.w -= v.w;
  1949. return this;
  1950. },
  1951. subScalar: function ( s ) {
  1952. this.x -= s;
  1953. this.y -= s;
  1954. this.z -= s;
  1955. this.w -= s;
  1956. return this;
  1957. },
  1958. subVectors: function ( a, b ) {
  1959. this.x = a.x - b.x;
  1960. this.y = a.y - b.y;
  1961. this.z = a.z - b.z;
  1962. this.w = a.w - b.w;
  1963. return this;
  1964. },
  1965. multiplyScalar: function ( scalar ) {
  1966. this.x *= scalar;
  1967. this.y *= scalar;
  1968. this.z *= scalar;
  1969. this.w *= scalar;
  1970. return this;
  1971. },
  1972. applyMatrix4: function ( m ) {
  1973. var x = this.x, y = this.y, z = this.z, w = this.w;
  1974. var e = m.elements;
  1975. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1976. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1977. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1978. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1979. return this;
  1980. },
  1981. divideScalar: function ( scalar ) {
  1982. return this.multiplyScalar( 1 / scalar );
  1983. },
  1984. setAxisAngleFromQuaternion: function ( q ) {
  1985. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1986. // q is assumed to be normalized
  1987. this.w = 2 * Math.acos( q.w );
  1988. var s = Math.sqrt( 1 - q.w * q.w );
  1989. if ( s < 0.0001 ) {
  1990. this.x = 1;
  1991. this.y = 0;
  1992. this.z = 0;
  1993. } else {
  1994. this.x = q.x / s;
  1995. this.y = q.y / s;
  1996. this.z = q.z / s;
  1997. }
  1998. return this;
  1999. },
  2000. setAxisAngleFromRotationMatrix: function ( m ) {
  2001. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2002. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2003. var angle, x, y, z, // variables for result
  2004. epsilon = 0.01, // margin to allow for rounding errors
  2005. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2006. te = m.elements,
  2007. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2008. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2009. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2010. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2011. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2012. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2013. // singularity found
  2014. // first check for identity matrix which must have +1 for all terms
  2015. // in leading diagonal and zero in other terms
  2016. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2017. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2018. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2019. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2020. // this singularity is identity matrix so angle = 0
  2021. this.set( 1, 0, 0, 0 );
  2022. return this; // zero angle, arbitrary axis
  2023. }
  2024. // otherwise this singularity is angle = 180
  2025. angle = Math.PI;
  2026. var xx = ( m11 + 1 ) / 2;
  2027. var yy = ( m22 + 1 ) / 2;
  2028. var zz = ( m33 + 1 ) / 2;
  2029. var xy = ( m12 + m21 ) / 4;
  2030. var xz = ( m13 + m31 ) / 4;
  2031. var yz = ( m23 + m32 ) / 4;
  2032. if ( ( xx > yy ) && ( xx > zz ) ) {
  2033. // m11 is the largest diagonal term
  2034. if ( xx < epsilon ) {
  2035. x = 0;
  2036. y = 0.707106781;
  2037. z = 0.707106781;
  2038. } else {
  2039. x = Math.sqrt( xx );
  2040. y = xy / x;
  2041. z = xz / x;
  2042. }
  2043. } else if ( yy > zz ) {
  2044. // m22 is the largest diagonal term
  2045. if ( yy < epsilon ) {
  2046. x = 0.707106781;
  2047. y = 0;
  2048. z = 0.707106781;
  2049. } else {
  2050. y = Math.sqrt( yy );
  2051. x = xy / y;
  2052. z = yz / y;
  2053. }
  2054. } else {
  2055. // m33 is the largest diagonal term so base result on this
  2056. if ( zz < epsilon ) {
  2057. x = 0.707106781;
  2058. y = 0.707106781;
  2059. z = 0;
  2060. } else {
  2061. z = Math.sqrt( zz );
  2062. x = xz / z;
  2063. y = yz / z;
  2064. }
  2065. }
  2066. this.set( x, y, z, angle );
  2067. return this; // return 180 deg rotation
  2068. }
  2069. // as we have reached here there are no singularities so we can handle normally
  2070. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2071. ( m13 - m31 ) * ( m13 - m31 ) +
  2072. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2073. if ( Math.abs( s ) < 0.001 ) s = 1;
  2074. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2075. // caught by singularity test above, but I've left it in just in case
  2076. this.x = ( m32 - m23 ) / s;
  2077. this.y = ( m13 - m31 ) / s;
  2078. this.z = ( m21 - m12 ) / s;
  2079. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2080. return this;
  2081. },
  2082. min: function ( v ) {
  2083. this.x = Math.min( this.x, v.x );
  2084. this.y = Math.min( this.y, v.y );
  2085. this.z = Math.min( this.z, v.z );
  2086. this.w = Math.min( this.w, v.w );
  2087. return this;
  2088. },
  2089. max: function ( v ) {
  2090. this.x = Math.max( this.x, v.x );
  2091. this.y = Math.max( this.y, v.y );
  2092. this.z = Math.max( this.z, v.z );
  2093. this.w = Math.max( this.w, v.w );
  2094. return this;
  2095. },
  2096. clamp: function ( min, max ) {
  2097. // assumes min < max, componentwise
  2098. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2099. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2100. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2101. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2102. return this;
  2103. },
  2104. clampScalar: function () {
  2105. var min, max;
  2106. return function clampScalar( minVal, maxVal ) {
  2107. if ( min === undefined ) {
  2108. min = new Vector4();
  2109. max = new Vector4();
  2110. }
  2111. min.set( minVal, minVal, minVal, minVal );
  2112. max.set( maxVal, maxVal, maxVal, maxVal );
  2113. return this.clamp( min, max );
  2114. };
  2115. }(),
  2116. clampLength: function ( min, max ) {
  2117. var length = this.length();
  2118. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2119. },
  2120. floor: function () {
  2121. this.x = Math.floor( this.x );
  2122. this.y = Math.floor( this.y );
  2123. this.z = Math.floor( this.z );
  2124. this.w = Math.floor( this.w );
  2125. return this;
  2126. },
  2127. ceil: function () {
  2128. this.x = Math.ceil( this.x );
  2129. this.y = Math.ceil( this.y );
  2130. this.z = Math.ceil( this.z );
  2131. this.w = Math.ceil( this.w );
  2132. return this;
  2133. },
  2134. round: function () {
  2135. this.x = Math.round( this.x );
  2136. this.y = Math.round( this.y );
  2137. this.z = Math.round( this.z );
  2138. this.w = Math.round( this.w );
  2139. return this;
  2140. },
  2141. roundToZero: function () {
  2142. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2143. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2144. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2145. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2146. return this;
  2147. },
  2148. negate: function () {
  2149. this.x = - this.x;
  2150. this.y = - this.y;
  2151. this.z = - this.z;
  2152. this.w = - this.w;
  2153. return this;
  2154. },
  2155. dot: function ( v ) {
  2156. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2157. },
  2158. lengthSq: function () {
  2159. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2160. },
  2161. length: function () {
  2162. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2163. },
  2164. manhattanLength: function () {
  2165. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2166. },
  2167. normalize: function () {
  2168. return this.divideScalar( this.length() || 1 );
  2169. },
  2170. setLength: function ( length ) {
  2171. return this.normalize().multiplyScalar( length );
  2172. },
  2173. lerp: function ( v, alpha ) {
  2174. this.x += ( v.x - this.x ) * alpha;
  2175. this.y += ( v.y - this.y ) * alpha;
  2176. this.z += ( v.z - this.z ) * alpha;
  2177. this.w += ( v.w - this.w ) * alpha;
  2178. return this;
  2179. },
  2180. lerpVectors: function ( v1, v2, alpha ) {
  2181. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2182. },
  2183. equals: function ( v ) {
  2184. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2185. },
  2186. fromArray: function ( array, offset ) {
  2187. if ( offset === undefined ) offset = 0;
  2188. this.x = array[ offset ];
  2189. this.y = array[ offset + 1 ];
  2190. this.z = array[ offset + 2 ];
  2191. this.w = array[ offset + 3 ];
  2192. return this;
  2193. },
  2194. toArray: function ( array, offset ) {
  2195. if ( array === undefined ) array = [];
  2196. if ( offset === undefined ) offset = 0;
  2197. array[ offset ] = this.x;
  2198. array[ offset + 1 ] = this.y;
  2199. array[ offset + 2 ] = this.z;
  2200. array[ offset + 3 ] = this.w;
  2201. return array;
  2202. },
  2203. fromBufferAttribute: function ( attribute, index, offset ) {
  2204. if ( offset !== undefined ) {
  2205. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2206. }
  2207. this.x = attribute.getX( index );
  2208. this.y = attribute.getY( index );
  2209. this.z = attribute.getZ( index );
  2210. this.w = attribute.getW( index );
  2211. return this;
  2212. }
  2213. } );
  2214. /**
  2215. * @author szimek / https://github.com/szimek/
  2216. * @author alteredq / http://alteredqualia.com/
  2217. * @author Marius Kintel / https://github.com/kintel
  2218. */
  2219. /*
  2220. In options, we can specify:
  2221. * Texture parameters for an auto-generated target texture
  2222. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2223. */
  2224. function WebGLRenderTarget( width, height, options ) {
  2225. this.width = width;
  2226. this.height = height;
  2227. this.scissor = new Vector4( 0, 0, width, height );
  2228. this.scissorTest = false;
  2229. this.viewport = new Vector4( 0, 0, width, height );
  2230. options = options || {};
  2231. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2232. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2233. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2234. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2235. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2236. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2237. }
  2238. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2239. constructor: WebGLRenderTarget,
  2240. isWebGLRenderTarget: true,
  2241. setSize: function ( width, height ) {
  2242. if ( this.width !== width || this.height !== height ) {
  2243. this.width = width;
  2244. this.height = height;
  2245. this.dispose();
  2246. }
  2247. this.viewport.set( 0, 0, width, height );
  2248. this.scissor.set( 0, 0, width, height );
  2249. },
  2250. clone: function () {
  2251. return new this.constructor().copy( this );
  2252. },
  2253. copy: function ( source ) {
  2254. this.width = source.width;
  2255. this.height = source.height;
  2256. this.viewport.copy( source.viewport );
  2257. this.texture = source.texture.clone();
  2258. this.depthBuffer = source.depthBuffer;
  2259. this.stencilBuffer = source.stencilBuffer;
  2260. this.depthTexture = source.depthTexture;
  2261. return this;
  2262. },
  2263. dispose: function () {
  2264. this.dispatchEvent( { type: 'dispose' } );
  2265. }
  2266. } );
  2267. /**
  2268. * @author Mugen87 / https://github.com/Mugen87
  2269. * @author Matt DesLauriers / @mattdesl
  2270. */
  2271. function WebGLMultisampleRenderTarget( width, height, options ) {
  2272. WebGLRenderTarget.call( this, width, height, options );
  2273. this.samples = 4;
  2274. }
  2275. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2276. constructor: WebGLMultisampleRenderTarget,
  2277. isWebGLMultisampleRenderTarget: true,
  2278. copy: function ( source ) {
  2279. WebGLRenderTarget.prototype.copy.call( this, source );
  2280. this.samples = source.samples;
  2281. return this;
  2282. }
  2283. } );
  2284. /**
  2285. * @author alteredq / http://alteredqualia.com
  2286. */
  2287. function WebGLRenderTargetCube( width, height, options ) {
  2288. WebGLRenderTarget.call( this, width, height, options );
  2289. }
  2290. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2291. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2292. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2293. /**
  2294. * @author alteredq / http://alteredqualia.com/
  2295. */
  2296. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2297. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2298. this.image = { data: data, width: width, height: height };
  2299. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2300. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2301. this.generateMipmaps = false;
  2302. this.flipY = false;
  2303. this.unpackAlignment = 1;
  2304. }
  2305. DataTexture.prototype = Object.create( Texture.prototype );
  2306. DataTexture.prototype.constructor = DataTexture;
  2307. DataTexture.prototype.isDataTexture = true;
  2308. /**
  2309. * @author bhouston / http://clara.io
  2310. * @author WestLangley / http://github.com/WestLangley
  2311. */
  2312. function Box3( min, max ) {
  2313. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2314. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2315. }
  2316. Object.assign( Box3.prototype, {
  2317. isBox3: true,
  2318. set: function ( min, max ) {
  2319. this.min.copy( min );
  2320. this.max.copy( max );
  2321. return this;
  2322. },
  2323. setFromArray: function ( array ) {
  2324. var minX = + Infinity;
  2325. var minY = + Infinity;
  2326. var minZ = + Infinity;
  2327. var maxX = - Infinity;
  2328. var maxY = - Infinity;
  2329. var maxZ = - Infinity;
  2330. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2331. var x = array[ i ];
  2332. var y = array[ i + 1 ];
  2333. var z = array[ i + 2 ];
  2334. if ( x < minX ) minX = x;
  2335. if ( y < minY ) minY = y;
  2336. if ( z < minZ ) minZ = z;
  2337. if ( x > maxX ) maxX = x;
  2338. if ( y > maxY ) maxY = y;
  2339. if ( z > maxZ ) maxZ = z;
  2340. }
  2341. this.min.set( minX, minY, minZ );
  2342. this.max.set( maxX, maxY, maxZ );
  2343. return this;
  2344. },
  2345. setFromBufferAttribute: function ( attribute ) {
  2346. var minX = + Infinity;
  2347. var minY = + Infinity;
  2348. var minZ = + Infinity;
  2349. var maxX = - Infinity;
  2350. var maxY = - Infinity;
  2351. var maxZ = - Infinity;
  2352. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2353. var x = attribute.getX( i );
  2354. var y = attribute.getY( i );
  2355. var z = attribute.getZ( i );
  2356. if ( x < minX ) minX = x;
  2357. if ( y < minY ) minY = y;
  2358. if ( z < minZ ) minZ = z;
  2359. if ( x > maxX ) maxX = x;
  2360. if ( y > maxY ) maxY = y;
  2361. if ( z > maxZ ) maxZ = z;
  2362. }
  2363. this.min.set( minX, minY, minZ );
  2364. this.max.set( maxX, maxY, maxZ );
  2365. return this;
  2366. },
  2367. setFromPoints: function ( points ) {
  2368. this.makeEmpty();
  2369. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2370. this.expandByPoint( points[ i ] );
  2371. }
  2372. return this;
  2373. },
  2374. setFromCenterAndSize: function () {
  2375. var v1 = new Vector3();
  2376. return function setFromCenterAndSize( center, size ) {
  2377. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2378. this.min.copy( center ).sub( halfSize );
  2379. this.max.copy( center ).add( halfSize );
  2380. return this;
  2381. };
  2382. }(),
  2383. setFromObject: function ( object ) {
  2384. this.makeEmpty();
  2385. return this.expandByObject( object );
  2386. },
  2387. clone: function () {
  2388. return new this.constructor().copy( this );
  2389. },
  2390. copy: function ( box ) {
  2391. this.min.copy( box.min );
  2392. this.max.copy( box.max );
  2393. return this;
  2394. },
  2395. makeEmpty: function () {
  2396. this.min.x = this.min.y = this.min.z = + Infinity;
  2397. this.max.x = this.max.y = this.max.z = - Infinity;
  2398. return this;
  2399. },
  2400. isEmpty: function () {
  2401. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2402. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2403. },
  2404. getCenter: function ( target ) {
  2405. if ( target === undefined ) {
  2406. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2407. target = new Vector3();
  2408. }
  2409. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2410. },
  2411. getSize: function ( target ) {
  2412. if ( target === undefined ) {
  2413. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2414. target = new Vector3();
  2415. }
  2416. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2417. },
  2418. expandByPoint: function ( point ) {
  2419. this.min.min( point );
  2420. this.max.max( point );
  2421. return this;
  2422. },
  2423. expandByVector: function ( vector ) {
  2424. this.min.sub( vector );
  2425. this.max.add( vector );
  2426. return this;
  2427. },
  2428. expandByScalar: function ( scalar ) {
  2429. this.min.addScalar( - scalar );
  2430. this.max.addScalar( scalar );
  2431. return this;
  2432. },
  2433. expandByObject: function () {
  2434. // Computes the world-axis-aligned bounding box of an object (including its children),
  2435. // accounting for both the object's, and children's, world transforms
  2436. var scope, i, l;
  2437. var v1 = new Vector3();
  2438. function traverse( node ) {
  2439. var geometry = node.geometry;
  2440. if ( geometry !== undefined ) {
  2441. if ( geometry.isGeometry ) {
  2442. var vertices = geometry.vertices;
  2443. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  2444. v1.copy( vertices[ i ] );
  2445. v1.applyMatrix4( node.matrixWorld );
  2446. scope.expandByPoint( v1 );
  2447. }
  2448. } else if ( geometry.isBufferGeometry ) {
  2449. var attribute = geometry.attributes.position;
  2450. if ( attribute !== undefined ) {
  2451. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  2452. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  2453. scope.expandByPoint( v1 );
  2454. }
  2455. }
  2456. }
  2457. }
  2458. }
  2459. return function expandByObject( object ) {
  2460. scope = this;
  2461. object.updateMatrixWorld( true );
  2462. object.traverse( traverse );
  2463. return this;
  2464. };
  2465. }(),
  2466. containsPoint: function ( point ) {
  2467. return point.x < this.min.x || point.x > this.max.x ||
  2468. point.y < this.min.y || point.y > this.max.y ||
  2469. point.z < this.min.z || point.z > this.max.z ? false : true;
  2470. },
  2471. containsBox: function ( box ) {
  2472. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2473. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2474. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2475. },
  2476. getParameter: function ( point, target ) {
  2477. // This can potentially have a divide by zero if the box
  2478. // has a size dimension of 0.
  2479. if ( target === undefined ) {
  2480. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  2481. target = new Vector3();
  2482. }
  2483. return target.set(
  2484. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2485. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2486. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2487. );
  2488. },
  2489. intersectsBox: function ( box ) {
  2490. // using 6 splitting planes to rule out intersections.
  2491. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2492. box.max.y < this.min.y || box.min.y > this.max.y ||
  2493. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2494. },
  2495. intersectsSphere: ( function () {
  2496. var closestPoint = new Vector3();
  2497. return function intersectsSphere( sphere ) {
  2498. // Find the point on the AABB closest to the sphere center.
  2499. this.clampPoint( sphere.center, closestPoint );
  2500. // If that point is inside the sphere, the AABB and sphere intersect.
  2501. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2502. };
  2503. } )(),
  2504. intersectsPlane: function ( plane ) {
  2505. // We compute the minimum and maximum dot product values. If those values
  2506. // are on the same side (back or front) of the plane, then there is no intersection.
  2507. var min, max;
  2508. if ( plane.normal.x > 0 ) {
  2509. min = plane.normal.x * this.min.x;
  2510. max = plane.normal.x * this.max.x;
  2511. } else {
  2512. min = plane.normal.x * this.max.x;
  2513. max = plane.normal.x * this.min.x;
  2514. }
  2515. if ( plane.normal.y > 0 ) {
  2516. min += plane.normal.y * this.min.y;
  2517. max += plane.normal.y * this.max.y;
  2518. } else {
  2519. min += plane.normal.y * this.max.y;
  2520. max += plane.normal.y * this.min.y;
  2521. }
  2522. if ( plane.normal.z > 0 ) {
  2523. min += plane.normal.z * this.min.z;
  2524. max += plane.normal.z * this.max.z;
  2525. } else {
  2526. min += plane.normal.z * this.max.z;
  2527. max += plane.normal.z * this.min.z;
  2528. }
  2529. return ( min <= - plane.constant && max >= - plane.constant );
  2530. },
  2531. intersectsTriangle: ( function () {
  2532. // triangle centered vertices
  2533. var v0 = new Vector3();
  2534. var v1 = new Vector3();
  2535. var v2 = new Vector3();
  2536. // triangle edge vectors
  2537. var f0 = new Vector3();
  2538. var f1 = new Vector3();
  2539. var f2 = new Vector3();
  2540. var testAxis = new Vector3();
  2541. var center = new Vector3();
  2542. var extents = new Vector3();
  2543. var triangleNormal = new Vector3();
  2544. function satForAxes( axes ) {
  2545. var i, j;
  2546. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2547. testAxis.fromArray( axes, i );
  2548. // project the aabb onto the seperating axis
  2549. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  2550. // project all 3 vertices of the triangle onto the seperating axis
  2551. var p0 = v0.dot( testAxis );
  2552. var p1 = v1.dot( testAxis );
  2553. var p2 = v2.dot( testAxis );
  2554. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2555. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2556. // points of the projected triangle are outside the projected half-length of the aabb
  2557. // the axis is seperating and we can exit
  2558. return false;
  2559. }
  2560. }
  2561. return true;
  2562. }
  2563. return function intersectsTriangle( triangle ) {
  2564. if ( this.isEmpty() ) {
  2565. return false;
  2566. }
  2567. // compute box center and extents
  2568. this.getCenter( center );
  2569. extents.subVectors( this.max, center );
  2570. // translate triangle to aabb origin
  2571. v0.subVectors( triangle.a, center );
  2572. v1.subVectors( triangle.b, center );
  2573. v2.subVectors( triangle.c, center );
  2574. // compute edge vectors for triangle
  2575. f0.subVectors( v1, v0 );
  2576. f1.subVectors( v2, v1 );
  2577. f2.subVectors( v0, v2 );
  2578. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2579. // 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
  2580. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2581. var axes = [
  2582. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  2583. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  2584. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  2585. ];
  2586. if ( ! satForAxes( axes ) ) {
  2587. return false;
  2588. }
  2589. // test 3 face normals from the aabb
  2590. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2591. if ( ! satForAxes( axes ) ) {
  2592. return false;
  2593. }
  2594. // finally testing the face normal of the triangle
  2595. // use already existing triangle edge vectors here
  2596. triangleNormal.crossVectors( f0, f1 );
  2597. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  2598. return satForAxes( axes );
  2599. };
  2600. } )(),
  2601. clampPoint: function ( point, target ) {
  2602. if ( target === undefined ) {
  2603. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  2604. target = new Vector3();
  2605. }
  2606. return target.copy( point ).clamp( this.min, this.max );
  2607. },
  2608. distanceToPoint: function () {
  2609. var v1 = new Vector3();
  2610. return function distanceToPoint( point ) {
  2611. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2612. return clampedPoint.sub( point ).length();
  2613. };
  2614. }(),
  2615. getBoundingSphere: function () {
  2616. var v1 = new Vector3();
  2617. return function getBoundingSphere( target ) {
  2618. if ( target === undefined ) {
  2619. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  2620. //target = new Sphere(); // removed to avoid cyclic dependency
  2621. }
  2622. this.getCenter( target.center );
  2623. target.radius = this.getSize( v1 ).length() * 0.5;
  2624. return target;
  2625. };
  2626. }(),
  2627. intersect: function ( box ) {
  2628. this.min.max( box.min );
  2629. this.max.min( box.max );
  2630. // 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.
  2631. if ( this.isEmpty() ) this.makeEmpty();
  2632. return this;
  2633. },
  2634. union: function ( box ) {
  2635. this.min.min( box.min );
  2636. this.max.max( box.max );
  2637. return this;
  2638. },
  2639. applyMatrix4: function () {
  2640. var points = [
  2641. new Vector3(),
  2642. new Vector3(),
  2643. new Vector3(),
  2644. new Vector3(),
  2645. new Vector3(),
  2646. new Vector3(),
  2647. new Vector3(),
  2648. new Vector3()
  2649. ];
  2650. return function applyMatrix4( matrix ) {
  2651. // transform of empty box is an empty box.
  2652. if ( this.isEmpty() ) return this;
  2653. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2654. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2655. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2656. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2657. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2658. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2659. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2660. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2661. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2662. this.setFromPoints( points );
  2663. return this;
  2664. };
  2665. }(),
  2666. translate: function ( offset ) {
  2667. this.min.add( offset );
  2668. this.max.add( offset );
  2669. return this;
  2670. },
  2671. equals: function ( box ) {
  2672. return box.min.equals( this.min ) && box.max.equals( this.max );
  2673. }
  2674. } );
  2675. /**
  2676. * @author bhouston / http://clara.io
  2677. * @author mrdoob / http://mrdoob.com/
  2678. */
  2679. function Sphere( center, radius ) {
  2680. this.center = ( center !== undefined ) ? center : new Vector3();
  2681. this.radius = ( radius !== undefined ) ? radius : 0;
  2682. }
  2683. Object.assign( Sphere.prototype, {
  2684. set: function ( center, radius ) {
  2685. this.center.copy( center );
  2686. this.radius = radius;
  2687. return this;
  2688. },
  2689. setFromPoints: function () {
  2690. var box = new Box3();
  2691. return function setFromPoints( points, optionalCenter ) {
  2692. var center = this.center;
  2693. if ( optionalCenter !== undefined ) {
  2694. center.copy( optionalCenter );
  2695. } else {
  2696. box.setFromPoints( points ).getCenter( center );
  2697. }
  2698. var maxRadiusSq = 0;
  2699. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2700. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2701. }
  2702. this.radius = Math.sqrt( maxRadiusSq );
  2703. return this;
  2704. };
  2705. }(),
  2706. clone: function () {
  2707. return new this.constructor().copy( this );
  2708. },
  2709. copy: function ( sphere ) {
  2710. this.center.copy( sphere.center );
  2711. this.radius = sphere.radius;
  2712. return this;
  2713. },
  2714. empty: function () {
  2715. return ( this.radius <= 0 );
  2716. },
  2717. containsPoint: function ( point ) {
  2718. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2719. },
  2720. distanceToPoint: function ( point ) {
  2721. return ( point.distanceTo( this.center ) - this.radius );
  2722. },
  2723. intersectsSphere: function ( sphere ) {
  2724. var radiusSum = this.radius + sphere.radius;
  2725. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2726. },
  2727. intersectsBox: function ( box ) {
  2728. return box.intersectsSphere( this );
  2729. },
  2730. intersectsPlane: function ( plane ) {
  2731. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2732. },
  2733. clampPoint: function ( point, target ) {
  2734. var deltaLengthSq = this.center.distanceToSquared( point );
  2735. if ( target === undefined ) {
  2736. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  2737. target = new Vector3();
  2738. }
  2739. target.copy( point );
  2740. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2741. target.sub( this.center ).normalize();
  2742. target.multiplyScalar( this.radius ).add( this.center );
  2743. }
  2744. return target;
  2745. },
  2746. getBoundingBox: function ( target ) {
  2747. if ( target === undefined ) {
  2748. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  2749. target = new Box3();
  2750. }
  2751. target.set( this.center, this.center );
  2752. target.expandByScalar( this.radius );
  2753. return target;
  2754. },
  2755. applyMatrix4: function ( matrix ) {
  2756. this.center.applyMatrix4( matrix );
  2757. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2758. return this;
  2759. },
  2760. translate: function ( offset ) {
  2761. this.center.add( offset );
  2762. return this;
  2763. },
  2764. equals: function ( sphere ) {
  2765. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2766. }
  2767. } );
  2768. /**
  2769. * @author bhouston / http://clara.io
  2770. */
  2771. function Plane( normal, constant ) {
  2772. // normal is assumed to be normalized
  2773. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  2774. this.constant = ( constant !== undefined ) ? constant : 0;
  2775. }
  2776. Object.assign( Plane.prototype, {
  2777. set: function ( normal, constant ) {
  2778. this.normal.copy( normal );
  2779. this.constant = constant;
  2780. return this;
  2781. },
  2782. setComponents: function ( x, y, z, w ) {
  2783. this.normal.set( x, y, z );
  2784. this.constant = w;
  2785. return this;
  2786. },
  2787. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  2788. this.normal.copy( normal );
  2789. this.constant = - point.dot( this.normal );
  2790. return this;
  2791. },
  2792. setFromCoplanarPoints: function () {
  2793. var v1 = new Vector3();
  2794. var v2 = new Vector3();
  2795. return function setFromCoplanarPoints( a, b, c ) {
  2796. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  2797. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  2798. this.setFromNormalAndCoplanarPoint( normal, a );
  2799. return this;
  2800. };
  2801. }(),
  2802. clone: function () {
  2803. return new this.constructor().copy( this );
  2804. },
  2805. copy: function ( plane ) {
  2806. this.normal.copy( plane.normal );
  2807. this.constant = plane.constant;
  2808. return this;
  2809. },
  2810. normalize: function () {
  2811. // Note: will lead to a divide by zero if the plane is invalid.
  2812. var inverseNormalLength = 1.0 / this.normal.length();
  2813. this.normal.multiplyScalar( inverseNormalLength );
  2814. this.constant *= inverseNormalLength;
  2815. return this;
  2816. },
  2817. negate: function () {
  2818. this.constant *= - 1;
  2819. this.normal.negate();
  2820. return this;
  2821. },
  2822. distanceToPoint: function ( point ) {
  2823. return this.normal.dot( point ) + this.constant;
  2824. },
  2825. distanceToSphere: function ( sphere ) {
  2826. return this.distanceToPoint( sphere.center ) - sphere.radius;
  2827. },
  2828. projectPoint: function ( point, target ) {
  2829. if ( target === undefined ) {
  2830. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  2831. target = new Vector3();
  2832. }
  2833. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  2834. },
  2835. intersectLine: function () {
  2836. var v1 = new Vector3();
  2837. return function intersectLine( line, target ) {
  2838. if ( target === undefined ) {
  2839. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  2840. target = new Vector3();
  2841. }
  2842. var direction = line.delta( v1 );
  2843. var denominator = this.normal.dot( direction );
  2844. if ( denominator === 0 ) {
  2845. // line is coplanar, return origin
  2846. if ( this.distanceToPoint( line.start ) === 0 ) {
  2847. return target.copy( line.start );
  2848. }
  2849. // Unsure if this is the correct method to handle this case.
  2850. return undefined;
  2851. }
  2852. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  2853. if ( t < 0 || t > 1 ) {
  2854. return undefined;
  2855. }
  2856. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  2857. };
  2858. }(),
  2859. intersectsLine: function ( line ) {
  2860. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  2861. var startSign = this.distanceToPoint( line.start );
  2862. var endSign = this.distanceToPoint( line.end );
  2863. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  2864. },
  2865. intersectsBox: function ( box ) {
  2866. return box.intersectsPlane( this );
  2867. },
  2868. intersectsSphere: function ( sphere ) {
  2869. return sphere.intersectsPlane( this );
  2870. },
  2871. coplanarPoint: function ( target ) {
  2872. if ( target === undefined ) {
  2873. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  2874. target = new Vector3();
  2875. }
  2876. return target.copy( this.normal ).multiplyScalar( - this.constant );
  2877. },
  2878. applyMatrix4: function () {
  2879. var v1 = new Vector3();
  2880. var m1 = new Matrix3();
  2881. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  2882. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  2883. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  2884. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  2885. this.constant = - referencePoint.dot( normal );
  2886. return this;
  2887. };
  2888. }(),
  2889. translate: function ( offset ) {
  2890. this.constant -= offset.dot( this.normal );
  2891. return this;
  2892. },
  2893. equals: function ( plane ) {
  2894. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  2895. }
  2896. } );
  2897. /**
  2898. * @author mrdoob / http://mrdoob.com/
  2899. * @author alteredq / http://alteredqualia.com/
  2900. * @author bhouston / http://clara.io
  2901. */
  2902. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  2903. this.planes = [
  2904. ( p0 !== undefined ) ? p0 : new Plane(),
  2905. ( p1 !== undefined ) ? p1 : new Plane(),
  2906. ( p2 !== undefined ) ? p2 : new Plane(),
  2907. ( p3 !== undefined ) ? p3 : new Plane(),
  2908. ( p4 !== undefined ) ? p4 : new Plane(),
  2909. ( p5 !== undefined ) ? p5 : new Plane()
  2910. ];
  2911. }
  2912. Object.assign( Frustum.prototype, {
  2913. set: function ( p0, p1, p2, p3, p4, p5 ) {
  2914. var planes = this.planes;
  2915. planes[ 0 ].copy( p0 );
  2916. planes[ 1 ].copy( p1 );
  2917. planes[ 2 ].copy( p2 );
  2918. planes[ 3 ].copy( p3 );
  2919. planes[ 4 ].copy( p4 );
  2920. planes[ 5 ].copy( p5 );
  2921. return this;
  2922. },
  2923. clone: function () {
  2924. return new this.constructor().copy( this );
  2925. },
  2926. copy: function ( frustum ) {
  2927. var planes = this.planes;
  2928. for ( var i = 0; i < 6; i ++ ) {
  2929. planes[ i ].copy( frustum.planes[ i ] );
  2930. }
  2931. return this;
  2932. },
  2933. setFromMatrix: function ( m ) {
  2934. var planes = this.planes;
  2935. var me = m.elements;
  2936. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  2937. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  2938. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  2939. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  2940. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  2941. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  2942. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  2943. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  2944. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  2945. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  2946. return this;
  2947. },
  2948. intersectsObject: function () {
  2949. var sphere = new Sphere();
  2950. return function intersectsObject( object ) {
  2951. var geometry = object.geometry;
  2952. if ( geometry.boundingSphere === null )
  2953. geometry.computeBoundingSphere();
  2954. sphere.copy( geometry.boundingSphere )
  2955. .applyMatrix4( object.matrixWorld );
  2956. return this.intersectsSphere( sphere );
  2957. };
  2958. }(),
  2959. intersectsSprite: function () {
  2960. var sphere = new Sphere();
  2961. return function intersectsSprite( sprite ) {
  2962. sphere.center.set( 0, 0, 0 );
  2963. sphere.radius = 0.7071067811865476;
  2964. sphere.applyMatrix4( sprite.matrixWorld );
  2965. return this.intersectsSphere( sphere );
  2966. };
  2967. }(),
  2968. intersectsSphere: function ( sphere ) {
  2969. var planes = this.planes;
  2970. var center = sphere.center;
  2971. var negRadius = - sphere.radius;
  2972. for ( var i = 0; i < 6; i ++ ) {
  2973. var distance = planes[ i ].distanceToPoint( center );
  2974. if ( distance < negRadius ) {
  2975. return false;
  2976. }
  2977. }
  2978. return true;
  2979. },
  2980. intersectsBox: function () {
  2981. var p = new Vector3();
  2982. return function intersectsBox( box ) {
  2983. var planes = this.planes;
  2984. for ( var i = 0; i < 6; i ++ ) {
  2985. var plane = planes[ i ];
  2986. // corner at max distance
  2987. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  2988. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  2989. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  2990. if ( plane.distanceToPoint( p ) < 0 ) {
  2991. return false;
  2992. }
  2993. }
  2994. return true;
  2995. };
  2996. }(),
  2997. containsPoint: function ( point ) {
  2998. var planes = this.planes;
  2999. for ( var i = 0; i < 6; i ++ ) {
  3000. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3001. return false;
  3002. }
  3003. }
  3004. return true;
  3005. }
  3006. } );
  3007. /**
  3008. * @author mrdoob / http://mrdoob.com/
  3009. * @author supereggbert / http://www.paulbrunt.co.uk/
  3010. * @author philogb / http://blog.thejit.org/
  3011. * @author jordi_ros / http://plattsoft.com
  3012. * @author D1plo1d / http://github.com/D1plo1d
  3013. * @author alteredq / http://alteredqualia.com/
  3014. * @author mikael emtinger / http://gomo.se/
  3015. * @author timknip / http://www.floorplanner.com/
  3016. * @author bhouston / http://clara.io
  3017. * @author WestLangley / http://github.com/WestLangley
  3018. */
  3019. function Matrix4() {
  3020. this.elements = [
  3021. 1, 0, 0, 0,
  3022. 0, 1, 0, 0,
  3023. 0, 0, 1, 0,
  3024. 0, 0, 0, 1
  3025. ];
  3026. if ( arguments.length > 0 ) {
  3027. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3028. }
  3029. }
  3030. Object.assign( Matrix4.prototype, {
  3031. isMatrix4: true,
  3032. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3033. var te = this.elements;
  3034. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3035. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3036. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3037. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3038. return this;
  3039. },
  3040. identity: function () {
  3041. this.set(
  3042. 1, 0, 0, 0,
  3043. 0, 1, 0, 0,
  3044. 0, 0, 1, 0,
  3045. 0, 0, 0, 1
  3046. );
  3047. return this;
  3048. },
  3049. clone: function () {
  3050. return new Matrix4().fromArray( this.elements );
  3051. },
  3052. copy: function ( m ) {
  3053. var te = this.elements;
  3054. var me = m.elements;
  3055. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3056. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3057. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3058. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3059. return this;
  3060. },
  3061. copyPosition: function ( m ) {
  3062. var te = this.elements, me = m.elements;
  3063. te[ 12 ] = me[ 12 ];
  3064. te[ 13 ] = me[ 13 ];
  3065. te[ 14 ] = me[ 14 ];
  3066. return this;
  3067. },
  3068. extractBasis: function ( xAxis, yAxis, zAxis ) {
  3069. xAxis.setFromMatrixColumn( this, 0 );
  3070. yAxis.setFromMatrixColumn( this, 1 );
  3071. zAxis.setFromMatrixColumn( this, 2 );
  3072. return this;
  3073. },
  3074. makeBasis: function ( xAxis, yAxis, zAxis ) {
  3075. this.set(
  3076. xAxis.x, yAxis.x, zAxis.x, 0,
  3077. xAxis.y, yAxis.y, zAxis.y, 0,
  3078. xAxis.z, yAxis.z, zAxis.z, 0,
  3079. 0, 0, 0, 1
  3080. );
  3081. return this;
  3082. },
  3083. extractRotation: function () {
  3084. var v1 = new Vector3();
  3085. return function extractRotation( m ) {
  3086. // this method does not support reflection matrices
  3087. var te = this.elements;
  3088. var me = m.elements;
  3089. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  3090. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  3091. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  3092. te[ 0 ] = me[ 0 ] * scaleX;
  3093. te[ 1 ] = me[ 1 ] * scaleX;
  3094. te[ 2 ] = me[ 2 ] * scaleX;
  3095. te[ 3 ] = 0;
  3096. te[ 4 ] = me[ 4 ] * scaleY;
  3097. te[ 5 ] = me[ 5 ] * scaleY;
  3098. te[ 6 ] = me[ 6 ] * scaleY;
  3099. te[ 7 ] = 0;
  3100. te[ 8 ] = me[ 8 ] * scaleZ;
  3101. te[ 9 ] = me[ 9 ] * scaleZ;
  3102. te[ 10 ] = me[ 10 ] * scaleZ;
  3103. te[ 11 ] = 0;
  3104. te[ 12 ] = 0;
  3105. te[ 13 ] = 0;
  3106. te[ 14 ] = 0;
  3107. te[ 15 ] = 1;
  3108. return this;
  3109. };
  3110. }(),
  3111. makeRotationFromEuler: function ( euler ) {
  3112. if ( ! ( euler && euler.isEuler ) ) {
  3113. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3114. }
  3115. var te = this.elements;
  3116. var x = euler.x, y = euler.y, z = euler.z;
  3117. var a = Math.cos( x ), b = Math.sin( x );
  3118. var c = Math.cos( y ), d = Math.sin( y );
  3119. var e = Math.cos( z ), f = Math.sin( z );
  3120. if ( euler.order === 'XYZ' ) {
  3121. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  3122. te[ 0 ] = c * e;
  3123. te[ 4 ] = - c * f;
  3124. te[ 8 ] = d;
  3125. te[ 1 ] = af + be * d;
  3126. te[ 5 ] = ae - bf * d;
  3127. te[ 9 ] = - b * c;
  3128. te[ 2 ] = bf - ae * d;
  3129. te[ 6 ] = be + af * d;
  3130. te[ 10 ] = a * c;
  3131. } else if ( euler.order === 'YXZ' ) {
  3132. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  3133. te[ 0 ] = ce + df * b;
  3134. te[ 4 ] = de * b - cf;
  3135. te[ 8 ] = a * d;
  3136. te[ 1 ] = a * f;
  3137. te[ 5 ] = a * e;
  3138. te[ 9 ] = - b;
  3139. te[ 2 ] = cf * b - de;
  3140. te[ 6 ] = df + ce * b;
  3141. te[ 10 ] = a * c;
  3142. } else if ( euler.order === 'ZXY' ) {
  3143. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  3144. te[ 0 ] = ce - df * b;
  3145. te[ 4 ] = - a * f;
  3146. te[ 8 ] = de + cf * b;
  3147. te[ 1 ] = cf + de * b;
  3148. te[ 5 ] = a * e;
  3149. te[ 9 ] = df - ce * b;
  3150. te[ 2 ] = - a * d;
  3151. te[ 6 ] = b;
  3152. te[ 10 ] = a * c;
  3153. } else if ( euler.order === 'ZYX' ) {
  3154. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  3155. te[ 0 ] = c * e;
  3156. te[ 4 ] = be * d - af;
  3157. te[ 8 ] = ae * d + bf;
  3158. te[ 1 ] = c * f;
  3159. te[ 5 ] = bf * d + ae;
  3160. te[ 9 ] = af * d - be;
  3161. te[ 2 ] = - d;
  3162. te[ 6 ] = b * c;
  3163. te[ 10 ] = a * c;
  3164. } else if ( euler.order === 'YZX' ) {
  3165. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3166. te[ 0 ] = c * e;
  3167. te[ 4 ] = bd - ac * f;
  3168. te[ 8 ] = bc * f + ad;
  3169. te[ 1 ] = f;
  3170. te[ 5 ] = a * e;
  3171. te[ 9 ] = - b * e;
  3172. te[ 2 ] = - d * e;
  3173. te[ 6 ] = ad * f + bc;
  3174. te[ 10 ] = ac - bd * f;
  3175. } else if ( euler.order === 'XZY' ) {
  3176. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3177. te[ 0 ] = c * e;
  3178. te[ 4 ] = - f;
  3179. te[ 8 ] = d * e;
  3180. te[ 1 ] = ac * f + bd;
  3181. te[ 5 ] = a * e;
  3182. te[ 9 ] = ad * f - bc;
  3183. te[ 2 ] = bc * f - ad;
  3184. te[ 6 ] = b * e;
  3185. te[ 10 ] = bd * f + ac;
  3186. }
  3187. // bottom row
  3188. te[ 3 ] = 0;
  3189. te[ 7 ] = 0;
  3190. te[ 11 ] = 0;
  3191. // last column
  3192. te[ 12 ] = 0;
  3193. te[ 13 ] = 0;
  3194. te[ 14 ] = 0;
  3195. te[ 15 ] = 1;
  3196. return this;
  3197. },
  3198. makeRotationFromQuaternion: function () {
  3199. var zero = new Vector3( 0, 0, 0 );
  3200. var one = new Vector3( 1, 1, 1 );
  3201. return function makeRotationFromQuaternion( q ) {
  3202. return this.compose( zero, q, one );
  3203. };
  3204. }(),
  3205. lookAt: function () {
  3206. var x = new Vector3();
  3207. var y = new Vector3();
  3208. var z = new Vector3();
  3209. return function lookAt( eye, target, up ) {
  3210. var te = this.elements;
  3211. z.subVectors( eye, target );
  3212. if ( z.lengthSq() === 0 ) {
  3213. // eye and target are in the same position
  3214. z.z = 1;
  3215. }
  3216. z.normalize();
  3217. x.crossVectors( up, z );
  3218. if ( x.lengthSq() === 0 ) {
  3219. // up and z are parallel
  3220. if ( Math.abs( up.z ) === 1 ) {
  3221. z.x += 0.0001;
  3222. } else {
  3223. z.z += 0.0001;
  3224. }
  3225. z.normalize();
  3226. x.crossVectors( up, z );
  3227. }
  3228. x.normalize();
  3229. y.crossVectors( z, x );
  3230. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3231. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3232. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3233. return this;
  3234. };
  3235. }(),
  3236. multiply: function ( m, n ) {
  3237. if ( n !== undefined ) {
  3238. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3239. return this.multiplyMatrices( m, n );
  3240. }
  3241. return this.multiplyMatrices( this, m );
  3242. },
  3243. premultiply: function ( m ) {
  3244. return this.multiplyMatrices( m, this );
  3245. },
  3246. multiplyMatrices: function ( a, b ) {
  3247. var ae = a.elements;
  3248. var be = b.elements;
  3249. var te = this.elements;
  3250. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3251. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3252. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3253. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3254. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3255. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3256. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3257. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3258. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3259. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3260. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3261. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3262. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3263. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3264. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3265. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3266. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3267. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3268. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3269. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3270. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3271. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3272. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3273. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3274. return this;
  3275. },
  3276. multiplyScalar: function ( s ) {
  3277. var te = this.elements;
  3278. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3279. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3280. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3281. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3282. return this;
  3283. },
  3284. applyToBufferAttribute: function () {
  3285. var v1 = new Vector3();
  3286. return function applyToBufferAttribute( attribute ) {
  3287. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3288. v1.x = attribute.getX( i );
  3289. v1.y = attribute.getY( i );
  3290. v1.z = attribute.getZ( i );
  3291. v1.applyMatrix4( this );
  3292. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  3293. }
  3294. return attribute;
  3295. };
  3296. }(),
  3297. determinant: function () {
  3298. var te = this.elements;
  3299. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3300. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3301. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3302. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3303. //TODO: make this more efficient
  3304. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3305. return (
  3306. n41 * (
  3307. + n14 * n23 * n32
  3308. - n13 * n24 * n32
  3309. - n14 * n22 * n33
  3310. + n12 * n24 * n33
  3311. + n13 * n22 * n34
  3312. - n12 * n23 * n34
  3313. ) +
  3314. n42 * (
  3315. + n11 * n23 * n34
  3316. - n11 * n24 * n33
  3317. + n14 * n21 * n33
  3318. - n13 * n21 * n34
  3319. + n13 * n24 * n31
  3320. - n14 * n23 * n31
  3321. ) +
  3322. n43 * (
  3323. + n11 * n24 * n32
  3324. - n11 * n22 * n34
  3325. - n14 * n21 * n32
  3326. + n12 * n21 * n34
  3327. + n14 * n22 * n31
  3328. - n12 * n24 * n31
  3329. ) +
  3330. n44 * (
  3331. - n13 * n22 * n31
  3332. - n11 * n23 * n32
  3333. + n11 * n22 * n33
  3334. + n13 * n21 * n32
  3335. - n12 * n21 * n33
  3336. + n12 * n23 * n31
  3337. )
  3338. );
  3339. },
  3340. transpose: function () {
  3341. var te = this.elements;
  3342. var tmp;
  3343. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3344. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3345. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3346. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3347. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3348. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3349. return this;
  3350. },
  3351. setPosition: function ( v ) {
  3352. var te = this.elements;
  3353. te[ 12 ] = v.x;
  3354. te[ 13 ] = v.y;
  3355. te[ 14 ] = v.z;
  3356. return this;
  3357. },
  3358. getInverse: function ( m, throwOnDegenerate ) {
  3359. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3360. var te = this.elements,
  3361. me = m.elements,
  3362. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3363. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3364. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3365. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3366. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3367. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3368. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3369. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3370. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3371. if ( det === 0 ) {
  3372. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  3373. if ( throwOnDegenerate === true ) {
  3374. throw new Error( msg );
  3375. } else {
  3376. console.warn( msg );
  3377. }
  3378. return this.identity();
  3379. }
  3380. var detInv = 1 / det;
  3381. te[ 0 ] = t11 * detInv;
  3382. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3383. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3384. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3385. te[ 4 ] = t12 * detInv;
  3386. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3387. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3388. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3389. te[ 8 ] = t13 * detInv;
  3390. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3391. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3392. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3393. te[ 12 ] = t14 * detInv;
  3394. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3395. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3396. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3397. return this;
  3398. },
  3399. scale: function ( v ) {
  3400. var te = this.elements;
  3401. var x = v.x, y = v.y, z = v.z;
  3402. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3403. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3404. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3405. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3406. return this;
  3407. },
  3408. getMaxScaleOnAxis: function () {
  3409. var te = this.elements;
  3410. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3411. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3412. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3413. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3414. },
  3415. makeTranslation: function ( x, y, z ) {
  3416. this.set(
  3417. 1, 0, 0, x,
  3418. 0, 1, 0, y,
  3419. 0, 0, 1, z,
  3420. 0, 0, 0, 1
  3421. );
  3422. return this;
  3423. },
  3424. makeRotationX: function ( theta ) {
  3425. var c = Math.cos( theta ), s = Math.sin( theta );
  3426. this.set(
  3427. 1, 0, 0, 0,
  3428. 0, c, - s, 0,
  3429. 0, s, c, 0,
  3430. 0, 0, 0, 1
  3431. );
  3432. return this;
  3433. },
  3434. makeRotationY: function ( theta ) {
  3435. var c = Math.cos( theta ), s = Math.sin( theta );
  3436. this.set(
  3437. c, 0, s, 0,
  3438. 0, 1, 0, 0,
  3439. - s, 0, c, 0,
  3440. 0, 0, 0, 1
  3441. );
  3442. return this;
  3443. },
  3444. makeRotationZ: function ( theta ) {
  3445. var c = Math.cos( theta ), s = Math.sin( theta );
  3446. this.set(
  3447. c, - s, 0, 0,
  3448. s, c, 0, 0,
  3449. 0, 0, 1, 0,
  3450. 0, 0, 0, 1
  3451. );
  3452. return this;
  3453. },
  3454. makeRotationAxis: function ( axis, angle ) {
  3455. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3456. var c = Math.cos( angle );
  3457. var s = Math.sin( angle );
  3458. var t = 1 - c;
  3459. var x = axis.x, y = axis.y, z = axis.z;
  3460. var tx = t * x, ty = t * y;
  3461. this.set(
  3462. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3463. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3464. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3465. 0, 0, 0, 1
  3466. );
  3467. return this;
  3468. },
  3469. makeScale: function ( x, y, z ) {
  3470. this.set(
  3471. x, 0, 0, 0,
  3472. 0, y, 0, 0,
  3473. 0, 0, z, 0,
  3474. 0, 0, 0, 1
  3475. );
  3476. return this;
  3477. },
  3478. makeShear: function ( x, y, z ) {
  3479. this.set(
  3480. 1, y, z, 0,
  3481. x, 1, z, 0,
  3482. x, y, 1, 0,
  3483. 0, 0, 0, 1
  3484. );
  3485. return this;
  3486. },
  3487. compose: function ( position, quaternion, scale ) {
  3488. var te = this.elements;
  3489. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3490. var x2 = x + x, y2 = y + y, z2 = z + z;
  3491. var xx = x * x2, xy = x * y2, xz = x * z2;
  3492. var yy = y * y2, yz = y * z2, zz = z * z2;
  3493. var wx = w * x2, wy = w * y2, wz = w * z2;
  3494. var sx = scale.x, sy = scale.y, sz = scale.z;
  3495. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3496. te[ 1 ] = ( xy + wz ) * sx;
  3497. te[ 2 ] = ( xz - wy ) * sx;
  3498. te[ 3 ] = 0;
  3499. te[ 4 ] = ( xy - wz ) * sy;
  3500. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3501. te[ 6 ] = ( yz + wx ) * sy;
  3502. te[ 7 ] = 0;
  3503. te[ 8 ] = ( xz + wy ) * sz;
  3504. te[ 9 ] = ( yz - wx ) * sz;
  3505. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3506. te[ 11 ] = 0;
  3507. te[ 12 ] = position.x;
  3508. te[ 13 ] = position.y;
  3509. te[ 14 ] = position.z;
  3510. te[ 15 ] = 1;
  3511. return this;
  3512. },
  3513. decompose: function () {
  3514. var vector = new Vector3();
  3515. var matrix = new Matrix4();
  3516. return function decompose( position, quaternion, scale ) {
  3517. var te = this.elements;
  3518. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3519. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3520. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3521. // if determine is negative, we need to invert one scale
  3522. var det = this.determinant();
  3523. if ( det < 0 ) sx = - sx;
  3524. position.x = te[ 12 ];
  3525. position.y = te[ 13 ];
  3526. position.z = te[ 14 ];
  3527. // scale the rotation part
  3528. matrix.copy( this );
  3529. var invSX = 1 / sx;
  3530. var invSY = 1 / sy;
  3531. var invSZ = 1 / sz;
  3532. matrix.elements[ 0 ] *= invSX;
  3533. matrix.elements[ 1 ] *= invSX;
  3534. matrix.elements[ 2 ] *= invSX;
  3535. matrix.elements[ 4 ] *= invSY;
  3536. matrix.elements[ 5 ] *= invSY;
  3537. matrix.elements[ 6 ] *= invSY;
  3538. matrix.elements[ 8 ] *= invSZ;
  3539. matrix.elements[ 9 ] *= invSZ;
  3540. matrix.elements[ 10 ] *= invSZ;
  3541. quaternion.setFromRotationMatrix( matrix );
  3542. scale.x = sx;
  3543. scale.y = sy;
  3544. scale.z = sz;
  3545. return this;
  3546. };
  3547. }(),
  3548. makePerspective: function ( left, right, top, bottom, near, far ) {
  3549. if ( far === undefined ) {
  3550. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3551. }
  3552. var te = this.elements;
  3553. var x = 2 * near / ( right - left );
  3554. var y = 2 * near / ( top - bottom );
  3555. var a = ( right + left ) / ( right - left );
  3556. var b = ( top + bottom ) / ( top - bottom );
  3557. var c = - ( far + near ) / ( far - near );
  3558. var d = - 2 * far * near / ( far - near );
  3559. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3560. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3561. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3562. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3563. return this;
  3564. },
  3565. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3566. var te = this.elements;
  3567. var w = 1.0 / ( right - left );
  3568. var h = 1.0 / ( top - bottom );
  3569. var p = 1.0 / ( far - near );
  3570. var x = ( right + left ) * w;
  3571. var y = ( top + bottom ) * h;
  3572. var z = ( far + near ) * p;
  3573. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3574. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3575. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3576. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3577. return this;
  3578. },
  3579. equals: function ( matrix ) {
  3580. var te = this.elements;
  3581. var me = matrix.elements;
  3582. for ( var i = 0; i < 16; i ++ ) {
  3583. if ( te[ i ] !== me[ i ] ) return false;
  3584. }
  3585. return true;
  3586. },
  3587. fromArray: function ( array, offset ) {
  3588. if ( offset === undefined ) offset = 0;
  3589. for ( var i = 0; i < 16; i ++ ) {
  3590. this.elements[ i ] = array[ i + offset ];
  3591. }
  3592. return this;
  3593. },
  3594. toArray: function ( array, offset ) {
  3595. if ( array === undefined ) array = [];
  3596. if ( offset === undefined ) offset = 0;
  3597. var te = this.elements;
  3598. array[ offset ] = te[ 0 ];
  3599. array[ offset + 1 ] = te[ 1 ];
  3600. array[ offset + 2 ] = te[ 2 ];
  3601. array[ offset + 3 ] = te[ 3 ];
  3602. array[ offset + 4 ] = te[ 4 ];
  3603. array[ offset + 5 ] = te[ 5 ];
  3604. array[ offset + 6 ] = te[ 6 ];
  3605. array[ offset + 7 ] = te[ 7 ];
  3606. array[ offset + 8 ] = te[ 8 ];
  3607. array[ offset + 9 ] = te[ 9 ];
  3608. array[ offset + 10 ] = te[ 10 ];
  3609. array[ offset + 11 ] = te[ 11 ];
  3610. array[ offset + 12 ] = te[ 12 ];
  3611. array[ offset + 13 ] = te[ 13 ];
  3612. array[ offset + 14 ] = te[ 14 ];
  3613. array[ offset + 15 ] = te[ 15 ];
  3614. return array;
  3615. }
  3616. } );
  3617. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3618. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3619. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3620. 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( PHYSICAL )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
  3621. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3622. var begin_vertex = "vec3 transformed = vec3( position );";
  3623. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  3624. 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}\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 GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, 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_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 GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.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( specularColor, dotNV );\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}";
  3625. 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";
  3626. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  3627. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  3628. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3629. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3630. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3631. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3632. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3633. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3634. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(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}\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};\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}";
  3635. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV( sampler2D envMap, vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif";
  3636. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = normalMatrix * objectTangent;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  3637. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3638. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3639. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3640. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3641. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3642. 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 = min( floor( D ) / 255.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}";
  3643. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, 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_EQUIREC )\n\t\tvec2 sampleUV;\n\t\treflectVec = normalize( reflectVec );\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\tenvColor = envMapTexelToLinear( envColor );\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";
  3644. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  3645. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  3646. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\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";
  3647. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3648. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3649. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\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";
  3650. 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";
  3651. var gradientmap_pars_fragment = "#ifdef TOON\n\tuniform sampler2D gradientMap;\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\t\tfloat dotNL = dot( normal, lightDirection );\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t\t#ifdef USE_GRADIENTMAP\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\n\t\t#else\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t\t#endif\n\t}\n#endif";
  3652. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3653. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3654. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = 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;\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\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#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\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#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\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#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop\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#endif";
  3655. var lights_pars_begin = "uniform vec3 ambientLightColor;\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\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\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\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\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\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\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";
  3656. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP ) && defined( PHYSICAL )\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\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryVec, 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 blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, 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\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent ));\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\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#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, 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";
  3657. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3658. 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\t#ifdef TOON\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#else\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\t\tvec3 irradiance = dotNL * directLight.color;\n\t#endif\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)";
  3659. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.clearCoat = saturate( clearCoat );\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\n#endif";
  3660. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#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#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#endif\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#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 singleScattering = vec3( 0.0 );\n\t\tvec3 multiScattering = vec3( 0.0 );\n\t\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\t\tvec3 diffuse = material.diffuseColor;\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\t\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\t\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#else\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#endif\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\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\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\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}";
  3661. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop\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#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearCoatRadiance = vec3( 0.0 );\n#endif";
  3662. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * 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( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), maxMipLevel );\n\t#ifndef STANDARD\n\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t#endif\n#endif";
  3663. 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, irradiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif";
  3664. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3665. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3666. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  3667. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\tgl_Position.z *= gl_Position.w;\n\t#endif\n#endif";
  3668. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3669. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3670. var map_particle_fragment = "#ifdef USE_MAP\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif";
  3671. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3672. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3673. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3674. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif";
  3675. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  3676. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  3677. 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#endif\n#endif";
  3678. var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t#ifdef FLIP_SIDED\n\t\t\tnormal = - normal;\n\t\t#endif\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tnormal = normalize( normalMatrix * normal );\n\t#else\n\t\t#ifdef USE_TANGENT\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy = normalScale * mapN.xy;\n\t\t\tnormal = normalize( vTBN * mapN );\n\t\t#else\n\t\t\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  3679. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tuniform mat3 normalMatrix;\n\t#else\n\t\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\t\tvec2 st0 = dFdx( vUv.st );\n\t\t\tvec2 st1 = dFdy( vUv.st );\n\t\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\t\tvec3 N = normalize( surf_norm );\n\t\t\tmat3 tsn = mat3( S, T, N );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy *= normalScale;\n\t\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\treturn normalize( tsn * mapN );\n\t\t}\n\t#endif\n#endif";
  3680. 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}\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}";
  3681. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3682. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3683. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3684. var dithering_pars_fragment = "#if defined( 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";
  3685. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3686. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3687. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\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\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( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, 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( 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 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\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\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\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 )\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";
  3688. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n#endif";
  3689. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif";
  3690. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  3691. 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";
  3692. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform 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";
  3693. 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";
  3694. 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";
  3695. 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";
  3696. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3697. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3698. var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\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}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\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 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
  3699. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n#endif";
  3700. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif";
  3701. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  3702. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3703. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3704. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3705. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3706. 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}";
  3707. 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}";
  3708. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3709. 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}";
  3710. 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>\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\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}";
  3711. 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>\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}";
  3712. 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}";
  3713. 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}";
  3714. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3715. 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}";
  3716. 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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3717. 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 <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\tvLineDistance = scale * lineDistance;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  3718. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\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_pars_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\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * 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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3719. 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}";
  3720. 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_pars_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\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\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}";
  3721. 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}";
  3722. 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 <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 <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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3723. 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 <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 <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}";
  3724. 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_pars_fragment>\n#include <gradientmap_pars_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}";
  3725. 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}";
  3726. var meshphysical_frag = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n\tuniform float clearCoat;\n\tuniform float clearCoatRoughness;\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_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 <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 <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\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}";
  3727. var meshphysical_vert = "#define PHYSICAL\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}";
  3728. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_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>\nvoid main() {\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}";
  3729. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_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 <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_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#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  3730. 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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3731. 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 = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\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}";
  3732. 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 <fog_fragment>\n}";
  3733. var shadow_vert = "#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 <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3734. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_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 <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}";
  3735. 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 = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\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}";
  3736. var ShaderChunk = {
  3737. alphamap_fragment: alphamap_fragment,
  3738. alphamap_pars_fragment: alphamap_pars_fragment,
  3739. alphatest_fragment: alphatest_fragment,
  3740. aomap_fragment: aomap_fragment,
  3741. aomap_pars_fragment: aomap_pars_fragment,
  3742. begin_vertex: begin_vertex,
  3743. beginnormal_vertex: beginnormal_vertex,
  3744. bsdfs: bsdfs,
  3745. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3746. clipping_planes_fragment: clipping_planes_fragment,
  3747. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3748. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3749. clipping_planes_vertex: clipping_planes_vertex,
  3750. color_fragment: color_fragment,
  3751. color_pars_fragment: color_pars_fragment,
  3752. color_pars_vertex: color_pars_vertex,
  3753. color_vertex: color_vertex,
  3754. common: common,
  3755. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3756. defaultnormal_vertex: defaultnormal_vertex,
  3757. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3758. displacementmap_vertex: displacementmap_vertex,
  3759. emissivemap_fragment: emissivemap_fragment,
  3760. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3761. encodings_fragment: encodings_fragment,
  3762. encodings_pars_fragment: encodings_pars_fragment,
  3763. envmap_fragment: envmap_fragment,
  3764. envmap_pars_fragment: envmap_pars_fragment,
  3765. envmap_pars_vertex: envmap_pars_vertex,
  3766. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3767. envmap_vertex: envmap_vertex,
  3768. fog_vertex: fog_vertex,
  3769. fog_pars_vertex: fog_pars_vertex,
  3770. fog_fragment: fog_fragment,
  3771. fog_pars_fragment: fog_pars_fragment,
  3772. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3773. lightmap_fragment: lightmap_fragment,
  3774. lightmap_pars_fragment: lightmap_pars_fragment,
  3775. lights_lambert_vertex: lights_lambert_vertex,
  3776. lights_pars_begin: lights_pars_begin,
  3777. lights_phong_fragment: lights_phong_fragment,
  3778. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3779. lights_physical_fragment: lights_physical_fragment,
  3780. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3781. lights_fragment_begin: lights_fragment_begin,
  3782. lights_fragment_maps: lights_fragment_maps,
  3783. lights_fragment_end: lights_fragment_end,
  3784. logdepthbuf_fragment: logdepthbuf_fragment,
  3785. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3786. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3787. logdepthbuf_vertex: logdepthbuf_vertex,
  3788. map_fragment: map_fragment,
  3789. map_pars_fragment: map_pars_fragment,
  3790. map_particle_fragment: map_particle_fragment,
  3791. map_particle_pars_fragment: map_particle_pars_fragment,
  3792. metalnessmap_fragment: metalnessmap_fragment,
  3793. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3794. morphnormal_vertex: morphnormal_vertex,
  3795. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3796. morphtarget_vertex: morphtarget_vertex,
  3797. normal_fragment_begin: normal_fragment_begin,
  3798. normal_fragment_maps: normal_fragment_maps,
  3799. normalmap_pars_fragment: normalmap_pars_fragment,
  3800. packing: packing,
  3801. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3802. project_vertex: project_vertex,
  3803. dithering_fragment: dithering_fragment,
  3804. dithering_pars_fragment: dithering_pars_fragment,
  3805. roughnessmap_fragment: roughnessmap_fragment,
  3806. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3807. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3808. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3809. shadowmap_vertex: shadowmap_vertex,
  3810. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3811. skinbase_vertex: skinbase_vertex,
  3812. skinning_pars_vertex: skinning_pars_vertex,
  3813. skinning_vertex: skinning_vertex,
  3814. skinnormal_vertex: skinnormal_vertex,
  3815. specularmap_fragment: specularmap_fragment,
  3816. specularmap_pars_fragment: specularmap_pars_fragment,
  3817. tonemapping_fragment: tonemapping_fragment,
  3818. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3819. uv_pars_fragment: uv_pars_fragment,
  3820. uv_pars_vertex: uv_pars_vertex,
  3821. uv_vertex: uv_vertex,
  3822. uv2_pars_fragment: uv2_pars_fragment,
  3823. uv2_pars_vertex: uv2_pars_vertex,
  3824. uv2_vertex: uv2_vertex,
  3825. worldpos_vertex: worldpos_vertex,
  3826. background_frag: background_frag,
  3827. background_vert: background_vert,
  3828. cube_frag: cube_frag,
  3829. cube_vert: cube_vert,
  3830. depth_frag: depth_frag,
  3831. depth_vert: depth_vert,
  3832. distanceRGBA_frag: distanceRGBA_frag,
  3833. distanceRGBA_vert: distanceRGBA_vert,
  3834. equirect_frag: equirect_frag,
  3835. equirect_vert: equirect_vert,
  3836. linedashed_frag: linedashed_frag,
  3837. linedashed_vert: linedashed_vert,
  3838. meshbasic_frag: meshbasic_frag,
  3839. meshbasic_vert: meshbasic_vert,
  3840. meshlambert_frag: meshlambert_frag,
  3841. meshlambert_vert: meshlambert_vert,
  3842. meshmatcap_frag: meshmatcap_frag,
  3843. meshmatcap_vert: meshmatcap_vert,
  3844. meshphong_frag: meshphong_frag,
  3845. meshphong_vert: meshphong_vert,
  3846. meshphysical_frag: meshphysical_frag,
  3847. meshphysical_vert: meshphysical_vert,
  3848. normal_frag: normal_frag,
  3849. normal_vert: normal_vert,
  3850. points_frag: points_frag,
  3851. points_vert: points_vert,
  3852. shadow_frag: shadow_frag,
  3853. shadow_vert: shadow_vert,
  3854. sprite_frag: sprite_frag,
  3855. sprite_vert: sprite_vert
  3856. };
  3857. /**
  3858. * Uniform Utilities
  3859. */
  3860. function cloneUniforms( src ) {
  3861. var dst = {};
  3862. for ( var u in src ) {
  3863. dst[ u ] = {};
  3864. for ( var p in src[ u ] ) {
  3865. var property = src[ u ][ p ];
  3866. if ( property && ( property.isColor ||
  3867. property.isMatrix3 || property.isMatrix4 ||
  3868. property.isVector2 || property.isVector3 || property.isVector4 ||
  3869. property.isTexture ) ) {
  3870. dst[ u ][ p ] = property.clone();
  3871. } else if ( Array.isArray( property ) ) {
  3872. dst[ u ][ p ] = property.slice();
  3873. } else {
  3874. dst[ u ][ p ] = property;
  3875. }
  3876. }
  3877. }
  3878. return dst;
  3879. }
  3880. function mergeUniforms( uniforms ) {
  3881. var merged = {};
  3882. for ( var u = 0; u < uniforms.length; u ++ ) {
  3883. var tmp = cloneUniforms( uniforms[ u ] );
  3884. for ( var p in tmp ) {
  3885. merged[ p ] = tmp[ p ];
  3886. }
  3887. }
  3888. return merged;
  3889. }
  3890. // Legacy
  3891. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3892. /**
  3893. * @author mrdoob / http://mrdoob.com/
  3894. */
  3895. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3896. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3897. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3898. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3899. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3900. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3901. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3902. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3903. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3904. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3905. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3906. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3907. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3908. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3909. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3910. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3911. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3912. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3913. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3914. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3915. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3916. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3917. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3918. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3919. function Color( r, g, b ) {
  3920. if ( g === undefined && b === undefined ) {
  3921. // r is THREE.Color, hex or string
  3922. return this.set( r );
  3923. }
  3924. return this.setRGB( r, g, b );
  3925. }
  3926. Object.assign( Color.prototype, {
  3927. isColor: true,
  3928. r: 1, g: 1, b: 1,
  3929. set: function ( value ) {
  3930. if ( value && value.isColor ) {
  3931. this.copy( value );
  3932. } else if ( typeof value === 'number' ) {
  3933. this.setHex( value );
  3934. } else if ( typeof value === 'string' ) {
  3935. this.setStyle( value );
  3936. }
  3937. return this;
  3938. },
  3939. setScalar: function ( scalar ) {
  3940. this.r = scalar;
  3941. this.g = scalar;
  3942. this.b = scalar;
  3943. return this;
  3944. },
  3945. setHex: function ( hex ) {
  3946. hex = Math.floor( hex );
  3947. this.r = ( hex >> 16 & 255 ) / 255;
  3948. this.g = ( hex >> 8 & 255 ) / 255;
  3949. this.b = ( hex & 255 ) / 255;
  3950. return this;
  3951. },
  3952. setRGB: function ( r, g, b ) {
  3953. this.r = r;
  3954. this.g = g;
  3955. this.b = b;
  3956. return this;
  3957. },
  3958. setHSL: function () {
  3959. function hue2rgb( p, q, t ) {
  3960. if ( t < 0 ) t += 1;
  3961. if ( t > 1 ) t -= 1;
  3962. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3963. if ( t < 1 / 2 ) return q;
  3964. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3965. return p;
  3966. }
  3967. return function setHSL( h, s, l ) {
  3968. // h,s,l ranges are in 0.0 - 1.0
  3969. h = _Math.euclideanModulo( h, 1 );
  3970. s = _Math.clamp( s, 0, 1 );
  3971. l = _Math.clamp( l, 0, 1 );
  3972. if ( s === 0 ) {
  3973. this.r = this.g = this.b = l;
  3974. } else {
  3975. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3976. var q = ( 2 * l ) - p;
  3977. this.r = hue2rgb( q, p, h + 1 / 3 );
  3978. this.g = hue2rgb( q, p, h );
  3979. this.b = hue2rgb( q, p, h - 1 / 3 );
  3980. }
  3981. return this;
  3982. };
  3983. }(),
  3984. setStyle: function ( style ) {
  3985. function handleAlpha( string ) {
  3986. if ( string === undefined ) return;
  3987. if ( parseFloat( string ) < 1 ) {
  3988. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3989. }
  3990. }
  3991. var m;
  3992. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3993. // rgb / hsl
  3994. var color;
  3995. var name = m[ 1 ];
  3996. var components = m[ 2 ];
  3997. switch ( name ) {
  3998. case 'rgb':
  3999. case 'rgba':
  4000. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4001. // rgb(255,0,0) rgba(255,0,0,0.5)
  4002. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4003. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4004. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4005. handleAlpha( color[ 5 ] );
  4006. return this;
  4007. }
  4008. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4009. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4010. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4011. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4012. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4013. handleAlpha( color[ 5 ] );
  4014. return this;
  4015. }
  4016. break;
  4017. case 'hsl':
  4018. case 'hsla':
  4019. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4020. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4021. var h = parseFloat( color[ 1 ] ) / 360;
  4022. var s = parseInt( color[ 2 ], 10 ) / 100;
  4023. var l = parseInt( color[ 3 ], 10 ) / 100;
  4024. handleAlpha( color[ 5 ] );
  4025. return this.setHSL( h, s, l );
  4026. }
  4027. break;
  4028. }
  4029. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4030. // hex color
  4031. var hex = m[ 1 ];
  4032. var size = hex.length;
  4033. if ( size === 3 ) {
  4034. // #ff0
  4035. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4036. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4037. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4038. return this;
  4039. } else if ( size === 6 ) {
  4040. // #ff0000
  4041. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4042. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4043. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4044. return this;
  4045. }
  4046. }
  4047. if ( style && style.length > 0 ) {
  4048. // color keywords
  4049. var hex = ColorKeywords[ style ];
  4050. if ( hex !== undefined ) {
  4051. // red
  4052. this.setHex( hex );
  4053. } else {
  4054. // unknown color
  4055. console.warn( 'THREE.Color: Unknown color ' + style );
  4056. }
  4057. }
  4058. return this;
  4059. },
  4060. clone: function () {
  4061. return new this.constructor( this.r, this.g, this.b );
  4062. },
  4063. copy: function ( color ) {
  4064. this.r = color.r;
  4065. this.g = color.g;
  4066. this.b = color.b;
  4067. return this;
  4068. },
  4069. copyGammaToLinear: function ( color, gammaFactor ) {
  4070. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4071. this.r = Math.pow( color.r, gammaFactor );
  4072. this.g = Math.pow( color.g, gammaFactor );
  4073. this.b = Math.pow( color.b, gammaFactor );
  4074. return this;
  4075. },
  4076. copyLinearToGamma: function ( color, gammaFactor ) {
  4077. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4078. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4079. this.r = Math.pow( color.r, safeInverse );
  4080. this.g = Math.pow( color.g, safeInverse );
  4081. this.b = Math.pow( color.b, safeInverse );
  4082. return this;
  4083. },
  4084. convertGammaToLinear: function ( gammaFactor ) {
  4085. this.copyGammaToLinear( this, gammaFactor );
  4086. return this;
  4087. },
  4088. convertLinearToGamma: function ( gammaFactor ) {
  4089. this.copyLinearToGamma( this, gammaFactor );
  4090. return this;
  4091. },
  4092. copySRGBToLinear: function () {
  4093. function SRGBToLinear( c ) {
  4094. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4095. }
  4096. return function copySRGBToLinear( color ) {
  4097. this.r = SRGBToLinear( color.r );
  4098. this.g = SRGBToLinear( color.g );
  4099. this.b = SRGBToLinear( color.b );
  4100. return this;
  4101. };
  4102. }(),
  4103. copyLinearToSRGB: function () {
  4104. function LinearToSRGB( c ) {
  4105. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4106. }
  4107. return function copyLinearToSRGB( color ) {
  4108. this.r = LinearToSRGB( color.r );
  4109. this.g = LinearToSRGB( color.g );
  4110. this.b = LinearToSRGB( color.b );
  4111. return this;
  4112. };
  4113. }(),
  4114. convertSRGBToLinear: function () {
  4115. this.copySRGBToLinear( this );
  4116. return this;
  4117. },
  4118. convertLinearToSRGB: function () {
  4119. this.copyLinearToSRGB( this );
  4120. return this;
  4121. },
  4122. getHex: function () {
  4123. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4124. },
  4125. getHexString: function () {
  4126. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4127. },
  4128. getHSL: function ( target ) {
  4129. // h,s,l ranges are in 0.0 - 1.0
  4130. if ( target === undefined ) {
  4131. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4132. target = { h: 0, s: 0, l: 0 };
  4133. }
  4134. var r = this.r, g = this.g, b = this.b;
  4135. var max = Math.max( r, g, b );
  4136. var min = Math.min( r, g, b );
  4137. var hue, saturation;
  4138. var lightness = ( min + max ) / 2.0;
  4139. if ( min === max ) {
  4140. hue = 0;
  4141. saturation = 0;
  4142. } else {
  4143. var delta = max - min;
  4144. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4145. switch ( max ) {
  4146. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4147. case g: hue = ( b - r ) / delta + 2; break;
  4148. case b: hue = ( r - g ) / delta + 4; break;
  4149. }
  4150. hue /= 6;
  4151. }
  4152. target.h = hue;
  4153. target.s = saturation;
  4154. target.l = lightness;
  4155. return target;
  4156. },
  4157. getStyle: function () {
  4158. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4159. },
  4160. offsetHSL: function () {
  4161. var hsl = {};
  4162. return function ( h, s, l ) {
  4163. this.getHSL( hsl );
  4164. hsl.h += h; hsl.s += s; hsl.l += l;
  4165. this.setHSL( hsl.h, hsl.s, hsl.l );
  4166. return this;
  4167. };
  4168. }(),
  4169. add: function ( color ) {
  4170. this.r += color.r;
  4171. this.g += color.g;
  4172. this.b += color.b;
  4173. return this;
  4174. },
  4175. addColors: function ( color1, color2 ) {
  4176. this.r = color1.r + color2.r;
  4177. this.g = color1.g + color2.g;
  4178. this.b = color1.b + color2.b;
  4179. return this;
  4180. },
  4181. addScalar: function ( s ) {
  4182. this.r += s;
  4183. this.g += s;
  4184. this.b += s;
  4185. return this;
  4186. },
  4187. sub: function ( color ) {
  4188. this.r = Math.max( 0, this.r - color.r );
  4189. this.g = Math.max( 0, this.g - color.g );
  4190. this.b = Math.max( 0, this.b - color.b );
  4191. return this;
  4192. },
  4193. multiply: function ( color ) {
  4194. this.r *= color.r;
  4195. this.g *= color.g;
  4196. this.b *= color.b;
  4197. return this;
  4198. },
  4199. multiplyScalar: function ( s ) {
  4200. this.r *= s;
  4201. this.g *= s;
  4202. this.b *= s;
  4203. return this;
  4204. },
  4205. lerp: function ( color, alpha ) {
  4206. this.r += ( color.r - this.r ) * alpha;
  4207. this.g += ( color.g - this.g ) * alpha;
  4208. this.b += ( color.b - this.b ) * alpha;
  4209. return this;
  4210. },
  4211. lerpHSL: function () {
  4212. var hslA = { h: 0, s: 0, l: 0 };
  4213. var hslB = { h: 0, s: 0, l: 0 };
  4214. return function lerpHSL( color, alpha ) {
  4215. this.getHSL( hslA );
  4216. color.getHSL( hslB );
  4217. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4218. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4219. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4220. this.setHSL( h, s, l );
  4221. return this;
  4222. };
  4223. }(),
  4224. equals: function ( c ) {
  4225. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4226. },
  4227. fromArray: function ( array, offset ) {
  4228. if ( offset === undefined ) offset = 0;
  4229. this.r = array[ offset ];
  4230. this.g = array[ offset + 1 ];
  4231. this.b = array[ offset + 2 ];
  4232. return this;
  4233. },
  4234. toArray: function ( array, offset ) {
  4235. if ( array === undefined ) array = [];
  4236. if ( offset === undefined ) offset = 0;
  4237. array[ offset ] = this.r;
  4238. array[ offset + 1 ] = this.g;
  4239. array[ offset + 2 ] = this.b;
  4240. return array;
  4241. },
  4242. toJSON: function () {
  4243. return this.getHex();
  4244. }
  4245. } );
  4246. /**
  4247. * Uniforms library for shared webgl shaders
  4248. */
  4249. var UniformsLib = {
  4250. common: {
  4251. diffuse: { value: new Color( 0xeeeeee ) },
  4252. opacity: { value: 1.0 },
  4253. map: { value: null },
  4254. uvTransform: { value: new Matrix3() },
  4255. alphaMap: { value: null },
  4256. },
  4257. specularmap: {
  4258. specularMap: { value: null },
  4259. },
  4260. envmap: {
  4261. envMap: { value: null },
  4262. flipEnvMap: { value: - 1 },
  4263. reflectivity: { value: 1.0 },
  4264. refractionRatio: { value: 0.98 },
  4265. maxMipLevel: { value: 0 }
  4266. },
  4267. aomap: {
  4268. aoMap: { value: null },
  4269. aoMapIntensity: { value: 1 }
  4270. },
  4271. lightmap: {
  4272. lightMap: { value: null },
  4273. lightMapIntensity: { value: 1 }
  4274. },
  4275. emissivemap: {
  4276. emissiveMap: { value: null }
  4277. },
  4278. bumpmap: {
  4279. bumpMap: { value: null },
  4280. bumpScale: { value: 1 }
  4281. },
  4282. normalmap: {
  4283. normalMap: { value: null },
  4284. normalScale: { value: new Vector2( 1, 1 ) }
  4285. },
  4286. displacementmap: {
  4287. displacementMap: { value: null },
  4288. displacementScale: { value: 1 },
  4289. displacementBias: { value: 0 }
  4290. },
  4291. roughnessmap: {
  4292. roughnessMap: { value: null }
  4293. },
  4294. metalnessmap: {
  4295. metalnessMap: { value: null }
  4296. },
  4297. gradientmap: {
  4298. gradientMap: { value: null }
  4299. },
  4300. fog: {
  4301. fogDensity: { value: 0.00025 },
  4302. fogNear: { value: 1 },
  4303. fogFar: { value: 2000 },
  4304. fogColor: { value: new Color( 0xffffff ) }
  4305. },
  4306. lights: {
  4307. ambientLightColor: { value: [] },
  4308. directionalLights: { value: [], properties: {
  4309. direction: {},
  4310. color: {},
  4311. shadow: {},
  4312. shadowBias: {},
  4313. shadowRadius: {},
  4314. shadowMapSize: {}
  4315. } },
  4316. directionalShadowMap: { value: [] },
  4317. directionalShadowMatrix: { value: [] },
  4318. spotLights: { value: [], properties: {
  4319. color: {},
  4320. position: {},
  4321. direction: {},
  4322. distance: {},
  4323. coneCos: {},
  4324. penumbraCos: {},
  4325. decay: {},
  4326. shadow: {},
  4327. shadowBias: {},
  4328. shadowRadius: {},
  4329. shadowMapSize: {}
  4330. } },
  4331. spotShadowMap: { value: [] },
  4332. spotShadowMatrix: { value: [] },
  4333. pointLights: { value: [], properties: {
  4334. color: {},
  4335. position: {},
  4336. decay: {},
  4337. distance: {},
  4338. shadow: {},
  4339. shadowBias: {},
  4340. shadowRadius: {},
  4341. shadowMapSize: {},
  4342. shadowCameraNear: {},
  4343. shadowCameraFar: {}
  4344. } },
  4345. pointShadowMap: { value: [] },
  4346. pointShadowMatrix: { value: [] },
  4347. hemisphereLights: { value: [], properties: {
  4348. direction: {},
  4349. skyColor: {},
  4350. groundColor: {}
  4351. } },
  4352. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4353. rectAreaLights: { value: [], properties: {
  4354. color: {},
  4355. position: {},
  4356. width: {},
  4357. height: {}
  4358. } }
  4359. },
  4360. points: {
  4361. diffuse: { value: new Color( 0xeeeeee ) },
  4362. opacity: { value: 1.0 },
  4363. size: { value: 1.0 },
  4364. scale: { value: 1.0 },
  4365. map: { value: null },
  4366. uvTransform: { value: new Matrix3() }
  4367. },
  4368. sprite: {
  4369. diffuse: { value: new Color( 0xeeeeee ) },
  4370. opacity: { value: 1.0 },
  4371. center: { value: new Vector2( 0.5, 0.5 ) },
  4372. rotation: { value: 0.0 },
  4373. map: { value: null },
  4374. uvTransform: { value: new Matrix3() }
  4375. }
  4376. };
  4377. /**
  4378. * @author alteredq / http://alteredqualia.com/
  4379. * @author mrdoob / http://mrdoob.com/
  4380. * @author mikael emtinger / http://gomo.se/
  4381. */
  4382. var ShaderLib = {
  4383. basic: {
  4384. uniforms: mergeUniforms( [
  4385. UniformsLib.common,
  4386. UniformsLib.specularmap,
  4387. UniformsLib.envmap,
  4388. UniformsLib.aomap,
  4389. UniformsLib.lightmap,
  4390. UniformsLib.fog
  4391. ] ),
  4392. vertexShader: ShaderChunk.meshbasic_vert,
  4393. fragmentShader: ShaderChunk.meshbasic_frag
  4394. },
  4395. lambert: {
  4396. uniforms: mergeUniforms( [
  4397. UniformsLib.common,
  4398. UniformsLib.specularmap,
  4399. UniformsLib.envmap,
  4400. UniformsLib.aomap,
  4401. UniformsLib.lightmap,
  4402. UniformsLib.emissivemap,
  4403. UniformsLib.fog,
  4404. UniformsLib.lights,
  4405. {
  4406. emissive: { value: new Color( 0x000000 ) }
  4407. }
  4408. ] ),
  4409. vertexShader: ShaderChunk.meshlambert_vert,
  4410. fragmentShader: ShaderChunk.meshlambert_frag
  4411. },
  4412. phong: {
  4413. uniforms: mergeUniforms( [
  4414. UniformsLib.common,
  4415. UniformsLib.specularmap,
  4416. UniformsLib.envmap,
  4417. UniformsLib.aomap,
  4418. UniformsLib.lightmap,
  4419. UniformsLib.emissivemap,
  4420. UniformsLib.bumpmap,
  4421. UniformsLib.normalmap,
  4422. UniformsLib.displacementmap,
  4423. UniformsLib.gradientmap,
  4424. UniformsLib.fog,
  4425. UniformsLib.lights,
  4426. {
  4427. emissive: { value: new Color( 0x000000 ) },
  4428. specular: { value: new Color( 0x111111 ) },
  4429. shininess: { value: 30 }
  4430. }
  4431. ] ),
  4432. vertexShader: ShaderChunk.meshphong_vert,
  4433. fragmentShader: ShaderChunk.meshphong_frag
  4434. },
  4435. standard: {
  4436. uniforms: mergeUniforms( [
  4437. UniformsLib.common,
  4438. UniformsLib.envmap,
  4439. UniformsLib.aomap,
  4440. UniformsLib.lightmap,
  4441. UniformsLib.emissivemap,
  4442. UniformsLib.bumpmap,
  4443. UniformsLib.normalmap,
  4444. UniformsLib.displacementmap,
  4445. UniformsLib.roughnessmap,
  4446. UniformsLib.metalnessmap,
  4447. UniformsLib.fog,
  4448. UniformsLib.lights,
  4449. {
  4450. emissive: { value: new Color( 0x000000 ) },
  4451. roughness: { value: 0.5 },
  4452. metalness: { value: 0.5 },
  4453. envMapIntensity: { value: 1 } // temporary
  4454. }
  4455. ] ),
  4456. vertexShader: ShaderChunk.meshphysical_vert,
  4457. fragmentShader: ShaderChunk.meshphysical_frag
  4458. },
  4459. matcap: {
  4460. uniforms: mergeUniforms( [
  4461. UniformsLib.common,
  4462. UniformsLib.bumpmap,
  4463. UniformsLib.normalmap,
  4464. UniformsLib.displacementmap,
  4465. UniformsLib.fog,
  4466. {
  4467. matcap: { value: null }
  4468. }
  4469. ] ),
  4470. vertexShader: ShaderChunk.meshmatcap_vert,
  4471. fragmentShader: ShaderChunk.meshmatcap_frag
  4472. },
  4473. points: {
  4474. uniforms: mergeUniforms( [
  4475. UniformsLib.points,
  4476. UniformsLib.fog
  4477. ] ),
  4478. vertexShader: ShaderChunk.points_vert,
  4479. fragmentShader: ShaderChunk.points_frag
  4480. },
  4481. dashed: {
  4482. uniforms: mergeUniforms( [
  4483. UniformsLib.common,
  4484. UniformsLib.fog,
  4485. {
  4486. scale: { value: 1 },
  4487. dashSize: { value: 1 },
  4488. totalSize: { value: 2 }
  4489. }
  4490. ] ),
  4491. vertexShader: ShaderChunk.linedashed_vert,
  4492. fragmentShader: ShaderChunk.linedashed_frag
  4493. },
  4494. depth: {
  4495. uniforms: mergeUniforms( [
  4496. UniformsLib.common,
  4497. UniformsLib.displacementmap
  4498. ] ),
  4499. vertexShader: ShaderChunk.depth_vert,
  4500. fragmentShader: ShaderChunk.depth_frag
  4501. },
  4502. normal: {
  4503. uniforms: mergeUniforms( [
  4504. UniformsLib.common,
  4505. UniformsLib.bumpmap,
  4506. UniformsLib.normalmap,
  4507. UniformsLib.displacementmap,
  4508. {
  4509. opacity: { value: 1.0 }
  4510. }
  4511. ] ),
  4512. vertexShader: ShaderChunk.normal_vert,
  4513. fragmentShader: ShaderChunk.normal_frag
  4514. },
  4515. sprite: {
  4516. uniforms: mergeUniforms( [
  4517. UniformsLib.sprite,
  4518. UniformsLib.fog
  4519. ] ),
  4520. vertexShader: ShaderChunk.sprite_vert,
  4521. fragmentShader: ShaderChunk.sprite_frag
  4522. },
  4523. background: {
  4524. uniforms: {
  4525. uvTransform: { value: new Matrix3() },
  4526. t2D: { value: null },
  4527. },
  4528. vertexShader: ShaderChunk.background_vert,
  4529. fragmentShader: ShaderChunk.background_frag
  4530. },
  4531. /* -------------------------------------------------------------------------
  4532. // Cube map shader
  4533. ------------------------------------------------------------------------- */
  4534. cube: {
  4535. uniforms: {
  4536. tCube: { value: null },
  4537. tFlip: { value: - 1 },
  4538. opacity: { value: 1.0 }
  4539. },
  4540. vertexShader: ShaderChunk.cube_vert,
  4541. fragmentShader: ShaderChunk.cube_frag
  4542. },
  4543. equirect: {
  4544. uniforms: {
  4545. tEquirect: { value: null },
  4546. },
  4547. vertexShader: ShaderChunk.equirect_vert,
  4548. fragmentShader: ShaderChunk.equirect_frag
  4549. },
  4550. distanceRGBA: {
  4551. uniforms: mergeUniforms( [
  4552. UniformsLib.common,
  4553. UniformsLib.displacementmap,
  4554. {
  4555. referencePosition: { value: new Vector3() },
  4556. nearDistance: { value: 1 },
  4557. farDistance: { value: 1000 }
  4558. }
  4559. ] ),
  4560. vertexShader: ShaderChunk.distanceRGBA_vert,
  4561. fragmentShader: ShaderChunk.distanceRGBA_frag
  4562. },
  4563. shadow: {
  4564. uniforms: mergeUniforms( [
  4565. UniformsLib.lights,
  4566. UniformsLib.fog,
  4567. {
  4568. color: { value: new Color( 0x00000 ) },
  4569. opacity: { value: 1.0 }
  4570. },
  4571. ] ),
  4572. vertexShader: ShaderChunk.shadow_vert,
  4573. fragmentShader: ShaderChunk.shadow_frag
  4574. }
  4575. };
  4576. ShaderLib.physical = {
  4577. uniforms: mergeUniforms( [
  4578. ShaderLib.standard.uniforms,
  4579. {
  4580. clearCoat: { value: 0 },
  4581. clearCoatRoughness: { value: 0 }
  4582. }
  4583. ] ),
  4584. vertexShader: ShaderChunk.meshphysical_vert,
  4585. fragmentShader: ShaderChunk.meshphysical_frag
  4586. };
  4587. /**
  4588. * @author mrdoob / http://mrdoob.com/
  4589. */
  4590. function WebGLAnimation() {
  4591. var context = null;
  4592. var isAnimating = false;
  4593. var animationLoop = null;
  4594. function onAnimationFrame( time, frame ) {
  4595. if ( isAnimating === false ) return;
  4596. animationLoop( time, frame );
  4597. context.requestAnimationFrame( onAnimationFrame );
  4598. }
  4599. return {
  4600. start: function () {
  4601. if ( isAnimating === true ) return;
  4602. if ( animationLoop === null ) return;
  4603. context.requestAnimationFrame( onAnimationFrame );
  4604. isAnimating = true;
  4605. },
  4606. stop: function () {
  4607. isAnimating = false;
  4608. },
  4609. setAnimationLoop: function ( callback ) {
  4610. animationLoop = callback;
  4611. },
  4612. setContext: function ( value ) {
  4613. context = value;
  4614. }
  4615. };
  4616. }
  4617. /**
  4618. * @author mrdoob / http://mrdoob.com/
  4619. */
  4620. function WebGLAttributes( gl ) {
  4621. var buffers = new WeakMap();
  4622. function createBuffer( attribute, bufferType ) {
  4623. var array = attribute.array;
  4624. var usage = attribute.dynamic ? 35048 : 35044;
  4625. var buffer = gl.createBuffer();
  4626. gl.bindBuffer( bufferType, buffer );
  4627. gl.bufferData( bufferType, array, usage );
  4628. attribute.onUploadCallback();
  4629. var type = 5126;
  4630. if ( array instanceof Float32Array ) {
  4631. type = 5126;
  4632. } else if ( array instanceof Float64Array ) {
  4633. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4634. } else if ( array instanceof Uint16Array ) {
  4635. type = 5123;
  4636. } else if ( array instanceof Int16Array ) {
  4637. type = 5122;
  4638. } else if ( array instanceof Uint32Array ) {
  4639. type = 5125;
  4640. } else if ( array instanceof Int32Array ) {
  4641. type = 5124;
  4642. } else if ( array instanceof Int8Array ) {
  4643. type = 5120;
  4644. } else if ( array instanceof Uint8Array ) {
  4645. type = 5121;
  4646. }
  4647. return {
  4648. buffer: buffer,
  4649. type: type,
  4650. bytesPerElement: array.BYTES_PER_ELEMENT,
  4651. version: attribute.version
  4652. };
  4653. }
  4654. function updateBuffer( buffer, attribute, bufferType ) {
  4655. var array = attribute.array;
  4656. var updateRange = attribute.updateRange;
  4657. gl.bindBuffer( bufferType, buffer );
  4658. if ( attribute.dynamic === false ) {
  4659. gl.bufferData( bufferType, array, 35044 );
  4660. } else if ( updateRange.count === - 1 ) {
  4661. // Not using update ranges
  4662. gl.bufferSubData( bufferType, 0, array );
  4663. } else if ( updateRange.count === 0 ) {
  4664. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  4665. } else {
  4666. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4667. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4668. updateRange.count = - 1; // reset range
  4669. }
  4670. }
  4671. //
  4672. function get( attribute ) {
  4673. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4674. return buffers.get( attribute );
  4675. }
  4676. function remove( attribute ) {
  4677. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4678. var data = buffers.get( attribute );
  4679. if ( data ) {
  4680. gl.deleteBuffer( data.buffer );
  4681. buffers.delete( attribute );
  4682. }
  4683. }
  4684. function update( attribute, bufferType ) {
  4685. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4686. var data = buffers.get( attribute );
  4687. if ( data === undefined ) {
  4688. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4689. } else if ( data.version < attribute.version ) {
  4690. updateBuffer( data.buffer, attribute, bufferType );
  4691. data.version = attribute.version;
  4692. }
  4693. }
  4694. return {
  4695. get: get,
  4696. remove: remove,
  4697. update: update
  4698. };
  4699. }
  4700. /**
  4701. * @author mrdoob / http://mrdoob.com/
  4702. * @author alteredq / http://alteredqualia.com/
  4703. */
  4704. function Face3( a, b, c, normal, color, materialIndex ) {
  4705. this.a = a;
  4706. this.b = b;
  4707. this.c = c;
  4708. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4709. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4710. this.color = ( color && color.isColor ) ? color : new Color();
  4711. this.vertexColors = Array.isArray( color ) ? color : [];
  4712. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4713. }
  4714. Object.assign( Face3.prototype, {
  4715. clone: function () {
  4716. return new this.constructor().copy( this );
  4717. },
  4718. copy: function ( source ) {
  4719. this.a = source.a;
  4720. this.b = source.b;
  4721. this.c = source.c;
  4722. this.normal.copy( source.normal );
  4723. this.color.copy( source.color );
  4724. this.materialIndex = source.materialIndex;
  4725. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4726. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4727. }
  4728. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4729. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4730. }
  4731. return this;
  4732. }
  4733. } );
  4734. /**
  4735. * @author mrdoob / http://mrdoob.com/
  4736. * @author WestLangley / http://github.com/WestLangley
  4737. * @author bhouston / http://clara.io
  4738. */
  4739. function Euler( x, y, z, order ) {
  4740. this._x = x || 0;
  4741. this._y = y || 0;
  4742. this._z = z || 0;
  4743. this._order = order || Euler.DefaultOrder;
  4744. }
  4745. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4746. Euler.DefaultOrder = 'XYZ';
  4747. Object.defineProperties( Euler.prototype, {
  4748. x: {
  4749. get: function () {
  4750. return this._x;
  4751. },
  4752. set: function ( value ) {
  4753. this._x = value;
  4754. this.onChangeCallback();
  4755. }
  4756. },
  4757. y: {
  4758. get: function () {
  4759. return this._y;
  4760. },
  4761. set: function ( value ) {
  4762. this._y = value;
  4763. this.onChangeCallback();
  4764. }
  4765. },
  4766. z: {
  4767. get: function () {
  4768. return this._z;
  4769. },
  4770. set: function ( value ) {
  4771. this._z = value;
  4772. this.onChangeCallback();
  4773. }
  4774. },
  4775. order: {
  4776. get: function () {
  4777. return this._order;
  4778. },
  4779. set: function ( value ) {
  4780. this._order = value;
  4781. this.onChangeCallback();
  4782. }
  4783. }
  4784. } );
  4785. Object.assign( Euler.prototype, {
  4786. isEuler: true,
  4787. set: function ( x, y, z, order ) {
  4788. this._x = x;
  4789. this._y = y;
  4790. this._z = z;
  4791. this._order = order || this._order;
  4792. this.onChangeCallback();
  4793. return this;
  4794. },
  4795. clone: function () {
  4796. return new this.constructor( this._x, this._y, this._z, this._order );
  4797. },
  4798. copy: function ( euler ) {
  4799. this._x = euler._x;
  4800. this._y = euler._y;
  4801. this._z = euler._z;
  4802. this._order = euler._order;
  4803. this.onChangeCallback();
  4804. return this;
  4805. },
  4806. setFromRotationMatrix: function ( m, order, update ) {
  4807. var clamp = _Math.clamp;
  4808. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4809. var te = m.elements;
  4810. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4811. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4812. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4813. order = order || this._order;
  4814. if ( order === 'XYZ' ) {
  4815. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4816. if ( Math.abs( m13 ) < 0.99999 ) {
  4817. this._x = Math.atan2( - m23, m33 );
  4818. this._z = Math.atan2( - m12, m11 );
  4819. } else {
  4820. this._x = Math.atan2( m32, m22 );
  4821. this._z = 0;
  4822. }
  4823. } else if ( order === 'YXZ' ) {
  4824. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4825. if ( Math.abs( m23 ) < 0.99999 ) {
  4826. this._y = Math.atan2( m13, m33 );
  4827. this._z = Math.atan2( m21, m22 );
  4828. } else {
  4829. this._y = Math.atan2( - m31, m11 );
  4830. this._z = 0;
  4831. }
  4832. } else if ( order === 'ZXY' ) {
  4833. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4834. if ( Math.abs( m32 ) < 0.99999 ) {
  4835. this._y = Math.atan2( - m31, m33 );
  4836. this._z = Math.atan2( - m12, m22 );
  4837. } else {
  4838. this._y = 0;
  4839. this._z = Math.atan2( m21, m11 );
  4840. }
  4841. } else if ( order === 'ZYX' ) {
  4842. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4843. if ( Math.abs( m31 ) < 0.99999 ) {
  4844. this._x = Math.atan2( m32, m33 );
  4845. this._z = Math.atan2( m21, m11 );
  4846. } else {
  4847. this._x = 0;
  4848. this._z = Math.atan2( - m12, m22 );
  4849. }
  4850. } else if ( order === 'YZX' ) {
  4851. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4852. if ( Math.abs( m21 ) < 0.99999 ) {
  4853. this._x = Math.atan2( - m23, m22 );
  4854. this._y = Math.atan2( - m31, m11 );
  4855. } else {
  4856. this._x = 0;
  4857. this._y = Math.atan2( m13, m33 );
  4858. }
  4859. } else if ( order === 'XZY' ) {
  4860. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4861. if ( Math.abs( m12 ) < 0.99999 ) {
  4862. this._x = Math.atan2( m32, m22 );
  4863. this._y = Math.atan2( m13, m11 );
  4864. } else {
  4865. this._x = Math.atan2( - m23, m33 );
  4866. this._y = 0;
  4867. }
  4868. } else {
  4869. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4870. }
  4871. this._order = order;
  4872. if ( update !== false ) this.onChangeCallback();
  4873. return this;
  4874. },
  4875. setFromQuaternion: function () {
  4876. var matrix = new Matrix4();
  4877. return function setFromQuaternion( q, order, update ) {
  4878. matrix.makeRotationFromQuaternion( q );
  4879. return this.setFromRotationMatrix( matrix, order, update );
  4880. };
  4881. }(),
  4882. setFromVector3: function ( v, order ) {
  4883. return this.set( v.x, v.y, v.z, order || this._order );
  4884. },
  4885. reorder: function () {
  4886. // WARNING: this discards revolution information -bhouston
  4887. var q = new Quaternion();
  4888. return function reorder( newOrder ) {
  4889. q.setFromEuler( this );
  4890. return this.setFromQuaternion( q, newOrder );
  4891. };
  4892. }(),
  4893. equals: function ( euler ) {
  4894. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4895. },
  4896. fromArray: function ( array ) {
  4897. this._x = array[ 0 ];
  4898. this._y = array[ 1 ];
  4899. this._z = array[ 2 ];
  4900. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4901. this.onChangeCallback();
  4902. return this;
  4903. },
  4904. toArray: function ( array, offset ) {
  4905. if ( array === undefined ) array = [];
  4906. if ( offset === undefined ) offset = 0;
  4907. array[ offset ] = this._x;
  4908. array[ offset + 1 ] = this._y;
  4909. array[ offset + 2 ] = this._z;
  4910. array[ offset + 3 ] = this._order;
  4911. return array;
  4912. },
  4913. toVector3: function ( optionalResult ) {
  4914. if ( optionalResult ) {
  4915. return optionalResult.set( this._x, this._y, this._z );
  4916. } else {
  4917. return new Vector3( this._x, this._y, this._z );
  4918. }
  4919. },
  4920. onChange: function ( callback ) {
  4921. this.onChangeCallback = callback;
  4922. return this;
  4923. },
  4924. onChangeCallback: function () {}
  4925. } );
  4926. /**
  4927. * @author mrdoob / http://mrdoob.com/
  4928. */
  4929. function Layers() {
  4930. this.mask = 1 | 0;
  4931. }
  4932. Object.assign( Layers.prototype, {
  4933. set: function ( channel ) {
  4934. this.mask = 1 << channel | 0;
  4935. },
  4936. enable: function ( channel ) {
  4937. this.mask |= 1 << channel | 0;
  4938. },
  4939. toggle: function ( channel ) {
  4940. this.mask ^= 1 << channel | 0;
  4941. },
  4942. disable: function ( channel ) {
  4943. this.mask &= ~ ( 1 << channel | 0 );
  4944. },
  4945. test: function ( layers ) {
  4946. return ( this.mask & layers.mask ) !== 0;
  4947. }
  4948. } );
  4949. /**
  4950. * @author mrdoob / http://mrdoob.com/
  4951. * @author mikael emtinger / http://gomo.se/
  4952. * @author alteredq / http://alteredqualia.com/
  4953. * @author WestLangley / http://github.com/WestLangley
  4954. * @author elephantatwork / www.elephantatwork.ch
  4955. */
  4956. var object3DId = 0;
  4957. function Object3D() {
  4958. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4959. this.uuid = _Math.generateUUID();
  4960. this.name = '';
  4961. this.type = 'Object3D';
  4962. this.parent = null;
  4963. this.children = [];
  4964. this.up = Object3D.DefaultUp.clone();
  4965. var position = new Vector3();
  4966. var rotation = new Euler();
  4967. var quaternion = new Quaternion();
  4968. var scale = new Vector3( 1, 1, 1 );
  4969. function onRotationChange() {
  4970. quaternion.setFromEuler( rotation, false );
  4971. }
  4972. function onQuaternionChange() {
  4973. rotation.setFromQuaternion( quaternion, undefined, false );
  4974. }
  4975. rotation.onChange( onRotationChange );
  4976. quaternion.onChange( onQuaternionChange );
  4977. Object.defineProperties( this, {
  4978. position: {
  4979. configurable: true,
  4980. enumerable: true,
  4981. value: position
  4982. },
  4983. rotation: {
  4984. configurable: true,
  4985. enumerable: true,
  4986. value: rotation
  4987. },
  4988. quaternion: {
  4989. configurable: true,
  4990. enumerable: true,
  4991. value: quaternion
  4992. },
  4993. scale: {
  4994. configurable: true,
  4995. enumerable: true,
  4996. value: scale
  4997. },
  4998. modelViewMatrix: {
  4999. value: new Matrix4()
  5000. },
  5001. normalMatrix: {
  5002. value: new Matrix3()
  5003. }
  5004. } );
  5005. this.matrix = new Matrix4();
  5006. this.matrixWorld = new Matrix4();
  5007. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5008. this.matrixWorldNeedsUpdate = false;
  5009. this.layers = new Layers();
  5010. this.visible = true;
  5011. this.castShadow = false;
  5012. this.receiveShadow = false;
  5013. this.frustumCulled = true;
  5014. this.renderOrder = 0;
  5015. this.userData = {};
  5016. }
  5017. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5018. Object3D.DefaultMatrixAutoUpdate = true;
  5019. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5020. constructor: Object3D,
  5021. isObject3D: true,
  5022. onBeforeRender: function () {},
  5023. onAfterRender: function () {},
  5024. applyMatrix: function ( matrix ) {
  5025. this.matrix.multiplyMatrices( matrix, this.matrix );
  5026. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5027. },
  5028. applyQuaternion: function ( q ) {
  5029. this.quaternion.premultiply( q );
  5030. return this;
  5031. },
  5032. setRotationFromAxisAngle: function ( axis, angle ) {
  5033. // assumes axis is normalized
  5034. this.quaternion.setFromAxisAngle( axis, angle );
  5035. },
  5036. setRotationFromEuler: function ( euler ) {
  5037. this.quaternion.setFromEuler( euler, true );
  5038. },
  5039. setRotationFromMatrix: function ( m ) {
  5040. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5041. this.quaternion.setFromRotationMatrix( m );
  5042. },
  5043. setRotationFromQuaternion: function ( q ) {
  5044. // assumes q is normalized
  5045. this.quaternion.copy( q );
  5046. },
  5047. rotateOnAxis: function () {
  5048. // rotate object on axis in object space
  5049. // axis is assumed to be normalized
  5050. var q1 = new Quaternion();
  5051. return function rotateOnAxis( axis, angle ) {
  5052. q1.setFromAxisAngle( axis, angle );
  5053. this.quaternion.multiply( q1 );
  5054. return this;
  5055. };
  5056. }(),
  5057. rotateOnWorldAxis: function () {
  5058. // rotate object on axis in world space
  5059. // axis is assumed to be normalized
  5060. // method assumes no rotated parent
  5061. var q1 = new Quaternion();
  5062. return function rotateOnWorldAxis( axis, angle ) {
  5063. q1.setFromAxisAngle( axis, angle );
  5064. this.quaternion.premultiply( q1 );
  5065. return this;
  5066. };
  5067. }(),
  5068. rotateX: function () {
  5069. var v1 = new Vector3( 1, 0, 0 );
  5070. return function rotateX( angle ) {
  5071. return this.rotateOnAxis( v1, angle );
  5072. };
  5073. }(),
  5074. rotateY: function () {
  5075. var v1 = new Vector3( 0, 1, 0 );
  5076. return function rotateY( angle ) {
  5077. return this.rotateOnAxis( v1, angle );
  5078. };
  5079. }(),
  5080. rotateZ: function () {
  5081. var v1 = new Vector3( 0, 0, 1 );
  5082. return function rotateZ( angle ) {
  5083. return this.rotateOnAxis( v1, angle );
  5084. };
  5085. }(),
  5086. translateOnAxis: function () {
  5087. // translate object by distance along axis in object space
  5088. // axis is assumed to be normalized
  5089. var v1 = new Vector3();
  5090. return function translateOnAxis( axis, distance ) {
  5091. v1.copy( axis ).applyQuaternion( this.quaternion );
  5092. this.position.add( v1.multiplyScalar( distance ) );
  5093. return this;
  5094. };
  5095. }(),
  5096. translateX: function () {
  5097. var v1 = new Vector3( 1, 0, 0 );
  5098. return function translateX( distance ) {
  5099. return this.translateOnAxis( v1, distance );
  5100. };
  5101. }(),
  5102. translateY: function () {
  5103. var v1 = new Vector3( 0, 1, 0 );
  5104. return function translateY( distance ) {
  5105. return this.translateOnAxis( v1, distance );
  5106. };
  5107. }(),
  5108. translateZ: function () {
  5109. var v1 = new Vector3( 0, 0, 1 );
  5110. return function translateZ( distance ) {
  5111. return this.translateOnAxis( v1, distance );
  5112. };
  5113. }(),
  5114. localToWorld: function ( vector ) {
  5115. return vector.applyMatrix4( this.matrixWorld );
  5116. },
  5117. worldToLocal: function () {
  5118. var m1 = new Matrix4();
  5119. return function worldToLocal( vector ) {
  5120. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5121. };
  5122. }(),
  5123. lookAt: function () {
  5124. // This method does not support objects having non-uniformly-scaled parent(s)
  5125. var q1 = new Quaternion();
  5126. var m1 = new Matrix4();
  5127. var target = new Vector3();
  5128. var position = new Vector3();
  5129. return function lookAt( x, y, z ) {
  5130. if ( x.isVector3 ) {
  5131. target.copy( x );
  5132. } else {
  5133. target.set( x, y, z );
  5134. }
  5135. var parent = this.parent;
  5136. this.updateWorldMatrix( true, false );
  5137. position.setFromMatrixPosition( this.matrixWorld );
  5138. if ( this.isCamera || this.isLight ) {
  5139. m1.lookAt( position, target, this.up );
  5140. } else {
  5141. m1.lookAt( target, position, this.up );
  5142. }
  5143. this.quaternion.setFromRotationMatrix( m1 );
  5144. if ( parent ) {
  5145. m1.extractRotation( parent.matrixWorld );
  5146. q1.setFromRotationMatrix( m1 );
  5147. this.quaternion.premultiply( q1.inverse() );
  5148. }
  5149. };
  5150. }(),
  5151. add: function ( object ) {
  5152. if ( arguments.length > 1 ) {
  5153. for ( var i = 0; i < arguments.length; i ++ ) {
  5154. this.add( arguments[ i ] );
  5155. }
  5156. return this;
  5157. }
  5158. if ( object === this ) {
  5159. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5160. return this;
  5161. }
  5162. if ( ( object && object.isObject3D ) ) {
  5163. if ( object.parent !== null ) {
  5164. object.parent.remove( object );
  5165. }
  5166. object.parent = this;
  5167. object.dispatchEvent( { type: 'added' } );
  5168. this.children.push( object );
  5169. } else {
  5170. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5171. }
  5172. return this;
  5173. },
  5174. remove: function ( object ) {
  5175. if ( arguments.length > 1 ) {
  5176. for ( var i = 0; i < arguments.length; i ++ ) {
  5177. this.remove( arguments[ i ] );
  5178. }
  5179. return this;
  5180. }
  5181. var index = this.children.indexOf( object );
  5182. if ( index !== - 1 ) {
  5183. object.parent = null;
  5184. object.dispatchEvent( { type: 'removed' } );
  5185. this.children.splice( index, 1 );
  5186. }
  5187. return this;
  5188. },
  5189. getObjectById: function ( id ) {
  5190. return this.getObjectByProperty( 'id', id );
  5191. },
  5192. getObjectByName: function ( name ) {
  5193. return this.getObjectByProperty( 'name', name );
  5194. },
  5195. getObjectByProperty: function ( name, value ) {
  5196. if ( this[ name ] === value ) return this;
  5197. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5198. var child = this.children[ i ];
  5199. var object = child.getObjectByProperty( name, value );
  5200. if ( object !== undefined ) {
  5201. return object;
  5202. }
  5203. }
  5204. return undefined;
  5205. },
  5206. getWorldPosition: function ( target ) {
  5207. if ( target === undefined ) {
  5208. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5209. target = new Vector3();
  5210. }
  5211. this.updateMatrixWorld( true );
  5212. return target.setFromMatrixPosition( this.matrixWorld );
  5213. },
  5214. getWorldQuaternion: function () {
  5215. var position = new Vector3();
  5216. var scale = new Vector3();
  5217. return function getWorldQuaternion( target ) {
  5218. if ( target === undefined ) {
  5219. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5220. target = new Quaternion();
  5221. }
  5222. this.updateMatrixWorld( true );
  5223. this.matrixWorld.decompose( position, target, scale );
  5224. return target;
  5225. };
  5226. }(),
  5227. getWorldScale: function () {
  5228. var position = new Vector3();
  5229. var quaternion = new Quaternion();
  5230. return function getWorldScale( target ) {
  5231. if ( target === undefined ) {
  5232. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5233. target = new Vector3();
  5234. }
  5235. this.updateMatrixWorld( true );
  5236. this.matrixWorld.decompose( position, quaternion, target );
  5237. return target;
  5238. };
  5239. }(),
  5240. getWorldDirection: function ( target ) {
  5241. if ( target === undefined ) {
  5242. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5243. target = new Vector3();
  5244. }
  5245. this.updateMatrixWorld( true );
  5246. var e = this.matrixWorld.elements;
  5247. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5248. },
  5249. raycast: function () {},
  5250. traverse: function ( callback ) {
  5251. callback( this );
  5252. var children = this.children;
  5253. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5254. children[ i ].traverse( callback );
  5255. }
  5256. },
  5257. traverseVisible: function ( callback ) {
  5258. if ( this.visible === false ) return;
  5259. callback( this );
  5260. var children = this.children;
  5261. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5262. children[ i ].traverseVisible( callback );
  5263. }
  5264. },
  5265. traverseAncestors: function ( callback ) {
  5266. var parent = this.parent;
  5267. if ( parent !== null ) {
  5268. callback( parent );
  5269. parent.traverseAncestors( callback );
  5270. }
  5271. },
  5272. updateMatrix: function () {
  5273. this.matrix.compose( this.position, this.quaternion, this.scale );
  5274. this.matrixWorldNeedsUpdate = true;
  5275. },
  5276. updateMatrixWorld: function ( force ) {
  5277. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5278. if ( this.matrixWorldNeedsUpdate || force ) {
  5279. if ( this.parent === null ) {
  5280. this.matrixWorld.copy( this.matrix );
  5281. } else {
  5282. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5283. }
  5284. this.matrixWorldNeedsUpdate = false;
  5285. force = true;
  5286. }
  5287. // update children
  5288. var children = this.children;
  5289. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5290. children[ i ].updateMatrixWorld( force );
  5291. }
  5292. },
  5293. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5294. var parent = this.parent;
  5295. if ( updateParents === true && parent !== null ) {
  5296. parent.updateWorldMatrix( true, false );
  5297. }
  5298. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5299. if ( this.parent === null ) {
  5300. this.matrixWorld.copy( this.matrix );
  5301. } else {
  5302. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5303. }
  5304. // update children
  5305. if ( updateChildren === true ) {
  5306. var children = this.children;
  5307. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5308. children[ i ].updateWorldMatrix( false, true );
  5309. }
  5310. }
  5311. },
  5312. toJSON: function ( meta ) {
  5313. // meta is a string when called from JSON.stringify
  5314. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5315. var output = {};
  5316. // meta is a hash used to collect geometries, materials.
  5317. // not providing it implies that this is the root object
  5318. // being serialized.
  5319. if ( isRootObject ) {
  5320. // initialize meta obj
  5321. meta = {
  5322. geometries: {},
  5323. materials: {},
  5324. textures: {},
  5325. images: {},
  5326. shapes: {}
  5327. };
  5328. output.metadata = {
  5329. version: 4.5,
  5330. type: 'Object',
  5331. generator: 'Object3D.toJSON'
  5332. };
  5333. }
  5334. // standard Object3D serialization
  5335. var object = {};
  5336. object.uuid = this.uuid;
  5337. object.type = this.type;
  5338. if ( this.name !== '' ) object.name = this.name;
  5339. if ( this.castShadow === true ) object.castShadow = true;
  5340. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5341. if ( this.visible === false ) object.visible = false;
  5342. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5343. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5344. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5345. object.layers = this.layers.mask;
  5346. object.matrix = this.matrix.toArray();
  5347. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5348. // object specific properties
  5349. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  5350. //
  5351. function serialize( library, element ) {
  5352. if ( library[ element.uuid ] === undefined ) {
  5353. library[ element.uuid ] = element.toJSON( meta );
  5354. }
  5355. return element.uuid;
  5356. }
  5357. if ( this.isMesh || this.isLine || this.isPoints ) {
  5358. object.geometry = serialize( meta.geometries, this.geometry );
  5359. var parameters = this.geometry.parameters;
  5360. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5361. var shapes = parameters.shapes;
  5362. if ( Array.isArray( shapes ) ) {
  5363. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5364. var shape = shapes[ i ];
  5365. serialize( meta.shapes, shape );
  5366. }
  5367. } else {
  5368. serialize( meta.shapes, shapes );
  5369. }
  5370. }
  5371. }
  5372. if ( this.material !== undefined ) {
  5373. if ( Array.isArray( this.material ) ) {
  5374. var uuids = [];
  5375. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5376. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5377. }
  5378. object.material = uuids;
  5379. } else {
  5380. object.material = serialize( meta.materials, this.material );
  5381. }
  5382. }
  5383. //
  5384. if ( this.children.length > 0 ) {
  5385. object.children = [];
  5386. for ( var i = 0; i < this.children.length; i ++ ) {
  5387. object.children.push( this.children[ i ].toJSON( meta ).object );
  5388. }
  5389. }
  5390. if ( isRootObject ) {
  5391. var geometries = extractFromCache( meta.geometries );
  5392. var materials = extractFromCache( meta.materials );
  5393. var textures = extractFromCache( meta.textures );
  5394. var images = extractFromCache( meta.images );
  5395. var shapes = extractFromCache( meta.shapes );
  5396. if ( geometries.length > 0 ) output.geometries = geometries;
  5397. if ( materials.length > 0 ) output.materials = materials;
  5398. if ( textures.length > 0 ) output.textures = textures;
  5399. if ( images.length > 0 ) output.images = images;
  5400. if ( shapes.length > 0 ) output.shapes = shapes;
  5401. }
  5402. output.object = object;
  5403. return output;
  5404. // extract data from the cache hash
  5405. // remove metadata on each item
  5406. // and return as array
  5407. function extractFromCache( cache ) {
  5408. var values = [];
  5409. for ( var key in cache ) {
  5410. var data = cache[ key ];
  5411. delete data.metadata;
  5412. values.push( data );
  5413. }
  5414. return values;
  5415. }
  5416. },
  5417. clone: function ( recursive ) {
  5418. return new this.constructor().copy( this, recursive );
  5419. },
  5420. copy: function ( source, recursive ) {
  5421. if ( recursive === undefined ) recursive = true;
  5422. this.name = source.name;
  5423. this.up.copy( source.up );
  5424. this.position.copy( source.position );
  5425. this.quaternion.copy( source.quaternion );
  5426. this.scale.copy( source.scale );
  5427. this.matrix.copy( source.matrix );
  5428. this.matrixWorld.copy( source.matrixWorld );
  5429. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5430. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5431. this.layers.mask = source.layers.mask;
  5432. this.visible = source.visible;
  5433. this.castShadow = source.castShadow;
  5434. this.receiveShadow = source.receiveShadow;
  5435. this.frustumCulled = source.frustumCulled;
  5436. this.renderOrder = source.renderOrder;
  5437. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5438. if ( recursive === true ) {
  5439. for ( var i = 0; i < source.children.length; i ++ ) {
  5440. var child = source.children[ i ];
  5441. this.add( child.clone() );
  5442. }
  5443. }
  5444. return this;
  5445. }
  5446. } );
  5447. /**
  5448. * @author mrdoob / http://mrdoob.com/
  5449. * @author kile / http://kile.stravaganza.org/
  5450. * @author alteredq / http://alteredqualia.com/
  5451. * @author mikael emtinger / http://gomo.se/
  5452. * @author zz85 / http://www.lab4games.net/zz85/blog
  5453. * @author bhouston / http://clara.io
  5454. */
  5455. var geometryId = 0; // Geometry uses even numbers as Id
  5456. function Geometry() {
  5457. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5458. this.uuid = _Math.generateUUID();
  5459. this.name = '';
  5460. this.type = 'Geometry';
  5461. this.vertices = [];
  5462. this.colors = [];
  5463. this.faces = [];
  5464. this.faceVertexUvs = [[]];
  5465. this.morphTargets = [];
  5466. this.morphNormals = [];
  5467. this.skinWeights = [];
  5468. this.skinIndices = [];
  5469. this.lineDistances = [];
  5470. this.boundingBox = null;
  5471. this.boundingSphere = null;
  5472. // update flags
  5473. this.elementsNeedUpdate = false;
  5474. this.verticesNeedUpdate = false;
  5475. this.uvsNeedUpdate = false;
  5476. this.normalsNeedUpdate = false;
  5477. this.colorsNeedUpdate = false;
  5478. this.lineDistancesNeedUpdate = false;
  5479. this.groupsNeedUpdate = false;
  5480. }
  5481. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5482. constructor: Geometry,
  5483. isGeometry: true,
  5484. applyMatrix: function ( matrix ) {
  5485. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5486. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5487. var vertex = this.vertices[ i ];
  5488. vertex.applyMatrix4( matrix );
  5489. }
  5490. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5491. var face = this.faces[ i ];
  5492. face.normal.applyMatrix3( normalMatrix ).normalize();
  5493. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5494. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5495. }
  5496. }
  5497. if ( this.boundingBox !== null ) {
  5498. this.computeBoundingBox();
  5499. }
  5500. if ( this.boundingSphere !== null ) {
  5501. this.computeBoundingSphere();
  5502. }
  5503. this.verticesNeedUpdate = true;
  5504. this.normalsNeedUpdate = true;
  5505. return this;
  5506. },
  5507. rotateX: function () {
  5508. // rotate geometry around world x-axis
  5509. var m1 = new Matrix4();
  5510. return function rotateX( angle ) {
  5511. m1.makeRotationX( angle );
  5512. this.applyMatrix( m1 );
  5513. return this;
  5514. };
  5515. }(),
  5516. rotateY: function () {
  5517. // rotate geometry around world y-axis
  5518. var m1 = new Matrix4();
  5519. return function rotateY( angle ) {
  5520. m1.makeRotationY( angle );
  5521. this.applyMatrix( m1 );
  5522. return this;
  5523. };
  5524. }(),
  5525. rotateZ: function () {
  5526. // rotate geometry around world z-axis
  5527. var m1 = new Matrix4();
  5528. return function rotateZ( angle ) {
  5529. m1.makeRotationZ( angle );
  5530. this.applyMatrix( m1 );
  5531. return this;
  5532. };
  5533. }(),
  5534. translate: function () {
  5535. // translate geometry
  5536. var m1 = new Matrix4();
  5537. return function translate( x, y, z ) {
  5538. m1.makeTranslation( x, y, z );
  5539. this.applyMatrix( m1 );
  5540. return this;
  5541. };
  5542. }(),
  5543. scale: function () {
  5544. // scale geometry
  5545. var m1 = new Matrix4();
  5546. return function scale( x, y, z ) {
  5547. m1.makeScale( x, y, z );
  5548. this.applyMatrix( m1 );
  5549. return this;
  5550. };
  5551. }(),
  5552. lookAt: function () {
  5553. var obj = new Object3D();
  5554. return function lookAt( vector ) {
  5555. obj.lookAt( vector );
  5556. obj.updateMatrix();
  5557. this.applyMatrix( obj.matrix );
  5558. };
  5559. }(),
  5560. fromBufferGeometry: function ( geometry ) {
  5561. var scope = this;
  5562. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5563. var attributes = geometry.attributes;
  5564. var positions = attributes.position.array;
  5565. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5566. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5567. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5568. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5569. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5570. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5571. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5572. if ( colors !== undefined ) {
  5573. scope.colors.push( new Color().fromArray( colors, i ) );
  5574. }
  5575. }
  5576. function addFace( a, b, c, materialIndex ) {
  5577. var vertexColors = ( colors === undefined ) ? [] : [
  5578. scope.colors[ a ].clone(),
  5579. scope.colors[ b ].clone(),
  5580. scope.colors[ c ].clone() ];
  5581. var vertexNormals = ( normals === undefined ) ? [] : [
  5582. new Vector3().fromArray( normals, a * 3 ),
  5583. new Vector3().fromArray( normals, b * 3 ),
  5584. new Vector3().fromArray( normals, c * 3 )
  5585. ];
  5586. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5587. scope.faces.push( face );
  5588. if ( uvs !== undefined ) {
  5589. scope.faceVertexUvs[ 0 ].push( [
  5590. new Vector2().fromArray( uvs, a * 2 ),
  5591. new Vector2().fromArray( uvs, b * 2 ),
  5592. new Vector2().fromArray( uvs, c * 2 )
  5593. ] );
  5594. }
  5595. if ( uvs2 !== undefined ) {
  5596. scope.faceVertexUvs[ 1 ].push( [
  5597. new Vector2().fromArray( uvs2, a * 2 ),
  5598. new Vector2().fromArray( uvs2, b * 2 ),
  5599. new Vector2().fromArray( uvs2, c * 2 )
  5600. ] );
  5601. }
  5602. }
  5603. var groups = geometry.groups;
  5604. if ( groups.length > 0 ) {
  5605. for ( var i = 0; i < groups.length; i ++ ) {
  5606. var group = groups[ i ];
  5607. var start = group.start;
  5608. var count = group.count;
  5609. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5610. if ( indices !== undefined ) {
  5611. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5612. } else {
  5613. addFace( j, j + 1, j + 2, group.materialIndex );
  5614. }
  5615. }
  5616. }
  5617. } else {
  5618. if ( indices !== undefined ) {
  5619. for ( var i = 0; i < indices.length; i += 3 ) {
  5620. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5621. }
  5622. } else {
  5623. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5624. addFace( i, i + 1, i + 2 );
  5625. }
  5626. }
  5627. }
  5628. this.computeFaceNormals();
  5629. if ( geometry.boundingBox !== null ) {
  5630. this.boundingBox = geometry.boundingBox.clone();
  5631. }
  5632. if ( geometry.boundingSphere !== null ) {
  5633. this.boundingSphere = geometry.boundingSphere.clone();
  5634. }
  5635. return this;
  5636. },
  5637. center: function () {
  5638. var offset = new Vector3();
  5639. return function center() {
  5640. this.computeBoundingBox();
  5641. this.boundingBox.getCenter( offset ).negate();
  5642. this.translate( offset.x, offset.y, offset.z );
  5643. return this;
  5644. };
  5645. }(),
  5646. normalize: function () {
  5647. this.computeBoundingSphere();
  5648. var center = this.boundingSphere.center;
  5649. var radius = this.boundingSphere.radius;
  5650. var s = radius === 0 ? 1 : 1.0 / radius;
  5651. var matrix = new Matrix4();
  5652. matrix.set(
  5653. s, 0, 0, - s * center.x,
  5654. 0, s, 0, - s * center.y,
  5655. 0, 0, s, - s * center.z,
  5656. 0, 0, 0, 1
  5657. );
  5658. this.applyMatrix( matrix );
  5659. return this;
  5660. },
  5661. computeFaceNormals: function () {
  5662. var cb = new Vector3(), ab = new Vector3();
  5663. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5664. var face = this.faces[ f ];
  5665. var vA = this.vertices[ face.a ];
  5666. var vB = this.vertices[ face.b ];
  5667. var vC = this.vertices[ face.c ];
  5668. cb.subVectors( vC, vB );
  5669. ab.subVectors( vA, vB );
  5670. cb.cross( ab );
  5671. cb.normalize();
  5672. face.normal.copy( cb );
  5673. }
  5674. },
  5675. computeVertexNormals: function ( areaWeighted ) {
  5676. if ( areaWeighted === undefined ) areaWeighted = true;
  5677. var v, vl, f, fl, face, vertices;
  5678. vertices = new Array( this.vertices.length );
  5679. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5680. vertices[ v ] = new Vector3();
  5681. }
  5682. if ( areaWeighted ) {
  5683. // vertex normals weighted by triangle areas
  5684. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5685. var vA, vB, vC;
  5686. var cb = new Vector3(), ab = new Vector3();
  5687. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5688. face = this.faces[ f ];
  5689. vA = this.vertices[ face.a ];
  5690. vB = this.vertices[ face.b ];
  5691. vC = this.vertices[ face.c ];
  5692. cb.subVectors( vC, vB );
  5693. ab.subVectors( vA, vB );
  5694. cb.cross( ab );
  5695. vertices[ face.a ].add( cb );
  5696. vertices[ face.b ].add( cb );
  5697. vertices[ face.c ].add( cb );
  5698. }
  5699. } else {
  5700. this.computeFaceNormals();
  5701. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5702. face = this.faces[ f ];
  5703. vertices[ face.a ].add( face.normal );
  5704. vertices[ face.b ].add( face.normal );
  5705. vertices[ face.c ].add( face.normal );
  5706. }
  5707. }
  5708. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5709. vertices[ v ].normalize();
  5710. }
  5711. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5712. face = this.faces[ f ];
  5713. var vertexNormals = face.vertexNormals;
  5714. if ( vertexNormals.length === 3 ) {
  5715. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5716. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5717. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5718. } else {
  5719. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5720. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5721. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5722. }
  5723. }
  5724. if ( this.faces.length > 0 ) {
  5725. this.normalsNeedUpdate = true;
  5726. }
  5727. },
  5728. computeFlatVertexNormals: function () {
  5729. var f, fl, face;
  5730. this.computeFaceNormals();
  5731. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5732. face = this.faces[ f ];
  5733. var vertexNormals = face.vertexNormals;
  5734. if ( vertexNormals.length === 3 ) {
  5735. vertexNormals[ 0 ].copy( face.normal );
  5736. vertexNormals[ 1 ].copy( face.normal );
  5737. vertexNormals[ 2 ].copy( face.normal );
  5738. } else {
  5739. vertexNormals[ 0 ] = face.normal.clone();
  5740. vertexNormals[ 1 ] = face.normal.clone();
  5741. vertexNormals[ 2 ] = face.normal.clone();
  5742. }
  5743. }
  5744. if ( this.faces.length > 0 ) {
  5745. this.normalsNeedUpdate = true;
  5746. }
  5747. },
  5748. computeMorphNormals: function () {
  5749. var i, il, f, fl, face;
  5750. // save original normals
  5751. // - create temp variables on first access
  5752. // otherwise just copy (for faster repeated calls)
  5753. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5754. face = this.faces[ f ];
  5755. if ( ! face.__originalFaceNormal ) {
  5756. face.__originalFaceNormal = face.normal.clone();
  5757. } else {
  5758. face.__originalFaceNormal.copy( face.normal );
  5759. }
  5760. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5761. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5762. if ( ! face.__originalVertexNormals[ i ] ) {
  5763. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5764. } else {
  5765. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5766. }
  5767. }
  5768. }
  5769. // use temp geometry to compute face and vertex normals for each morph
  5770. var tmpGeo = new Geometry();
  5771. tmpGeo.faces = this.faces;
  5772. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5773. // create on first access
  5774. if ( ! this.morphNormals[ i ] ) {
  5775. this.morphNormals[ i ] = {};
  5776. this.morphNormals[ i ].faceNormals = [];
  5777. this.morphNormals[ i ].vertexNormals = [];
  5778. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5779. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5780. var faceNormal, vertexNormals;
  5781. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5782. faceNormal = new Vector3();
  5783. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5784. dstNormalsFace.push( faceNormal );
  5785. dstNormalsVertex.push( vertexNormals );
  5786. }
  5787. }
  5788. var morphNormals = this.morphNormals[ i ];
  5789. // set vertices to morph target
  5790. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5791. // compute morph normals
  5792. tmpGeo.computeFaceNormals();
  5793. tmpGeo.computeVertexNormals();
  5794. // store morph normals
  5795. var faceNormal, vertexNormals;
  5796. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5797. face = this.faces[ f ];
  5798. faceNormal = morphNormals.faceNormals[ f ];
  5799. vertexNormals = morphNormals.vertexNormals[ f ];
  5800. faceNormal.copy( face.normal );
  5801. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5802. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5803. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5804. }
  5805. }
  5806. // restore original normals
  5807. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5808. face = this.faces[ f ];
  5809. face.normal = face.__originalFaceNormal;
  5810. face.vertexNormals = face.__originalVertexNormals;
  5811. }
  5812. },
  5813. computeBoundingBox: function () {
  5814. if ( this.boundingBox === null ) {
  5815. this.boundingBox = new Box3();
  5816. }
  5817. this.boundingBox.setFromPoints( this.vertices );
  5818. },
  5819. computeBoundingSphere: function () {
  5820. if ( this.boundingSphere === null ) {
  5821. this.boundingSphere = new Sphere();
  5822. }
  5823. this.boundingSphere.setFromPoints( this.vertices );
  5824. },
  5825. merge: function ( geometry, matrix, materialIndexOffset ) {
  5826. if ( ! ( geometry && geometry.isGeometry ) ) {
  5827. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5828. return;
  5829. }
  5830. var normalMatrix,
  5831. vertexOffset = this.vertices.length,
  5832. vertices1 = this.vertices,
  5833. vertices2 = geometry.vertices,
  5834. faces1 = this.faces,
  5835. faces2 = geometry.faces,
  5836. uvs1 = this.faceVertexUvs[ 0 ],
  5837. uvs2 = geometry.faceVertexUvs[ 0 ],
  5838. colors1 = this.colors,
  5839. colors2 = geometry.colors;
  5840. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5841. if ( matrix !== undefined ) {
  5842. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5843. }
  5844. // vertices
  5845. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5846. var vertex = vertices2[ i ];
  5847. var vertexCopy = vertex.clone();
  5848. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5849. vertices1.push( vertexCopy );
  5850. }
  5851. // colors
  5852. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5853. colors1.push( colors2[ i ].clone() );
  5854. }
  5855. // faces
  5856. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5857. var face = faces2[ i ], faceCopy, normal, color,
  5858. faceVertexNormals = face.vertexNormals,
  5859. faceVertexColors = face.vertexColors;
  5860. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5861. faceCopy.normal.copy( face.normal );
  5862. if ( normalMatrix !== undefined ) {
  5863. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5864. }
  5865. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5866. normal = faceVertexNormals[ j ].clone();
  5867. if ( normalMatrix !== undefined ) {
  5868. normal.applyMatrix3( normalMatrix ).normalize();
  5869. }
  5870. faceCopy.vertexNormals.push( normal );
  5871. }
  5872. faceCopy.color.copy( face.color );
  5873. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5874. color = faceVertexColors[ j ];
  5875. faceCopy.vertexColors.push( color.clone() );
  5876. }
  5877. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5878. faces1.push( faceCopy );
  5879. }
  5880. // uvs
  5881. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5882. var uv = uvs2[ i ], uvCopy = [];
  5883. if ( uv === undefined ) {
  5884. continue;
  5885. }
  5886. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5887. uvCopy.push( uv[ j ].clone() );
  5888. }
  5889. uvs1.push( uvCopy );
  5890. }
  5891. },
  5892. mergeMesh: function ( mesh ) {
  5893. if ( ! ( mesh && mesh.isMesh ) ) {
  5894. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5895. return;
  5896. }
  5897. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5898. this.merge( mesh.geometry, mesh.matrix );
  5899. },
  5900. /*
  5901. * Checks for duplicate vertices with hashmap.
  5902. * Duplicated vertices are removed
  5903. * and faces' vertices are updated.
  5904. */
  5905. mergeVertices: function () {
  5906. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5907. var unique = [], changes = [];
  5908. var v, key;
  5909. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5910. var precision = Math.pow( 10, precisionPoints );
  5911. var i, il, face;
  5912. var indices, j, jl;
  5913. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5914. v = this.vertices[ i ];
  5915. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5916. if ( verticesMap[ key ] === undefined ) {
  5917. verticesMap[ key ] = i;
  5918. unique.push( this.vertices[ i ] );
  5919. changes[ i ] = unique.length - 1;
  5920. } else {
  5921. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5922. changes[ i ] = changes[ verticesMap[ key ] ];
  5923. }
  5924. }
  5925. // if faces are completely degenerate after merging vertices, we
  5926. // have to remove them from the geometry.
  5927. var faceIndicesToRemove = [];
  5928. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5929. face = this.faces[ i ];
  5930. face.a = changes[ face.a ];
  5931. face.b = changes[ face.b ];
  5932. face.c = changes[ face.c ];
  5933. indices = [ face.a, face.b, face.c ];
  5934. // if any duplicate vertices are found in a Face3
  5935. // we have to remove the face as nothing can be saved
  5936. for ( var n = 0; n < 3; n ++ ) {
  5937. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5938. faceIndicesToRemove.push( i );
  5939. break;
  5940. }
  5941. }
  5942. }
  5943. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5944. var idx = faceIndicesToRemove[ i ];
  5945. this.faces.splice( idx, 1 );
  5946. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5947. this.faceVertexUvs[ j ].splice( idx, 1 );
  5948. }
  5949. }
  5950. // Use unique set of vertices
  5951. var diff = this.vertices.length - unique.length;
  5952. this.vertices = unique;
  5953. return diff;
  5954. },
  5955. setFromPoints: function ( points ) {
  5956. this.vertices = [];
  5957. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5958. var point = points[ i ];
  5959. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5960. }
  5961. return this;
  5962. },
  5963. sortFacesByMaterialIndex: function () {
  5964. var faces = this.faces;
  5965. var length = faces.length;
  5966. // tag faces
  5967. for ( var i = 0; i < length; i ++ ) {
  5968. faces[ i ]._id = i;
  5969. }
  5970. // sort faces
  5971. function materialIndexSort( a, b ) {
  5972. return a.materialIndex - b.materialIndex;
  5973. }
  5974. faces.sort( materialIndexSort );
  5975. // sort uvs
  5976. var uvs1 = this.faceVertexUvs[ 0 ];
  5977. var uvs2 = this.faceVertexUvs[ 1 ];
  5978. var newUvs1, newUvs2;
  5979. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5980. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5981. for ( var i = 0; i < length; i ++ ) {
  5982. var id = faces[ i ]._id;
  5983. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5984. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5985. }
  5986. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5987. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5988. },
  5989. toJSON: function () {
  5990. var data = {
  5991. metadata: {
  5992. version: 4.5,
  5993. type: 'Geometry',
  5994. generator: 'Geometry.toJSON'
  5995. }
  5996. };
  5997. // standard Geometry serialization
  5998. data.uuid = this.uuid;
  5999. data.type = this.type;
  6000. if ( this.name !== '' ) data.name = this.name;
  6001. if ( this.parameters !== undefined ) {
  6002. var parameters = this.parameters;
  6003. for ( var key in parameters ) {
  6004. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6005. }
  6006. return data;
  6007. }
  6008. var vertices = [];
  6009. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6010. var vertex = this.vertices[ i ];
  6011. vertices.push( vertex.x, vertex.y, vertex.z );
  6012. }
  6013. var faces = [];
  6014. var normals = [];
  6015. var normalsHash = {};
  6016. var colors = [];
  6017. var colorsHash = {};
  6018. var uvs = [];
  6019. var uvsHash = {};
  6020. for ( var i = 0; i < this.faces.length; i ++ ) {
  6021. var face = this.faces[ i ];
  6022. var hasMaterial = true;
  6023. var hasFaceUv = false; // deprecated
  6024. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6025. var hasFaceNormal = face.normal.length() > 0;
  6026. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6027. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6028. var hasFaceVertexColor = face.vertexColors.length > 0;
  6029. var faceType = 0;
  6030. faceType = setBit( faceType, 0, 0 ); // isQuad
  6031. faceType = setBit( faceType, 1, hasMaterial );
  6032. faceType = setBit( faceType, 2, hasFaceUv );
  6033. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6034. faceType = setBit( faceType, 4, hasFaceNormal );
  6035. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6036. faceType = setBit( faceType, 6, hasFaceColor );
  6037. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6038. faces.push( faceType );
  6039. faces.push( face.a, face.b, face.c );
  6040. faces.push( face.materialIndex );
  6041. if ( hasFaceVertexUv ) {
  6042. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6043. faces.push(
  6044. getUvIndex( faceVertexUvs[ 0 ] ),
  6045. getUvIndex( faceVertexUvs[ 1 ] ),
  6046. getUvIndex( faceVertexUvs[ 2 ] )
  6047. );
  6048. }
  6049. if ( hasFaceNormal ) {
  6050. faces.push( getNormalIndex( face.normal ) );
  6051. }
  6052. if ( hasFaceVertexNormal ) {
  6053. var vertexNormals = face.vertexNormals;
  6054. faces.push(
  6055. getNormalIndex( vertexNormals[ 0 ] ),
  6056. getNormalIndex( vertexNormals[ 1 ] ),
  6057. getNormalIndex( vertexNormals[ 2 ] )
  6058. );
  6059. }
  6060. if ( hasFaceColor ) {
  6061. faces.push( getColorIndex( face.color ) );
  6062. }
  6063. if ( hasFaceVertexColor ) {
  6064. var vertexColors = face.vertexColors;
  6065. faces.push(
  6066. getColorIndex( vertexColors[ 0 ] ),
  6067. getColorIndex( vertexColors[ 1 ] ),
  6068. getColorIndex( vertexColors[ 2 ] )
  6069. );
  6070. }
  6071. }
  6072. function setBit( value, position, enabled ) {
  6073. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6074. }
  6075. function getNormalIndex( normal ) {
  6076. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6077. if ( normalsHash[ hash ] !== undefined ) {
  6078. return normalsHash[ hash ];
  6079. }
  6080. normalsHash[ hash ] = normals.length / 3;
  6081. normals.push( normal.x, normal.y, normal.z );
  6082. return normalsHash[ hash ];
  6083. }
  6084. function getColorIndex( color ) {
  6085. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6086. if ( colorsHash[ hash ] !== undefined ) {
  6087. return colorsHash[ hash ];
  6088. }
  6089. colorsHash[ hash ] = colors.length;
  6090. colors.push( color.getHex() );
  6091. return colorsHash[ hash ];
  6092. }
  6093. function getUvIndex( uv ) {
  6094. var hash = uv.x.toString() + uv.y.toString();
  6095. if ( uvsHash[ hash ] !== undefined ) {
  6096. return uvsHash[ hash ];
  6097. }
  6098. uvsHash[ hash ] = uvs.length / 2;
  6099. uvs.push( uv.x, uv.y );
  6100. return uvsHash[ hash ];
  6101. }
  6102. data.data = {};
  6103. data.data.vertices = vertices;
  6104. data.data.normals = normals;
  6105. if ( colors.length > 0 ) data.data.colors = colors;
  6106. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6107. data.data.faces = faces;
  6108. return data;
  6109. },
  6110. clone: function () {
  6111. /*
  6112. // Handle primitives
  6113. var parameters = this.parameters;
  6114. if ( parameters !== undefined ) {
  6115. var values = [];
  6116. for ( var key in parameters ) {
  6117. values.push( parameters[ key ] );
  6118. }
  6119. var geometry = Object.create( this.constructor.prototype );
  6120. this.constructor.apply( geometry, values );
  6121. return geometry;
  6122. }
  6123. return new this.constructor().copy( this );
  6124. */
  6125. return new Geometry().copy( this );
  6126. },
  6127. copy: function ( source ) {
  6128. var i, il, j, jl, k, kl;
  6129. // reset
  6130. this.vertices = [];
  6131. this.colors = [];
  6132. this.faces = [];
  6133. this.faceVertexUvs = [[]];
  6134. this.morphTargets = [];
  6135. this.morphNormals = [];
  6136. this.skinWeights = [];
  6137. this.skinIndices = [];
  6138. this.lineDistances = [];
  6139. this.boundingBox = null;
  6140. this.boundingSphere = null;
  6141. // name
  6142. this.name = source.name;
  6143. // vertices
  6144. var vertices = source.vertices;
  6145. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6146. this.vertices.push( vertices[ i ].clone() );
  6147. }
  6148. // colors
  6149. var colors = source.colors;
  6150. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6151. this.colors.push( colors[ i ].clone() );
  6152. }
  6153. // faces
  6154. var faces = source.faces;
  6155. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6156. this.faces.push( faces[ i ].clone() );
  6157. }
  6158. // face vertex uvs
  6159. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6160. var faceVertexUvs = source.faceVertexUvs[ i ];
  6161. if ( this.faceVertexUvs[ i ] === undefined ) {
  6162. this.faceVertexUvs[ i ] = [];
  6163. }
  6164. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6165. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6166. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6167. var uv = uvs[ k ];
  6168. uvsCopy.push( uv.clone() );
  6169. }
  6170. this.faceVertexUvs[ i ].push( uvsCopy );
  6171. }
  6172. }
  6173. // morph targets
  6174. var morphTargets = source.morphTargets;
  6175. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6176. var morphTarget = {};
  6177. morphTarget.name = morphTargets[ i ].name;
  6178. // vertices
  6179. if ( morphTargets[ i ].vertices !== undefined ) {
  6180. morphTarget.vertices = [];
  6181. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6182. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6183. }
  6184. }
  6185. // normals
  6186. if ( morphTargets[ i ].normals !== undefined ) {
  6187. morphTarget.normals = [];
  6188. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6189. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6190. }
  6191. }
  6192. this.morphTargets.push( morphTarget );
  6193. }
  6194. // morph normals
  6195. var morphNormals = source.morphNormals;
  6196. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6197. var morphNormal = {};
  6198. // vertex normals
  6199. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6200. morphNormal.vertexNormals = [];
  6201. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6202. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6203. var destVertexNormal = {};
  6204. destVertexNormal.a = srcVertexNormal.a.clone();
  6205. destVertexNormal.b = srcVertexNormal.b.clone();
  6206. destVertexNormal.c = srcVertexNormal.c.clone();
  6207. morphNormal.vertexNormals.push( destVertexNormal );
  6208. }
  6209. }
  6210. // face normals
  6211. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6212. morphNormal.faceNormals = [];
  6213. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6214. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6215. }
  6216. }
  6217. this.morphNormals.push( morphNormal );
  6218. }
  6219. // skin weights
  6220. var skinWeights = source.skinWeights;
  6221. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6222. this.skinWeights.push( skinWeights[ i ].clone() );
  6223. }
  6224. // skin indices
  6225. var skinIndices = source.skinIndices;
  6226. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6227. this.skinIndices.push( skinIndices[ i ].clone() );
  6228. }
  6229. // line distances
  6230. var lineDistances = source.lineDistances;
  6231. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6232. this.lineDistances.push( lineDistances[ i ] );
  6233. }
  6234. // bounding box
  6235. var boundingBox = source.boundingBox;
  6236. if ( boundingBox !== null ) {
  6237. this.boundingBox = boundingBox.clone();
  6238. }
  6239. // bounding sphere
  6240. var boundingSphere = source.boundingSphere;
  6241. if ( boundingSphere !== null ) {
  6242. this.boundingSphere = boundingSphere.clone();
  6243. }
  6244. // update flags
  6245. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6246. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6247. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6248. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6249. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6250. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6251. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6252. return this;
  6253. },
  6254. dispose: function () {
  6255. this.dispatchEvent( { type: 'dispose' } );
  6256. }
  6257. } );
  6258. /**
  6259. * @author mrdoob / http://mrdoob.com/
  6260. */
  6261. function BufferAttribute( array, itemSize, normalized ) {
  6262. if ( Array.isArray( array ) ) {
  6263. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6264. }
  6265. this.name = '';
  6266. this.array = array;
  6267. this.itemSize = itemSize;
  6268. this.count = array !== undefined ? array.length / itemSize : 0;
  6269. this.normalized = normalized === true;
  6270. this.dynamic = false;
  6271. this.updateRange = { offset: 0, count: - 1 };
  6272. this.version = 0;
  6273. }
  6274. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6275. set: function ( value ) {
  6276. if ( value === true ) this.version ++;
  6277. }
  6278. } );
  6279. Object.assign( BufferAttribute.prototype, {
  6280. isBufferAttribute: true,
  6281. onUploadCallback: function () {},
  6282. setArray: function ( array ) {
  6283. if ( Array.isArray( array ) ) {
  6284. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6285. }
  6286. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6287. this.array = array;
  6288. return this;
  6289. },
  6290. setDynamic: function ( value ) {
  6291. this.dynamic = value;
  6292. return this;
  6293. },
  6294. copy: function ( source ) {
  6295. this.name = source.name;
  6296. this.array = new source.array.constructor( source.array );
  6297. this.itemSize = source.itemSize;
  6298. this.count = source.count;
  6299. this.normalized = source.normalized;
  6300. this.dynamic = source.dynamic;
  6301. return this;
  6302. },
  6303. copyAt: function ( index1, attribute, index2 ) {
  6304. index1 *= this.itemSize;
  6305. index2 *= attribute.itemSize;
  6306. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6307. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6308. }
  6309. return this;
  6310. },
  6311. copyArray: function ( array ) {
  6312. this.array.set( array );
  6313. return this;
  6314. },
  6315. copyColorsArray: function ( colors ) {
  6316. var array = this.array, offset = 0;
  6317. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6318. var color = colors[ i ];
  6319. if ( color === undefined ) {
  6320. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6321. color = new Color();
  6322. }
  6323. array[ offset ++ ] = color.r;
  6324. array[ offset ++ ] = color.g;
  6325. array[ offset ++ ] = color.b;
  6326. }
  6327. return this;
  6328. },
  6329. copyVector2sArray: function ( vectors ) {
  6330. var array = this.array, offset = 0;
  6331. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6332. var vector = vectors[ i ];
  6333. if ( vector === undefined ) {
  6334. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6335. vector = new Vector2();
  6336. }
  6337. array[ offset ++ ] = vector.x;
  6338. array[ offset ++ ] = vector.y;
  6339. }
  6340. return this;
  6341. },
  6342. copyVector3sArray: function ( vectors ) {
  6343. var array = this.array, offset = 0;
  6344. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6345. var vector = vectors[ i ];
  6346. if ( vector === undefined ) {
  6347. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6348. vector = new Vector3();
  6349. }
  6350. array[ offset ++ ] = vector.x;
  6351. array[ offset ++ ] = vector.y;
  6352. array[ offset ++ ] = vector.z;
  6353. }
  6354. return this;
  6355. },
  6356. copyVector4sArray: function ( vectors ) {
  6357. var array = this.array, offset = 0;
  6358. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6359. var vector = vectors[ i ];
  6360. if ( vector === undefined ) {
  6361. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6362. vector = new Vector4();
  6363. }
  6364. array[ offset ++ ] = vector.x;
  6365. array[ offset ++ ] = vector.y;
  6366. array[ offset ++ ] = vector.z;
  6367. array[ offset ++ ] = vector.w;
  6368. }
  6369. return this;
  6370. },
  6371. set: function ( value, offset ) {
  6372. if ( offset === undefined ) offset = 0;
  6373. this.array.set( value, offset );
  6374. return this;
  6375. },
  6376. getX: function ( index ) {
  6377. return this.array[ index * this.itemSize ];
  6378. },
  6379. setX: function ( index, x ) {
  6380. this.array[ index * this.itemSize ] = x;
  6381. return this;
  6382. },
  6383. getY: function ( index ) {
  6384. return this.array[ index * this.itemSize + 1 ];
  6385. },
  6386. setY: function ( index, y ) {
  6387. this.array[ index * this.itemSize + 1 ] = y;
  6388. return this;
  6389. },
  6390. getZ: function ( index ) {
  6391. return this.array[ index * this.itemSize + 2 ];
  6392. },
  6393. setZ: function ( index, z ) {
  6394. this.array[ index * this.itemSize + 2 ] = z;
  6395. return this;
  6396. },
  6397. getW: function ( index ) {
  6398. return this.array[ index * this.itemSize + 3 ];
  6399. },
  6400. setW: function ( index, w ) {
  6401. this.array[ index * this.itemSize + 3 ] = w;
  6402. return this;
  6403. },
  6404. setXY: function ( index, x, y ) {
  6405. index *= this.itemSize;
  6406. this.array[ index + 0 ] = x;
  6407. this.array[ index + 1 ] = y;
  6408. return this;
  6409. },
  6410. setXYZ: function ( index, x, y, z ) {
  6411. index *= this.itemSize;
  6412. this.array[ index + 0 ] = x;
  6413. this.array[ index + 1 ] = y;
  6414. this.array[ index + 2 ] = z;
  6415. return this;
  6416. },
  6417. setXYZW: function ( index, x, y, z, w ) {
  6418. index *= this.itemSize;
  6419. this.array[ index + 0 ] = x;
  6420. this.array[ index + 1 ] = y;
  6421. this.array[ index + 2 ] = z;
  6422. this.array[ index + 3 ] = w;
  6423. return this;
  6424. },
  6425. onUpload: function ( callback ) {
  6426. this.onUploadCallback = callback;
  6427. return this;
  6428. },
  6429. clone: function () {
  6430. return new this.constructor( this.array, this.itemSize ).copy( this );
  6431. }
  6432. } );
  6433. //
  6434. function Int8BufferAttribute( array, itemSize, normalized ) {
  6435. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6436. }
  6437. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6438. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6439. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6440. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6441. }
  6442. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6443. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6444. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6445. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6446. }
  6447. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6448. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6449. function Int16BufferAttribute( array, itemSize, normalized ) {
  6450. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6451. }
  6452. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6453. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6454. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6455. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6456. }
  6457. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6458. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6459. function Int32BufferAttribute( array, itemSize, normalized ) {
  6460. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6461. }
  6462. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6463. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6464. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6465. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6466. }
  6467. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6468. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6469. function Float32BufferAttribute( array, itemSize, normalized ) {
  6470. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6471. }
  6472. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6473. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6474. function Float64BufferAttribute( array, itemSize, normalized ) {
  6475. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6476. }
  6477. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6478. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6479. /**
  6480. * @author mrdoob / http://mrdoob.com/
  6481. */
  6482. function DirectGeometry() {
  6483. this.vertices = [];
  6484. this.normals = [];
  6485. this.colors = [];
  6486. this.uvs = [];
  6487. this.uvs2 = [];
  6488. this.groups = [];
  6489. this.morphTargets = {};
  6490. this.skinWeights = [];
  6491. this.skinIndices = [];
  6492. // this.lineDistances = [];
  6493. this.boundingBox = null;
  6494. this.boundingSphere = null;
  6495. // update flags
  6496. this.verticesNeedUpdate = false;
  6497. this.normalsNeedUpdate = false;
  6498. this.colorsNeedUpdate = false;
  6499. this.uvsNeedUpdate = false;
  6500. this.groupsNeedUpdate = false;
  6501. }
  6502. Object.assign( DirectGeometry.prototype, {
  6503. computeGroups: function ( geometry ) {
  6504. var group;
  6505. var groups = [];
  6506. var materialIndex = undefined;
  6507. var faces = geometry.faces;
  6508. for ( var i = 0; i < faces.length; i ++ ) {
  6509. var face = faces[ i ];
  6510. // materials
  6511. if ( face.materialIndex !== materialIndex ) {
  6512. materialIndex = face.materialIndex;
  6513. if ( group !== undefined ) {
  6514. group.count = ( i * 3 ) - group.start;
  6515. groups.push( group );
  6516. }
  6517. group = {
  6518. start: i * 3,
  6519. materialIndex: materialIndex
  6520. };
  6521. }
  6522. }
  6523. if ( group !== undefined ) {
  6524. group.count = ( i * 3 ) - group.start;
  6525. groups.push( group );
  6526. }
  6527. this.groups = groups;
  6528. },
  6529. fromGeometry: function ( geometry ) {
  6530. var faces = geometry.faces;
  6531. var vertices = geometry.vertices;
  6532. var faceVertexUvs = geometry.faceVertexUvs;
  6533. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6534. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6535. // morphs
  6536. var morphTargets = geometry.morphTargets;
  6537. var morphTargetsLength = morphTargets.length;
  6538. var morphTargetsPosition;
  6539. if ( morphTargetsLength > 0 ) {
  6540. morphTargetsPosition = [];
  6541. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6542. morphTargetsPosition[ i ] = {
  6543. name: morphTargets[ i ].name,
  6544. data: []
  6545. };
  6546. }
  6547. this.morphTargets.position = morphTargetsPosition;
  6548. }
  6549. var morphNormals = geometry.morphNormals;
  6550. var morphNormalsLength = morphNormals.length;
  6551. var morphTargetsNormal;
  6552. if ( morphNormalsLength > 0 ) {
  6553. morphTargetsNormal = [];
  6554. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6555. morphTargetsNormal[ i ] = {
  6556. name: morphNormals[ i ].name,
  6557. data: []
  6558. };
  6559. }
  6560. this.morphTargets.normal = morphTargetsNormal;
  6561. }
  6562. // skins
  6563. var skinIndices = geometry.skinIndices;
  6564. var skinWeights = geometry.skinWeights;
  6565. var hasSkinIndices = skinIndices.length === vertices.length;
  6566. var hasSkinWeights = skinWeights.length === vertices.length;
  6567. //
  6568. if ( vertices.length > 0 && faces.length === 0 ) {
  6569. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6570. }
  6571. for ( var i = 0; i < faces.length; i ++ ) {
  6572. var face = faces[ i ];
  6573. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6574. var vertexNormals = face.vertexNormals;
  6575. if ( vertexNormals.length === 3 ) {
  6576. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6577. } else {
  6578. var normal = face.normal;
  6579. this.normals.push( normal, normal, normal );
  6580. }
  6581. var vertexColors = face.vertexColors;
  6582. if ( vertexColors.length === 3 ) {
  6583. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6584. } else {
  6585. var color = face.color;
  6586. this.colors.push( color, color, color );
  6587. }
  6588. if ( hasFaceVertexUv === true ) {
  6589. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6590. if ( vertexUvs !== undefined ) {
  6591. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6592. } else {
  6593. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6594. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6595. }
  6596. }
  6597. if ( hasFaceVertexUv2 === true ) {
  6598. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6599. if ( vertexUvs !== undefined ) {
  6600. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6601. } else {
  6602. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6603. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6604. }
  6605. }
  6606. // morphs
  6607. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6608. var morphTarget = morphTargets[ j ].vertices;
  6609. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6610. }
  6611. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6612. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6613. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6614. }
  6615. // skins
  6616. if ( hasSkinIndices ) {
  6617. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6618. }
  6619. if ( hasSkinWeights ) {
  6620. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6621. }
  6622. }
  6623. this.computeGroups( geometry );
  6624. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6625. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6626. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6627. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6628. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6629. return this;
  6630. }
  6631. } );
  6632. /**
  6633. * @author mrdoob / http://mrdoob.com/
  6634. */
  6635. function arrayMax( array ) {
  6636. if ( array.length === 0 ) return - Infinity;
  6637. var max = array[ 0 ];
  6638. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6639. if ( array[ i ] > max ) max = array[ i ];
  6640. }
  6641. return max;
  6642. }
  6643. /**
  6644. * @author alteredq / http://alteredqualia.com/
  6645. * @author mrdoob / http://mrdoob.com/
  6646. */
  6647. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6648. function BufferGeometry() {
  6649. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6650. this.uuid = _Math.generateUUID();
  6651. this.name = '';
  6652. this.type = 'BufferGeometry';
  6653. this.index = null;
  6654. this.attributes = {};
  6655. this.morphAttributes = {};
  6656. this.groups = [];
  6657. this.boundingBox = null;
  6658. this.boundingSphere = null;
  6659. this.drawRange = { start: 0, count: Infinity };
  6660. this.userData = {};
  6661. }
  6662. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6663. constructor: BufferGeometry,
  6664. isBufferGeometry: true,
  6665. getIndex: function () {
  6666. return this.index;
  6667. },
  6668. setIndex: function ( index ) {
  6669. if ( Array.isArray( index ) ) {
  6670. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6671. } else {
  6672. this.index = index;
  6673. }
  6674. },
  6675. addAttribute: function ( name, attribute ) {
  6676. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6677. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6678. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6679. }
  6680. if ( name === 'index' ) {
  6681. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6682. this.setIndex( attribute );
  6683. return this;
  6684. }
  6685. this.attributes[ name ] = attribute;
  6686. return this;
  6687. },
  6688. getAttribute: function ( name ) {
  6689. return this.attributes[ name ];
  6690. },
  6691. removeAttribute: function ( name ) {
  6692. delete this.attributes[ name ];
  6693. return this;
  6694. },
  6695. addGroup: function ( start, count, materialIndex ) {
  6696. this.groups.push( {
  6697. start: start,
  6698. count: count,
  6699. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6700. } );
  6701. },
  6702. clearGroups: function () {
  6703. this.groups = [];
  6704. },
  6705. setDrawRange: function ( start, count ) {
  6706. this.drawRange.start = start;
  6707. this.drawRange.count = count;
  6708. },
  6709. applyMatrix: function ( matrix ) {
  6710. var position = this.attributes.position;
  6711. if ( position !== undefined ) {
  6712. matrix.applyToBufferAttribute( position );
  6713. position.needsUpdate = true;
  6714. }
  6715. var normal = this.attributes.normal;
  6716. if ( normal !== undefined ) {
  6717. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6718. normalMatrix.applyToBufferAttribute( normal );
  6719. normal.needsUpdate = true;
  6720. }
  6721. var tangent = this.attributes.tangent;
  6722. if ( tangent !== undefined ) {
  6723. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6724. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  6725. normalMatrix.applyToBufferAttribute( tangent );
  6726. tangent.needsUpdate = true;
  6727. }
  6728. if ( this.boundingBox !== null ) {
  6729. this.computeBoundingBox();
  6730. }
  6731. if ( this.boundingSphere !== null ) {
  6732. this.computeBoundingSphere();
  6733. }
  6734. return this;
  6735. },
  6736. rotateX: function () {
  6737. // rotate geometry around world x-axis
  6738. var m1 = new Matrix4();
  6739. return function rotateX( angle ) {
  6740. m1.makeRotationX( angle );
  6741. this.applyMatrix( m1 );
  6742. return this;
  6743. };
  6744. }(),
  6745. rotateY: function () {
  6746. // rotate geometry around world y-axis
  6747. var m1 = new Matrix4();
  6748. return function rotateY( angle ) {
  6749. m1.makeRotationY( angle );
  6750. this.applyMatrix( m1 );
  6751. return this;
  6752. };
  6753. }(),
  6754. rotateZ: function () {
  6755. // rotate geometry around world z-axis
  6756. var m1 = new Matrix4();
  6757. return function rotateZ( angle ) {
  6758. m1.makeRotationZ( angle );
  6759. this.applyMatrix( m1 );
  6760. return this;
  6761. };
  6762. }(),
  6763. translate: function () {
  6764. // translate geometry
  6765. var m1 = new Matrix4();
  6766. return function translate( x, y, z ) {
  6767. m1.makeTranslation( x, y, z );
  6768. this.applyMatrix( m1 );
  6769. return this;
  6770. };
  6771. }(),
  6772. scale: function () {
  6773. // scale geometry
  6774. var m1 = new Matrix4();
  6775. return function scale( x, y, z ) {
  6776. m1.makeScale( x, y, z );
  6777. this.applyMatrix( m1 );
  6778. return this;
  6779. };
  6780. }(),
  6781. lookAt: function () {
  6782. var obj = new Object3D();
  6783. return function lookAt( vector ) {
  6784. obj.lookAt( vector );
  6785. obj.updateMatrix();
  6786. this.applyMatrix( obj.matrix );
  6787. };
  6788. }(),
  6789. center: function () {
  6790. var offset = new Vector3();
  6791. return function center() {
  6792. this.computeBoundingBox();
  6793. this.boundingBox.getCenter( offset ).negate();
  6794. this.translate( offset.x, offset.y, offset.z );
  6795. return this;
  6796. };
  6797. }(),
  6798. setFromObject: function ( object ) {
  6799. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6800. var geometry = object.geometry;
  6801. if ( object.isPoints || object.isLine ) {
  6802. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6803. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6804. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6805. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6806. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6807. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6808. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6809. }
  6810. if ( geometry.boundingSphere !== null ) {
  6811. this.boundingSphere = geometry.boundingSphere.clone();
  6812. }
  6813. if ( geometry.boundingBox !== null ) {
  6814. this.boundingBox = geometry.boundingBox.clone();
  6815. }
  6816. } else if ( object.isMesh ) {
  6817. if ( geometry && geometry.isGeometry ) {
  6818. this.fromGeometry( geometry );
  6819. }
  6820. }
  6821. return this;
  6822. },
  6823. setFromPoints: function ( points ) {
  6824. var position = [];
  6825. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6826. var point = points[ i ];
  6827. position.push( point.x, point.y, point.z || 0 );
  6828. }
  6829. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6830. return this;
  6831. },
  6832. updateFromObject: function ( object ) {
  6833. var geometry = object.geometry;
  6834. if ( object.isMesh ) {
  6835. var direct = geometry.__directGeometry;
  6836. if ( geometry.elementsNeedUpdate === true ) {
  6837. direct = undefined;
  6838. geometry.elementsNeedUpdate = false;
  6839. }
  6840. if ( direct === undefined ) {
  6841. return this.fromGeometry( geometry );
  6842. }
  6843. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6844. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6845. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6846. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6847. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6848. geometry.verticesNeedUpdate = false;
  6849. geometry.normalsNeedUpdate = false;
  6850. geometry.colorsNeedUpdate = false;
  6851. geometry.uvsNeedUpdate = false;
  6852. geometry.groupsNeedUpdate = false;
  6853. geometry = direct;
  6854. }
  6855. var attribute;
  6856. if ( geometry.verticesNeedUpdate === true ) {
  6857. attribute = this.attributes.position;
  6858. if ( attribute !== undefined ) {
  6859. attribute.copyVector3sArray( geometry.vertices );
  6860. attribute.needsUpdate = true;
  6861. }
  6862. geometry.verticesNeedUpdate = false;
  6863. }
  6864. if ( geometry.normalsNeedUpdate === true ) {
  6865. attribute = this.attributes.normal;
  6866. if ( attribute !== undefined ) {
  6867. attribute.copyVector3sArray( geometry.normals );
  6868. attribute.needsUpdate = true;
  6869. }
  6870. geometry.normalsNeedUpdate = false;
  6871. }
  6872. if ( geometry.colorsNeedUpdate === true ) {
  6873. attribute = this.attributes.color;
  6874. if ( attribute !== undefined ) {
  6875. attribute.copyColorsArray( geometry.colors );
  6876. attribute.needsUpdate = true;
  6877. }
  6878. geometry.colorsNeedUpdate = false;
  6879. }
  6880. if ( geometry.uvsNeedUpdate ) {
  6881. attribute = this.attributes.uv;
  6882. if ( attribute !== undefined ) {
  6883. attribute.copyVector2sArray( geometry.uvs );
  6884. attribute.needsUpdate = true;
  6885. }
  6886. geometry.uvsNeedUpdate = false;
  6887. }
  6888. if ( geometry.lineDistancesNeedUpdate ) {
  6889. attribute = this.attributes.lineDistance;
  6890. if ( attribute !== undefined ) {
  6891. attribute.copyArray( geometry.lineDistances );
  6892. attribute.needsUpdate = true;
  6893. }
  6894. geometry.lineDistancesNeedUpdate = false;
  6895. }
  6896. if ( geometry.groupsNeedUpdate ) {
  6897. geometry.computeGroups( object.geometry );
  6898. this.groups = geometry.groups;
  6899. geometry.groupsNeedUpdate = false;
  6900. }
  6901. return this;
  6902. },
  6903. fromGeometry: function ( geometry ) {
  6904. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6905. return this.fromDirectGeometry( geometry.__directGeometry );
  6906. },
  6907. fromDirectGeometry: function ( geometry ) {
  6908. var positions = new Float32Array( geometry.vertices.length * 3 );
  6909. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6910. if ( geometry.normals.length > 0 ) {
  6911. var normals = new Float32Array( geometry.normals.length * 3 );
  6912. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6913. }
  6914. if ( geometry.colors.length > 0 ) {
  6915. var colors = new Float32Array( geometry.colors.length * 3 );
  6916. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6917. }
  6918. if ( geometry.uvs.length > 0 ) {
  6919. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6920. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6921. }
  6922. if ( geometry.uvs2.length > 0 ) {
  6923. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6924. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6925. }
  6926. // groups
  6927. this.groups = geometry.groups;
  6928. // morphs
  6929. for ( var name in geometry.morphTargets ) {
  6930. var array = [];
  6931. var morphTargets = geometry.morphTargets[ name ];
  6932. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6933. var morphTarget = morphTargets[ i ];
  6934. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6935. attribute.name = morphTarget.name;
  6936. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6937. }
  6938. this.morphAttributes[ name ] = array;
  6939. }
  6940. // skinning
  6941. if ( geometry.skinIndices.length > 0 ) {
  6942. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6943. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6944. }
  6945. if ( geometry.skinWeights.length > 0 ) {
  6946. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6947. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6948. }
  6949. //
  6950. if ( geometry.boundingSphere !== null ) {
  6951. this.boundingSphere = geometry.boundingSphere.clone();
  6952. }
  6953. if ( geometry.boundingBox !== null ) {
  6954. this.boundingBox = geometry.boundingBox.clone();
  6955. }
  6956. return this;
  6957. },
  6958. computeBoundingBox: function () {
  6959. var box = new Box3();
  6960. return function computeBoundingBox() {
  6961. if ( this.boundingBox === null ) {
  6962. this.boundingBox = new Box3();
  6963. }
  6964. var position = this.attributes.position;
  6965. var morphAttributesPosition = this.morphAttributes.position;
  6966. if ( position !== undefined ) {
  6967. this.boundingBox.setFromBufferAttribute( position );
  6968. // process morph attributes if present
  6969. if ( morphAttributesPosition ) {
  6970. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6971. var morphAttribute = morphAttributesPosition[ i ];
  6972. box.setFromBufferAttribute( morphAttribute );
  6973. this.boundingBox.expandByPoint( box.min );
  6974. this.boundingBox.expandByPoint( box.max );
  6975. }
  6976. }
  6977. } else {
  6978. this.boundingBox.makeEmpty();
  6979. }
  6980. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6981. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6982. }
  6983. };
  6984. }(),
  6985. computeBoundingSphere: function () {
  6986. var box = new Box3();
  6987. var boxMorphTargets = new Box3();
  6988. var vector = new Vector3();
  6989. return function computeBoundingSphere() {
  6990. if ( this.boundingSphere === null ) {
  6991. this.boundingSphere = new Sphere();
  6992. }
  6993. var position = this.attributes.position;
  6994. var morphAttributesPosition = this.morphAttributes.position;
  6995. if ( position ) {
  6996. // first, find the center of the bounding sphere
  6997. var center = this.boundingSphere.center;
  6998. box.setFromBufferAttribute( position );
  6999. // process morph attributes if present
  7000. if ( morphAttributesPosition ) {
  7001. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  7002. var morphAttribute = morphAttributesPosition[ i ];
  7003. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  7004. box.expandByPoint( boxMorphTargets.min );
  7005. box.expandByPoint( boxMorphTargets.max );
  7006. }
  7007. }
  7008. box.getCenter( center );
  7009. // second, try to find a boundingSphere with a radius smaller than the
  7010. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7011. var maxRadiusSq = 0;
  7012. for ( var i = 0, il = position.count; i < il; i ++ ) {
  7013. vector.fromBufferAttribute( position, i );
  7014. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7015. }
  7016. // process morph attributes if present
  7017. if ( morphAttributesPosition ) {
  7018. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  7019. var morphAttribute = morphAttributesPosition[ i ];
  7020. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  7021. vector.fromBufferAttribute( morphAttribute, i );
  7022. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7023. }
  7024. }
  7025. }
  7026. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  7027. if ( isNaN( this.boundingSphere.radius ) ) {
  7028. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  7029. }
  7030. }
  7031. };
  7032. }(),
  7033. computeFaceNormals: function () {
  7034. // backwards compatibility
  7035. },
  7036. computeVertexNormals: function () {
  7037. var index = this.index;
  7038. var attributes = this.attributes;
  7039. if ( attributes.position ) {
  7040. var positions = attributes.position.array;
  7041. if ( attributes.normal === undefined ) {
  7042. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7043. } else {
  7044. // reset existing normals to zero
  7045. var array = attributes.normal.array;
  7046. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7047. array[ i ] = 0;
  7048. }
  7049. }
  7050. var normals = attributes.normal.array;
  7051. var vA, vB, vC;
  7052. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7053. var cb = new Vector3(), ab = new Vector3();
  7054. // indexed elements
  7055. if ( index ) {
  7056. var indices = index.array;
  7057. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7058. vA = indices[ i + 0 ] * 3;
  7059. vB = indices[ i + 1 ] * 3;
  7060. vC = indices[ i + 2 ] * 3;
  7061. pA.fromArray( positions, vA );
  7062. pB.fromArray( positions, vB );
  7063. pC.fromArray( positions, vC );
  7064. cb.subVectors( pC, pB );
  7065. ab.subVectors( pA, pB );
  7066. cb.cross( ab );
  7067. normals[ vA ] += cb.x;
  7068. normals[ vA + 1 ] += cb.y;
  7069. normals[ vA + 2 ] += cb.z;
  7070. normals[ vB ] += cb.x;
  7071. normals[ vB + 1 ] += cb.y;
  7072. normals[ vB + 2 ] += cb.z;
  7073. normals[ vC ] += cb.x;
  7074. normals[ vC + 1 ] += cb.y;
  7075. normals[ vC + 2 ] += cb.z;
  7076. }
  7077. } else {
  7078. // non-indexed elements (unconnected triangle soup)
  7079. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7080. pA.fromArray( positions, i );
  7081. pB.fromArray( positions, i + 3 );
  7082. pC.fromArray( positions, i + 6 );
  7083. cb.subVectors( pC, pB );
  7084. ab.subVectors( pA, pB );
  7085. cb.cross( ab );
  7086. normals[ i ] = cb.x;
  7087. normals[ i + 1 ] = cb.y;
  7088. normals[ i + 2 ] = cb.z;
  7089. normals[ i + 3 ] = cb.x;
  7090. normals[ i + 4 ] = cb.y;
  7091. normals[ i + 5 ] = cb.z;
  7092. normals[ i + 6 ] = cb.x;
  7093. normals[ i + 7 ] = cb.y;
  7094. normals[ i + 8 ] = cb.z;
  7095. }
  7096. }
  7097. this.normalizeNormals();
  7098. attributes.normal.needsUpdate = true;
  7099. }
  7100. },
  7101. merge: function ( geometry, offset ) {
  7102. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7103. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7104. return;
  7105. }
  7106. if ( offset === undefined ) {
  7107. offset = 0;
  7108. console.warn(
  7109. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7110. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7111. );
  7112. }
  7113. var attributes = this.attributes;
  7114. for ( var key in attributes ) {
  7115. if ( geometry.attributes[ key ] === undefined ) continue;
  7116. var attribute1 = attributes[ key ];
  7117. var attributeArray1 = attribute1.array;
  7118. var attribute2 = geometry.attributes[ key ];
  7119. var attributeArray2 = attribute2.array;
  7120. var attributeSize = attribute2.itemSize;
  7121. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7122. attributeArray1[ j ] = attributeArray2[ i ];
  7123. }
  7124. }
  7125. return this;
  7126. },
  7127. normalizeNormals: function () {
  7128. var vector = new Vector3();
  7129. return function normalizeNormals() {
  7130. var normals = this.attributes.normal;
  7131. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7132. vector.x = normals.getX( i );
  7133. vector.y = normals.getY( i );
  7134. vector.z = normals.getZ( i );
  7135. vector.normalize();
  7136. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7137. }
  7138. };
  7139. }(),
  7140. toNonIndexed: function () {
  7141. function convertBufferAttribute( attribute, indices ) {
  7142. var array = attribute.array;
  7143. var itemSize = attribute.itemSize;
  7144. var array2 = new array.constructor( indices.length * itemSize );
  7145. var index = 0, index2 = 0;
  7146. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7147. index = indices[ i ] * itemSize;
  7148. for ( var j = 0; j < itemSize; j ++ ) {
  7149. array2[ index2 ++ ] = array[ index ++ ];
  7150. }
  7151. }
  7152. return new BufferAttribute( array2, itemSize );
  7153. }
  7154. //
  7155. if ( this.index === null ) {
  7156. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7157. return this;
  7158. }
  7159. var geometry2 = new BufferGeometry();
  7160. var indices = this.index.array;
  7161. var attributes = this.attributes;
  7162. // attributes
  7163. for ( var name in attributes ) {
  7164. var attribute = attributes[ name ];
  7165. var newAttribute = convertBufferAttribute( attribute, indices );
  7166. geometry2.addAttribute( name, newAttribute );
  7167. }
  7168. // morph attributes
  7169. var morphAttributes = this.morphAttributes;
  7170. for ( name in morphAttributes ) {
  7171. var morphArray = [];
  7172. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7173. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  7174. var attribute = morphAttribute[ i ];
  7175. var newAttribute = convertBufferAttribute( attribute, indices );
  7176. morphArray.push( newAttribute );
  7177. }
  7178. geometry2.morphAttributes[ name ] = morphArray;
  7179. }
  7180. // groups
  7181. var groups = this.groups;
  7182. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7183. var group = groups[ i ];
  7184. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7185. }
  7186. return geometry2;
  7187. },
  7188. toJSON: function () {
  7189. var data = {
  7190. metadata: {
  7191. version: 4.5,
  7192. type: 'BufferGeometry',
  7193. generator: 'BufferGeometry.toJSON'
  7194. }
  7195. };
  7196. // standard BufferGeometry serialization
  7197. data.uuid = this.uuid;
  7198. data.type = this.type;
  7199. if ( this.name !== '' ) data.name = this.name;
  7200. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7201. if ( this.parameters !== undefined ) {
  7202. var parameters = this.parameters;
  7203. for ( var key in parameters ) {
  7204. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7205. }
  7206. return data;
  7207. }
  7208. data.data = { attributes: {} };
  7209. var index = this.index;
  7210. if ( index !== null ) {
  7211. data.data.index = {
  7212. type: index.array.constructor.name,
  7213. array: Array.prototype.slice.call( index.array )
  7214. };
  7215. }
  7216. var attributes = this.attributes;
  7217. for ( var key in attributes ) {
  7218. var attribute = attributes[ key ];
  7219. var attributeData = {
  7220. itemSize: attribute.itemSize,
  7221. type: attribute.array.constructor.name,
  7222. array: Array.prototype.slice.call( attribute.array ),
  7223. normalized: attribute.normalized
  7224. };
  7225. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7226. data.data.attributes[ key ] = attributeData;
  7227. }
  7228. var morphAttributes = {};
  7229. var hasMorphAttributes = false;
  7230. for ( var key in this.morphAttributes ) {
  7231. var attributeArray = this.morphAttributes[ key ];
  7232. var array = [];
  7233. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  7234. var attribute = attributeArray[ i ];
  7235. var attributeData = {
  7236. itemSize: attribute.itemSize,
  7237. type: attribute.array.constructor.name,
  7238. array: Array.prototype.slice.call( attribute.array ),
  7239. normalized: attribute.normalized
  7240. };
  7241. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7242. array.push( attributeData );
  7243. }
  7244. if ( array.length > 0 ) {
  7245. morphAttributes[ key ] = array;
  7246. hasMorphAttributes = true;
  7247. }
  7248. }
  7249. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  7250. var groups = this.groups;
  7251. if ( groups.length > 0 ) {
  7252. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7253. }
  7254. var boundingSphere = this.boundingSphere;
  7255. if ( boundingSphere !== null ) {
  7256. data.data.boundingSphere = {
  7257. center: boundingSphere.center.toArray(),
  7258. radius: boundingSphere.radius
  7259. };
  7260. }
  7261. return data;
  7262. },
  7263. clone: function () {
  7264. /*
  7265. // Handle primitives
  7266. var parameters = this.parameters;
  7267. if ( parameters !== undefined ) {
  7268. var values = [];
  7269. for ( var key in parameters ) {
  7270. values.push( parameters[ key ] );
  7271. }
  7272. var geometry = Object.create( this.constructor.prototype );
  7273. this.constructor.apply( geometry, values );
  7274. return geometry;
  7275. }
  7276. return new this.constructor().copy( this );
  7277. */
  7278. return new BufferGeometry().copy( this );
  7279. },
  7280. copy: function ( source ) {
  7281. var name, i, l;
  7282. // reset
  7283. this.index = null;
  7284. this.attributes = {};
  7285. this.morphAttributes = {};
  7286. this.groups = [];
  7287. this.boundingBox = null;
  7288. this.boundingSphere = null;
  7289. // name
  7290. this.name = source.name;
  7291. // index
  7292. var index = source.index;
  7293. if ( index !== null ) {
  7294. this.setIndex( index.clone() );
  7295. }
  7296. // attributes
  7297. var attributes = source.attributes;
  7298. for ( name in attributes ) {
  7299. var attribute = attributes[ name ];
  7300. this.addAttribute( name, attribute.clone() );
  7301. }
  7302. // morph attributes
  7303. var morphAttributes = source.morphAttributes;
  7304. for ( name in morphAttributes ) {
  7305. var array = [];
  7306. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7307. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7308. array.push( morphAttribute[ i ].clone() );
  7309. }
  7310. this.morphAttributes[ name ] = array;
  7311. }
  7312. // groups
  7313. var groups = source.groups;
  7314. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7315. var group = groups[ i ];
  7316. this.addGroup( group.start, group.count, group.materialIndex );
  7317. }
  7318. // bounding box
  7319. var boundingBox = source.boundingBox;
  7320. if ( boundingBox !== null ) {
  7321. this.boundingBox = boundingBox.clone();
  7322. }
  7323. // bounding sphere
  7324. var boundingSphere = source.boundingSphere;
  7325. if ( boundingSphere !== null ) {
  7326. this.boundingSphere = boundingSphere.clone();
  7327. }
  7328. // draw range
  7329. this.drawRange.start = source.drawRange.start;
  7330. this.drawRange.count = source.drawRange.count;
  7331. // user data
  7332. this.userData = source.userData;
  7333. return this;
  7334. },
  7335. dispose: function () {
  7336. this.dispatchEvent( { type: 'dispose' } );
  7337. }
  7338. } );
  7339. /**
  7340. * @author mrdoob / http://mrdoob.com/
  7341. * @author Mugen87 / https://github.com/Mugen87
  7342. */
  7343. // BoxGeometry
  7344. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7345. Geometry.call( this );
  7346. this.type = 'BoxGeometry';
  7347. this.parameters = {
  7348. width: width,
  7349. height: height,
  7350. depth: depth,
  7351. widthSegments: widthSegments,
  7352. heightSegments: heightSegments,
  7353. depthSegments: depthSegments
  7354. };
  7355. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7356. this.mergeVertices();
  7357. }
  7358. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7359. BoxGeometry.prototype.constructor = BoxGeometry;
  7360. // BoxBufferGeometry
  7361. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7362. BufferGeometry.call( this );
  7363. this.type = 'BoxBufferGeometry';
  7364. this.parameters = {
  7365. width: width,
  7366. height: height,
  7367. depth: depth,
  7368. widthSegments: widthSegments,
  7369. heightSegments: heightSegments,
  7370. depthSegments: depthSegments
  7371. };
  7372. var scope = this;
  7373. width = width || 1;
  7374. height = height || 1;
  7375. depth = depth || 1;
  7376. // segments
  7377. widthSegments = Math.floor( widthSegments ) || 1;
  7378. heightSegments = Math.floor( heightSegments ) || 1;
  7379. depthSegments = Math.floor( depthSegments ) || 1;
  7380. // buffers
  7381. var indices = [];
  7382. var vertices = [];
  7383. var normals = [];
  7384. var uvs = [];
  7385. // helper variables
  7386. var numberOfVertices = 0;
  7387. var groupStart = 0;
  7388. // build each side of the box geometry
  7389. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7390. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7391. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7392. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7393. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7394. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7395. // build geometry
  7396. this.setIndex( indices );
  7397. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7398. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7399. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7400. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7401. var segmentWidth = width / gridX;
  7402. var segmentHeight = height / gridY;
  7403. var widthHalf = width / 2;
  7404. var heightHalf = height / 2;
  7405. var depthHalf = depth / 2;
  7406. var gridX1 = gridX + 1;
  7407. var gridY1 = gridY + 1;
  7408. var vertexCounter = 0;
  7409. var groupCount = 0;
  7410. var ix, iy;
  7411. var vector = new Vector3();
  7412. // generate vertices, normals and uvs
  7413. for ( iy = 0; iy < gridY1; iy ++ ) {
  7414. var y = iy * segmentHeight - heightHalf;
  7415. for ( ix = 0; ix < gridX1; ix ++ ) {
  7416. var x = ix * segmentWidth - widthHalf;
  7417. // set values to correct vector component
  7418. vector[ u ] = x * udir;
  7419. vector[ v ] = y * vdir;
  7420. vector[ w ] = depthHalf;
  7421. // now apply vector to vertex buffer
  7422. vertices.push( vector.x, vector.y, vector.z );
  7423. // set values to correct vector component
  7424. vector[ u ] = 0;
  7425. vector[ v ] = 0;
  7426. vector[ w ] = depth > 0 ? 1 : - 1;
  7427. // now apply vector to normal buffer
  7428. normals.push( vector.x, vector.y, vector.z );
  7429. // uvs
  7430. uvs.push( ix / gridX );
  7431. uvs.push( 1 - ( iy / gridY ) );
  7432. // counters
  7433. vertexCounter += 1;
  7434. }
  7435. }
  7436. // indices
  7437. // 1. you need three indices to draw a single face
  7438. // 2. a single segment consists of two faces
  7439. // 3. so we need to generate six (2*3) indices per segment
  7440. for ( iy = 0; iy < gridY; iy ++ ) {
  7441. for ( ix = 0; ix < gridX; ix ++ ) {
  7442. var a = numberOfVertices + ix + gridX1 * iy;
  7443. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7444. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7445. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7446. // faces
  7447. indices.push( a, b, d );
  7448. indices.push( b, c, d );
  7449. // increase counter
  7450. groupCount += 6;
  7451. }
  7452. }
  7453. // add a group to the geometry. this will ensure multi material support
  7454. scope.addGroup( groupStart, groupCount, materialIndex );
  7455. // calculate new start value for groups
  7456. groupStart += groupCount;
  7457. // update total number of vertices
  7458. numberOfVertices += vertexCounter;
  7459. }
  7460. }
  7461. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7462. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7463. /**
  7464. * @author mrdoob / http://mrdoob.com/
  7465. * @author Mugen87 / https://github.com/Mugen87
  7466. */
  7467. // PlaneGeometry
  7468. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7469. Geometry.call( this );
  7470. this.type = 'PlaneGeometry';
  7471. this.parameters = {
  7472. width: width,
  7473. height: height,
  7474. widthSegments: widthSegments,
  7475. heightSegments: heightSegments
  7476. };
  7477. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7478. this.mergeVertices();
  7479. }
  7480. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7481. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7482. // PlaneBufferGeometry
  7483. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7484. BufferGeometry.call( this );
  7485. this.type = 'PlaneBufferGeometry';
  7486. this.parameters = {
  7487. width: width,
  7488. height: height,
  7489. widthSegments: widthSegments,
  7490. heightSegments: heightSegments
  7491. };
  7492. width = width || 1;
  7493. height = height || 1;
  7494. var width_half = width / 2;
  7495. var height_half = height / 2;
  7496. var gridX = Math.floor( widthSegments ) || 1;
  7497. var gridY = Math.floor( heightSegments ) || 1;
  7498. var gridX1 = gridX + 1;
  7499. var gridY1 = gridY + 1;
  7500. var segment_width = width / gridX;
  7501. var segment_height = height / gridY;
  7502. var ix, iy;
  7503. // buffers
  7504. var indices = [];
  7505. var vertices = [];
  7506. var normals = [];
  7507. var uvs = [];
  7508. // generate vertices, normals and uvs
  7509. for ( iy = 0; iy < gridY1; iy ++ ) {
  7510. var y = iy * segment_height - height_half;
  7511. for ( ix = 0; ix < gridX1; ix ++ ) {
  7512. var x = ix * segment_width - width_half;
  7513. vertices.push( x, - y, 0 );
  7514. normals.push( 0, 0, 1 );
  7515. uvs.push( ix / gridX );
  7516. uvs.push( 1 - ( iy / gridY ) );
  7517. }
  7518. }
  7519. // indices
  7520. for ( iy = 0; iy < gridY; iy ++ ) {
  7521. for ( ix = 0; ix < gridX; ix ++ ) {
  7522. var a = ix + gridX1 * iy;
  7523. var b = ix + gridX1 * ( iy + 1 );
  7524. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7525. var d = ( ix + 1 ) + gridX1 * iy;
  7526. // faces
  7527. indices.push( a, b, d );
  7528. indices.push( b, c, d );
  7529. }
  7530. }
  7531. // build geometry
  7532. this.setIndex( indices );
  7533. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7534. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7535. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7536. }
  7537. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7538. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7539. /**
  7540. * @author mrdoob / http://mrdoob.com/
  7541. * @author alteredq / http://alteredqualia.com/
  7542. */
  7543. var materialId = 0;
  7544. function Material() {
  7545. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7546. this.uuid = _Math.generateUUID();
  7547. this.name = '';
  7548. this.type = 'Material';
  7549. this.fog = true;
  7550. this.lights = true;
  7551. this.blending = NormalBlending;
  7552. this.side = FrontSide;
  7553. this.flatShading = false;
  7554. this.vertexTangents = false;
  7555. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7556. this.opacity = 1;
  7557. this.transparent = false;
  7558. this.blendSrc = SrcAlphaFactor;
  7559. this.blendDst = OneMinusSrcAlphaFactor;
  7560. this.blendEquation = AddEquation;
  7561. this.blendSrcAlpha = null;
  7562. this.blendDstAlpha = null;
  7563. this.blendEquationAlpha = null;
  7564. this.depthFunc = LessEqualDepth;
  7565. this.depthTest = true;
  7566. this.depthWrite = true;
  7567. this.clippingPlanes = null;
  7568. this.clipIntersection = false;
  7569. this.clipShadows = false;
  7570. this.shadowSide = null;
  7571. this.colorWrite = true;
  7572. this.precision = null; // override the renderer's default precision for this material
  7573. this.polygonOffset = false;
  7574. this.polygonOffsetFactor = 0;
  7575. this.polygonOffsetUnits = 0;
  7576. this.dithering = false;
  7577. this.alphaTest = 0;
  7578. this.premultipliedAlpha = false;
  7579. this.visible = true;
  7580. this.userData = {};
  7581. this.needsUpdate = true;
  7582. }
  7583. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7584. constructor: Material,
  7585. isMaterial: true,
  7586. onBeforeCompile: function () {},
  7587. setValues: function ( values ) {
  7588. if ( values === undefined ) return;
  7589. for ( var key in values ) {
  7590. var newValue = values[ key ];
  7591. if ( newValue === undefined ) {
  7592. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7593. continue;
  7594. }
  7595. // for backward compatability if shading is set in the constructor
  7596. if ( key === 'shading' ) {
  7597. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7598. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7599. continue;
  7600. }
  7601. var currentValue = this[ key ];
  7602. if ( currentValue === undefined ) {
  7603. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7604. continue;
  7605. }
  7606. if ( currentValue && currentValue.isColor ) {
  7607. currentValue.set( newValue );
  7608. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7609. currentValue.copy( newValue );
  7610. } else {
  7611. this[ key ] = newValue;
  7612. }
  7613. }
  7614. },
  7615. toJSON: function ( meta ) {
  7616. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7617. if ( isRoot ) {
  7618. meta = {
  7619. textures: {},
  7620. images: {}
  7621. };
  7622. }
  7623. var data = {
  7624. metadata: {
  7625. version: 4.5,
  7626. type: 'Material',
  7627. generator: 'Material.toJSON'
  7628. }
  7629. };
  7630. // standard Material serialization
  7631. data.uuid = this.uuid;
  7632. data.type = this.type;
  7633. if ( this.name !== '' ) data.name = this.name;
  7634. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7635. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7636. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7637. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7638. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7639. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7640. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7641. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7642. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7643. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7644. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  7645. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7646. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7647. if ( this.aoMap && this.aoMap.isTexture ) {
  7648. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7649. data.aoMapIntensity = this.aoMapIntensity;
  7650. }
  7651. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7652. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7653. data.bumpScale = this.bumpScale;
  7654. }
  7655. if ( this.normalMap && this.normalMap.isTexture ) {
  7656. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7657. data.normalMapType = this.normalMapType;
  7658. data.normalScale = this.normalScale.toArray();
  7659. }
  7660. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7661. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7662. data.displacementScale = this.displacementScale;
  7663. data.displacementBias = this.displacementBias;
  7664. }
  7665. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7666. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7667. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7668. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7669. if ( this.envMap && this.envMap.isTexture ) {
  7670. data.envMap = this.envMap.toJSON( meta ).uuid;
  7671. data.reflectivity = this.reflectivity; // Scale behind envMap
  7672. if ( this.combine !== undefined ) data.combine = this.combine;
  7673. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7674. }
  7675. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7676. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7677. }
  7678. if ( this.size !== undefined ) data.size = this.size;
  7679. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7680. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7681. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7682. if ( this.side !== FrontSide ) data.side = this.side;
  7683. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7684. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7685. if ( this.transparent === true ) data.transparent = this.transparent;
  7686. data.depthFunc = this.depthFunc;
  7687. data.depthTest = this.depthTest;
  7688. data.depthWrite = this.depthWrite;
  7689. // rotation (SpriteMaterial)
  7690. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7691. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7692. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7693. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7694. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7695. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7696. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7697. if ( this.scale !== undefined ) data.scale = this.scale;
  7698. if ( this.dithering === true ) data.dithering = true;
  7699. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7700. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7701. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7702. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7703. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7704. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7705. if ( this.morphTargets === true ) data.morphTargets = true;
  7706. if ( this.skinning === true ) data.skinning = true;
  7707. if ( this.visible === false ) data.visible = false;
  7708. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7709. // TODO: Copied from Object3D.toJSON
  7710. function extractFromCache( cache ) {
  7711. var values = [];
  7712. for ( var key in cache ) {
  7713. var data = cache[ key ];
  7714. delete data.metadata;
  7715. values.push( data );
  7716. }
  7717. return values;
  7718. }
  7719. if ( isRoot ) {
  7720. var textures = extractFromCache( meta.textures );
  7721. var images = extractFromCache( meta.images );
  7722. if ( textures.length > 0 ) data.textures = textures;
  7723. if ( images.length > 0 ) data.images = images;
  7724. }
  7725. return data;
  7726. },
  7727. clone: function () {
  7728. return new this.constructor().copy( this );
  7729. },
  7730. copy: function ( source ) {
  7731. this.name = source.name;
  7732. this.fog = source.fog;
  7733. this.lights = source.lights;
  7734. this.blending = source.blending;
  7735. this.side = source.side;
  7736. this.flatShading = source.flatShading;
  7737. this.vertexColors = source.vertexColors;
  7738. this.opacity = source.opacity;
  7739. this.transparent = source.transparent;
  7740. this.blendSrc = source.blendSrc;
  7741. this.blendDst = source.blendDst;
  7742. this.blendEquation = source.blendEquation;
  7743. this.blendSrcAlpha = source.blendSrcAlpha;
  7744. this.blendDstAlpha = source.blendDstAlpha;
  7745. this.blendEquationAlpha = source.blendEquationAlpha;
  7746. this.depthFunc = source.depthFunc;
  7747. this.depthTest = source.depthTest;
  7748. this.depthWrite = source.depthWrite;
  7749. this.colorWrite = source.colorWrite;
  7750. this.precision = source.precision;
  7751. this.polygonOffset = source.polygonOffset;
  7752. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7753. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7754. this.dithering = source.dithering;
  7755. this.alphaTest = source.alphaTest;
  7756. this.premultipliedAlpha = source.premultipliedAlpha;
  7757. this.visible = source.visible;
  7758. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7759. this.clipShadows = source.clipShadows;
  7760. this.clipIntersection = source.clipIntersection;
  7761. var srcPlanes = source.clippingPlanes,
  7762. dstPlanes = null;
  7763. if ( srcPlanes !== null ) {
  7764. var n = srcPlanes.length;
  7765. dstPlanes = new Array( n );
  7766. for ( var i = 0; i !== n; ++ i )
  7767. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7768. }
  7769. this.clippingPlanes = dstPlanes;
  7770. this.shadowSide = source.shadowSide;
  7771. return this;
  7772. },
  7773. dispose: function () {
  7774. this.dispatchEvent( { type: 'dispose' } );
  7775. }
  7776. } );
  7777. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7778. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7779. /**
  7780. * @author alteredq / http://alteredqualia.com/
  7781. *
  7782. * parameters = {
  7783. * defines: { "label" : "value" },
  7784. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7785. *
  7786. * fragmentShader: <string>,
  7787. * vertexShader: <string>,
  7788. *
  7789. * wireframe: <boolean>,
  7790. * wireframeLinewidth: <float>,
  7791. *
  7792. * lights: <bool>,
  7793. *
  7794. * skinning: <bool>,
  7795. * morphTargets: <bool>,
  7796. * morphNormals: <bool>
  7797. * }
  7798. */
  7799. function ShaderMaterial( parameters ) {
  7800. Material.call( this );
  7801. this.type = 'ShaderMaterial';
  7802. this.defines = {};
  7803. this.uniforms = {};
  7804. this.vertexShader = default_vertex;
  7805. this.fragmentShader = default_fragment;
  7806. this.linewidth = 1;
  7807. this.wireframe = false;
  7808. this.wireframeLinewidth = 1;
  7809. this.fog = false; // set to use scene fog
  7810. this.lights = false; // set to use scene lights
  7811. this.clipping = false; // set to use user-defined clipping planes
  7812. this.skinning = false; // set to use skinning attribute streams
  7813. this.morphTargets = false; // set to use morph targets
  7814. this.morphNormals = false; // set to use morph normals
  7815. this.extensions = {
  7816. derivatives: false, // set to use derivatives
  7817. fragDepth: false, // set to use fragment depth values
  7818. drawBuffers: false, // set to use draw buffers
  7819. shaderTextureLOD: false // set to use shader texture LOD
  7820. };
  7821. // When rendered geometry doesn't include these attributes but the material does,
  7822. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7823. this.defaultAttributeValues = {
  7824. 'color': [ 1, 1, 1 ],
  7825. 'uv': [ 0, 0 ],
  7826. 'uv2': [ 0, 0 ]
  7827. };
  7828. this.index0AttributeName = undefined;
  7829. this.uniformsNeedUpdate = false;
  7830. if ( parameters !== undefined ) {
  7831. if ( parameters.attributes !== undefined ) {
  7832. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7833. }
  7834. this.setValues( parameters );
  7835. }
  7836. }
  7837. ShaderMaterial.prototype = Object.create( Material.prototype );
  7838. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7839. ShaderMaterial.prototype.isShaderMaterial = true;
  7840. ShaderMaterial.prototype.copy = function ( source ) {
  7841. Material.prototype.copy.call( this, source );
  7842. this.fragmentShader = source.fragmentShader;
  7843. this.vertexShader = source.vertexShader;
  7844. this.uniforms = cloneUniforms( source.uniforms );
  7845. this.defines = Object.assign( {}, source.defines );
  7846. this.wireframe = source.wireframe;
  7847. this.wireframeLinewidth = source.wireframeLinewidth;
  7848. this.lights = source.lights;
  7849. this.clipping = source.clipping;
  7850. this.skinning = source.skinning;
  7851. this.morphTargets = source.morphTargets;
  7852. this.morphNormals = source.morphNormals;
  7853. this.extensions = source.extensions;
  7854. return this;
  7855. };
  7856. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7857. var data = Material.prototype.toJSON.call( this, meta );
  7858. data.uniforms = {};
  7859. for ( var name in this.uniforms ) {
  7860. var uniform = this.uniforms[ name ];
  7861. var value = uniform.value;
  7862. if ( value && value.isTexture ) {
  7863. data.uniforms[ name ] = {
  7864. type: 't',
  7865. value: value.toJSON( meta ).uuid
  7866. };
  7867. } else if ( value && value.isColor ) {
  7868. data.uniforms[ name ] = {
  7869. type: 'c',
  7870. value: value.getHex()
  7871. };
  7872. } else if ( value && value.isVector2 ) {
  7873. data.uniforms[ name ] = {
  7874. type: 'v2',
  7875. value: value.toArray()
  7876. };
  7877. } else if ( value && value.isVector3 ) {
  7878. data.uniforms[ name ] = {
  7879. type: 'v3',
  7880. value: value.toArray()
  7881. };
  7882. } else if ( value && value.isVector4 ) {
  7883. data.uniforms[ name ] = {
  7884. type: 'v4',
  7885. value: value.toArray()
  7886. };
  7887. } else if ( value && value.isMatrix3 ) {
  7888. data.uniforms[ name ] = {
  7889. type: 'm3',
  7890. value: value.toArray()
  7891. };
  7892. } else if ( value && value.isMatrix4 ) {
  7893. data.uniforms[ name ] = {
  7894. type: 'm4',
  7895. value: value.toArray()
  7896. };
  7897. } else {
  7898. data.uniforms[ name ] = {
  7899. value: value
  7900. };
  7901. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7902. }
  7903. }
  7904. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7905. data.vertexShader = this.vertexShader;
  7906. data.fragmentShader = this.fragmentShader;
  7907. var extensions = {};
  7908. for ( var key in this.extensions ) {
  7909. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7910. }
  7911. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7912. return data;
  7913. };
  7914. /**
  7915. * @author bhouston / http://clara.io
  7916. */
  7917. function Ray( origin, direction ) {
  7918. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7919. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7920. }
  7921. Object.assign( Ray.prototype, {
  7922. set: function ( origin, direction ) {
  7923. this.origin.copy( origin );
  7924. this.direction.copy( direction );
  7925. return this;
  7926. },
  7927. clone: function () {
  7928. return new this.constructor().copy( this );
  7929. },
  7930. copy: function ( ray ) {
  7931. this.origin.copy( ray.origin );
  7932. this.direction.copy( ray.direction );
  7933. return this;
  7934. },
  7935. at: function ( t, target ) {
  7936. if ( target === undefined ) {
  7937. console.warn( 'THREE.Ray: .at() target is now required' );
  7938. target = new Vector3();
  7939. }
  7940. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7941. },
  7942. lookAt: function ( v ) {
  7943. this.direction.copy( v ).sub( this.origin ).normalize();
  7944. return this;
  7945. },
  7946. recast: function () {
  7947. var v1 = new Vector3();
  7948. return function recast( t ) {
  7949. this.origin.copy( this.at( t, v1 ) );
  7950. return this;
  7951. };
  7952. }(),
  7953. closestPointToPoint: function ( point, target ) {
  7954. if ( target === undefined ) {
  7955. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7956. target = new Vector3();
  7957. }
  7958. target.subVectors( point, this.origin );
  7959. var directionDistance = target.dot( this.direction );
  7960. if ( directionDistance < 0 ) {
  7961. return target.copy( this.origin );
  7962. }
  7963. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7964. },
  7965. distanceToPoint: function ( point ) {
  7966. return Math.sqrt( this.distanceSqToPoint( point ) );
  7967. },
  7968. distanceSqToPoint: function () {
  7969. var v1 = new Vector3();
  7970. return function distanceSqToPoint( point ) {
  7971. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7972. // point behind the ray
  7973. if ( directionDistance < 0 ) {
  7974. return this.origin.distanceToSquared( point );
  7975. }
  7976. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7977. return v1.distanceToSquared( point );
  7978. };
  7979. }(),
  7980. distanceSqToSegment: function () {
  7981. var segCenter = new Vector3();
  7982. var segDir = new Vector3();
  7983. var diff = new Vector3();
  7984. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7985. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7986. // It returns the min distance between the ray and the segment
  7987. // defined by v0 and v1
  7988. // It can also set two optional targets :
  7989. // - The closest point on the ray
  7990. // - The closest point on the segment
  7991. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7992. segDir.copy( v1 ).sub( v0 ).normalize();
  7993. diff.copy( this.origin ).sub( segCenter );
  7994. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7995. var a01 = - this.direction.dot( segDir );
  7996. var b0 = diff.dot( this.direction );
  7997. var b1 = - diff.dot( segDir );
  7998. var c = diff.lengthSq();
  7999. var det = Math.abs( 1 - a01 * a01 );
  8000. var s0, s1, sqrDist, extDet;
  8001. if ( det > 0 ) {
  8002. // The ray and segment are not parallel.
  8003. s0 = a01 * b1 - b0;
  8004. s1 = a01 * b0 - b1;
  8005. extDet = segExtent * det;
  8006. if ( s0 >= 0 ) {
  8007. if ( s1 >= - extDet ) {
  8008. if ( s1 <= extDet ) {
  8009. // region 0
  8010. // Minimum at interior points of ray and segment.
  8011. var invDet = 1 / det;
  8012. s0 *= invDet;
  8013. s1 *= invDet;
  8014. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  8015. } else {
  8016. // region 1
  8017. s1 = segExtent;
  8018. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8019. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8020. }
  8021. } else {
  8022. // region 5
  8023. s1 = - segExtent;
  8024. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8025. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8026. }
  8027. } else {
  8028. if ( s1 <= - extDet ) {
  8029. // region 4
  8030. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  8031. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8032. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8033. } else if ( s1 <= extDet ) {
  8034. // region 3
  8035. s0 = 0;
  8036. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8037. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8038. } else {
  8039. // region 2
  8040. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8041. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8042. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8043. }
  8044. }
  8045. } else {
  8046. // Ray and segment are parallel.
  8047. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8048. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8049. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8050. }
  8051. if ( optionalPointOnRay ) {
  8052. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8053. }
  8054. if ( optionalPointOnSegment ) {
  8055. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8056. }
  8057. return sqrDist;
  8058. };
  8059. }(),
  8060. intersectSphere: function () {
  8061. var v1 = new Vector3();
  8062. return function intersectSphere( sphere, target ) {
  8063. v1.subVectors( sphere.center, this.origin );
  8064. var tca = v1.dot( this.direction );
  8065. var d2 = v1.dot( v1 ) - tca * tca;
  8066. var radius2 = sphere.radius * sphere.radius;
  8067. if ( d2 > radius2 ) return null;
  8068. var thc = Math.sqrt( radius2 - d2 );
  8069. // t0 = first intersect point - entrance on front of sphere
  8070. var t0 = tca - thc;
  8071. // t1 = second intersect point - exit point on back of sphere
  8072. var t1 = tca + thc;
  8073. // test to see if both t0 and t1 are behind the ray - if so, return null
  8074. if ( t0 < 0 && t1 < 0 ) return null;
  8075. // test to see if t0 is behind the ray:
  8076. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8077. // in order to always return an intersect point that is in front of the ray.
  8078. if ( t0 < 0 ) return this.at( t1, target );
  8079. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8080. return this.at( t0, target );
  8081. };
  8082. }(),
  8083. intersectsSphere: function ( sphere ) {
  8084. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8085. },
  8086. distanceToPlane: function ( plane ) {
  8087. var denominator = plane.normal.dot( this.direction );
  8088. if ( denominator === 0 ) {
  8089. // line is coplanar, return origin
  8090. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8091. return 0;
  8092. }
  8093. // Null is preferable to undefined since undefined means.... it is undefined
  8094. return null;
  8095. }
  8096. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8097. // Return if the ray never intersects the plane
  8098. return t >= 0 ? t : null;
  8099. },
  8100. intersectPlane: function ( plane, target ) {
  8101. var t = this.distanceToPlane( plane );
  8102. if ( t === null ) {
  8103. return null;
  8104. }
  8105. return this.at( t, target );
  8106. },
  8107. intersectsPlane: function ( plane ) {
  8108. // check if the ray lies on the plane first
  8109. var distToPoint = plane.distanceToPoint( this.origin );
  8110. if ( distToPoint === 0 ) {
  8111. return true;
  8112. }
  8113. var denominator = plane.normal.dot( this.direction );
  8114. if ( denominator * distToPoint < 0 ) {
  8115. return true;
  8116. }
  8117. // ray origin is behind the plane (and is pointing behind it)
  8118. return false;
  8119. },
  8120. intersectBox: function ( box, target ) {
  8121. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8122. var invdirx = 1 / this.direction.x,
  8123. invdiry = 1 / this.direction.y,
  8124. invdirz = 1 / this.direction.z;
  8125. var origin = this.origin;
  8126. if ( invdirx >= 0 ) {
  8127. tmin = ( box.min.x - origin.x ) * invdirx;
  8128. tmax = ( box.max.x - origin.x ) * invdirx;
  8129. } else {
  8130. tmin = ( box.max.x - origin.x ) * invdirx;
  8131. tmax = ( box.min.x - origin.x ) * invdirx;
  8132. }
  8133. if ( invdiry >= 0 ) {
  8134. tymin = ( box.min.y - origin.y ) * invdiry;
  8135. tymax = ( box.max.y - origin.y ) * invdiry;
  8136. } else {
  8137. tymin = ( box.max.y - origin.y ) * invdiry;
  8138. tymax = ( box.min.y - origin.y ) * invdiry;
  8139. }
  8140. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8141. // These lines also handle the case where tmin or tmax is NaN
  8142. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8143. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8144. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8145. if ( invdirz >= 0 ) {
  8146. tzmin = ( box.min.z - origin.z ) * invdirz;
  8147. tzmax = ( box.max.z - origin.z ) * invdirz;
  8148. } else {
  8149. tzmin = ( box.max.z - origin.z ) * invdirz;
  8150. tzmax = ( box.min.z - origin.z ) * invdirz;
  8151. }
  8152. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8153. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8154. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8155. //return point closest to the ray (positive side)
  8156. if ( tmax < 0 ) return null;
  8157. return this.at( tmin >= 0 ? tmin : tmax, target );
  8158. },
  8159. intersectsBox: ( function () {
  8160. var v = new Vector3();
  8161. return function intersectsBox( box ) {
  8162. return this.intersectBox( box, v ) !== null;
  8163. };
  8164. } )(),
  8165. intersectTriangle: function () {
  8166. // Compute the offset origin, edges, and normal.
  8167. var diff = new Vector3();
  8168. var edge1 = new Vector3();
  8169. var edge2 = new Vector3();
  8170. var normal = new Vector3();
  8171. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8172. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8173. edge1.subVectors( b, a );
  8174. edge2.subVectors( c, a );
  8175. normal.crossVectors( edge1, edge2 );
  8176. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8177. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8178. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8179. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8180. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8181. var DdN = this.direction.dot( normal );
  8182. var sign;
  8183. if ( DdN > 0 ) {
  8184. if ( backfaceCulling ) return null;
  8185. sign = 1;
  8186. } else if ( DdN < 0 ) {
  8187. sign = - 1;
  8188. DdN = - DdN;
  8189. } else {
  8190. return null;
  8191. }
  8192. diff.subVectors( this.origin, a );
  8193. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8194. // b1 < 0, no intersection
  8195. if ( DdQxE2 < 0 ) {
  8196. return null;
  8197. }
  8198. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8199. // b2 < 0, no intersection
  8200. if ( DdE1xQ < 0 ) {
  8201. return null;
  8202. }
  8203. // b1+b2 > 1, no intersection
  8204. if ( DdQxE2 + DdE1xQ > DdN ) {
  8205. return null;
  8206. }
  8207. // Line intersects triangle, check if ray does.
  8208. var QdN = - sign * diff.dot( normal );
  8209. // t < 0, no intersection
  8210. if ( QdN < 0 ) {
  8211. return null;
  8212. }
  8213. // Ray intersects triangle.
  8214. return this.at( QdN / DdN, target );
  8215. };
  8216. }(),
  8217. applyMatrix4: function ( matrix4 ) {
  8218. this.origin.applyMatrix4( matrix4 );
  8219. this.direction.transformDirection( matrix4 );
  8220. return this;
  8221. },
  8222. equals: function ( ray ) {
  8223. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8224. }
  8225. } );
  8226. /**
  8227. * @author bhouston / http://clara.io
  8228. * @author mrdoob / http://mrdoob.com/
  8229. */
  8230. function Triangle( a, b, c ) {
  8231. this.a = ( a !== undefined ) ? a : new Vector3();
  8232. this.b = ( b !== undefined ) ? b : new Vector3();
  8233. this.c = ( c !== undefined ) ? c : new Vector3();
  8234. }
  8235. Object.assign( Triangle, {
  8236. getNormal: function () {
  8237. var v0 = new Vector3();
  8238. return function getNormal( a, b, c, target ) {
  8239. if ( target === undefined ) {
  8240. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8241. target = new Vector3();
  8242. }
  8243. target.subVectors( c, b );
  8244. v0.subVectors( a, b );
  8245. target.cross( v0 );
  8246. var targetLengthSq = target.lengthSq();
  8247. if ( targetLengthSq > 0 ) {
  8248. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8249. }
  8250. return target.set( 0, 0, 0 );
  8251. };
  8252. }(),
  8253. // static/instance method to calculate barycentric coordinates
  8254. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8255. getBarycoord: function () {
  8256. var v0 = new Vector3();
  8257. var v1 = new Vector3();
  8258. var v2 = new Vector3();
  8259. return function getBarycoord( point, a, b, c, target ) {
  8260. v0.subVectors( c, a );
  8261. v1.subVectors( b, a );
  8262. v2.subVectors( point, a );
  8263. var dot00 = v0.dot( v0 );
  8264. var dot01 = v0.dot( v1 );
  8265. var dot02 = v0.dot( v2 );
  8266. var dot11 = v1.dot( v1 );
  8267. var dot12 = v1.dot( v2 );
  8268. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8269. if ( target === undefined ) {
  8270. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8271. target = new Vector3();
  8272. }
  8273. // collinear or singular triangle
  8274. if ( denom === 0 ) {
  8275. // arbitrary location outside of triangle?
  8276. // not sure if this is the best idea, maybe should be returning undefined
  8277. return target.set( - 2, - 1, - 1 );
  8278. }
  8279. var invDenom = 1 / denom;
  8280. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8281. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8282. // barycentric coordinates must always sum to 1
  8283. return target.set( 1 - u - v, v, u );
  8284. };
  8285. }(),
  8286. containsPoint: function () {
  8287. var v1 = new Vector3();
  8288. return function containsPoint( point, a, b, c ) {
  8289. Triangle.getBarycoord( point, a, b, c, v1 );
  8290. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8291. };
  8292. }(),
  8293. getUV: function () {
  8294. var barycoord = new Vector3();
  8295. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8296. this.getBarycoord( point, p1, p2, p3, barycoord );
  8297. target.set( 0, 0 );
  8298. target.addScaledVector( uv1, barycoord.x );
  8299. target.addScaledVector( uv2, barycoord.y );
  8300. target.addScaledVector( uv3, barycoord.z );
  8301. return target;
  8302. };
  8303. }()
  8304. } );
  8305. Object.assign( Triangle.prototype, {
  8306. set: function ( a, b, c ) {
  8307. this.a.copy( a );
  8308. this.b.copy( b );
  8309. this.c.copy( c );
  8310. return this;
  8311. },
  8312. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8313. this.a.copy( points[ i0 ] );
  8314. this.b.copy( points[ i1 ] );
  8315. this.c.copy( points[ i2 ] );
  8316. return this;
  8317. },
  8318. clone: function () {
  8319. return new this.constructor().copy( this );
  8320. },
  8321. copy: function ( triangle ) {
  8322. this.a.copy( triangle.a );
  8323. this.b.copy( triangle.b );
  8324. this.c.copy( triangle.c );
  8325. return this;
  8326. },
  8327. getArea: function () {
  8328. var v0 = new Vector3();
  8329. var v1 = new Vector3();
  8330. return function getArea() {
  8331. v0.subVectors( this.c, this.b );
  8332. v1.subVectors( this.a, this.b );
  8333. return v0.cross( v1 ).length() * 0.5;
  8334. };
  8335. }(),
  8336. getMidpoint: function ( target ) {
  8337. if ( target === undefined ) {
  8338. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8339. target = new Vector3();
  8340. }
  8341. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8342. },
  8343. getNormal: function ( target ) {
  8344. return Triangle.getNormal( this.a, this.b, this.c, target );
  8345. },
  8346. getPlane: function ( target ) {
  8347. if ( target === undefined ) {
  8348. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8349. target = new Vector3();
  8350. }
  8351. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8352. },
  8353. getBarycoord: function ( point, target ) {
  8354. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8355. },
  8356. containsPoint: function ( point ) {
  8357. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8358. },
  8359. getUV: function ( point, uv1, uv2, uv3, result ) {
  8360. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
  8361. },
  8362. intersectsBox: function ( box ) {
  8363. return box.intersectsTriangle( this );
  8364. },
  8365. closestPointToPoint: function () {
  8366. var vab = new Vector3();
  8367. var vac = new Vector3();
  8368. var vbc = new Vector3();
  8369. var vap = new Vector3();
  8370. var vbp = new Vector3();
  8371. var vcp = new Vector3();
  8372. return function closestPointToPoint( p, target ) {
  8373. if ( target === undefined ) {
  8374. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8375. target = new Vector3();
  8376. }
  8377. var a = this.a, b = this.b, c = this.c;
  8378. var v, w;
  8379. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8380. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8381. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8382. // basically, we're distinguishing which of the voronoi regions of the triangle
  8383. // the point lies in with the minimum amount of redundant computation.
  8384. vab.subVectors( b, a );
  8385. vac.subVectors( c, a );
  8386. vap.subVectors( p, a );
  8387. var d1 = vab.dot( vap );
  8388. var d2 = vac.dot( vap );
  8389. if ( d1 <= 0 && d2 <= 0 ) {
  8390. // vertex region of A; barycentric coords (1, 0, 0)
  8391. return target.copy( a );
  8392. }
  8393. vbp.subVectors( p, b );
  8394. var d3 = vab.dot( vbp );
  8395. var d4 = vac.dot( vbp );
  8396. if ( d3 >= 0 && d4 <= d3 ) {
  8397. // vertex region of B; barycentric coords (0, 1, 0)
  8398. return target.copy( b );
  8399. }
  8400. var vc = d1 * d4 - d3 * d2;
  8401. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8402. v = d1 / ( d1 - d3 );
  8403. // edge region of AB; barycentric coords (1-v, v, 0)
  8404. return target.copy( a ).addScaledVector( vab, v );
  8405. }
  8406. vcp.subVectors( p, c );
  8407. var d5 = vab.dot( vcp );
  8408. var d6 = vac.dot( vcp );
  8409. if ( d6 >= 0 && d5 <= d6 ) {
  8410. // vertex region of C; barycentric coords (0, 0, 1)
  8411. return target.copy( c );
  8412. }
  8413. var vb = d5 * d2 - d1 * d6;
  8414. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8415. w = d2 / ( d2 - d6 );
  8416. // edge region of AC; barycentric coords (1-w, 0, w)
  8417. return target.copy( a ).addScaledVector( vac, w );
  8418. }
  8419. var va = d3 * d6 - d5 * d4;
  8420. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8421. vbc.subVectors( c, b );
  8422. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8423. // edge region of BC; barycentric coords (0, 1-w, w)
  8424. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8425. }
  8426. // face region
  8427. var denom = 1 / ( va + vb + vc );
  8428. // u = va * denom
  8429. v = vb * denom;
  8430. w = vc * denom;
  8431. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8432. };
  8433. }(),
  8434. equals: function ( triangle ) {
  8435. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8436. }
  8437. } );
  8438. /**
  8439. * @author mrdoob / http://mrdoob.com/
  8440. * @author alteredq / http://alteredqualia.com/
  8441. *
  8442. * parameters = {
  8443. * color: <hex>,
  8444. * opacity: <float>,
  8445. * map: new THREE.Texture( <Image> ),
  8446. *
  8447. * lightMap: new THREE.Texture( <Image> ),
  8448. * lightMapIntensity: <float>
  8449. *
  8450. * aoMap: new THREE.Texture( <Image> ),
  8451. * aoMapIntensity: <float>
  8452. *
  8453. * specularMap: new THREE.Texture( <Image> ),
  8454. *
  8455. * alphaMap: new THREE.Texture( <Image> ),
  8456. *
  8457. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8458. * combine: THREE.Multiply,
  8459. * reflectivity: <float>,
  8460. * refractionRatio: <float>,
  8461. *
  8462. * depthTest: <bool>,
  8463. * depthWrite: <bool>,
  8464. *
  8465. * wireframe: <boolean>,
  8466. * wireframeLinewidth: <float>,
  8467. *
  8468. * skinning: <bool>,
  8469. * morphTargets: <bool>
  8470. * }
  8471. */
  8472. function MeshBasicMaterial( parameters ) {
  8473. Material.call( this );
  8474. this.type = 'MeshBasicMaterial';
  8475. this.color = new Color( 0xffffff ); // emissive
  8476. this.map = null;
  8477. this.lightMap = null;
  8478. this.lightMapIntensity = 1.0;
  8479. this.aoMap = null;
  8480. this.aoMapIntensity = 1.0;
  8481. this.specularMap = null;
  8482. this.alphaMap = null;
  8483. this.envMap = null;
  8484. this.combine = MultiplyOperation;
  8485. this.reflectivity = 1;
  8486. this.refractionRatio = 0.98;
  8487. this.wireframe = false;
  8488. this.wireframeLinewidth = 1;
  8489. this.wireframeLinecap = 'round';
  8490. this.wireframeLinejoin = 'round';
  8491. this.skinning = false;
  8492. this.morphTargets = false;
  8493. this.lights = false;
  8494. this.setValues( parameters );
  8495. }
  8496. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8497. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8498. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8499. MeshBasicMaterial.prototype.copy = function ( source ) {
  8500. Material.prototype.copy.call( this, source );
  8501. this.color.copy( source.color );
  8502. this.map = source.map;
  8503. this.lightMap = source.lightMap;
  8504. this.lightMapIntensity = source.lightMapIntensity;
  8505. this.aoMap = source.aoMap;
  8506. this.aoMapIntensity = source.aoMapIntensity;
  8507. this.specularMap = source.specularMap;
  8508. this.alphaMap = source.alphaMap;
  8509. this.envMap = source.envMap;
  8510. this.combine = source.combine;
  8511. this.reflectivity = source.reflectivity;
  8512. this.refractionRatio = source.refractionRatio;
  8513. this.wireframe = source.wireframe;
  8514. this.wireframeLinewidth = source.wireframeLinewidth;
  8515. this.wireframeLinecap = source.wireframeLinecap;
  8516. this.wireframeLinejoin = source.wireframeLinejoin;
  8517. this.skinning = source.skinning;
  8518. this.morphTargets = source.morphTargets;
  8519. return this;
  8520. };
  8521. /**
  8522. * @author mrdoob / http://mrdoob.com/
  8523. * @author alteredq / http://alteredqualia.com/
  8524. * @author mikael emtinger / http://gomo.se/
  8525. * @author jonobr1 / http://jonobr1.com/
  8526. */
  8527. function Mesh( geometry, material ) {
  8528. Object3D.call( this );
  8529. this.type = 'Mesh';
  8530. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8531. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8532. this.drawMode = TrianglesDrawMode;
  8533. this.updateMorphTargets();
  8534. }
  8535. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8536. constructor: Mesh,
  8537. isMesh: true,
  8538. setDrawMode: function ( value ) {
  8539. this.drawMode = value;
  8540. },
  8541. copy: function ( source ) {
  8542. Object3D.prototype.copy.call( this, source );
  8543. this.drawMode = source.drawMode;
  8544. if ( source.morphTargetInfluences !== undefined ) {
  8545. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8546. }
  8547. if ( source.morphTargetDictionary !== undefined ) {
  8548. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8549. }
  8550. return this;
  8551. },
  8552. updateMorphTargets: function () {
  8553. var geometry = this.geometry;
  8554. var m, ml, name;
  8555. if ( geometry.isBufferGeometry ) {
  8556. var morphAttributes = geometry.morphAttributes;
  8557. var keys = Object.keys( morphAttributes );
  8558. if ( keys.length > 0 ) {
  8559. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8560. if ( morphAttribute !== undefined ) {
  8561. this.morphTargetInfluences = [];
  8562. this.morphTargetDictionary = {};
  8563. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8564. name = morphAttribute[ m ].name || String( m );
  8565. this.morphTargetInfluences.push( 0 );
  8566. this.morphTargetDictionary[ name ] = m;
  8567. }
  8568. }
  8569. }
  8570. } else {
  8571. var morphTargets = geometry.morphTargets;
  8572. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8573. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8574. }
  8575. }
  8576. },
  8577. raycast: ( function () {
  8578. var inverseMatrix = new Matrix4();
  8579. var ray = new Ray();
  8580. var sphere = new Sphere();
  8581. var vA = new Vector3();
  8582. var vB = new Vector3();
  8583. var vC = new Vector3();
  8584. var tempA = new Vector3();
  8585. var tempB = new Vector3();
  8586. var tempC = new Vector3();
  8587. var morphA = new Vector3();
  8588. var morphB = new Vector3();
  8589. var morphC = new Vector3();
  8590. var uvA = new Vector2();
  8591. var uvB = new Vector2();
  8592. var uvC = new Vector2();
  8593. var intersectionPoint = new Vector3();
  8594. var intersectionPointWorld = new Vector3();
  8595. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8596. var intersect;
  8597. if ( material.side === BackSide ) {
  8598. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8599. } else {
  8600. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8601. }
  8602. if ( intersect === null ) return null;
  8603. intersectionPointWorld.copy( point );
  8604. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8605. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8606. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8607. return {
  8608. distance: distance,
  8609. point: intersectionPointWorld.clone(),
  8610. object: object
  8611. };
  8612. }
  8613. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, a, b, c ) {
  8614. vA.fromBufferAttribute( position, a );
  8615. vB.fromBufferAttribute( position, b );
  8616. vC.fromBufferAttribute( position, c );
  8617. var morphInfluences = object.morphTargetInfluences;
  8618. if ( material.morphTargets && morphPosition && morphInfluences ) {
  8619. morphA.set( 0, 0, 0 );
  8620. morphB.set( 0, 0, 0 );
  8621. morphC.set( 0, 0, 0 );
  8622. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  8623. var influence = morphInfluences[ i ];
  8624. var morphAttribute = morphPosition[ i ];
  8625. if ( influence === 0 ) continue;
  8626. tempA.fromBufferAttribute( morphAttribute, a );
  8627. tempB.fromBufferAttribute( morphAttribute, b );
  8628. tempC.fromBufferAttribute( morphAttribute, c );
  8629. morphA.addScaledVector( tempA.sub( vA ), influence );
  8630. morphB.addScaledVector( tempB.sub( vB ), influence );
  8631. morphC.addScaledVector( tempC.sub( vC ), influence );
  8632. }
  8633. vA.add( morphA );
  8634. vB.add( morphB );
  8635. vC.add( morphC );
  8636. }
  8637. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8638. if ( intersection ) {
  8639. if ( uv ) {
  8640. uvA.fromBufferAttribute( uv, a );
  8641. uvB.fromBufferAttribute( uv, b );
  8642. uvC.fromBufferAttribute( uv, c );
  8643. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8644. }
  8645. var face = new Face3( a, b, c );
  8646. Triangle.getNormal( vA, vB, vC, face.normal );
  8647. intersection.face = face;
  8648. }
  8649. return intersection;
  8650. }
  8651. return function raycast( raycaster, intersects ) {
  8652. var geometry = this.geometry;
  8653. var material = this.material;
  8654. var matrixWorld = this.matrixWorld;
  8655. if ( material === undefined ) return;
  8656. // Checking boundingSphere distance to ray
  8657. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8658. sphere.copy( geometry.boundingSphere );
  8659. sphere.applyMatrix4( matrixWorld );
  8660. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8661. //
  8662. inverseMatrix.getInverse( matrixWorld );
  8663. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8664. // Check boundingBox before continuing
  8665. if ( geometry.boundingBox !== null ) {
  8666. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8667. }
  8668. var intersection;
  8669. if ( geometry.isBufferGeometry ) {
  8670. var a, b, c;
  8671. var index = geometry.index;
  8672. var position = geometry.attributes.position;
  8673. var morphPosition = geometry.morphAttributes.position;
  8674. var uv = geometry.attributes.uv;
  8675. var groups = geometry.groups;
  8676. var drawRange = geometry.drawRange;
  8677. var i, j, il, jl;
  8678. var group, groupMaterial;
  8679. var start, end;
  8680. if ( index !== null ) {
  8681. // indexed buffer geometry
  8682. if ( Array.isArray( material ) ) {
  8683. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8684. group = groups[ i ];
  8685. groupMaterial = material[ group.materialIndex ];
  8686. start = Math.max( group.start, drawRange.start );
  8687. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8688. for ( j = start, jl = end; j < jl; j += 3 ) {
  8689. a = index.getX( j );
  8690. b = index.getX( j + 1 );
  8691. c = index.getX( j + 2 );
  8692. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8693. if ( intersection ) {
  8694. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8695. intersection.face.materialIndex = group.materialIndex;
  8696. intersects.push( intersection );
  8697. }
  8698. }
  8699. }
  8700. } else {
  8701. start = Math.max( 0, drawRange.start );
  8702. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8703. for ( i = start, il = end; i < il; i += 3 ) {
  8704. a = index.getX( i );
  8705. b = index.getX( i + 1 );
  8706. c = index.getX( i + 2 );
  8707. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8708. if ( intersection ) {
  8709. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8710. intersects.push( intersection );
  8711. }
  8712. }
  8713. }
  8714. } else if ( position !== undefined ) {
  8715. // non-indexed buffer geometry
  8716. if ( Array.isArray( material ) ) {
  8717. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8718. group = groups[ i ];
  8719. groupMaterial = material[ group.materialIndex ];
  8720. start = Math.max( group.start, drawRange.start );
  8721. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8722. for ( j = start, jl = end; j < jl; j += 3 ) {
  8723. a = j;
  8724. b = j + 1;
  8725. c = j + 2;
  8726. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8727. if ( intersection ) {
  8728. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  8729. intersection.face.materialIndex = group.materialIndex;
  8730. intersects.push( intersection );
  8731. }
  8732. }
  8733. }
  8734. } else {
  8735. start = Math.max( 0, drawRange.start );
  8736. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  8737. for ( i = start, il = end; i < il; i += 3 ) {
  8738. a = i;
  8739. b = i + 1;
  8740. c = i + 2;
  8741. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8742. if ( intersection ) {
  8743. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8744. intersects.push( intersection );
  8745. }
  8746. }
  8747. }
  8748. }
  8749. } else if ( geometry.isGeometry ) {
  8750. var fvA, fvB, fvC;
  8751. var isMultiMaterial = Array.isArray( material );
  8752. var vertices = geometry.vertices;
  8753. var faces = geometry.faces;
  8754. var uvs;
  8755. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8756. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8757. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8758. var face = faces[ f ];
  8759. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8760. if ( faceMaterial === undefined ) continue;
  8761. fvA = vertices[ face.a ];
  8762. fvB = vertices[ face.b ];
  8763. fvC = vertices[ face.c ];
  8764. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8765. if ( intersection ) {
  8766. if ( uvs && uvs[ f ] ) {
  8767. var uvs_f = uvs[ f ];
  8768. uvA.copy( uvs_f[ 0 ] );
  8769. uvB.copy( uvs_f[ 1 ] );
  8770. uvC.copy( uvs_f[ 2 ] );
  8771. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8772. }
  8773. intersection.face = face;
  8774. intersection.faceIndex = f;
  8775. intersects.push( intersection );
  8776. }
  8777. }
  8778. }
  8779. };
  8780. }() ),
  8781. clone: function () {
  8782. return new this.constructor( this.geometry, this.material ).copy( this );
  8783. }
  8784. } );
  8785. /**
  8786. * @author mrdoob / http://mrdoob.com/
  8787. */
  8788. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8789. var clearColor = new Color( 0x000000 );
  8790. var clearAlpha = 0;
  8791. var planeMesh;
  8792. var boxMesh;
  8793. // Store the current background texture and its `version`
  8794. // so we can recompile the material accordingly.
  8795. var currentBackground = null;
  8796. var currentBackgroundVersion = 0;
  8797. function render( renderList, scene, camera, forceClear ) {
  8798. var background = scene.background;
  8799. // Ignore background in AR
  8800. // TODO: Reconsider this.
  8801. var vr = renderer.vr;
  8802. var session = vr.getSession && vr.getSession();
  8803. if ( session && session.environmentBlendMode === 'additive' ) {
  8804. background = null;
  8805. }
  8806. if ( background === null ) {
  8807. setClear( clearColor, clearAlpha );
  8808. currentBackground = null;
  8809. currentBackgroundVersion = 0;
  8810. } else if ( background && background.isColor ) {
  8811. setClear( background, 1 );
  8812. forceClear = true;
  8813. currentBackground = null;
  8814. currentBackgroundVersion = 0;
  8815. }
  8816. if ( renderer.autoClear || forceClear ) {
  8817. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8818. }
  8819. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8820. if ( boxMesh === undefined ) {
  8821. boxMesh = new Mesh(
  8822. new BoxBufferGeometry( 1, 1, 1 ),
  8823. new ShaderMaterial( {
  8824. type: 'BackgroundCubeMaterial',
  8825. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8826. vertexShader: ShaderLib.cube.vertexShader,
  8827. fragmentShader: ShaderLib.cube.fragmentShader,
  8828. side: BackSide,
  8829. depthTest: false,
  8830. depthWrite: false,
  8831. fog: false
  8832. } )
  8833. );
  8834. boxMesh.geometry.removeAttribute( 'normal' );
  8835. boxMesh.geometry.removeAttribute( 'uv' );
  8836. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8837. this.matrixWorld.copyPosition( camera.matrixWorld );
  8838. };
  8839. // enable code injection for non-built-in material
  8840. Object.defineProperty( boxMesh.material, 'map', {
  8841. get: function () {
  8842. return this.uniforms.tCube.value;
  8843. }
  8844. } );
  8845. objects.update( boxMesh );
  8846. }
  8847. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8848. boxMesh.material.uniforms.tCube.value = texture;
  8849. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8850. if ( currentBackground !== background ||
  8851. currentBackgroundVersion !== texture.version ) {
  8852. boxMesh.material.needsUpdate = true;
  8853. currentBackground = background;
  8854. currentBackgroundVersion = texture.version;
  8855. }
  8856. // push to the pre-sorted opaque render list
  8857. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8858. } else if ( background && background.isTexture ) {
  8859. if ( planeMesh === undefined ) {
  8860. planeMesh = new Mesh(
  8861. new PlaneBufferGeometry( 2, 2 ),
  8862. new ShaderMaterial( {
  8863. type: 'BackgroundMaterial',
  8864. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8865. vertexShader: ShaderLib.background.vertexShader,
  8866. fragmentShader: ShaderLib.background.fragmentShader,
  8867. side: FrontSide,
  8868. depthTest: false,
  8869. depthWrite: false,
  8870. fog: false
  8871. } )
  8872. );
  8873. planeMesh.geometry.removeAttribute( 'normal' );
  8874. // enable code injection for non-built-in material
  8875. Object.defineProperty( planeMesh.material, 'map', {
  8876. get: function () {
  8877. return this.uniforms.t2D.value;
  8878. }
  8879. } );
  8880. objects.update( planeMesh );
  8881. }
  8882. planeMesh.material.uniforms.t2D.value = background;
  8883. if ( background.matrixAutoUpdate === true ) {
  8884. background.updateMatrix();
  8885. }
  8886. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8887. if ( currentBackground !== background ||
  8888. currentBackgroundVersion !== background.version ) {
  8889. planeMesh.material.needsUpdate = true;
  8890. currentBackground = background;
  8891. currentBackgroundVersion = background.version;
  8892. }
  8893. // push to the pre-sorted opaque render list
  8894. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8895. }
  8896. }
  8897. function setClear( color, alpha ) {
  8898. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8899. }
  8900. return {
  8901. getClearColor: function () {
  8902. return clearColor;
  8903. },
  8904. setClearColor: function ( color, alpha ) {
  8905. clearColor.set( color );
  8906. clearAlpha = alpha !== undefined ? alpha : 1;
  8907. setClear( clearColor, clearAlpha );
  8908. },
  8909. getClearAlpha: function () {
  8910. return clearAlpha;
  8911. },
  8912. setClearAlpha: function ( alpha ) {
  8913. clearAlpha = alpha;
  8914. setClear( clearColor, clearAlpha );
  8915. },
  8916. render: render
  8917. };
  8918. }
  8919. /**
  8920. * @author mrdoob / http://mrdoob.com/
  8921. */
  8922. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8923. var mode;
  8924. function setMode( value ) {
  8925. mode = value;
  8926. }
  8927. function render( start, count ) {
  8928. gl.drawArrays( mode, start, count );
  8929. info.update( count, mode );
  8930. }
  8931. function renderInstances( geometry, start, count ) {
  8932. var extension;
  8933. if ( capabilities.isWebGL2 ) {
  8934. extension = gl;
  8935. } else {
  8936. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8937. if ( extension === null ) {
  8938. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8939. return;
  8940. }
  8941. }
  8942. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8943. info.update( count, mode, geometry.maxInstancedCount );
  8944. }
  8945. //
  8946. this.setMode = setMode;
  8947. this.render = render;
  8948. this.renderInstances = renderInstances;
  8949. }
  8950. /**
  8951. * @author mrdoob / http://mrdoob.com/
  8952. */
  8953. function WebGLCapabilities( gl, extensions, parameters ) {
  8954. var maxAnisotropy;
  8955. function getMaxAnisotropy() {
  8956. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8957. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8958. if ( extension !== null ) {
  8959. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8960. } else {
  8961. maxAnisotropy = 0;
  8962. }
  8963. return maxAnisotropy;
  8964. }
  8965. function getMaxPrecision( precision ) {
  8966. if ( precision === 'highp' ) {
  8967. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8968. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8969. return 'highp';
  8970. }
  8971. precision = 'mediump';
  8972. }
  8973. if ( precision === 'mediump' ) {
  8974. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8975. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8976. return 'mediump';
  8977. }
  8978. }
  8979. return 'lowp';
  8980. }
  8981. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  8982. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8983. var maxPrecision = getMaxPrecision( precision );
  8984. if ( maxPrecision !== precision ) {
  8985. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8986. precision = maxPrecision;
  8987. }
  8988. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8989. var maxTextures = gl.getParameter( 34930 );
  8990. var maxVertexTextures = gl.getParameter( 35660 );
  8991. var maxTextureSize = gl.getParameter( 3379 );
  8992. var maxCubemapSize = gl.getParameter( 34076 );
  8993. var maxAttributes = gl.getParameter( 34921 );
  8994. var maxVertexUniforms = gl.getParameter( 36347 );
  8995. var maxVaryings = gl.getParameter( 36348 );
  8996. var maxFragmentUniforms = gl.getParameter( 36349 );
  8997. var vertexTextures = maxVertexTextures > 0;
  8998. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8999. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9000. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9001. return {
  9002. isWebGL2: isWebGL2,
  9003. getMaxAnisotropy: getMaxAnisotropy,
  9004. getMaxPrecision: getMaxPrecision,
  9005. precision: precision,
  9006. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9007. maxTextures: maxTextures,
  9008. maxVertexTextures: maxVertexTextures,
  9009. maxTextureSize: maxTextureSize,
  9010. maxCubemapSize: maxCubemapSize,
  9011. maxAttributes: maxAttributes,
  9012. maxVertexUniforms: maxVertexUniforms,
  9013. maxVaryings: maxVaryings,
  9014. maxFragmentUniforms: maxFragmentUniforms,
  9015. vertexTextures: vertexTextures,
  9016. floatFragmentTextures: floatFragmentTextures,
  9017. floatVertexTextures: floatVertexTextures,
  9018. maxSamples: maxSamples
  9019. };
  9020. }
  9021. /**
  9022. * @author tschw
  9023. */
  9024. function WebGLClipping() {
  9025. var scope = this,
  9026. globalState = null,
  9027. numGlobalPlanes = 0,
  9028. localClippingEnabled = false,
  9029. renderingShadows = false,
  9030. plane = new Plane(),
  9031. viewNormalMatrix = new Matrix3(),
  9032. uniform = { value: null, needsUpdate: false };
  9033. this.uniform = uniform;
  9034. this.numPlanes = 0;
  9035. this.numIntersection = 0;
  9036. this.init = function ( planes, enableLocalClipping, camera ) {
  9037. var enabled =
  9038. planes.length !== 0 ||
  9039. enableLocalClipping ||
  9040. // enable state of previous frame - the clipping code has to
  9041. // run another frame in order to reset the state:
  9042. numGlobalPlanes !== 0 ||
  9043. localClippingEnabled;
  9044. localClippingEnabled = enableLocalClipping;
  9045. globalState = projectPlanes( planes, camera, 0 );
  9046. numGlobalPlanes = planes.length;
  9047. return enabled;
  9048. };
  9049. this.beginShadows = function () {
  9050. renderingShadows = true;
  9051. projectPlanes( null );
  9052. };
  9053. this.endShadows = function () {
  9054. renderingShadows = false;
  9055. resetGlobalState();
  9056. };
  9057. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9058. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9059. // there's no local clipping
  9060. if ( renderingShadows ) {
  9061. // there's no global clipping
  9062. projectPlanes( null );
  9063. } else {
  9064. resetGlobalState();
  9065. }
  9066. } else {
  9067. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9068. lGlobal = nGlobal * 4,
  9069. dstArray = cache.clippingState || null;
  9070. uniform.value = dstArray; // ensure unique state
  9071. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9072. for ( var i = 0; i !== lGlobal; ++ i ) {
  9073. dstArray[ i ] = globalState[ i ];
  9074. }
  9075. cache.clippingState = dstArray;
  9076. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9077. this.numPlanes += nGlobal;
  9078. }
  9079. };
  9080. function resetGlobalState() {
  9081. if ( uniform.value !== globalState ) {
  9082. uniform.value = globalState;
  9083. uniform.needsUpdate = numGlobalPlanes > 0;
  9084. }
  9085. scope.numPlanes = numGlobalPlanes;
  9086. scope.numIntersection = 0;
  9087. }
  9088. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9089. var nPlanes = planes !== null ? planes.length : 0,
  9090. dstArray = null;
  9091. if ( nPlanes !== 0 ) {
  9092. dstArray = uniform.value;
  9093. if ( skipTransform !== true || dstArray === null ) {
  9094. var flatSize = dstOffset + nPlanes * 4,
  9095. viewMatrix = camera.matrixWorldInverse;
  9096. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9097. if ( dstArray === null || dstArray.length < flatSize ) {
  9098. dstArray = new Float32Array( flatSize );
  9099. }
  9100. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9101. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9102. plane.normal.toArray( dstArray, i4 );
  9103. dstArray[ i4 + 3 ] = plane.constant;
  9104. }
  9105. }
  9106. uniform.value = dstArray;
  9107. uniform.needsUpdate = true;
  9108. }
  9109. scope.numPlanes = nPlanes;
  9110. return dstArray;
  9111. }
  9112. }
  9113. /**
  9114. * @author mrdoob / http://mrdoob.com/
  9115. */
  9116. function WebGLExtensions( gl ) {
  9117. var extensions = {};
  9118. return {
  9119. get: function ( name ) {
  9120. if ( extensions[ name ] !== undefined ) {
  9121. return extensions[ name ];
  9122. }
  9123. var extension;
  9124. switch ( name ) {
  9125. case 'WEBGL_depth_texture':
  9126. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9127. break;
  9128. case 'EXT_texture_filter_anisotropic':
  9129. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9130. break;
  9131. case 'WEBGL_compressed_texture_s3tc':
  9132. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9133. break;
  9134. case 'WEBGL_compressed_texture_pvrtc':
  9135. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9136. break;
  9137. default:
  9138. extension = gl.getExtension( name );
  9139. }
  9140. if ( extension === null ) {
  9141. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9142. }
  9143. extensions[ name ] = extension;
  9144. return extension;
  9145. }
  9146. };
  9147. }
  9148. /**
  9149. * @author mrdoob / http://mrdoob.com/
  9150. */
  9151. function WebGLGeometries( gl, attributes, info ) {
  9152. var geometries = {};
  9153. var wireframeAttributes = {};
  9154. function onGeometryDispose( event ) {
  9155. var geometry = event.target;
  9156. var buffergeometry = geometries[ geometry.id ];
  9157. if ( buffergeometry.index !== null ) {
  9158. attributes.remove( buffergeometry.index );
  9159. }
  9160. for ( var name in buffergeometry.attributes ) {
  9161. attributes.remove( buffergeometry.attributes[ name ] );
  9162. }
  9163. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9164. delete geometries[ geometry.id ];
  9165. var attribute = wireframeAttributes[ buffergeometry.id ];
  9166. if ( attribute ) {
  9167. attributes.remove( attribute );
  9168. delete wireframeAttributes[ buffergeometry.id ];
  9169. }
  9170. //
  9171. info.memory.geometries --;
  9172. }
  9173. function get( object, geometry ) {
  9174. var buffergeometry = geometries[ geometry.id ];
  9175. if ( buffergeometry ) return buffergeometry;
  9176. geometry.addEventListener( 'dispose', onGeometryDispose );
  9177. if ( geometry.isBufferGeometry ) {
  9178. buffergeometry = geometry;
  9179. } else if ( geometry.isGeometry ) {
  9180. if ( geometry._bufferGeometry === undefined ) {
  9181. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9182. }
  9183. buffergeometry = geometry._bufferGeometry;
  9184. }
  9185. geometries[ geometry.id ] = buffergeometry;
  9186. info.memory.geometries ++;
  9187. return buffergeometry;
  9188. }
  9189. function update( geometry ) {
  9190. var index = geometry.index;
  9191. var geometryAttributes = geometry.attributes;
  9192. if ( index !== null ) {
  9193. attributes.update( index, 34963 );
  9194. }
  9195. for ( var name in geometryAttributes ) {
  9196. attributes.update( geometryAttributes[ name ], 34962 );
  9197. }
  9198. // morph targets
  9199. var morphAttributes = geometry.morphAttributes;
  9200. for ( var name in morphAttributes ) {
  9201. var array = morphAttributes[ name ];
  9202. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9203. attributes.update( array[ i ], 34962 );
  9204. }
  9205. }
  9206. }
  9207. function getWireframeAttribute( geometry ) {
  9208. var attribute = wireframeAttributes[ geometry.id ];
  9209. if ( attribute ) return attribute;
  9210. var indices = [];
  9211. var geometryIndex = geometry.index;
  9212. var geometryAttributes = geometry.attributes;
  9213. // console.time( 'wireframe' );
  9214. if ( geometryIndex !== null ) {
  9215. var array = geometryIndex.array;
  9216. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9217. var a = array[ i + 0 ];
  9218. var b = array[ i + 1 ];
  9219. var c = array[ i + 2 ];
  9220. indices.push( a, b, b, c, c, a );
  9221. }
  9222. } else {
  9223. var array = geometryAttributes.position.array;
  9224. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9225. var a = i + 0;
  9226. var b = i + 1;
  9227. var c = i + 2;
  9228. indices.push( a, b, b, c, c, a );
  9229. }
  9230. }
  9231. // console.timeEnd( 'wireframe' );
  9232. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9233. attributes.update( attribute, 34963 );
  9234. wireframeAttributes[ geometry.id ] = attribute;
  9235. return attribute;
  9236. }
  9237. return {
  9238. get: get,
  9239. update: update,
  9240. getWireframeAttribute: getWireframeAttribute
  9241. };
  9242. }
  9243. /**
  9244. * @author mrdoob / http://mrdoob.com/
  9245. */
  9246. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9247. var mode;
  9248. function setMode( value ) {
  9249. mode = value;
  9250. }
  9251. var type, bytesPerElement;
  9252. function setIndex( value ) {
  9253. type = value.type;
  9254. bytesPerElement = value.bytesPerElement;
  9255. }
  9256. function render( start, count ) {
  9257. gl.drawElements( mode, count, type, start * bytesPerElement );
  9258. info.update( count, mode );
  9259. }
  9260. function renderInstances( geometry, start, count ) {
  9261. var extension;
  9262. if ( capabilities.isWebGL2 ) {
  9263. extension = gl;
  9264. } else {
  9265. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9266. if ( extension === null ) {
  9267. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9268. return;
  9269. }
  9270. }
  9271. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9272. info.update( count, mode, geometry.maxInstancedCount );
  9273. }
  9274. //
  9275. this.setMode = setMode;
  9276. this.setIndex = setIndex;
  9277. this.render = render;
  9278. this.renderInstances = renderInstances;
  9279. }
  9280. /**
  9281. * @author Mugen87 / https://github.com/Mugen87
  9282. */
  9283. function WebGLInfo( gl ) {
  9284. var memory = {
  9285. geometries: 0,
  9286. textures: 0
  9287. };
  9288. var render = {
  9289. frame: 0,
  9290. calls: 0,
  9291. triangles: 0,
  9292. points: 0,
  9293. lines: 0
  9294. };
  9295. function update( count, mode, instanceCount ) {
  9296. instanceCount = instanceCount || 1;
  9297. render.calls ++;
  9298. switch ( mode ) {
  9299. case 4:
  9300. render.triangles += instanceCount * ( count / 3 );
  9301. break;
  9302. case 5:
  9303. case 6:
  9304. render.triangles += instanceCount * ( count - 2 );
  9305. break;
  9306. case 1:
  9307. render.lines += instanceCount * ( count / 2 );
  9308. break;
  9309. case 3:
  9310. render.lines += instanceCount * ( count - 1 );
  9311. break;
  9312. case 2:
  9313. render.lines += instanceCount * count;
  9314. break;
  9315. case 0:
  9316. render.points += instanceCount * count;
  9317. break;
  9318. default:
  9319. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9320. break;
  9321. }
  9322. }
  9323. function reset() {
  9324. render.frame ++;
  9325. render.calls = 0;
  9326. render.triangles = 0;
  9327. render.points = 0;
  9328. render.lines = 0;
  9329. }
  9330. return {
  9331. memory: memory,
  9332. render: render,
  9333. programs: null,
  9334. autoReset: true,
  9335. reset: reset,
  9336. update: update
  9337. };
  9338. }
  9339. /**
  9340. * @author mrdoob / http://mrdoob.com/
  9341. */
  9342. function absNumericalSort( a, b ) {
  9343. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9344. }
  9345. function WebGLMorphtargets( gl ) {
  9346. var influencesList = {};
  9347. var morphInfluences = new Float32Array( 8 );
  9348. function update( object, geometry, material, program ) {
  9349. var objectInfluences = object.morphTargetInfluences;
  9350. var length = objectInfluences.length;
  9351. var influences = influencesList[ geometry.id ];
  9352. if ( influences === undefined ) {
  9353. // initialise list
  9354. influences = [];
  9355. for ( var i = 0; i < length; i ++ ) {
  9356. influences[ i ] = [ i, 0 ];
  9357. }
  9358. influencesList[ geometry.id ] = influences;
  9359. }
  9360. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9361. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9362. // Remove current morphAttributes
  9363. for ( var i = 0; i < length; i ++ ) {
  9364. var influence = influences[ i ];
  9365. if ( influence[ 1 ] !== 0 ) {
  9366. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9367. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9368. }
  9369. }
  9370. // Collect influences
  9371. for ( var i = 0; i < length; i ++ ) {
  9372. var influence = influences[ i ];
  9373. influence[ 0 ] = i;
  9374. influence[ 1 ] = objectInfluences[ i ];
  9375. }
  9376. influences.sort( absNumericalSort );
  9377. // Add morphAttributes
  9378. for ( var i = 0; i < 8; i ++ ) {
  9379. var influence = influences[ i ];
  9380. if ( influence ) {
  9381. var index = influence[ 0 ];
  9382. var value = influence[ 1 ];
  9383. if ( value ) {
  9384. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9385. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9386. morphInfluences[ i ] = value;
  9387. continue;
  9388. }
  9389. }
  9390. morphInfluences[ i ] = 0;
  9391. }
  9392. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9393. }
  9394. return {
  9395. update: update
  9396. };
  9397. }
  9398. /**
  9399. * @author mrdoob / http://mrdoob.com/
  9400. */
  9401. function WebGLObjects( geometries, info ) {
  9402. var updateList = {};
  9403. function update( object ) {
  9404. var frame = info.render.frame;
  9405. var geometry = object.geometry;
  9406. var buffergeometry = geometries.get( object, geometry );
  9407. // Update once per frame
  9408. if ( updateList[ buffergeometry.id ] !== frame ) {
  9409. if ( geometry.isGeometry ) {
  9410. buffergeometry.updateFromObject( object );
  9411. }
  9412. geometries.update( buffergeometry );
  9413. updateList[ buffergeometry.id ] = frame;
  9414. }
  9415. return buffergeometry;
  9416. }
  9417. function dispose() {
  9418. updateList = {};
  9419. }
  9420. return {
  9421. update: update,
  9422. dispose: dispose
  9423. };
  9424. }
  9425. /**
  9426. * @author mrdoob / http://mrdoob.com/
  9427. */
  9428. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9429. images = images !== undefined ? images : [];
  9430. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9431. format = format !== undefined ? format : RGBFormat;
  9432. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9433. this.flipY = false;
  9434. }
  9435. CubeTexture.prototype = Object.create( Texture.prototype );
  9436. CubeTexture.prototype.constructor = CubeTexture;
  9437. CubeTexture.prototype.isCubeTexture = true;
  9438. Object.defineProperty( CubeTexture.prototype, 'images', {
  9439. get: function () {
  9440. return this.image;
  9441. },
  9442. set: function ( value ) {
  9443. this.image = value;
  9444. }
  9445. } );
  9446. /**
  9447. * @author Takahiro https://github.com/takahirox
  9448. */
  9449. function DataTexture2DArray( data, width, height, depth ) {
  9450. Texture.call( this, null );
  9451. this.image = { data: data, width: width, height: height, depth: depth };
  9452. this.magFilter = NearestFilter;
  9453. this.minFilter = NearestFilter;
  9454. this.wrapR = ClampToEdgeWrapping;
  9455. this.generateMipmaps = false;
  9456. this.flipY = false;
  9457. }
  9458. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9459. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9460. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9461. /**
  9462. * @author Artur Trzesiok
  9463. */
  9464. function DataTexture3D( data, width, height, depth ) {
  9465. // We're going to add .setXXX() methods for setting properties later.
  9466. // Users can still set in DataTexture3D directly.
  9467. //
  9468. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9469. // texture.anisotropy = 16;
  9470. //
  9471. // See #14839
  9472. Texture.call( this, null );
  9473. this.image = { data: data, width: width, height: height, depth: depth };
  9474. this.magFilter = NearestFilter;
  9475. this.minFilter = NearestFilter;
  9476. this.wrapR = ClampToEdgeWrapping;
  9477. this.generateMipmaps = false;
  9478. this.flipY = false;
  9479. }
  9480. DataTexture3D.prototype = Object.create( Texture.prototype );
  9481. DataTexture3D.prototype.constructor = DataTexture3D;
  9482. DataTexture3D.prototype.isDataTexture3D = true;
  9483. /**
  9484. * @author tschw
  9485. * @author Mugen87 / https://github.com/Mugen87
  9486. * @author mrdoob / http://mrdoob.com/
  9487. *
  9488. * Uniforms of a program.
  9489. * Those form a tree structure with a special top-level container for the root,
  9490. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9491. *
  9492. *
  9493. * Properties of inner nodes including the top-level container:
  9494. *
  9495. * .seq - array of nested uniforms
  9496. * .map - nested uniforms by name
  9497. *
  9498. *
  9499. * Methods of all nodes except the top-level container:
  9500. *
  9501. * .setValue( gl, value, [textures] )
  9502. *
  9503. * uploads a uniform value(s)
  9504. * the 'textures' parameter is needed for sampler uniforms
  9505. *
  9506. *
  9507. * Static methods of the top-level container (textures factorizations):
  9508. *
  9509. * .upload( gl, seq, values, textures )
  9510. *
  9511. * sets uniforms in 'seq' to 'values[id].value'
  9512. *
  9513. * .seqWithValue( seq, values ) : filteredSeq
  9514. *
  9515. * filters 'seq' entries with corresponding entry in values
  9516. *
  9517. *
  9518. * Methods of the top-level container (textures factorizations):
  9519. *
  9520. * .setValue( gl, name, value, textures )
  9521. *
  9522. * sets uniform with name 'name' to 'value'
  9523. *
  9524. * .setOptional( gl, obj, prop )
  9525. *
  9526. * like .set for an optional property of the object
  9527. *
  9528. */
  9529. var emptyTexture = new Texture();
  9530. var emptyTexture2dArray = new DataTexture2DArray();
  9531. var emptyTexture3d = new DataTexture3D();
  9532. var emptyCubeTexture = new CubeTexture();
  9533. // --- Utilities ---
  9534. // Array Caches (provide typed arrays for temporary by size)
  9535. var arrayCacheF32 = [];
  9536. var arrayCacheI32 = [];
  9537. // Float32Array caches used for uploading Matrix uniforms
  9538. var mat4array = new Float32Array( 16 );
  9539. var mat3array = new Float32Array( 9 );
  9540. var mat2array = new Float32Array( 4 );
  9541. // Flattening for arrays of vectors and matrices
  9542. function flatten( array, nBlocks, blockSize ) {
  9543. var firstElem = array[ 0 ];
  9544. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9545. // unoptimized: ! isNaN( firstElem )
  9546. // see http://jacksondunstan.com/articles/983
  9547. var n = nBlocks * blockSize,
  9548. r = arrayCacheF32[ n ];
  9549. if ( r === undefined ) {
  9550. r = new Float32Array( n );
  9551. arrayCacheF32[ n ] = r;
  9552. }
  9553. if ( nBlocks !== 0 ) {
  9554. firstElem.toArray( r, 0 );
  9555. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9556. offset += blockSize;
  9557. array[ i ].toArray( r, offset );
  9558. }
  9559. }
  9560. return r;
  9561. }
  9562. function arraysEqual( a, b ) {
  9563. if ( a.length !== b.length ) return false;
  9564. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9565. if ( a[ i ] !== b[ i ] ) return false;
  9566. }
  9567. return true;
  9568. }
  9569. function copyArray( a, b ) {
  9570. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9571. a[ i ] = b[ i ];
  9572. }
  9573. }
  9574. // Texture unit allocation
  9575. function allocTexUnits( textures, n ) {
  9576. var r = arrayCacheI32[ n ];
  9577. if ( r === undefined ) {
  9578. r = new Int32Array( n );
  9579. arrayCacheI32[ n ] = r;
  9580. }
  9581. for ( var i = 0; i !== n; ++ i )
  9582. r[ i ] = textures.allocateTextureUnit();
  9583. return r;
  9584. }
  9585. // --- Setters ---
  9586. // Note: Defining these methods externally, because they come in a bunch
  9587. // and this way their names minify.
  9588. // Single scalar
  9589. function setValue1f( gl, v ) {
  9590. var cache = this.cache;
  9591. if ( cache[ 0 ] === v ) return;
  9592. gl.uniform1f( this.addr, v );
  9593. cache[ 0 ] = v;
  9594. }
  9595. function setValue1i( gl, v ) {
  9596. var cache = this.cache;
  9597. if ( cache[ 0 ] === v ) return;
  9598. gl.uniform1i( this.addr, v );
  9599. cache[ 0 ] = v;
  9600. }
  9601. // Single float vector (from flat array or THREE.VectorN)
  9602. function setValue2fv( gl, v ) {
  9603. var cache = this.cache;
  9604. if ( v.x !== undefined ) {
  9605. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9606. gl.uniform2f( this.addr, v.x, v.y );
  9607. cache[ 0 ] = v.x;
  9608. cache[ 1 ] = v.y;
  9609. }
  9610. } else {
  9611. if ( arraysEqual( cache, v ) ) return;
  9612. gl.uniform2fv( this.addr, v );
  9613. copyArray( cache, v );
  9614. }
  9615. }
  9616. function setValue3fv( gl, v ) {
  9617. var cache = this.cache;
  9618. if ( v.x !== undefined ) {
  9619. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9620. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9621. cache[ 0 ] = v.x;
  9622. cache[ 1 ] = v.y;
  9623. cache[ 2 ] = v.z;
  9624. }
  9625. } else if ( v.r !== undefined ) {
  9626. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9627. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9628. cache[ 0 ] = v.r;
  9629. cache[ 1 ] = v.g;
  9630. cache[ 2 ] = v.b;
  9631. }
  9632. } else {
  9633. if ( arraysEqual( cache, v ) ) return;
  9634. gl.uniform3fv( this.addr, v );
  9635. copyArray( cache, v );
  9636. }
  9637. }
  9638. function setValue4fv( gl, v ) {
  9639. var cache = this.cache;
  9640. if ( v.x !== undefined ) {
  9641. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9642. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9643. cache[ 0 ] = v.x;
  9644. cache[ 1 ] = v.y;
  9645. cache[ 2 ] = v.z;
  9646. cache[ 3 ] = v.w;
  9647. }
  9648. } else {
  9649. if ( arraysEqual( cache, v ) ) return;
  9650. gl.uniform4fv( this.addr, v );
  9651. copyArray( cache, v );
  9652. }
  9653. }
  9654. // Single matrix (from flat array or MatrixN)
  9655. function setValue2fm( gl, v ) {
  9656. var cache = this.cache;
  9657. var elements = v.elements;
  9658. if ( elements === undefined ) {
  9659. if ( arraysEqual( cache, v ) ) return;
  9660. gl.uniformMatrix2fv( this.addr, false, v );
  9661. copyArray( cache, v );
  9662. } else {
  9663. if ( arraysEqual( cache, elements ) ) return;
  9664. mat2array.set( elements );
  9665. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9666. copyArray( cache, elements );
  9667. }
  9668. }
  9669. function setValue3fm( gl, v ) {
  9670. var cache = this.cache;
  9671. var elements = v.elements;
  9672. if ( elements === undefined ) {
  9673. if ( arraysEqual( cache, v ) ) return;
  9674. gl.uniformMatrix3fv( this.addr, false, v );
  9675. copyArray( cache, v );
  9676. } else {
  9677. if ( arraysEqual( cache, elements ) ) return;
  9678. mat3array.set( elements );
  9679. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9680. copyArray( cache, elements );
  9681. }
  9682. }
  9683. function setValue4fm( gl, v ) {
  9684. var cache = this.cache;
  9685. var elements = v.elements;
  9686. if ( elements === undefined ) {
  9687. if ( arraysEqual( cache, v ) ) return;
  9688. gl.uniformMatrix4fv( this.addr, false, v );
  9689. copyArray( cache, v );
  9690. } else {
  9691. if ( arraysEqual( cache, elements ) ) return;
  9692. mat4array.set( elements );
  9693. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9694. copyArray( cache, elements );
  9695. }
  9696. }
  9697. // Single texture (2D / Cube)
  9698. function setValueT1( gl, v, textures ) {
  9699. var cache = this.cache;
  9700. var unit = textures.allocateTextureUnit();
  9701. if ( cache[ 0 ] !== unit ) {
  9702. gl.uniform1i( this.addr, unit );
  9703. cache[ 0 ] = unit;
  9704. }
  9705. textures.safeSetTexture2D( v || emptyTexture, unit );
  9706. }
  9707. function setValueT2DArray1( gl, v, textures ) {
  9708. var cache = this.cache;
  9709. var unit = textures.allocateTextureUnit();
  9710. if ( cache[ 0 ] !== unit ) {
  9711. gl.uniform1i( this.addr, unit );
  9712. cache[ 0 ] = unit;
  9713. }
  9714. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9715. }
  9716. function setValueT3D1( gl, v, textures ) {
  9717. var cache = this.cache;
  9718. var unit = textures.allocateTextureUnit();
  9719. if ( cache[ 0 ] !== unit ) {
  9720. gl.uniform1i( this.addr, unit );
  9721. cache[ 0 ] = unit;
  9722. }
  9723. textures.setTexture3D( v || emptyTexture3d, unit );
  9724. }
  9725. function setValueT6( gl, v, textures ) {
  9726. var cache = this.cache;
  9727. var unit = textures.allocateTextureUnit();
  9728. if ( cache[ 0 ] !== unit ) {
  9729. gl.uniform1i( this.addr, unit );
  9730. cache[ 0 ] = unit;
  9731. }
  9732. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9733. }
  9734. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9735. function setValue2iv( gl, v ) {
  9736. var cache = this.cache;
  9737. if ( arraysEqual( cache, v ) ) return;
  9738. gl.uniform2iv( this.addr, v );
  9739. copyArray( cache, v );
  9740. }
  9741. function setValue3iv( gl, v ) {
  9742. var cache = this.cache;
  9743. if ( arraysEqual( cache, v ) ) return;
  9744. gl.uniform3iv( this.addr, v );
  9745. copyArray( cache, v );
  9746. }
  9747. function setValue4iv( gl, v ) {
  9748. var cache = this.cache;
  9749. if ( arraysEqual( cache, v ) ) return;
  9750. gl.uniform4iv( this.addr, v );
  9751. copyArray( cache, v );
  9752. }
  9753. // Helper to pick the right setter for the singular case
  9754. function getSingularSetter( type ) {
  9755. switch ( type ) {
  9756. case 0x1406: return setValue1f; // FLOAT
  9757. case 0x8b50: return setValue2fv; // _VEC2
  9758. case 0x8b51: return setValue3fv; // _VEC3
  9759. case 0x8b52: return setValue4fv; // _VEC4
  9760. case 0x8b5a: return setValue2fm; // _MAT2
  9761. case 0x8b5b: return setValue3fm; // _MAT3
  9762. case 0x8b5c: return setValue4fm; // _MAT4
  9763. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9764. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  9765. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9766. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  9767. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9768. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9769. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9770. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9771. }
  9772. }
  9773. // Array of scalars
  9774. function setValue1fv( gl, v ) {
  9775. var cache = this.cache;
  9776. if ( arraysEqual( cache, v ) ) return;
  9777. gl.uniform1fv( this.addr, v );
  9778. copyArray( cache, v );
  9779. }
  9780. function setValue1iv( gl, v ) {
  9781. var cache = this.cache;
  9782. if ( arraysEqual( cache, v ) ) return;
  9783. gl.uniform1iv( this.addr, v );
  9784. copyArray( cache, v );
  9785. }
  9786. // Array of vectors (flat or from THREE classes)
  9787. function setValueV2a( gl, v ) {
  9788. var cache = this.cache;
  9789. var data = flatten( v, this.size, 2 );
  9790. if ( arraysEqual( cache, data ) ) return;
  9791. gl.uniform2fv( this.addr, data );
  9792. this.updateCache( data );
  9793. }
  9794. function setValueV3a( gl, v ) {
  9795. var cache = this.cache;
  9796. var data = flatten( v, this.size, 3 );
  9797. if ( arraysEqual( cache, data ) ) return;
  9798. gl.uniform3fv( this.addr, data );
  9799. this.updateCache( data );
  9800. }
  9801. function setValueV4a( gl, v ) {
  9802. var cache = this.cache;
  9803. var data = flatten( v, this.size, 4 );
  9804. if ( arraysEqual( cache, data ) ) return;
  9805. gl.uniform4fv( this.addr, data );
  9806. this.updateCache( data );
  9807. }
  9808. // Array of matrices (flat or from THREE clases)
  9809. function setValueM2a( gl, v ) {
  9810. var cache = this.cache;
  9811. var data = flatten( v, this.size, 4 );
  9812. if ( arraysEqual( cache, data ) ) return;
  9813. gl.uniformMatrix2fv( this.addr, false, data );
  9814. this.updateCache( data );
  9815. }
  9816. function setValueM3a( gl, v ) {
  9817. var cache = this.cache;
  9818. var data = flatten( v, this.size, 9 );
  9819. if ( arraysEqual( cache, data ) ) return;
  9820. gl.uniformMatrix3fv( this.addr, false, data );
  9821. this.updateCache( data );
  9822. }
  9823. function setValueM4a( gl, v ) {
  9824. var cache = this.cache;
  9825. var data = flatten( v, this.size, 16 );
  9826. if ( arraysEqual( cache, data ) ) return;
  9827. gl.uniformMatrix4fv( this.addr, false, data );
  9828. this.updateCache( data );
  9829. }
  9830. // Array of textures (2D / Cube)
  9831. function setValueT1a( gl, v, textures ) {
  9832. var cache = this.cache;
  9833. var n = v.length;
  9834. var units = allocTexUnits( textures, n );
  9835. if ( arraysEqual( cache, units ) === false ) {
  9836. gl.uniform1iv( this.addr, units );
  9837. copyArray( cache, units );
  9838. }
  9839. for ( var i = 0; i !== n; ++ i ) {
  9840. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9841. }
  9842. }
  9843. function setValueT6a( gl, v, textures ) {
  9844. var cache = this.cache;
  9845. var n = v.length;
  9846. var units = allocTexUnits( textures, n );
  9847. if ( arraysEqual( cache, units ) === false ) {
  9848. gl.uniform1iv( this.addr, units );
  9849. copyArray( cache, units );
  9850. }
  9851. for ( var i = 0; i !== n; ++ i ) {
  9852. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9853. }
  9854. }
  9855. // Helper to pick the right setter for a pure (bottom-level) array
  9856. function getPureArraySetter( type ) {
  9857. switch ( type ) {
  9858. case 0x1406: return setValue1fv; // FLOAT
  9859. case 0x8b50: return setValueV2a; // _VEC2
  9860. case 0x8b51: return setValueV3a; // _VEC3
  9861. case 0x8b52: return setValueV4a; // _VEC4
  9862. case 0x8b5a: return setValueM2a; // _MAT2
  9863. case 0x8b5b: return setValueM3a; // _MAT3
  9864. case 0x8b5c: return setValueM4a; // _MAT4
  9865. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9866. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9867. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9868. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9869. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9870. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9871. }
  9872. }
  9873. // --- Uniform Classes ---
  9874. function SingleUniform( id, activeInfo, addr ) {
  9875. this.id = id;
  9876. this.addr = addr;
  9877. this.cache = [];
  9878. this.setValue = getSingularSetter( activeInfo.type );
  9879. // this.path = activeInfo.name; // DEBUG
  9880. }
  9881. function PureArrayUniform( id, activeInfo, addr ) {
  9882. this.id = id;
  9883. this.addr = addr;
  9884. this.cache = [];
  9885. this.size = activeInfo.size;
  9886. this.setValue = getPureArraySetter( activeInfo.type );
  9887. // this.path = activeInfo.name; // DEBUG
  9888. }
  9889. PureArrayUniform.prototype.updateCache = function ( data ) {
  9890. var cache = this.cache;
  9891. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9892. this.cache = new Float32Array( data.length );
  9893. }
  9894. copyArray( cache, data );
  9895. };
  9896. function StructuredUniform( id ) {
  9897. this.id = id;
  9898. this.seq = [];
  9899. this.map = {};
  9900. }
  9901. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9902. var seq = this.seq;
  9903. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9904. var u = seq[ i ];
  9905. u.setValue( gl, value[ u.id ], textures );
  9906. }
  9907. };
  9908. // --- Top-level ---
  9909. // Parser - builds up the property tree from the path strings
  9910. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9911. // extracts
  9912. // - the identifier (member name or array index)
  9913. // - followed by an optional right bracket (found when array index)
  9914. // - followed by an optional left bracket or dot (type of subscript)
  9915. //
  9916. // Note: These portions can be read in a non-overlapping fashion and
  9917. // allow straightforward parsing of the hierarchy that WebGL encodes
  9918. // in the uniform names.
  9919. function addUniform( container, uniformObject ) {
  9920. container.seq.push( uniformObject );
  9921. container.map[ uniformObject.id ] = uniformObject;
  9922. }
  9923. function parseUniform( activeInfo, addr, container ) {
  9924. var path = activeInfo.name,
  9925. pathLength = path.length;
  9926. // reset RegExp object, because of the early exit of a previous run
  9927. RePathPart.lastIndex = 0;
  9928. while ( true ) {
  9929. var match = RePathPart.exec( path ),
  9930. matchEnd = RePathPart.lastIndex,
  9931. id = match[ 1 ],
  9932. idIsIndex = match[ 2 ] === ']',
  9933. subscript = match[ 3 ];
  9934. if ( idIsIndex ) id = id | 0; // convert to integer
  9935. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9936. // bare name or "pure" bottom-level array "[0]" suffix
  9937. addUniform( container, subscript === undefined ?
  9938. new SingleUniform( id, activeInfo, addr ) :
  9939. new PureArrayUniform( id, activeInfo, addr ) );
  9940. break;
  9941. } else {
  9942. // step into inner node / create it in case it doesn't exist
  9943. var map = container.map, next = map[ id ];
  9944. if ( next === undefined ) {
  9945. next = new StructuredUniform( id );
  9946. addUniform( container, next );
  9947. }
  9948. container = next;
  9949. }
  9950. }
  9951. }
  9952. // Root Container
  9953. function WebGLUniforms( gl, program ) {
  9954. this.seq = [];
  9955. this.map = {};
  9956. var n = gl.getProgramParameter( program, 35718 );
  9957. for ( var i = 0; i < n; ++ i ) {
  9958. var info = gl.getActiveUniform( program, i ),
  9959. addr = gl.getUniformLocation( program, info.name );
  9960. parseUniform( info, addr, this );
  9961. }
  9962. }
  9963. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9964. var u = this.map[ name ];
  9965. if ( u !== undefined ) u.setValue( gl, value, textures );
  9966. };
  9967. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9968. var v = object[ name ];
  9969. if ( v !== undefined ) this.setValue( gl, name, v );
  9970. };
  9971. // Static interface
  9972. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9973. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9974. var u = seq[ i ],
  9975. v = values[ u.id ];
  9976. if ( v.needsUpdate !== false ) {
  9977. // note: always updating when .needsUpdate is undefined
  9978. u.setValue( gl, v.value, textures );
  9979. }
  9980. }
  9981. };
  9982. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9983. var r = [];
  9984. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9985. var u = seq[ i ];
  9986. if ( u.id in values ) r.push( u );
  9987. }
  9988. return r;
  9989. };
  9990. /**
  9991. * @author mrdoob / http://mrdoob.com/
  9992. */
  9993. function addLineNumbers( string ) {
  9994. var lines = string.split( '\n' );
  9995. for ( var i = 0; i < lines.length; i ++ ) {
  9996. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9997. }
  9998. return lines.join( '\n' );
  9999. }
  10000. function WebGLShader( gl, type, string ) {
  10001. var shader = gl.createShader( type );
  10002. gl.shaderSource( shader, string );
  10003. gl.compileShader( shader );
  10004. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  10005. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  10006. }
  10007. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  10008. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  10009. }
  10010. // --enable-privileged-webgl-extension
  10011. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10012. return shader;
  10013. }
  10014. /**
  10015. * @author mrdoob / http://mrdoob.com/
  10016. */
  10017. var programIdCount = 0;
  10018. function getEncodingComponents( encoding ) {
  10019. switch ( encoding ) {
  10020. case LinearEncoding:
  10021. return [ 'Linear', '( value )' ];
  10022. case sRGBEncoding:
  10023. return [ 'sRGB', '( value )' ];
  10024. case RGBEEncoding:
  10025. return [ 'RGBE', '( value )' ];
  10026. case RGBM7Encoding:
  10027. return [ 'RGBM', '( value, 7.0 )' ];
  10028. case RGBM16Encoding:
  10029. return [ 'RGBM', '( value, 16.0 )' ];
  10030. case RGBDEncoding:
  10031. return [ 'RGBD', '( value, 256.0 )' ];
  10032. case GammaEncoding:
  10033. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10034. default:
  10035. throw new Error( 'unsupported encoding: ' + encoding );
  10036. }
  10037. }
  10038. function getTexelDecodingFunction( functionName, encoding ) {
  10039. var components = getEncodingComponents( encoding );
  10040. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10041. }
  10042. function getTexelEncodingFunction( functionName, encoding ) {
  10043. var components = getEncodingComponents( encoding );
  10044. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10045. }
  10046. function getToneMappingFunction( functionName, toneMapping ) {
  10047. var toneMappingName;
  10048. switch ( toneMapping ) {
  10049. case LinearToneMapping:
  10050. toneMappingName = 'Linear';
  10051. break;
  10052. case ReinhardToneMapping:
  10053. toneMappingName = 'Reinhard';
  10054. break;
  10055. case Uncharted2ToneMapping:
  10056. toneMappingName = 'Uncharted2';
  10057. break;
  10058. case CineonToneMapping:
  10059. toneMappingName = 'OptimizedCineon';
  10060. break;
  10061. case ACESFilmicToneMapping:
  10062. toneMappingName = 'ACESFilmic';
  10063. break;
  10064. default:
  10065. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10066. }
  10067. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10068. }
  10069. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10070. extensions = extensions || {};
  10071. var chunks = [
  10072. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10073. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10074. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10075. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10076. ];
  10077. return chunks.filter( filterEmptyLine ).join( '\n' );
  10078. }
  10079. function generateDefines( defines ) {
  10080. var chunks = [];
  10081. for ( var name in defines ) {
  10082. var value = defines[ name ];
  10083. if ( value === false ) continue;
  10084. chunks.push( '#define ' + name + ' ' + value );
  10085. }
  10086. return chunks.join( '\n' );
  10087. }
  10088. function fetchAttributeLocations( gl, program ) {
  10089. var attributes = {};
  10090. var n = gl.getProgramParameter( program, 35721 );
  10091. for ( var i = 0; i < n; i ++ ) {
  10092. var info = gl.getActiveAttrib( program, i );
  10093. var name = info.name;
  10094. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10095. attributes[ name ] = gl.getAttribLocation( program, name );
  10096. }
  10097. return attributes;
  10098. }
  10099. function filterEmptyLine( string ) {
  10100. return string !== '';
  10101. }
  10102. function replaceLightNums( string, parameters ) {
  10103. return string
  10104. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10105. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10106. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10107. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10108. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10109. }
  10110. function replaceClippingPlaneNums( string, parameters ) {
  10111. return string
  10112. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10113. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10114. }
  10115. function parseIncludes( string ) {
  10116. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10117. function replace( match, include ) {
  10118. var replace = ShaderChunk[ include ];
  10119. if ( replace === undefined ) {
  10120. throw new Error( 'Can not resolve #include <' + include + '>' );
  10121. }
  10122. return parseIncludes( replace );
  10123. }
  10124. return string.replace( pattern, replace );
  10125. }
  10126. function unrollLoops( string ) {
  10127. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10128. function replace( match, start, end, snippet ) {
  10129. var unroll = '';
  10130. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10131. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10132. }
  10133. return unroll;
  10134. }
  10135. return string.replace( pattern, replace );
  10136. }
  10137. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures ) {
  10138. var gl = renderer.context;
  10139. var defines = material.defines;
  10140. var vertexShader = shader.vertexShader;
  10141. var fragmentShader = shader.fragmentShader;
  10142. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10143. if ( parameters.shadowMapType === PCFShadowMap ) {
  10144. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10145. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10146. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10147. }
  10148. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10149. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10150. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10151. if ( parameters.envMap ) {
  10152. switch ( material.envMap.mapping ) {
  10153. case CubeReflectionMapping:
  10154. case CubeRefractionMapping:
  10155. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10156. break;
  10157. case CubeUVReflectionMapping:
  10158. case CubeUVRefractionMapping:
  10159. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10160. break;
  10161. case EquirectangularReflectionMapping:
  10162. case EquirectangularRefractionMapping:
  10163. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10164. break;
  10165. case SphericalReflectionMapping:
  10166. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10167. break;
  10168. }
  10169. switch ( material.envMap.mapping ) {
  10170. case CubeRefractionMapping:
  10171. case EquirectangularRefractionMapping:
  10172. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10173. break;
  10174. }
  10175. switch ( material.combine ) {
  10176. case MultiplyOperation:
  10177. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10178. break;
  10179. case MixOperation:
  10180. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10181. break;
  10182. case AddOperation:
  10183. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10184. break;
  10185. }
  10186. }
  10187. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10188. // console.log( 'building new program ' );
  10189. //
  10190. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10191. var customDefines = generateDefines( defines );
  10192. //
  10193. var program = gl.createProgram();
  10194. var prefixVertex, prefixFragment;
  10195. if ( material.isRawShaderMaterial ) {
  10196. prefixVertex = [
  10197. customDefines
  10198. ].filter( filterEmptyLine ).join( '\n' );
  10199. if ( prefixVertex.length > 0 ) {
  10200. prefixVertex += '\n';
  10201. }
  10202. prefixFragment = [
  10203. customExtensions,
  10204. customDefines
  10205. ].filter( filterEmptyLine ).join( '\n' );
  10206. if ( prefixFragment.length > 0 ) {
  10207. prefixFragment += '\n';
  10208. }
  10209. } else {
  10210. prefixVertex = [
  10211. 'precision ' + parameters.precision + ' float;',
  10212. 'precision ' + parameters.precision + ' int;',
  10213. '#define SHADER_NAME ' + shader.name,
  10214. customDefines,
  10215. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10216. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10217. '#define MAX_BONES ' + parameters.maxBones,
  10218. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10219. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10220. parameters.map ? '#define USE_MAP' : '',
  10221. parameters.envMap ? '#define USE_ENVMAP' : '',
  10222. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10223. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10224. parameters.aoMap ? '#define USE_AOMAP' : '',
  10225. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10226. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10227. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10228. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10229. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10230. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10231. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10232. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10233. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10234. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10235. parameters.vertexColors ? '#define USE_COLOR' : '',
  10236. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10237. parameters.skinning ? '#define USE_SKINNING' : '',
  10238. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10239. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10240. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10241. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10242. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10243. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10244. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10245. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10246. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10247. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10248. 'uniform mat4 modelMatrix;',
  10249. 'uniform mat4 modelViewMatrix;',
  10250. 'uniform mat4 projectionMatrix;',
  10251. 'uniform mat4 viewMatrix;',
  10252. 'uniform mat3 normalMatrix;',
  10253. 'uniform vec3 cameraPosition;',
  10254. 'attribute vec3 position;',
  10255. 'attribute vec3 normal;',
  10256. 'attribute vec2 uv;',
  10257. '#ifdef USE_TANGENT',
  10258. ' attribute vec4 tangent;',
  10259. '#endif',
  10260. '#ifdef USE_COLOR',
  10261. ' attribute vec3 color;',
  10262. '#endif',
  10263. '#ifdef USE_MORPHTARGETS',
  10264. ' attribute vec3 morphTarget0;',
  10265. ' attribute vec3 morphTarget1;',
  10266. ' attribute vec3 morphTarget2;',
  10267. ' attribute vec3 morphTarget3;',
  10268. ' #ifdef USE_MORPHNORMALS',
  10269. ' attribute vec3 morphNormal0;',
  10270. ' attribute vec3 morphNormal1;',
  10271. ' attribute vec3 morphNormal2;',
  10272. ' attribute vec3 morphNormal3;',
  10273. ' #else',
  10274. ' attribute vec3 morphTarget4;',
  10275. ' attribute vec3 morphTarget5;',
  10276. ' attribute vec3 morphTarget6;',
  10277. ' attribute vec3 morphTarget7;',
  10278. ' #endif',
  10279. '#endif',
  10280. '#ifdef USE_SKINNING',
  10281. ' attribute vec4 skinIndex;',
  10282. ' attribute vec4 skinWeight;',
  10283. '#endif',
  10284. '\n'
  10285. ].filter( filterEmptyLine ).join( '\n' );
  10286. prefixFragment = [
  10287. customExtensions,
  10288. 'precision ' + parameters.precision + ' float;',
  10289. 'precision ' + parameters.precision + ' int;',
  10290. '#define SHADER_NAME ' + shader.name,
  10291. customDefines,
  10292. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10293. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10294. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10295. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10296. parameters.map ? '#define USE_MAP' : '',
  10297. parameters.matcap ? '#define USE_MATCAP' : '',
  10298. parameters.envMap ? '#define USE_ENVMAP' : '',
  10299. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10300. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10301. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10302. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10303. parameters.aoMap ? '#define USE_AOMAP' : '',
  10304. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10305. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10306. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10307. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10308. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10309. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10310. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10311. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10312. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10313. parameters.vertexColors ? '#define USE_COLOR' : '',
  10314. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10315. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10316. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10317. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10318. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10319. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10320. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10321. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10322. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10323. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10324. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10325. 'uniform mat4 viewMatrix;',
  10326. 'uniform vec3 cameraPosition;',
  10327. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10328. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10329. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10330. parameters.dithering ? '#define DITHERING' : '',
  10331. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10332. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10333. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10334. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10335. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10336. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10337. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10338. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10339. '\n'
  10340. ].filter( filterEmptyLine ).join( '\n' );
  10341. }
  10342. vertexShader = parseIncludes( vertexShader );
  10343. vertexShader = replaceLightNums( vertexShader, parameters );
  10344. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10345. fragmentShader = parseIncludes( fragmentShader );
  10346. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10347. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10348. vertexShader = unrollLoops( vertexShader );
  10349. fragmentShader = unrollLoops( fragmentShader );
  10350. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10351. var isGLSL3ShaderMaterial = false;
  10352. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10353. if ( material.isShaderMaterial &&
  10354. vertexShader.match( versionRegex ) !== null &&
  10355. fragmentShader.match( versionRegex ) !== null ) {
  10356. isGLSL3ShaderMaterial = true;
  10357. vertexShader = vertexShader.replace( versionRegex, '' );
  10358. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10359. }
  10360. // GLSL 3.0 conversion
  10361. prefixVertex = [
  10362. '#version 300 es\n',
  10363. '#define attribute in',
  10364. '#define varying out',
  10365. '#define texture2D texture'
  10366. ].join( '\n' ) + '\n' + prefixVertex;
  10367. prefixFragment = [
  10368. '#version 300 es\n',
  10369. '#define varying in',
  10370. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10371. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10372. '#define gl_FragDepthEXT gl_FragDepth',
  10373. '#define texture2D texture',
  10374. '#define textureCube texture',
  10375. '#define texture2DProj textureProj',
  10376. '#define texture2DLodEXT textureLod',
  10377. '#define texture2DProjLodEXT textureProjLod',
  10378. '#define textureCubeLodEXT textureLod',
  10379. '#define texture2DGradEXT textureGrad',
  10380. '#define texture2DProjGradEXT textureProjGrad',
  10381. '#define textureCubeGradEXT textureGrad'
  10382. ].join( '\n' ) + '\n' + prefixFragment;
  10383. }
  10384. var vertexGlsl = prefixVertex + vertexShader;
  10385. var fragmentGlsl = prefixFragment + fragmentShader;
  10386. // console.log( '*VERTEX*', vertexGlsl );
  10387. // console.log( '*FRAGMENT*', fragmentGlsl );
  10388. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10389. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10390. gl.attachShader( program, glVertexShader );
  10391. gl.attachShader( program, glFragmentShader );
  10392. // Force a particular attribute to index 0.
  10393. if ( material.index0AttributeName !== undefined ) {
  10394. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10395. } else if ( parameters.morphTargets === true ) {
  10396. // programs with morphTargets displace position out of attribute 0
  10397. gl.bindAttribLocation( program, 0, 'position' );
  10398. }
  10399. gl.linkProgram( program );
  10400. var programLog = gl.getProgramInfoLog( program ).trim();
  10401. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10402. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10403. var runnable = true;
  10404. var haveDiagnostics = true;
  10405. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10406. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10407. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10408. runnable = false;
  10409. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10410. } else if ( programLog !== '' ) {
  10411. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10412. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10413. haveDiagnostics = false;
  10414. }
  10415. if ( haveDiagnostics ) {
  10416. this.diagnostics = {
  10417. runnable: runnable,
  10418. material: material,
  10419. programLog: programLog,
  10420. vertexShader: {
  10421. log: vertexLog,
  10422. prefix: prefixVertex
  10423. },
  10424. fragmentShader: {
  10425. log: fragmentLog,
  10426. prefix: prefixFragment
  10427. }
  10428. };
  10429. }
  10430. // clean up
  10431. gl.deleteShader( glVertexShader );
  10432. gl.deleteShader( glFragmentShader );
  10433. // set up caching for uniform locations
  10434. var cachedUniforms;
  10435. this.getUniforms = function () {
  10436. if ( cachedUniforms === undefined ) {
  10437. cachedUniforms = new WebGLUniforms( gl, program, textures );
  10438. }
  10439. return cachedUniforms;
  10440. };
  10441. // set up caching for attribute locations
  10442. var cachedAttributes;
  10443. this.getAttributes = function () {
  10444. if ( cachedAttributes === undefined ) {
  10445. cachedAttributes = fetchAttributeLocations( gl, program );
  10446. }
  10447. return cachedAttributes;
  10448. };
  10449. // free resource
  10450. this.destroy = function () {
  10451. gl.deleteProgram( program );
  10452. this.program = undefined;
  10453. };
  10454. // DEPRECATED
  10455. Object.defineProperties( this, {
  10456. uniforms: {
  10457. get: function () {
  10458. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10459. return this.getUniforms();
  10460. }
  10461. },
  10462. attributes: {
  10463. get: function () {
  10464. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10465. return this.getAttributes();
  10466. }
  10467. }
  10468. } );
  10469. //
  10470. this.name = shader.name;
  10471. this.id = programIdCount ++;
  10472. this.code = code;
  10473. this.usedTimes = 1;
  10474. this.program = program;
  10475. this.vertexShader = glVertexShader;
  10476. this.fragmentShader = glFragmentShader;
  10477. return this;
  10478. }
  10479. /**
  10480. * @author mrdoob / http://mrdoob.com/
  10481. */
  10482. function WebGLPrograms( renderer, extensions, capabilities, textures ) {
  10483. var programs = [];
  10484. var shaderIDs = {
  10485. MeshDepthMaterial: 'depth',
  10486. MeshDistanceMaterial: 'distanceRGBA',
  10487. MeshNormalMaterial: 'normal',
  10488. MeshBasicMaterial: 'basic',
  10489. MeshLambertMaterial: 'lambert',
  10490. MeshPhongMaterial: 'phong',
  10491. MeshToonMaterial: 'phong',
  10492. MeshStandardMaterial: 'physical',
  10493. MeshPhysicalMaterial: 'physical',
  10494. MeshMatcapMaterial: 'matcap',
  10495. LineBasicMaterial: 'basic',
  10496. LineDashedMaterial: 'dashed',
  10497. PointsMaterial: 'points',
  10498. ShadowMaterial: 'shadow',
  10499. SpriteMaterial: 'sprite'
  10500. };
  10501. var parameterNames = [
  10502. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10503. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10504. "roughnessMap", "metalnessMap", "gradientMap",
  10505. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10506. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10507. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10508. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10509. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10510. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10511. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10512. ];
  10513. function allocateBones( object ) {
  10514. var skeleton = object.skeleton;
  10515. var bones = skeleton.bones;
  10516. if ( capabilities.floatVertexTextures ) {
  10517. return 1024;
  10518. } else {
  10519. // default for when object is not specified
  10520. // ( for example when prebuilding shader to be used with multiple objects )
  10521. //
  10522. // - leave some extra space for other uniforms
  10523. // - limit here is ANGLE's 254 max uniform vectors
  10524. // (up to 54 should be safe)
  10525. var nVertexUniforms = capabilities.maxVertexUniforms;
  10526. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10527. var maxBones = Math.min( nVertexMatrices, bones.length );
  10528. if ( maxBones < bones.length ) {
  10529. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10530. return 0;
  10531. }
  10532. return maxBones;
  10533. }
  10534. }
  10535. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10536. var encoding;
  10537. if ( ! map ) {
  10538. encoding = LinearEncoding;
  10539. } else if ( map.isTexture ) {
  10540. encoding = map.encoding;
  10541. } else if ( map.isWebGLRenderTarget ) {
  10542. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10543. encoding = map.texture.encoding;
  10544. }
  10545. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10546. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10547. encoding = GammaEncoding;
  10548. }
  10549. return encoding;
  10550. }
  10551. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10552. var shaderID = shaderIDs[ material.type ];
  10553. // heuristics to create shader parameters according to lights in the scene
  10554. // (not to blow over maxLights budget)
  10555. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10556. var precision = capabilities.precision;
  10557. if ( material.precision !== null ) {
  10558. precision = capabilities.getMaxPrecision( material.precision );
  10559. if ( precision !== material.precision ) {
  10560. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10561. }
  10562. }
  10563. var currentRenderTarget = renderer.getRenderTarget();
  10564. var parameters = {
  10565. shaderID: shaderID,
  10566. precision: precision,
  10567. supportsVertexTextures: capabilities.vertexTextures,
  10568. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10569. map: !! material.map,
  10570. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10571. matcap: !! material.matcap,
  10572. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10573. envMap: !! material.envMap,
  10574. envMapMode: material.envMap && material.envMap.mapping,
  10575. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10576. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10577. lightMap: !! material.lightMap,
  10578. aoMap: !! material.aoMap,
  10579. emissiveMap: !! material.emissiveMap,
  10580. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10581. bumpMap: !! material.bumpMap,
  10582. normalMap: !! material.normalMap,
  10583. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10584. displacementMap: !! material.displacementMap,
  10585. roughnessMap: !! material.roughnessMap,
  10586. metalnessMap: !! material.metalnessMap,
  10587. specularMap: !! material.specularMap,
  10588. alphaMap: !! material.alphaMap,
  10589. gradientMap: !! material.gradientMap,
  10590. combine: material.combine,
  10591. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10592. vertexColors: material.vertexColors,
  10593. fog: !! fog,
  10594. useFog: material.fog,
  10595. fogExp: ( fog && fog.isFogExp2 ),
  10596. flatShading: material.flatShading,
  10597. sizeAttenuation: material.sizeAttenuation,
  10598. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10599. skinning: material.skinning && maxBones > 0,
  10600. maxBones: maxBones,
  10601. useVertexTexture: capabilities.floatVertexTextures,
  10602. morphTargets: material.morphTargets,
  10603. morphNormals: material.morphNormals,
  10604. maxMorphTargets: renderer.maxMorphTargets,
  10605. maxMorphNormals: renderer.maxMorphNormals,
  10606. numDirLights: lights.directional.length,
  10607. numPointLights: lights.point.length,
  10608. numSpotLights: lights.spot.length,
  10609. numRectAreaLights: lights.rectArea.length,
  10610. numHemiLights: lights.hemi.length,
  10611. numClippingPlanes: nClipPlanes,
  10612. numClipIntersection: nClipIntersection,
  10613. dithering: material.dithering,
  10614. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10615. shadowMapType: renderer.shadowMap.type,
  10616. toneMapping: renderer.toneMapping,
  10617. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10618. premultipliedAlpha: material.premultipliedAlpha,
  10619. alphaTest: material.alphaTest,
  10620. doubleSided: material.side === DoubleSide,
  10621. flipSided: material.side === BackSide,
  10622. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10623. };
  10624. return parameters;
  10625. };
  10626. this.getProgramCode = function ( material, parameters ) {
  10627. var array = [];
  10628. if ( parameters.shaderID ) {
  10629. array.push( parameters.shaderID );
  10630. } else {
  10631. array.push( material.fragmentShader );
  10632. array.push( material.vertexShader );
  10633. }
  10634. if ( material.defines !== undefined ) {
  10635. for ( var name in material.defines ) {
  10636. array.push( name );
  10637. array.push( material.defines[ name ] );
  10638. }
  10639. }
  10640. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10641. array.push( parameters[ parameterNames[ i ] ] );
  10642. }
  10643. array.push( material.onBeforeCompile.toString() );
  10644. array.push( renderer.gammaOutput );
  10645. array.push( renderer.gammaFactor );
  10646. return array.join();
  10647. };
  10648. this.acquireProgram = function ( material, shader, parameters, code ) {
  10649. var program;
  10650. // Check if code has been already compiled
  10651. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10652. var programInfo = programs[ p ];
  10653. if ( programInfo.code === code ) {
  10654. program = programInfo;
  10655. ++ program.usedTimes;
  10656. break;
  10657. }
  10658. }
  10659. if ( program === undefined ) {
  10660. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures );
  10661. programs.push( program );
  10662. }
  10663. return program;
  10664. };
  10665. this.releaseProgram = function ( program ) {
  10666. if ( -- program.usedTimes === 0 ) {
  10667. // Remove from unordered set
  10668. var i = programs.indexOf( program );
  10669. programs[ i ] = programs[ programs.length - 1 ];
  10670. programs.pop();
  10671. // Free WebGL resources
  10672. program.destroy();
  10673. }
  10674. };
  10675. // Exposed for resource monitoring & error feedback via renderer.info:
  10676. this.programs = programs;
  10677. }
  10678. /**
  10679. * @author fordacious / fordacious.github.io
  10680. */
  10681. function WebGLProperties() {
  10682. var properties = new WeakMap();
  10683. function get( object ) {
  10684. var map = properties.get( object );
  10685. if ( map === undefined ) {
  10686. map = {};
  10687. properties.set( object, map );
  10688. }
  10689. return map;
  10690. }
  10691. function remove( object ) {
  10692. properties.delete( object );
  10693. }
  10694. function update( object, key, value ) {
  10695. properties.get( object )[ key ] = value;
  10696. }
  10697. function dispose() {
  10698. properties = new WeakMap();
  10699. }
  10700. return {
  10701. get: get,
  10702. remove: remove,
  10703. update: update,
  10704. dispose: dispose
  10705. };
  10706. }
  10707. /**
  10708. * @author mrdoob / http://mrdoob.com/
  10709. */
  10710. function painterSortStable( a, b ) {
  10711. if ( a.groupOrder !== b.groupOrder ) {
  10712. return a.groupOrder - b.groupOrder;
  10713. } else if ( a.renderOrder !== b.renderOrder ) {
  10714. return a.renderOrder - b.renderOrder;
  10715. } else if ( a.program !== b.program ) {
  10716. return a.program.id - b.program.id;
  10717. } else if ( a.material.id !== b.material.id ) {
  10718. return a.material.id - b.material.id;
  10719. } else if ( a.z !== b.z ) {
  10720. return a.z - b.z;
  10721. } else {
  10722. return a.id - b.id;
  10723. }
  10724. }
  10725. function reversePainterSortStable( a, b ) {
  10726. if ( a.groupOrder !== b.groupOrder ) {
  10727. return a.groupOrder - b.groupOrder;
  10728. } else if ( a.renderOrder !== b.renderOrder ) {
  10729. return a.renderOrder - b.renderOrder;
  10730. } else if ( a.z !== b.z ) {
  10731. return b.z - a.z;
  10732. } else {
  10733. return a.id - b.id;
  10734. }
  10735. }
  10736. function WebGLRenderList() {
  10737. var renderItems = [];
  10738. var renderItemsIndex = 0;
  10739. var opaque = [];
  10740. var transparent = [];
  10741. var defaultProgram = { id: - 1 };
  10742. function init() {
  10743. renderItemsIndex = 0;
  10744. opaque.length = 0;
  10745. transparent.length = 0;
  10746. }
  10747. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10748. var renderItem = renderItems[ renderItemsIndex ];
  10749. if ( renderItem === undefined ) {
  10750. renderItem = {
  10751. id: object.id,
  10752. object: object,
  10753. geometry: geometry,
  10754. material: material,
  10755. program: material.program || defaultProgram,
  10756. groupOrder: groupOrder,
  10757. renderOrder: object.renderOrder,
  10758. z: z,
  10759. group: group
  10760. };
  10761. renderItems[ renderItemsIndex ] = renderItem;
  10762. } else {
  10763. renderItem.id = object.id;
  10764. renderItem.object = object;
  10765. renderItem.geometry = geometry;
  10766. renderItem.material = material;
  10767. renderItem.program = material.program || defaultProgram;
  10768. renderItem.groupOrder = groupOrder;
  10769. renderItem.renderOrder = object.renderOrder;
  10770. renderItem.z = z;
  10771. renderItem.group = group;
  10772. }
  10773. renderItemsIndex ++;
  10774. return renderItem;
  10775. }
  10776. function push( object, geometry, material, groupOrder, z, group ) {
  10777. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10778. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10779. }
  10780. function unshift( object, geometry, material, groupOrder, z, group ) {
  10781. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10782. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10783. }
  10784. function sort() {
  10785. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10786. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10787. }
  10788. return {
  10789. opaque: opaque,
  10790. transparent: transparent,
  10791. init: init,
  10792. push: push,
  10793. unshift: unshift,
  10794. sort: sort
  10795. };
  10796. }
  10797. function WebGLRenderLists() {
  10798. var lists = {};
  10799. function onSceneDispose( event ) {
  10800. var scene = event.target;
  10801. scene.removeEventListener( 'dispose', onSceneDispose );
  10802. delete lists[ scene.id ];
  10803. }
  10804. function get( scene, camera ) {
  10805. var cameras = lists[ scene.id ];
  10806. var list;
  10807. if ( cameras === undefined ) {
  10808. list = new WebGLRenderList();
  10809. lists[ scene.id ] = {};
  10810. lists[ scene.id ][ camera.id ] = list;
  10811. scene.addEventListener( 'dispose', onSceneDispose );
  10812. } else {
  10813. list = cameras[ camera.id ];
  10814. if ( list === undefined ) {
  10815. list = new WebGLRenderList();
  10816. cameras[ camera.id ] = list;
  10817. }
  10818. }
  10819. return list;
  10820. }
  10821. function dispose() {
  10822. lists = {};
  10823. }
  10824. return {
  10825. get: get,
  10826. dispose: dispose
  10827. };
  10828. }
  10829. /**
  10830. * @author mrdoob / http://mrdoob.com/
  10831. */
  10832. function UniformsCache() {
  10833. var lights = {};
  10834. return {
  10835. get: function ( light ) {
  10836. if ( lights[ light.id ] !== undefined ) {
  10837. return lights[ light.id ];
  10838. }
  10839. var uniforms;
  10840. switch ( light.type ) {
  10841. case 'DirectionalLight':
  10842. uniforms = {
  10843. direction: new Vector3(),
  10844. color: new Color(),
  10845. shadow: false,
  10846. shadowBias: 0,
  10847. shadowRadius: 1,
  10848. shadowMapSize: new Vector2()
  10849. };
  10850. break;
  10851. case 'SpotLight':
  10852. uniforms = {
  10853. position: new Vector3(),
  10854. direction: new Vector3(),
  10855. color: new Color(),
  10856. distance: 0,
  10857. coneCos: 0,
  10858. penumbraCos: 0,
  10859. decay: 0,
  10860. shadow: false,
  10861. shadowBias: 0,
  10862. shadowRadius: 1,
  10863. shadowMapSize: new Vector2()
  10864. };
  10865. break;
  10866. case 'PointLight':
  10867. uniforms = {
  10868. position: new Vector3(),
  10869. color: new Color(),
  10870. distance: 0,
  10871. decay: 0,
  10872. shadow: false,
  10873. shadowBias: 0,
  10874. shadowRadius: 1,
  10875. shadowMapSize: new Vector2(),
  10876. shadowCameraNear: 1,
  10877. shadowCameraFar: 1000
  10878. };
  10879. break;
  10880. case 'HemisphereLight':
  10881. uniforms = {
  10882. direction: new Vector3(),
  10883. skyColor: new Color(),
  10884. groundColor: new Color()
  10885. };
  10886. break;
  10887. case 'RectAreaLight':
  10888. uniforms = {
  10889. color: new Color(),
  10890. position: new Vector3(),
  10891. halfWidth: new Vector3(),
  10892. halfHeight: new Vector3()
  10893. // TODO (abelnation): set RectAreaLight shadow uniforms
  10894. };
  10895. break;
  10896. }
  10897. lights[ light.id ] = uniforms;
  10898. return uniforms;
  10899. }
  10900. };
  10901. }
  10902. var count = 0;
  10903. function WebGLLights() {
  10904. var cache = new UniformsCache();
  10905. var state = {
  10906. id: count ++,
  10907. hash: {
  10908. stateID: - 1,
  10909. directionalLength: - 1,
  10910. pointLength: - 1,
  10911. spotLength: - 1,
  10912. rectAreaLength: - 1,
  10913. hemiLength: - 1,
  10914. shadowsLength: - 1
  10915. },
  10916. ambient: [ 0, 0, 0 ],
  10917. directional: [],
  10918. directionalShadowMap: [],
  10919. directionalShadowMatrix: [],
  10920. spot: [],
  10921. spotShadowMap: [],
  10922. spotShadowMatrix: [],
  10923. rectArea: [],
  10924. point: [],
  10925. pointShadowMap: [],
  10926. pointShadowMatrix: [],
  10927. hemi: []
  10928. };
  10929. var vector3 = new Vector3();
  10930. var matrix4 = new Matrix4();
  10931. var matrix42 = new Matrix4();
  10932. function setup( lights, shadows, camera ) {
  10933. var r = 0, g = 0, b = 0;
  10934. var directionalLength = 0;
  10935. var pointLength = 0;
  10936. var spotLength = 0;
  10937. var rectAreaLength = 0;
  10938. var hemiLength = 0;
  10939. var viewMatrix = camera.matrixWorldInverse;
  10940. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10941. var light = lights[ i ];
  10942. var color = light.color;
  10943. var intensity = light.intensity;
  10944. var distance = light.distance;
  10945. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10946. if ( light.isAmbientLight ) {
  10947. r += color.r * intensity;
  10948. g += color.g * intensity;
  10949. b += color.b * intensity;
  10950. } else if ( light.isDirectionalLight ) {
  10951. var uniforms = cache.get( light );
  10952. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10953. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10954. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10955. uniforms.direction.sub( vector3 );
  10956. uniforms.direction.transformDirection( viewMatrix );
  10957. uniforms.shadow = light.castShadow;
  10958. if ( light.castShadow ) {
  10959. var shadow = light.shadow;
  10960. uniforms.shadowBias = shadow.bias;
  10961. uniforms.shadowRadius = shadow.radius;
  10962. uniforms.shadowMapSize = shadow.mapSize;
  10963. }
  10964. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10965. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10966. state.directional[ directionalLength ] = uniforms;
  10967. directionalLength ++;
  10968. } else if ( light.isSpotLight ) {
  10969. var uniforms = cache.get( light );
  10970. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10971. uniforms.position.applyMatrix4( viewMatrix );
  10972. uniforms.color.copy( color ).multiplyScalar( intensity );
  10973. uniforms.distance = distance;
  10974. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10975. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10976. uniforms.direction.sub( vector3 );
  10977. uniforms.direction.transformDirection( viewMatrix );
  10978. uniforms.coneCos = Math.cos( light.angle );
  10979. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10980. uniforms.decay = light.decay;
  10981. uniforms.shadow = light.castShadow;
  10982. if ( light.castShadow ) {
  10983. var shadow = light.shadow;
  10984. uniforms.shadowBias = shadow.bias;
  10985. uniforms.shadowRadius = shadow.radius;
  10986. uniforms.shadowMapSize = shadow.mapSize;
  10987. }
  10988. state.spotShadowMap[ spotLength ] = shadowMap;
  10989. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10990. state.spot[ spotLength ] = uniforms;
  10991. spotLength ++;
  10992. } else if ( light.isRectAreaLight ) {
  10993. var uniforms = cache.get( light );
  10994. // (a) intensity is the total visible light emitted
  10995. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10996. // (b) intensity is the brightness of the light
  10997. uniforms.color.copy( color ).multiplyScalar( intensity );
  10998. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10999. uniforms.position.applyMatrix4( viewMatrix );
  11000. // extract local rotation of light to derive width/height half vectors
  11001. matrix42.identity();
  11002. matrix4.copy( light.matrixWorld );
  11003. matrix4.premultiply( viewMatrix );
  11004. matrix42.extractRotation( matrix4 );
  11005. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11006. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11007. uniforms.halfWidth.applyMatrix4( matrix42 );
  11008. uniforms.halfHeight.applyMatrix4( matrix42 );
  11009. // TODO (abelnation): RectAreaLight distance?
  11010. // uniforms.distance = distance;
  11011. state.rectArea[ rectAreaLength ] = uniforms;
  11012. rectAreaLength ++;
  11013. } else if ( light.isPointLight ) {
  11014. var uniforms = cache.get( light );
  11015. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11016. uniforms.position.applyMatrix4( viewMatrix );
  11017. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11018. uniforms.distance = light.distance;
  11019. uniforms.decay = light.decay;
  11020. uniforms.shadow = light.castShadow;
  11021. if ( light.castShadow ) {
  11022. var shadow = light.shadow;
  11023. uniforms.shadowBias = shadow.bias;
  11024. uniforms.shadowRadius = shadow.radius;
  11025. uniforms.shadowMapSize = shadow.mapSize;
  11026. uniforms.shadowCameraNear = shadow.camera.near;
  11027. uniforms.shadowCameraFar = shadow.camera.far;
  11028. }
  11029. state.pointShadowMap[ pointLength ] = shadowMap;
  11030. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11031. state.point[ pointLength ] = uniforms;
  11032. pointLength ++;
  11033. } else if ( light.isHemisphereLight ) {
  11034. var uniforms = cache.get( light );
  11035. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11036. uniforms.direction.transformDirection( viewMatrix );
  11037. uniforms.direction.normalize();
  11038. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11039. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11040. state.hemi[ hemiLength ] = uniforms;
  11041. hemiLength ++;
  11042. }
  11043. }
  11044. state.ambient[ 0 ] = r;
  11045. state.ambient[ 1 ] = g;
  11046. state.ambient[ 2 ] = b;
  11047. state.directional.length = directionalLength;
  11048. state.spot.length = spotLength;
  11049. state.rectArea.length = rectAreaLength;
  11050. state.point.length = pointLength;
  11051. state.hemi.length = hemiLength;
  11052. state.hash.stateID = state.id;
  11053. state.hash.directionalLength = directionalLength;
  11054. state.hash.pointLength = pointLength;
  11055. state.hash.spotLength = spotLength;
  11056. state.hash.rectAreaLength = rectAreaLength;
  11057. state.hash.hemiLength = hemiLength;
  11058. state.hash.shadowsLength = shadows.length;
  11059. }
  11060. return {
  11061. setup: setup,
  11062. state: state
  11063. };
  11064. }
  11065. /**
  11066. * @author Mugen87 / https://github.com/Mugen87
  11067. */
  11068. function WebGLRenderState() {
  11069. var lights = new WebGLLights();
  11070. var lightsArray = [];
  11071. var shadowsArray = [];
  11072. function init() {
  11073. lightsArray.length = 0;
  11074. shadowsArray.length = 0;
  11075. }
  11076. function pushLight( light ) {
  11077. lightsArray.push( light );
  11078. }
  11079. function pushShadow( shadowLight ) {
  11080. shadowsArray.push( shadowLight );
  11081. }
  11082. function setupLights( camera ) {
  11083. lights.setup( lightsArray, shadowsArray, camera );
  11084. }
  11085. var state = {
  11086. lightsArray: lightsArray,
  11087. shadowsArray: shadowsArray,
  11088. lights: lights
  11089. };
  11090. return {
  11091. init: init,
  11092. state: state,
  11093. setupLights: setupLights,
  11094. pushLight: pushLight,
  11095. pushShadow: pushShadow
  11096. };
  11097. }
  11098. function WebGLRenderStates() {
  11099. var renderStates = {};
  11100. function onSceneDispose( event ) {
  11101. var scene = event.target;
  11102. scene.removeEventListener( 'dispose', onSceneDispose );
  11103. delete renderStates[ scene.id ];
  11104. }
  11105. function get( scene, camera ) {
  11106. var renderState;
  11107. if ( renderStates[ scene.id ] === undefined ) {
  11108. renderState = new WebGLRenderState();
  11109. renderStates[ scene.id ] = {};
  11110. renderStates[ scene.id ][ camera.id ] = renderState;
  11111. scene.addEventListener( 'dispose', onSceneDispose );
  11112. } else {
  11113. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11114. renderState = new WebGLRenderState();
  11115. renderStates[ scene.id ][ camera.id ] = renderState;
  11116. } else {
  11117. renderState = renderStates[ scene.id ][ camera.id ];
  11118. }
  11119. }
  11120. return renderState;
  11121. }
  11122. function dispose() {
  11123. renderStates = {};
  11124. }
  11125. return {
  11126. get: get,
  11127. dispose: dispose
  11128. };
  11129. }
  11130. /**
  11131. * @author mrdoob / http://mrdoob.com/
  11132. * @author alteredq / http://alteredqualia.com/
  11133. * @author bhouston / https://clara.io
  11134. * @author WestLangley / http://github.com/WestLangley
  11135. *
  11136. * parameters = {
  11137. *
  11138. * opacity: <float>,
  11139. *
  11140. * map: new THREE.Texture( <Image> ),
  11141. *
  11142. * alphaMap: new THREE.Texture( <Image> ),
  11143. *
  11144. * displacementMap: new THREE.Texture( <Image> ),
  11145. * displacementScale: <float>,
  11146. * displacementBias: <float>,
  11147. *
  11148. * wireframe: <boolean>,
  11149. * wireframeLinewidth: <float>
  11150. * }
  11151. */
  11152. function MeshDepthMaterial( parameters ) {
  11153. Material.call( this );
  11154. this.type = 'MeshDepthMaterial';
  11155. this.depthPacking = BasicDepthPacking;
  11156. this.skinning = false;
  11157. this.morphTargets = false;
  11158. this.map = null;
  11159. this.alphaMap = null;
  11160. this.displacementMap = null;
  11161. this.displacementScale = 1;
  11162. this.displacementBias = 0;
  11163. this.wireframe = false;
  11164. this.wireframeLinewidth = 1;
  11165. this.fog = false;
  11166. this.lights = false;
  11167. this.setValues( parameters );
  11168. }
  11169. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11170. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11171. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11172. MeshDepthMaterial.prototype.copy = function ( source ) {
  11173. Material.prototype.copy.call( this, source );
  11174. this.depthPacking = source.depthPacking;
  11175. this.skinning = source.skinning;
  11176. this.morphTargets = source.morphTargets;
  11177. this.map = source.map;
  11178. this.alphaMap = source.alphaMap;
  11179. this.displacementMap = source.displacementMap;
  11180. this.displacementScale = source.displacementScale;
  11181. this.displacementBias = source.displacementBias;
  11182. this.wireframe = source.wireframe;
  11183. this.wireframeLinewidth = source.wireframeLinewidth;
  11184. return this;
  11185. };
  11186. /**
  11187. * @author WestLangley / http://github.com/WestLangley
  11188. *
  11189. * parameters = {
  11190. *
  11191. * referencePosition: <float>,
  11192. * nearDistance: <float>,
  11193. * farDistance: <float>,
  11194. *
  11195. * skinning: <bool>,
  11196. * morphTargets: <bool>,
  11197. *
  11198. * map: new THREE.Texture( <Image> ),
  11199. *
  11200. * alphaMap: new THREE.Texture( <Image> ),
  11201. *
  11202. * displacementMap: new THREE.Texture( <Image> ),
  11203. * displacementScale: <float>,
  11204. * displacementBias: <float>
  11205. *
  11206. * }
  11207. */
  11208. function MeshDistanceMaterial( parameters ) {
  11209. Material.call( this );
  11210. this.type = 'MeshDistanceMaterial';
  11211. this.referencePosition = new Vector3();
  11212. this.nearDistance = 1;
  11213. this.farDistance = 1000;
  11214. this.skinning = false;
  11215. this.morphTargets = false;
  11216. this.map = null;
  11217. this.alphaMap = null;
  11218. this.displacementMap = null;
  11219. this.displacementScale = 1;
  11220. this.displacementBias = 0;
  11221. this.fog = false;
  11222. this.lights = false;
  11223. this.setValues( parameters );
  11224. }
  11225. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11226. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11227. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11228. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11229. Material.prototype.copy.call( this, source );
  11230. this.referencePosition.copy( source.referencePosition );
  11231. this.nearDistance = source.nearDistance;
  11232. this.farDistance = source.farDistance;
  11233. this.skinning = source.skinning;
  11234. this.morphTargets = source.morphTargets;
  11235. this.map = source.map;
  11236. this.alphaMap = source.alphaMap;
  11237. this.displacementMap = source.displacementMap;
  11238. this.displacementScale = source.displacementScale;
  11239. this.displacementBias = source.displacementBias;
  11240. return this;
  11241. };
  11242. /**
  11243. * @author alteredq / http://alteredqualia.com/
  11244. * @author mrdoob / http://mrdoob.com/
  11245. */
  11246. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11247. var _frustum = new Frustum(),
  11248. _projScreenMatrix = new Matrix4(),
  11249. _shadowMapSize = new Vector2(),
  11250. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11251. _lookTarget = new Vector3(),
  11252. _lightPositionWorld = new Vector3(),
  11253. _MorphingFlag = 1,
  11254. _SkinningFlag = 2,
  11255. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11256. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11257. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11258. _materialCache = {};
  11259. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11260. var cubeDirections = [
  11261. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11262. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11263. ];
  11264. var cubeUps = [
  11265. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11266. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11267. ];
  11268. var cube2DViewPorts = [
  11269. new Vector4(), new Vector4(), new Vector4(),
  11270. new Vector4(), new Vector4(), new Vector4()
  11271. ];
  11272. // init
  11273. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11274. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11275. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11276. var depthMaterial = new MeshDepthMaterial( {
  11277. depthPacking: RGBADepthPacking,
  11278. morphTargets: useMorphing,
  11279. skinning: useSkinning
  11280. } );
  11281. _depthMaterials[ i ] = depthMaterial;
  11282. //
  11283. var distanceMaterial = new MeshDistanceMaterial( {
  11284. morphTargets: useMorphing,
  11285. skinning: useSkinning
  11286. } );
  11287. _distanceMaterials[ i ] = distanceMaterial;
  11288. }
  11289. //
  11290. var scope = this;
  11291. this.enabled = false;
  11292. this.autoUpdate = true;
  11293. this.needsUpdate = false;
  11294. this.type = PCFShadowMap;
  11295. this.render = function ( lights, scene, camera ) {
  11296. if ( scope.enabled === false ) return;
  11297. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11298. if ( lights.length === 0 ) return;
  11299. var currentRenderTarget = _renderer.getRenderTarget();
  11300. var _state = _renderer.state;
  11301. // Set GL state for depth map.
  11302. _state.setBlending( NoBlending );
  11303. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11304. _state.buffers.depth.setTest( true );
  11305. _state.setScissorTest( false );
  11306. // render depth map
  11307. var faceCount;
  11308. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11309. var light = lights[ i ];
  11310. var shadow = light.shadow;
  11311. var isPointLight = light && light.isPointLight;
  11312. if ( shadow === undefined ) {
  11313. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11314. continue;
  11315. }
  11316. var shadowCamera = shadow.camera;
  11317. _shadowMapSize.copy( shadow.mapSize );
  11318. _shadowMapSize.min( _maxShadowMapSize );
  11319. if ( isPointLight ) {
  11320. var vpWidth = _shadowMapSize.x;
  11321. var vpHeight = _shadowMapSize.y;
  11322. // These viewports map a cube-map onto a 2D texture with the
  11323. // following orientation:
  11324. //
  11325. // xzXZ
  11326. // y Y
  11327. //
  11328. // X - Positive x direction
  11329. // x - Negative x direction
  11330. // Y - Positive y direction
  11331. // y - Negative y direction
  11332. // Z - Positive z direction
  11333. // z - Negative z direction
  11334. // positive X
  11335. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11336. // negative X
  11337. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11338. // positive Z
  11339. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11340. // negative Z
  11341. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11342. // positive Y
  11343. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11344. // negative Y
  11345. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11346. _shadowMapSize.x *= 4.0;
  11347. _shadowMapSize.y *= 2.0;
  11348. }
  11349. if ( shadow.map === null ) {
  11350. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11351. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11352. shadow.map.texture.name = light.name + ".shadowMap";
  11353. shadowCamera.updateProjectionMatrix();
  11354. }
  11355. if ( shadow.isSpotLightShadow ) {
  11356. shadow.update( light );
  11357. }
  11358. var shadowMap = shadow.map;
  11359. var shadowMatrix = shadow.matrix;
  11360. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11361. shadowCamera.position.copy( _lightPositionWorld );
  11362. if ( isPointLight ) {
  11363. faceCount = 6;
  11364. // for point lights we set the shadow matrix to be a translation-only matrix
  11365. // equal to inverse of the light's position
  11366. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11367. } else {
  11368. faceCount = 1;
  11369. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11370. shadowCamera.lookAt( _lookTarget );
  11371. shadowCamera.updateMatrixWorld();
  11372. // compute shadow matrix
  11373. shadowMatrix.set(
  11374. 0.5, 0.0, 0.0, 0.5,
  11375. 0.0, 0.5, 0.0, 0.5,
  11376. 0.0, 0.0, 0.5, 0.5,
  11377. 0.0, 0.0, 0.0, 1.0
  11378. );
  11379. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11380. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11381. }
  11382. _renderer.setRenderTarget( shadowMap );
  11383. _renderer.clear();
  11384. // render shadow map for each cube face (if omni-directional) or
  11385. // run a single pass if not
  11386. for ( var face = 0; face < faceCount; face ++ ) {
  11387. if ( isPointLight ) {
  11388. _lookTarget.copy( shadowCamera.position );
  11389. _lookTarget.add( cubeDirections[ face ] );
  11390. shadowCamera.up.copy( cubeUps[ face ] );
  11391. shadowCamera.lookAt( _lookTarget );
  11392. shadowCamera.updateMatrixWorld();
  11393. var vpDimensions = cube2DViewPorts[ face ];
  11394. _state.viewport( vpDimensions );
  11395. }
  11396. // update camera matrices and frustum
  11397. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11398. _frustum.setFromMatrix( _projScreenMatrix );
  11399. // set object matrices & frustum culling
  11400. renderObject( scene, camera, shadowCamera, isPointLight );
  11401. }
  11402. }
  11403. scope.needsUpdate = false;
  11404. _renderer.setRenderTarget( currentRenderTarget );
  11405. };
  11406. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11407. var geometry = object.geometry;
  11408. var result = null;
  11409. var materialVariants = _depthMaterials;
  11410. var customMaterial = object.customDepthMaterial;
  11411. if ( isPointLight ) {
  11412. materialVariants = _distanceMaterials;
  11413. customMaterial = object.customDistanceMaterial;
  11414. }
  11415. if ( ! customMaterial ) {
  11416. var useMorphing = false;
  11417. if ( material.morphTargets ) {
  11418. if ( geometry && geometry.isBufferGeometry ) {
  11419. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11420. } else if ( geometry && geometry.isGeometry ) {
  11421. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11422. }
  11423. }
  11424. if ( object.isSkinnedMesh && material.skinning === false ) {
  11425. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11426. }
  11427. var useSkinning = object.isSkinnedMesh && material.skinning;
  11428. var variantIndex = 0;
  11429. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11430. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11431. result = materialVariants[ variantIndex ];
  11432. } else {
  11433. result = customMaterial;
  11434. }
  11435. if ( _renderer.localClippingEnabled &&
  11436. material.clipShadows === true &&
  11437. material.clippingPlanes.length !== 0 ) {
  11438. // in this case we need a unique material instance reflecting the
  11439. // appropriate state
  11440. var keyA = result.uuid, keyB = material.uuid;
  11441. var materialsForVariant = _materialCache[ keyA ];
  11442. if ( materialsForVariant === undefined ) {
  11443. materialsForVariant = {};
  11444. _materialCache[ keyA ] = materialsForVariant;
  11445. }
  11446. var cachedMaterial = materialsForVariant[ keyB ];
  11447. if ( cachedMaterial === undefined ) {
  11448. cachedMaterial = result.clone();
  11449. materialsForVariant[ keyB ] = cachedMaterial;
  11450. }
  11451. result = cachedMaterial;
  11452. }
  11453. result.visible = material.visible;
  11454. result.wireframe = material.wireframe;
  11455. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11456. result.clipShadows = material.clipShadows;
  11457. result.clippingPlanes = material.clippingPlanes;
  11458. result.clipIntersection = material.clipIntersection;
  11459. result.wireframeLinewidth = material.wireframeLinewidth;
  11460. result.linewidth = material.linewidth;
  11461. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11462. result.referencePosition.copy( lightPositionWorld );
  11463. result.nearDistance = shadowCameraNear;
  11464. result.farDistance = shadowCameraFar;
  11465. }
  11466. return result;
  11467. }
  11468. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11469. if ( object.visible === false ) return;
  11470. var visible = object.layers.test( camera.layers );
  11471. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11472. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11473. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11474. var geometry = _objects.update( object );
  11475. var material = object.material;
  11476. if ( Array.isArray( material ) ) {
  11477. var groups = geometry.groups;
  11478. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11479. var group = groups[ k ];
  11480. var groupMaterial = material[ group.materialIndex ];
  11481. if ( groupMaterial && groupMaterial.visible ) {
  11482. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11483. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11484. }
  11485. }
  11486. } else if ( material.visible ) {
  11487. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11488. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11489. }
  11490. }
  11491. }
  11492. var children = object.children;
  11493. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11494. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11495. }
  11496. }
  11497. }
  11498. /**
  11499. * @author mrdoob / http://mrdoob.com/
  11500. */
  11501. function WebGLState( gl, extensions, utils, capabilities ) {
  11502. function ColorBuffer() {
  11503. var locked = false;
  11504. var color = new Vector4();
  11505. var currentColorMask = null;
  11506. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11507. return {
  11508. setMask: function ( colorMask ) {
  11509. if ( currentColorMask !== colorMask && ! locked ) {
  11510. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11511. currentColorMask = colorMask;
  11512. }
  11513. },
  11514. setLocked: function ( lock ) {
  11515. locked = lock;
  11516. },
  11517. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11518. if ( premultipliedAlpha === true ) {
  11519. r *= a; g *= a; b *= a;
  11520. }
  11521. color.set( r, g, b, a );
  11522. if ( currentColorClear.equals( color ) === false ) {
  11523. gl.clearColor( r, g, b, a );
  11524. currentColorClear.copy( color );
  11525. }
  11526. },
  11527. reset: function () {
  11528. locked = false;
  11529. currentColorMask = null;
  11530. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11531. }
  11532. };
  11533. }
  11534. function DepthBuffer() {
  11535. var locked = false;
  11536. var currentDepthMask = null;
  11537. var currentDepthFunc = null;
  11538. var currentDepthClear = null;
  11539. return {
  11540. setTest: function ( depthTest ) {
  11541. if ( depthTest ) {
  11542. enable( 2929 );
  11543. } else {
  11544. disable( 2929 );
  11545. }
  11546. },
  11547. setMask: function ( depthMask ) {
  11548. if ( currentDepthMask !== depthMask && ! locked ) {
  11549. gl.depthMask( depthMask );
  11550. currentDepthMask = depthMask;
  11551. }
  11552. },
  11553. setFunc: function ( depthFunc ) {
  11554. if ( currentDepthFunc !== depthFunc ) {
  11555. if ( depthFunc ) {
  11556. switch ( depthFunc ) {
  11557. case NeverDepth:
  11558. gl.depthFunc( 512 );
  11559. break;
  11560. case AlwaysDepth:
  11561. gl.depthFunc( 519 );
  11562. break;
  11563. case LessDepth:
  11564. gl.depthFunc( 513 );
  11565. break;
  11566. case LessEqualDepth:
  11567. gl.depthFunc( 515 );
  11568. break;
  11569. case EqualDepth:
  11570. gl.depthFunc( 514 );
  11571. break;
  11572. case GreaterEqualDepth:
  11573. gl.depthFunc( 518 );
  11574. break;
  11575. case GreaterDepth:
  11576. gl.depthFunc( 516 );
  11577. break;
  11578. case NotEqualDepth:
  11579. gl.depthFunc( 517 );
  11580. break;
  11581. default:
  11582. gl.depthFunc( 515 );
  11583. }
  11584. } else {
  11585. gl.depthFunc( 515 );
  11586. }
  11587. currentDepthFunc = depthFunc;
  11588. }
  11589. },
  11590. setLocked: function ( lock ) {
  11591. locked = lock;
  11592. },
  11593. setClear: function ( depth ) {
  11594. if ( currentDepthClear !== depth ) {
  11595. gl.clearDepth( depth );
  11596. currentDepthClear = depth;
  11597. }
  11598. },
  11599. reset: function () {
  11600. locked = false;
  11601. currentDepthMask = null;
  11602. currentDepthFunc = null;
  11603. currentDepthClear = null;
  11604. }
  11605. };
  11606. }
  11607. function StencilBuffer() {
  11608. var locked = false;
  11609. var currentStencilMask = null;
  11610. var currentStencilFunc = null;
  11611. var currentStencilRef = null;
  11612. var currentStencilFuncMask = null;
  11613. var currentStencilFail = null;
  11614. var currentStencilZFail = null;
  11615. var currentStencilZPass = null;
  11616. var currentStencilClear = null;
  11617. return {
  11618. setTest: function ( stencilTest ) {
  11619. if ( stencilTest ) {
  11620. enable( 2960 );
  11621. } else {
  11622. disable( 2960 );
  11623. }
  11624. },
  11625. setMask: function ( stencilMask ) {
  11626. if ( currentStencilMask !== stencilMask && ! locked ) {
  11627. gl.stencilMask( stencilMask );
  11628. currentStencilMask = stencilMask;
  11629. }
  11630. },
  11631. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11632. if ( currentStencilFunc !== stencilFunc ||
  11633. currentStencilRef !== stencilRef ||
  11634. currentStencilFuncMask !== stencilMask ) {
  11635. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11636. currentStencilFunc = stencilFunc;
  11637. currentStencilRef = stencilRef;
  11638. currentStencilFuncMask = stencilMask;
  11639. }
  11640. },
  11641. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11642. if ( currentStencilFail !== stencilFail ||
  11643. currentStencilZFail !== stencilZFail ||
  11644. currentStencilZPass !== stencilZPass ) {
  11645. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11646. currentStencilFail = stencilFail;
  11647. currentStencilZFail = stencilZFail;
  11648. currentStencilZPass = stencilZPass;
  11649. }
  11650. },
  11651. setLocked: function ( lock ) {
  11652. locked = lock;
  11653. },
  11654. setClear: function ( stencil ) {
  11655. if ( currentStencilClear !== stencil ) {
  11656. gl.clearStencil( stencil );
  11657. currentStencilClear = stencil;
  11658. }
  11659. },
  11660. reset: function () {
  11661. locked = false;
  11662. currentStencilMask = null;
  11663. currentStencilFunc = null;
  11664. currentStencilRef = null;
  11665. currentStencilFuncMask = null;
  11666. currentStencilFail = null;
  11667. currentStencilZFail = null;
  11668. currentStencilZPass = null;
  11669. currentStencilClear = null;
  11670. }
  11671. };
  11672. }
  11673. //
  11674. var colorBuffer = new ColorBuffer();
  11675. var depthBuffer = new DepthBuffer();
  11676. var stencilBuffer = new StencilBuffer();
  11677. var maxVertexAttributes = gl.getParameter( 34921 );
  11678. var newAttributes = new Uint8Array( maxVertexAttributes );
  11679. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11680. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11681. var enabledCapabilities = {};
  11682. var compressedTextureFormats = null;
  11683. var currentProgram = null;
  11684. var currentBlendingEnabled = null;
  11685. var currentBlending = null;
  11686. var currentBlendEquation = null;
  11687. var currentBlendSrc = null;
  11688. var currentBlendDst = null;
  11689. var currentBlendEquationAlpha = null;
  11690. var currentBlendSrcAlpha = null;
  11691. var currentBlendDstAlpha = null;
  11692. var currentPremultipledAlpha = false;
  11693. var currentFlipSided = null;
  11694. var currentCullFace = null;
  11695. var currentLineWidth = null;
  11696. var currentPolygonOffsetFactor = null;
  11697. var currentPolygonOffsetUnits = null;
  11698. var maxTextures = gl.getParameter( 35661 );
  11699. var lineWidthAvailable = false;
  11700. var version = 0;
  11701. var glVersion = gl.getParameter( 7938 );
  11702. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11703. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11704. lineWidthAvailable = ( version >= 1.0 );
  11705. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11706. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11707. lineWidthAvailable = ( version >= 2.0 );
  11708. }
  11709. var currentTextureSlot = null;
  11710. var currentBoundTextures = {};
  11711. var currentScissor = new Vector4();
  11712. var currentViewport = new Vector4();
  11713. function createTexture( type, target, count ) {
  11714. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11715. var texture = gl.createTexture();
  11716. gl.bindTexture( type, texture );
  11717. gl.texParameteri( type, 10241, 9728 );
  11718. gl.texParameteri( type, 10240, 9728 );
  11719. for ( var i = 0; i < count; i ++ ) {
  11720. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11721. }
  11722. return texture;
  11723. }
  11724. var emptyTextures = {};
  11725. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11726. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11727. // init
  11728. colorBuffer.setClear( 0, 0, 0, 1 );
  11729. depthBuffer.setClear( 1 );
  11730. stencilBuffer.setClear( 0 );
  11731. enable( 2929 );
  11732. depthBuffer.setFunc( LessEqualDepth );
  11733. setFlipSided( false );
  11734. setCullFace( CullFaceBack );
  11735. enable( 2884 );
  11736. setBlending( NoBlending );
  11737. //
  11738. function initAttributes() {
  11739. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11740. newAttributes[ i ] = 0;
  11741. }
  11742. }
  11743. function enableAttribute( attribute ) {
  11744. enableAttributeAndDivisor( attribute, 0 );
  11745. }
  11746. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11747. newAttributes[ attribute ] = 1;
  11748. if ( enabledAttributes[ attribute ] === 0 ) {
  11749. gl.enableVertexAttribArray( attribute );
  11750. enabledAttributes[ attribute ] = 1;
  11751. }
  11752. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11753. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11754. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11755. attributeDivisors[ attribute ] = meshPerAttribute;
  11756. }
  11757. }
  11758. function disableUnusedAttributes() {
  11759. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11760. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11761. gl.disableVertexAttribArray( i );
  11762. enabledAttributes[ i ] = 0;
  11763. }
  11764. }
  11765. }
  11766. function enable( id ) {
  11767. if ( enabledCapabilities[ id ] !== true ) {
  11768. gl.enable( id );
  11769. enabledCapabilities[ id ] = true;
  11770. }
  11771. }
  11772. function disable( id ) {
  11773. if ( enabledCapabilities[ id ] !== false ) {
  11774. gl.disable( id );
  11775. enabledCapabilities[ id ] = false;
  11776. }
  11777. }
  11778. function getCompressedTextureFormats() {
  11779. if ( compressedTextureFormats === null ) {
  11780. compressedTextureFormats = [];
  11781. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11782. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11783. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11784. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11785. var formats = gl.getParameter( 34467 );
  11786. for ( var i = 0; i < formats.length; i ++ ) {
  11787. compressedTextureFormats.push( formats[ i ] );
  11788. }
  11789. }
  11790. }
  11791. return compressedTextureFormats;
  11792. }
  11793. function useProgram( program ) {
  11794. if ( currentProgram !== program ) {
  11795. gl.useProgram( program );
  11796. currentProgram = program;
  11797. return true;
  11798. }
  11799. return false;
  11800. }
  11801. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11802. if ( blending === NoBlending ) {
  11803. if ( currentBlendingEnabled ) {
  11804. disable( 3042 );
  11805. currentBlendingEnabled = false;
  11806. }
  11807. return;
  11808. }
  11809. if ( ! currentBlendingEnabled ) {
  11810. enable( 3042 );
  11811. currentBlendingEnabled = true;
  11812. }
  11813. if ( blending !== CustomBlending ) {
  11814. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11815. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11816. gl.blendEquation( 32774 );
  11817. currentBlendEquation = AddEquation;
  11818. currentBlendEquationAlpha = AddEquation;
  11819. }
  11820. if ( premultipliedAlpha ) {
  11821. switch ( blending ) {
  11822. case NormalBlending:
  11823. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11824. break;
  11825. case AdditiveBlending:
  11826. gl.blendFunc( 1, 1 );
  11827. break;
  11828. case SubtractiveBlending:
  11829. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11830. break;
  11831. case MultiplyBlending:
  11832. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11833. break;
  11834. default:
  11835. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11836. break;
  11837. }
  11838. } else {
  11839. switch ( blending ) {
  11840. case NormalBlending:
  11841. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11842. break;
  11843. case AdditiveBlending:
  11844. gl.blendFunc( 770, 1 );
  11845. break;
  11846. case SubtractiveBlending:
  11847. gl.blendFunc( 0, 769 );
  11848. break;
  11849. case MultiplyBlending:
  11850. gl.blendFunc( 0, 768 );
  11851. break;
  11852. default:
  11853. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11854. break;
  11855. }
  11856. }
  11857. currentBlendSrc = null;
  11858. currentBlendDst = null;
  11859. currentBlendSrcAlpha = null;
  11860. currentBlendDstAlpha = null;
  11861. currentBlending = blending;
  11862. currentPremultipledAlpha = premultipliedAlpha;
  11863. }
  11864. return;
  11865. }
  11866. // custom blending
  11867. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11868. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11869. blendDstAlpha = blendDstAlpha || blendDst;
  11870. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11871. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11872. currentBlendEquation = blendEquation;
  11873. currentBlendEquationAlpha = blendEquationAlpha;
  11874. }
  11875. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11876. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11877. currentBlendSrc = blendSrc;
  11878. currentBlendDst = blendDst;
  11879. currentBlendSrcAlpha = blendSrcAlpha;
  11880. currentBlendDstAlpha = blendDstAlpha;
  11881. }
  11882. currentBlending = blending;
  11883. currentPremultipledAlpha = null;
  11884. }
  11885. function setMaterial( material, frontFaceCW ) {
  11886. material.side === DoubleSide
  11887. ? disable( 2884 )
  11888. : enable( 2884 );
  11889. var flipSided = ( material.side === BackSide );
  11890. if ( frontFaceCW ) flipSided = ! flipSided;
  11891. setFlipSided( flipSided );
  11892. ( material.blending === NormalBlending && material.transparent === false )
  11893. ? setBlending( NoBlending )
  11894. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11895. depthBuffer.setFunc( material.depthFunc );
  11896. depthBuffer.setTest( material.depthTest );
  11897. depthBuffer.setMask( material.depthWrite );
  11898. colorBuffer.setMask( material.colorWrite );
  11899. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11900. }
  11901. //
  11902. function setFlipSided( flipSided ) {
  11903. if ( currentFlipSided !== flipSided ) {
  11904. if ( flipSided ) {
  11905. gl.frontFace( 2304 );
  11906. } else {
  11907. gl.frontFace( 2305 );
  11908. }
  11909. currentFlipSided = flipSided;
  11910. }
  11911. }
  11912. function setCullFace( cullFace ) {
  11913. if ( cullFace !== CullFaceNone ) {
  11914. enable( 2884 );
  11915. if ( cullFace !== currentCullFace ) {
  11916. if ( cullFace === CullFaceBack ) {
  11917. gl.cullFace( 1029 );
  11918. } else if ( cullFace === CullFaceFront ) {
  11919. gl.cullFace( 1028 );
  11920. } else {
  11921. gl.cullFace( 1032 );
  11922. }
  11923. }
  11924. } else {
  11925. disable( 2884 );
  11926. }
  11927. currentCullFace = cullFace;
  11928. }
  11929. function setLineWidth( width ) {
  11930. if ( width !== currentLineWidth ) {
  11931. if ( lineWidthAvailable ) gl.lineWidth( width );
  11932. currentLineWidth = width;
  11933. }
  11934. }
  11935. function setPolygonOffset( polygonOffset, factor, units ) {
  11936. if ( polygonOffset ) {
  11937. enable( 32823 );
  11938. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11939. gl.polygonOffset( factor, units );
  11940. currentPolygonOffsetFactor = factor;
  11941. currentPolygonOffsetUnits = units;
  11942. }
  11943. } else {
  11944. disable( 32823 );
  11945. }
  11946. }
  11947. function setScissorTest( scissorTest ) {
  11948. if ( scissorTest ) {
  11949. enable( 3089 );
  11950. } else {
  11951. disable( 3089 );
  11952. }
  11953. }
  11954. // texture
  11955. function activeTexture( webglSlot ) {
  11956. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11957. if ( currentTextureSlot !== webglSlot ) {
  11958. gl.activeTexture( webglSlot );
  11959. currentTextureSlot = webglSlot;
  11960. }
  11961. }
  11962. function bindTexture( webglType, webglTexture ) {
  11963. if ( currentTextureSlot === null ) {
  11964. activeTexture();
  11965. }
  11966. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11967. if ( boundTexture === undefined ) {
  11968. boundTexture = { type: undefined, texture: undefined };
  11969. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11970. }
  11971. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11972. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11973. boundTexture.type = webglType;
  11974. boundTexture.texture = webglTexture;
  11975. }
  11976. }
  11977. function compressedTexImage2D() {
  11978. try {
  11979. gl.compressedTexImage2D.apply( gl, arguments );
  11980. } catch ( error ) {
  11981. console.error( 'THREE.WebGLState:', error );
  11982. }
  11983. }
  11984. function texImage2D() {
  11985. try {
  11986. gl.texImage2D.apply( gl, arguments );
  11987. } catch ( error ) {
  11988. console.error( 'THREE.WebGLState:', error );
  11989. }
  11990. }
  11991. function texImage3D() {
  11992. try {
  11993. gl.texImage3D.apply( gl, arguments );
  11994. } catch ( error ) {
  11995. console.error( 'THREE.WebGLState:', error );
  11996. }
  11997. }
  11998. //
  11999. function scissor( scissor ) {
  12000. if ( currentScissor.equals( scissor ) === false ) {
  12001. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12002. currentScissor.copy( scissor );
  12003. }
  12004. }
  12005. function viewport( viewport ) {
  12006. if ( currentViewport.equals( viewport ) === false ) {
  12007. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12008. currentViewport.copy( viewport );
  12009. }
  12010. }
  12011. //
  12012. function reset() {
  12013. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12014. if ( enabledAttributes[ i ] === 1 ) {
  12015. gl.disableVertexAttribArray( i );
  12016. enabledAttributes[ i ] = 0;
  12017. }
  12018. }
  12019. enabledCapabilities = {};
  12020. compressedTextureFormats = null;
  12021. currentTextureSlot = null;
  12022. currentBoundTextures = {};
  12023. currentProgram = null;
  12024. currentBlending = null;
  12025. currentFlipSided = null;
  12026. currentCullFace = null;
  12027. colorBuffer.reset();
  12028. depthBuffer.reset();
  12029. stencilBuffer.reset();
  12030. }
  12031. return {
  12032. buffers: {
  12033. color: colorBuffer,
  12034. depth: depthBuffer,
  12035. stencil: stencilBuffer
  12036. },
  12037. initAttributes: initAttributes,
  12038. enableAttribute: enableAttribute,
  12039. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12040. disableUnusedAttributes: disableUnusedAttributes,
  12041. enable: enable,
  12042. disable: disable,
  12043. getCompressedTextureFormats: getCompressedTextureFormats,
  12044. useProgram: useProgram,
  12045. setBlending: setBlending,
  12046. setMaterial: setMaterial,
  12047. setFlipSided: setFlipSided,
  12048. setCullFace: setCullFace,
  12049. setLineWidth: setLineWidth,
  12050. setPolygonOffset: setPolygonOffset,
  12051. setScissorTest: setScissorTest,
  12052. activeTexture: activeTexture,
  12053. bindTexture: bindTexture,
  12054. compressedTexImage2D: compressedTexImage2D,
  12055. texImage2D: texImage2D,
  12056. texImage3D: texImage3D,
  12057. scissor: scissor,
  12058. viewport: viewport,
  12059. reset: reset
  12060. };
  12061. }
  12062. /**
  12063. * @author mrdoob / http://mrdoob.com/
  12064. */
  12065. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12066. var _videoTextures = {};
  12067. var _canvas;
  12068. //
  12069. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12070. function createCanvas( width, height ) {
  12071. // Use OffscreenCanvas when available. Specially needed in web workers
  12072. return useOffscreenCanvas ?
  12073. new OffscreenCanvas( width, height ) :
  12074. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12075. }
  12076. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12077. var scale = 1;
  12078. // handle case if texture exceeds max size
  12079. if ( image.width > maxSize || image.height > maxSize ) {
  12080. scale = maxSize / Math.max( image.width, image.height );
  12081. }
  12082. // only perform resize if necessary
  12083. if ( scale < 1 || needsPowerOfTwo === true ) {
  12084. // only perform resize for certain image types
  12085. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12086. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12087. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12088. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12089. var width = floor( scale * image.width );
  12090. var height = floor( scale * image.height );
  12091. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12092. // cube textures can't reuse the same canvas
  12093. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12094. canvas.width = width;
  12095. canvas.height = height;
  12096. var context = canvas.getContext( '2d' );
  12097. context.drawImage( image, 0, 0, width, height );
  12098. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12099. return canvas;
  12100. } else {
  12101. if ( 'data' in image ) {
  12102. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12103. }
  12104. return image;
  12105. }
  12106. }
  12107. return image;
  12108. }
  12109. function isPowerOfTwo( image ) {
  12110. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12111. }
  12112. function textureNeedsPowerOfTwo( texture ) {
  12113. if ( capabilities.isWebGL2 ) return false;
  12114. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12115. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12116. }
  12117. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12118. return texture.generateMipmaps && supportsMips &&
  12119. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12120. }
  12121. function generateMipmap( target, texture, width, height ) {
  12122. _gl.generateMipmap( target );
  12123. var textureProperties = properties.get( texture );
  12124. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12125. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12126. }
  12127. function getInternalFormat( glFormat, glType ) {
  12128. if ( ! capabilities.isWebGL2 ) return glFormat;
  12129. var internalFormat = glFormat;
  12130. if ( glFormat === 6403 ) {
  12131. if ( glType === 5126 ) internalFormat = 33326;
  12132. if ( glType === 5131 ) internalFormat = 33325;
  12133. if ( glType === 5121 ) internalFormat = 33321;
  12134. }
  12135. if ( glFormat === 6407 ) {
  12136. if ( glType === 5126 ) internalFormat = 34837;
  12137. if ( glType === 5131 ) internalFormat = 34843;
  12138. if ( glType === 5121 ) internalFormat = 32849;
  12139. }
  12140. if ( glFormat === 6408 ) {
  12141. if ( glType === 5126 ) internalFormat = 34836;
  12142. if ( glType === 5131 ) internalFormat = 34842;
  12143. if ( glType === 5121 ) internalFormat = 32856;
  12144. }
  12145. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12146. internalFormat === 34842 || internalFormat === 34836 ) {
  12147. extensions.get( 'EXT_color_buffer_float' );
  12148. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12149. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12150. }
  12151. return internalFormat;
  12152. }
  12153. // Fallback filters for non-power-of-2 textures
  12154. function filterFallback( f ) {
  12155. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12156. return 9728;
  12157. }
  12158. return 9729;
  12159. }
  12160. //
  12161. function onTextureDispose( event ) {
  12162. var texture = event.target;
  12163. texture.removeEventListener( 'dispose', onTextureDispose );
  12164. deallocateTexture( texture );
  12165. if ( texture.isVideoTexture ) {
  12166. delete _videoTextures[ texture.id ];
  12167. }
  12168. info.memory.textures --;
  12169. }
  12170. function onRenderTargetDispose( event ) {
  12171. var renderTarget = event.target;
  12172. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12173. deallocateRenderTarget( renderTarget );
  12174. info.memory.textures --;
  12175. }
  12176. //
  12177. function deallocateTexture( texture ) {
  12178. var textureProperties = properties.get( texture );
  12179. if ( textureProperties.__webglInit === undefined ) return;
  12180. _gl.deleteTexture( textureProperties.__webglTexture );
  12181. properties.remove( texture );
  12182. }
  12183. function deallocateRenderTarget( renderTarget ) {
  12184. var renderTargetProperties = properties.get( renderTarget );
  12185. var textureProperties = properties.get( renderTarget.texture );
  12186. if ( ! renderTarget ) return;
  12187. if ( textureProperties.__webglTexture !== undefined ) {
  12188. _gl.deleteTexture( textureProperties.__webglTexture );
  12189. }
  12190. if ( renderTarget.depthTexture ) {
  12191. renderTarget.depthTexture.dispose();
  12192. }
  12193. if ( renderTarget.isWebGLRenderTargetCube ) {
  12194. for ( var i = 0; i < 6; i ++ ) {
  12195. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12196. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12197. }
  12198. } else {
  12199. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12200. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12201. }
  12202. properties.remove( renderTarget.texture );
  12203. properties.remove( renderTarget );
  12204. }
  12205. //
  12206. var textureUnits = 0;
  12207. function resetTextureUnits() {
  12208. textureUnits = 0;
  12209. }
  12210. function allocateTextureUnit() {
  12211. var textureUnit = textureUnits;
  12212. if ( textureUnit >= capabilities.maxTextures ) {
  12213. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12214. }
  12215. textureUnits += 1;
  12216. return textureUnit;
  12217. }
  12218. //
  12219. function setTexture2D( texture, slot ) {
  12220. var textureProperties = properties.get( texture );
  12221. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12222. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12223. var image = texture.image;
  12224. if ( image === undefined ) {
  12225. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12226. } else if ( image.complete === false ) {
  12227. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12228. } else {
  12229. uploadTexture( textureProperties, texture, slot );
  12230. return;
  12231. }
  12232. }
  12233. state.activeTexture( 33984 + slot );
  12234. state.bindTexture( 3553, textureProperties.__webglTexture );
  12235. }
  12236. function setTexture2DArray( texture, slot ) {
  12237. var textureProperties = properties.get( texture );
  12238. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12239. uploadTexture( textureProperties, texture, slot );
  12240. return;
  12241. }
  12242. state.activeTexture( 33984 + slot );
  12243. state.bindTexture( 35866, textureProperties.__webglTexture );
  12244. }
  12245. function setTexture3D( texture, slot ) {
  12246. var textureProperties = properties.get( texture );
  12247. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12248. uploadTexture( textureProperties, texture, slot );
  12249. return;
  12250. }
  12251. state.activeTexture( 33984 + slot );
  12252. state.bindTexture( 32879, textureProperties.__webglTexture );
  12253. }
  12254. function setTextureCube( texture, slot ) {
  12255. var textureProperties = properties.get( texture );
  12256. if ( texture.image.length === 6 ) {
  12257. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12258. initTexture( textureProperties, texture );
  12259. state.activeTexture( 33984 + slot );
  12260. state.bindTexture( 34067, textureProperties.__webglTexture );
  12261. _gl.pixelStorei( 37440, texture.flipY );
  12262. var isCompressed = ( texture && texture.isCompressedTexture );
  12263. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12264. var cubeImage = [];
  12265. for ( var i = 0; i < 6; i ++ ) {
  12266. if ( ! isCompressed && ! isDataTexture ) {
  12267. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12268. } else {
  12269. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12270. }
  12271. }
  12272. var image = cubeImage[ 0 ],
  12273. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12274. glFormat = utils.convert( texture.format ),
  12275. glType = utils.convert( texture.type ),
  12276. glInternalFormat = getInternalFormat( glFormat, glType );
  12277. setTextureParameters( 34067, texture, supportsMips );
  12278. for ( var i = 0; i < 6; i ++ ) {
  12279. if ( ! isCompressed ) {
  12280. if ( isDataTexture ) {
  12281. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12282. } else {
  12283. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12284. }
  12285. } else {
  12286. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12287. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12288. mipmap = mipmaps[ j ];
  12289. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12290. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12291. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12292. } else {
  12293. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12294. }
  12295. } else {
  12296. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12297. }
  12298. }
  12299. }
  12300. }
  12301. if ( ! isCompressed ) {
  12302. textureProperties.__maxMipLevel = 0;
  12303. } else {
  12304. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12305. }
  12306. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12307. // We assume images for cube map have the same size.
  12308. generateMipmap( 34067, texture, image.width, image.height );
  12309. }
  12310. textureProperties.__version = texture.version;
  12311. if ( texture.onUpdate ) texture.onUpdate( texture );
  12312. } else {
  12313. state.activeTexture( 33984 + slot );
  12314. state.bindTexture( 34067, textureProperties.__webglTexture );
  12315. }
  12316. }
  12317. }
  12318. function setTextureCubeDynamic( texture, slot ) {
  12319. state.activeTexture( 33984 + slot );
  12320. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12321. }
  12322. function setTextureParameters( textureType, texture, supportsMips ) {
  12323. var extension;
  12324. if ( supportsMips ) {
  12325. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12326. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12327. if ( textureType === 32879 || textureType === 35866 ) {
  12328. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12329. }
  12330. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12331. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12332. } else {
  12333. _gl.texParameteri( textureType, 10242, 33071 );
  12334. _gl.texParameteri( textureType, 10243, 33071 );
  12335. if ( textureType === 32879 || textureType === 35866 ) {
  12336. _gl.texParameteri( textureType, 32882, 33071 );
  12337. }
  12338. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12339. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12340. }
  12341. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12342. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12343. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12344. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12345. }
  12346. }
  12347. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12348. if ( extension ) {
  12349. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12350. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12351. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12352. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12353. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12354. }
  12355. }
  12356. }
  12357. function initTexture( textureProperties, texture ) {
  12358. if ( textureProperties.__webglInit === undefined ) {
  12359. textureProperties.__webglInit = true;
  12360. texture.addEventListener( 'dispose', onTextureDispose );
  12361. textureProperties.__webglTexture = _gl.createTexture();
  12362. info.memory.textures ++;
  12363. }
  12364. }
  12365. function uploadTexture( textureProperties, texture, slot ) {
  12366. var textureType = 3553;
  12367. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12368. if ( texture.isDataTexture3D ) textureType = 32879;
  12369. initTexture( textureProperties, texture );
  12370. state.activeTexture( 33984 + slot );
  12371. state.bindTexture( textureType, textureProperties.__webglTexture );
  12372. _gl.pixelStorei( 37440, texture.flipY );
  12373. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12374. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12375. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12376. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12377. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12378. glFormat = utils.convert( texture.format ),
  12379. glType = utils.convert( texture.type ),
  12380. glInternalFormat = getInternalFormat( glFormat, glType );
  12381. setTextureParameters( textureType, texture, supportsMips );
  12382. var mipmap, mipmaps = texture.mipmaps;
  12383. if ( texture.isDepthTexture ) {
  12384. // populate depth texture with dummy data
  12385. glInternalFormat = 6402;
  12386. if ( texture.type === FloatType ) {
  12387. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12388. glInternalFormat = 36012;
  12389. } else if ( capabilities.isWebGL2 ) {
  12390. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12391. glInternalFormat = 33189;
  12392. }
  12393. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12394. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12395. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12396. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12397. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12398. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12399. texture.type = UnsignedShortType;
  12400. glType = utils.convert( texture.type );
  12401. }
  12402. }
  12403. // Depth stencil textures need the DEPTH_STENCIL internal format
  12404. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12405. if ( texture.format === DepthStencilFormat ) {
  12406. glInternalFormat = 34041;
  12407. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12408. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12409. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12410. if ( texture.type !== UnsignedInt248Type ) {
  12411. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12412. texture.type = UnsignedInt248Type;
  12413. glType = utils.convert( texture.type );
  12414. }
  12415. }
  12416. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12417. } else if ( texture.isDataTexture ) {
  12418. // use manually created mipmaps if available
  12419. // if there are no manual mipmaps
  12420. // set 0 level mipmap and then use GL to generate other mipmap levels
  12421. if ( mipmaps.length > 0 && supportsMips ) {
  12422. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12423. mipmap = mipmaps[ i ];
  12424. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12425. }
  12426. texture.generateMipmaps = false;
  12427. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12428. } else {
  12429. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12430. textureProperties.__maxMipLevel = 0;
  12431. }
  12432. } else if ( texture.isCompressedTexture ) {
  12433. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12434. mipmap = mipmaps[ i ];
  12435. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12436. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12437. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12438. } else {
  12439. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12440. }
  12441. } else {
  12442. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12443. }
  12444. }
  12445. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12446. } else if ( texture.isDataTexture2DArray ) {
  12447. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12448. textureProperties.__maxMipLevel = 0;
  12449. } else if ( texture.isDataTexture3D ) {
  12450. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12451. textureProperties.__maxMipLevel = 0;
  12452. } else {
  12453. // regular Texture (image, video, canvas)
  12454. // use manually created mipmaps if available
  12455. // if there are no manual mipmaps
  12456. // set 0 level mipmap and then use GL to generate other mipmap levels
  12457. if ( mipmaps.length > 0 && supportsMips ) {
  12458. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12459. mipmap = mipmaps[ i ];
  12460. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12461. }
  12462. texture.generateMipmaps = false;
  12463. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12464. } else {
  12465. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12466. textureProperties.__maxMipLevel = 0;
  12467. }
  12468. }
  12469. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12470. generateMipmap( 3553, texture, image.width, image.height );
  12471. }
  12472. textureProperties.__version = texture.version;
  12473. if ( texture.onUpdate ) texture.onUpdate( texture );
  12474. }
  12475. // Render targets
  12476. // Setup storage for target texture and bind it to correct framebuffer
  12477. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12478. var glFormat = utils.convert( renderTarget.texture.format );
  12479. var glType = utils.convert( renderTarget.texture.type );
  12480. var glInternalFormat = getInternalFormat( glFormat, glType );
  12481. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12482. _gl.bindFramebuffer( 36160, framebuffer );
  12483. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12484. _gl.bindFramebuffer( 36160, null );
  12485. }
  12486. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12487. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12488. _gl.bindRenderbuffer( 36161, renderbuffer );
  12489. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12490. if ( isMultisample ) {
  12491. var samples = getRenderTargetSamples( renderTarget );
  12492. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12493. } else {
  12494. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12495. }
  12496. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12497. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12498. if ( isMultisample ) {
  12499. var samples = getRenderTargetSamples( renderTarget );
  12500. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12501. } else {
  12502. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12503. }
  12504. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12505. } else {
  12506. var glFormat = utils.convert( renderTarget.texture.format );
  12507. var glType = utils.convert( renderTarget.texture.type );
  12508. var glInternalFormat = getInternalFormat( glFormat, glType );
  12509. if ( isMultisample ) {
  12510. var samples = getRenderTargetSamples( renderTarget );
  12511. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12512. } else {
  12513. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12514. }
  12515. }
  12516. _gl.bindRenderbuffer( 36161, null );
  12517. }
  12518. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12519. function setupDepthTexture( framebuffer, renderTarget ) {
  12520. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12521. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12522. _gl.bindFramebuffer( 36160, framebuffer );
  12523. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12524. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12525. }
  12526. // upload an empty depth texture with framebuffer size
  12527. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12528. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12529. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12530. renderTarget.depthTexture.image.width = renderTarget.width;
  12531. renderTarget.depthTexture.image.height = renderTarget.height;
  12532. renderTarget.depthTexture.needsUpdate = true;
  12533. }
  12534. setTexture2D( renderTarget.depthTexture, 0 );
  12535. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12536. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12537. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12538. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12539. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12540. } else {
  12541. throw new Error( 'Unknown depthTexture format' );
  12542. }
  12543. }
  12544. // Setup GL resources for a non-texture depth buffer
  12545. function setupDepthRenderbuffer( renderTarget ) {
  12546. var renderTargetProperties = properties.get( renderTarget );
  12547. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12548. if ( renderTarget.depthTexture ) {
  12549. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12550. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12551. } else {
  12552. if ( isCube ) {
  12553. renderTargetProperties.__webglDepthbuffer = [];
  12554. for ( var i = 0; i < 6; i ++ ) {
  12555. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12556. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12557. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12558. }
  12559. } else {
  12560. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12561. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12562. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12563. }
  12564. }
  12565. _gl.bindFramebuffer( 36160, null );
  12566. }
  12567. // Set up GL resources for the render target
  12568. function setupRenderTarget( renderTarget ) {
  12569. var renderTargetProperties = properties.get( renderTarget );
  12570. var textureProperties = properties.get( renderTarget.texture );
  12571. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12572. textureProperties.__webglTexture = _gl.createTexture();
  12573. info.memory.textures ++;
  12574. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12575. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12576. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12577. // Setup framebuffer
  12578. if ( isCube ) {
  12579. renderTargetProperties.__webglFramebuffer = [];
  12580. for ( var i = 0; i < 6; i ++ ) {
  12581. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12582. }
  12583. } else {
  12584. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12585. if ( isMultisample ) {
  12586. if ( capabilities.isWebGL2 ) {
  12587. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12588. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12589. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12590. var glFormat = utils.convert( renderTarget.texture.format );
  12591. var glType = utils.convert( renderTarget.texture.type );
  12592. var glInternalFormat = getInternalFormat( glFormat, glType );
  12593. var samples = getRenderTargetSamples( renderTarget );
  12594. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12595. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12596. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12597. _gl.bindRenderbuffer( 36161, null );
  12598. if ( renderTarget.depthBuffer ) {
  12599. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12600. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12601. }
  12602. _gl.bindFramebuffer( 36160, null );
  12603. } else {
  12604. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12605. }
  12606. }
  12607. }
  12608. // Setup color buffer
  12609. if ( isCube ) {
  12610. state.bindTexture( 34067, textureProperties.__webglTexture );
  12611. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12612. for ( var i = 0; i < 6; i ++ ) {
  12613. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12614. }
  12615. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12616. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12617. }
  12618. state.bindTexture( 34067, null );
  12619. } else {
  12620. state.bindTexture( 3553, textureProperties.__webglTexture );
  12621. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12622. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12623. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12624. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12625. }
  12626. state.bindTexture( 3553, null );
  12627. }
  12628. // Setup depth and stencil buffers
  12629. if ( renderTarget.depthBuffer ) {
  12630. setupDepthRenderbuffer( renderTarget );
  12631. }
  12632. }
  12633. function updateRenderTargetMipmap( renderTarget ) {
  12634. var texture = renderTarget.texture;
  12635. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12636. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12637. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12638. var webglTexture = properties.get( texture ).__webglTexture;
  12639. state.bindTexture( target, webglTexture );
  12640. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12641. state.bindTexture( target, null );
  12642. }
  12643. }
  12644. function updateMultisampleRenderTarget( renderTarget ) {
  12645. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12646. if ( capabilities.isWebGL2 ) {
  12647. var renderTargetProperties = properties.get( renderTarget );
  12648. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12649. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12650. var width = renderTarget.width;
  12651. var height = renderTarget.height;
  12652. var mask = 16384;
  12653. if ( renderTarget.depthBuffer ) mask |= 256;
  12654. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12655. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12656. } else {
  12657. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12658. }
  12659. }
  12660. }
  12661. function getRenderTargetSamples( renderTarget ) {
  12662. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12663. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12664. }
  12665. function updateVideoTexture( texture ) {
  12666. var id = texture.id;
  12667. var frame = info.render.frame;
  12668. // Check the last frame we updated the VideoTexture
  12669. if ( _videoTextures[ id ] !== frame ) {
  12670. _videoTextures[ id ] = frame;
  12671. texture.update();
  12672. }
  12673. }
  12674. // backwards compatibility
  12675. var warnedTexture2D = false;
  12676. var warnedTextureCube = false;
  12677. function safeSetTexture2D( texture, slot ) {
  12678. if ( texture && texture.isWebGLRenderTarget ) {
  12679. if ( warnedTexture2D === false ) {
  12680. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  12681. warnedTexture2D = true;
  12682. }
  12683. texture = texture.texture;
  12684. }
  12685. setTexture2D( texture, slot );
  12686. }
  12687. function safeSetTextureCube( texture, slot ) {
  12688. if ( texture && texture.isWebGLRenderTargetCube ) {
  12689. if ( warnedTextureCube === false ) {
  12690. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  12691. warnedTextureCube = true;
  12692. }
  12693. texture = texture.texture;
  12694. }
  12695. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  12696. // TODO: unify these code paths
  12697. if ( ( texture && texture.isCubeTexture ) ||
  12698. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  12699. // CompressedTexture can have Array in image :/
  12700. // this function alone should take care of cube textures
  12701. setTextureCube( texture, slot );
  12702. } else {
  12703. // assumed: texture property of THREE.WebGLRenderTargetCube
  12704. setTextureCubeDynamic( texture, slot );
  12705. }
  12706. }
  12707. //
  12708. this.allocateTextureUnit = allocateTextureUnit;
  12709. this.resetTextureUnits = resetTextureUnits;
  12710. this.setTexture2D = setTexture2D;
  12711. this.setTexture2DArray = setTexture2DArray;
  12712. this.setTexture3D = setTexture3D;
  12713. this.setTextureCube = setTextureCube;
  12714. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12715. this.setupRenderTarget = setupRenderTarget;
  12716. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12717. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12718. this.safeSetTexture2D = safeSetTexture2D;
  12719. this.safeSetTextureCube = safeSetTextureCube;
  12720. }
  12721. /**
  12722. * @author thespite / http://www.twitter.com/thespite
  12723. */
  12724. function WebGLUtils( gl, extensions, capabilities ) {
  12725. function convert( p ) {
  12726. var extension;
  12727. if ( p === RepeatWrapping ) return 10497;
  12728. if ( p === ClampToEdgeWrapping ) return 33071;
  12729. if ( p === MirroredRepeatWrapping ) return 33648;
  12730. if ( p === NearestFilter ) return 9728;
  12731. if ( p === NearestMipMapNearestFilter ) return 9984;
  12732. if ( p === NearestMipMapLinearFilter ) return 9986;
  12733. if ( p === LinearFilter ) return 9729;
  12734. if ( p === LinearMipMapNearestFilter ) return 9985;
  12735. if ( p === LinearMipMapLinearFilter ) return 9987;
  12736. if ( p === UnsignedByteType ) return 5121;
  12737. if ( p === UnsignedShort4444Type ) return 32819;
  12738. if ( p === UnsignedShort5551Type ) return 32820;
  12739. if ( p === UnsignedShort565Type ) return 33635;
  12740. if ( p === ByteType ) return 5120;
  12741. if ( p === ShortType ) return 5122;
  12742. if ( p === UnsignedShortType ) return 5123;
  12743. if ( p === IntType ) return 5124;
  12744. if ( p === UnsignedIntType ) return 5125;
  12745. if ( p === FloatType ) return 5126;
  12746. if ( p === HalfFloatType ) {
  12747. if ( capabilities.isWebGL2 ) return 5131;
  12748. extension = extensions.get( 'OES_texture_half_float' );
  12749. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12750. }
  12751. if ( p === AlphaFormat ) return 6406;
  12752. if ( p === RGBFormat ) return 6407;
  12753. if ( p === RGBAFormat ) return 6408;
  12754. if ( p === LuminanceFormat ) return 6409;
  12755. if ( p === LuminanceAlphaFormat ) return 6410;
  12756. if ( p === DepthFormat ) return 6402;
  12757. if ( p === DepthStencilFormat ) return 34041;
  12758. if ( p === RedFormat ) return 6403;
  12759. if ( p === AddEquation ) return 32774;
  12760. if ( p === SubtractEquation ) return 32778;
  12761. if ( p === ReverseSubtractEquation ) return 32779;
  12762. if ( p === ZeroFactor ) return 0;
  12763. if ( p === OneFactor ) return 1;
  12764. if ( p === SrcColorFactor ) return 768;
  12765. if ( p === OneMinusSrcColorFactor ) return 769;
  12766. if ( p === SrcAlphaFactor ) return 770;
  12767. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12768. if ( p === DstAlphaFactor ) return 772;
  12769. if ( p === OneMinusDstAlphaFactor ) return 773;
  12770. if ( p === DstColorFactor ) return 774;
  12771. if ( p === OneMinusDstColorFactor ) return 775;
  12772. if ( p === SrcAlphaSaturateFactor ) return 776;
  12773. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12774. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12775. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12776. if ( extension !== null ) {
  12777. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12778. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12779. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12780. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12781. }
  12782. }
  12783. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12784. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12785. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12786. if ( extension !== null ) {
  12787. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12788. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12789. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12790. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12791. }
  12792. }
  12793. if ( p === RGB_ETC1_Format ) {
  12794. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12795. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12796. }
  12797. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12798. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12799. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12800. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12801. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12802. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12803. if ( extension !== null ) {
  12804. return p;
  12805. }
  12806. }
  12807. if ( p === MinEquation || p === MaxEquation ) {
  12808. if ( capabilities.isWebGL2 ) {
  12809. if ( p === MinEquation ) return 32775;
  12810. if ( p === MaxEquation ) return 32776;
  12811. }
  12812. extension = extensions.get( 'EXT_blend_minmax' );
  12813. if ( extension !== null ) {
  12814. if ( p === MinEquation ) return extension.MIN_EXT;
  12815. if ( p === MaxEquation ) return extension.MAX_EXT;
  12816. }
  12817. }
  12818. if ( p === UnsignedInt248Type ) {
  12819. if ( capabilities.isWebGL2 ) return 34042;
  12820. extension = extensions.get( 'WEBGL_depth_texture' );
  12821. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12822. }
  12823. return 0;
  12824. }
  12825. return { convert: convert };
  12826. }
  12827. /**
  12828. * @author mrdoob / http://mrdoob.com/
  12829. */
  12830. function Group() {
  12831. Object3D.call( this );
  12832. this.type = 'Group';
  12833. }
  12834. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12835. constructor: Group,
  12836. isGroup: true
  12837. } );
  12838. /**
  12839. * @author mrdoob / http://mrdoob.com/
  12840. * @author mikael emtinger / http://gomo.se/
  12841. * @author WestLangley / http://github.com/WestLangley
  12842. */
  12843. function Camera() {
  12844. Object3D.call( this );
  12845. this.type = 'Camera';
  12846. this.matrixWorldInverse = new Matrix4();
  12847. this.projectionMatrix = new Matrix4();
  12848. this.projectionMatrixInverse = new Matrix4();
  12849. }
  12850. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12851. constructor: Camera,
  12852. isCamera: true,
  12853. copy: function ( source, recursive ) {
  12854. Object3D.prototype.copy.call( this, source, recursive );
  12855. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12856. this.projectionMatrix.copy( source.projectionMatrix );
  12857. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12858. return this;
  12859. },
  12860. getWorldDirection: function ( target ) {
  12861. if ( target === undefined ) {
  12862. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12863. target = new Vector3();
  12864. }
  12865. this.updateMatrixWorld( true );
  12866. var e = this.matrixWorld.elements;
  12867. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12868. },
  12869. updateMatrixWorld: function ( force ) {
  12870. Object3D.prototype.updateMatrixWorld.call( this, force );
  12871. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12872. },
  12873. clone: function () {
  12874. return new this.constructor().copy( this );
  12875. }
  12876. } );
  12877. /**
  12878. * @author mrdoob / http://mrdoob.com/
  12879. * @author greggman / http://games.greggman.com/
  12880. * @author zz85 / http://www.lab4games.net/zz85/blog
  12881. * @author tschw
  12882. */
  12883. function PerspectiveCamera( fov, aspect, near, far ) {
  12884. Camera.call( this );
  12885. this.type = 'PerspectiveCamera';
  12886. this.fov = fov !== undefined ? fov : 50;
  12887. this.zoom = 1;
  12888. this.near = near !== undefined ? near : 0.1;
  12889. this.far = far !== undefined ? far : 2000;
  12890. this.focus = 10;
  12891. this.aspect = aspect !== undefined ? aspect : 1;
  12892. this.view = null;
  12893. this.filmGauge = 35; // width of the film (default in millimeters)
  12894. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12895. this.updateProjectionMatrix();
  12896. }
  12897. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12898. constructor: PerspectiveCamera,
  12899. isPerspectiveCamera: true,
  12900. copy: function ( source, recursive ) {
  12901. Camera.prototype.copy.call( this, source, recursive );
  12902. this.fov = source.fov;
  12903. this.zoom = source.zoom;
  12904. this.near = source.near;
  12905. this.far = source.far;
  12906. this.focus = source.focus;
  12907. this.aspect = source.aspect;
  12908. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12909. this.filmGauge = source.filmGauge;
  12910. this.filmOffset = source.filmOffset;
  12911. return this;
  12912. },
  12913. /**
  12914. * Sets the FOV by focal length in respect to the current .filmGauge.
  12915. *
  12916. * The default film gauge is 35, so that the focal length can be specified for
  12917. * a 35mm (full frame) camera.
  12918. *
  12919. * Values for focal length and film gauge must have the same unit.
  12920. */
  12921. setFocalLength: function ( focalLength ) {
  12922. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12923. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12924. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12925. this.updateProjectionMatrix();
  12926. },
  12927. /**
  12928. * Calculates the focal length from the current .fov and .filmGauge.
  12929. */
  12930. getFocalLength: function () {
  12931. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12932. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12933. },
  12934. getEffectiveFOV: function () {
  12935. return _Math.RAD2DEG * 2 * Math.atan(
  12936. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12937. },
  12938. getFilmWidth: function () {
  12939. // film not completely covered in portrait format (aspect < 1)
  12940. return this.filmGauge * Math.min( this.aspect, 1 );
  12941. },
  12942. getFilmHeight: function () {
  12943. // film not completely covered in landscape format (aspect > 1)
  12944. return this.filmGauge / Math.max( this.aspect, 1 );
  12945. },
  12946. /**
  12947. * Sets an offset in a larger frustum. This is useful for multi-window or
  12948. * multi-monitor/multi-machine setups.
  12949. *
  12950. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12951. * the monitors are in grid like this
  12952. *
  12953. * +---+---+---+
  12954. * | A | B | C |
  12955. * +---+---+---+
  12956. * | D | E | F |
  12957. * +---+---+---+
  12958. *
  12959. * then for each monitor you would call it like this
  12960. *
  12961. * var w = 1920;
  12962. * var h = 1080;
  12963. * var fullWidth = w * 3;
  12964. * var fullHeight = h * 2;
  12965. *
  12966. * --A--
  12967. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12968. * --B--
  12969. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12970. * --C--
  12971. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12972. * --D--
  12973. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12974. * --E--
  12975. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12976. * --F--
  12977. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12978. *
  12979. * Note there is no reason monitors have to be the same size or in a grid.
  12980. */
  12981. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12982. this.aspect = fullWidth / fullHeight;
  12983. if ( this.view === null ) {
  12984. this.view = {
  12985. enabled: true,
  12986. fullWidth: 1,
  12987. fullHeight: 1,
  12988. offsetX: 0,
  12989. offsetY: 0,
  12990. width: 1,
  12991. height: 1
  12992. };
  12993. }
  12994. this.view.enabled = true;
  12995. this.view.fullWidth = fullWidth;
  12996. this.view.fullHeight = fullHeight;
  12997. this.view.offsetX = x;
  12998. this.view.offsetY = y;
  12999. this.view.width = width;
  13000. this.view.height = height;
  13001. this.updateProjectionMatrix();
  13002. },
  13003. clearViewOffset: function () {
  13004. if ( this.view !== null ) {
  13005. this.view.enabled = false;
  13006. }
  13007. this.updateProjectionMatrix();
  13008. },
  13009. updateProjectionMatrix: function () {
  13010. var near = this.near,
  13011. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  13012. height = 2 * top,
  13013. width = this.aspect * height,
  13014. left = - 0.5 * width,
  13015. view = this.view;
  13016. if ( this.view !== null && this.view.enabled ) {
  13017. var fullWidth = view.fullWidth,
  13018. fullHeight = view.fullHeight;
  13019. left += view.offsetX * width / fullWidth;
  13020. top -= view.offsetY * height / fullHeight;
  13021. width *= view.width / fullWidth;
  13022. height *= view.height / fullHeight;
  13023. }
  13024. var skew = this.filmOffset;
  13025. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  13026. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  13027. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  13028. },
  13029. toJSON: function ( meta ) {
  13030. var data = Object3D.prototype.toJSON.call( this, meta );
  13031. data.object.fov = this.fov;
  13032. data.object.zoom = this.zoom;
  13033. data.object.near = this.near;
  13034. data.object.far = this.far;
  13035. data.object.focus = this.focus;
  13036. data.object.aspect = this.aspect;
  13037. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  13038. data.object.filmGauge = this.filmGauge;
  13039. data.object.filmOffset = this.filmOffset;
  13040. return data;
  13041. }
  13042. } );
  13043. /**
  13044. * @author mrdoob / http://mrdoob.com/
  13045. */
  13046. function ArrayCamera( array ) {
  13047. PerspectiveCamera.call( this );
  13048. this.cameras = array || [];
  13049. }
  13050. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13051. constructor: ArrayCamera,
  13052. isArrayCamera: true
  13053. } );
  13054. /**
  13055. * @author jsantell / https://www.jsantell.com/
  13056. * @author mrdoob / http://mrdoob.com/
  13057. */
  13058. var cameraLPos = new Vector3();
  13059. var cameraRPos = new Vector3();
  13060. /**
  13061. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13062. * the cameras' projection and world matrices have already been set.
  13063. * And that near and far planes are identical for both cameras.
  13064. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13065. */
  13066. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13067. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13068. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13069. var ipd = cameraLPos.distanceTo( cameraRPos );
  13070. var projL = cameraL.projectionMatrix.elements;
  13071. var projR = cameraR.projectionMatrix.elements;
  13072. // VR systems will have identical far and near planes, and
  13073. // most likely identical top and bottom frustum extents.
  13074. // Use the left camera for these values.
  13075. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13076. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13077. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13078. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13079. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13080. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13081. var left = near * leftFov;
  13082. var right = near * rightFov;
  13083. // Calculate the new camera's position offset from the
  13084. // left camera. xOffset should be roughly half `ipd`.
  13085. var zOffset = ipd / ( - leftFov + rightFov );
  13086. var xOffset = zOffset * - leftFov;
  13087. // TODO: Better way to apply this offset?
  13088. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13089. camera.translateX( xOffset );
  13090. camera.translateZ( zOffset );
  13091. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13092. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13093. // Find the union of the frustum values of the cameras and scale
  13094. // the values so that the near plane's position does not change in world space,
  13095. // although must now be relative to the new union camera.
  13096. var near2 = near + zOffset;
  13097. var far2 = far + zOffset;
  13098. var left2 = left - xOffset;
  13099. var right2 = right + ( ipd - xOffset );
  13100. var top2 = topFov * far / far2 * near2;
  13101. var bottom2 = bottomFov * far / far2 * near2;
  13102. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13103. }
  13104. /**
  13105. * @author mrdoob / http://mrdoob.com/
  13106. */
  13107. function WebVRManager( renderer ) {
  13108. var scope = this;
  13109. var device = null;
  13110. var frameData = null;
  13111. var poseTarget = null;
  13112. var controllers = [];
  13113. var standingMatrix = new Matrix4();
  13114. var standingMatrixInverse = new Matrix4();
  13115. var framebufferScaleFactor = 1.0;
  13116. var frameOfReferenceType = 'stage';
  13117. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13118. frameData = new window.VRFrameData();
  13119. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13120. }
  13121. var matrixWorldInverse = new Matrix4();
  13122. var tempQuaternion = new Quaternion();
  13123. var tempPosition = new Vector3();
  13124. var cameraL = new PerspectiveCamera();
  13125. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  13126. cameraL.layers.enable( 1 );
  13127. var cameraR = new PerspectiveCamera();
  13128. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  13129. cameraR.layers.enable( 2 );
  13130. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13131. cameraVR.layers.enable( 1 );
  13132. cameraVR.layers.enable( 2 );
  13133. //
  13134. function isPresenting() {
  13135. return device !== null && device.isPresenting === true;
  13136. }
  13137. var currentSize = new Vector2(), currentPixelRatio;
  13138. function onVRDisplayPresentChange() {
  13139. if ( isPresenting() ) {
  13140. var eyeParameters = device.getEyeParameters( 'left' );
  13141. var renderWidth = eyeParameters.renderWidth * framebufferScaleFactor;
  13142. var renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13143. currentPixelRatio = renderer.getPixelRatio();
  13144. renderer.getSize( currentSize );
  13145. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  13146. animation.start();
  13147. } else {
  13148. if ( scope.enabled ) {
  13149. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13150. }
  13151. animation.stop();
  13152. }
  13153. }
  13154. //
  13155. var triggers = [];
  13156. function findGamepad( id ) {
  13157. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13158. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13159. var gamepad = gamepads[ i ];
  13160. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13161. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13162. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13163. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13164. if ( j === id ) return gamepad;
  13165. j ++;
  13166. }
  13167. }
  13168. }
  13169. function updateControllers() {
  13170. for ( var i = 0; i < controllers.length; i ++ ) {
  13171. var controller = controllers[ i ];
  13172. var gamepad = findGamepad( i );
  13173. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13174. if ( gamepad.pose === null ) return;
  13175. // Pose
  13176. var pose = gamepad.pose;
  13177. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13178. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13179. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13180. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13181. controller.matrix.premultiply( standingMatrix );
  13182. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13183. controller.matrixWorldNeedsUpdate = true;
  13184. controller.visible = true;
  13185. // Trigger
  13186. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13187. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13188. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13189. if ( triggers[ i ] === true ) {
  13190. controller.dispatchEvent( { type: 'selectstart' } );
  13191. } else {
  13192. controller.dispatchEvent( { type: 'selectend' } );
  13193. controller.dispatchEvent( { type: 'select' } );
  13194. }
  13195. }
  13196. } else {
  13197. controller.visible = false;
  13198. }
  13199. }
  13200. }
  13201. //
  13202. this.enabled = false;
  13203. this.getController = function ( id ) {
  13204. var controller = controllers[ id ];
  13205. if ( controller === undefined ) {
  13206. controller = new Group();
  13207. controller.matrixAutoUpdate = false;
  13208. controller.visible = false;
  13209. controllers[ id ] = controller;
  13210. }
  13211. return controller;
  13212. };
  13213. this.getDevice = function () {
  13214. return device;
  13215. };
  13216. this.setDevice = function ( value ) {
  13217. if ( value !== undefined ) device = value;
  13218. animation.setContext( value );
  13219. };
  13220. this.setFramebufferScaleFactor = function ( value ) {
  13221. framebufferScaleFactor = value;
  13222. };
  13223. this.setFrameOfReferenceType = function ( value ) {
  13224. frameOfReferenceType = value;
  13225. };
  13226. this.setPoseTarget = function ( object ) {
  13227. if ( object !== undefined ) poseTarget = object;
  13228. };
  13229. this.getCamera = function ( camera ) {
  13230. var userHeight = frameOfReferenceType === 'stage' ? 1.6 : 0;
  13231. if ( isPresenting() === false ) {
  13232. camera.position.set( 0, userHeight, 0 );
  13233. camera.rotation.set( 0, 0, 0 );
  13234. return camera;
  13235. }
  13236. device.depthNear = camera.near;
  13237. device.depthFar = camera.far;
  13238. device.getFrameData( frameData );
  13239. //
  13240. if ( frameOfReferenceType === 'stage' ) {
  13241. var stageParameters = device.stageParameters;
  13242. if ( stageParameters ) {
  13243. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13244. } else {
  13245. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13246. }
  13247. }
  13248. var pose = frameData.pose;
  13249. var poseObject = poseTarget !== null ? poseTarget : camera;
  13250. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13251. poseObject.matrix.copy( standingMatrix );
  13252. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13253. if ( pose.orientation !== null ) {
  13254. tempQuaternion.fromArray( pose.orientation );
  13255. poseObject.quaternion.multiply( tempQuaternion );
  13256. }
  13257. if ( pose.position !== null ) {
  13258. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13259. tempPosition.fromArray( pose.position );
  13260. tempPosition.applyQuaternion( tempQuaternion );
  13261. poseObject.position.add( tempPosition );
  13262. }
  13263. poseObject.updateMatrixWorld();
  13264. //
  13265. cameraL.near = camera.near;
  13266. cameraR.near = camera.near;
  13267. cameraL.far = camera.far;
  13268. cameraR.far = camera.far;
  13269. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13270. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13271. // TODO (mrdoob) Double check this code
  13272. standingMatrixInverse.getInverse( standingMatrix );
  13273. if ( frameOfReferenceType === 'stage' ) {
  13274. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13275. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13276. }
  13277. var parent = poseObject.parent;
  13278. if ( parent !== null ) {
  13279. matrixWorldInverse.getInverse( parent.matrixWorld );
  13280. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13281. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13282. }
  13283. // envMap and Mirror needs camera.matrixWorld
  13284. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13285. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13286. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13287. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13288. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13289. //
  13290. var layers = device.getLayers();
  13291. if ( layers.length ) {
  13292. var layer = layers[ 0 ];
  13293. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  13294. cameraL.bounds.fromArray( layer.leftBounds );
  13295. }
  13296. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  13297. cameraR.bounds.fromArray( layer.rightBounds );
  13298. }
  13299. }
  13300. updateControllers();
  13301. return cameraVR;
  13302. };
  13303. this.getStandingMatrix = function () {
  13304. return standingMatrix;
  13305. };
  13306. this.isPresenting = isPresenting;
  13307. // Animation Loop
  13308. var animation = new WebGLAnimation();
  13309. this.setAnimationLoop = function ( callback ) {
  13310. animation.setAnimationLoop( callback );
  13311. if ( isPresenting() ) animation.start();
  13312. };
  13313. this.submitFrame = function () {
  13314. if ( isPresenting() ) device.submitFrame();
  13315. };
  13316. this.dispose = function () {
  13317. if ( typeof window !== 'undefined' ) {
  13318. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13319. }
  13320. };
  13321. }
  13322. /**
  13323. * @author mrdoob / http://mrdoob.com/
  13324. */
  13325. function WebXRManager( renderer ) {
  13326. var gl = renderer.context;
  13327. var device = null;
  13328. var session = null;
  13329. var framebufferScaleFactor = 1.0;
  13330. var frameOfReference = null;
  13331. var frameOfReferenceType = 'stage';
  13332. var pose = null;
  13333. var controllers = [];
  13334. var inputSources = [];
  13335. function isPresenting() {
  13336. return session !== null && frameOfReference !== null;
  13337. }
  13338. //
  13339. var cameraL = new PerspectiveCamera();
  13340. cameraL.layers.enable( 1 );
  13341. cameraL.viewport = new Vector4();
  13342. var cameraR = new PerspectiveCamera();
  13343. cameraR.layers.enable( 2 );
  13344. cameraR.viewport = new Vector4();
  13345. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13346. cameraVR.layers.enable( 1 );
  13347. cameraVR.layers.enable( 2 );
  13348. //
  13349. this.enabled = false;
  13350. this.getController = function ( id ) {
  13351. var controller = controllers[ id ];
  13352. if ( controller === undefined ) {
  13353. controller = new Group();
  13354. controller.matrixAutoUpdate = false;
  13355. controller.visible = false;
  13356. controllers[ id ] = controller;
  13357. }
  13358. return controller;
  13359. };
  13360. this.getDevice = function () {
  13361. return device;
  13362. };
  13363. this.setDevice = function ( value ) {
  13364. if ( value !== undefined ) device = value;
  13365. if ( value instanceof XRDevice ) gl.setCompatibleXRDevice( value );
  13366. };
  13367. //
  13368. function onSessionEvent( event ) {
  13369. var controller = controllers[ inputSources.indexOf( event.inputSource ) ];
  13370. if ( controller ) controller.dispatchEvent( { type: event.type } );
  13371. }
  13372. function onSessionEnd() {
  13373. renderer.setFramebuffer( null );
  13374. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13375. animation.stop();
  13376. }
  13377. this.setFramebufferScaleFactor = function ( value ) {
  13378. framebufferScaleFactor = value;
  13379. };
  13380. this.setFrameOfReferenceType = function ( value ) {
  13381. frameOfReferenceType = value;
  13382. };
  13383. this.setSession = function ( value ) {
  13384. session = value;
  13385. if ( session !== null ) {
  13386. session.addEventListener( 'select', onSessionEvent );
  13387. session.addEventListener( 'selectstart', onSessionEvent );
  13388. session.addEventListener( 'selectend', onSessionEvent );
  13389. session.addEventListener( 'end', onSessionEnd );
  13390. session.baseLayer = new XRWebGLLayer( session, gl, { framebufferScaleFactor: framebufferScaleFactor } );
  13391. session.requestFrameOfReference( frameOfReferenceType ).then( function ( value ) {
  13392. frameOfReference = value;
  13393. renderer.setFramebuffer( session.baseLayer.framebuffer );
  13394. animation.setContext( session );
  13395. animation.start();
  13396. } );
  13397. //
  13398. inputSources = session.getInputSources();
  13399. session.addEventListener( 'inputsourceschange', function () {
  13400. inputSources = session.getInputSources();
  13401. console.log( inputSources );
  13402. for ( var i = 0; i < controllers.length; i ++ ) {
  13403. var controller = controllers[ i ];
  13404. controller.userData.inputSource = inputSources[ i ];
  13405. }
  13406. } );
  13407. }
  13408. };
  13409. function updateCamera( camera, parent ) {
  13410. if ( parent === null ) {
  13411. camera.matrixWorld.copy( camera.matrix );
  13412. } else {
  13413. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13414. }
  13415. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13416. }
  13417. this.getCamera = function ( camera ) {
  13418. if ( isPresenting() ) {
  13419. var parent = camera.parent;
  13420. var cameras = cameraVR.cameras;
  13421. updateCamera( cameraVR, parent );
  13422. for ( var i = 0; i < cameras.length; i ++ ) {
  13423. updateCamera( cameras[ i ], parent );
  13424. }
  13425. // update camera and its children
  13426. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13427. var children = camera.children;
  13428. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13429. children[ i ].updateMatrixWorld( true );
  13430. }
  13431. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13432. return cameraVR;
  13433. }
  13434. return camera;
  13435. };
  13436. this.isPresenting = isPresenting;
  13437. // Animation Loop
  13438. var onAnimationFrameCallback = null;
  13439. function onAnimationFrame( time, frame ) {
  13440. pose = frame.getDevicePose( frameOfReference );
  13441. if ( pose !== null ) {
  13442. var layer = session.baseLayer;
  13443. var views = frame.views;
  13444. for ( var i = 0; i < views.length; i ++ ) {
  13445. var view = views[ i ];
  13446. var viewport = layer.getViewport( view );
  13447. var viewMatrix = pose.getViewMatrix( view );
  13448. var camera = cameraVR.cameras[ i ];
  13449. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13450. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13451. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13452. if ( i === 0 ) {
  13453. cameraVR.matrix.copy( camera.matrix );
  13454. }
  13455. }
  13456. }
  13457. //
  13458. for ( var i = 0; i < controllers.length; i ++ ) {
  13459. var controller = controllers[ i ];
  13460. var inputSource = inputSources[ i ];
  13461. if ( inputSource ) {
  13462. var inputPose = frame.getInputPose( inputSource, frameOfReference );
  13463. if ( inputPose !== null ) {
  13464. if ( 'targetRay' in inputPose ) {
  13465. controller.matrix.elements = inputPose.targetRay.transformMatrix;
  13466. } else if ( 'pointerMatrix' in inputPose ) {
  13467. // DEPRECATED
  13468. controller.matrix.elements = inputPose.pointerMatrix;
  13469. }
  13470. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13471. controller.visible = true;
  13472. continue;
  13473. }
  13474. }
  13475. controller.visible = false;
  13476. }
  13477. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13478. }
  13479. var animation = new WebGLAnimation();
  13480. animation.setAnimationLoop( onAnimationFrame );
  13481. this.setAnimationLoop = function ( callback ) {
  13482. onAnimationFrameCallback = callback;
  13483. };
  13484. this.dispose = function () {};
  13485. // DEPRECATED
  13486. this.getStandingMatrix = function () {
  13487. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13488. return new Matrix4();
  13489. };
  13490. this.submitFrame = function () {};
  13491. }
  13492. /**
  13493. * @author supereggbert / http://www.paulbrunt.co.uk/
  13494. * @author mrdoob / http://mrdoob.com/
  13495. * @author alteredq / http://alteredqualia.com/
  13496. * @author szimek / https://github.com/szimek/
  13497. * @author tschw
  13498. */
  13499. function WebGLRenderer( parameters ) {
  13500. console.log( 'THREE.WebGLRenderer', REVISION );
  13501. parameters = parameters || {};
  13502. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13503. _context = parameters.context !== undefined ? parameters.context : null,
  13504. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13505. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13506. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13507. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13508. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13509. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13510. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  13511. var currentRenderList = null;
  13512. var currentRenderState = null;
  13513. // public properties
  13514. this.domElement = _canvas;
  13515. this.context = null;
  13516. // clearing
  13517. this.autoClear = true;
  13518. this.autoClearColor = true;
  13519. this.autoClearDepth = true;
  13520. this.autoClearStencil = true;
  13521. // scene graph
  13522. this.sortObjects = true;
  13523. // user-defined clipping
  13524. this.clippingPlanes = [];
  13525. this.localClippingEnabled = false;
  13526. // physically based shading
  13527. this.gammaFactor = 2.0; // for backwards compatibility
  13528. this.gammaInput = false;
  13529. this.gammaOutput = false;
  13530. // physical lights
  13531. this.physicallyCorrectLights = false;
  13532. // tone mapping
  13533. this.toneMapping = LinearToneMapping;
  13534. this.toneMappingExposure = 1.0;
  13535. this.toneMappingWhitePoint = 1.0;
  13536. // morphs
  13537. this.maxMorphTargets = 8;
  13538. this.maxMorphNormals = 4;
  13539. // internal properties
  13540. var _this = this,
  13541. _isContextLost = false,
  13542. // internal state cache
  13543. _framebuffer = null,
  13544. _currentRenderTarget = null,
  13545. _currentFramebuffer = null,
  13546. _currentMaterialId = - 1,
  13547. // geometry and program caching
  13548. _currentGeometryProgram = {
  13549. geometry: null,
  13550. program: null,
  13551. wireframe: false
  13552. },
  13553. _currentCamera = null,
  13554. _currentArrayCamera = null,
  13555. _currentViewport = new Vector4(),
  13556. _currentScissor = new Vector4(),
  13557. _currentScissorTest = null,
  13558. //
  13559. _width = _canvas.width,
  13560. _height = _canvas.height,
  13561. _pixelRatio = 1,
  13562. _viewport = new Vector4( 0, 0, _width, _height ),
  13563. _scissor = new Vector4( 0, 0, _width, _height ),
  13564. _scissorTest = false,
  13565. // frustum
  13566. _frustum = new Frustum(),
  13567. // clipping
  13568. _clipping = new WebGLClipping(),
  13569. _clippingEnabled = false,
  13570. _localClippingEnabled = false,
  13571. // camera matrices cache
  13572. _projScreenMatrix = new Matrix4(),
  13573. _vector3 = new Vector3();
  13574. function getTargetPixelRatio() {
  13575. return _currentRenderTarget === null ? _pixelRatio : 1;
  13576. }
  13577. // initialize
  13578. var _gl;
  13579. try {
  13580. var contextAttributes = {
  13581. alpha: _alpha,
  13582. depth: _depth,
  13583. stencil: _stencil,
  13584. antialias: _antialias,
  13585. premultipliedAlpha: _premultipliedAlpha,
  13586. preserveDrawingBuffer: _preserveDrawingBuffer,
  13587. powerPreference: _powerPreference
  13588. };
  13589. // event listeners must be registered before WebGL context is created, see #12753
  13590. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13591. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13592. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13593. if ( _gl === null ) {
  13594. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13595. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13596. } else {
  13597. throw new Error( 'Error creating WebGL context.' );
  13598. }
  13599. }
  13600. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13601. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13602. _gl.getShaderPrecisionFormat = function () {
  13603. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13604. };
  13605. }
  13606. } catch ( error ) {
  13607. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13608. throw error;
  13609. }
  13610. var extensions, capabilities, state, info;
  13611. var properties, textures, attributes, geometries, objects;
  13612. var programCache, renderLists, renderStates;
  13613. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13614. var utils;
  13615. function initGLContext() {
  13616. extensions = new WebGLExtensions( _gl );
  13617. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13618. if ( ! capabilities.isWebGL2 ) {
  13619. extensions.get( 'WEBGL_depth_texture' );
  13620. extensions.get( 'OES_texture_float' );
  13621. extensions.get( 'OES_texture_half_float' );
  13622. extensions.get( 'OES_texture_half_float_linear' );
  13623. extensions.get( 'OES_standard_derivatives' );
  13624. extensions.get( 'OES_element_index_uint' );
  13625. extensions.get( 'ANGLE_instanced_arrays' );
  13626. }
  13627. extensions.get( 'OES_texture_float_linear' );
  13628. utils = new WebGLUtils( _gl, extensions, capabilities );
  13629. state = new WebGLState( _gl, extensions, utils, capabilities );
  13630. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13631. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13632. info = new WebGLInfo( _gl );
  13633. properties = new WebGLProperties();
  13634. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13635. attributes = new WebGLAttributes( _gl );
  13636. geometries = new WebGLGeometries( _gl, attributes, info );
  13637. objects = new WebGLObjects( geometries, info );
  13638. morphtargets = new WebGLMorphtargets( _gl );
  13639. programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
  13640. renderLists = new WebGLRenderLists();
  13641. renderStates = new WebGLRenderStates();
  13642. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13643. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13644. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13645. info.programs = programCache.programs;
  13646. _this.context = _gl;
  13647. _this.capabilities = capabilities;
  13648. _this.extensions = extensions;
  13649. _this.properties = properties;
  13650. _this.renderLists = renderLists;
  13651. _this.state = state;
  13652. _this.info = info;
  13653. }
  13654. initGLContext();
  13655. // vr
  13656. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13657. this.vr = vr;
  13658. // shadow map
  13659. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13660. this.shadowMap = shadowMap;
  13661. // API
  13662. this.getContext = function () {
  13663. return _gl;
  13664. };
  13665. this.getContextAttributes = function () {
  13666. return _gl.getContextAttributes();
  13667. };
  13668. this.forceContextLoss = function () {
  13669. var extension = extensions.get( 'WEBGL_lose_context' );
  13670. if ( extension ) extension.loseContext();
  13671. };
  13672. this.forceContextRestore = function () {
  13673. var extension = extensions.get( 'WEBGL_lose_context' );
  13674. if ( extension ) extension.restoreContext();
  13675. };
  13676. this.getPixelRatio = function () {
  13677. return _pixelRatio;
  13678. };
  13679. this.setPixelRatio = function ( value ) {
  13680. if ( value === undefined ) return;
  13681. _pixelRatio = value;
  13682. this.setSize( _width, _height, false );
  13683. };
  13684. this.getSize = function ( target ) {
  13685. if ( target === undefined ) {
  13686. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13687. target = new Vector2();
  13688. }
  13689. return target.set( _width, _height );
  13690. };
  13691. this.setSize = function ( width, height, updateStyle ) {
  13692. if ( vr.isPresenting() ) {
  13693. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13694. return;
  13695. }
  13696. _width = width;
  13697. _height = height;
  13698. _canvas.width = width * _pixelRatio;
  13699. _canvas.height = height * _pixelRatio;
  13700. if ( updateStyle !== false ) {
  13701. _canvas.style.width = width + 'px';
  13702. _canvas.style.height = height + 'px';
  13703. }
  13704. this.setViewport( 0, 0, width, height );
  13705. };
  13706. this.getDrawingBufferSize = function ( target ) {
  13707. if ( target === undefined ) {
  13708. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13709. target = new Vector2();
  13710. }
  13711. return target.set( _width * _pixelRatio, _height * _pixelRatio );
  13712. };
  13713. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13714. _width = width;
  13715. _height = height;
  13716. _pixelRatio = pixelRatio;
  13717. _canvas.width = width * pixelRatio;
  13718. _canvas.height = height * pixelRatio;
  13719. this.setViewport( 0, 0, width, height );
  13720. };
  13721. this.getCurrentViewport = function ( target ) {
  13722. if ( target === undefined ) {
  13723. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13724. target = new Vector4();
  13725. }
  13726. return target.copy( _currentViewport );
  13727. };
  13728. this.getViewport = function ( target ) {
  13729. return target.copy( _viewport );
  13730. };
  13731. this.setViewport = function ( x, y, width, height ) {
  13732. if ( x.isVector4 ) {
  13733. _viewport.set( x.x, x.y, x.z, x.w );
  13734. } else {
  13735. _viewport.set( x, y, width, height );
  13736. }
  13737. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13738. };
  13739. this.getScissor = function ( target ) {
  13740. return target.copy( _scissor );
  13741. };
  13742. this.setScissor = function ( x, y, width, height ) {
  13743. if ( x.isVector4 ) {
  13744. _scissor.set( x.x, x.y, x.z, x.w );
  13745. } else {
  13746. _scissor.set( x, y, width, height );
  13747. }
  13748. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13749. };
  13750. this.getScissorTest = function () {
  13751. return _scissorTest;
  13752. };
  13753. this.setScissorTest = function ( boolean ) {
  13754. state.setScissorTest( _scissorTest = boolean );
  13755. };
  13756. // Clearing
  13757. this.getClearColor = function () {
  13758. return background.getClearColor();
  13759. };
  13760. this.setClearColor = function () {
  13761. background.setClearColor.apply( background, arguments );
  13762. };
  13763. this.getClearAlpha = function () {
  13764. return background.getClearAlpha();
  13765. };
  13766. this.setClearAlpha = function () {
  13767. background.setClearAlpha.apply( background, arguments );
  13768. };
  13769. this.clear = function ( color, depth, stencil ) {
  13770. var bits = 0;
  13771. if ( color === undefined || color ) bits |= 16384;
  13772. if ( depth === undefined || depth ) bits |= 256;
  13773. if ( stencil === undefined || stencil ) bits |= 1024;
  13774. _gl.clear( bits );
  13775. };
  13776. this.clearColor = function () {
  13777. this.clear( true, false, false );
  13778. };
  13779. this.clearDepth = function () {
  13780. this.clear( false, true, false );
  13781. };
  13782. this.clearStencil = function () {
  13783. this.clear( false, false, true );
  13784. };
  13785. //
  13786. this.dispose = function () {
  13787. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13788. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13789. renderLists.dispose();
  13790. renderStates.dispose();
  13791. properties.dispose();
  13792. objects.dispose();
  13793. vr.dispose();
  13794. animation.stop();
  13795. };
  13796. // Events
  13797. function onContextLost( event ) {
  13798. event.preventDefault();
  13799. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13800. _isContextLost = true;
  13801. }
  13802. function onContextRestore( /* event */ ) {
  13803. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13804. _isContextLost = false;
  13805. initGLContext();
  13806. }
  13807. function onMaterialDispose( event ) {
  13808. var material = event.target;
  13809. material.removeEventListener( 'dispose', onMaterialDispose );
  13810. deallocateMaterial( material );
  13811. }
  13812. // Buffer deallocation
  13813. function deallocateMaterial( material ) {
  13814. releaseMaterialProgramReference( material );
  13815. properties.remove( material );
  13816. }
  13817. function releaseMaterialProgramReference( material ) {
  13818. var programInfo = properties.get( material ).program;
  13819. material.program = undefined;
  13820. if ( programInfo !== undefined ) {
  13821. programCache.releaseProgram( programInfo );
  13822. }
  13823. }
  13824. // Buffer rendering
  13825. function renderObjectImmediate( object, program ) {
  13826. object.render( function ( object ) {
  13827. _this.renderBufferImmediate( object, program );
  13828. } );
  13829. }
  13830. this.renderBufferImmediate = function ( object, program ) {
  13831. state.initAttributes();
  13832. var buffers = properties.get( object );
  13833. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13834. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13835. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13836. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13837. var programAttributes = program.getAttributes();
  13838. if ( object.hasPositions ) {
  13839. _gl.bindBuffer( 34962, buffers.position );
  13840. _gl.bufferData( 34962, object.positionArray, 35048 );
  13841. state.enableAttribute( programAttributes.position );
  13842. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13843. }
  13844. if ( object.hasNormals ) {
  13845. _gl.bindBuffer( 34962, buffers.normal );
  13846. _gl.bufferData( 34962, object.normalArray, 35048 );
  13847. state.enableAttribute( programAttributes.normal );
  13848. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13849. }
  13850. if ( object.hasUvs ) {
  13851. _gl.bindBuffer( 34962, buffers.uv );
  13852. _gl.bufferData( 34962, object.uvArray, 35048 );
  13853. state.enableAttribute( programAttributes.uv );
  13854. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13855. }
  13856. if ( object.hasColors ) {
  13857. _gl.bindBuffer( 34962, buffers.color );
  13858. _gl.bufferData( 34962, object.colorArray, 35048 );
  13859. state.enableAttribute( programAttributes.color );
  13860. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13861. }
  13862. state.disableUnusedAttributes();
  13863. _gl.drawArrays( 4, 0, object.count );
  13864. object.count = 0;
  13865. };
  13866. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13867. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13868. state.setMaterial( material, frontFaceCW );
  13869. var program = setProgram( camera, fog, material, object );
  13870. var updateBuffers = false;
  13871. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13872. _currentGeometryProgram.program !== program.id ||
  13873. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13874. _currentGeometryProgram.geometry = geometry.id;
  13875. _currentGeometryProgram.program = program.id;
  13876. _currentGeometryProgram.wireframe = material.wireframe === true;
  13877. updateBuffers = true;
  13878. }
  13879. if ( object.morphTargetInfluences ) {
  13880. morphtargets.update( object, geometry, material, program );
  13881. updateBuffers = true;
  13882. }
  13883. //
  13884. var index = geometry.index;
  13885. var position = geometry.attributes.position;
  13886. var rangeFactor = 1;
  13887. if ( material.wireframe === true ) {
  13888. index = geometries.getWireframeAttribute( geometry );
  13889. rangeFactor = 2;
  13890. }
  13891. var attribute;
  13892. var renderer = bufferRenderer;
  13893. if ( index !== null ) {
  13894. attribute = attributes.get( index );
  13895. renderer = indexedBufferRenderer;
  13896. renderer.setIndex( attribute );
  13897. }
  13898. if ( updateBuffers ) {
  13899. setupVertexAttributes( material, program, geometry );
  13900. if ( index !== null ) {
  13901. _gl.bindBuffer( 34963, attribute.buffer );
  13902. }
  13903. }
  13904. //
  13905. var dataCount = Infinity;
  13906. if ( index !== null ) {
  13907. dataCount = index.count;
  13908. } else if ( position !== undefined ) {
  13909. dataCount = position.count;
  13910. }
  13911. var rangeStart = geometry.drawRange.start * rangeFactor;
  13912. var rangeCount = geometry.drawRange.count * rangeFactor;
  13913. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13914. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13915. var drawStart = Math.max( rangeStart, groupStart );
  13916. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13917. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13918. if ( drawCount === 0 ) return;
  13919. //
  13920. if ( object.isMesh ) {
  13921. if ( material.wireframe === true ) {
  13922. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13923. renderer.setMode( 1 );
  13924. } else {
  13925. switch ( object.drawMode ) {
  13926. case TrianglesDrawMode:
  13927. renderer.setMode( 4 );
  13928. break;
  13929. case TriangleStripDrawMode:
  13930. renderer.setMode( 5 );
  13931. break;
  13932. case TriangleFanDrawMode:
  13933. renderer.setMode( 6 );
  13934. break;
  13935. }
  13936. }
  13937. } else if ( object.isLine ) {
  13938. var lineWidth = material.linewidth;
  13939. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13940. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13941. if ( object.isLineSegments ) {
  13942. renderer.setMode( 1 );
  13943. } else if ( object.isLineLoop ) {
  13944. renderer.setMode( 2 );
  13945. } else {
  13946. renderer.setMode( 3 );
  13947. }
  13948. } else if ( object.isPoints ) {
  13949. renderer.setMode( 0 );
  13950. } else if ( object.isSprite ) {
  13951. renderer.setMode( 4 );
  13952. }
  13953. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13954. if ( geometry.maxInstancedCount > 0 ) {
  13955. renderer.renderInstances( geometry, drawStart, drawCount );
  13956. }
  13957. } else {
  13958. renderer.render( drawStart, drawCount );
  13959. }
  13960. };
  13961. function setupVertexAttributes( material, program, geometry ) {
  13962. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  13963. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13964. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13965. return;
  13966. }
  13967. }
  13968. state.initAttributes();
  13969. var geometryAttributes = geometry.attributes;
  13970. var programAttributes = program.getAttributes();
  13971. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13972. for ( var name in programAttributes ) {
  13973. var programAttribute = programAttributes[ name ];
  13974. if ( programAttribute >= 0 ) {
  13975. var geometryAttribute = geometryAttributes[ name ];
  13976. if ( geometryAttribute !== undefined ) {
  13977. var normalized = geometryAttribute.normalized;
  13978. var size = geometryAttribute.itemSize;
  13979. var attribute = attributes.get( geometryAttribute );
  13980. // TODO Attribute may not be available on context restore
  13981. if ( attribute === undefined ) continue;
  13982. var buffer = attribute.buffer;
  13983. var type = attribute.type;
  13984. var bytesPerElement = attribute.bytesPerElement;
  13985. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13986. var data = geometryAttribute.data;
  13987. var stride = data.stride;
  13988. var offset = geometryAttribute.offset;
  13989. if ( data && data.isInstancedInterleavedBuffer ) {
  13990. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13991. if ( geometry.maxInstancedCount === undefined ) {
  13992. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13993. }
  13994. } else {
  13995. state.enableAttribute( programAttribute );
  13996. }
  13997. _gl.bindBuffer( 34962, buffer );
  13998. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13999. } else {
  14000. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14001. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14002. if ( geometry.maxInstancedCount === undefined ) {
  14003. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14004. }
  14005. } else {
  14006. state.enableAttribute( programAttribute );
  14007. }
  14008. _gl.bindBuffer( 34962, buffer );
  14009. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14010. }
  14011. } else if ( materialDefaultAttributeValues !== undefined ) {
  14012. var value = materialDefaultAttributeValues[ name ];
  14013. if ( value !== undefined ) {
  14014. switch ( value.length ) {
  14015. case 2:
  14016. _gl.vertexAttrib2fv( programAttribute, value );
  14017. break;
  14018. case 3:
  14019. _gl.vertexAttrib3fv( programAttribute, value );
  14020. break;
  14021. case 4:
  14022. _gl.vertexAttrib4fv( programAttribute, value );
  14023. break;
  14024. default:
  14025. _gl.vertexAttrib1fv( programAttribute, value );
  14026. }
  14027. }
  14028. }
  14029. }
  14030. }
  14031. state.disableUnusedAttributes();
  14032. }
  14033. // Compile
  14034. this.compile = function ( scene, camera ) {
  14035. currentRenderState = renderStates.get( scene, camera );
  14036. currentRenderState.init();
  14037. scene.traverse( function ( object ) {
  14038. if ( object.isLight ) {
  14039. currentRenderState.pushLight( object );
  14040. if ( object.castShadow ) {
  14041. currentRenderState.pushShadow( object );
  14042. }
  14043. }
  14044. } );
  14045. currentRenderState.setupLights( camera );
  14046. scene.traverse( function ( object ) {
  14047. if ( object.material ) {
  14048. if ( Array.isArray( object.material ) ) {
  14049. for ( var i = 0; i < object.material.length; i ++ ) {
  14050. initMaterial( object.material[ i ], scene.fog, object );
  14051. }
  14052. } else {
  14053. initMaterial( object.material, scene.fog, object );
  14054. }
  14055. }
  14056. } );
  14057. };
  14058. // Animation Loop
  14059. var onAnimationFrameCallback = null;
  14060. function onAnimationFrame( time ) {
  14061. if ( vr.isPresenting() ) return;
  14062. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14063. }
  14064. var animation = new WebGLAnimation();
  14065. animation.setAnimationLoop( onAnimationFrame );
  14066. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14067. this.setAnimationLoop = function ( callback ) {
  14068. onAnimationFrameCallback = callback;
  14069. vr.setAnimationLoop( callback );
  14070. animation.start();
  14071. };
  14072. // Rendering
  14073. this.render = function ( scene, camera ) {
  14074. var renderTarget, forceClear;
  14075. if ( arguments[ 2 ] !== undefined ) {
  14076. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14077. renderTarget = arguments[ 2 ];
  14078. }
  14079. if ( arguments[ 3 ] !== undefined ) {
  14080. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14081. forceClear = arguments[ 3 ];
  14082. }
  14083. if ( ! ( camera && camera.isCamera ) ) {
  14084. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14085. return;
  14086. }
  14087. if ( _isContextLost ) return;
  14088. // reset caching for this frame
  14089. _currentGeometryProgram.geometry = null;
  14090. _currentGeometryProgram.program = null;
  14091. _currentGeometryProgram.wireframe = false;
  14092. _currentMaterialId = - 1;
  14093. _currentCamera = null;
  14094. // update scene graph
  14095. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14096. // update camera matrices and frustum
  14097. if ( camera.parent === null ) camera.updateMatrixWorld();
  14098. if ( vr.enabled ) {
  14099. camera = vr.getCamera( camera );
  14100. }
  14101. //
  14102. currentRenderState = renderStates.get( scene, camera );
  14103. currentRenderState.init();
  14104. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14105. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14106. _frustum.setFromMatrix( _projScreenMatrix );
  14107. _localClippingEnabled = this.localClippingEnabled;
  14108. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14109. currentRenderList = renderLists.get( scene, camera );
  14110. currentRenderList.init();
  14111. projectObject( scene, camera, 0, _this.sortObjects );
  14112. if ( _this.sortObjects === true ) {
  14113. currentRenderList.sort();
  14114. }
  14115. //
  14116. if ( _clippingEnabled ) _clipping.beginShadows();
  14117. var shadowsArray = currentRenderState.state.shadowsArray;
  14118. shadowMap.render( shadowsArray, scene, camera );
  14119. currentRenderState.setupLights( camera );
  14120. if ( _clippingEnabled ) _clipping.endShadows();
  14121. //
  14122. if ( this.info.autoReset ) this.info.reset();
  14123. if ( renderTarget !== undefined ) {
  14124. this.setRenderTarget( renderTarget );
  14125. }
  14126. //
  14127. background.render( currentRenderList, scene, camera, forceClear );
  14128. // render scene
  14129. var opaqueObjects = currentRenderList.opaque;
  14130. var transparentObjects = currentRenderList.transparent;
  14131. if ( scene.overrideMaterial ) {
  14132. var overrideMaterial = scene.overrideMaterial;
  14133. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14134. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14135. } else {
  14136. // opaque pass (front-to-back order)
  14137. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14138. // transparent pass (back-to-front order)
  14139. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14140. }
  14141. //
  14142. scene.onAfterRender( _this, scene, camera );
  14143. //
  14144. if ( _currentRenderTarget !== null ) {
  14145. // Generate mipmap if we're using any kind of mipmap filtering
  14146. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14147. // resolve multisample renderbuffers to a single-sample texture if necessary
  14148. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14149. }
  14150. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14151. state.buffers.depth.setTest( true );
  14152. state.buffers.depth.setMask( true );
  14153. state.buffers.color.setMask( true );
  14154. state.setPolygonOffset( false );
  14155. if ( vr.enabled ) {
  14156. vr.submitFrame();
  14157. }
  14158. // _gl.finish();
  14159. currentRenderList = null;
  14160. currentRenderState = null;
  14161. };
  14162. function projectObject( object, camera, groupOrder, sortObjects ) {
  14163. if ( object.visible === false ) return;
  14164. var visible = object.layers.test( camera.layers );
  14165. if ( visible ) {
  14166. if ( object.isGroup ) {
  14167. groupOrder = object.renderOrder;
  14168. } else if ( object.isLight ) {
  14169. currentRenderState.pushLight( object );
  14170. if ( object.castShadow ) {
  14171. currentRenderState.pushShadow( object );
  14172. }
  14173. } else if ( object.isSprite ) {
  14174. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14175. if ( sortObjects ) {
  14176. _vector3.setFromMatrixPosition( object.matrixWorld )
  14177. .applyMatrix4( _projScreenMatrix );
  14178. }
  14179. var geometry = objects.update( object );
  14180. var material = object.material;
  14181. if ( material.visible ) {
  14182. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14183. }
  14184. }
  14185. } else if ( object.isImmediateRenderObject ) {
  14186. if ( sortObjects ) {
  14187. _vector3.setFromMatrixPosition( object.matrixWorld )
  14188. .applyMatrix4( _projScreenMatrix );
  14189. }
  14190. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14191. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14192. if ( object.isSkinnedMesh ) {
  14193. object.skeleton.update();
  14194. }
  14195. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14196. if ( sortObjects ) {
  14197. _vector3.setFromMatrixPosition( object.matrixWorld )
  14198. .applyMatrix4( _projScreenMatrix );
  14199. }
  14200. var geometry = objects.update( object );
  14201. var material = object.material;
  14202. if ( Array.isArray( material ) ) {
  14203. var groups = geometry.groups;
  14204. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14205. var group = groups[ i ];
  14206. var groupMaterial = material[ group.materialIndex ];
  14207. if ( groupMaterial && groupMaterial.visible ) {
  14208. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14209. }
  14210. }
  14211. } else if ( material.visible ) {
  14212. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14213. }
  14214. }
  14215. }
  14216. }
  14217. var children = object.children;
  14218. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14219. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14220. }
  14221. }
  14222. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14223. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14224. var renderItem = renderList[ i ];
  14225. var object = renderItem.object;
  14226. var geometry = renderItem.geometry;
  14227. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14228. var group = renderItem.group;
  14229. if ( camera.isArrayCamera ) {
  14230. _currentArrayCamera = camera;
  14231. var cameras = camera.cameras;
  14232. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14233. var camera2 = cameras[ j ];
  14234. if ( object.layers.test( camera2.layers ) ) {
  14235. if ( 'viewport' in camera2 ) { // XR
  14236. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14237. } else {
  14238. var bounds = camera2.bounds;
  14239. var x = bounds.x * _width;
  14240. var y = bounds.y * _height;
  14241. var width = bounds.z * _width;
  14242. var height = bounds.w * _height;
  14243. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  14244. }
  14245. currentRenderState.setupLights( camera2 );
  14246. renderObject( object, scene, camera2, geometry, material, group );
  14247. }
  14248. }
  14249. } else {
  14250. _currentArrayCamera = null;
  14251. renderObject( object, scene, camera, geometry, material, group );
  14252. }
  14253. }
  14254. }
  14255. function renderObject( object, scene, camera, geometry, material, group ) {
  14256. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14257. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14258. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14259. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14260. if ( object.isImmediateRenderObject ) {
  14261. state.setMaterial( material );
  14262. var program = setProgram( camera, scene.fog, material, object );
  14263. _currentGeometryProgram.geometry = null;
  14264. _currentGeometryProgram.program = null;
  14265. _currentGeometryProgram.wireframe = false;
  14266. renderObjectImmediate( object, program );
  14267. } else {
  14268. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14269. }
  14270. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14271. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14272. }
  14273. function initMaterial( material, fog, object ) {
  14274. var materialProperties = properties.get( material );
  14275. var lights = currentRenderState.state.lights;
  14276. var shadowsArray = currentRenderState.state.shadowsArray;
  14277. var lightsHash = materialProperties.lightsHash;
  14278. var lightsStateHash = lights.state.hash;
  14279. var parameters = programCache.getParameters(
  14280. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14281. var code = programCache.getProgramCode( material, parameters );
  14282. var program = materialProperties.program;
  14283. var programChange = true;
  14284. if ( program === undefined ) {
  14285. // new material
  14286. material.addEventListener( 'dispose', onMaterialDispose );
  14287. } else if ( program.code !== code ) {
  14288. // changed glsl or parameters
  14289. releaseMaterialProgramReference( material );
  14290. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14291. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14292. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14293. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14294. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14295. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14296. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14297. lightsHash.stateID = lightsStateHash.stateID;
  14298. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14299. lightsHash.pointLength = lightsStateHash.pointLength;
  14300. lightsHash.spotLength = lightsStateHash.spotLength;
  14301. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14302. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14303. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14304. programChange = false;
  14305. } else if ( parameters.shaderID !== undefined ) {
  14306. // same glsl and uniform list
  14307. return;
  14308. } else {
  14309. // only rebuild uniform list
  14310. programChange = false;
  14311. }
  14312. if ( programChange ) {
  14313. if ( parameters.shaderID ) {
  14314. var shader = ShaderLib[ parameters.shaderID ];
  14315. materialProperties.shader = {
  14316. name: material.type,
  14317. uniforms: cloneUniforms( shader.uniforms ),
  14318. vertexShader: shader.vertexShader,
  14319. fragmentShader: shader.fragmentShader
  14320. };
  14321. } else {
  14322. materialProperties.shader = {
  14323. name: material.type,
  14324. uniforms: material.uniforms,
  14325. vertexShader: material.vertexShader,
  14326. fragmentShader: material.fragmentShader
  14327. };
  14328. }
  14329. material.onBeforeCompile( materialProperties.shader, _this );
  14330. // Computing code again as onBeforeCompile may have changed the shaders
  14331. code = programCache.getProgramCode( material, parameters );
  14332. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14333. materialProperties.program = program;
  14334. material.program = program;
  14335. }
  14336. var programAttributes = program.getAttributes();
  14337. if ( material.morphTargets ) {
  14338. material.numSupportedMorphTargets = 0;
  14339. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14340. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14341. material.numSupportedMorphTargets ++;
  14342. }
  14343. }
  14344. }
  14345. if ( material.morphNormals ) {
  14346. material.numSupportedMorphNormals = 0;
  14347. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14348. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14349. material.numSupportedMorphNormals ++;
  14350. }
  14351. }
  14352. }
  14353. var uniforms = materialProperties.shader.uniforms;
  14354. if ( ! material.isShaderMaterial &&
  14355. ! material.isRawShaderMaterial ||
  14356. material.clipping === true ) {
  14357. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14358. materialProperties.numIntersection = _clipping.numIntersection;
  14359. uniforms.clippingPlanes = _clipping.uniform;
  14360. }
  14361. materialProperties.fog = fog;
  14362. // store the light setup it was created for
  14363. if ( lightsHash === undefined ) {
  14364. materialProperties.lightsHash = lightsHash = {};
  14365. }
  14366. lightsHash.stateID = lightsStateHash.stateID;
  14367. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14368. lightsHash.pointLength = lightsStateHash.pointLength;
  14369. lightsHash.spotLength = lightsStateHash.spotLength;
  14370. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14371. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14372. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14373. if ( material.lights ) {
  14374. // wire up the material to this renderer's lighting state
  14375. uniforms.ambientLightColor.value = lights.state.ambient;
  14376. uniforms.directionalLights.value = lights.state.directional;
  14377. uniforms.spotLights.value = lights.state.spot;
  14378. uniforms.rectAreaLights.value = lights.state.rectArea;
  14379. uniforms.pointLights.value = lights.state.point;
  14380. uniforms.hemisphereLights.value = lights.state.hemi;
  14381. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14382. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14383. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14384. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14385. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14386. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14387. // TODO (abelnation): add area lights shadow info to uniforms
  14388. }
  14389. var progUniforms = materialProperties.program.getUniforms(),
  14390. uniformsList =
  14391. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14392. materialProperties.uniformsList = uniformsList;
  14393. }
  14394. function setProgram( camera, fog, material, object ) {
  14395. textures.resetTextureUnits();
  14396. var materialProperties = properties.get( material );
  14397. var lights = currentRenderState.state.lights;
  14398. var lightsHash = materialProperties.lightsHash;
  14399. var lightsStateHash = lights.state.hash;
  14400. if ( _clippingEnabled ) {
  14401. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14402. var useCache =
  14403. camera === _currentCamera &&
  14404. material.id === _currentMaterialId;
  14405. // we might want to call this function with some ClippingGroup
  14406. // object instead of the material, once it becomes feasible
  14407. // (#8465, #8379)
  14408. _clipping.setState(
  14409. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14410. camera, materialProperties, useCache );
  14411. }
  14412. }
  14413. if ( material.needsUpdate === false ) {
  14414. if ( materialProperties.program === undefined ) {
  14415. material.needsUpdate = true;
  14416. } else if ( material.fog && materialProperties.fog !== fog ) {
  14417. material.needsUpdate = true;
  14418. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14419. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14420. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14421. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14422. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14423. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14424. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14425. material.needsUpdate = true;
  14426. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14427. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14428. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14429. material.needsUpdate = true;
  14430. }
  14431. }
  14432. if ( material.needsUpdate ) {
  14433. initMaterial( material, fog, object );
  14434. material.needsUpdate = false;
  14435. }
  14436. var refreshProgram = false;
  14437. var refreshMaterial = false;
  14438. var refreshLights = false;
  14439. var program = materialProperties.program,
  14440. p_uniforms = program.getUniforms(),
  14441. m_uniforms = materialProperties.shader.uniforms;
  14442. if ( state.useProgram( program.program ) ) {
  14443. refreshProgram = true;
  14444. refreshMaterial = true;
  14445. refreshLights = true;
  14446. }
  14447. if ( material.id !== _currentMaterialId ) {
  14448. _currentMaterialId = material.id;
  14449. refreshMaterial = true;
  14450. }
  14451. if ( refreshProgram || _currentCamera !== camera ) {
  14452. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14453. if ( capabilities.logarithmicDepthBuffer ) {
  14454. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14455. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14456. }
  14457. if ( _currentCamera !== camera ) {
  14458. _currentCamera = camera;
  14459. // lighting uniforms depend on the camera so enforce an update
  14460. // now, in case this material supports lights - or later, when
  14461. // the next material that does gets activated:
  14462. refreshMaterial = true; // set to true on material change
  14463. refreshLights = true; // remains set until update done
  14464. }
  14465. // load material specific uniforms
  14466. // (shader material also gets them for the sake of genericity)
  14467. if ( material.isShaderMaterial ||
  14468. material.isMeshPhongMaterial ||
  14469. material.isMeshStandardMaterial ||
  14470. material.envMap ) {
  14471. var uCamPos = p_uniforms.map.cameraPosition;
  14472. if ( uCamPos !== undefined ) {
  14473. uCamPos.setValue( _gl,
  14474. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14475. }
  14476. }
  14477. if ( material.isMeshPhongMaterial ||
  14478. material.isMeshLambertMaterial ||
  14479. material.isMeshBasicMaterial ||
  14480. material.isMeshStandardMaterial ||
  14481. material.isShaderMaterial ||
  14482. material.skinning ) {
  14483. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14484. }
  14485. }
  14486. // skinning uniforms must be set even if material didn't change
  14487. // auto-setting of texture unit for bone texture must go before other textures
  14488. // not sure why, but otherwise weird things happen
  14489. if ( material.skinning ) {
  14490. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14491. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14492. var skeleton = object.skeleton;
  14493. if ( skeleton ) {
  14494. var bones = skeleton.bones;
  14495. if ( capabilities.floatVertexTextures ) {
  14496. if ( skeleton.boneTexture === undefined ) {
  14497. // layout (1 matrix = 4 pixels)
  14498. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14499. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14500. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14501. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14502. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14503. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14504. size = _Math.ceilPowerOfTwo( size );
  14505. size = Math.max( size, 4 );
  14506. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14507. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14508. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14509. boneTexture.needsUpdate = true;
  14510. skeleton.boneMatrices = boneMatrices;
  14511. skeleton.boneTexture = boneTexture;
  14512. skeleton.boneTextureSize = size;
  14513. }
  14514. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14515. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14516. } else {
  14517. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14518. }
  14519. }
  14520. }
  14521. if ( refreshMaterial ) {
  14522. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14523. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14524. if ( material.lights ) {
  14525. // the current material requires lighting info
  14526. // note: all lighting uniforms are always set correctly
  14527. // they simply reference the renderer's state for their
  14528. // values
  14529. //
  14530. // use the current material's .needsUpdate flags to set
  14531. // the GL state when required
  14532. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14533. }
  14534. // refresh uniforms common to several materials
  14535. if ( fog && material.fog ) {
  14536. refreshUniformsFog( m_uniforms, fog );
  14537. }
  14538. if ( material.isMeshBasicMaterial ) {
  14539. refreshUniformsCommon( m_uniforms, material );
  14540. } else if ( material.isMeshLambertMaterial ) {
  14541. refreshUniformsCommon( m_uniforms, material );
  14542. refreshUniformsLambert( m_uniforms, material );
  14543. } else if ( material.isMeshPhongMaterial ) {
  14544. refreshUniformsCommon( m_uniforms, material );
  14545. if ( material.isMeshToonMaterial ) {
  14546. refreshUniformsToon( m_uniforms, material );
  14547. } else {
  14548. refreshUniformsPhong( m_uniforms, material );
  14549. }
  14550. } else if ( material.isMeshStandardMaterial ) {
  14551. refreshUniformsCommon( m_uniforms, material );
  14552. if ( material.isMeshPhysicalMaterial ) {
  14553. refreshUniformsPhysical( m_uniforms, material );
  14554. } else {
  14555. refreshUniformsStandard( m_uniforms, material );
  14556. }
  14557. } else if ( material.isMeshMatcapMaterial ) {
  14558. refreshUniformsCommon( m_uniforms, material );
  14559. refreshUniformsMatcap( m_uniforms, material );
  14560. } else if ( material.isMeshDepthMaterial ) {
  14561. refreshUniformsCommon( m_uniforms, material );
  14562. refreshUniformsDepth( m_uniforms, material );
  14563. } else if ( material.isMeshDistanceMaterial ) {
  14564. refreshUniformsCommon( m_uniforms, material );
  14565. refreshUniformsDistance( m_uniforms, material );
  14566. } else if ( material.isMeshNormalMaterial ) {
  14567. refreshUniformsCommon( m_uniforms, material );
  14568. refreshUniformsNormal( m_uniforms, material );
  14569. } else if ( material.isLineBasicMaterial ) {
  14570. refreshUniformsLine( m_uniforms, material );
  14571. if ( material.isLineDashedMaterial ) {
  14572. refreshUniformsDash( m_uniforms, material );
  14573. }
  14574. } else if ( material.isPointsMaterial ) {
  14575. refreshUniformsPoints( m_uniforms, material );
  14576. } else if ( material.isSpriteMaterial ) {
  14577. refreshUniformsSprites( m_uniforms, material );
  14578. } else if ( material.isShadowMaterial ) {
  14579. m_uniforms.color.value = material.color;
  14580. m_uniforms.opacity.value = material.opacity;
  14581. }
  14582. // RectAreaLight Texture
  14583. // TODO (mrdoob): Find a nicer implementation
  14584. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14585. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14586. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14587. }
  14588. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14589. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14590. material.uniformsNeedUpdate = false;
  14591. }
  14592. if ( material.isSpriteMaterial ) {
  14593. p_uniforms.setValue( _gl, 'center', object.center );
  14594. }
  14595. // common matrices
  14596. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14597. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14598. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14599. return program;
  14600. }
  14601. // Uniforms (refresh uniforms objects)
  14602. function refreshUniformsCommon( uniforms, material ) {
  14603. uniforms.opacity.value = material.opacity;
  14604. if ( material.color ) {
  14605. uniforms.diffuse.value = material.color;
  14606. }
  14607. if ( material.emissive ) {
  14608. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14609. }
  14610. if ( material.map ) {
  14611. uniforms.map.value = material.map;
  14612. }
  14613. if ( material.alphaMap ) {
  14614. uniforms.alphaMap.value = material.alphaMap;
  14615. }
  14616. if ( material.specularMap ) {
  14617. uniforms.specularMap.value = material.specularMap;
  14618. }
  14619. if ( material.envMap ) {
  14620. uniforms.envMap.value = material.envMap;
  14621. // don't flip CubeTexture envMaps, flip everything else:
  14622. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14623. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14624. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14625. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14626. uniforms.reflectivity.value = material.reflectivity;
  14627. uniforms.refractionRatio.value = material.refractionRatio;
  14628. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14629. }
  14630. if ( material.lightMap ) {
  14631. uniforms.lightMap.value = material.lightMap;
  14632. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14633. }
  14634. if ( material.aoMap ) {
  14635. uniforms.aoMap.value = material.aoMap;
  14636. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14637. }
  14638. // uv repeat and offset setting priorities
  14639. // 1. color map
  14640. // 2. specular map
  14641. // 3. normal map
  14642. // 4. bump map
  14643. // 5. alpha map
  14644. // 6. emissive map
  14645. var uvScaleMap;
  14646. if ( material.map ) {
  14647. uvScaleMap = material.map;
  14648. } else if ( material.specularMap ) {
  14649. uvScaleMap = material.specularMap;
  14650. } else if ( material.displacementMap ) {
  14651. uvScaleMap = material.displacementMap;
  14652. } else if ( material.normalMap ) {
  14653. uvScaleMap = material.normalMap;
  14654. } else if ( material.bumpMap ) {
  14655. uvScaleMap = material.bumpMap;
  14656. } else if ( material.roughnessMap ) {
  14657. uvScaleMap = material.roughnessMap;
  14658. } else if ( material.metalnessMap ) {
  14659. uvScaleMap = material.metalnessMap;
  14660. } else if ( material.alphaMap ) {
  14661. uvScaleMap = material.alphaMap;
  14662. } else if ( material.emissiveMap ) {
  14663. uvScaleMap = material.emissiveMap;
  14664. }
  14665. if ( uvScaleMap !== undefined ) {
  14666. // backwards compatibility
  14667. if ( uvScaleMap.isWebGLRenderTarget ) {
  14668. uvScaleMap = uvScaleMap.texture;
  14669. }
  14670. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14671. uvScaleMap.updateMatrix();
  14672. }
  14673. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14674. }
  14675. }
  14676. function refreshUniformsLine( uniforms, material ) {
  14677. uniforms.diffuse.value = material.color;
  14678. uniforms.opacity.value = material.opacity;
  14679. }
  14680. function refreshUniformsDash( uniforms, material ) {
  14681. uniforms.dashSize.value = material.dashSize;
  14682. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14683. uniforms.scale.value = material.scale;
  14684. }
  14685. function refreshUniformsPoints( uniforms, material ) {
  14686. uniforms.diffuse.value = material.color;
  14687. uniforms.opacity.value = material.opacity;
  14688. uniforms.size.value = material.size * _pixelRatio;
  14689. uniforms.scale.value = _height * 0.5;
  14690. uniforms.map.value = material.map;
  14691. if ( material.map !== null ) {
  14692. if ( material.map.matrixAutoUpdate === true ) {
  14693. material.map.updateMatrix();
  14694. }
  14695. uniforms.uvTransform.value.copy( material.map.matrix );
  14696. }
  14697. }
  14698. function refreshUniformsSprites( uniforms, material ) {
  14699. uniforms.diffuse.value = material.color;
  14700. uniforms.opacity.value = material.opacity;
  14701. uniforms.rotation.value = material.rotation;
  14702. uniforms.map.value = material.map;
  14703. if ( material.map !== null ) {
  14704. if ( material.map.matrixAutoUpdate === true ) {
  14705. material.map.updateMatrix();
  14706. }
  14707. uniforms.uvTransform.value.copy( material.map.matrix );
  14708. }
  14709. }
  14710. function refreshUniformsFog( uniforms, fog ) {
  14711. uniforms.fogColor.value = fog.color;
  14712. if ( fog.isFog ) {
  14713. uniforms.fogNear.value = fog.near;
  14714. uniforms.fogFar.value = fog.far;
  14715. } else if ( fog.isFogExp2 ) {
  14716. uniforms.fogDensity.value = fog.density;
  14717. }
  14718. }
  14719. function refreshUniformsLambert( uniforms, material ) {
  14720. if ( material.emissiveMap ) {
  14721. uniforms.emissiveMap.value = material.emissiveMap;
  14722. }
  14723. }
  14724. function refreshUniformsPhong( uniforms, material ) {
  14725. uniforms.specular.value = material.specular;
  14726. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14727. if ( material.emissiveMap ) {
  14728. uniforms.emissiveMap.value = material.emissiveMap;
  14729. }
  14730. if ( material.bumpMap ) {
  14731. uniforms.bumpMap.value = material.bumpMap;
  14732. uniforms.bumpScale.value = material.bumpScale;
  14733. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14734. }
  14735. if ( material.normalMap ) {
  14736. uniforms.normalMap.value = material.normalMap;
  14737. uniforms.normalScale.value.copy( material.normalScale );
  14738. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14739. }
  14740. if ( material.displacementMap ) {
  14741. uniforms.displacementMap.value = material.displacementMap;
  14742. uniforms.displacementScale.value = material.displacementScale;
  14743. uniforms.displacementBias.value = material.displacementBias;
  14744. }
  14745. }
  14746. function refreshUniformsToon( uniforms, material ) {
  14747. refreshUniformsPhong( uniforms, material );
  14748. if ( material.gradientMap ) {
  14749. uniforms.gradientMap.value = material.gradientMap;
  14750. }
  14751. }
  14752. function refreshUniformsStandard( uniforms, material ) {
  14753. uniforms.roughness.value = material.roughness;
  14754. uniforms.metalness.value = material.metalness;
  14755. if ( material.roughnessMap ) {
  14756. uniforms.roughnessMap.value = material.roughnessMap;
  14757. }
  14758. if ( material.metalnessMap ) {
  14759. uniforms.metalnessMap.value = material.metalnessMap;
  14760. }
  14761. if ( material.emissiveMap ) {
  14762. uniforms.emissiveMap.value = material.emissiveMap;
  14763. }
  14764. if ( material.bumpMap ) {
  14765. uniforms.bumpMap.value = material.bumpMap;
  14766. uniforms.bumpScale.value = material.bumpScale;
  14767. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14768. }
  14769. if ( material.normalMap ) {
  14770. uniforms.normalMap.value = material.normalMap;
  14771. uniforms.normalScale.value.copy( material.normalScale );
  14772. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14773. }
  14774. if ( material.displacementMap ) {
  14775. uniforms.displacementMap.value = material.displacementMap;
  14776. uniforms.displacementScale.value = material.displacementScale;
  14777. uniforms.displacementBias.value = material.displacementBias;
  14778. }
  14779. if ( material.envMap ) {
  14780. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14781. uniforms.envMapIntensity.value = material.envMapIntensity;
  14782. }
  14783. }
  14784. function refreshUniformsPhysical( uniforms, material ) {
  14785. refreshUniformsStandard( uniforms, material );
  14786. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14787. uniforms.clearCoat.value = material.clearCoat;
  14788. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14789. }
  14790. function refreshUniformsMatcap( uniforms, material ) {
  14791. if ( material.matcap ) {
  14792. uniforms.matcap.value = material.matcap;
  14793. }
  14794. if ( material.bumpMap ) {
  14795. uniforms.bumpMap.value = material.bumpMap;
  14796. uniforms.bumpScale.value = material.bumpScale;
  14797. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14798. }
  14799. if ( material.normalMap ) {
  14800. uniforms.normalMap.value = material.normalMap;
  14801. uniforms.normalScale.value.copy( material.normalScale );
  14802. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14803. }
  14804. if ( material.displacementMap ) {
  14805. uniforms.displacementMap.value = material.displacementMap;
  14806. uniforms.displacementScale.value = material.displacementScale;
  14807. uniforms.displacementBias.value = material.displacementBias;
  14808. }
  14809. }
  14810. function refreshUniformsDepth( uniforms, material ) {
  14811. if ( material.displacementMap ) {
  14812. uniforms.displacementMap.value = material.displacementMap;
  14813. uniforms.displacementScale.value = material.displacementScale;
  14814. uniforms.displacementBias.value = material.displacementBias;
  14815. }
  14816. }
  14817. function refreshUniformsDistance( uniforms, material ) {
  14818. if ( material.displacementMap ) {
  14819. uniforms.displacementMap.value = material.displacementMap;
  14820. uniforms.displacementScale.value = material.displacementScale;
  14821. uniforms.displacementBias.value = material.displacementBias;
  14822. }
  14823. uniforms.referencePosition.value.copy( material.referencePosition );
  14824. uniforms.nearDistance.value = material.nearDistance;
  14825. uniforms.farDistance.value = material.farDistance;
  14826. }
  14827. function refreshUniformsNormal( uniforms, material ) {
  14828. if ( material.bumpMap ) {
  14829. uniforms.bumpMap.value = material.bumpMap;
  14830. uniforms.bumpScale.value = material.bumpScale;
  14831. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14832. }
  14833. if ( material.normalMap ) {
  14834. uniforms.normalMap.value = material.normalMap;
  14835. uniforms.normalScale.value.copy( material.normalScale );
  14836. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14837. }
  14838. if ( material.displacementMap ) {
  14839. uniforms.displacementMap.value = material.displacementMap;
  14840. uniforms.displacementScale.value = material.displacementScale;
  14841. uniforms.displacementBias.value = material.displacementBias;
  14842. }
  14843. }
  14844. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14845. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14846. uniforms.ambientLightColor.needsUpdate = value;
  14847. uniforms.directionalLights.needsUpdate = value;
  14848. uniforms.pointLights.needsUpdate = value;
  14849. uniforms.spotLights.needsUpdate = value;
  14850. uniforms.rectAreaLights.needsUpdate = value;
  14851. uniforms.hemisphereLights.needsUpdate = value;
  14852. }
  14853. //
  14854. this.setFramebuffer = function ( value ) {
  14855. _framebuffer = value;
  14856. };
  14857. this.getRenderTarget = function () {
  14858. return _currentRenderTarget;
  14859. };
  14860. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipMapLevel ) {
  14861. _currentRenderTarget = renderTarget;
  14862. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14863. textures.setupRenderTarget( renderTarget );
  14864. }
  14865. var framebuffer = _framebuffer;
  14866. var isCube = false;
  14867. if ( renderTarget ) {
  14868. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14869. if ( renderTarget.isWebGLRenderTargetCube ) {
  14870. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  14871. isCube = true;
  14872. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14873. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14874. } else {
  14875. framebuffer = __webglFramebuffer;
  14876. }
  14877. _currentViewport.copy( renderTarget.viewport );
  14878. _currentScissor.copy( renderTarget.scissor );
  14879. _currentScissorTest = renderTarget.scissorTest;
  14880. } else {
  14881. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14882. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14883. _currentScissorTest = _scissorTest;
  14884. }
  14885. if ( _currentFramebuffer !== framebuffer ) {
  14886. _gl.bindFramebuffer( 36160, framebuffer );
  14887. _currentFramebuffer = framebuffer;
  14888. }
  14889. state.viewport( _currentViewport );
  14890. state.scissor( _currentScissor );
  14891. state.setScissorTest( _currentScissorTest );
  14892. if ( isCube ) {
  14893. var textureProperties = properties.get( renderTarget.texture );
  14894. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipMapLevel || 0 );
  14895. }
  14896. };
  14897. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14898. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14899. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14900. return;
  14901. }
  14902. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14903. if ( framebuffer ) {
  14904. var restore = false;
  14905. if ( framebuffer !== _currentFramebuffer ) {
  14906. _gl.bindFramebuffer( 36160, framebuffer );
  14907. restore = true;
  14908. }
  14909. try {
  14910. var texture = renderTarget.texture;
  14911. var textureFormat = texture.format;
  14912. var textureType = texture.type;
  14913. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14914. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14915. return;
  14916. }
  14917. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14918. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14919. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14920. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14921. return;
  14922. }
  14923. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14924. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14925. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14926. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14927. }
  14928. } else {
  14929. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14930. }
  14931. } finally {
  14932. if ( restore ) {
  14933. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14934. }
  14935. }
  14936. }
  14937. };
  14938. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14939. var width = texture.image.width;
  14940. var height = texture.image.height;
  14941. var glFormat = utils.convert( texture.format );
  14942. textures.setTexture2D( texture, 0 );
  14943. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14944. };
  14945. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14946. var width = srcTexture.image.width;
  14947. var height = srcTexture.image.height;
  14948. var glFormat = utils.convert( dstTexture.format );
  14949. var glType = utils.convert( dstTexture.type );
  14950. textures.setTexture2D( dstTexture, 0 );
  14951. if ( srcTexture.isDataTexture ) {
  14952. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14953. } else {
  14954. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14955. }
  14956. };
  14957. }
  14958. /**
  14959. * @author mrdoob / http://mrdoob.com/
  14960. * @author alteredq / http://alteredqualia.com/
  14961. */
  14962. function FogExp2( color, density ) {
  14963. this.name = '';
  14964. this.color = new Color( color );
  14965. this.density = ( density !== undefined ) ? density : 0.00025;
  14966. }
  14967. Object.assign( FogExp2.prototype, {
  14968. isFogExp2: true,
  14969. clone: function () {
  14970. return new FogExp2( this.color, this.density );
  14971. },
  14972. toJSON: function ( /* meta */ ) {
  14973. return {
  14974. type: 'FogExp2',
  14975. color: this.color.getHex(),
  14976. density: this.density
  14977. };
  14978. }
  14979. } );
  14980. /**
  14981. * @author mrdoob / http://mrdoob.com/
  14982. * @author alteredq / http://alteredqualia.com/
  14983. */
  14984. function Fog( color, near, far ) {
  14985. this.name = '';
  14986. this.color = new Color( color );
  14987. this.near = ( near !== undefined ) ? near : 1;
  14988. this.far = ( far !== undefined ) ? far : 1000;
  14989. }
  14990. Object.assign( Fog.prototype, {
  14991. isFog: true,
  14992. clone: function () {
  14993. return new Fog( this.color, this.near, this.far );
  14994. },
  14995. toJSON: function ( /* meta */ ) {
  14996. return {
  14997. type: 'Fog',
  14998. color: this.color.getHex(),
  14999. near: this.near,
  15000. far: this.far
  15001. };
  15002. }
  15003. } );
  15004. /**
  15005. * @author mrdoob / http://mrdoob.com/
  15006. */
  15007. function Scene() {
  15008. Object3D.call( this );
  15009. this.type = 'Scene';
  15010. this.background = null;
  15011. this.fog = null;
  15012. this.overrideMaterial = null;
  15013. this.autoUpdate = true; // checked by the renderer
  15014. }
  15015. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15016. constructor: Scene,
  15017. isScene: true,
  15018. copy: function ( source, recursive ) {
  15019. Object3D.prototype.copy.call( this, source, recursive );
  15020. if ( source.background !== null ) this.background = source.background.clone();
  15021. if ( source.fog !== null ) this.fog = source.fog.clone();
  15022. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  15023. this.autoUpdate = source.autoUpdate;
  15024. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15025. return this;
  15026. },
  15027. toJSON: function ( meta ) {
  15028. var data = Object3D.prototype.toJSON.call( this, meta );
  15029. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  15030. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  15031. return data;
  15032. },
  15033. dispose: function () {
  15034. this.dispatchEvent( { type: 'dispose' } );
  15035. }
  15036. } );
  15037. /**
  15038. * @author benaadams / https://twitter.com/ben_a_adams
  15039. */
  15040. function InterleavedBuffer( array, stride ) {
  15041. this.array = array;
  15042. this.stride = stride;
  15043. this.count = array !== undefined ? array.length / stride : 0;
  15044. this.dynamic = false;
  15045. this.updateRange = { offset: 0, count: - 1 };
  15046. this.version = 0;
  15047. }
  15048. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15049. set: function ( value ) {
  15050. if ( value === true ) this.version ++;
  15051. }
  15052. } );
  15053. Object.assign( InterleavedBuffer.prototype, {
  15054. isInterleavedBuffer: true,
  15055. onUploadCallback: function () {},
  15056. setArray: function ( array ) {
  15057. if ( Array.isArray( array ) ) {
  15058. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15059. }
  15060. this.count = array !== undefined ? array.length / this.stride : 0;
  15061. this.array = array;
  15062. return this;
  15063. },
  15064. setDynamic: function ( value ) {
  15065. this.dynamic = value;
  15066. return this;
  15067. },
  15068. copy: function ( source ) {
  15069. this.array = new source.array.constructor( source.array );
  15070. this.count = source.count;
  15071. this.stride = source.stride;
  15072. this.dynamic = source.dynamic;
  15073. return this;
  15074. },
  15075. copyAt: function ( index1, attribute, index2 ) {
  15076. index1 *= this.stride;
  15077. index2 *= attribute.stride;
  15078. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15079. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15080. }
  15081. return this;
  15082. },
  15083. set: function ( value, offset ) {
  15084. if ( offset === undefined ) offset = 0;
  15085. this.array.set( value, offset );
  15086. return this;
  15087. },
  15088. clone: function () {
  15089. return new this.constructor().copy( this );
  15090. },
  15091. onUpload: function ( callback ) {
  15092. this.onUploadCallback = callback;
  15093. return this;
  15094. }
  15095. } );
  15096. /**
  15097. * @author benaadams / https://twitter.com/ben_a_adams
  15098. */
  15099. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15100. this.data = interleavedBuffer;
  15101. this.itemSize = itemSize;
  15102. this.offset = offset;
  15103. this.normalized = normalized === true;
  15104. }
  15105. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15106. count: {
  15107. get: function () {
  15108. return this.data.count;
  15109. }
  15110. },
  15111. array: {
  15112. get: function () {
  15113. return this.data.array;
  15114. }
  15115. }
  15116. } );
  15117. Object.assign( InterleavedBufferAttribute.prototype, {
  15118. isInterleavedBufferAttribute: true,
  15119. setX: function ( index, x ) {
  15120. this.data.array[ index * this.data.stride + this.offset ] = x;
  15121. return this;
  15122. },
  15123. setY: function ( index, y ) {
  15124. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15125. return this;
  15126. },
  15127. setZ: function ( index, z ) {
  15128. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15129. return this;
  15130. },
  15131. setW: function ( index, w ) {
  15132. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15133. return this;
  15134. },
  15135. getX: function ( index ) {
  15136. return this.data.array[ index * this.data.stride + this.offset ];
  15137. },
  15138. getY: function ( index ) {
  15139. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15140. },
  15141. getZ: function ( index ) {
  15142. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15143. },
  15144. getW: function ( index ) {
  15145. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15146. },
  15147. setXY: function ( index, x, y ) {
  15148. index = index * this.data.stride + this.offset;
  15149. this.data.array[ index + 0 ] = x;
  15150. this.data.array[ index + 1 ] = y;
  15151. return this;
  15152. },
  15153. setXYZ: function ( index, x, y, z ) {
  15154. index = index * this.data.stride + this.offset;
  15155. this.data.array[ index + 0 ] = x;
  15156. this.data.array[ index + 1 ] = y;
  15157. this.data.array[ index + 2 ] = z;
  15158. return this;
  15159. },
  15160. setXYZW: function ( index, x, y, z, w ) {
  15161. index = index * this.data.stride + this.offset;
  15162. this.data.array[ index + 0 ] = x;
  15163. this.data.array[ index + 1 ] = y;
  15164. this.data.array[ index + 2 ] = z;
  15165. this.data.array[ index + 3 ] = w;
  15166. return this;
  15167. }
  15168. } );
  15169. /**
  15170. * @author alteredq / http://alteredqualia.com/
  15171. *
  15172. * parameters = {
  15173. * color: <hex>,
  15174. * map: new THREE.Texture( <Image> ),
  15175. * rotation: <float>,
  15176. * sizeAttenuation: <bool>
  15177. * }
  15178. */
  15179. function SpriteMaterial( parameters ) {
  15180. Material.call( this );
  15181. this.type = 'SpriteMaterial';
  15182. this.color = new Color( 0xffffff );
  15183. this.map = null;
  15184. this.rotation = 0;
  15185. this.sizeAttenuation = true;
  15186. this.lights = false;
  15187. this.transparent = true;
  15188. this.setValues( parameters );
  15189. }
  15190. SpriteMaterial.prototype = Object.create( Material.prototype );
  15191. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15192. SpriteMaterial.prototype.isSpriteMaterial = true;
  15193. SpriteMaterial.prototype.copy = function ( source ) {
  15194. Material.prototype.copy.call( this, source );
  15195. this.color.copy( source.color );
  15196. this.map = source.map;
  15197. this.rotation = source.rotation;
  15198. this.sizeAttenuation = source.sizeAttenuation;
  15199. return this;
  15200. };
  15201. /**
  15202. * @author mikael emtinger / http://gomo.se/
  15203. * @author alteredq / http://alteredqualia.com/
  15204. */
  15205. var geometry;
  15206. function Sprite( material ) {
  15207. Object3D.call( this );
  15208. this.type = 'Sprite';
  15209. if ( geometry === undefined ) {
  15210. geometry = new BufferGeometry();
  15211. var float32Array = new Float32Array( [
  15212. - 0.5, - 0.5, 0, 0, 0,
  15213. 0.5, - 0.5, 0, 1, 0,
  15214. 0.5, 0.5, 0, 1, 1,
  15215. - 0.5, 0.5, 0, 0, 1
  15216. ] );
  15217. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15218. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15219. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15220. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15221. }
  15222. this.geometry = geometry;
  15223. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15224. this.center = new Vector2( 0.5, 0.5 );
  15225. }
  15226. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15227. constructor: Sprite,
  15228. isSprite: true,
  15229. raycast: ( function () {
  15230. var intersectPoint = new Vector3();
  15231. var worldScale = new Vector3();
  15232. var mvPosition = new Vector3();
  15233. var alignedPosition = new Vector2();
  15234. var rotatedPosition = new Vector2();
  15235. var viewWorldMatrix = new Matrix4();
  15236. var vA = new Vector3();
  15237. var vB = new Vector3();
  15238. var vC = new Vector3();
  15239. var uvA = new Vector2();
  15240. var uvB = new Vector2();
  15241. var uvC = new Vector2();
  15242. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15243. // compute position in camera space
  15244. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15245. // to check if rotation is not zero
  15246. if ( sin !== undefined ) {
  15247. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15248. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15249. } else {
  15250. rotatedPosition.copy( alignedPosition );
  15251. }
  15252. vertexPosition.copy( mvPosition );
  15253. vertexPosition.x += rotatedPosition.x;
  15254. vertexPosition.y += rotatedPosition.y;
  15255. // transform to world space
  15256. vertexPosition.applyMatrix4( viewWorldMatrix );
  15257. }
  15258. return function raycast( raycaster, intersects ) {
  15259. worldScale.setFromMatrixScale( this.matrixWorld );
  15260. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15261. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15262. var rotation = this.material.rotation;
  15263. var sin, cos;
  15264. if ( rotation !== 0 ) {
  15265. cos = Math.cos( rotation );
  15266. sin = Math.sin( rotation );
  15267. }
  15268. var center = this.center;
  15269. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15270. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15271. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15272. uvA.set( 0, 0 );
  15273. uvB.set( 1, 0 );
  15274. uvC.set( 1, 1 );
  15275. // check first triangle
  15276. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15277. if ( intersect === null ) {
  15278. // check second triangle
  15279. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15280. uvB.set( 0, 1 );
  15281. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15282. if ( intersect === null ) {
  15283. return;
  15284. }
  15285. }
  15286. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15287. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15288. intersects.push( {
  15289. distance: distance,
  15290. point: intersectPoint.clone(),
  15291. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15292. face: null,
  15293. object: this
  15294. } );
  15295. };
  15296. }() ),
  15297. clone: function () {
  15298. return new this.constructor( this.material ).copy( this );
  15299. },
  15300. copy: function ( source ) {
  15301. Object3D.prototype.copy.call( this, source );
  15302. if ( source.center !== undefined ) this.center.copy( source.center );
  15303. return this;
  15304. }
  15305. } );
  15306. /**
  15307. * @author mikael emtinger / http://gomo.se/
  15308. * @author alteredq / http://alteredqualia.com/
  15309. * @author mrdoob / http://mrdoob.com/
  15310. */
  15311. function LOD() {
  15312. Object3D.call( this );
  15313. this.type = 'LOD';
  15314. Object.defineProperties( this, {
  15315. levels: {
  15316. enumerable: true,
  15317. value: []
  15318. }
  15319. } );
  15320. }
  15321. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15322. constructor: LOD,
  15323. copy: function ( source ) {
  15324. Object3D.prototype.copy.call( this, source, false );
  15325. var levels = source.levels;
  15326. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15327. var level = levels[ i ];
  15328. this.addLevel( level.object.clone(), level.distance );
  15329. }
  15330. return this;
  15331. },
  15332. addLevel: function ( object, distance ) {
  15333. if ( distance === undefined ) distance = 0;
  15334. distance = Math.abs( distance );
  15335. var levels = this.levels;
  15336. for ( var l = 0; l < levels.length; l ++ ) {
  15337. if ( distance < levels[ l ].distance ) {
  15338. break;
  15339. }
  15340. }
  15341. levels.splice( l, 0, { distance: distance, object: object } );
  15342. this.add( object );
  15343. },
  15344. getObjectForDistance: function ( distance ) {
  15345. var levels = this.levels;
  15346. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15347. if ( distance < levels[ i ].distance ) {
  15348. break;
  15349. }
  15350. }
  15351. return levels[ i - 1 ].object;
  15352. },
  15353. raycast: ( function () {
  15354. var matrixPosition = new Vector3();
  15355. return function raycast( raycaster, intersects ) {
  15356. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15357. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15358. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15359. };
  15360. }() ),
  15361. update: function () {
  15362. var v1 = new Vector3();
  15363. var v2 = new Vector3();
  15364. return function update( camera ) {
  15365. var levels = this.levels;
  15366. if ( levels.length > 1 ) {
  15367. v1.setFromMatrixPosition( camera.matrixWorld );
  15368. v2.setFromMatrixPosition( this.matrixWorld );
  15369. var distance = v1.distanceTo( v2 );
  15370. levels[ 0 ].object.visible = true;
  15371. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15372. if ( distance >= levels[ i ].distance ) {
  15373. levels[ i - 1 ].object.visible = false;
  15374. levels[ i ].object.visible = true;
  15375. } else {
  15376. break;
  15377. }
  15378. }
  15379. for ( ; i < l; i ++ ) {
  15380. levels[ i ].object.visible = false;
  15381. }
  15382. }
  15383. };
  15384. }(),
  15385. toJSON: function ( meta ) {
  15386. var data = Object3D.prototype.toJSON.call( this, meta );
  15387. data.object.levels = [];
  15388. var levels = this.levels;
  15389. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15390. var level = levels[ i ];
  15391. data.object.levels.push( {
  15392. object: level.object.uuid,
  15393. distance: level.distance
  15394. } );
  15395. }
  15396. return data;
  15397. }
  15398. } );
  15399. /**
  15400. * @author mikael emtinger / http://gomo.se/
  15401. * @author alteredq / http://alteredqualia.com/
  15402. * @author ikerr / http://verold.com
  15403. */
  15404. function SkinnedMesh( geometry, material ) {
  15405. if ( geometry && geometry.isGeometry ) {
  15406. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15407. }
  15408. Mesh.call( this, geometry, material );
  15409. this.type = 'SkinnedMesh';
  15410. this.bindMode = 'attached';
  15411. this.bindMatrix = new Matrix4();
  15412. this.bindMatrixInverse = new Matrix4();
  15413. }
  15414. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15415. constructor: SkinnedMesh,
  15416. isSkinnedMesh: true,
  15417. bind: function ( skeleton, bindMatrix ) {
  15418. this.skeleton = skeleton;
  15419. if ( bindMatrix === undefined ) {
  15420. this.updateMatrixWorld( true );
  15421. this.skeleton.calculateInverses();
  15422. bindMatrix = this.matrixWorld;
  15423. }
  15424. this.bindMatrix.copy( bindMatrix );
  15425. this.bindMatrixInverse.getInverse( bindMatrix );
  15426. },
  15427. pose: function () {
  15428. this.skeleton.pose();
  15429. },
  15430. normalizeSkinWeights: function () {
  15431. var vector = new Vector4();
  15432. var skinWeight = this.geometry.attributes.skinWeight;
  15433. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15434. vector.x = skinWeight.getX( i );
  15435. vector.y = skinWeight.getY( i );
  15436. vector.z = skinWeight.getZ( i );
  15437. vector.w = skinWeight.getW( i );
  15438. var scale = 1.0 / vector.manhattanLength();
  15439. if ( scale !== Infinity ) {
  15440. vector.multiplyScalar( scale );
  15441. } else {
  15442. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15443. }
  15444. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15445. }
  15446. },
  15447. updateMatrixWorld: function ( force ) {
  15448. Mesh.prototype.updateMatrixWorld.call( this, force );
  15449. if ( this.bindMode === 'attached' ) {
  15450. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15451. } else if ( this.bindMode === 'detached' ) {
  15452. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15453. } else {
  15454. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15455. }
  15456. },
  15457. clone: function () {
  15458. return new this.constructor( this.geometry, this.material ).copy( this );
  15459. }
  15460. } );
  15461. /**
  15462. * @author mikael emtinger / http://gomo.se/
  15463. * @author alteredq / http://alteredqualia.com/
  15464. * @author michael guerrero / http://realitymeltdown.com
  15465. * @author ikerr / http://verold.com
  15466. */
  15467. function Skeleton( bones, boneInverses ) {
  15468. // copy the bone array
  15469. bones = bones || [];
  15470. this.bones = bones.slice( 0 );
  15471. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15472. // use the supplied bone inverses or calculate the inverses
  15473. if ( boneInverses === undefined ) {
  15474. this.calculateInverses();
  15475. } else {
  15476. if ( this.bones.length === boneInverses.length ) {
  15477. this.boneInverses = boneInverses.slice( 0 );
  15478. } else {
  15479. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15480. this.boneInverses = [];
  15481. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15482. this.boneInverses.push( new Matrix4() );
  15483. }
  15484. }
  15485. }
  15486. }
  15487. Object.assign( Skeleton.prototype, {
  15488. calculateInverses: function () {
  15489. this.boneInverses = [];
  15490. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15491. var inverse = new Matrix4();
  15492. if ( this.bones[ i ] ) {
  15493. inverse.getInverse( this.bones[ i ].matrixWorld );
  15494. }
  15495. this.boneInverses.push( inverse );
  15496. }
  15497. },
  15498. pose: function () {
  15499. var bone, i, il;
  15500. // recover the bind-time world matrices
  15501. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15502. bone = this.bones[ i ];
  15503. if ( bone ) {
  15504. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15505. }
  15506. }
  15507. // compute the local matrices, positions, rotations and scales
  15508. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15509. bone = this.bones[ i ];
  15510. if ( bone ) {
  15511. if ( bone.parent && bone.parent.isBone ) {
  15512. bone.matrix.getInverse( bone.parent.matrixWorld );
  15513. bone.matrix.multiply( bone.matrixWorld );
  15514. } else {
  15515. bone.matrix.copy( bone.matrixWorld );
  15516. }
  15517. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15518. }
  15519. }
  15520. },
  15521. update: ( function () {
  15522. var offsetMatrix = new Matrix4();
  15523. var identityMatrix = new Matrix4();
  15524. return function update() {
  15525. var bones = this.bones;
  15526. var boneInverses = this.boneInverses;
  15527. var boneMatrices = this.boneMatrices;
  15528. var boneTexture = this.boneTexture;
  15529. // flatten bone matrices to array
  15530. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15531. // compute the offset between the current and the original transform
  15532. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15533. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15534. offsetMatrix.toArray( boneMatrices, i * 16 );
  15535. }
  15536. if ( boneTexture !== undefined ) {
  15537. boneTexture.needsUpdate = true;
  15538. }
  15539. };
  15540. } )(),
  15541. clone: function () {
  15542. return new Skeleton( this.bones, this.boneInverses );
  15543. },
  15544. getBoneByName: function ( name ) {
  15545. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15546. var bone = this.bones[ i ];
  15547. if ( bone.name === name ) {
  15548. return bone;
  15549. }
  15550. }
  15551. return undefined;
  15552. }
  15553. } );
  15554. /**
  15555. * @author mikael emtinger / http://gomo.se/
  15556. * @author alteredq / http://alteredqualia.com/
  15557. * @author ikerr / http://verold.com
  15558. */
  15559. function Bone() {
  15560. Object3D.call( this );
  15561. this.type = 'Bone';
  15562. }
  15563. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15564. constructor: Bone,
  15565. isBone: true
  15566. } );
  15567. /**
  15568. * @author mrdoob / http://mrdoob.com/
  15569. * @author alteredq / http://alteredqualia.com/
  15570. *
  15571. * parameters = {
  15572. * color: <hex>,
  15573. * opacity: <float>,
  15574. *
  15575. * linewidth: <float>,
  15576. * linecap: "round",
  15577. * linejoin: "round"
  15578. * }
  15579. */
  15580. function LineBasicMaterial( parameters ) {
  15581. Material.call( this );
  15582. this.type = 'LineBasicMaterial';
  15583. this.color = new Color( 0xffffff );
  15584. this.linewidth = 1;
  15585. this.linecap = 'round';
  15586. this.linejoin = 'round';
  15587. this.lights = false;
  15588. this.setValues( parameters );
  15589. }
  15590. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15591. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15592. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15593. LineBasicMaterial.prototype.copy = function ( source ) {
  15594. Material.prototype.copy.call( this, source );
  15595. this.color.copy( source.color );
  15596. this.linewidth = source.linewidth;
  15597. this.linecap = source.linecap;
  15598. this.linejoin = source.linejoin;
  15599. return this;
  15600. };
  15601. /**
  15602. * @author mrdoob / http://mrdoob.com/
  15603. */
  15604. function Line( geometry, material, mode ) {
  15605. if ( mode === 1 ) {
  15606. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15607. }
  15608. Object3D.call( this );
  15609. this.type = 'Line';
  15610. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15611. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15612. }
  15613. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15614. constructor: Line,
  15615. isLine: true,
  15616. computeLineDistances: ( function () {
  15617. var start = new Vector3();
  15618. var end = new Vector3();
  15619. return function computeLineDistances() {
  15620. var geometry = this.geometry;
  15621. if ( geometry.isBufferGeometry ) {
  15622. // we assume non-indexed geometry
  15623. if ( geometry.index === null ) {
  15624. var positionAttribute = geometry.attributes.position;
  15625. var lineDistances = [ 0 ];
  15626. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15627. start.fromBufferAttribute( positionAttribute, i - 1 );
  15628. end.fromBufferAttribute( positionAttribute, i );
  15629. lineDistances[ i ] = lineDistances[ i - 1 ];
  15630. lineDistances[ i ] += start.distanceTo( end );
  15631. }
  15632. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15633. } else {
  15634. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15635. }
  15636. } else if ( geometry.isGeometry ) {
  15637. var vertices = geometry.vertices;
  15638. var lineDistances = geometry.lineDistances;
  15639. lineDistances[ 0 ] = 0;
  15640. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15641. lineDistances[ i ] = lineDistances[ i - 1 ];
  15642. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15643. }
  15644. }
  15645. return this;
  15646. };
  15647. }() ),
  15648. raycast: ( function () {
  15649. var inverseMatrix = new Matrix4();
  15650. var ray = new Ray();
  15651. var sphere = new Sphere();
  15652. return function raycast( raycaster, intersects ) {
  15653. var precision = raycaster.linePrecision;
  15654. var geometry = this.geometry;
  15655. var matrixWorld = this.matrixWorld;
  15656. // Checking boundingSphere distance to ray
  15657. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15658. sphere.copy( geometry.boundingSphere );
  15659. sphere.applyMatrix4( matrixWorld );
  15660. sphere.radius += precision;
  15661. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15662. //
  15663. inverseMatrix.getInverse( matrixWorld );
  15664. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15665. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15666. var localPrecisionSq = localPrecision * localPrecision;
  15667. var vStart = new Vector3();
  15668. var vEnd = new Vector3();
  15669. var interSegment = new Vector3();
  15670. var interRay = new Vector3();
  15671. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15672. if ( geometry.isBufferGeometry ) {
  15673. var index = geometry.index;
  15674. var attributes = geometry.attributes;
  15675. var positions = attributes.position.array;
  15676. if ( index !== null ) {
  15677. var indices = index.array;
  15678. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15679. var a = indices[ i ];
  15680. var b = indices[ i + 1 ];
  15681. vStart.fromArray( positions, a * 3 );
  15682. vEnd.fromArray( positions, b * 3 );
  15683. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15684. if ( distSq > localPrecisionSq ) continue;
  15685. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15686. var distance = raycaster.ray.origin.distanceTo( interRay );
  15687. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15688. intersects.push( {
  15689. distance: distance,
  15690. // What do we want? intersection point on the ray or on the segment??
  15691. // point: raycaster.ray.at( distance ),
  15692. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15693. index: i,
  15694. face: null,
  15695. faceIndex: null,
  15696. object: this
  15697. } );
  15698. }
  15699. } else {
  15700. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15701. vStart.fromArray( positions, 3 * i );
  15702. vEnd.fromArray( positions, 3 * i + 3 );
  15703. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15704. if ( distSq > localPrecisionSq ) continue;
  15705. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15706. var distance = raycaster.ray.origin.distanceTo( interRay );
  15707. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15708. intersects.push( {
  15709. distance: distance,
  15710. // What do we want? intersection point on the ray or on the segment??
  15711. // point: raycaster.ray.at( distance ),
  15712. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15713. index: i,
  15714. face: null,
  15715. faceIndex: null,
  15716. object: this
  15717. } );
  15718. }
  15719. }
  15720. } else if ( geometry.isGeometry ) {
  15721. var vertices = geometry.vertices;
  15722. var nbVertices = vertices.length;
  15723. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15724. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15725. if ( distSq > localPrecisionSq ) continue;
  15726. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15727. var distance = raycaster.ray.origin.distanceTo( interRay );
  15728. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15729. intersects.push( {
  15730. distance: distance,
  15731. // What do we want? intersection point on the ray or on the segment??
  15732. // point: raycaster.ray.at( distance ),
  15733. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15734. index: i,
  15735. face: null,
  15736. faceIndex: null,
  15737. object: this
  15738. } );
  15739. }
  15740. }
  15741. };
  15742. }() ),
  15743. clone: function () {
  15744. return new this.constructor( this.geometry, this.material ).copy( this );
  15745. }
  15746. } );
  15747. /**
  15748. * @author mrdoob / http://mrdoob.com/
  15749. */
  15750. function LineSegments( geometry, material ) {
  15751. Line.call( this, geometry, material );
  15752. this.type = 'LineSegments';
  15753. }
  15754. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15755. constructor: LineSegments,
  15756. isLineSegments: true,
  15757. computeLineDistances: ( function () {
  15758. var start = new Vector3();
  15759. var end = new Vector3();
  15760. return function computeLineDistances() {
  15761. var geometry = this.geometry;
  15762. if ( geometry.isBufferGeometry ) {
  15763. // we assume non-indexed geometry
  15764. if ( geometry.index === null ) {
  15765. var positionAttribute = geometry.attributes.position;
  15766. var lineDistances = [];
  15767. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15768. start.fromBufferAttribute( positionAttribute, i );
  15769. end.fromBufferAttribute( positionAttribute, i + 1 );
  15770. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15771. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15772. }
  15773. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15774. } else {
  15775. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15776. }
  15777. } else if ( geometry.isGeometry ) {
  15778. var vertices = geometry.vertices;
  15779. var lineDistances = geometry.lineDistances;
  15780. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15781. start.copy( vertices[ i ] );
  15782. end.copy( vertices[ i + 1 ] );
  15783. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15784. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15785. }
  15786. }
  15787. return this;
  15788. };
  15789. }() )
  15790. } );
  15791. /**
  15792. * @author mgreter / http://github.com/mgreter
  15793. */
  15794. function LineLoop( geometry, material ) {
  15795. Line.call( this, geometry, material );
  15796. this.type = 'LineLoop';
  15797. }
  15798. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15799. constructor: LineLoop,
  15800. isLineLoop: true,
  15801. } );
  15802. /**
  15803. * @author mrdoob / http://mrdoob.com/
  15804. * @author alteredq / http://alteredqualia.com/
  15805. *
  15806. * parameters = {
  15807. * color: <hex>,
  15808. * opacity: <float>,
  15809. * map: new THREE.Texture( <Image> ),
  15810. *
  15811. * size: <float>,
  15812. * sizeAttenuation: <bool>
  15813. *
  15814. * morphTargets: <bool>
  15815. * }
  15816. */
  15817. function PointsMaterial( parameters ) {
  15818. Material.call( this );
  15819. this.type = 'PointsMaterial';
  15820. this.color = new Color( 0xffffff );
  15821. this.map = null;
  15822. this.size = 1;
  15823. this.sizeAttenuation = true;
  15824. this.morphTargets = false;
  15825. this.lights = false;
  15826. this.setValues( parameters );
  15827. }
  15828. PointsMaterial.prototype = Object.create( Material.prototype );
  15829. PointsMaterial.prototype.constructor = PointsMaterial;
  15830. PointsMaterial.prototype.isPointsMaterial = true;
  15831. PointsMaterial.prototype.copy = function ( source ) {
  15832. Material.prototype.copy.call( this, source );
  15833. this.color.copy( source.color );
  15834. this.map = source.map;
  15835. this.size = source.size;
  15836. this.sizeAttenuation = source.sizeAttenuation;
  15837. this.morphTargets = source.morphTargets;
  15838. return this;
  15839. };
  15840. /**
  15841. * @author alteredq / http://alteredqualia.com/
  15842. */
  15843. function Points( geometry, material ) {
  15844. Object3D.call( this );
  15845. this.type = 'Points';
  15846. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15847. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15848. }
  15849. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15850. constructor: Points,
  15851. isPoints: true,
  15852. raycast: ( function () {
  15853. var inverseMatrix = new Matrix4();
  15854. var ray = new Ray();
  15855. var sphere = new Sphere();
  15856. return function raycast( raycaster, intersects ) {
  15857. var object = this;
  15858. var geometry = this.geometry;
  15859. var matrixWorld = this.matrixWorld;
  15860. var threshold = raycaster.params.Points.threshold;
  15861. // Checking boundingSphere distance to ray
  15862. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15863. sphere.copy( geometry.boundingSphere );
  15864. sphere.applyMatrix4( matrixWorld );
  15865. sphere.radius += threshold;
  15866. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15867. //
  15868. inverseMatrix.getInverse( matrixWorld );
  15869. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15870. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15871. var localThresholdSq = localThreshold * localThreshold;
  15872. var position = new Vector3();
  15873. var intersectPoint = new Vector3();
  15874. function testPoint( point, index ) {
  15875. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15876. if ( rayPointDistanceSq < localThresholdSq ) {
  15877. ray.closestPointToPoint( point, intersectPoint );
  15878. intersectPoint.applyMatrix4( matrixWorld );
  15879. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15880. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15881. intersects.push( {
  15882. distance: distance,
  15883. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15884. point: intersectPoint.clone(),
  15885. index: index,
  15886. face: null,
  15887. object: object
  15888. } );
  15889. }
  15890. }
  15891. if ( geometry.isBufferGeometry ) {
  15892. var index = geometry.index;
  15893. var attributes = geometry.attributes;
  15894. var positions = attributes.position.array;
  15895. if ( index !== null ) {
  15896. var indices = index.array;
  15897. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15898. var a = indices[ i ];
  15899. position.fromArray( positions, a * 3 );
  15900. testPoint( position, a );
  15901. }
  15902. } else {
  15903. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15904. position.fromArray( positions, i * 3 );
  15905. testPoint( position, i );
  15906. }
  15907. }
  15908. } else {
  15909. var vertices = geometry.vertices;
  15910. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15911. testPoint( vertices[ i ], i );
  15912. }
  15913. }
  15914. };
  15915. }() ),
  15916. clone: function () {
  15917. return new this.constructor( this.geometry, this.material ).copy( this );
  15918. }
  15919. } );
  15920. /**
  15921. * @author mrdoob / http://mrdoob.com/
  15922. */
  15923. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15924. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15925. this.format = format !== undefined ? format : RGBFormat;
  15926. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15927. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15928. this.generateMipmaps = false;
  15929. }
  15930. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15931. constructor: VideoTexture,
  15932. isVideoTexture: true,
  15933. update: function () {
  15934. var video = this.image;
  15935. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15936. this.needsUpdate = true;
  15937. }
  15938. }
  15939. } );
  15940. /**
  15941. * @author alteredq / http://alteredqualia.com/
  15942. */
  15943. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15944. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15945. this.image = { width: width, height: height };
  15946. this.mipmaps = mipmaps;
  15947. // no flipping for cube textures
  15948. // (also flipping doesn't work for compressed textures )
  15949. this.flipY = false;
  15950. // can't generate mipmaps for compressed textures
  15951. // mips must be embedded in DDS files
  15952. this.generateMipmaps = false;
  15953. }
  15954. CompressedTexture.prototype = Object.create( Texture.prototype );
  15955. CompressedTexture.prototype.constructor = CompressedTexture;
  15956. CompressedTexture.prototype.isCompressedTexture = true;
  15957. /**
  15958. * @author mrdoob / http://mrdoob.com/
  15959. */
  15960. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15961. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15962. this.needsUpdate = true;
  15963. }
  15964. CanvasTexture.prototype = Object.create( Texture.prototype );
  15965. CanvasTexture.prototype.constructor = CanvasTexture;
  15966. CanvasTexture.prototype.isCanvasTexture = true;
  15967. /**
  15968. * @author Matt DesLauriers / @mattdesl
  15969. * @author atix / arthursilber.de
  15970. */
  15971. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15972. format = format !== undefined ? format : DepthFormat;
  15973. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15974. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15975. }
  15976. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15977. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15978. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15979. this.image = { width: width, height: height };
  15980. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15981. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15982. this.flipY = false;
  15983. this.generateMipmaps = false;
  15984. }
  15985. DepthTexture.prototype = Object.create( Texture.prototype );
  15986. DepthTexture.prototype.constructor = DepthTexture;
  15987. DepthTexture.prototype.isDepthTexture = true;
  15988. /**
  15989. * @author mrdoob / http://mrdoob.com/
  15990. * @author Mugen87 / https://github.com/Mugen87
  15991. */
  15992. function WireframeGeometry( geometry ) {
  15993. BufferGeometry.call( this );
  15994. this.type = 'WireframeGeometry';
  15995. // buffer
  15996. var vertices = [];
  15997. // helper variables
  15998. var i, j, l, o, ol;
  15999. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16000. var key, keys = [ 'a', 'b', 'c' ];
  16001. var vertex;
  16002. // different logic for Geometry and BufferGeometry
  16003. if ( geometry && geometry.isGeometry ) {
  16004. // create a data structure that contains all edges without duplicates
  16005. var faces = geometry.faces;
  16006. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16007. var face = faces[ i ];
  16008. for ( j = 0; j < 3; j ++ ) {
  16009. edge1 = face[ keys[ j ] ];
  16010. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16011. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16012. edge[ 1 ] = Math.max( edge1, edge2 );
  16013. key = edge[ 0 ] + ',' + edge[ 1 ];
  16014. if ( edges[ key ] === undefined ) {
  16015. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16016. }
  16017. }
  16018. }
  16019. // generate vertices
  16020. for ( key in edges ) {
  16021. e = edges[ key ];
  16022. vertex = geometry.vertices[ e.index1 ];
  16023. vertices.push( vertex.x, vertex.y, vertex.z );
  16024. vertex = geometry.vertices[ e.index2 ];
  16025. vertices.push( vertex.x, vertex.y, vertex.z );
  16026. }
  16027. } else if ( geometry && geometry.isBufferGeometry ) {
  16028. var position, indices, groups;
  16029. var group, start, count;
  16030. var index1, index2;
  16031. vertex = new Vector3();
  16032. if ( geometry.index !== null ) {
  16033. // indexed BufferGeometry
  16034. position = geometry.attributes.position;
  16035. indices = geometry.index;
  16036. groups = geometry.groups;
  16037. if ( groups.length === 0 ) {
  16038. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16039. }
  16040. // create a data structure that contains all eges without duplicates
  16041. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16042. group = groups[ o ];
  16043. start = group.start;
  16044. count = group.count;
  16045. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16046. for ( j = 0; j < 3; j ++ ) {
  16047. edge1 = indices.getX( i + j );
  16048. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16049. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16050. edge[ 1 ] = Math.max( edge1, edge2 );
  16051. key = edge[ 0 ] + ',' + edge[ 1 ];
  16052. if ( edges[ key ] === undefined ) {
  16053. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16054. }
  16055. }
  16056. }
  16057. }
  16058. // generate vertices
  16059. for ( key in edges ) {
  16060. e = edges[ key ];
  16061. vertex.fromBufferAttribute( position, e.index1 );
  16062. vertices.push( vertex.x, vertex.y, vertex.z );
  16063. vertex.fromBufferAttribute( position, e.index2 );
  16064. vertices.push( vertex.x, vertex.y, vertex.z );
  16065. }
  16066. } else {
  16067. // non-indexed BufferGeometry
  16068. position = geometry.attributes.position;
  16069. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16070. for ( j = 0; j < 3; j ++ ) {
  16071. // three edges per triangle, an edge is represented as (index1, index2)
  16072. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16073. index1 = 3 * i + j;
  16074. vertex.fromBufferAttribute( position, index1 );
  16075. vertices.push( vertex.x, vertex.y, vertex.z );
  16076. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16077. vertex.fromBufferAttribute( position, index2 );
  16078. vertices.push( vertex.x, vertex.y, vertex.z );
  16079. }
  16080. }
  16081. }
  16082. }
  16083. // build geometry
  16084. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16085. }
  16086. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16087. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16088. /**
  16089. * @author zz85 / https://github.com/zz85
  16090. * @author Mugen87 / https://github.com/Mugen87
  16091. *
  16092. * Parametric Surfaces Geometry
  16093. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16094. */
  16095. // ParametricGeometry
  16096. function ParametricGeometry( func, slices, stacks ) {
  16097. Geometry.call( this );
  16098. this.type = 'ParametricGeometry';
  16099. this.parameters = {
  16100. func: func,
  16101. slices: slices,
  16102. stacks: stacks
  16103. };
  16104. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16105. this.mergeVertices();
  16106. }
  16107. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16108. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16109. // ParametricBufferGeometry
  16110. function ParametricBufferGeometry( func, slices, stacks ) {
  16111. BufferGeometry.call( this );
  16112. this.type = 'ParametricBufferGeometry';
  16113. this.parameters = {
  16114. func: func,
  16115. slices: slices,
  16116. stacks: stacks
  16117. };
  16118. // buffers
  16119. var indices = [];
  16120. var vertices = [];
  16121. var normals = [];
  16122. var uvs = [];
  16123. var EPS = 0.00001;
  16124. var normal = new Vector3();
  16125. var p0 = new Vector3(), p1 = new Vector3();
  16126. var pu = new Vector3(), pv = new Vector3();
  16127. var i, j;
  16128. if ( func.length < 3 ) {
  16129. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16130. }
  16131. // generate vertices, normals and uvs
  16132. var sliceCount = slices + 1;
  16133. for ( i = 0; i <= stacks; i ++ ) {
  16134. var v = i / stacks;
  16135. for ( j = 0; j <= slices; j ++ ) {
  16136. var u = j / slices;
  16137. // vertex
  16138. func( u, v, p0 );
  16139. vertices.push( p0.x, p0.y, p0.z );
  16140. // normal
  16141. // approximate tangent vectors via finite differences
  16142. if ( u - EPS >= 0 ) {
  16143. func( u - EPS, v, p1 );
  16144. pu.subVectors( p0, p1 );
  16145. } else {
  16146. func( u + EPS, v, p1 );
  16147. pu.subVectors( p1, p0 );
  16148. }
  16149. if ( v - EPS >= 0 ) {
  16150. func( u, v - EPS, p1 );
  16151. pv.subVectors( p0, p1 );
  16152. } else {
  16153. func( u, v + EPS, p1 );
  16154. pv.subVectors( p1, p0 );
  16155. }
  16156. // cross product of tangent vectors returns surface normal
  16157. normal.crossVectors( pu, pv ).normalize();
  16158. normals.push( normal.x, normal.y, normal.z );
  16159. // uv
  16160. uvs.push( u, v );
  16161. }
  16162. }
  16163. // generate indices
  16164. for ( i = 0; i < stacks; i ++ ) {
  16165. for ( j = 0; j < slices; j ++ ) {
  16166. var a = i * sliceCount + j;
  16167. var b = i * sliceCount + j + 1;
  16168. var c = ( i + 1 ) * sliceCount + j + 1;
  16169. var d = ( i + 1 ) * sliceCount + j;
  16170. // faces one and two
  16171. indices.push( a, b, d );
  16172. indices.push( b, c, d );
  16173. }
  16174. }
  16175. // build geometry
  16176. this.setIndex( indices );
  16177. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16178. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16179. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16180. }
  16181. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16182. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16183. /**
  16184. * @author clockworkgeek / https://github.com/clockworkgeek
  16185. * @author timothypratley / https://github.com/timothypratley
  16186. * @author WestLangley / http://github.com/WestLangley
  16187. * @author Mugen87 / https://github.com/Mugen87
  16188. */
  16189. // PolyhedronGeometry
  16190. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16191. Geometry.call( this );
  16192. this.type = 'PolyhedronGeometry';
  16193. this.parameters = {
  16194. vertices: vertices,
  16195. indices: indices,
  16196. radius: radius,
  16197. detail: detail
  16198. };
  16199. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16200. this.mergeVertices();
  16201. }
  16202. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16203. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16204. // PolyhedronBufferGeometry
  16205. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16206. BufferGeometry.call( this );
  16207. this.type = 'PolyhedronBufferGeometry';
  16208. this.parameters = {
  16209. vertices: vertices,
  16210. indices: indices,
  16211. radius: radius,
  16212. detail: detail
  16213. };
  16214. radius = radius || 1;
  16215. detail = detail || 0;
  16216. // default buffer data
  16217. var vertexBuffer = [];
  16218. var uvBuffer = [];
  16219. // the subdivision creates the vertex buffer data
  16220. subdivide( detail );
  16221. // all vertices should lie on a conceptual sphere with a given radius
  16222. appplyRadius( radius );
  16223. // finally, create the uv data
  16224. generateUVs();
  16225. // build non-indexed geometry
  16226. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16227. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16228. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16229. if ( detail === 0 ) {
  16230. this.computeVertexNormals(); // flat normals
  16231. } else {
  16232. this.normalizeNormals(); // smooth normals
  16233. }
  16234. // helper functions
  16235. function subdivide( detail ) {
  16236. var a = new Vector3();
  16237. var b = new Vector3();
  16238. var c = new Vector3();
  16239. // iterate over all faces and apply a subdivison with the given detail value
  16240. for ( var i = 0; i < indices.length; i += 3 ) {
  16241. // get the vertices of the face
  16242. getVertexByIndex( indices[ i + 0 ], a );
  16243. getVertexByIndex( indices[ i + 1 ], b );
  16244. getVertexByIndex( indices[ i + 2 ], c );
  16245. // perform subdivision
  16246. subdivideFace( a, b, c, detail );
  16247. }
  16248. }
  16249. function subdivideFace( a, b, c, detail ) {
  16250. var cols = Math.pow( 2, detail );
  16251. // we use this multidimensional array as a data structure for creating the subdivision
  16252. var v = [];
  16253. var i, j;
  16254. // construct all of the vertices for this subdivision
  16255. for ( i = 0; i <= cols; i ++ ) {
  16256. v[ i ] = [];
  16257. var aj = a.clone().lerp( c, i / cols );
  16258. var bj = b.clone().lerp( c, i / cols );
  16259. var rows = cols - i;
  16260. for ( j = 0; j <= rows; j ++ ) {
  16261. if ( j === 0 && i === cols ) {
  16262. v[ i ][ j ] = aj;
  16263. } else {
  16264. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16265. }
  16266. }
  16267. }
  16268. // construct all of the faces
  16269. for ( i = 0; i < cols; i ++ ) {
  16270. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16271. var k = Math.floor( j / 2 );
  16272. if ( j % 2 === 0 ) {
  16273. pushVertex( v[ i ][ k + 1 ] );
  16274. pushVertex( v[ i + 1 ][ k ] );
  16275. pushVertex( v[ i ][ k ] );
  16276. } else {
  16277. pushVertex( v[ i ][ k + 1 ] );
  16278. pushVertex( v[ i + 1 ][ k + 1 ] );
  16279. pushVertex( v[ i + 1 ][ k ] );
  16280. }
  16281. }
  16282. }
  16283. }
  16284. function appplyRadius( radius ) {
  16285. var vertex = new Vector3();
  16286. // iterate over the entire buffer and apply the radius to each vertex
  16287. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16288. vertex.x = vertexBuffer[ i + 0 ];
  16289. vertex.y = vertexBuffer[ i + 1 ];
  16290. vertex.z = vertexBuffer[ i + 2 ];
  16291. vertex.normalize().multiplyScalar( radius );
  16292. vertexBuffer[ i + 0 ] = vertex.x;
  16293. vertexBuffer[ i + 1 ] = vertex.y;
  16294. vertexBuffer[ i + 2 ] = vertex.z;
  16295. }
  16296. }
  16297. function generateUVs() {
  16298. var vertex = new Vector3();
  16299. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16300. vertex.x = vertexBuffer[ i + 0 ];
  16301. vertex.y = vertexBuffer[ i + 1 ];
  16302. vertex.z = vertexBuffer[ i + 2 ];
  16303. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16304. var v = inclination( vertex ) / Math.PI + 0.5;
  16305. uvBuffer.push( u, 1 - v );
  16306. }
  16307. correctUVs();
  16308. correctSeam();
  16309. }
  16310. function correctSeam() {
  16311. // handle case when face straddles the seam, see #3269
  16312. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16313. // uv data of a single face
  16314. var x0 = uvBuffer[ i + 0 ];
  16315. var x1 = uvBuffer[ i + 2 ];
  16316. var x2 = uvBuffer[ i + 4 ];
  16317. var max = Math.max( x0, x1, x2 );
  16318. var min = Math.min( x0, x1, x2 );
  16319. // 0.9 is somewhat arbitrary
  16320. if ( max > 0.9 && min < 0.1 ) {
  16321. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16322. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16323. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16324. }
  16325. }
  16326. }
  16327. function pushVertex( vertex ) {
  16328. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16329. }
  16330. function getVertexByIndex( index, vertex ) {
  16331. var stride = index * 3;
  16332. vertex.x = vertices[ stride + 0 ];
  16333. vertex.y = vertices[ stride + 1 ];
  16334. vertex.z = vertices[ stride + 2 ];
  16335. }
  16336. function correctUVs() {
  16337. var a = new Vector3();
  16338. var b = new Vector3();
  16339. var c = new Vector3();
  16340. var centroid = new Vector3();
  16341. var uvA = new Vector2();
  16342. var uvB = new Vector2();
  16343. var uvC = new Vector2();
  16344. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16345. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16346. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16347. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16348. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16349. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16350. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16351. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16352. var azi = azimuth( centroid );
  16353. correctUV( uvA, j + 0, a, azi );
  16354. correctUV( uvB, j + 2, b, azi );
  16355. correctUV( uvC, j + 4, c, azi );
  16356. }
  16357. }
  16358. function correctUV( uv, stride, vector, azimuth ) {
  16359. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16360. uvBuffer[ stride ] = uv.x - 1;
  16361. }
  16362. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16363. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16364. }
  16365. }
  16366. // Angle around the Y axis, counter-clockwise when looking from above.
  16367. function azimuth( vector ) {
  16368. return Math.atan2( vector.z, - vector.x );
  16369. }
  16370. // Angle above the XZ plane.
  16371. function inclination( vector ) {
  16372. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16373. }
  16374. }
  16375. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16376. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16377. /**
  16378. * @author timothypratley / https://github.com/timothypratley
  16379. * @author Mugen87 / https://github.com/Mugen87
  16380. */
  16381. // TetrahedronGeometry
  16382. function TetrahedronGeometry( radius, detail ) {
  16383. Geometry.call( this );
  16384. this.type = 'TetrahedronGeometry';
  16385. this.parameters = {
  16386. radius: radius,
  16387. detail: detail
  16388. };
  16389. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16390. this.mergeVertices();
  16391. }
  16392. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16393. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16394. // TetrahedronBufferGeometry
  16395. function TetrahedronBufferGeometry( radius, detail ) {
  16396. var vertices = [
  16397. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16398. ];
  16399. var indices = [
  16400. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16401. ];
  16402. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16403. this.type = 'TetrahedronBufferGeometry';
  16404. this.parameters = {
  16405. radius: radius,
  16406. detail: detail
  16407. };
  16408. }
  16409. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16410. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16411. /**
  16412. * @author timothypratley / https://github.com/timothypratley
  16413. * @author Mugen87 / https://github.com/Mugen87
  16414. */
  16415. // OctahedronGeometry
  16416. function OctahedronGeometry( radius, detail ) {
  16417. Geometry.call( this );
  16418. this.type = 'OctahedronGeometry';
  16419. this.parameters = {
  16420. radius: radius,
  16421. detail: detail
  16422. };
  16423. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16424. this.mergeVertices();
  16425. }
  16426. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16427. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16428. // OctahedronBufferGeometry
  16429. function OctahedronBufferGeometry( radius, detail ) {
  16430. var vertices = [
  16431. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16432. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16433. ];
  16434. var indices = [
  16435. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16436. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16437. 1, 3, 4, 1, 4, 2
  16438. ];
  16439. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16440. this.type = 'OctahedronBufferGeometry';
  16441. this.parameters = {
  16442. radius: radius,
  16443. detail: detail
  16444. };
  16445. }
  16446. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16447. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16448. /**
  16449. * @author timothypratley / https://github.com/timothypratley
  16450. * @author Mugen87 / https://github.com/Mugen87
  16451. */
  16452. // IcosahedronGeometry
  16453. function IcosahedronGeometry( radius, detail ) {
  16454. Geometry.call( this );
  16455. this.type = 'IcosahedronGeometry';
  16456. this.parameters = {
  16457. radius: radius,
  16458. detail: detail
  16459. };
  16460. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16461. this.mergeVertices();
  16462. }
  16463. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16464. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16465. // IcosahedronBufferGeometry
  16466. function IcosahedronBufferGeometry( radius, detail ) {
  16467. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16468. var vertices = [
  16469. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16470. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16471. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16472. ];
  16473. var indices = [
  16474. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16475. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16476. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16477. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16478. ];
  16479. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16480. this.type = 'IcosahedronBufferGeometry';
  16481. this.parameters = {
  16482. radius: radius,
  16483. detail: detail
  16484. };
  16485. }
  16486. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16487. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16488. /**
  16489. * @author Abe Pazos / https://hamoid.com
  16490. * @author Mugen87 / https://github.com/Mugen87
  16491. */
  16492. // DodecahedronGeometry
  16493. function DodecahedronGeometry( radius, detail ) {
  16494. Geometry.call( this );
  16495. this.type = 'DodecahedronGeometry';
  16496. this.parameters = {
  16497. radius: radius,
  16498. detail: detail
  16499. };
  16500. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16501. this.mergeVertices();
  16502. }
  16503. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16504. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16505. // DodecahedronBufferGeometry
  16506. function DodecahedronBufferGeometry( radius, detail ) {
  16507. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16508. var r = 1 / t;
  16509. var vertices = [
  16510. // (±1, ±1, ±1)
  16511. - 1, - 1, - 1, - 1, - 1, 1,
  16512. - 1, 1, - 1, - 1, 1, 1,
  16513. 1, - 1, - 1, 1, - 1, 1,
  16514. 1, 1, - 1, 1, 1, 1,
  16515. // (0, ±1/φ, ±φ)
  16516. 0, - r, - t, 0, - r, t,
  16517. 0, r, - t, 0, r, t,
  16518. // (±1/φ, ±φ, 0)
  16519. - r, - t, 0, - r, t, 0,
  16520. r, - t, 0, r, t, 0,
  16521. // (±φ, 0, ±1/φ)
  16522. - t, 0, - r, t, 0, - r,
  16523. - t, 0, r, t, 0, r
  16524. ];
  16525. var indices = [
  16526. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16527. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16528. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16529. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16530. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16531. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16532. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16533. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16534. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16535. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16536. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16537. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16538. ];
  16539. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16540. this.type = 'DodecahedronBufferGeometry';
  16541. this.parameters = {
  16542. radius: radius,
  16543. detail: detail
  16544. };
  16545. }
  16546. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16547. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16548. /**
  16549. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16550. * @author WestLangley / https://github.com/WestLangley
  16551. * @author zz85 / https://github.com/zz85
  16552. * @author miningold / https://github.com/miningold
  16553. * @author jonobr1 / https://github.com/jonobr1
  16554. * @author Mugen87 / https://github.com/Mugen87
  16555. *
  16556. */
  16557. // TubeGeometry
  16558. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16559. Geometry.call( this );
  16560. this.type = 'TubeGeometry';
  16561. this.parameters = {
  16562. path: path,
  16563. tubularSegments: tubularSegments,
  16564. radius: radius,
  16565. radialSegments: radialSegments,
  16566. closed: closed
  16567. };
  16568. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16569. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16570. // expose internals
  16571. this.tangents = bufferGeometry.tangents;
  16572. this.normals = bufferGeometry.normals;
  16573. this.binormals = bufferGeometry.binormals;
  16574. // create geometry
  16575. this.fromBufferGeometry( bufferGeometry );
  16576. this.mergeVertices();
  16577. }
  16578. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16579. TubeGeometry.prototype.constructor = TubeGeometry;
  16580. // TubeBufferGeometry
  16581. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16582. BufferGeometry.call( this );
  16583. this.type = 'TubeBufferGeometry';
  16584. this.parameters = {
  16585. path: path,
  16586. tubularSegments: tubularSegments,
  16587. radius: radius,
  16588. radialSegments: radialSegments,
  16589. closed: closed
  16590. };
  16591. tubularSegments = tubularSegments || 64;
  16592. radius = radius || 1;
  16593. radialSegments = radialSegments || 8;
  16594. closed = closed || false;
  16595. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16596. // expose internals
  16597. this.tangents = frames.tangents;
  16598. this.normals = frames.normals;
  16599. this.binormals = frames.binormals;
  16600. // helper variables
  16601. var vertex = new Vector3();
  16602. var normal = new Vector3();
  16603. var uv = new Vector2();
  16604. var P = new Vector3();
  16605. var i, j;
  16606. // buffer
  16607. var vertices = [];
  16608. var normals = [];
  16609. var uvs = [];
  16610. var indices = [];
  16611. // create buffer data
  16612. generateBufferData();
  16613. // build geometry
  16614. this.setIndex( indices );
  16615. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16616. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16617. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16618. // functions
  16619. function generateBufferData() {
  16620. for ( i = 0; i < tubularSegments; i ++ ) {
  16621. generateSegment( i );
  16622. }
  16623. // if the geometry is not closed, generate the last row of vertices and normals
  16624. // at the regular position on the given path
  16625. //
  16626. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16627. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16628. // uvs are generated in a separate function.
  16629. // this makes it easy compute correct values for closed geometries
  16630. generateUVs();
  16631. // finally create faces
  16632. generateIndices();
  16633. }
  16634. function generateSegment( i ) {
  16635. // we use getPointAt to sample evenly distributed points from the given path
  16636. P = path.getPointAt( i / tubularSegments, P );
  16637. // retrieve corresponding normal and binormal
  16638. var N = frames.normals[ i ];
  16639. var B = frames.binormals[ i ];
  16640. // generate normals and vertices for the current segment
  16641. for ( j = 0; j <= radialSegments; j ++ ) {
  16642. var v = j / radialSegments * Math.PI * 2;
  16643. var sin = Math.sin( v );
  16644. var cos = - Math.cos( v );
  16645. // normal
  16646. normal.x = ( cos * N.x + sin * B.x );
  16647. normal.y = ( cos * N.y + sin * B.y );
  16648. normal.z = ( cos * N.z + sin * B.z );
  16649. normal.normalize();
  16650. normals.push( normal.x, normal.y, normal.z );
  16651. // vertex
  16652. vertex.x = P.x + radius * normal.x;
  16653. vertex.y = P.y + radius * normal.y;
  16654. vertex.z = P.z + radius * normal.z;
  16655. vertices.push( vertex.x, vertex.y, vertex.z );
  16656. }
  16657. }
  16658. function generateIndices() {
  16659. for ( j = 1; j <= tubularSegments; j ++ ) {
  16660. for ( i = 1; i <= radialSegments; i ++ ) {
  16661. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16662. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16663. var c = ( radialSegments + 1 ) * j + i;
  16664. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16665. // faces
  16666. indices.push( a, b, d );
  16667. indices.push( b, c, d );
  16668. }
  16669. }
  16670. }
  16671. function generateUVs() {
  16672. for ( i = 0; i <= tubularSegments; i ++ ) {
  16673. for ( j = 0; j <= radialSegments; j ++ ) {
  16674. uv.x = i / tubularSegments;
  16675. uv.y = j / radialSegments;
  16676. uvs.push( uv.x, uv.y );
  16677. }
  16678. }
  16679. }
  16680. }
  16681. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16682. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16683. TubeBufferGeometry.prototype.toJSON = function () {
  16684. var data = BufferGeometry.prototype.toJSON.call( this );
  16685. data.path = this.parameters.path.toJSON();
  16686. return data;
  16687. };
  16688. /**
  16689. * @author oosmoxiecode
  16690. * @author Mugen87 / https://github.com/Mugen87
  16691. *
  16692. * based on http://www.blackpawn.com/texts/pqtorus/
  16693. */
  16694. // TorusKnotGeometry
  16695. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16696. Geometry.call( this );
  16697. this.type = 'TorusKnotGeometry';
  16698. this.parameters = {
  16699. radius: radius,
  16700. tube: tube,
  16701. tubularSegments: tubularSegments,
  16702. radialSegments: radialSegments,
  16703. p: p,
  16704. q: q
  16705. };
  16706. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16707. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16708. this.mergeVertices();
  16709. }
  16710. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16711. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16712. // TorusKnotBufferGeometry
  16713. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16714. BufferGeometry.call( this );
  16715. this.type = 'TorusKnotBufferGeometry';
  16716. this.parameters = {
  16717. radius: radius,
  16718. tube: tube,
  16719. tubularSegments: tubularSegments,
  16720. radialSegments: radialSegments,
  16721. p: p,
  16722. q: q
  16723. };
  16724. radius = radius || 1;
  16725. tube = tube || 0.4;
  16726. tubularSegments = Math.floor( tubularSegments ) || 64;
  16727. radialSegments = Math.floor( radialSegments ) || 8;
  16728. p = p || 2;
  16729. q = q || 3;
  16730. // buffers
  16731. var indices = [];
  16732. var vertices = [];
  16733. var normals = [];
  16734. var uvs = [];
  16735. // helper variables
  16736. var i, j;
  16737. var vertex = new Vector3();
  16738. var normal = new Vector3();
  16739. var P1 = new Vector3();
  16740. var P2 = new Vector3();
  16741. var B = new Vector3();
  16742. var T = new Vector3();
  16743. var N = new Vector3();
  16744. // generate vertices, normals and uvs
  16745. for ( i = 0; i <= tubularSegments; ++ i ) {
  16746. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16747. var u = i / tubularSegments * p * Math.PI * 2;
  16748. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16749. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16750. calculatePositionOnCurve( u, p, q, radius, P1 );
  16751. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16752. // calculate orthonormal basis
  16753. T.subVectors( P2, P1 );
  16754. N.addVectors( P2, P1 );
  16755. B.crossVectors( T, N );
  16756. N.crossVectors( B, T );
  16757. // normalize B, N. T can be ignored, we don't use it
  16758. B.normalize();
  16759. N.normalize();
  16760. for ( j = 0; j <= radialSegments; ++ j ) {
  16761. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16762. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16763. var v = j / radialSegments * Math.PI * 2;
  16764. var cx = - tube * Math.cos( v );
  16765. var cy = tube * Math.sin( v );
  16766. // now calculate the final vertex position.
  16767. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16768. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16769. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16770. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16771. vertices.push( vertex.x, vertex.y, vertex.z );
  16772. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16773. normal.subVectors( vertex, P1 ).normalize();
  16774. normals.push( normal.x, normal.y, normal.z );
  16775. // uv
  16776. uvs.push( i / tubularSegments );
  16777. uvs.push( j / radialSegments );
  16778. }
  16779. }
  16780. // generate indices
  16781. for ( j = 1; j <= tubularSegments; j ++ ) {
  16782. for ( i = 1; i <= radialSegments; i ++ ) {
  16783. // indices
  16784. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16785. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16786. var c = ( radialSegments + 1 ) * j + i;
  16787. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16788. // faces
  16789. indices.push( a, b, d );
  16790. indices.push( b, c, d );
  16791. }
  16792. }
  16793. // build geometry
  16794. this.setIndex( indices );
  16795. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16796. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16797. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16798. // this function calculates the current position on the torus curve
  16799. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16800. var cu = Math.cos( u );
  16801. var su = Math.sin( u );
  16802. var quOverP = q / p * u;
  16803. var cs = Math.cos( quOverP );
  16804. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16805. position.y = radius * ( 2 + cs ) * su * 0.5;
  16806. position.z = radius * Math.sin( quOverP ) * 0.5;
  16807. }
  16808. }
  16809. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16810. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16811. /**
  16812. * @author oosmoxiecode
  16813. * @author mrdoob / http://mrdoob.com/
  16814. * @author Mugen87 / https://github.com/Mugen87
  16815. */
  16816. // TorusGeometry
  16817. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16818. Geometry.call( this );
  16819. this.type = 'TorusGeometry';
  16820. this.parameters = {
  16821. radius: radius,
  16822. tube: tube,
  16823. radialSegments: radialSegments,
  16824. tubularSegments: tubularSegments,
  16825. arc: arc
  16826. };
  16827. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16828. this.mergeVertices();
  16829. }
  16830. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16831. TorusGeometry.prototype.constructor = TorusGeometry;
  16832. // TorusBufferGeometry
  16833. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16834. BufferGeometry.call( this );
  16835. this.type = 'TorusBufferGeometry';
  16836. this.parameters = {
  16837. radius: radius,
  16838. tube: tube,
  16839. radialSegments: radialSegments,
  16840. tubularSegments: tubularSegments,
  16841. arc: arc
  16842. };
  16843. radius = radius || 1;
  16844. tube = tube || 0.4;
  16845. radialSegments = Math.floor( radialSegments ) || 8;
  16846. tubularSegments = Math.floor( tubularSegments ) || 6;
  16847. arc = arc || Math.PI * 2;
  16848. // buffers
  16849. var indices = [];
  16850. var vertices = [];
  16851. var normals = [];
  16852. var uvs = [];
  16853. // helper variables
  16854. var center = new Vector3();
  16855. var vertex = new Vector3();
  16856. var normal = new Vector3();
  16857. var j, i;
  16858. // generate vertices, normals and uvs
  16859. for ( j = 0; j <= radialSegments; j ++ ) {
  16860. for ( i = 0; i <= tubularSegments; i ++ ) {
  16861. var u = i / tubularSegments * arc;
  16862. var v = j / radialSegments * Math.PI * 2;
  16863. // vertex
  16864. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16865. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16866. vertex.z = tube * Math.sin( v );
  16867. vertices.push( vertex.x, vertex.y, vertex.z );
  16868. // normal
  16869. center.x = radius * Math.cos( u );
  16870. center.y = radius * Math.sin( u );
  16871. normal.subVectors( vertex, center ).normalize();
  16872. normals.push( normal.x, normal.y, normal.z );
  16873. // uv
  16874. uvs.push( i / tubularSegments );
  16875. uvs.push( j / radialSegments );
  16876. }
  16877. }
  16878. // generate indices
  16879. for ( j = 1; j <= radialSegments; j ++ ) {
  16880. for ( i = 1; i <= tubularSegments; i ++ ) {
  16881. // indices
  16882. var a = ( tubularSegments + 1 ) * j + i - 1;
  16883. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16884. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16885. var d = ( tubularSegments + 1 ) * j + i;
  16886. // faces
  16887. indices.push( a, b, d );
  16888. indices.push( b, c, d );
  16889. }
  16890. }
  16891. // build geometry
  16892. this.setIndex( indices );
  16893. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16894. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16895. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16896. }
  16897. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16898. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16899. /**
  16900. * @author Mugen87 / https://github.com/Mugen87
  16901. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16902. */
  16903. var Earcut = {
  16904. triangulate: function ( data, holeIndices, dim ) {
  16905. dim = dim || 2;
  16906. var hasHoles = holeIndices && holeIndices.length,
  16907. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16908. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16909. triangles = [];
  16910. if ( ! outerNode ) return triangles;
  16911. var minX, minY, maxX, maxY, x, y, invSize;
  16912. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16913. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16914. if ( data.length > 80 * dim ) {
  16915. minX = maxX = data[ 0 ];
  16916. minY = maxY = data[ 1 ];
  16917. for ( var i = dim; i < outerLen; i += dim ) {
  16918. x = data[ i ];
  16919. y = data[ i + 1 ];
  16920. if ( x < minX ) minX = x;
  16921. if ( y < minY ) minY = y;
  16922. if ( x > maxX ) maxX = x;
  16923. if ( y > maxY ) maxY = y;
  16924. }
  16925. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16926. invSize = Math.max( maxX - minX, maxY - minY );
  16927. invSize = invSize !== 0 ? 1 / invSize : 0;
  16928. }
  16929. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16930. return triangles;
  16931. }
  16932. };
  16933. // create a circular doubly linked list from polygon points in the specified winding order
  16934. function linkedList( data, start, end, dim, clockwise ) {
  16935. var i, last;
  16936. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16937. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16938. } else {
  16939. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16940. }
  16941. if ( last && equals( last, last.next ) ) {
  16942. removeNode( last );
  16943. last = last.next;
  16944. }
  16945. return last;
  16946. }
  16947. // eliminate colinear or duplicate points
  16948. function filterPoints( start, end ) {
  16949. if ( ! start ) return start;
  16950. if ( ! end ) end = start;
  16951. var p = start, again;
  16952. do {
  16953. again = false;
  16954. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16955. removeNode( p );
  16956. p = end = p.prev;
  16957. if ( p === p.next ) break;
  16958. again = true;
  16959. } else {
  16960. p = p.next;
  16961. }
  16962. } while ( again || p !== end );
  16963. return end;
  16964. }
  16965. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16966. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16967. if ( ! ear ) return;
  16968. // interlink polygon nodes in z-order
  16969. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16970. var stop = ear, prev, next;
  16971. // iterate through ears, slicing them one by one
  16972. while ( ear.prev !== ear.next ) {
  16973. prev = ear.prev;
  16974. next = ear.next;
  16975. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16976. // cut off the triangle
  16977. triangles.push( prev.i / dim );
  16978. triangles.push( ear.i / dim );
  16979. triangles.push( next.i / dim );
  16980. removeNode( ear );
  16981. // skipping the next vertice leads to less sliver triangles
  16982. ear = next.next;
  16983. stop = next.next;
  16984. continue;
  16985. }
  16986. ear = next;
  16987. // if we looped through the whole remaining polygon and can't find any more ears
  16988. if ( ear === stop ) {
  16989. // try filtering points and slicing again
  16990. if ( ! pass ) {
  16991. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16992. // if this didn't work, try curing all small self-intersections locally
  16993. } else if ( pass === 1 ) {
  16994. ear = cureLocalIntersections( ear, triangles, dim );
  16995. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16996. // as a last resort, try splitting the remaining polygon into two
  16997. } else if ( pass === 2 ) {
  16998. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16999. }
  17000. break;
  17001. }
  17002. }
  17003. }
  17004. // check whether a polygon node forms a valid ear with adjacent nodes
  17005. function isEar( ear ) {
  17006. var a = ear.prev,
  17007. b = ear,
  17008. c = ear.next;
  17009. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17010. // now make sure we don't have other points inside the potential ear
  17011. var p = ear.next.next;
  17012. while ( p !== ear.prev ) {
  17013. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) {
  17014. return false;
  17015. }
  17016. p = p.next;
  17017. }
  17018. return true;
  17019. }
  17020. function isEarHashed( ear, minX, minY, invSize ) {
  17021. var a = ear.prev,
  17022. b = ear,
  17023. c = ear.next;
  17024. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17025. // triangle bbox; min & max are calculated like this for speed
  17026. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17027. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17028. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17029. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17030. // z-order range for the current triangle bbox;
  17031. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17032. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17033. // first look for points inside the triangle in increasing z-order
  17034. var p = ear.nextZ;
  17035. while ( p && p.z <= maxZ ) {
  17036. if ( p !== ear.prev && p !== ear.next &&
  17037. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17038. area( p.prev, p, p.next ) >= 0 ) return false;
  17039. p = p.nextZ;
  17040. }
  17041. // then look for points in decreasing z-order
  17042. p = ear.prevZ;
  17043. while ( p && p.z >= minZ ) {
  17044. if ( p !== ear.prev && p !== ear.next &&
  17045. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17046. area( p.prev, p, p.next ) >= 0 ) return false;
  17047. p = p.prevZ;
  17048. }
  17049. return true;
  17050. }
  17051. // go through all polygon nodes and cure small local self-intersections
  17052. function cureLocalIntersections( start, triangles, dim ) {
  17053. var p = start;
  17054. do {
  17055. var a = p.prev, b = p.next.next;
  17056. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17057. triangles.push( a.i / dim );
  17058. triangles.push( p.i / dim );
  17059. triangles.push( b.i / dim );
  17060. // remove two nodes involved
  17061. removeNode( p );
  17062. removeNode( p.next );
  17063. p = start = b;
  17064. }
  17065. p = p.next;
  17066. } while ( p !== start );
  17067. return p;
  17068. }
  17069. // try splitting polygon into two and triangulate them independently
  17070. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17071. // look for a valid diagonal that divides the polygon into two
  17072. var a = start;
  17073. do {
  17074. var b = a.next.next;
  17075. while ( b !== a.prev ) {
  17076. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17077. // split the polygon in two by the diagonal
  17078. var c = splitPolygon( a, b );
  17079. // filter colinear points around the cuts
  17080. a = filterPoints( a, a.next );
  17081. c = filterPoints( c, c.next );
  17082. // run earcut on each half
  17083. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17084. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17085. return;
  17086. }
  17087. b = b.next;
  17088. }
  17089. a = a.next;
  17090. } while ( a !== start );
  17091. }
  17092. // link every hole into the outer loop, producing a single-ring polygon without holes
  17093. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17094. var queue = [], i, len, start, end, list;
  17095. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17096. start = holeIndices[ i ] * dim;
  17097. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17098. list = linkedList( data, start, end, dim, false );
  17099. if ( list === list.next ) list.steiner = true;
  17100. queue.push( getLeftmost( list ) );
  17101. }
  17102. queue.sort( compareX );
  17103. // process holes from left to right
  17104. for ( i = 0; i < queue.length; i ++ ) {
  17105. eliminateHole( queue[ i ], outerNode );
  17106. outerNode = filterPoints( outerNode, outerNode.next );
  17107. }
  17108. return outerNode;
  17109. }
  17110. function compareX( a, b ) {
  17111. return a.x - b.x;
  17112. }
  17113. // find a bridge between vertices that connects hole with an outer ring and and link it
  17114. function eliminateHole( hole, outerNode ) {
  17115. outerNode = findHoleBridge( hole, outerNode );
  17116. if ( outerNode ) {
  17117. var b = splitPolygon( outerNode, hole );
  17118. filterPoints( b, b.next );
  17119. }
  17120. }
  17121. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17122. function findHoleBridge( hole, outerNode ) {
  17123. var p = outerNode,
  17124. hx = hole.x,
  17125. hy = hole.y,
  17126. qx = - Infinity,
  17127. m;
  17128. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17129. // segment's endpoint with lesser x will be potential connection point
  17130. do {
  17131. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17132. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17133. if ( x <= hx && x > qx ) {
  17134. qx = x;
  17135. if ( x === hx ) {
  17136. if ( hy === p.y ) return p;
  17137. if ( hy === p.next.y ) return p.next;
  17138. }
  17139. m = p.x < p.next.x ? p : p.next;
  17140. }
  17141. }
  17142. p = p.next;
  17143. } while ( p !== outerNode );
  17144. if ( ! m ) return null;
  17145. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17146. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17147. // if there are no points found, we have a valid connection;
  17148. // otherwise choose the point of the minimum angle with the ray as connection point
  17149. var stop = m,
  17150. mx = m.x,
  17151. my = m.y,
  17152. tanMin = Infinity,
  17153. tan;
  17154. p = m.next;
  17155. while ( p !== stop ) {
  17156. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17157. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17158. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17159. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17160. m = p;
  17161. tanMin = tan;
  17162. }
  17163. }
  17164. p = p.next;
  17165. }
  17166. return m;
  17167. }
  17168. // interlink polygon nodes in z-order
  17169. function indexCurve( start, minX, minY, invSize ) {
  17170. var p = start;
  17171. do {
  17172. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17173. p.prevZ = p.prev;
  17174. p.nextZ = p.next;
  17175. p = p.next;
  17176. } while ( p !== start );
  17177. p.prevZ.nextZ = null;
  17178. p.prevZ = null;
  17179. sortLinked( p );
  17180. }
  17181. // Simon Tatham's linked list merge sort algorithm
  17182. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17183. function sortLinked( list ) {
  17184. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17185. do {
  17186. p = list;
  17187. list = null;
  17188. tail = null;
  17189. numMerges = 0;
  17190. while ( p ) {
  17191. numMerges ++;
  17192. q = p;
  17193. pSize = 0;
  17194. for ( i = 0; i < inSize; i ++ ) {
  17195. pSize ++;
  17196. q = q.nextZ;
  17197. if ( ! q ) break;
  17198. }
  17199. qSize = inSize;
  17200. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17201. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17202. e = p;
  17203. p = p.nextZ;
  17204. pSize --;
  17205. } else {
  17206. e = q;
  17207. q = q.nextZ;
  17208. qSize --;
  17209. }
  17210. if ( tail ) tail.nextZ = e;
  17211. else list = e;
  17212. e.prevZ = tail;
  17213. tail = e;
  17214. }
  17215. p = q;
  17216. }
  17217. tail.nextZ = null;
  17218. inSize *= 2;
  17219. } while ( numMerges > 1 );
  17220. return list;
  17221. }
  17222. // z-order of a point given coords and inverse of the longer side of data bbox
  17223. function zOrder( x, y, minX, minY, invSize ) {
  17224. // coords are transformed into non-negative 15-bit integer range
  17225. x = 32767 * ( x - minX ) * invSize;
  17226. y = 32767 * ( y - minY ) * invSize;
  17227. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17228. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17229. x = ( x | ( x << 2 ) ) & 0x33333333;
  17230. x = ( x | ( x << 1 ) ) & 0x55555555;
  17231. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17232. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17233. y = ( y | ( y << 2 ) ) & 0x33333333;
  17234. y = ( y | ( y << 1 ) ) & 0x55555555;
  17235. return x | ( y << 1 );
  17236. }
  17237. // find the leftmost node of a polygon ring
  17238. function getLeftmost( start ) {
  17239. var p = start, leftmost = start;
  17240. do {
  17241. if ( p.x < leftmost.x ) leftmost = p;
  17242. p = p.next;
  17243. } while ( p !== start );
  17244. return leftmost;
  17245. }
  17246. // check if a point lies within a convex triangle
  17247. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17248. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17249. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17250. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17251. }
  17252. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17253. function isValidDiagonal( a, b ) {
  17254. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17255. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17256. }
  17257. // signed area of a triangle
  17258. function area( p, q, r ) {
  17259. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17260. }
  17261. // check if two points are equal
  17262. function equals( p1, p2 ) {
  17263. return p1.x === p2.x && p1.y === p2.y;
  17264. }
  17265. // check if two segments intersect
  17266. function intersects( p1, q1, p2, q2 ) {
  17267. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17268. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17269. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17270. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17271. }
  17272. // check if a polygon diagonal intersects any polygon segments
  17273. function intersectsPolygon( a, b ) {
  17274. var p = a;
  17275. do {
  17276. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17277. intersects( p, p.next, a, b ) ) {
  17278. return true;
  17279. }
  17280. p = p.next;
  17281. } while ( p !== a );
  17282. return false;
  17283. }
  17284. // check if a polygon diagonal is locally inside the polygon
  17285. function locallyInside( a, b ) {
  17286. return area( a.prev, a, a.next ) < 0 ?
  17287. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17288. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17289. }
  17290. // check if the middle point of a polygon diagonal is inside the polygon
  17291. function middleInside( a, b ) {
  17292. var p = a,
  17293. inside = false,
  17294. px = ( a.x + b.x ) / 2,
  17295. py = ( a.y + b.y ) / 2;
  17296. do {
  17297. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17298. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17299. inside = ! inside;
  17300. }
  17301. p = p.next;
  17302. } while ( p !== a );
  17303. return inside;
  17304. }
  17305. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17306. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17307. function splitPolygon( a, b ) {
  17308. var a2 = new Node( a.i, a.x, a.y ),
  17309. b2 = new Node( b.i, b.x, b.y ),
  17310. an = a.next,
  17311. bp = b.prev;
  17312. a.next = b;
  17313. b.prev = a;
  17314. a2.next = an;
  17315. an.prev = a2;
  17316. b2.next = a2;
  17317. a2.prev = b2;
  17318. bp.next = b2;
  17319. b2.prev = bp;
  17320. return b2;
  17321. }
  17322. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17323. function insertNode( i, x, y, last ) {
  17324. var p = new Node( i, x, y );
  17325. if ( ! last ) {
  17326. p.prev = p;
  17327. p.next = p;
  17328. } else {
  17329. p.next = last.next;
  17330. p.prev = last;
  17331. last.next.prev = p;
  17332. last.next = p;
  17333. }
  17334. return p;
  17335. }
  17336. function removeNode( p ) {
  17337. p.next.prev = p.prev;
  17338. p.prev.next = p.next;
  17339. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17340. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17341. }
  17342. function Node( i, x, y ) {
  17343. // vertice index in coordinates array
  17344. this.i = i;
  17345. // vertex coordinates
  17346. this.x = x;
  17347. this.y = y;
  17348. // previous and next vertice nodes in a polygon ring
  17349. this.prev = null;
  17350. this.next = null;
  17351. // z-order curve value
  17352. this.z = null;
  17353. // previous and next nodes in z-order
  17354. this.prevZ = null;
  17355. this.nextZ = null;
  17356. // indicates whether this is a steiner point
  17357. this.steiner = false;
  17358. }
  17359. function signedArea( data, start, end, dim ) {
  17360. var sum = 0;
  17361. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17362. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17363. j = i;
  17364. }
  17365. return sum;
  17366. }
  17367. /**
  17368. * @author zz85 / http://www.lab4games.net/zz85/blog
  17369. */
  17370. var ShapeUtils = {
  17371. // calculate area of the contour polygon
  17372. area: function ( contour ) {
  17373. var n = contour.length;
  17374. var a = 0.0;
  17375. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17376. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17377. }
  17378. return a * 0.5;
  17379. },
  17380. isClockWise: function ( pts ) {
  17381. return ShapeUtils.area( pts ) < 0;
  17382. },
  17383. triangulateShape: function ( contour, holes ) {
  17384. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17385. var holeIndices = []; // array of hole indices
  17386. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17387. removeDupEndPts( contour );
  17388. addContour( vertices, contour );
  17389. //
  17390. var holeIndex = contour.length;
  17391. holes.forEach( removeDupEndPts );
  17392. for ( var i = 0; i < holes.length; i ++ ) {
  17393. holeIndices.push( holeIndex );
  17394. holeIndex += holes[ i ].length;
  17395. addContour( vertices, holes[ i ] );
  17396. }
  17397. //
  17398. var triangles = Earcut.triangulate( vertices, holeIndices );
  17399. //
  17400. for ( var i = 0; i < triangles.length; i += 3 ) {
  17401. faces.push( triangles.slice( i, i + 3 ) );
  17402. }
  17403. return faces;
  17404. }
  17405. };
  17406. function removeDupEndPts( points ) {
  17407. var l = points.length;
  17408. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17409. points.pop();
  17410. }
  17411. }
  17412. function addContour( vertices, contour ) {
  17413. for ( var i = 0; i < contour.length; i ++ ) {
  17414. vertices.push( contour[ i ].x );
  17415. vertices.push( contour[ i ].y );
  17416. }
  17417. }
  17418. /**
  17419. * @author zz85 / http://www.lab4games.net/zz85/blog
  17420. *
  17421. * Creates extruded geometry from a path shape.
  17422. *
  17423. * parameters = {
  17424. *
  17425. * curveSegments: <int>, // number of points on the curves
  17426. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17427. * depth: <float>, // Depth to extrude the shape
  17428. *
  17429. * bevelEnabled: <bool>, // turn on bevel
  17430. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17431. * bevelSize: <float>, // how far from shape outline is bevel
  17432. * bevelSegments: <int>, // number of bevel layers
  17433. *
  17434. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17435. *
  17436. * UVGenerator: <Object> // object that provides UV generator functions
  17437. *
  17438. * }
  17439. */
  17440. // ExtrudeGeometry
  17441. function ExtrudeGeometry( shapes, options ) {
  17442. Geometry.call( this );
  17443. this.type = 'ExtrudeGeometry';
  17444. this.parameters = {
  17445. shapes: shapes,
  17446. options: options
  17447. };
  17448. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17449. this.mergeVertices();
  17450. }
  17451. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17452. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17453. ExtrudeGeometry.prototype.toJSON = function () {
  17454. var data = Geometry.prototype.toJSON.call( this );
  17455. var shapes = this.parameters.shapes;
  17456. var options = this.parameters.options;
  17457. return toJSON( shapes, options, data );
  17458. };
  17459. // ExtrudeBufferGeometry
  17460. function ExtrudeBufferGeometry( shapes, options ) {
  17461. BufferGeometry.call( this );
  17462. this.type = 'ExtrudeBufferGeometry';
  17463. this.parameters = {
  17464. shapes: shapes,
  17465. options: options
  17466. };
  17467. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17468. var scope = this;
  17469. var verticesArray = [];
  17470. var uvArray = [];
  17471. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17472. var shape = shapes[ i ];
  17473. addShape( shape );
  17474. }
  17475. // build geometry
  17476. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17477. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17478. this.computeVertexNormals();
  17479. // functions
  17480. function addShape( shape ) {
  17481. var placeholder = [];
  17482. // options
  17483. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17484. var steps = options.steps !== undefined ? options.steps : 1;
  17485. var depth = options.depth !== undefined ? options.depth : 100;
  17486. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17487. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17488. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17489. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17490. var extrudePath = options.extrudePath;
  17491. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17492. // deprecated options
  17493. if ( options.amount !== undefined ) {
  17494. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17495. depth = options.amount;
  17496. }
  17497. //
  17498. var extrudePts, extrudeByPath = false;
  17499. var splineTube, binormal, normal, position2;
  17500. if ( extrudePath ) {
  17501. extrudePts = extrudePath.getSpacedPoints( steps );
  17502. extrudeByPath = true;
  17503. bevelEnabled = false; // bevels not supported for path extrusion
  17504. // SETUP TNB variables
  17505. // TODO1 - have a .isClosed in spline?
  17506. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17507. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17508. binormal = new Vector3();
  17509. normal = new Vector3();
  17510. position2 = new Vector3();
  17511. }
  17512. // Safeguards if bevels are not enabled
  17513. if ( ! bevelEnabled ) {
  17514. bevelSegments = 0;
  17515. bevelThickness = 0;
  17516. bevelSize = 0;
  17517. }
  17518. // Variables initialization
  17519. var ahole, h, hl; // looping of holes
  17520. var shapePoints = shape.extractPoints( curveSegments );
  17521. var vertices = shapePoints.shape;
  17522. var holes = shapePoints.holes;
  17523. var reverse = ! ShapeUtils.isClockWise( vertices );
  17524. if ( reverse ) {
  17525. vertices = vertices.reverse();
  17526. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17527. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17528. ahole = holes[ h ];
  17529. if ( ShapeUtils.isClockWise( ahole ) ) {
  17530. holes[ h ] = ahole.reverse();
  17531. }
  17532. }
  17533. }
  17534. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17535. /* Vertices */
  17536. var contour = vertices; // vertices has all points but contour has only points of circumference
  17537. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17538. ahole = holes[ h ];
  17539. vertices = vertices.concat( ahole );
  17540. }
  17541. function scalePt2( pt, vec, size ) {
  17542. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17543. return vec.clone().multiplyScalar( size ).add( pt );
  17544. }
  17545. var b, bs, t, z,
  17546. vert, vlen = vertices.length,
  17547. face, flen = faces.length;
  17548. // Find directions for point movement
  17549. function getBevelVec( inPt, inPrev, inNext ) {
  17550. // computes for inPt the corresponding point inPt' on a new contour
  17551. // shifted by 1 unit (length of normalized vector) to the left
  17552. // if we walk along contour clockwise, this new contour is outside the old one
  17553. //
  17554. // inPt' is the intersection of the two lines parallel to the two
  17555. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17556. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17557. // good reading for geometry algorithms (here: line-line intersection)
  17558. // http://geomalgorithms.com/a05-_intersect-1.html
  17559. var v_prev_x = inPt.x - inPrev.x,
  17560. v_prev_y = inPt.y - inPrev.y;
  17561. var v_next_x = inNext.x - inPt.x,
  17562. v_next_y = inNext.y - inPt.y;
  17563. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17564. // check for collinear edges
  17565. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17566. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17567. // not collinear
  17568. // length of vectors for normalizing
  17569. var v_prev_len = Math.sqrt( v_prev_lensq );
  17570. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17571. // shift adjacent points by unit vectors to the left
  17572. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17573. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17574. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17575. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17576. // scaling factor for v_prev to intersection point
  17577. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17578. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17579. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17580. // vector from inPt to intersection point
  17581. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17582. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17583. // Don't normalize!, otherwise sharp corners become ugly
  17584. // but prevent crazy spikes
  17585. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17586. if ( v_trans_lensq <= 2 ) {
  17587. return new Vector2( v_trans_x, v_trans_y );
  17588. } else {
  17589. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17590. }
  17591. } else {
  17592. // handle special case of collinear edges
  17593. var direction_eq = false; // assumes: opposite
  17594. if ( v_prev_x > Number.EPSILON ) {
  17595. if ( v_next_x > Number.EPSILON ) {
  17596. direction_eq = true;
  17597. }
  17598. } else {
  17599. if ( v_prev_x < - Number.EPSILON ) {
  17600. if ( v_next_x < - Number.EPSILON ) {
  17601. direction_eq = true;
  17602. }
  17603. } else {
  17604. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17605. direction_eq = true;
  17606. }
  17607. }
  17608. }
  17609. if ( direction_eq ) {
  17610. // console.log("Warning: lines are a straight sequence");
  17611. v_trans_x = - v_prev_y;
  17612. v_trans_y = v_prev_x;
  17613. shrink_by = Math.sqrt( v_prev_lensq );
  17614. } else {
  17615. // console.log("Warning: lines are a straight spike");
  17616. v_trans_x = v_prev_x;
  17617. v_trans_y = v_prev_y;
  17618. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17619. }
  17620. }
  17621. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17622. }
  17623. var contourMovements = [];
  17624. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17625. if ( j === il ) j = 0;
  17626. if ( k === il ) k = 0;
  17627. // (j)---(i)---(k)
  17628. // console.log('i,j,k', i, j , k)
  17629. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17630. }
  17631. var holesMovements = [],
  17632. oneHoleMovements, verticesMovements = contourMovements.concat();
  17633. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17634. ahole = holes[ h ];
  17635. oneHoleMovements = [];
  17636. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17637. if ( j === il ) j = 0;
  17638. if ( k === il ) k = 0;
  17639. // (j)---(i)---(k)
  17640. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17641. }
  17642. holesMovements.push( oneHoleMovements );
  17643. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17644. }
  17645. // Loop bevelSegments, 1 for the front, 1 for the back
  17646. for ( b = 0; b < bevelSegments; b ++ ) {
  17647. //for ( b = bevelSegments; b > 0; b -- ) {
  17648. t = b / bevelSegments;
  17649. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17650. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17651. // contract shape
  17652. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17653. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17654. v( vert.x, vert.y, - z );
  17655. }
  17656. // expand holes
  17657. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17658. ahole = holes[ h ];
  17659. oneHoleMovements = holesMovements[ h ];
  17660. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17661. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17662. v( vert.x, vert.y, - z );
  17663. }
  17664. }
  17665. }
  17666. bs = bevelSize;
  17667. // Back facing vertices
  17668. for ( i = 0; i < vlen; i ++ ) {
  17669. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17670. if ( ! extrudeByPath ) {
  17671. v( vert.x, vert.y, 0 );
  17672. } else {
  17673. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17674. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17675. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17676. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17677. v( position2.x, position2.y, position2.z );
  17678. }
  17679. }
  17680. // Add stepped vertices...
  17681. // Including front facing vertices
  17682. var s;
  17683. for ( s = 1; s <= steps; s ++ ) {
  17684. for ( i = 0; i < vlen; i ++ ) {
  17685. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17686. if ( ! extrudeByPath ) {
  17687. v( vert.x, vert.y, depth / steps * s );
  17688. } else {
  17689. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17690. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17691. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17692. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17693. v( position2.x, position2.y, position2.z );
  17694. }
  17695. }
  17696. }
  17697. // Add bevel segments planes
  17698. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17699. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17700. t = b / bevelSegments;
  17701. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17702. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17703. // contract shape
  17704. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17705. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17706. v( vert.x, vert.y, depth + z );
  17707. }
  17708. // expand holes
  17709. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17710. ahole = holes[ h ];
  17711. oneHoleMovements = holesMovements[ h ];
  17712. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17713. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17714. if ( ! extrudeByPath ) {
  17715. v( vert.x, vert.y, depth + z );
  17716. } else {
  17717. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17718. }
  17719. }
  17720. }
  17721. }
  17722. /* Faces */
  17723. // Top and bottom faces
  17724. buildLidFaces();
  17725. // Sides faces
  17726. buildSideFaces();
  17727. ///// Internal functions
  17728. function buildLidFaces() {
  17729. var start = verticesArray.length / 3;
  17730. if ( bevelEnabled ) {
  17731. var layer = 0; // steps + 1
  17732. var offset = vlen * layer;
  17733. // Bottom faces
  17734. for ( i = 0; i < flen; i ++ ) {
  17735. face = faces[ i ];
  17736. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17737. }
  17738. layer = steps + bevelSegments * 2;
  17739. offset = vlen * layer;
  17740. // Top faces
  17741. for ( i = 0; i < flen; i ++ ) {
  17742. face = faces[ i ];
  17743. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17744. }
  17745. } else {
  17746. // Bottom faces
  17747. for ( i = 0; i < flen; i ++ ) {
  17748. face = faces[ i ];
  17749. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17750. }
  17751. // Top faces
  17752. for ( i = 0; i < flen; i ++ ) {
  17753. face = faces[ i ];
  17754. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17755. }
  17756. }
  17757. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17758. }
  17759. // Create faces for the z-sides of the shape
  17760. function buildSideFaces() {
  17761. var start = verticesArray.length / 3;
  17762. var layeroffset = 0;
  17763. sidewalls( contour, layeroffset );
  17764. layeroffset += contour.length;
  17765. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17766. ahole = holes[ h ];
  17767. sidewalls( ahole, layeroffset );
  17768. //, true
  17769. layeroffset += ahole.length;
  17770. }
  17771. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17772. }
  17773. function sidewalls( contour, layeroffset ) {
  17774. var j, k;
  17775. i = contour.length;
  17776. while ( -- i >= 0 ) {
  17777. j = i;
  17778. k = i - 1;
  17779. if ( k < 0 ) k = contour.length - 1;
  17780. //console.log('b', i,j, i-1, k,vertices.length);
  17781. var s = 0,
  17782. sl = steps + bevelSegments * 2;
  17783. for ( s = 0; s < sl; s ++ ) {
  17784. var slen1 = vlen * s;
  17785. var slen2 = vlen * ( s + 1 );
  17786. var a = layeroffset + j + slen1,
  17787. b = layeroffset + k + slen1,
  17788. c = layeroffset + k + slen2,
  17789. d = layeroffset + j + slen2;
  17790. f4( a, b, c, d );
  17791. }
  17792. }
  17793. }
  17794. function v( x, y, z ) {
  17795. placeholder.push( x );
  17796. placeholder.push( y );
  17797. placeholder.push( z );
  17798. }
  17799. function f3( a, b, c ) {
  17800. addVertex( a );
  17801. addVertex( b );
  17802. addVertex( c );
  17803. var nextIndex = verticesArray.length / 3;
  17804. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17805. addUV( uvs[ 0 ] );
  17806. addUV( uvs[ 1 ] );
  17807. addUV( uvs[ 2 ] );
  17808. }
  17809. function f4( a, b, c, d ) {
  17810. addVertex( a );
  17811. addVertex( b );
  17812. addVertex( d );
  17813. addVertex( b );
  17814. addVertex( c );
  17815. addVertex( d );
  17816. var nextIndex = verticesArray.length / 3;
  17817. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17818. addUV( uvs[ 0 ] );
  17819. addUV( uvs[ 1 ] );
  17820. addUV( uvs[ 3 ] );
  17821. addUV( uvs[ 1 ] );
  17822. addUV( uvs[ 2 ] );
  17823. addUV( uvs[ 3 ] );
  17824. }
  17825. function addVertex( index ) {
  17826. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17827. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17828. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17829. }
  17830. function addUV( vector2 ) {
  17831. uvArray.push( vector2.x );
  17832. uvArray.push( vector2.y );
  17833. }
  17834. }
  17835. }
  17836. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17837. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17838. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17839. var data = BufferGeometry.prototype.toJSON.call( this );
  17840. var shapes = this.parameters.shapes;
  17841. var options = this.parameters.options;
  17842. return toJSON( shapes, options, data );
  17843. };
  17844. //
  17845. var WorldUVGenerator = {
  17846. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17847. var a_x = vertices[ indexA * 3 ];
  17848. var a_y = vertices[ indexA * 3 + 1 ];
  17849. var b_x = vertices[ indexB * 3 ];
  17850. var b_y = vertices[ indexB * 3 + 1 ];
  17851. var c_x = vertices[ indexC * 3 ];
  17852. var c_y = vertices[ indexC * 3 + 1 ];
  17853. return [
  17854. new Vector2( a_x, a_y ),
  17855. new Vector2( b_x, b_y ),
  17856. new Vector2( c_x, c_y )
  17857. ];
  17858. },
  17859. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17860. var a_x = vertices[ indexA * 3 ];
  17861. var a_y = vertices[ indexA * 3 + 1 ];
  17862. var a_z = vertices[ indexA * 3 + 2 ];
  17863. var b_x = vertices[ indexB * 3 ];
  17864. var b_y = vertices[ indexB * 3 + 1 ];
  17865. var b_z = vertices[ indexB * 3 + 2 ];
  17866. var c_x = vertices[ indexC * 3 ];
  17867. var c_y = vertices[ indexC * 3 + 1 ];
  17868. var c_z = vertices[ indexC * 3 + 2 ];
  17869. var d_x = vertices[ indexD * 3 ];
  17870. var d_y = vertices[ indexD * 3 + 1 ];
  17871. var d_z = vertices[ indexD * 3 + 2 ];
  17872. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17873. return [
  17874. new Vector2( a_x, 1 - a_z ),
  17875. new Vector2( b_x, 1 - b_z ),
  17876. new Vector2( c_x, 1 - c_z ),
  17877. new Vector2( d_x, 1 - d_z )
  17878. ];
  17879. } else {
  17880. return [
  17881. new Vector2( a_y, 1 - a_z ),
  17882. new Vector2( b_y, 1 - b_z ),
  17883. new Vector2( c_y, 1 - c_z ),
  17884. new Vector2( d_y, 1 - d_z )
  17885. ];
  17886. }
  17887. }
  17888. };
  17889. function toJSON( shapes, options, data ) {
  17890. //
  17891. data.shapes = [];
  17892. if ( Array.isArray( shapes ) ) {
  17893. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17894. var shape = shapes[ i ];
  17895. data.shapes.push( shape.uuid );
  17896. }
  17897. } else {
  17898. data.shapes.push( shapes.uuid );
  17899. }
  17900. //
  17901. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17902. return data;
  17903. }
  17904. /**
  17905. * @author zz85 / http://www.lab4games.net/zz85/blog
  17906. * @author alteredq / http://alteredqualia.com/
  17907. *
  17908. * Text = 3D Text
  17909. *
  17910. * parameters = {
  17911. * font: <THREE.Font>, // font
  17912. *
  17913. * size: <float>, // size of the text
  17914. * height: <float>, // thickness to extrude text
  17915. * curveSegments: <int>, // number of points on the curves
  17916. *
  17917. * bevelEnabled: <bool>, // turn on bevel
  17918. * bevelThickness: <float>, // how deep into text bevel goes
  17919. * bevelSize: <float> // how far from text outline is bevel
  17920. * }
  17921. */
  17922. // TextGeometry
  17923. function TextGeometry( text, parameters ) {
  17924. Geometry.call( this );
  17925. this.type = 'TextGeometry';
  17926. this.parameters = {
  17927. text: text,
  17928. parameters: parameters
  17929. };
  17930. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17931. this.mergeVertices();
  17932. }
  17933. TextGeometry.prototype = Object.create( Geometry.prototype );
  17934. TextGeometry.prototype.constructor = TextGeometry;
  17935. // TextBufferGeometry
  17936. function TextBufferGeometry( text, parameters ) {
  17937. parameters = parameters || {};
  17938. var font = parameters.font;
  17939. if ( ! ( font && font.isFont ) ) {
  17940. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17941. return new Geometry();
  17942. }
  17943. var shapes = font.generateShapes( text, parameters.size );
  17944. // translate parameters to ExtrudeGeometry API
  17945. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17946. // defaults
  17947. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17948. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17949. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17950. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17951. this.type = 'TextBufferGeometry';
  17952. }
  17953. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17954. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17955. /**
  17956. * @author mrdoob / http://mrdoob.com/
  17957. * @author benaadams / https://twitter.com/ben_a_adams
  17958. * @author Mugen87 / https://github.com/Mugen87
  17959. */
  17960. // SphereGeometry
  17961. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17962. Geometry.call( this );
  17963. this.type = 'SphereGeometry';
  17964. this.parameters = {
  17965. radius: radius,
  17966. widthSegments: widthSegments,
  17967. heightSegments: heightSegments,
  17968. phiStart: phiStart,
  17969. phiLength: phiLength,
  17970. thetaStart: thetaStart,
  17971. thetaLength: thetaLength
  17972. };
  17973. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17974. this.mergeVertices();
  17975. }
  17976. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17977. SphereGeometry.prototype.constructor = SphereGeometry;
  17978. // SphereBufferGeometry
  17979. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17980. BufferGeometry.call( this );
  17981. this.type = 'SphereBufferGeometry';
  17982. this.parameters = {
  17983. radius: radius,
  17984. widthSegments: widthSegments,
  17985. heightSegments: heightSegments,
  17986. phiStart: phiStart,
  17987. phiLength: phiLength,
  17988. thetaStart: thetaStart,
  17989. thetaLength: thetaLength
  17990. };
  17991. radius = radius || 1;
  17992. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17993. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17994. phiStart = phiStart !== undefined ? phiStart : 0;
  17995. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17996. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17997. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17998. var thetaEnd = thetaStart + thetaLength;
  17999. var ix, iy;
  18000. var index = 0;
  18001. var grid = [];
  18002. var vertex = new Vector3();
  18003. var normal = new Vector3();
  18004. // buffers
  18005. var indices = [];
  18006. var vertices = [];
  18007. var normals = [];
  18008. var uvs = [];
  18009. // generate vertices, normals and uvs
  18010. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18011. var verticesRow = [];
  18012. var v = iy / heightSegments;
  18013. // special case for the poles
  18014. var uOffset = ( iy == 0 ) ? 0.5 / widthSegments : ( ( iy == heightSegments ) ? - 0.5 / widthSegments : 0 );
  18015. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18016. var u = ix / widthSegments;
  18017. // vertex
  18018. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18019. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18020. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18021. vertices.push( vertex.x, vertex.y, vertex.z );
  18022. // normal
  18023. normal.copy( vertex ).normalize();
  18024. normals.push( normal.x, normal.y, normal.z );
  18025. // uv
  18026. uvs.push( u + uOffset, 1 - v );
  18027. verticesRow.push( index ++ );
  18028. }
  18029. grid.push( verticesRow );
  18030. }
  18031. // indices
  18032. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18033. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18034. var a = grid[ iy ][ ix + 1 ];
  18035. var b = grid[ iy ][ ix ];
  18036. var c = grid[ iy + 1 ][ ix ];
  18037. var d = grid[ iy + 1 ][ ix + 1 ];
  18038. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18039. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18040. }
  18041. }
  18042. // build geometry
  18043. this.setIndex( indices );
  18044. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18045. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18046. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18047. }
  18048. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18049. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18050. /**
  18051. * @author Kaleb Murphy
  18052. * @author Mugen87 / https://github.com/Mugen87
  18053. */
  18054. // RingGeometry
  18055. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18056. Geometry.call( this );
  18057. this.type = 'RingGeometry';
  18058. this.parameters = {
  18059. innerRadius: innerRadius,
  18060. outerRadius: outerRadius,
  18061. thetaSegments: thetaSegments,
  18062. phiSegments: phiSegments,
  18063. thetaStart: thetaStart,
  18064. thetaLength: thetaLength
  18065. };
  18066. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18067. this.mergeVertices();
  18068. }
  18069. RingGeometry.prototype = Object.create( Geometry.prototype );
  18070. RingGeometry.prototype.constructor = RingGeometry;
  18071. // RingBufferGeometry
  18072. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18073. BufferGeometry.call( this );
  18074. this.type = 'RingBufferGeometry';
  18075. this.parameters = {
  18076. innerRadius: innerRadius,
  18077. outerRadius: outerRadius,
  18078. thetaSegments: thetaSegments,
  18079. phiSegments: phiSegments,
  18080. thetaStart: thetaStart,
  18081. thetaLength: thetaLength
  18082. };
  18083. innerRadius = innerRadius || 0.5;
  18084. outerRadius = outerRadius || 1;
  18085. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18086. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18087. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18088. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18089. // buffers
  18090. var indices = [];
  18091. var vertices = [];
  18092. var normals = [];
  18093. var uvs = [];
  18094. // some helper variables
  18095. var segment;
  18096. var radius = innerRadius;
  18097. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18098. var vertex = new Vector3();
  18099. var uv = new Vector2();
  18100. var j, i;
  18101. // generate vertices, normals and uvs
  18102. for ( j = 0; j <= phiSegments; j ++ ) {
  18103. for ( i = 0; i <= thetaSegments; i ++ ) {
  18104. // values are generate from the inside of the ring to the outside
  18105. segment = thetaStart + i / thetaSegments * thetaLength;
  18106. // vertex
  18107. vertex.x = radius * Math.cos( segment );
  18108. vertex.y = radius * Math.sin( segment );
  18109. vertices.push( vertex.x, vertex.y, vertex.z );
  18110. // normal
  18111. normals.push( 0, 0, 1 );
  18112. // uv
  18113. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18114. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18115. uvs.push( uv.x, uv.y );
  18116. }
  18117. // increase the radius for next row of vertices
  18118. radius += radiusStep;
  18119. }
  18120. // indices
  18121. for ( j = 0; j < phiSegments; j ++ ) {
  18122. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18123. for ( i = 0; i < thetaSegments; i ++ ) {
  18124. segment = i + thetaSegmentLevel;
  18125. var a = segment;
  18126. var b = segment + thetaSegments + 1;
  18127. var c = segment + thetaSegments + 2;
  18128. var d = segment + 1;
  18129. // faces
  18130. indices.push( a, b, d );
  18131. indices.push( b, c, d );
  18132. }
  18133. }
  18134. // build geometry
  18135. this.setIndex( indices );
  18136. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18137. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18138. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18139. }
  18140. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18141. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18142. /**
  18143. * @author zz85 / https://github.com/zz85
  18144. * @author bhouston / http://clara.io
  18145. * @author Mugen87 / https://github.com/Mugen87
  18146. */
  18147. // LatheGeometry
  18148. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18149. Geometry.call( this );
  18150. this.type = 'LatheGeometry';
  18151. this.parameters = {
  18152. points: points,
  18153. segments: segments,
  18154. phiStart: phiStart,
  18155. phiLength: phiLength
  18156. };
  18157. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18158. this.mergeVertices();
  18159. }
  18160. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18161. LatheGeometry.prototype.constructor = LatheGeometry;
  18162. // LatheBufferGeometry
  18163. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18164. BufferGeometry.call( this );
  18165. this.type = 'LatheBufferGeometry';
  18166. this.parameters = {
  18167. points: points,
  18168. segments: segments,
  18169. phiStart: phiStart,
  18170. phiLength: phiLength
  18171. };
  18172. segments = Math.floor( segments ) || 12;
  18173. phiStart = phiStart || 0;
  18174. phiLength = phiLength || Math.PI * 2;
  18175. // clamp phiLength so it's in range of [ 0, 2PI ]
  18176. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18177. // buffers
  18178. var indices = [];
  18179. var vertices = [];
  18180. var uvs = [];
  18181. // helper variables
  18182. var base;
  18183. var inverseSegments = 1.0 / segments;
  18184. var vertex = new Vector3();
  18185. var uv = new Vector2();
  18186. var i, j;
  18187. // generate vertices and uvs
  18188. for ( i = 0; i <= segments; i ++ ) {
  18189. var phi = phiStart + i * inverseSegments * phiLength;
  18190. var sin = Math.sin( phi );
  18191. var cos = Math.cos( phi );
  18192. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18193. // vertex
  18194. vertex.x = points[ j ].x * sin;
  18195. vertex.y = points[ j ].y;
  18196. vertex.z = points[ j ].x * cos;
  18197. vertices.push( vertex.x, vertex.y, vertex.z );
  18198. // uv
  18199. uv.x = i / segments;
  18200. uv.y = j / ( points.length - 1 );
  18201. uvs.push( uv.x, uv.y );
  18202. }
  18203. }
  18204. // indices
  18205. for ( i = 0; i < segments; i ++ ) {
  18206. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18207. base = j + i * points.length;
  18208. var a = base;
  18209. var b = base + points.length;
  18210. var c = base + points.length + 1;
  18211. var d = base + 1;
  18212. // faces
  18213. indices.push( a, b, d );
  18214. indices.push( b, c, d );
  18215. }
  18216. }
  18217. // build geometry
  18218. this.setIndex( indices );
  18219. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18220. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18221. // generate normals
  18222. this.computeVertexNormals();
  18223. // if the geometry is closed, we need to average the normals along the seam.
  18224. // because the corresponding vertices are identical (but still have different UVs).
  18225. if ( phiLength === Math.PI * 2 ) {
  18226. var normals = this.attributes.normal.array;
  18227. var n1 = new Vector3();
  18228. var n2 = new Vector3();
  18229. var n = new Vector3();
  18230. // this is the buffer offset for the last line of vertices
  18231. base = segments * points.length * 3;
  18232. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18233. // select the normal of the vertex in the first line
  18234. n1.x = normals[ j + 0 ];
  18235. n1.y = normals[ j + 1 ];
  18236. n1.z = normals[ j + 2 ];
  18237. // select the normal of the vertex in the last line
  18238. n2.x = normals[ base + j + 0 ];
  18239. n2.y = normals[ base + j + 1 ];
  18240. n2.z = normals[ base + j + 2 ];
  18241. // average normals
  18242. n.addVectors( n1, n2 ).normalize();
  18243. // assign the new values to both normals
  18244. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18245. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18246. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18247. }
  18248. }
  18249. }
  18250. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18251. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18252. /**
  18253. * @author jonobr1 / http://jonobr1.com
  18254. * @author Mugen87 / https://github.com/Mugen87
  18255. */
  18256. // ShapeGeometry
  18257. function ShapeGeometry( shapes, curveSegments ) {
  18258. Geometry.call( this );
  18259. this.type = 'ShapeGeometry';
  18260. if ( typeof curveSegments === 'object' ) {
  18261. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18262. curveSegments = curveSegments.curveSegments;
  18263. }
  18264. this.parameters = {
  18265. shapes: shapes,
  18266. curveSegments: curveSegments
  18267. };
  18268. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18269. this.mergeVertices();
  18270. }
  18271. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18272. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18273. ShapeGeometry.prototype.toJSON = function () {
  18274. var data = Geometry.prototype.toJSON.call( this );
  18275. var shapes = this.parameters.shapes;
  18276. return toJSON$1( shapes, data );
  18277. };
  18278. // ShapeBufferGeometry
  18279. function ShapeBufferGeometry( shapes, curveSegments ) {
  18280. BufferGeometry.call( this );
  18281. this.type = 'ShapeBufferGeometry';
  18282. this.parameters = {
  18283. shapes: shapes,
  18284. curveSegments: curveSegments
  18285. };
  18286. curveSegments = curveSegments || 12;
  18287. // buffers
  18288. var indices = [];
  18289. var vertices = [];
  18290. var normals = [];
  18291. var uvs = [];
  18292. // helper variables
  18293. var groupStart = 0;
  18294. var groupCount = 0;
  18295. // allow single and array values for "shapes" parameter
  18296. if ( Array.isArray( shapes ) === false ) {
  18297. addShape( shapes );
  18298. } else {
  18299. for ( var i = 0; i < shapes.length; i ++ ) {
  18300. addShape( shapes[ i ] );
  18301. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18302. groupStart += groupCount;
  18303. groupCount = 0;
  18304. }
  18305. }
  18306. // build geometry
  18307. this.setIndex( indices );
  18308. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18309. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18310. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18311. // helper functions
  18312. function addShape( shape ) {
  18313. var i, l, shapeHole;
  18314. var indexOffset = vertices.length / 3;
  18315. var points = shape.extractPoints( curveSegments );
  18316. var shapeVertices = points.shape;
  18317. var shapeHoles = points.holes;
  18318. // check direction of vertices
  18319. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18320. shapeVertices = shapeVertices.reverse();
  18321. }
  18322. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18323. shapeHole = shapeHoles[ i ];
  18324. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18325. shapeHoles[ i ] = shapeHole.reverse();
  18326. }
  18327. }
  18328. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18329. // join vertices of inner and outer paths to a single array
  18330. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18331. shapeHole = shapeHoles[ i ];
  18332. shapeVertices = shapeVertices.concat( shapeHole );
  18333. }
  18334. // vertices, normals, uvs
  18335. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18336. var vertex = shapeVertices[ i ];
  18337. vertices.push( vertex.x, vertex.y, 0 );
  18338. normals.push( 0, 0, 1 );
  18339. uvs.push( vertex.x, vertex.y ); // world uvs
  18340. }
  18341. // incides
  18342. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18343. var face = faces[ i ];
  18344. var a = face[ 0 ] + indexOffset;
  18345. var b = face[ 1 ] + indexOffset;
  18346. var c = face[ 2 ] + indexOffset;
  18347. indices.push( a, b, c );
  18348. groupCount += 3;
  18349. }
  18350. }
  18351. }
  18352. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18353. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18354. ShapeBufferGeometry.prototype.toJSON = function () {
  18355. var data = BufferGeometry.prototype.toJSON.call( this );
  18356. var shapes = this.parameters.shapes;
  18357. return toJSON$1( shapes, data );
  18358. };
  18359. //
  18360. function toJSON$1( shapes, data ) {
  18361. data.shapes = [];
  18362. if ( Array.isArray( shapes ) ) {
  18363. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18364. var shape = shapes[ i ];
  18365. data.shapes.push( shape.uuid );
  18366. }
  18367. } else {
  18368. data.shapes.push( shapes.uuid );
  18369. }
  18370. return data;
  18371. }
  18372. /**
  18373. * @author WestLangley / http://github.com/WestLangley
  18374. * @author Mugen87 / https://github.com/Mugen87
  18375. */
  18376. function EdgesGeometry( geometry, thresholdAngle ) {
  18377. BufferGeometry.call( this );
  18378. this.type = 'EdgesGeometry';
  18379. this.parameters = {
  18380. thresholdAngle: thresholdAngle
  18381. };
  18382. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18383. // buffer
  18384. var vertices = [];
  18385. // helper variables
  18386. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18387. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18388. var key, keys = [ 'a', 'b', 'c' ];
  18389. // prepare source geometry
  18390. var geometry2;
  18391. if ( geometry.isBufferGeometry ) {
  18392. geometry2 = new Geometry();
  18393. geometry2.fromBufferGeometry( geometry );
  18394. } else {
  18395. geometry2 = geometry.clone();
  18396. }
  18397. geometry2.mergeVertices();
  18398. geometry2.computeFaceNormals();
  18399. var sourceVertices = geometry2.vertices;
  18400. var faces = geometry2.faces;
  18401. // now create a data structure where each entry represents an edge with its adjoining faces
  18402. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18403. var face = faces[ i ];
  18404. for ( var j = 0; j < 3; j ++ ) {
  18405. edge1 = face[ keys[ j ] ];
  18406. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18407. edge[ 0 ] = Math.min( edge1, edge2 );
  18408. edge[ 1 ] = Math.max( edge1, edge2 );
  18409. key = edge[ 0 ] + ',' + edge[ 1 ];
  18410. if ( edges[ key ] === undefined ) {
  18411. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18412. } else {
  18413. edges[ key ].face2 = i;
  18414. }
  18415. }
  18416. }
  18417. // generate vertices
  18418. for ( key in edges ) {
  18419. var e = edges[ key ];
  18420. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18421. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18422. var vertex = sourceVertices[ e.index1 ];
  18423. vertices.push( vertex.x, vertex.y, vertex.z );
  18424. vertex = sourceVertices[ e.index2 ];
  18425. vertices.push( vertex.x, vertex.y, vertex.z );
  18426. }
  18427. }
  18428. // build geometry
  18429. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18430. }
  18431. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18432. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18433. /**
  18434. * @author mrdoob / http://mrdoob.com/
  18435. * @author Mugen87 / https://github.com/Mugen87
  18436. */
  18437. // CylinderGeometry
  18438. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18439. Geometry.call( this );
  18440. this.type = 'CylinderGeometry';
  18441. this.parameters = {
  18442. radiusTop: radiusTop,
  18443. radiusBottom: radiusBottom,
  18444. height: height,
  18445. radialSegments: radialSegments,
  18446. heightSegments: heightSegments,
  18447. openEnded: openEnded,
  18448. thetaStart: thetaStart,
  18449. thetaLength: thetaLength
  18450. };
  18451. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18452. this.mergeVertices();
  18453. }
  18454. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18455. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18456. // CylinderBufferGeometry
  18457. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18458. BufferGeometry.call( this );
  18459. this.type = 'CylinderBufferGeometry';
  18460. this.parameters = {
  18461. radiusTop: radiusTop,
  18462. radiusBottom: radiusBottom,
  18463. height: height,
  18464. radialSegments: radialSegments,
  18465. heightSegments: heightSegments,
  18466. openEnded: openEnded,
  18467. thetaStart: thetaStart,
  18468. thetaLength: thetaLength
  18469. };
  18470. var scope = this;
  18471. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18472. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18473. height = height || 1;
  18474. radialSegments = Math.floor( radialSegments ) || 8;
  18475. heightSegments = Math.floor( heightSegments ) || 1;
  18476. openEnded = openEnded !== undefined ? openEnded : false;
  18477. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18478. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18479. // buffers
  18480. var indices = [];
  18481. var vertices = [];
  18482. var normals = [];
  18483. var uvs = [];
  18484. // helper variables
  18485. var index = 0;
  18486. var indexArray = [];
  18487. var halfHeight = height / 2;
  18488. var groupStart = 0;
  18489. // generate geometry
  18490. generateTorso();
  18491. if ( openEnded === false ) {
  18492. if ( radiusTop > 0 ) generateCap( true );
  18493. if ( radiusBottom > 0 ) generateCap( false );
  18494. }
  18495. // build geometry
  18496. this.setIndex( indices );
  18497. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18498. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18499. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18500. function generateTorso() {
  18501. var x, y;
  18502. var normal = new Vector3();
  18503. var vertex = new Vector3();
  18504. var groupCount = 0;
  18505. // this will be used to calculate the normal
  18506. var slope = ( radiusBottom - radiusTop ) / height;
  18507. // generate vertices, normals and uvs
  18508. for ( y = 0; y <= heightSegments; y ++ ) {
  18509. var indexRow = [];
  18510. var v = y / heightSegments;
  18511. // calculate the radius of the current row
  18512. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18513. for ( x = 0; x <= radialSegments; x ++ ) {
  18514. var u = x / radialSegments;
  18515. var theta = u * thetaLength + thetaStart;
  18516. var sinTheta = Math.sin( theta );
  18517. var cosTheta = Math.cos( theta );
  18518. // vertex
  18519. vertex.x = radius * sinTheta;
  18520. vertex.y = - v * height + halfHeight;
  18521. vertex.z = radius * cosTheta;
  18522. vertices.push( vertex.x, vertex.y, vertex.z );
  18523. // normal
  18524. normal.set( sinTheta, slope, cosTheta ).normalize();
  18525. normals.push( normal.x, normal.y, normal.z );
  18526. // uv
  18527. uvs.push( u, 1 - v );
  18528. // save index of vertex in respective row
  18529. indexRow.push( index ++ );
  18530. }
  18531. // now save vertices of the row in our index array
  18532. indexArray.push( indexRow );
  18533. }
  18534. // generate indices
  18535. for ( x = 0; x < radialSegments; x ++ ) {
  18536. for ( y = 0; y < heightSegments; y ++ ) {
  18537. // we use the index array to access the correct indices
  18538. var a = indexArray[ y ][ x ];
  18539. var b = indexArray[ y + 1 ][ x ];
  18540. var c = indexArray[ y + 1 ][ x + 1 ];
  18541. var d = indexArray[ y ][ x + 1 ];
  18542. // faces
  18543. indices.push( a, b, d );
  18544. indices.push( b, c, d );
  18545. // update group counter
  18546. groupCount += 6;
  18547. }
  18548. }
  18549. // add a group to the geometry. this will ensure multi material support
  18550. scope.addGroup( groupStart, groupCount, 0 );
  18551. // calculate new start value for groups
  18552. groupStart += groupCount;
  18553. }
  18554. function generateCap( top ) {
  18555. var x, centerIndexStart, centerIndexEnd;
  18556. var uv = new Vector2();
  18557. var vertex = new Vector3();
  18558. var groupCount = 0;
  18559. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18560. var sign = ( top === true ) ? 1 : - 1;
  18561. // save the index of the first center vertex
  18562. centerIndexStart = index;
  18563. // first we generate the center vertex data of the cap.
  18564. // because the geometry needs one set of uvs per face,
  18565. // we must generate a center vertex per face/segment
  18566. for ( x = 1; x <= radialSegments; x ++ ) {
  18567. // vertex
  18568. vertices.push( 0, halfHeight * sign, 0 );
  18569. // normal
  18570. normals.push( 0, sign, 0 );
  18571. // uv
  18572. uvs.push( 0.5, 0.5 );
  18573. // increase index
  18574. index ++;
  18575. }
  18576. // save the index of the last center vertex
  18577. centerIndexEnd = index;
  18578. // now we generate the surrounding vertices, normals and uvs
  18579. for ( x = 0; x <= radialSegments; x ++ ) {
  18580. var u = x / radialSegments;
  18581. var theta = u * thetaLength + thetaStart;
  18582. var cosTheta = Math.cos( theta );
  18583. var sinTheta = Math.sin( theta );
  18584. // vertex
  18585. vertex.x = radius * sinTheta;
  18586. vertex.y = halfHeight * sign;
  18587. vertex.z = radius * cosTheta;
  18588. vertices.push( vertex.x, vertex.y, vertex.z );
  18589. // normal
  18590. normals.push( 0, sign, 0 );
  18591. // uv
  18592. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18593. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18594. uvs.push( uv.x, uv.y );
  18595. // increase index
  18596. index ++;
  18597. }
  18598. // generate indices
  18599. for ( x = 0; x < radialSegments; x ++ ) {
  18600. var c = centerIndexStart + x;
  18601. var i = centerIndexEnd + x;
  18602. if ( top === true ) {
  18603. // face top
  18604. indices.push( i, i + 1, c );
  18605. } else {
  18606. // face bottom
  18607. indices.push( i + 1, i, c );
  18608. }
  18609. groupCount += 3;
  18610. }
  18611. // add a group to the geometry. this will ensure multi material support
  18612. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18613. // calculate new start value for groups
  18614. groupStart += groupCount;
  18615. }
  18616. }
  18617. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18618. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18619. /**
  18620. * @author abelnation / http://github.com/abelnation
  18621. */
  18622. // ConeGeometry
  18623. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18624. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18625. this.type = 'ConeGeometry';
  18626. this.parameters = {
  18627. radius: radius,
  18628. height: height,
  18629. radialSegments: radialSegments,
  18630. heightSegments: heightSegments,
  18631. openEnded: openEnded,
  18632. thetaStart: thetaStart,
  18633. thetaLength: thetaLength
  18634. };
  18635. }
  18636. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18637. ConeGeometry.prototype.constructor = ConeGeometry;
  18638. // ConeBufferGeometry
  18639. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18640. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18641. this.type = 'ConeBufferGeometry';
  18642. this.parameters = {
  18643. radius: radius,
  18644. height: height,
  18645. radialSegments: radialSegments,
  18646. heightSegments: heightSegments,
  18647. openEnded: openEnded,
  18648. thetaStart: thetaStart,
  18649. thetaLength: thetaLength
  18650. };
  18651. }
  18652. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18653. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18654. /**
  18655. * @author benaadams / https://twitter.com/ben_a_adams
  18656. * @author Mugen87 / https://github.com/Mugen87
  18657. * @author hughes
  18658. */
  18659. // CircleGeometry
  18660. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18661. Geometry.call( this );
  18662. this.type = 'CircleGeometry';
  18663. this.parameters = {
  18664. radius: radius,
  18665. segments: segments,
  18666. thetaStart: thetaStart,
  18667. thetaLength: thetaLength
  18668. };
  18669. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18670. this.mergeVertices();
  18671. }
  18672. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18673. CircleGeometry.prototype.constructor = CircleGeometry;
  18674. // CircleBufferGeometry
  18675. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18676. BufferGeometry.call( this );
  18677. this.type = 'CircleBufferGeometry';
  18678. this.parameters = {
  18679. radius: radius,
  18680. segments: segments,
  18681. thetaStart: thetaStart,
  18682. thetaLength: thetaLength
  18683. };
  18684. radius = radius || 1;
  18685. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18686. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18687. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18688. // buffers
  18689. var indices = [];
  18690. var vertices = [];
  18691. var normals = [];
  18692. var uvs = [];
  18693. // helper variables
  18694. var i, s;
  18695. var vertex = new Vector3();
  18696. var uv = new Vector2();
  18697. // center point
  18698. vertices.push( 0, 0, 0 );
  18699. normals.push( 0, 0, 1 );
  18700. uvs.push( 0.5, 0.5 );
  18701. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18702. var segment = thetaStart + s / segments * thetaLength;
  18703. // vertex
  18704. vertex.x = radius * Math.cos( segment );
  18705. vertex.y = radius * Math.sin( segment );
  18706. vertices.push( vertex.x, vertex.y, vertex.z );
  18707. // normal
  18708. normals.push( 0, 0, 1 );
  18709. // uvs
  18710. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18711. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18712. uvs.push( uv.x, uv.y );
  18713. }
  18714. // indices
  18715. for ( i = 1; i <= segments; i ++ ) {
  18716. indices.push( i, i + 1, 0 );
  18717. }
  18718. // build geometry
  18719. this.setIndex( indices );
  18720. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18721. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18722. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18723. }
  18724. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18725. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18726. var Geometries = /*#__PURE__*/Object.freeze({
  18727. WireframeGeometry: WireframeGeometry,
  18728. ParametricGeometry: ParametricGeometry,
  18729. ParametricBufferGeometry: ParametricBufferGeometry,
  18730. TetrahedronGeometry: TetrahedronGeometry,
  18731. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18732. OctahedronGeometry: OctahedronGeometry,
  18733. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18734. IcosahedronGeometry: IcosahedronGeometry,
  18735. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18736. DodecahedronGeometry: DodecahedronGeometry,
  18737. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18738. PolyhedronGeometry: PolyhedronGeometry,
  18739. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18740. TubeGeometry: TubeGeometry,
  18741. TubeBufferGeometry: TubeBufferGeometry,
  18742. TorusKnotGeometry: TorusKnotGeometry,
  18743. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18744. TorusGeometry: TorusGeometry,
  18745. TorusBufferGeometry: TorusBufferGeometry,
  18746. TextGeometry: TextGeometry,
  18747. TextBufferGeometry: TextBufferGeometry,
  18748. SphereGeometry: SphereGeometry,
  18749. SphereBufferGeometry: SphereBufferGeometry,
  18750. RingGeometry: RingGeometry,
  18751. RingBufferGeometry: RingBufferGeometry,
  18752. PlaneGeometry: PlaneGeometry,
  18753. PlaneBufferGeometry: PlaneBufferGeometry,
  18754. LatheGeometry: LatheGeometry,
  18755. LatheBufferGeometry: LatheBufferGeometry,
  18756. ShapeGeometry: ShapeGeometry,
  18757. ShapeBufferGeometry: ShapeBufferGeometry,
  18758. ExtrudeGeometry: ExtrudeGeometry,
  18759. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18760. EdgesGeometry: EdgesGeometry,
  18761. ConeGeometry: ConeGeometry,
  18762. ConeBufferGeometry: ConeBufferGeometry,
  18763. CylinderGeometry: CylinderGeometry,
  18764. CylinderBufferGeometry: CylinderBufferGeometry,
  18765. CircleGeometry: CircleGeometry,
  18766. CircleBufferGeometry: CircleBufferGeometry,
  18767. BoxGeometry: BoxGeometry,
  18768. BoxBufferGeometry: BoxBufferGeometry
  18769. });
  18770. /**
  18771. * @author mrdoob / http://mrdoob.com/
  18772. *
  18773. * parameters = {
  18774. * color: <THREE.Color>
  18775. * }
  18776. */
  18777. function ShadowMaterial( parameters ) {
  18778. Material.call( this );
  18779. this.type = 'ShadowMaterial';
  18780. this.color = new Color( 0x000000 );
  18781. this.transparent = true;
  18782. this.setValues( parameters );
  18783. }
  18784. ShadowMaterial.prototype = Object.create( Material.prototype );
  18785. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18786. ShadowMaterial.prototype.isShadowMaterial = true;
  18787. ShadowMaterial.prototype.copy = function ( source ) {
  18788. Material.prototype.copy.call( this, source );
  18789. this.color.copy( source.color );
  18790. return this;
  18791. };
  18792. /**
  18793. * @author mrdoob / http://mrdoob.com/
  18794. */
  18795. function RawShaderMaterial( parameters ) {
  18796. ShaderMaterial.call( this, parameters );
  18797. this.type = 'RawShaderMaterial';
  18798. }
  18799. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18800. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18801. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18802. /**
  18803. * @author WestLangley / http://github.com/WestLangley
  18804. *
  18805. * parameters = {
  18806. * color: <hex>,
  18807. * roughness: <float>,
  18808. * metalness: <float>,
  18809. * opacity: <float>,
  18810. *
  18811. * map: new THREE.Texture( <Image> ),
  18812. *
  18813. * lightMap: new THREE.Texture( <Image> ),
  18814. * lightMapIntensity: <float>
  18815. *
  18816. * aoMap: new THREE.Texture( <Image> ),
  18817. * aoMapIntensity: <float>
  18818. *
  18819. * emissive: <hex>,
  18820. * emissiveIntensity: <float>
  18821. * emissiveMap: new THREE.Texture( <Image> ),
  18822. *
  18823. * bumpMap: new THREE.Texture( <Image> ),
  18824. * bumpScale: <float>,
  18825. *
  18826. * normalMap: new THREE.Texture( <Image> ),
  18827. * normalMapType: THREE.TangentSpaceNormalMap,
  18828. * normalScale: <Vector2>,
  18829. *
  18830. * displacementMap: new THREE.Texture( <Image> ),
  18831. * displacementScale: <float>,
  18832. * displacementBias: <float>,
  18833. *
  18834. * roughnessMap: new THREE.Texture( <Image> ),
  18835. *
  18836. * metalnessMap: new THREE.Texture( <Image> ),
  18837. *
  18838. * alphaMap: new THREE.Texture( <Image> ),
  18839. *
  18840. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18841. * envMapIntensity: <float>
  18842. *
  18843. * refractionRatio: <float>,
  18844. *
  18845. * wireframe: <boolean>,
  18846. * wireframeLinewidth: <float>,
  18847. *
  18848. * skinning: <bool>,
  18849. * morphTargets: <bool>,
  18850. * morphNormals: <bool>
  18851. * }
  18852. */
  18853. function MeshStandardMaterial( parameters ) {
  18854. Material.call( this );
  18855. this.defines = { 'STANDARD': '' };
  18856. this.type = 'MeshStandardMaterial';
  18857. this.color = new Color( 0xffffff ); // diffuse
  18858. this.roughness = 0.5;
  18859. this.metalness = 0.5;
  18860. this.map = null;
  18861. this.lightMap = null;
  18862. this.lightMapIntensity = 1.0;
  18863. this.aoMap = null;
  18864. this.aoMapIntensity = 1.0;
  18865. this.emissive = new Color( 0x000000 );
  18866. this.emissiveIntensity = 1.0;
  18867. this.emissiveMap = null;
  18868. this.bumpMap = null;
  18869. this.bumpScale = 1;
  18870. this.normalMap = null;
  18871. this.normalMapType = TangentSpaceNormalMap;
  18872. this.normalScale = new Vector2( 1, 1 );
  18873. this.displacementMap = null;
  18874. this.displacementScale = 1;
  18875. this.displacementBias = 0;
  18876. this.roughnessMap = null;
  18877. this.metalnessMap = null;
  18878. this.alphaMap = null;
  18879. this.envMap = null;
  18880. this.envMapIntensity = 1.0;
  18881. this.refractionRatio = 0.98;
  18882. this.wireframe = false;
  18883. this.wireframeLinewidth = 1;
  18884. this.wireframeLinecap = 'round';
  18885. this.wireframeLinejoin = 'round';
  18886. this.skinning = false;
  18887. this.morphTargets = false;
  18888. this.morphNormals = false;
  18889. this.setValues( parameters );
  18890. }
  18891. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18892. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18893. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18894. MeshStandardMaterial.prototype.copy = function ( source ) {
  18895. Material.prototype.copy.call( this, source );
  18896. this.defines = { 'STANDARD': '' };
  18897. this.color.copy( source.color );
  18898. this.roughness = source.roughness;
  18899. this.metalness = source.metalness;
  18900. this.map = source.map;
  18901. this.lightMap = source.lightMap;
  18902. this.lightMapIntensity = source.lightMapIntensity;
  18903. this.aoMap = source.aoMap;
  18904. this.aoMapIntensity = source.aoMapIntensity;
  18905. this.emissive.copy( source.emissive );
  18906. this.emissiveMap = source.emissiveMap;
  18907. this.emissiveIntensity = source.emissiveIntensity;
  18908. this.bumpMap = source.bumpMap;
  18909. this.bumpScale = source.bumpScale;
  18910. this.normalMap = source.normalMap;
  18911. this.normalMapType = source.normalMapType;
  18912. this.normalScale.copy( source.normalScale );
  18913. this.displacementMap = source.displacementMap;
  18914. this.displacementScale = source.displacementScale;
  18915. this.displacementBias = source.displacementBias;
  18916. this.roughnessMap = source.roughnessMap;
  18917. this.metalnessMap = source.metalnessMap;
  18918. this.alphaMap = source.alphaMap;
  18919. this.envMap = source.envMap;
  18920. this.envMapIntensity = source.envMapIntensity;
  18921. this.refractionRatio = source.refractionRatio;
  18922. this.wireframe = source.wireframe;
  18923. this.wireframeLinewidth = source.wireframeLinewidth;
  18924. this.wireframeLinecap = source.wireframeLinecap;
  18925. this.wireframeLinejoin = source.wireframeLinejoin;
  18926. this.skinning = source.skinning;
  18927. this.morphTargets = source.morphTargets;
  18928. this.morphNormals = source.morphNormals;
  18929. return this;
  18930. };
  18931. /**
  18932. * @author WestLangley / http://github.com/WestLangley
  18933. *
  18934. * parameters = {
  18935. * reflectivity: <float>
  18936. * clearCoat: <float>
  18937. * clearCoatRoughness: <float>
  18938. * }
  18939. */
  18940. function MeshPhysicalMaterial( parameters ) {
  18941. MeshStandardMaterial.call( this );
  18942. this.defines = { 'PHYSICAL': '' };
  18943. this.type = 'MeshPhysicalMaterial';
  18944. this.reflectivity = 0.5; // maps to F0 = 0.04
  18945. this.clearCoat = 0.0;
  18946. this.clearCoatRoughness = 0.0;
  18947. this.setValues( parameters );
  18948. }
  18949. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18950. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18951. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18952. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18953. MeshStandardMaterial.prototype.copy.call( this, source );
  18954. this.defines = { 'PHYSICAL': '' };
  18955. this.reflectivity = source.reflectivity;
  18956. this.clearCoat = source.clearCoat;
  18957. this.clearCoatRoughness = source.clearCoatRoughness;
  18958. return this;
  18959. };
  18960. /**
  18961. * @author mrdoob / http://mrdoob.com/
  18962. * @author alteredq / http://alteredqualia.com/
  18963. *
  18964. * parameters = {
  18965. * color: <hex>,
  18966. * specular: <hex>,
  18967. * shininess: <float>,
  18968. * opacity: <float>,
  18969. *
  18970. * map: new THREE.Texture( <Image> ),
  18971. *
  18972. * lightMap: new THREE.Texture( <Image> ),
  18973. * lightMapIntensity: <float>
  18974. *
  18975. * aoMap: new THREE.Texture( <Image> ),
  18976. * aoMapIntensity: <float>
  18977. *
  18978. * emissive: <hex>,
  18979. * emissiveIntensity: <float>
  18980. * emissiveMap: new THREE.Texture( <Image> ),
  18981. *
  18982. * bumpMap: new THREE.Texture( <Image> ),
  18983. * bumpScale: <float>,
  18984. *
  18985. * normalMap: new THREE.Texture( <Image> ),
  18986. * normalMapType: THREE.TangentSpaceNormalMap,
  18987. * normalScale: <Vector2>,
  18988. *
  18989. * displacementMap: new THREE.Texture( <Image> ),
  18990. * displacementScale: <float>,
  18991. * displacementBias: <float>,
  18992. *
  18993. * specularMap: new THREE.Texture( <Image> ),
  18994. *
  18995. * alphaMap: new THREE.Texture( <Image> ),
  18996. *
  18997. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18998. * combine: THREE.Multiply,
  18999. * reflectivity: <float>,
  19000. * refractionRatio: <float>,
  19001. *
  19002. * wireframe: <boolean>,
  19003. * wireframeLinewidth: <float>,
  19004. *
  19005. * skinning: <bool>,
  19006. * morphTargets: <bool>,
  19007. * morphNormals: <bool>
  19008. * }
  19009. */
  19010. function MeshPhongMaterial( parameters ) {
  19011. Material.call( this );
  19012. this.type = 'MeshPhongMaterial';
  19013. this.color = new Color( 0xffffff ); // diffuse
  19014. this.specular = new Color( 0x111111 );
  19015. this.shininess = 30;
  19016. this.map = null;
  19017. this.lightMap = null;
  19018. this.lightMapIntensity = 1.0;
  19019. this.aoMap = null;
  19020. this.aoMapIntensity = 1.0;
  19021. this.emissive = new Color( 0x000000 );
  19022. this.emissiveIntensity = 1.0;
  19023. this.emissiveMap = null;
  19024. this.bumpMap = null;
  19025. this.bumpScale = 1;
  19026. this.normalMap = null;
  19027. this.normalMapType = TangentSpaceNormalMap;
  19028. this.normalScale = new Vector2( 1, 1 );
  19029. this.displacementMap = null;
  19030. this.displacementScale = 1;
  19031. this.displacementBias = 0;
  19032. this.specularMap = null;
  19033. this.alphaMap = null;
  19034. this.envMap = null;
  19035. this.combine = MultiplyOperation;
  19036. this.reflectivity = 1;
  19037. this.refractionRatio = 0.98;
  19038. this.wireframe = false;
  19039. this.wireframeLinewidth = 1;
  19040. this.wireframeLinecap = 'round';
  19041. this.wireframeLinejoin = 'round';
  19042. this.skinning = false;
  19043. this.morphTargets = false;
  19044. this.morphNormals = false;
  19045. this.setValues( parameters );
  19046. }
  19047. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19048. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19049. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19050. MeshPhongMaterial.prototype.copy = function ( source ) {
  19051. Material.prototype.copy.call( this, source );
  19052. this.color.copy( source.color );
  19053. this.specular.copy( source.specular );
  19054. this.shininess = source.shininess;
  19055. this.map = source.map;
  19056. this.lightMap = source.lightMap;
  19057. this.lightMapIntensity = source.lightMapIntensity;
  19058. this.aoMap = source.aoMap;
  19059. this.aoMapIntensity = source.aoMapIntensity;
  19060. this.emissive.copy( source.emissive );
  19061. this.emissiveMap = source.emissiveMap;
  19062. this.emissiveIntensity = source.emissiveIntensity;
  19063. this.bumpMap = source.bumpMap;
  19064. this.bumpScale = source.bumpScale;
  19065. this.normalMap = source.normalMap;
  19066. this.normalMapType = source.normalMapType;
  19067. this.normalScale.copy( source.normalScale );
  19068. this.displacementMap = source.displacementMap;
  19069. this.displacementScale = source.displacementScale;
  19070. this.displacementBias = source.displacementBias;
  19071. this.specularMap = source.specularMap;
  19072. this.alphaMap = source.alphaMap;
  19073. this.envMap = source.envMap;
  19074. this.combine = source.combine;
  19075. this.reflectivity = source.reflectivity;
  19076. this.refractionRatio = source.refractionRatio;
  19077. this.wireframe = source.wireframe;
  19078. this.wireframeLinewidth = source.wireframeLinewidth;
  19079. this.wireframeLinecap = source.wireframeLinecap;
  19080. this.wireframeLinejoin = source.wireframeLinejoin;
  19081. this.skinning = source.skinning;
  19082. this.morphTargets = source.morphTargets;
  19083. this.morphNormals = source.morphNormals;
  19084. return this;
  19085. };
  19086. /**
  19087. * @author takahirox / http://github.com/takahirox
  19088. *
  19089. * parameters = {
  19090. * gradientMap: new THREE.Texture( <Image> )
  19091. * }
  19092. */
  19093. function MeshToonMaterial( parameters ) {
  19094. MeshPhongMaterial.call( this );
  19095. this.defines = { 'TOON': '' };
  19096. this.type = 'MeshToonMaterial';
  19097. this.gradientMap = null;
  19098. this.setValues( parameters );
  19099. }
  19100. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19101. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19102. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19103. MeshToonMaterial.prototype.copy = function ( source ) {
  19104. MeshPhongMaterial.prototype.copy.call( this, source );
  19105. this.gradientMap = source.gradientMap;
  19106. return this;
  19107. };
  19108. /**
  19109. * @author mrdoob / http://mrdoob.com/
  19110. * @author WestLangley / http://github.com/WestLangley
  19111. *
  19112. * parameters = {
  19113. * opacity: <float>,
  19114. *
  19115. * bumpMap: new THREE.Texture( <Image> ),
  19116. * bumpScale: <float>,
  19117. *
  19118. * normalMap: new THREE.Texture( <Image> ),
  19119. * normalMapType: THREE.TangentSpaceNormalMap,
  19120. * normalScale: <Vector2>,
  19121. *
  19122. * displacementMap: new THREE.Texture( <Image> ),
  19123. * displacementScale: <float>,
  19124. * displacementBias: <float>,
  19125. *
  19126. * wireframe: <boolean>,
  19127. * wireframeLinewidth: <float>
  19128. *
  19129. * skinning: <bool>,
  19130. * morphTargets: <bool>,
  19131. * morphNormals: <bool>
  19132. * }
  19133. */
  19134. function MeshNormalMaterial( parameters ) {
  19135. Material.call( this );
  19136. this.type = 'MeshNormalMaterial';
  19137. this.bumpMap = null;
  19138. this.bumpScale = 1;
  19139. this.normalMap = null;
  19140. this.normalMapType = TangentSpaceNormalMap;
  19141. this.normalScale = new Vector2( 1, 1 );
  19142. this.displacementMap = null;
  19143. this.displacementScale = 1;
  19144. this.displacementBias = 0;
  19145. this.wireframe = false;
  19146. this.wireframeLinewidth = 1;
  19147. this.fog = false;
  19148. this.lights = false;
  19149. this.skinning = false;
  19150. this.morphTargets = false;
  19151. this.morphNormals = false;
  19152. this.setValues( parameters );
  19153. }
  19154. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19155. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19156. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19157. MeshNormalMaterial.prototype.copy = function ( source ) {
  19158. Material.prototype.copy.call( this, source );
  19159. this.bumpMap = source.bumpMap;
  19160. this.bumpScale = source.bumpScale;
  19161. this.normalMap = source.normalMap;
  19162. this.normalMapType = source.normalMapType;
  19163. this.normalScale.copy( source.normalScale );
  19164. this.displacementMap = source.displacementMap;
  19165. this.displacementScale = source.displacementScale;
  19166. this.displacementBias = source.displacementBias;
  19167. this.wireframe = source.wireframe;
  19168. this.wireframeLinewidth = source.wireframeLinewidth;
  19169. this.skinning = source.skinning;
  19170. this.morphTargets = source.morphTargets;
  19171. this.morphNormals = source.morphNormals;
  19172. return this;
  19173. };
  19174. /**
  19175. * @author mrdoob / http://mrdoob.com/
  19176. * @author alteredq / http://alteredqualia.com/
  19177. *
  19178. * parameters = {
  19179. * color: <hex>,
  19180. * opacity: <float>,
  19181. *
  19182. * map: new THREE.Texture( <Image> ),
  19183. *
  19184. * lightMap: new THREE.Texture( <Image> ),
  19185. * lightMapIntensity: <float>
  19186. *
  19187. * aoMap: new THREE.Texture( <Image> ),
  19188. * aoMapIntensity: <float>
  19189. *
  19190. * emissive: <hex>,
  19191. * emissiveIntensity: <float>
  19192. * emissiveMap: new THREE.Texture( <Image> ),
  19193. *
  19194. * specularMap: new THREE.Texture( <Image> ),
  19195. *
  19196. * alphaMap: new THREE.Texture( <Image> ),
  19197. *
  19198. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19199. * combine: THREE.Multiply,
  19200. * reflectivity: <float>,
  19201. * refractionRatio: <float>,
  19202. *
  19203. * wireframe: <boolean>,
  19204. * wireframeLinewidth: <float>,
  19205. *
  19206. * skinning: <bool>,
  19207. * morphTargets: <bool>,
  19208. * morphNormals: <bool>
  19209. * }
  19210. */
  19211. function MeshLambertMaterial( parameters ) {
  19212. Material.call( this );
  19213. this.type = 'MeshLambertMaterial';
  19214. this.color = new Color( 0xffffff ); // diffuse
  19215. this.map = null;
  19216. this.lightMap = null;
  19217. this.lightMapIntensity = 1.0;
  19218. this.aoMap = null;
  19219. this.aoMapIntensity = 1.0;
  19220. this.emissive = new Color( 0x000000 );
  19221. this.emissiveIntensity = 1.0;
  19222. this.emissiveMap = null;
  19223. this.specularMap = null;
  19224. this.alphaMap = null;
  19225. this.envMap = null;
  19226. this.combine = MultiplyOperation;
  19227. this.reflectivity = 1;
  19228. this.refractionRatio = 0.98;
  19229. this.wireframe = false;
  19230. this.wireframeLinewidth = 1;
  19231. this.wireframeLinecap = 'round';
  19232. this.wireframeLinejoin = 'round';
  19233. this.skinning = false;
  19234. this.morphTargets = false;
  19235. this.morphNormals = false;
  19236. this.setValues( parameters );
  19237. }
  19238. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19239. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19240. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19241. MeshLambertMaterial.prototype.copy = function ( source ) {
  19242. Material.prototype.copy.call( this, source );
  19243. this.color.copy( source.color );
  19244. this.map = source.map;
  19245. this.lightMap = source.lightMap;
  19246. this.lightMapIntensity = source.lightMapIntensity;
  19247. this.aoMap = source.aoMap;
  19248. this.aoMapIntensity = source.aoMapIntensity;
  19249. this.emissive.copy( source.emissive );
  19250. this.emissiveMap = source.emissiveMap;
  19251. this.emissiveIntensity = source.emissiveIntensity;
  19252. this.specularMap = source.specularMap;
  19253. this.alphaMap = source.alphaMap;
  19254. this.envMap = source.envMap;
  19255. this.combine = source.combine;
  19256. this.reflectivity = source.reflectivity;
  19257. this.refractionRatio = source.refractionRatio;
  19258. this.wireframe = source.wireframe;
  19259. this.wireframeLinewidth = source.wireframeLinewidth;
  19260. this.wireframeLinecap = source.wireframeLinecap;
  19261. this.wireframeLinejoin = source.wireframeLinejoin;
  19262. this.skinning = source.skinning;
  19263. this.morphTargets = source.morphTargets;
  19264. this.morphNormals = source.morphNormals;
  19265. return this;
  19266. };
  19267. /**
  19268. * @author WestLangley / http://github.com/WestLangley
  19269. *
  19270. * parameters = {
  19271. * color: <hex>,
  19272. * opacity: <float>,
  19273. *
  19274. * matcap: new THREE.Texture( <Image> ),
  19275. *
  19276. * map: new THREE.Texture( <Image> ),
  19277. *
  19278. * bumpMap: new THREE.Texture( <Image> ),
  19279. * bumpScale: <float>,
  19280. *
  19281. * normalMap: new THREE.Texture( <Image> ),
  19282. * normalMapType: THREE.TangentSpaceNormalMap,
  19283. * normalScale: <Vector2>,
  19284. *
  19285. * displacementMap: new THREE.Texture( <Image> ),
  19286. * displacementScale: <float>,
  19287. * displacementBias: <float>,
  19288. *
  19289. * alphaMap: new THREE.Texture( <Image> ),
  19290. *
  19291. * skinning: <bool>,
  19292. * morphTargets: <bool>,
  19293. * morphNormals: <bool>
  19294. * }
  19295. */
  19296. function MeshMatcapMaterial( parameters ) {
  19297. Material.call( this );
  19298. this.defines = { 'MATCAP': '' };
  19299. this.type = 'MeshMatcapMaterial';
  19300. this.color = new Color( 0xffffff ); // diffuse
  19301. this.matcap = null;
  19302. this.map = null;
  19303. this.bumpMap = null;
  19304. this.bumpScale = 1;
  19305. this.normalMap = null;
  19306. this.normalMapType = TangentSpaceNormalMap;
  19307. this.normalScale = new Vector2( 1, 1 );
  19308. this.displacementMap = null;
  19309. this.displacementScale = 1;
  19310. this.displacementBias = 0;
  19311. this.alphaMap = null;
  19312. this.skinning = false;
  19313. this.morphTargets = false;
  19314. this.morphNormals = false;
  19315. this.lights = false;
  19316. this.setValues( parameters );
  19317. }
  19318. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19319. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19320. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19321. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19322. Material.prototype.copy.call( this, source );
  19323. this.defines = { 'MATCAP': '' };
  19324. this.color.copy( source.color );
  19325. this.matcap = source.matcap;
  19326. this.map = source.map;
  19327. this.bumpMap = source.bumpMap;
  19328. this.bumpScale = source.bumpScale;
  19329. this.normalMap = source.normalMap;
  19330. this.normalMapType = source.normalMapType;
  19331. this.normalScale.copy( source.normalScale );
  19332. this.displacementMap = source.displacementMap;
  19333. this.displacementScale = source.displacementScale;
  19334. this.displacementBias = source.displacementBias;
  19335. this.alphaMap = source.alphaMap;
  19336. this.skinning = source.skinning;
  19337. this.morphTargets = source.morphTargets;
  19338. this.morphNormals = source.morphNormals;
  19339. return this;
  19340. };
  19341. /**
  19342. * @author alteredq / http://alteredqualia.com/
  19343. *
  19344. * parameters = {
  19345. * color: <hex>,
  19346. * opacity: <float>,
  19347. *
  19348. * linewidth: <float>,
  19349. *
  19350. * scale: <float>,
  19351. * dashSize: <float>,
  19352. * gapSize: <float>
  19353. * }
  19354. */
  19355. function LineDashedMaterial( parameters ) {
  19356. LineBasicMaterial.call( this );
  19357. this.type = 'LineDashedMaterial';
  19358. this.scale = 1;
  19359. this.dashSize = 3;
  19360. this.gapSize = 1;
  19361. this.setValues( parameters );
  19362. }
  19363. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19364. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19365. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19366. LineDashedMaterial.prototype.copy = function ( source ) {
  19367. LineBasicMaterial.prototype.copy.call( this, source );
  19368. this.scale = source.scale;
  19369. this.dashSize = source.dashSize;
  19370. this.gapSize = source.gapSize;
  19371. return this;
  19372. };
  19373. var Materials = /*#__PURE__*/Object.freeze({
  19374. ShadowMaterial: ShadowMaterial,
  19375. SpriteMaterial: SpriteMaterial,
  19376. RawShaderMaterial: RawShaderMaterial,
  19377. ShaderMaterial: ShaderMaterial,
  19378. PointsMaterial: PointsMaterial,
  19379. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19380. MeshStandardMaterial: MeshStandardMaterial,
  19381. MeshPhongMaterial: MeshPhongMaterial,
  19382. MeshToonMaterial: MeshToonMaterial,
  19383. MeshNormalMaterial: MeshNormalMaterial,
  19384. MeshLambertMaterial: MeshLambertMaterial,
  19385. MeshDepthMaterial: MeshDepthMaterial,
  19386. MeshDistanceMaterial: MeshDistanceMaterial,
  19387. MeshBasicMaterial: MeshBasicMaterial,
  19388. MeshMatcapMaterial: MeshMatcapMaterial,
  19389. LineDashedMaterial: LineDashedMaterial,
  19390. LineBasicMaterial: LineBasicMaterial,
  19391. Material: Material
  19392. });
  19393. /**
  19394. * @author tschw
  19395. * @author Ben Houston / http://clara.io/
  19396. * @author David Sarno / http://lighthaus.us/
  19397. */
  19398. var AnimationUtils = {
  19399. // same as Array.prototype.slice, but also works on typed arrays
  19400. arraySlice: function ( array, from, to ) {
  19401. if ( AnimationUtils.isTypedArray( array ) ) {
  19402. // in ios9 array.subarray(from, undefined) will return empty array
  19403. // but array.subarray(from) or array.subarray(from, len) is correct
  19404. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19405. }
  19406. return array.slice( from, to );
  19407. },
  19408. // converts an array to a specific type
  19409. convertArray: function ( array, type, forceClone ) {
  19410. if ( ! array || // let 'undefined' and 'null' pass
  19411. ! forceClone && array.constructor === type ) return array;
  19412. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19413. return new type( array ); // create typed array
  19414. }
  19415. return Array.prototype.slice.call( array ); // create Array
  19416. },
  19417. isTypedArray: function ( object ) {
  19418. return ArrayBuffer.isView( object ) &&
  19419. ! ( object instanceof DataView );
  19420. },
  19421. // returns an array by which times and values can be sorted
  19422. getKeyframeOrder: function ( times ) {
  19423. function compareTime( i, j ) {
  19424. return times[ i ] - times[ j ];
  19425. }
  19426. var n = times.length;
  19427. var result = new Array( n );
  19428. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19429. result.sort( compareTime );
  19430. return result;
  19431. },
  19432. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19433. sortedArray: function ( values, stride, order ) {
  19434. var nValues = values.length;
  19435. var result = new values.constructor( nValues );
  19436. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19437. var srcOffset = order[ i ] * stride;
  19438. for ( var j = 0; j !== stride; ++ j ) {
  19439. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19440. }
  19441. }
  19442. return result;
  19443. },
  19444. // function for parsing AOS keyframe formats
  19445. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19446. var i = 1, key = jsonKeys[ 0 ];
  19447. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19448. key = jsonKeys[ i ++ ];
  19449. }
  19450. if ( key === undefined ) return; // no data
  19451. var value = key[ valuePropertyName ];
  19452. if ( value === undefined ) return; // no data
  19453. if ( Array.isArray( value ) ) {
  19454. do {
  19455. value = key[ valuePropertyName ];
  19456. if ( value !== undefined ) {
  19457. times.push( key.time );
  19458. values.push.apply( values, value ); // push all elements
  19459. }
  19460. key = jsonKeys[ i ++ ];
  19461. } while ( key !== undefined );
  19462. } else if ( value.toArray !== undefined ) {
  19463. // ...assume THREE.Math-ish
  19464. do {
  19465. value = key[ valuePropertyName ];
  19466. if ( value !== undefined ) {
  19467. times.push( key.time );
  19468. value.toArray( values, values.length );
  19469. }
  19470. key = jsonKeys[ i ++ ];
  19471. } while ( key !== undefined );
  19472. } else {
  19473. // otherwise push as-is
  19474. do {
  19475. value = key[ valuePropertyName ];
  19476. if ( value !== undefined ) {
  19477. times.push( key.time );
  19478. values.push( value );
  19479. }
  19480. key = jsonKeys[ i ++ ];
  19481. } while ( key !== undefined );
  19482. }
  19483. }
  19484. };
  19485. /**
  19486. * Abstract base class of interpolants over parametric samples.
  19487. *
  19488. * The parameter domain is one dimensional, typically the time or a path
  19489. * along a curve defined by the data.
  19490. *
  19491. * The sample values can have any dimensionality and derived classes may
  19492. * apply special interpretations to the data.
  19493. *
  19494. * This class provides the interval seek in a Template Method, deferring
  19495. * the actual interpolation to derived classes.
  19496. *
  19497. * Time complexity is O(1) for linear access crossing at most two points
  19498. * and O(log N) for random access, where N is the number of positions.
  19499. *
  19500. * References:
  19501. *
  19502. * http://www.oodesign.com/template-method-pattern.html
  19503. *
  19504. * @author tschw
  19505. */
  19506. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19507. this.parameterPositions = parameterPositions;
  19508. this._cachedIndex = 0;
  19509. this.resultBuffer = resultBuffer !== undefined ?
  19510. resultBuffer : new sampleValues.constructor( sampleSize );
  19511. this.sampleValues = sampleValues;
  19512. this.valueSize = sampleSize;
  19513. }
  19514. Object.assign( Interpolant.prototype, {
  19515. evaluate: function ( t ) {
  19516. var pp = this.parameterPositions,
  19517. i1 = this._cachedIndex,
  19518. t1 = pp[ i1 ],
  19519. t0 = pp[ i1 - 1 ];
  19520. validate_interval: {
  19521. seek: {
  19522. var right;
  19523. linear_scan: {
  19524. //- See http://jsperf.com/comparison-to-undefined/3
  19525. //- slower code:
  19526. //-
  19527. //- if ( t >= t1 || t1 === undefined ) {
  19528. forward_scan: if ( ! ( t < t1 ) ) {
  19529. for ( var giveUpAt = i1 + 2; ; ) {
  19530. if ( t1 === undefined ) {
  19531. if ( t < t0 ) break forward_scan;
  19532. // after end
  19533. i1 = pp.length;
  19534. this._cachedIndex = i1;
  19535. return this.afterEnd_( i1 - 1, t, t0 );
  19536. }
  19537. if ( i1 === giveUpAt ) break; // this loop
  19538. t0 = t1;
  19539. t1 = pp[ ++ i1 ];
  19540. if ( t < t1 ) {
  19541. // we have arrived at the sought interval
  19542. break seek;
  19543. }
  19544. }
  19545. // prepare binary search on the right side of the index
  19546. right = pp.length;
  19547. break linear_scan;
  19548. }
  19549. //- slower code:
  19550. //- if ( t < t0 || t0 === undefined ) {
  19551. if ( ! ( t >= t0 ) ) {
  19552. // looping?
  19553. var t1global = pp[ 1 ];
  19554. if ( t < t1global ) {
  19555. i1 = 2; // + 1, using the scan for the details
  19556. t0 = t1global;
  19557. }
  19558. // linear reverse scan
  19559. for ( var giveUpAt = i1 - 2; ; ) {
  19560. if ( t0 === undefined ) {
  19561. // before start
  19562. this._cachedIndex = 0;
  19563. return this.beforeStart_( 0, t, t1 );
  19564. }
  19565. if ( i1 === giveUpAt ) break; // this loop
  19566. t1 = t0;
  19567. t0 = pp[ -- i1 - 1 ];
  19568. if ( t >= t0 ) {
  19569. // we have arrived at the sought interval
  19570. break seek;
  19571. }
  19572. }
  19573. // prepare binary search on the left side of the index
  19574. right = i1;
  19575. i1 = 0;
  19576. break linear_scan;
  19577. }
  19578. // the interval is valid
  19579. break validate_interval;
  19580. } // linear scan
  19581. // binary search
  19582. while ( i1 < right ) {
  19583. var mid = ( i1 + right ) >>> 1;
  19584. if ( t < pp[ mid ] ) {
  19585. right = mid;
  19586. } else {
  19587. i1 = mid + 1;
  19588. }
  19589. }
  19590. t1 = pp[ i1 ];
  19591. t0 = pp[ i1 - 1 ];
  19592. // check boundary cases, again
  19593. if ( t0 === undefined ) {
  19594. this._cachedIndex = 0;
  19595. return this.beforeStart_( 0, t, t1 );
  19596. }
  19597. if ( t1 === undefined ) {
  19598. i1 = pp.length;
  19599. this._cachedIndex = i1;
  19600. return this.afterEnd_( i1 - 1, t0, t );
  19601. }
  19602. } // seek
  19603. this._cachedIndex = i1;
  19604. this.intervalChanged_( i1, t0, t1 );
  19605. } // validate_interval
  19606. return this.interpolate_( i1, t0, t, t1 );
  19607. },
  19608. settings: null, // optional, subclass-specific settings structure
  19609. // Note: The indirection allows central control of many interpolants.
  19610. // --- Protected interface
  19611. DefaultSettings_: {},
  19612. getSettings_: function () {
  19613. return this.settings || this.DefaultSettings_;
  19614. },
  19615. copySampleValue_: function ( index ) {
  19616. // copies a sample value to the result buffer
  19617. var result = this.resultBuffer,
  19618. values = this.sampleValues,
  19619. stride = this.valueSize,
  19620. offset = index * stride;
  19621. for ( var i = 0; i !== stride; ++ i ) {
  19622. result[ i ] = values[ offset + i ];
  19623. }
  19624. return result;
  19625. },
  19626. // Template methods for derived classes:
  19627. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19628. throw new Error( 'call to abstract method' );
  19629. // implementations shall return this.resultBuffer
  19630. },
  19631. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19632. // empty
  19633. }
  19634. } );
  19635. //!\ DECLARE ALIAS AFTER assign prototype !
  19636. Object.assign( Interpolant.prototype, {
  19637. //( 0, t, t0 ), returns this.resultBuffer
  19638. beforeStart_: Interpolant.prototype.copySampleValue_,
  19639. //( N-1, tN-1, t ), returns this.resultBuffer
  19640. afterEnd_: Interpolant.prototype.copySampleValue_,
  19641. } );
  19642. /**
  19643. * Fast and simple cubic spline interpolant.
  19644. *
  19645. * It was derived from a Hermitian construction setting the first derivative
  19646. * at each sample position to the linear slope between neighboring positions
  19647. * over their parameter interval.
  19648. *
  19649. * @author tschw
  19650. */
  19651. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19652. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19653. this._weightPrev = - 0;
  19654. this._offsetPrev = - 0;
  19655. this._weightNext = - 0;
  19656. this._offsetNext = - 0;
  19657. }
  19658. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19659. constructor: CubicInterpolant,
  19660. DefaultSettings_: {
  19661. endingStart: ZeroCurvatureEnding,
  19662. endingEnd: ZeroCurvatureEnding
  19663. },
  19664. intervalChanged_: function ( i1, t0, t1 ) {
  19665. var pp = this.parameterPositions,
  19666. iPrev = i1 - 2,
  19667. iNext = i1 + 1,
  19668. tPrev = pp[ iPrev ],
  19669. tNext = pp[ iNext ];
  19670. if ( tPrev === undefined ) {
  19671. switch ( this.getSettings_().endingStart ) {
  19672. case ZeroSlopeEnding:
  19673. // f'(t0) = 0
  19674. iPrev = i1;
  19675. tPrev = 2 * t0 - t1;
  19676. break;
  19677. case WrapAroundEnding:
  19678. // use the other end of the curve
  19679. iPrev = pp.length - 2;
  19680. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19681. break;
  19682. default: // ZeroCurvatureEnding
  19683. // f''(t0) = 0 a.k.a. Natural Spline
  19684. iPrev = i1;
  19685. tPrev = t1;
  19686. }
  19687. }
  19688. if ( tNext === undefined ) {
  19689. switch ( this.getSettings_().endingEnd ) {
  19690. case ZeroSlopeEnding:
  19691. // f'(tN) = 0
  19692. iNext = i1;
  19693. tNext = 2 * t1 - t0;
  19694. break;
  19695. case WrapAroundEnding:
  19696. // use the other end of the curve
  19697. iNext = 1;
  19698. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19699. break;
  19700. default: // ZeroCurvatureEnding
  19701. // f''(tN) = 0, a.k.a. Natural Spline
  19702. iNext = i1 - 1;
  19703. tNext = t0;
  19704. }
  19705. }
  19706. var halfDt = ( t1 - t0 ) * 0.5,
  19707. stride = this.valueSize;
  19708. this._weightPrev = halfDt / ( t0 - tPrev );
  19709. this._weightNext = halfDt / ( tNext - t1 );
  19710. this._offsetPrev = iPrev * stride;
  19711. this._offsetNext = iNext * stride;
  19712. },
  19713. interpolate_: function ( i1, t0, t, t1 ) {
  19714. var result = this.resultBuffer,
  19715. values = this.sampleValues,
  19716. stride = this.valueSize,
  19717. o1 = i1 * stride, o0 = o1 - stride,
  19718. oP = this._offsetPrev, oN = this._offsetNext,
  19719. wP = this._weightPrev, wN = this._weightNext,
  19720. p = ( t - t0 ) / ( t1 - t0 ),
  19721. pp = p * p,
  19722. ppp = pp * p;
  19723. // evaluate polynomials
  19724. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19725. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19726. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19727. var sN = wN * ppp - wN * pp;
  19728. // combine data linearly
  19729. for ( var i = 0; i !== stride; ++ i ) {
  19730. result[ i ] =
  19731. sP * values[ oP + i ] +
  19732. s0 * values[ o0 + i ] +
  19733. s1 * values[ o1 + i ] +
  19734. sN * values[ oN + i ];
  19735. }
  19736. return result;
  19737. }
  19738. } );
  19739. /**
  19740. * @author tschw
  19741. */
  19742. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19743. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19744. }
  19745. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19746. constructor: LinearInterpolant,
  19747. interpolate_: function ( i1, t0, t, t1 ) {
  19748. var result = this.resultBuffer,
  19749. values = this.sampleValues,
  19750. stride = this.valueSize,
  19751. offset1 = i1 * stride,
  19752. offset0 = offset1 - stride,
  19753. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19754. weight0 = 1 - weight1;
  19755. for ( var i = 0; i !== stride; ++ i ) {
  19756. result[ i ] =
  19757. values[ offset0 + i ] * weight0 +
  19758. values[ offset1 + i ] * weight1;
  19759. }
  19760. return result;
  19761. }
  19762. } );
  19763. /**
  19764. *
  19765. * Interpolant that evaluates to the sample value at the position preceeding
  19766. * the parameter.
  19767. *
  19768. * @author tschw
  19769. */
  19770. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19771. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19772. }
  19773. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19774. constructor: DiscreteInterpolant,
  19775. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19776. return this.copySampleValue_( i1 - 1 );
  19777. }
  19778. } );
  19779. /**
  19780. *
  19781. * A timed sequence of keyframes for a specific property.
  19782. *
  19783. *
  19784. * @author Ben Houston / http://clara.io/
  19785. * @author David Sarno / http://lighthaus.us/
  19786. * @author tschw
  19787. */
  19788. function KeyframeTrack( name, times, values, interpolation ) {
  19789. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19790. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19791. this.name = name;
  19792. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19793. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19794. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19795. }
  19796. // Static methods
  19797. Object.assign( KeyframeTrack, {
  19798. // Serialization (in static context, because of constructor invocation
  19799. // and automatic invocation of .toJSON):
  19800. toJSON: function ( track ) {
  19801. var trackType = track.constructor;
  19802. var json;
  19803. // derived classes can define a static toJSON method
  19804. if ( trackType.toJSON !== undefined ) {
  19805. json = trackType.toJSON( track );
  19806. } else {
  19807. // by default, we assume the data can be serialized as-is
  19808. json = {
  19809. 'name': track.name,
  19810. 'times': AnimationUtils.convertArray( track.times, Array ),
  19811. 'values': AnimationUtils.convertArray( track.values, Array )
  19812. };
  19813. var interpolation = track.getInterpolation();
  19814. if ( interpolation !== track.DefaultInterpolation ) {
  19815. json.interpolation = interpolation;
  19816. }
  19817. }
  19818. json.type = track.ValueTypeName; // mandatory
  19819. return json;
  19820. }
  19821. } );
  19822. Object.assign( KeyframeTrack.prototype, {
  19823. constructor: KeyframeTrack,
  19824. TimeBufferType: Float32Array,
  19825. ValueBufferType: Float32Array,
  19826. DefaultInterpolation: InterpolateLinear,
  19827. InterpolantFactoryMethodDiscrete: function ( result ) {
  19828. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19829. },
  19830. InterpolantFactoryMethodLinear: function ( result ) {
  19831. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19832. },
  19833. InterpolantFactoryMethodSmooth: function ( result ) {
  19834. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19835. },
  19836. setInterpolation: function ( interpolation ) {
  19837. var factoryMethod;
  19838. switch ( interpolation ) {
  19839. case InterpolateDiscrete:
  19840. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19841. break;
  19842. case InterpolateLinear:
  19843. factoryMethod = this.InterpolantFactoryMethodLinear;
  19844. break;
  19845. case InterpolateSmooth:
  19846. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19847. break;
  19848. }
  19849. if ( factoryMethod === undefined ) {
  19850. var message = "unsupported interpolation for " +
  19851. this.ValueTypeName + " keyframe track named " + this.name;
  19852. if ( this.createInterpolant === undefined ) {
  19853. // fall back to default, unless the default itself is messed up
  19854. if ( interpolation !== this.DefaultInterpolation ) {
  19855. this.setInterpolation( this.DefaultInterpolation );
  19856. } else {
  19857. throw new Error( message ); // fatal, in this case
  19858. }
  19859. }
  19860. console.warn( 'THREE.KeyframeTrack:', message );
  19861. return this;
  19862. }
  19863. this.createInterpolant = factoryMethod;
  19864. return this;
  19865. },
  19866. getInterpolation: function () {
  19867. switch ( this.createInterpolant ) {
  19868. case this.InterpolantFactoryMethodDiscrete:
  19869. return InterpolateDiscrete;
  19870. case this.InterpolantFactoryMethodLinear:
  19871. return InterpolateLinear;
  19872. case this.InterpolantFactoryMethodSmooth:
  19873. return InterpolateSmooth;
  19874. }
  19875. },
  19876. getValueSize: function () {
  19877. return this.values.length / this.times.length;
  19878. },
  19879. // move all keyframes either forwards or backwards in time
  19880. shift: function ( timeOffset ) {
  19881. if ( timeOffset !== 0.0 ) {
  19882. var times = this.times;
  19883. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19884. times[ i ] += timeOffset;
  19885. }
  19886. }
  19887. return this;
  19888. },
  19889. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19890. scale: function ( timeScale ) {
  19891. if ( timeScale !== 1.0 ) {
  19892. var times = this.times;
  19893. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19894. times[ i ] *= timeScale;
  19895. }
  19896. }
  19897. return this;
  19898. },
  19899. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19900. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19901. trim: function ( startTime, endTime ) {
  19902. var times = this.times,
  19903. nKeys = times.length,
  19904. from = 0,
  19905. to = nKeys - 1;
  19906. while ( from !== nKeys && times[ from ] < startTime ) {
  19907. ++ from;
  19908. }
  19909. while ( to !== - 1 && times[ to ] > endTime ) {
  19910. -- to;
  19911. }
  19912. ++ to; // inclusive -> exclusive bound
  19913. if ( from !== 0 || to !== nKeys ) {
  19914. // empty tracks are forbidden, so keep at least one keyframe
  19915. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19916. var stride = this.getValueSize();
  19917. this.times = AnimationUtils.arraySlice( times, from, to );
  19918. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19919. }
  19920. return this;
  19921. },
  19922. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19923. validate: function () {
  19924. var valid = true;
  19925. var valueSize = this.getValueSize();
  19926. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19927. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19928. valid = false;
  19929. }
  19930. var times = this.times,
  19931. values = this.values,
  19932. nKeys = times.length;
  19933. if ( nKeys === 0 ) {
  19934. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19935. valid = false;
  19936. }
  19937. var prevTime = null;
  19938. for ( var i = 0; i !== nKeys; i ++ ) {
  19939. var currTime = times[ i ];
  19940. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19941. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19942. valid = false;
  19943. break;
  19944. }
  19945. if ( prevTime !== null && prevTime > currTime ) {
  19946. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19947. valid = false;
  19948. break;
  19949. }
  19950. prevTime = currTime;
  19951. }
  19952. if ( values !== undefined ) {
  19953. if ( AnimationUtils.isTypedArray( values ) ) {
  19954. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  19955. var value = values[ i ];
  19956. if ( isNaN( value ) ) {
  19957. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19958. valid = false;
  19959. break;
  19960. }
  19961. }
  19962. }
  19963. }
  19964. return valid;
  19965. },
  19966. // removes equivalent sequential keys as common in morph target sequences
  19967. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19968. optimize: function () {
  19969. var times = this.times,
  19970. values = this.values,
  19971. stride = this.getValueSize(),
  19972. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19973. writeIndex = 1,
  19974. lastIndex = times.length - 1;
  19975. for ( var i = 1; i < lastIndex; ++ i ) {
  19976. var keep = false;
  19977. var time = times[ i ];
  19978. var timeNext = times[ i + 1 ];
  19979. // remove adjacent keyframes scheduled at the same time
  19980. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  19981. if ( ! smoothInterpolation ) {
  19982. // remove unnecessary keyframes same as their neighbors
  19983. var offset = i * stride,
  19984. offsetP = offset - stride,
  19985. offsetN = offset + stride;
  19986. for ( var j = 0; j !== stride; ++ j ) {
  19987. var value = values[ offset + j ];
  19988. if ( value !== values[ offsetP + j ] ||
  19989. value !== values[ offsetN + j ] ) {
  19990. keep = true;
  19991. break;
  19992. }
  19993. }
  19994. } else {
  19995. keep = true;
  19996. }
  19997. }
  19998. // in-place compaction
  19999. if ( keep ) {
  20000. if ( i !== writeIndex ) {
  20001. times[ writeIndex ] = times[ i ];
  20002. var readOffset = i * stride,
  20003. writeOffset = writeIndex * stride;
  20004. for ( var j = 0; j !== stride; ++ j ) {
  20005. values[ writeOffset + j ] = values[ readOffset + j ];
  20006. }
  20007. }
  20008. ++ writeIndex;
  20009. }
  20010. }
  20011. // flush last keyframe (compaction looks ahead)
  20012. if ( lastIndex > 0 ) {
  20013. times[ writeIndex ] = times[ lastIndex ];
  20014. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20015. values[ writeOffset + j ] = values[ readOffset + j ];
  20016. }
  20017. ++ writeIndex;
  20018. }
  20019. if ( writeIndex !== times.length ) {
  20020. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20021. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20022. }
  20023. return this;
  20024. },
  20025. clone: function () {
  20026. var times = AnimationUtils.arraySlice( this.times, 0 );
  20027. var values = AnimationUtils.arraySlice( this.values, 0 );
  20028. var TypedKeyframeTrack = this.constructor;
  20029. var track = new TypedKeyframeTrack( this.name, times, values );
  20030. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20031. track.createInterpolant = this.createInterpolant;
  20032. return track;
  20033. }
  20034. } );
  20035. /**
  20036. *
  20037. * A Track of Boolean keyframe values.
  20038. *
  20039. *
  20040. * @author Ben Houston / http://clara.io/
  20041. * @author David Sarno / http://lighthaus.us/
  20042. * @author tschw
  20043. */
  20044. function BooleanKeyframeTrack( name, times, values ) {
  20045. KeyframeTrack.call( this, name, times, values );
  20046. }
  20047. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20048. constructor: BooleanKeyframeTrack,
  20049. ValueTypeName: 'bool',
  20050. ValueBufferType: Array,
  20051. DefaultInterpolation: InterpolateDiscrete,
  20052. InterpolantFactoryMethodLinear: undefined,
  20053. InterpolantFactoryMethodSmooth: undefined
  20054. // Note: Actually this track could have a optimized / compressed
  20055. // representation of a single value and a custom interpolant that
  20056. // computes "firstValue ^ isOdd( index )".
  20057. } );
  20058. /**
  20059. *
  20060. * A Track of keyframe values that represent color.
  20061. *
  20062. *
  20063. * @author Ben Houston / http://clara.io/
  20064. * @author David Sarno / http://lighthaus.us/
  20065. * @author tschw
  20066. */
  20067. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20068. KeyframeTrack.call( this, name, times, values, interpolation );
  20069. }
  20070. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20071. constructor: ColorKeyframeTrack,
  20072. ValueTypeName: 'color'
  20073. // ValueBufferType is inherited
  20074. // DefaultInterpolation is inherited
  20075. // Note: Very basic implementation and nothing special yet.
  20076. // However, this is the place for color space parameterization.
  20077. } );
  20078. /**
  20079. *
  20080. * A Track of numeric keyframe values.
  20081. *
  20082. * @author Ben Houston / http://clara.io/
  20083. * @author David Sarno / http://lighthaus.us/
  20084. * @author tschw
  20085. */
  20086. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20087. KeyframeTrack.call( this, name, times, values, interpolation );
  20088. }
  20089. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20090. constructor: NumberKeyframeTrack,
  20091. ValueTypeName: 'number'
  20092. // ValueBufferType is inherited
  20093. // DefaultInterpolation is inherited
  20094. } );
  20095. /**
  20096. * Spherical linear unit quaternion interpolant.
  20097. *
  20098. * @author tschw
  20099. */
  20100. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20101. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20102. }
  20103. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20104. constructor: QuaternionLinearInterpolant,
  20105. interpolate_: function ( i1, t0, t, t1 ) {
  20106. var result = this.resultBuffer,
  20107. values = this.sampleValues,
  20108. stride = this.valueSize,
  20109. offset = i1 * stride,
  20110. alpha = ( t - t0 ) / ( t1 - t0 );
  20111. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20112. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20113. }
  20114. return result;
  20115. }
  20116. } );
  20117. /**
  20118. *
  20119. * A Track of quaternion keyframe values.
  20120. *
  20121. * @author Ben Houston / http://clara.io/
  20122. * @author David Sarno / http://lighthaus.us/
  20123. * @author tschw
  20124. */
  20125. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20126. KeyframeTrack.call( this, name, times, values, interpolation );
  20127. }
  20128. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20129. constructor: QuaternionKeyframeTrack,
  20130. ValueTypeName: 'quaternion',
  20131. // ValueBufferType is inherited
  20132. DefaultInterpolation: InterpolateLinear,
  20133. InterpolantFactoryMethodLinear: function ( result ) {
  20134. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20135. },
  20136. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20137. } );
  20138. /**
  20139. *
  20140. * A Track that interpolates Strings
  20141. *
  20142. *
  20143. * @author Ben Houston / http://clara.io/
  20144. * @author David Sarno / http://lighthaus.us/
  20145. * @author tschw
  20146. */
  20147. function StringKeyframeTrack( name, times, values, interpolation ) {
  20148. KeyframeTrack.call( this, name, times, values, interpolation );
  20149. }
  20150. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20151. constructor: StringKeyframeTrack,
  20152. ValueTypeName: 'string',
  20153. ValueBufferType: Array,
  20154. DefaultInterpolation: InterpolateDiscrete,
  20155. InterpolantFactoryMethodLinear: undefined,
  20156. InterpolantFactoryMethodSmooth: undefined
  20157. } );
  20158. /**
  20159. *
  20160. * A Track of vectored keyframe values.
  20161. *
  20162. *
  20163. * @author Ben Houston / http://clara.io/
  20164. * @author David Sarno / http://lighthaus.us/
  20165. * @author tschw
  20166. */
  20167. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20168. KeyframeTrack.call( this, name, times, values, interpolation );
  20169. }
  20170. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20171. constructor: VectorKeyframeTrack,
  20172. ValueTypeName: 'vector'
  20173. // ValueBufferType is inherited
  20174. // DefaultInterpolation is inherited
  20175. } );
  20176. /**
  20177. *
  20178. * Reusable set of Tracks that represent an animation.
  20179. *
  20180. * @author Ben Houston / http://clara.io/
  20181. * @author David Sarno / http://lighthaus.us/
  20182. */
  20183. function AnimationClip( name, duration, tracks ) {
  20184. this.name = name;
  20185. this.tracks = tracks;
  20186. this.duration = ( duration !== undefined ) ? duration : - 1;
  20187. this.uuid = _Math.generateUUID();
  20188. // this means it should figure out its duration by scanning the tracks
  20189. if ( this.duration < 0 ) {
  20190. this.resetDuration();
  20191. }
  20192. }
  20193. function getTrackTypeForValueTypeName( typeName ) {
  20194. switch ( typeName.toLowerCase() ) {
  20195. case 'scalar':
  20196. case 'double':
  20197. case 'float':
  20198. case 'number':
  20199. case 'integer':
  20200. return NumberKeyframeTrack;
  20201. case 'vector':
  20202. case 'vector2':
  20203. case 'vector3':
  20204. case 'vector4':
  20205. return VectorKeyframeTrack;
  20206. case 'color':
  20207. return ColorKeyframeTrack;
  20208. case 'quaternion':
  20209. return QuaternionKeyframeTrack;
  20210. case 'bool':
  20211. case 'boolean':
  20212. return BooleanKeyframeTrack;
  20213. case 'string':
  20214. return StringKeyframeTrack;
  20215. }
  20216. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20217. }
  20218. function parseKeyframeTrack( json ) {
  20219. if ( json.type === undefined ) {
  20220. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20221. }
  20222. var trackType = getTrackTypeForValueTypeName( json.type );
  20223. if ( json.times === undefined ) {
  20224. var times = [], values = [];
  20225. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20226. json.times = times;
  20227. json.values = values;
  20228. }
  20229. // derived classes can define a static parse method
  20230. if ( trackType.parse !== undefined ) {
  20231. return trackType.parse( json );
  20232. } else {
  20233. // by default, we assume a constructor compatible with the base
  20234. return new trackType( json.name, json.times, json.values, json.interpolation );
  20235. }
  20236. }
  20237. Object.assign( AnimationClip, {
  20238. parse: function ( json ) {
  20239. var tracks = [],
  20240. jsonTracks = json.tracks,
  20241. frameTime = 1.0 / ( json.fps || 1.0 );
  20242. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20243. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20244. }
  20245. return new AnimationClip( json.name, json.duration, tracks );
  20246. },
  20247. toJSON: function ( clip ) {
  20248. var tracks = [],
  20249. clipTracks = clip.tracks;
  20250. var json = {
  20251. 'name': clip.name,
  20252. 'duration': clip.duration,
  20253. 'tracks': tracks,
  20254. 'uuid': clip.uuid
  20255. };
  20256. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20257. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20258. }
  20259. return json;
  20260. },
  20261. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20262. var numMorphTargets = morphTargetSequence.length;
  20263. var tracks = [];
  20264. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20265. var times = [];
  20266. var values = [];
  20267. times.push(
  20268. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20269. i,
  20270. ( i + 1 ) % numMorphTargets );
  20271. values.push( 0, 1, 0 );
  20272. var order = AnimationUtils.getKeyframeOrder( times );
  20273. times = AnimationUtils.sortedArray( times, 1, order );
  20274. values = AnimationUtils.sortedArray( values, 1, order );
  20275. // if there is a key at the first frame, duplicate it as the
  20276. // last frame as well for perfect loop.
  20277. if ( ! noLoop && times[ 0 ] === 0 ) {
  20278. times.push( numMorphTargets );
  20279. values.push( values[ 0 ] );
  20280. }
  20281. tracks.push(
  20282. new NumberKeyframeTrack(
  20283. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20284. times, values
  20285. ).scale( 1.0 / fps ) );
  20286. }
  20287. return new AnimationClip( name, - 1, tracks );
  20288. },
  20289. findByName: function ( objectOrClipArray, name ) {
  20290. var clipArray = objectOrClipArray;
  20291. if ( ! Array.isArray( objectOrClipArray ) ) {
  20292. var o = objectOrClipArray;
  20293. clipArray = o.geometry && o.geometry.animations || o.animations;
  20294. }
  20295. for ( var i = 0; i < clipArray.length; i ++ ) {
  20296. if ( clipArray[ i ].name === name ) {
  20297. return clipArray[ i ];
  20298. }
  20299. }
  20300. return null;
  20301. },
  20302. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20303. var animationToMorphTargets = {};
  20304. // tested with https://regex101.com/ on trick sequences
  20305. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20306. var pattern = /^([\w-]*?)([\d]+)$/;
  20307. // sort morph target names into animation groups based
  20308. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20309. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20310. var morphTarget = morphTargets[ i ];
  20311. var parts = morphTarget.name.match( pattern );
  20312. if ( parts && parts.length > 1 ) {
  20313. var name = parts[ 1 ];
  20314. var animationMorphTargets = animationToMorphTargets[ name ];
  20315. if ( ! animationMorphTargets ) {
  20316. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20317. }
  20318. animationMorphTargets.push( morphTarget );
  20319. }
  20320. }
  20321. var clips = [];
  20322. for ( var name in animationToMorphTargets ) {
  20323. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20324. }
  20325. return clips;
  20326. },
  20327. // parse the animation.hierarchy format
  20328. parseAnimation: function ( animation, bones ) {
  20329. if ( ! animation ) {
  20330. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20331. return null;
  20332. }
  20333. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20334. // only return track if there are actually keys.
  20335. if ( animationKeys.length !== 0 ) {
  20336. var times = [];
  20337. var values = [];
  20338. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20339. // empty keys are filtered out, so check again
  20340. if ( times.length !== 0 ) {
  20341. destTracks.push( new trackType( trackName, times, values ) );
  20342. }
  20343. }
  20344. };
  20345. var tracks = [];
  20346. var clipName = animation.name || 'default';
  20347. // automatic length determination in AnimationClip.
  20348. var duration = animation.length || - 1;
  20349. var fps = animation.fps || 30;
  20350. var hierarchyTracks = animation.hierarchy || [];
  20351. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20352. var animationKeys = hierarchyTracks[ h ].keys;
  20353. // skip empty tracks
  20354. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20355. // process morph targets
  20356. if ( animationKeys[ 0 ].morphTargets ) {
  20357. // figure out all morph targets used in this track
  20358. var morphTargetNames = {};
  20359. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20360. if ( animationKeys[ k ].morphTargets ) {
  20361. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20362. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20363. }
  20364. }
  20365. }
  20366. // create a track for each morph target with all zero
  20367. // morphTargetInfluences except for the keys in which
  20368. // the morphTarget is named.
  20369. for ( var morphTargetName in morphTargetNames ) {
  20370. var times = [];
  20371. var values = [];
  20372. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20373. var animationKey = animationKeys[ k ];
  20374. times.push( animationKey.time );
  20375. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20376. }
  20377. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20378. }
  20379. duration = morphTargetNames.length * ( fps || 1.0 );
  20380. } else {
  20381. // ...assume skeletal animation
  20382. var boneName = '.bones[' + bones[ h ].name + ']';
  20383. addNonemptyTrack(
  20384. VectorKeyframeTrack, boneName + '.position',
  20385. animationKeys, 'pos', tracks );
  20386. addNonemptyTrack(
  20387. QuaternionKeyframeTrack, boneName + '.quaternion',
  20388. animationKeys, 'rot', tracks );
  20389. addNonemptyTrack(
  20390. VectorKeyframeTrack, boneName + '.scale',
  20391. animationKeys, 'scl', tracks );
  20392. }
  20393. }
  20394. if ( tracks.length === 0 ) {
  20395. return null;
  20396. }
  20397. var clip = new AnimationClip( clipName, duration, tracks );
  20398. return clip;
  20399. }
  20400. } );
  20401. Object.assign( AnimationClip.prototype, {
  20402. resetDuration: function () {
  20403. var tracks = this.tracks, duration = 0;
  20404. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20405. var track = this.tracks[ i ];
  20406. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20407. }
  20408. this.duration = duration;
  20409. return this;
  20410. },
  20411. trim: function () {
  20412. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20413. this.tracks[ i ].trim( 0, this.duration );
  20414. }
  20415. return this;
  20416. },
  20417. validate: function () {
  20418. var valid = true;
  20419. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20420. valid = valid && this.tracks[ i ].validate();
  20421. }
  20422. return valid;
  20423. },
  20424. optimize: function () {
  20425. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20426. this.tracks[ i ].optimize();
  20427. }
  20428. return this;
  20429. },
  20430. clone: function () {
  20431. var tracks = [];
  20432. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20433. tracks.push( this.tracks[ i ].clone() );
  20434. }
  20435. return new AnimationClip( this.name, this.duration, tracks );
  20436. }
  20437. } );
  20438. /**
  20439. * @author mrdoob / http://mrdoob.com/
  20440. */
  20441. var Cache = {
  20442. enabled: false,
  20443. files: {},
  20444. add: function ( key, file ) {
  20445. if ( this.enabled === false ) return;
  20446. // console.log( 'THREE.Cache', 'Adding key:', key );
  20447. this.files[ key ] = file;
  20448. },
  20449. get: function ( key ) {
  20450. if ( this.enabled === false ) return;
  20451. // console.log( 'THREE.Cache', 'Checking key:', key );
  20452. return this.files[ key ];
  20453. },
  20454. remove: function ( key ) {
  20455. delete this.files[ key ];
  20456. },
  20457. clear: function () {
  20458. this.files = {};
  20459. }
  20460. };
  20461. /**
  20462. * @author mrdoob / http://mrdoob.com/
  20463. */
  20464. function LoadingManager( onLoad, onProgress, onError ) {
  20465. var scope = this;
  20466. var isLoading = false;
  20467. var itemsLoaded = 0;
  20468. var itemsTotal = 0;
  20469. var urlModifier = undefined;
  20470. // Refer to #5689 for the reason why we don't set .onStart
  20471. // in the constructor
  20472. this.onStart = undefined;
  20473. this.onLoad = onLoad;
  20474. this.onProgress = onProgress;
  20475. this.onError = onError;
  20476. this.itemStart = function ( url ) {
  20477. itemsTotal ++;
  20478. if ( isLoading === false ) {
  20479. if ( scope.onStart !== undefined ) {
  20480. scope.onStart( url, itemsLoaded, itemsTotal );
  20481. }
  20482. }
  20483. isLoading = true;
  20484. };
  20485. this.itemEnd = function ( url ) {
  20486. itemsLoaded ++;
  20487. if ( scope.onProgress !== undefined ) {
  20488. scope.onProgress( url, itemsLoaded, itemsTotal );
  20489. }
  20490. if ( itemsLoaded === itemsTotal ) {
  20491. isLoading = false;
  20492. if ( scope.onLoad !== undefined ) {
  20493. scope.onLoad();
  20494. }
  20495. }
  20496. };
  20497. this.itemError = function ( url ) {
  20498. if ( scope.onError !== undefined ) {
  20499. scope.onError( url );
  20500. }
  20501. };
  20502. this.resolveURL = function ( url ) {
  20503. if ( urlModifier ) {
  20504. return urlModifier( url );
  20505. }
  20506. return url;
  20507. };
  20508. this.setURLModifier = function ( transform ) {
  20509. urlModifier = transform;
  20510. return this;
  20511. };
  20512. }
  20513. var DefaultLoadingManager = new LoadingManager();
  20514. /**
  20515. * @author mrdoob / http://mrdoob.com/
  20516. */
  20517. var loading = {};
  20518. function FileLoader( manager ) {
  20519. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20520. }
  20521. Object.assign( FileLoader.prototype, {
  20522. load: function ( url, onLoad, onProgress, onError ) {
  20523. if ( url === undefined ) url = '';
  20524. if ( this.path !== undefined ) url = this.path + url;
  20525. url = this.manager.resolveURL( url );
  20526. var scope = this;
  20527. var cached = Cache.get( url );
  20528. if ( cached !== undefined ) {
  20529. scope.manager.itemStart( url );
  20530. setTimeout( function () {
  20531. if ( onLoad ) onLoad( cached );
  20532. scope.manager.itemEnd( url );
  20533. }, 0 );
  20534. return cached;
  20535. }
  20536. // Check if request is duplicate
  20537. if ( loading[ url ] !== undefined ) {
  20538. loading[ url ].push( {
  20539. onLoad: onLoad,
  20540. onProgress: onProgress,
  20541. onError: onError
  20542. } );
  20543. return;
  20544. }
  20545. // Check for data: URI
  20546. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20547. var dataUriRegexResult = url.match( dataUriRegex );
  20548. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20549. if ( dataUriRegexResult ) {
  20550. var mimeType = dataUriRegexResult[ 1 ];
  20551. var isBase64 = !! dataUriRegexResult[ 2 ];
  20552. var data = dataUriRegexResult[ 3 ];
  20553. data = decodeURIComponent( data );
  20554. if ( isBase64 ) data = atob( data );
  20555. try {
  20556. var response;
  20557. var responseType = ( this.responseType || '' ).toLowerCase();
  20558. switch ( responseType ) {
  20559. case 'arraybuffer':
  20560. case 'blob':
  20561. var view = new Uint8Array( data.length );
  20562. for ( var i = 0; i < data.length; i ++ ) {
  20563. view[ i ] = data.charCodeAt( i );
  20564. }
  20565. if ( responseType === 'blob' ) {
  20566. response = new Blob( [ view.buffer ], { type: mimeType } );
  20567. } else {
  20568. response = view.buffer;
  20569. }
  20570. break;
  20571. case 'document':
  20572. var parser = new DOMParser();
  20573. response = parser.parseFromString( data, mimeType );
  20574. break;
  20575. case 'json':
  20576. response = JSON.parse( data );
  20577. break;
  20578. default: // 'text' or other
  20579. response = data;
  20580. break;
  20581. }
  20582. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20583. setTimeout( function () {
  20584. if ( onLoad ) onLoad( response );
  20585. scope.manager.itemEnd( url );
  20586. }, 0 );
  20587. } catch ( error ) {
  20588. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20589. setTimeout( function () {
  20590. if ( onError ) onError( error );
  20591. scope.manager.itemError( url );
  20592. scope.manager.itemEnd( url );
  20593. }, 0 );
  20594. }
  20595. } else {
  20596. // Initialise array for duplicate requests
  20597. loading[ url ] = [];
  20598. loading[ url ].push( {
  20599. onLoad: onLoad,
  20600. onProgress: onProgress,
  20601. onError: onError
  20602. } );
  20603. var request = new XMLHttpRequest();
  20604. request.open( 'GET', url, true );
  20605. request.addEventListener( 'load', function ( event ) {
  20606. var response = this.response;
  20607. Cache.add( url, response );
  20608. var callbacks = loading[ url ];
  20609. delete loading[ url ];
  20610. if ( this.status === 200 || this.status === 0 ) {
  20611. // Some browsers return HTTP Status 0 when using non-http protocol
  20612. // e.g. 'file://' or 'data://'. Handle as success.
  20613. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20614. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20615. var callback = callbacks[ i ];
  20616. if ( callback.onLoad ) callback.onLoad( response );
  20617. }
  20618. scope.manager.itemEnd( url );
  20619. } else {
  20620. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20621. var callback = callbacks[ i ];
  20622. if ( callback.onError ) callback.onError( event );
  20623. }
  20624. scope.manager.itemError( url );
  20625. scope.manager.itemEnd( url );
  20626. }
  20627. }, false );
  20628. request.addEventListener( 'progress', function ( event ) {
  20629. var callbacks = loading[ url ];
  20630. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20631. var callback = callbacks[ i ];
  20632. if ( callback.onProgress ) callback.onProgress( event );
  20633. }
  20634. }, false );
  20635. request.addEventListener( 'error', function ( event ) {
  20636. var callbacks = loading[ url ];
  20637. delete loading[ url ];
  20638. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20639. var callback = callbacks[ i ];
  20640. if ( callback.onError ) callback.onError( event );
  20641. }
  20642. scope.manager.itemError( url );
  20643. scope.manager.itemEnd( url );
  20644. }, false );
  20645. request.addEventListener( 'abort', function ( event ) {
  20646. var callbacks = loading[ url ];
  20647. delete loading[ url ];
  20648. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20649. var callback = callbacks[ i ];
  20650. if ( callback.onError ) callback.onError( event );
  20651. }
  20652. scope.manager.itemError( url );
  20653. scope.manager.itemEnd( url );
  20654. }, false );
  20655. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20656. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20657. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20658. for ( var header in this.requestHeader ) {
  20659. request.setRequestHeader( header, this.requestHeader[ header ] );
  20660. }
  20661. request.send( null );
  20662. }
  20663. scope.manager.itemStart( url );
  20664. return request;
  20665. },
  20666. setPath: function ( value ) {
  20667. this.path = value;
  20668. return this;
  20669. },
  20670. setResponseType: function ( value ) {
  20671. this.responseType = value;
  20672. return this;
  20673. },
  20674. setWithCredentials: function ( value ) {
  20675. this.withCredentials = value;
  20676. return this;
  20677. },
  20678. setMimeType: function ( value ) {
  20679. this.mimeType = value;
  20680. return this;
  20681. },
  20682. setRequestHeader: function ( value ) {
  20683. this.requestHeader = value;
  20684. return this;
  20685. }
  20686. } );
  20687. /**
  20688. * @author bhouston / http://clara.io/
  20689. */
  20690. function AnimationLoader( manager ) {
  20691. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20692. }
  20693. Object.assign( AnimationLoader.prototype, {
  20694. load: function ( url, onLoad, onProgress, onError ) {
  20695. var scope = this;
  20696. var loader = new FileLoader( scope.manager );
  20697. loader.setPath( scope.path );
  20698. loader.load( url, function ( text ) {
  20699. onLoad( scope.parse( JSON.parse( text ) ) );
  20700. }, onProgress, onError );
  20701. },
  20702. parse: function ( json ) {
  20703. var animations = [];
  20704. for ( var i = 0; i < json.length; i ++ ) {
  20705. var clip = AnimationClip.parse( json[ i ] );
  20706. animations.push( clip );
  20707. }
  20708. return animations;
  20709. },
  20710. setPath: function ( value ) {
  20711. this.path = value;
  20712. return this;
  20713. }
  20714. } );
  20715. /**
  20716. * @author mrdoob / http://mrdoob.com/
  20717. *
  20718. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20719. */
  20720. function CompressedTextureLoader( manager ) {
  20721. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20722. // override in sub classes
  20723. this._parser = null;
  20724. }
  20725. Object.assign( CompressedTextureLoader.prototype, {
  20726. load: function ( url, onLoad, onProgress, onError ) {
  20727. var scope = this;
  20728. var images = [];
  20729. var texture = new CompressedTexture();
  20730. texture.image = images;
  20731. var loader = new FileLoader( this.manager );
  20732. loader.setPath( this.path );
  20733. loader.setResponseType( 'arraybuffer' );
  20734. function loadTexture( i ) {
  20735. loader.load( url[ i ], function ( buffer ) {
  20736. var texDatas = scope._parser( buffer, true );
  20737. images[ i ] = {
  20738. width: texDatas.width,
  20739. height: texDatas.height,
  20740. format: texDatas.format,
  20741. mipmaps: texDatas.mipmaps
  20742. };
  20743. loaded += 1;
  20744. if ( loaded === 6 ) {
  20745. if ( texDatas.mipmapCount === 1 )
  20746. texture.minFilter = LinearFilter;
  20747. texture.format = texDatas.format;
  20748. texture.needsUpdate = true;
  20749. if ( onLoad ) onLoad( texture );
  20750. }
  20751. }, onProgress, onError );
  20752. }
  20753. if ( Array.isArray( url ) ) {
  20754. var loaded = 0;
  20755. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20756. loadTexture( i );
  20757. }
  20758. } else {
  20759. // compressed cubemap texture stored in a single DDS file
  20760. loader.load( url, function ( buffer ) {
  20761. var texDatas = scope._parser( buffer, true );
  20762. if ( texDatas.isCubemap ) {
  20763. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20764. for ( var f = 0; f < faces; f ++ ) {
  20765. images[ f ] = { mipmaps: [] };
  20766. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20767. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20768. images[ f ].format = texDatas.format;
  20769. images[ f ].width = texDatas.width;
  20770. images[ f ].height = texDatas.height;
  20771. }
  20772. }
  20773. } else {
  20774. texture.image.width = texDatas.width;
  20775. texture.image.height = texDatas.height;
  20776. texture.mipmaps = texDatas.mipmaps;
  20777. }
  20778. if ( texDatas.mipmapCount === 1 ) {
  20779. texture.minFilter = LinearFilter;
  20780. }
  20781. texture.format = texDatas.format;
  20782. texture.needsUpdate = true;
  20783. if ( onLoad ) onLoad( texture );
  20784. }, onProgress, onError );
  20785. }
  20786. return texture;
  20787. },
  20788. setPath: function ( value ) {
  20789. this.path = value;
  20790. return this;
  20791. }
  20792. } );
  20793. /**
  20794. * @author Nikos M. / https://github.com/foo123/
  20795. *
  20796. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20797. */
  20798. function DataTextureLoader( manager ) {
  20799. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20800. // override in sub classes
  20801. this._parser = null;
  20802. }
  20803. Object.assign( DataTextureLoader.prototype, {
  20804. load: function ( url, onLoad, onProgress, onError ) {
  20805. var scope = this;
  20806. var texture = new DataTexture();
  20807. var loader = new FileLoader( this.manager );
  20808. loader.setResponseType( 'arraybuffer' );
  20809. loader.setPath( this.path );
  20810. loader.load( url, function ( buffer ) {
  20811. var texData = scope._parser( buffer );
  20812. if ( ! texData ) return;
  20813. if ( texData.image !== undefined ) {
  20814. texture.image = texData.image;
  20815. } else if ( texData.data !== undefined ) {
  20816. texture.image.width = texData.width;
  20817. texture.image.height = texData.height;
  20818. texture.image.data = texData.data;
  20819. }
  20820. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20821. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20822. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20823. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20824. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20825. if ( texData.format !== undefined ) {
  20826. texture.format = texData.format;
  20827. }
  20828. if ( texData.type !== undefined ) {
  20829. texture.type = texData.type;
  20830. }
  20831. if ( texData.mipmaps !== undefined ) {
  20832. texture.mipmaps = texData.mipmaps;
  20833. }
  20834. if ( texData.mipmapCount === 1 ) {
  20835. texture.minFilter = LinearFilter;
  20836. }
  20837. texture.needsUpdate = true;
  20838. if ( onLoad ) onLoad( texture, texData );
  20839. }, onProgress, onError );
  20840. return texture;
  20841. },
  20842. setPath: function ( value ) {
  20843. this.path = value;
  20844. return this;
  20845. }
  20846. } );
  20847. /**
  20848. * @author mrdoob / http://mrdoob.com/
  20849. */
  20850. function ImageLoader( manager ) {
  20851. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20852. }
  20853. Object.assign( ImageLoader.prototype, {
  20854. crossOrigin: 'anonymous',
  20855. load: function ( url, onLoad, onProgress, onError ) {
  20856. if ( url === undefined ) url = '';
  20857. if ( this.path !== undefined ) url = this.path + url;
  20858. url = this.manager.resolveURL( url );
  20859. var scope = this;
  20860. var cached = Cache.get( url );
  20861. if ( cached !== undefined ) {
  20862. scope.manager.itemStart( url );
  20863. setTimeout( function () {
  20864. if ( onLoad ) onLoad( cached );
  20865. scope.manager.itemEnd( url );
  20866. }, 0 );
  20867. return cached;
  20868. }
  20869. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20870. function onImageLoad() {
  20871. image.removeEventListener( 'load', onImageLoad, false );
  20872. image.removeEventListener( 'error', onImageError, false );
  20873. Cache.add( url, this );
  20874. if ( onLoad ) onLoad( this );
  20875. scope.manager.itemEnd( url );
  20876. }
  20877. function onImageError( event ) {
  20878. image.removeEventListener( 'load', onImageLoad, false );
  20879. image.removeEventListener( 'error', onImageError, false );
  20880. if ( onError ) onError( event );
  20881. scope.manager.itemError( url );
  20882. scope.manager.itemEnd( url );
  20883. }
  20884. image.addEventListener( 'load', onImageLoad, false );
  20885. image.addEventListener( 'error', onImageError, false );
  20886. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20887. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20888. }
  20889. scope.manager.itemStart( url );
  20890. image.src = url;
  20891. return image;
  20892. },
  20893. setCrossOrigin: function ( value ) {
  20894. this.crossOrigin = value;
  20895. return this;
  20896. },
  20897. setPath: function ( value ) {
  20898. this.path = value;
  20899. return this;
  20900. }
  20901. } );
  20902. /**
  20903. * @author mrdoob / http://mrdoob.com/
  20904. */
  20905. function CubeTextureLoader( manager ) {
  20906. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20907. }
  20908. Object.assign( CubeTextureLoader.prototype, {
  20909. crossOrigin: 'anonymous',
  20910. load: function ( urls, onLoad, onProgress, onError ) {
  20911. var texture = new CubeTexture();
  20912. var loader = new ImageLoader( this.manager );
  20913. loader.setCrossOrigin( this.crossOrigin );
  20914. loader.setPath( this.path );
  20915. var loaded = 0;
  20916. function loadTexture( i ) {
  20917. loader.load( urls[ i ], function ( image ) {
  20918. texture.images[ i ] = image;
  20919. loaded ++;
  20920. if ( loaded === 6 ) {
  20921. texture.needsUpdate = true;
  20922. if ( onLoad ) onLoad( texture );
  20923. }
  20924. }, undefined, onError );
  20925. }
  20926. for ( var i = 0; i < urls.length; ++ i ) {
  20927. loadTexture( i );
  20928. }
  20929. return texture;
  20930. },
  20931. setCrossOrigin: function ( value ) {
  20932. this.crossOrigin = value;
  20933. return this;
  20934. },
  20935. setPath: function ( value ) {
  20936. this.path = value;
  20937. return this;
  20938. }
  20939. } );
  20940. /**
  20941. * @author mrdoob / http://mrdoob.com/
  20942. */
  20943. function TextureLoader( manager ) {
  20944. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20945. }
  20946. Object.assign( TextureLoader.prototype, {
  20947. crossOrigin: 'anonymous',
  20948. load: function ( url, onLoad, onProgress, onError ) {
  20949. var texture = new Texture();
  20950. var loader = new ImageLoader( this.manager );
  20951. loader.setCrossOrigin( this.crossOrigin );
  20952. loader.setPath( this.path );
  20953. loader.load( url, function ( image ) {
  20954. texture.image = image;
  20955. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20956. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20957. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20958. texture.needsUpdate = true;
  20959. if ( onLoad !== undefined ) {
  20960. onLoad( texture );
  20961. }
  20962. }, onProgress, onError );
  20963. return texture;
  20964. },
  20965. setCrossOrigin: function ( value ) {
  20966. this.crossOrigin = value;
  20967. return this;
  20968. },
  20969. setPath: function ( value ) {
  20970. this.path = value;
  20971. return this;
  20972. }
  20973. } );
  20974. /**
  20975. * @author zz85 / http://www.lab4games.net/zz85/blog
  20976. * Extensible curve object
  20977. *
  20978. * Some common of curve methods:
  20979. * .getPoint( t, optionalTarget ), .getTangent( t )
  20980. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  20981. * .getPoints(), .getSpacedPoints()
  20982. * .getLength()
  20983. * .updateArcLengths()
  20984. *
  20985. * This following curves inherit from THREE.Curve:
  20986. *
  20987. * -- 2D curves --
  20988. * THREE.ArcCurve
  20989. * THREE.CubicBezierCurve
  20990. * THREE.EllipseCurve
  20991. * THREE.LineCurve
  20992. * THREE.QuadraticBezierCurve
  20993. * THREE.SplineCurve
  20994. *
  20995. * -- 3D curves --
  20996. * THREE.CatmullRomCurve3
  20997. * THREE.CubicBezierCurve3
  20998. * THREE.LineCurve3
  20999. * THREE.QuadraticBezierCurve3
  21000. *
  21001. * A series of curves can be represented as a THREE.CurvePath.
  21002. *
  21003. **/
  21004. /**************************************************************
  21005. * Abstract Curve base class
  21006. **************************************************************/
  21007. function Curve() {
  21008. this.type = 'Curve';
  21009. this.arcLengthDivisions = 200;
  21010. }
  21011. Object.assign( Curve.prototype, {
  21012. // Virtual base class method to overwrite and implement in subclasses
  21013. // - t [0 .. 1]
  21014. getPoint: function ( /* t, optionalTarget */ ) {
  21015. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21016. return null;
  21017. },
  21018. // Get point at relative position in curve according to arc length
  21019. // - u [0 .. 1]
  21020. getPointAt: function ( u, optionalTarget ) {
  21021. var t = this.getUtoTmapping( u );
  21022. return this.getPoint( t, optionalTarget );
  21023. },
  21024. // Get sequence of points using getPoint( t )
  21025. getPoints: function ( divisions ) {
  21026. if ( divisions === undefined ) divisions = 5;
  21027. var points = [];
  21028. for ( var d = 0; d <= divisions; d ++ ) {
  21029. points.push( this.getPoint( d / divisions ) );
  21030. }
  21031. return points;
  21032. },
  21033. // Get sequence of points using getPointAt( u )
  21034. getSpacedPoints: function ( divisions ) {
  21035. if ( divisions === undefined ) divisions = 5;
  21036. var points = [];
  21037. for ( var d = 0; d <= divisions; d ++ ) {
  21038. points.push( this.getPointAt( d / divisions ) );
  21039. }
  21040. return points;
  21041. },
  21042. // Get total curve arc length
  21043. getLength: function () {
  21044. var lengths = this.getLengths();
  21045. return lengths[ lengths.length - 1 ];
  21046. },
  21047. // Get list of cumulative segment lengths
  21048. getLengths: function ( divisions ) {
  21049. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21050. if ( this.cacheArcLengths &&
  21051. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21052. ! this.needsUpdate ) {
  21053. return this.cacheArcLengths;
  21054. }
  21055. this.needsUpdate = false;
  21056. var cache = [];
  21057. var current, last = this.getPoint( 0 );
  21058. var p, sum = 0;
  21059. cache.push( 0 );
  21060. for ( p = 1; p <= divisions; p ++ ) {
  21061. current = this.getPoint( p / divisions );
  21062. sum += current.distanceTo( last );
  21063. cache.push( sum );
  21064. last = current;
  21065. }
  21066. this.cacheArcLengths = cache;
  21067. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21068. },
  21069. updateArcLengths: function () {
  21070. this.needsUpdate = true;
  21071. this.getLengths();
  21072. },
  21073. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21074. getUtoTmapping: function ( u, distance ) {
  21075. var arcLengths = this.getLengths();
  21076. var i = 0, il = arcLengths.length;
  21077. var targetArcLength; // The targeted u distance value to get
  21078. if ( distance ) {
  21079. targetArcLength = distance;
  21080. } else {
  21081. targetArcLength = u * arcLengths[ il - 1 ];
  21082. }
  21083. // binary search for the index with largest value smaller than target u distance
  21084. var low = 0, high = il - 1, comparison;
  21085. while ( low <= high ) {
  21086. 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
  21087. comparison = arcLengths[ i ] - targetArcLength;
  21088. if ( comparison < 0 ) {
  21089. low = i + 1;
  21090. } else if ( comparison > 0 ) {
  21091. high = i - 1;
  21092. } else {
  21093. high = i;
  21094. break;
  21095. // DONE
  21096. }
  21097. }
  21098. i = high;
  21099. if ( arcLengths[ i ] === targetArcLength ) {
  21100. return i / ( il - 1 );
  21101. }
  21102. // we could get finer grain at lengths, or use simple interpolation between two points
  21103. var lengthBefore = arcLengths[ i ];
  21104. var lengthAfter = arcLengths[ i + 1 ];
  21105. var segmentLength = lengthAfter - lengthBefore;
  21106. // determine where we are between the 'before' and 'after' points
  21107. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21108. // add that fractional amount to t
  21109. var t = ( i + segmentFraction ) / ( il - 1 );
  21110. return t;
  21111. },
  21112. // Returns a unit vector tangent at t
  21113. // In case any sub curve does not implement its tangent derivation,
  21114. // 2 points a small delta apart will be used to find its gradient
  21115. // which seems to give a reasonable approximation
  21116. getTangent: function ( t ) {
  21117. var delta = 0.0001;
  21118. var t1 = t - delta;
  21119. var t2 = t + delta;
  21120. // Capping in case of danger
  21121. if ( t1 < 0 ) t1 = 0;
  21122. if ( t2 > 1 ) t2 = 1;
  21123. var pt1 = this.getPoint( t1 );
  21124. var pt2 = this.getPoint( t2 );
  21125. var vec = pt2.clone().sub( pt1 );
  21126. return vec.normalize();
  21127. },
  21128. getTangentAt: function ( u ) {
  21129. var t = this.getUtoTmapping( u );
  21130. return this.getTangent( t );
  21131. },
  21132. computeFrenetFrames: function ( segments, closed ) {
  21133. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21134. var normal = new Vector3();
  21135. var tangents = [];
  21136. var normals = [];
  21137. var binormals = [];
  21138. var vec = new Vector3();
  21139. var mat = new Matrix4();
  21140. var i, u, theta;
  21141. // compute the tangent vectors for each segment on the curve
  21142. for ( i = 0; i <= segments; i ++ ) {
  21143. u = i / segments;
  21144. tangents[ i ] = this.getTangentAt( u );
  21145. tangents[ i ].normalize();
  21146. }
  21147. // select an initial normal vector perpendicular to the first tangent vector,
  21148. // and in the direction of the minimum tangent xyz component
  21149. normals[ 0 ] = new Vector3();
  21150. binormals[ 0 ] = new Vector3();
  21151. var min = Number.MAX_VALUE;
  21152. var tx = Math.abs( tangents[ 0 ].x );
  21153. var ty = Math.abs( tangents[ 0 ].y );
  21154. var tz = Math.abs( tangents[ 0 ].z );
  21155. if ( tx <= min ) {
  21156. min = tx;
  21157. normal.set( 1, 0, 0 );
  21158. }
  21159. if ( ty <= min ) {
  21160. min = ty;
  21161. normal.set( 0, 1, 0 );
  21162. }
  21163. if ( tz <= min ) {
  21164. normal.set( 0, 0, 1 );
  21165. }
  21166. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21167. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21168. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21169. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21170. for ( i = 1; i <= segments; i ++ ) {
  21171. normals[ i ] = normals[ i - 1 ].clone();
  21172. binormals[ i ] = binormals[ i - 1 ].clone();
  21173. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21174. if ( vec.length() > Number.EPSILON ) {
  21175. vec.normalize();
  21176. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21177. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21178. }
  21179. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21180. }
  21181. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21182. if ( closed === true ) {
  21183. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21184. theta /= segments;
  21185. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21186. theta = - theta;
  21187. }
  21188. for ( i = 1; i <= segments; i ++ ) {
  21189. // twist a little...
  21190. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21191. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21192. }
  21193. }
  21194. return {
  21195. tangents: tangents,
  21196. normals: normals,
  21197. binormals: binormals
  21198. };
  21199. },
  21200. clone: function () {
  21201. return new this.constructor().copy( this );
  21202. },
  21203. copy: function ( source ) {
  21204. this.arcLengthDivisions = source.arcLengthDivisions;
  21205. return this;
  21206. },
  21207. toJSON: function () {
  21208. var data = {
  21209. metadata: {
  21210. version: 4.5,
  21211. type: 'Curve',
  21212. generator: 'Curve.toJSON'
  21213. }
  21214. };
  21215. data.arcLengthDivisions = this.arcLengthDivisions;
  21216. data.type = this.type;
  21217. return data;
  21218. },
  21219. fromJSON: function ( json ) {
  21220. this.arcLengthDivisions = json.arcLengthDivisions;
  21221. return this;
  21222. }
  21223. } );
  21224. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21225. Curve.call( this );
  21226. this.type = 'EllipseCurve';
  21227. this.aX = aX || 0;
  21228. this.aY = aY || 0;
  21229. this.xRadius = xRadius || 1;
  21230. this.yRadius = yRadius || 1;
  21231. this.aStartAngle = aStartAngle || 0;
  21232. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21233. this.aClockwise = aClockwise || false;
  21234. this.aRotation = aRotation || 0;
  21235. }
  21236. EllipseCurve.prototype = Object.create( Curve.prototype );
  21237. EllipseCurve.prototype.constructor = EllipseCurve;
  21238. EllipseCurve.prototype.isEllipseCurve = true;
  21239. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21240. var point = optionalTarget || new Vector2();
  21241. var twoPi = Math.PI * 2;
  21242. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21243. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21244. // ensures that deltaAngle is 0 .. 2 PI
  21245. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21246. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21247. if ( deltaAngle < Number.EPSILON ) {
  21248. if ( samePoints ) {
  21249. deltaAngle = 0;
  21250. } else {
  21251. deltaAngle = twoPi;
  21252. }
  21253. }
  21254. if ( this.aClockwise === true && ! samePoints ) {
  21255. if ( deltaAngle === twoPi ) {
  21256. deltaAngle = - twoPi;
  21257. } else {
  21258. deltaAngle = deltaAngle - twoPi;
  21259. }
  21260. }
  21261. var angle = this.aStartAngle + t * deltaAngle;
  21262. var x = this.aX + this.xRadius * Math.cos( angle );
  21263. var y = this.aY + this.yRadius * Math.sin( angle );
  21264. if ( this.aRotation !== 0 ) {
  21265. var cos = Math.cos( this.aRotation );
  21266. var sin = Math.sin( this.aRotation );
  21267. var tx = x - this.aX;
  21268. var ty = y - this.aY;
  21269. // Rotate the point about the center of the ellipse.
  21270. x = tx * cos - ty * sin + this.aX;
  21271. y = tx * sin + ty * cos + this.aY;
  21272. }
  21273. return point.set( x, y );
  21274. };
  21275. EllipseCurve.prototype.copy = function ( source ) {
  21276. Curve.prototype.copy.call( this, source );
  21277. this.aX = source.aX;
  21278. this.aY = source.aY;
  21279. this.xRadius = source.xRadius;
  21280. this.yRadius = source.yRadius;
  21281. this.aStartAngle = source.aStartAngle;
  21282. this.aEndAngle = source.aEndAngle;
  21283. this.aClockwise = source.aClockwise;
  21284. this.aRotation = source.aRotation;
  21285. return this;
  21286. };
  21287. EllipseCurve.prototype.toJSON = function () {
  21288. var data = Curve.prototype.toJSON.call( this );
  21289. data.aX = this.aX;
  21290. data.aY = this.aY;
  21291. data.xRadius = this.xRadius;
  21292. data.yRadius = this.yRadius;
  21293. data.aStartAngle = this.aStartAngle;
  21294. data.aEndAngle = this.aEndAngle;
  21295. data.aClockwise = this.aClockwise;
  21296. data.aRotation = this.aRotation;
  21297. return data;
  21298. };
  21299. EllipseCurve.prototype.fromJSON = function ( json ) {
  21300. Curve.prototype.fromJSON.call( this, json );
  21301. this.aX = json.aX;
  21302. this.aY = json.aY;
  21303. this.xRadius = json.xRadius;
  21304. this.yRadius = json.yRadius;
  21305. this.aStartAngle = json.aStartAngle;
  21306. this.aEndAngle = json.aEndAngle;
  21307. this.aClockwise = json.aClockwise;
  21308. this.aRotation = json.aRotation;
  21309. return this;
  21310. };
  21311. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21312. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21313. this.type = 'ArcCurve';
  21314. }
  21315. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21316. ArcCurve.prototype.constructor = ArcCurve;
  21317. ArcCurve.prototype.isArcCurve = true;
  21318. /**
  21319. * @author zz85 https://github.com/zz85
  21320. *
  21321. * Centripetal CatmullRom Curve - which is useful for avoiding
  21322. * cusps and self-intersections in non-uniform catmull rom curves.
  21323. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21324. *
  21325. * curve.type accepts centripetal(default), chordal and catmullrom
  21326. * curve.tension is used for catmullrom which defaults to 0.5
  21327. */
  21328. /*
  21329. Based on an optimized c++ solution in
  21330. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21331. - http://ideone.com/NoEbVM
  21332. This CubicPoly class could be used for reusing some variables and calculations,
  21333. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21334. which can be placed in CurveUtils.
  21335. */
  21336. function CubicPoly() {
  21337. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21338. /*
  21339. * Compute coefficients for a cubic polynomial
  21340. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21341. * such that
  21342. * p(0) = x0, p(1) = x1
  21343. * and
  21344. * p'(0) = t0, p'(1) = t1.
  21345. */
  21346. function init( x0, x1, t0, t1 ) {
  21347. c0 = x0;
  21348. c1 = t0;
  21349. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21350. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21351. }
  21352. return {
  21353. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21354. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21355. },
  21356. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21357. // compute tangents when parameterized in [t1,t2]
  21358. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21359. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21360. // rescale tangents for parametrization in [0,1]
  21361. t1 *= dt1;
  21362. t2 *= dt1;
  21363. init( x1, x2, t1, t2 );
  21364. },
  21365. calc: function ( t ) {
  21366. var t2 = t * t;
  21367. var t3 = t2 * t;
  21368. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21369. }
  21370. };
  21371. }
  21372. //
  21373. var tmp = new Vector3();
  21374. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21375. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21376. Curve.call( this );
  21377. this.type = 'CatmullRomCurve3';
  21378. this.points = points || [];
  21379. this.closed = closed || false;
  21380. this.curveType = curveType || 'centripetal';
  21381. this.tension = tension || 0.5;
  21382. }
  21383. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21384. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21385. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21386. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21387. var point = optionalTarget || new Vector3();
  21388. var points = this.points;
  21389. var l = points.length;
  21390. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21391. var intPoint = Math.floor( p );
  21392. var weight = p - intPoint;
  21393. if ( this.closed ) {
  21394. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21395. } else if ( weight === 0 && intPoint === l - 1 ) {
  21396. intPoint = l - 2;
  21397. weight = 1;
  21398. }
  21399. var p0, p1, p2, p3; // 4 points
  21400. if ( this.closed || intPoint > 0 ) {
  21401. p0 = points[ ( intPoint - 1 ) % l ];
  21402. } else {
  21403. // extrapolate first point
  21404. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21405. p0 = tmp;
  21406. }
  21407. p1 = points[ intPoint % l ];
  21408. p2 = points[ ( intPoint + 1 ) % l ];
  21409. if ( this.closed || intPoint + 2 < l ) {
  21410. p3 = points[ ( intPoint + 2 ) % l ];
  21411. } else {
  21412. // extrapolate last point
  21413. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21414. p3 = tmp;
  21415. }
  21416. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21417. // init Centripetal / Chordal Catmull-Rom
  21418. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21419. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21420. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21421. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21422. // safety check for repeated points
  21423. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21424. if ( dt0 < 1e-4 ) dt0 = dt1;
  21425. if ( dt2 < 1e-4 ) dt2 = dt1;
  21426. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21427. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21428. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21429. } else if ( this.curveType === 'catmullrom' ) {
  21430. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21431. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21432. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21433. }
  21434. point.set(
  21435. px.calc( weight ),
  21436. py.calc( weight ),
  21437. pz.calc( weight )
  21438. );
  21439. return point;
  21440. };
  21441. CatmullRomCurve3.prototype.copy = function ( source ) {
  21442. Curve.prototype.copy.call( this, source );
  21443. this.points = [];
  21444. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21445. var point = source.points[ i ];
  21446. this.points.push( point.clone() );
  21447. }
  21448. this.closed = source.closed;
  21449. this.curveType = source.curveType;
  21450. this.tension = source.tension;
  21451. return this;
  21452. };
  21453. CatmullRomCurve3.prototype.toJSON = function () {
  21454. var data = Curve.prototype.toJSON.call( this );
  21455. data.points = [];
  21456. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21457. var point = this.points[ i ];
  21458. data.points.push( point.toArray() );
  21459. }
  21460. data.closed = this.closed;
  21461. data.curveType = this.curveType;
  21462. data.tension = this.tension;
  21463. return data;
  21464. };
  21465. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21466. Curve.prototype.fromJSON.call( this, json );
  21467. this.points = [];
  21468. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21469. var point = json.points[ i ];
  21470. this.points.push( new Vector3().fromArray( point ) );
  21471. }
  21472. this.closed = json.closed;
  21473. this.curveType = json.curveType;
  21474. this.tension = json.tension;
  21475. return this;
  21476. };
  21477. /**
  21478. * @author zz85 / http://www.lab4games.net/zz85/blog
  21479. *
  21480. * Bezier Curves formulas obtained from
  21481. * http://en.wikipedia.org/wiki/Bézier_curve
  21482. */
  21483. function CatmullRom( t, p0, p1, p2, p3 ) {
  21484. var v0 = ( p2 - p0 ) * 0.5;
  21485. var v1 = ( p3 - p1 ) * 0.5;
  21486. var t2 = t * t;
  21487. var t3 = t * t2;
  21488. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21489. }
  21490. //
  21491. function QuadraticBezierP0( t, p ) {
  21492. var k = 1 - t;
  21493. return k * k * p;
  21494. }
  21495. function QuadraticBezierP1( t, p ) {
  21496. return 2 * ( 1 - t ) * t * p;
  21497. }
  21498. function QuadraticBezierP2( t, p ) {
  21499. return t * t * p;
  21500. }
  21501. function QuadraticBezier( t, p0, p1, p2 ) {
  21502. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21503. QuadraticBezierP2( t, p2 );
  21504. }
  21505. //
  21506. function CubicBezierP0( t, p ) {
  21507. var k = 1 - t;
  21508. return k * k * k * p;
  21509. }
  21510. function CubicBezierP1( t, p ) {
  21511. var k = 1 - t;
  21512. return 3 * k * k * t * p;
  21513. }
  21514. function CubicBezierP2( t, p ) {
  21515. return 3 * ( 1 - t ) * t * t * p;
  21516. }
  21517. function CubicBezierP3( t, p ) {
  21518. return t * t * t * p;
  21519. }
  21520. function CubicBezier( t, p0, p1, p2, p3 ) {
  21521. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21522. CubicBezierP3( t, p3 );
  21523. }
  21524. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21525. Curve.call( this );
  21526. this.type = 'CubicBezierCurve';
  21527. this.v0 = v0 || new Vector2();
  21528. this.v1 = v1 || new Vector2();
  21529. this.v2 = v2 || new Vector2();
  21530. this.v3 = v3 || new Vector2();
  21531. }
  21532. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21533. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21534. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21535. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21536. var point = optionalTarget || new Vector2();
  21537. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21538. point.set(
  21539. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21540. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21541. );
  21542. return point;
  21543. };
  21544. CubicBezierCurve.prototype.copy = function ( source ) {
  21545. Curve.prototype.copy.call( this, source );
  21546. this.v0.copy( source.v0 );
  21547. this.v1.copy( source.v1 );
  21548. this.v2.copy( source.v2 );
  21549. this.v3.copy( source.v3 );
  21550. return this;
  21551. };
  21552. CubicBezierCurve.prototype.toJSON = function () {
  21553. var data = Curve.prototype.toJSON.call( this );
  21554. data.v0 = this.v0.toArray();
  21555. data.v1 = this.v1.toArray();
  21556. data.v2 = this.v2.toArray();
  21557. data.v3 = this.v3.toArray();
  21558. return data;
  21559. };
  21560. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21561. Curve.prototype.fromJSON.call( this, json );
  21562. this.v0.fromArray( json.v0 );
  21563. this.v1.fromArray( json.v1 );
  21564. this.v2.fromArray( json.v2 );
  21565. this.v3.fromArray( json.v3 );
  21566. return this;
  21567. };
  21568. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21569. Curve.call( this );
  21570. this.type = 'CubicBezierCurve3';
  21571. this.v0 = v0 || new Vector3();
  21572. this.v1 = v1 || new Vector3();
  21573. this.v2 = v2 || new Vector3();
  21574. this.v3 = v3 || new Vector3();
  21575. }
  21576. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21577. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21578. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21579. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21580. var point = optionalTarget || new Vector3();
  21581. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21582. point.set(
  21583. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21584. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21585. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21586. );
  21587. return point;
  21588. };
  21589. CubicBezierCurve3.prototype.copy = function ( source ) {
  21590. Curve.prototype.copy.call( this, source );
  21591. this.v0.copy( source.v0 );
  21592. this.v1.copy( source.v1 );
  21593. this.v2.copy( source.v2 );
  21594. this.v3.copy( source.v3 );
  21595. return this;
  21596. };
  21597. CubicBezierCurve3.prototype.toJSON = function () {
  21598. var data = Curve.prototype.toJSON.call( this );
  21599. data.v0 = this.v0.toArray();
  21600. data.v1 = this.v1.toArray();
  21601. data.v2 = this.v2.toArray();
  21602. data.v3 = this.v3.toArray();
  21603. return data;
  21604. };
  21605. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21606. Curve.prototype.fromJSON.call( this, json );
  21607. this.v0.fromArray( json.v0 );
  21608. this.v1.fromArray( json.v1 );
  21609. this.v2.fromArray( json.v2 );
  21610. this.v3.fromArray( json.v3 );
  21611. return this;
  21612. };
  21613. function LineCurve( v1, v2 ) {
  21614. Curve.call( this );
  21615. this.type = 'LineCurve';
  21616. this.v1 = v1 || new Vector2();
  21617. this.v2 = v2 || new Vector2();
  21618. }
  21619. LineCurve.prototype = Object.create( Curve.prototype );
  21620. LineCurve.prototype.constructor = LineCurve;
  21621. LineCurve.prototype.isLineCurve = true;
  21622. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21623. var point = optionalTarget || new Vector2();
  21624. if ( t === 1 ) {
  21625. point.copy( this.v2 );
  21626. } else {
  21627. point.copy( this.v2 ).sub( this.v1 );
  21628. point.multiplyScalar( t ).add( this.v1 );
  21629. }
  21630. return point;
  21631. };
  21632. // Line curve is linear, so we can overwrite default getPointAt
  21633. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21634. return this.getPoint( u, optionalTarget );
  21635. };
  21636. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21637. var tangent = this.v2.clone().sub( this.v1 );
  21638. return tangent.normalize();
  21639. };
  21640. LineCurve.prototype.copy = function ( source ) {
  21641. Curve.prototype.copy.call( this, source );
  21642. this.v1.copy( source.v1 );
  21643. this.v2.copy( source.v2 );
  21644. return this;
  21645. };
  21646. LineCurve.prototype.toJSON = function () {
  21647. var data = Curve.prototype.toJSON.call( this );
  21648. data.v1 = this.v1.toArray();
  21649. data.v2 = this.v2.toArray();
  21650. return data;
  21651. };
  21652. LineCurve.prototype.fromJSON = function ( json ) {
  21653. Curve.prototype.fromJSON.call( this, json );
  21654. this.v1.fromArray( json.v1 );
  21655. this.v2.fromArray( json.v2 );
  21656. return this;
  21657. };
  21658. function LineCurve3( v1, v2 ) {
  21659. Curve.call( this );
  21660. this.type = 'LineCurve3';
  21661. this.v1 = v1 || new Vector3();
  21662. this.v2 = v2 || new Vector3();
  21663. }
  21664. LineCurve3.prototype = Object.create( Curve.prototype );
  21665. LineCurve3.prototype.constructor = LineCurve3;
  21666. LineCurve3.prototype.isLineCurve3 = true;
  21667. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21668. var point = optionalTarget || new Vector3();
  21669. if ( t === 1 ) {
  21670. point.copy( this.v2 );
  21671. } else {
  21672. point.copy( this.v2 ).sub( this.v1 );
  21673. point.multiplyScalar( t ).add( this.v1 );
  21674. }
  21675. return point;
  21676. };
  21677. // Line curve is linear, so we can overwrite default getPointAt
  21678. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21679. return this.getPoint( u, optionalTarget );
  21680. };
  21681. LineCurve3.prototype.copy = function ( source ) {
  21682. Curve.prototype.copy.call( this, source );
  21683. this.v1.copy( source.v1 );
  21684. this.v2.copy( source.v2 );
  21685. return this;
  21686. };
  21687. LineCurve3.prototype.toJSON = function () {
  21688. var data = Curve.prototype.toJSON.call( this );
  21689. data.v1 = this.v1.toArray();
  21690. data.v2 = this.v2.toArray();
  21691. return data;
  21692. };
  21693. LineCurve3.prototype.fromJSON = function ( json ) {
  21694. Curve.prototype.fromJSON.call( this, json );
  21695. this.v1.fromArray( json.v1 );
  21696. this.v2.fromArray( json.v2 );
  21697. return this;
  21698. };
  21699. function QuadraticBezierCurve( v0, v1, v2 ) {
  21700. Curve.call( this );
  21701. this.type = 'QuadraticBezierCurve';
  21702. this.v0 = v0 || new Vector2();
  21703. this.v1 = v1 || new Vector2();
  21704. this.v2 = v2 || new Vector2();
  21705. }
  21706. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21707. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21708. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21709. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21710. var point = optionalTarget || new Vector2();
  21711. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21712. point.set(
  21713. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21714. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21715. );
  21716. return point;
  21717. };
  21718. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21719. Curve.prototype.copy.call( this, source );
  21720. this.v0.copy( source.v0 );
  21721. this.v1.copy( source.v1 );
  21722. this.v2.copy( source.v2 );
  21723. return this;
  21724. };
  21725. QuadraticBezierCurve.prototype.toJSON = function () {
  21726. var data = Curve.prototype.toJSON.call( this );
  21727. data.v0 = this.v0.toArray();
  21728. data.v1 = this.v1.toArray();
  21729. data.v2 = this.v2.toArray();
  21730. return data;
  21731. };
  21732. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21733. Curve.prototype.fromJSON.call( this, json );
  21734. this.v0.fromArray( json.v0 );
  21735. this.v1.fromArray( json.v1 );
  21736. this.v2.fromArray( json.v2 );
  21737. return this;
  21738. };
  21739. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21740. Curve.call( this );
  21741. this.type = 'QuadraticBezierCurve3';
  21742. this.v0 = v0 || new Vector3();
  21743. this.v1 = v1 || new Vector3();
  21744. this.v2 = v2 || new Vector3();
  21745. }
  21746. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21747. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21748. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21749. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21750. var point = optionalTarget || new Vector3();
  21751. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21752. point.set(
  21753. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21754. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21755. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21756. );
  21757. return point;
  21758. };
  21759. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21760. Curve.prototype.copy.call( this, source );
  21761. this.v0.copy( source.v0 );
  21762. this.v1.copy( source.v1 );
  21763. this.v2.copy( source.v2 );
  21764. return this;
  21765. };
  21766. QuadraticBezierCurve3.prototype.toJSON = function () {
  21767. var data = Curve.prototype.toJSON.call( this );
  21768. data.v0 = this.v0.toArray();
  21769. data.v1 = this.v1.toArray();
  21770. data.v2 = this.v2.toArray();
  21771. return data;
  21772. };
  21773. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21774. Curve.prototype.fromJSON.call( this, json );
  21775. this.v0.fromArray( json.v0 );
  21776. this.v1.fromArray( json.v1 );
  21777. this.v2.fromArray( json.v2 );
  21778. return this;
  21779. };
  21780. function SplineCurve( points /* array of Vector2 */ ) {
  21781. Curve.call( this );
  21782. this.type = 'SplineCurve';
  21783. this.points = points || [];
  21784. }
  21785. SplineCurve.prototype = Object.create( Curve.prototype );
  21786. SplineCurve.prototype.constructor = SplineCurve;
  21787. SplineCurve.prototype.isSplineCurve = true;
  21788. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21789. var point = optionalTarget || new Vector2();
  21790. var points = this.points;
  21791. var p = ( points.length - 1 ) * t;
  21792. var intPoint = Math.floor( p );
  21793. var weight = p - intPoint;
  21794. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21795. var p1 = points[ intPoint ];
  21796. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21797. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21798. point.set(
  21799. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21800. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21801. );
  21802. return point;
  21803. };
  21804. SplineCurve.prototype.copy = function ( source ) {
  21805. Curve.prototype.copy.call( this, source );
  21806. this.points = [];
  21807. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21808. var point = source.points[ i ];
  21809. this.points.push( point.clone() );
  21810. }
  21811. return this;
  21812. };
  21813. SplineCurve.prototype.toJSON = function () {
  21814. var data = Curve.prototype.toJSON.call( this );
  21815. data.points = [];
  21816. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21817. var point = this.points[ i ];
  21818. data.points.push( point.toArray() );
  21819. }
  21820. return data;
  21821. };
  21822. SplineCurve.prototype.fromJSON = function ( json ) {
  21823. Curve.prototype.fromJSON.call( this, json );
  21824. this.points = [];
  21825. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21826. var point = json.points[ i ];
  21827. this.points.push( new Vector2().fromArray( point ) );
  21828. }
  21829. return this;
  21830. };
  21831. var Curves = /*#__PURE__*/Object.freeze({
  21832. ArcCurve: ArcCurve,
  21833. CatmullRomCurve3: CatmullRomCurve3,
  21834. CubicBezierCurve: CubicBezierCurve,
  21835. CubicBezierCurve3: CubicBezierCurve3,
  21836. EllipseCurve: EllipseCurve,
  21837. LineCurve: LineCurve,
  21838. LineCurve3: LineCurve3,
  21839. QuadraticBezierCurve: QuadraticBezierCurve,
  21840. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21841. SplineCurve: SplineCurve
  21842. });
  21843. /**
  21844. * @author zz85 / http://www.lab4games.net/zz85/blog
  21845. *
  21846. **/
  21847. /**************************************************************
  21848. * Curved Path - a curve path is simply a array of connected
  21849. * curves, but retains the api of a curve
  21850. **************************************************************/
  21851. function CurvePath() {
  21852. Curve.call( this );
  21853. this.type = 'CurvePath';
  21854. this.curves = [];
  21855. this.autoClose = false; // Automatically closes the path
  21856. }
  21857. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21858. constructor: CurvePath,
  21859. add: function ( curve ) {
  21860. this.curves.push( curve );
  21861. },
  21862. closePath: function () {
  21863. // Add a line curve if start and end of lines are not connected
  21864. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21865. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21866. if ( ! startPoint.equals( endPoint ) ) {
  21867. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21868. }
  21869. },
  21870. // To get accurate point with reference to
  21871. // entire path distance at time t,
  21872. // following has to be done:
  21873. // 1. Length of each sub path have to be known
  21874. // 2. Locate and identify type of curve
  21875. // 3. Get t for the curve
  21876. // 4. Return curve.getPointAt(t')
  21877. getPoint: function ( t ) {
  21878. var d = t * this.getLength();
  21879. var curveLengths = this.getCurveLengths();
  21880. var i = 0;
  21881. // To think about boundaries points.
  21882. while ( i < curveLengths.length ) {
  21883. if ( curveLengths[ i ] >= d ) {
  21884. var diff = curveLengths[ i ] - d;
  21885. var curve = this.curves[ i ];
  21886. var segmentLength = curve.getLength();
  21887. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21888. return curve.getPointAt( u );
  21889. }
  21890. i ++;
  21891. }
  21892. return null;
  21893. // loop where sum != 0, sum > d , sum+1 <d
  21894. },
  21895. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21896. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21897. // getPoint() depends on getLength
  21898. getLength: function () {
  21899. var lens = this.getCurveLengths();
  21900. return lens[ lens.length - 1 ];
  21901. },
  21902. // cacheLengths must be recalculated.
  21903. updateArcLengths: function () {
  21904. this.needsUpdate = true;
  21905. this.cacheLengths = null;
  21906. this.getCurveLengths();
  21907. },
  21908. // Compute lengths and cache them
  21909. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21910. getCurveLengths: function () {
  21911. // We use cache values if curves and cache array are same length
  21912. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21913. return this.cacheLengths;
  21914. }
  21915. // Get length of sub-curve
  21916. // Push sums into cached array
  21917. var lengths = [], sums = 0;
  21918. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21919. sums += this.curves[ i ].getLength();
  21920. lengths.push( sums );
  21921. }
  21922. this.cacheLengths = lengths;
  21923. return lengths;
  21924. },
  21925. getSpacedPoints: function ( divisions ) {
  21926. if ( divisions === undefined ) divisions = 40;
  21927. var points = [];
  21928. for ( var i = 0; i <= divisions; i ++ ) {
  21929. points.push( this.getPoint( i / divisions ) );
  21930. }
  21931. if ( this.autoClose ) {
  21932. points.push( points[ 0 ] );
  21933. }
  21934. return points;
  21935. },
  21936. getPoints: function ( divisions ) {
  21937. divisions = divisions || 12;
  21938. var points = [], last;
  21939. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21940. var curve = curves[ i ];
  21941. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21942. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21943. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21944. : divisions;
  21945. var pts = curve.getPoints( resolution );
  21946. for ( var j = 0; j < pts.length; j ++ ) {
  21947. var point = pts[ j ];
  21948. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21949. points.push( point );
  21950. last = point;
  21951. }
  21952. }
  21953. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21954. points.push( points[ 0 ] );
  21955. }
  21956. return points;
  21957. },
  21958. copy: function ( source ) {
  21959. Curve.prototype.copy.call( this, source );
  21960. this.curves = [];
  21961. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  21962. var curve = source.curves[ i ];
  21963. this.curves.push( curve.clone() );
  21964. }
  21965. this.autoClose = source.autoClose;
  21966. return this;
  21967. },
  21968. toJSON: function () {
  21969. var data = Curve.prototype.toJSON.call( this );
  21970. data.autoClose = this.autoClose;
  21971. data.curves = [];
  21972. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21973. var curve = this.curves[ i ];
  21974. data.curves.push( curve.toJSON() );
  21975. }
  21976. return data;
  21977. },
  21978. fromJSON: function ( json ) {
  21979. Curve.prototype.fromJSON.call( this, json );
  21980. this.autoClose = json.autoClose;
  21981. this.curves = [];
  21982. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  21983. var curve = json.curves[ i ];
  21984. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  21985. }
  21986. return this;
  21987. }
  21988. } );
  21989. /**
  21990. * @author zz85 / http://www.lab4games.net/zz85/blog
  21991. * Creates free form 2d path using series of points, lines or curves.
  21992. **/
  21993. function Path( points ) {
  21994. CurvePath.call( this );
  21995. this.type = 'Path';
  21996. this.currentPoint = new Vector2();
  21997. if ( points ) {
  21998. this.setFromPoints( points );
  21999. }
  22000. }
  22001. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22002. constructor: Path,
  22003. setFromPoints: function ( points ) {
  22004. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22005. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22006. this.lineTo( points[ i ].x, points[ i ].y );
  22007. }
  22008. },
  22009. moveTo: function ( x, y ) {
  22010. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22011. },
  22012. lineTo: function ( x, y ) {
  22013. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22014. this.curves.push( curve );
  22015. this.currentPoint.set( x, y );
  22016. },
  22017. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22018. var curve = new QuadraticBezierCurve(
  22019. this.currentPoint.clone(),
  22020. new Vector2( aCPx, aCPy ),
  22021. new Vector2( aX, aY )
  22022. );
  22023. this.curves.push( curve );
  22024. this.currentPoint.set( aX, aY );
  22025. },
  22026. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22027. var curve = new CubicBezierCurve(
  22028. this.currentPoint.clone(),
  22029. new Vector2( aCP1x, aCP1y ),
  22030. new Vector2( aCP2x, aCP2y ),
  22031. new Vector2( aX, aY )
  22032. );
  22033. this.curves.push( curve );
  22034. this.currentPoint.set( aX, aY );
  22035. },
  22036. splineThru: function ( pts /*Array of Vector*/ ) {
  22037. var npts = [ this.currentPoint.clone() ].concat( pts );
  22038. var curve = new SplineCurve( npts );
  22039. this.curves.push( curve );
  22040. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22041. },
  22042. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22043. var x0 = this.currentPoint.x;
  22044. var y0 = this.currentPoint.y;
  22045. this.absarc( aX + x0, aY + y0, aRadius,
  22046. aStartAngle, aEndAngle, aClockwise );
  22047. },
  22048. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22049. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22050. },
  22051. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22052. var x0 = this.currentPoint.x;
  22053. var y0 = this.currentPoint.y;
  22054. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22055. },
  22056. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22057. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22058. if ( this.curves.length > 0 ) {
  22059. // if a previous curve is present, attempt to join
  22060. var firstPoint = curve.getPoint( 0 );
  22061. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22062. this.lineTo( firstPoint.x, firstPoint.y );
  22063. }
  22064. }
  22065. this.curves.push( curve );
  22066. var lastPoint = curve.getPoint( 1 );
  22067. this.currentPoint.copy( lastPoint );
  22068. },
  22069. copy: function ( source ) {
  22070. CurvePath.prototype.copy.call( this, source );
  22071. this.currentPoint.copy( source.currentPoint );
  22072. return this;
  22073. },
  22074. toJSON: function () {
  22075. var data = CurvePath.prototype.toJSON.call( this );
  22076. data.currentPoint = this.currentPoint.toArray();
  22077. return data;
  22078. },
  22079. fromJSON: function ( json ) {
  22080. CurvePath.prototype.fromJSON.call( this, json );
  22081. this.currentPoint.fromArray( json.currentPoint );
  22082. return this;
  22083. }
  22084. } );
  22085. /**
  22086. * @author zz85 / http://www.lab4games.net/zz85/blog
  22087. * Defines a 2d shape plane using paths.
  22088. **/
  22089. // STEP 1 Create a path.
  22090. // STEP 2 Turn path into shape.
  22091. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22092. // STEP 3a - Extract points from each shape, turn to vertices
  22093. // STEP 3b - Triangulate each shape, add faces.
  22094. function Shape( points ) {
  22095. Path.call( this, points );
  22096. this.uuid = _Math.generateUUID();
  22097. this.type = 'Shape';
  22098. this.holes = [];
  22099. }
  22100. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22101. constructor: Shape,
  22102. getPointsHoles: function ( divisions ) {
  22103. var holesPts = [];
  22104. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22105. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22106. }
  22107. return holesPts;
  22108. },
  22109. // get points of shape and holes (keypoints based on segments parameter)
  22110. extractPoints: function ( divisions ) {
  22111. return {
  22112. shape: this.getPoints( divisions ),
  22113. holes: this.getPointsHoles( divisions )
  22114. };
  22115. },
  22116. copy: function ( source ) {
  22117. Path.prototype.copy.call( this, source );
  22118. this.holes = [];
  22119. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22120. var hole = source.holes[ i ];
  22121. this.holes.push( hole.clone() );
  22122. }
  22123. return this;
  22124. },
  22125. toJSON: function () {
  22126. var data = Path.prototype.toJSON.call( this );
  22127. data.uuid = this.uuid;
  22128. data.holes = [];
  22129. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22130. var hole = this.holes[ i ];
  22131. data.holes.push( hole.toJSON() );
  22132. }
  22133. return data;
  22134. },
  22135. fromJSON: function ( json ) {
  22136. Path.prototype.fromJSON.call( this, json );
  22137. this.uuid = json.uuid;
  22138. this.holes = [];
  22139. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22140. var hole = json.holes[ i ];
  22141. this.holes.push( new Path().fromJSON( hole ) );
  22142. }
  22143. return this;
  22144. }
  22145. } );
  22146. /**
  22147. * @author mrdoob / http://mrdoob.com/
  22148. * @author alteredq / http://alteredqualia.com/
  22149. */
  22150. function Light( color, intensity ) {
  22151. Object3D.call( this );
  22152. this.type = 'Light';
  22153. this.color = new Color( color );
  22154. this.intensity = intensity !== undefined ? intensity : 1;
  22155. this.receiveShadow = undefined;
  22156. }
  22157. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22158. constructor: Light,
  22159. isLight: true,
  22160. copy: function ( source ) {
  22161. Object3D.prototype.copy.call( this, source );
  22162. this.color.copy( source.color );
  22163. this.intensity = source.intensity;
  22164. return this;
  22165. },
  22166. toJSON: function ( meta ) {
  22167. var data = Object3D.prototype.toJSON.call( this, meta );
  22168. data.object.color = this.color.getHex();
  22169. data.object.intensity = this.intensity;
  22170. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22171. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22172. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22173. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22174. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22175. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22176. return data;
  22177. }
  22178. } );
  22179. /**
  22180. * @author alteredq / http://alteredqualia.com/
  22181. */
  22182. function HemisphereLight( skyColor, groundColor, intensity ) {
  22183. Light.call( this, skyColor, intensity );
  22184. this.type = 'HemisphereLight';
  22185. this.castShadow = undefined;
  22186. this.position.copy( Object3D.DefaultUp );
  22187. this.updateMatrix();
  22188. this.groundColor = new Color( groundColor );
  22189. }
  22190. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22191. constructor: HemisphereLight,
  22192. isHemisphereLight: true,
  22193. copy: function ( source ) {
  22194. Light.prototype.copy.call( this, source );
  22195. this.groundColor.copy( source.groundColor );
  22196. return this;
  22197. }
  22198. } );
  22199. /**
  22200. * @author mrdoob / http://mrdoob.com/
  22201. */
  22202. function LightShadow( camera ) {
  22203. this.camera = camera;
  22204. this.bias = 0;
  22205. this.radius = 1;
  22206. this.mapSize = new Vector2( 512, 512 );
  22207. this.map = null;
  22208. this.matrix = new Matrix4();
  22209. }
  22210. Object.assign( LightShadow.prototype, {
  22211. copy: function ( source ) {
  22212. this.camera = source.camera.clone();
  22213. this.bias = source.bias;
  22214. this.radius = source.radius;
  22215. this.mapSize.copy( source.mapSize );
  22216. return this;
  22217. },
  22218. clone: function () {
  22219. return new this.constructor().copy( this );
  22220. },
  22221. toJSON: function () {
  22222. var object = {};
  22223. if ( this.bias !== 0 ) object.bias = this.bias;
  22224. if ( this.radius !== 1 ) object.radius = this.radius;
  22225. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22226. object.camera = this.camera.toJSON( false ).object;
  22227. delete object.camera.matrix;
  22228. return object;
  22229. }
  22230. } );
  22231. /**
  22232. * @author mrdoob / http://mrdoob.com/
  22233. */
  22234. function SpotLightShadow() {
  22235. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22236. }
  22237. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22238. constructor: SpotLightShadow,
  22239. isSpotLightShadow: true,
  22240. update: function ( light ) {
  22241. var camera = this.camera;
  22242. var fov = _Math.RAD2DEG * 2 * light.angle;
  22243. var aspect = this.mapSize.width / this.mapSize.height;
  22244. var far = light.distance || camera.far;
  22245. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22246. camera.fov = fov;
  22247. camera.aspect = aspect;
  22248. camera.far = far;
  22249. camera.updateProjectionMatrix();
  22250. }
  22251. }
  22252. } );
  22253. /**
  22254. * @author alteredq / http://alteredqualia.com/
  22255. */
  22256. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22257. Light.call( this, color, intensity );
  22258. this.type = 'SpotLight';
  22259. this.position.copy( Object3D.DefaultUp );
  22260. this.updateMatrix();
  22261. this.target = new Object3D();
  22262. Object.defineProperty( this, 'power', {
  22263. get: function () {
  22264. // intensity = power per solid angle.
  22265. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22266. return this.intensity * Math.PI;
  22267. },
  22268. set: function ( power ) {
  22269. // intensity = power per solid angle.
  22270. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22271. this.intensity = power / Math.PI;
  22272. }
  22273. } );
  22274. this.distance = ( distance !== undefined ) ? distance : 0;
  22275. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22276. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22277. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22278. this.shadow = new SpotLightShadow();
  22279. }
  22280. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22281. constructor: SpotLight,
  22282. isSpotLight: true,
  22283. copy: function ( source ) {
  22284. Light.prototype.copy.call( this, source );
  22285. this.distance = source.distance;
  22286. this.angle = source.angle;
  22287. this.penumbra = source.penumbra;
  22288. this.decay = source.decay;
  22289. this.target = source.target.clone();
  22290. this.shadow = source.shadow.clone();
  22291. return this;
  22292. }
  22293. } );
  22294. /**
  22295. * @author mrdoob / http://mrdoob.com/
  22296. */
  22297. function PointLight( color, intensity, distance, decay ) {
  22298. Light.call( this, color, intensity );
  22299. this.type = 'PointLight';
  22300. Object.defineProperty( this, 'power', {
  22301. get: function () {
  22302. // intensity = power per solid angle.
  22303. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22304. return this.intensity * 4 * Math.PI;
  22305. },
  22306. set: function ( power ) {
  22307. // intensity = power per solid angle.
  22308. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22309. this.intensity = power / ( 4 * Math.PI );
  22310. }
  22311. } );
  22312. this.distance = ( distance !== undefined ) ? distance : 0;
  22313. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22314. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22315. }
  22316. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22317. constructor: PointLight,
  22318. isPointLight: true,
  22319. copy: function ( source ) {
  22320. Light.prototype.copy.call( this, source );
  22321. this.distance = source.distance;
  22322. this.decay = source.decay;
  22323. this.shadow = source.shadow.clone();
  22324. return this;
  22325. }
  22326. } );
  22327. /**
  22328. * @author alteredq / http://alteredqualia.com/
  22329. * @author arose / http://github.com/arose
  22330. */
  22331. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22332. Camera.call( this );
  22333. this.type = 'OrthographicCamera';
  22334. this.zoom = 1;
  22335. this.view = null;
  22336. this.left = ( left !== undefined ) ? left : - 1;
  22337. this.right = ( right !== undefined ) ? right : 1;
  22338. this.top = ( top !== undefined ) ? top : 1;
  22339. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22340. this.near = ( near !== undefined ) ? near : 0.1;
  22341. this.far = ( far !== undefined ) ? far : 2000;
  22342. this.updateProjectionMatrix();
  22343. }
  22344. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22345. constructor: OrthographicCamera,
  22346. isOrthographicCamera: true,
  22347. copy: function ( source, recursive ) {
  22348. Camera.prototype.copy.call( this, source, recursive );
  22349. this.left = source.left;
  22350. this.right = source.right;
  22351. this.top = source.top;
  22352. this.bottom = source.bottom;
  22353. this.near = source.near;
  22354. this.far = source.far;
  22355. this.zoom = source.zoom;
  22356. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22357. return this;
  22358. },
  22359. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22360. if ( this.view === null ) {
  22361. this.view = {
  22362. enabled: true,
  22363. fullWidth: 1,
  22364. fullHeight: 1,
  22365. offsetX: 0,
  22366. offsetY: 0,
  22367. width: 1,
  22368. height: 1
  22369. };
  22370. }
  22371. this.view.enabled = true;
  22372. this.view.fullWidth = fullWidth;
  22373. this.view.fullHeight = fullHeight;
  22374. this.view.offsetX = x;
  22375. this.view.offsetY = y;
  22376. this.view.width = width;
  22377. this.view.height = height;
  22378. this.updateProjectionMatrix();
  22379. },
  22380. clearViewOffset: function () {
  22381. if ( this.view !== null ) {
  22382. this.view.enabled = false;
  22383. }
  22384. this.updateProjectionMatrix();
  22385. },
  22386. updateProjectionMatrix: function () {
  22387. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22388. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22389. var cx = ( this.right + this.left ) / 2;
  22390. var cy = ( this.top + this.bottom ) / 2;
  22391. var left = cx - dx;
  22392. var right = cx + dx;
  22393. var top = cy + dy;
  22394. var bottom = cy - dy;
  22395. if ( this.view !== null && this.view.enabled ) {
  22396. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22397. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22398. var scaleW = ( this.right - this.left ) / this.view.width;
  22399. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22400. left += scaleW * ( this.view.offsetX / zoomW );
  22401. right = left + scaleW * ( this.view.width / zoomW );
  22402. top -= scaleH * ( this.view.offsetY / zoomH );
  22403. bottom = top - scaleH * ( this.view.height / zoomH );
  22404. }
  22405. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22406. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22407. },
  22408. toJSON: function ( meta ) {
  22409. var data = Object3D.prototype.toJSON.call( this, meta );
  22410. data.object.zoom = this.zoom;
  22411. data.object.left = this.left;
  22412. data.object.right = this.right;
  22413. data.object.top = this.top;
  22414. data.object.bottom = this.bottom;
  22415. data.object.near = this.near;
  22416. data.object.far = this.far;
  22417. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22418. return data;
  22419. }
  22420. } );
  22421. /**
  22422. * @author mrdoob / http://mrdoob.com/
  22423. */
  22424. function DirectionalLightShadow( ) {
  22425. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22426. }
  22427. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22428. constructor: DirectionalLightShadow
  22429. } );
  22430. /**
  22431. * @author mrdoob / http://mrdoob.com/
  22432. * @author alteredq / http://alteredqualia.com/
  22433. */
  22434. function DirectionalLight( color, intensity ) {
  22435. Light.call( this, color, intensity );
  22436. this.type = 'DirectionalLight';
  22437. this.position.copy( Object3D.DefaultUp );
  22438. this.updateMatrix();
  22439. this.target = new Object3D();
  22440. this.shadow = new DirectionalLightShadow();
  22441. }
  22442. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22443. constructor: DirectionalLight,
  22444. isDirectionalLight: true,
  22445. copy: function ( source ) {
  22446. Light.prototype.copy.call( this, source );
  22447. this.target = source.target.clone();
  22448. this.shadow = source.shadow.clone();
  22449. return this;
  22450. }
  22451. } );
  22452. /**
  22453. * @author mrdoob / http://mrdoob.com/
  22454. */
  22455. function AmbientLight( color, intensity ) {
  22456. Light.call( this, color, intensity );
  22457. this.type = 'AmbientLight';
  22458. this.castShadow = undefined;
  22459. }
  22460. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22461. constructor: AmbientLight,
  22462. isAmbientLight: true
  22463. } );
  22464. /**
  22465. * @author abelnation / http://github.com/abelnation
  22466. */
  22467. function RectAreaLight( color, intensity, width, height ) {
  22468. Light.call( this, color, intensity );
  22469. this.type = 'RectAreaLight';
  22470. this.width = ( width !== undefined ) ? width : 10;
  22471. this.height = ( height !== undefined ) ? height : 10;
  22472. }
  22473. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22474. constructor: RectAreaLight,
  22475. isRectAreaLight: true,
  22476. copy: function ( source ) {
  22477. Light.prototype.copy.call( this, source );
  22478. this.width = source.width;
  22479. this.height = source.height;
  22480. return this;
  22481. },
  22482. toJSON: function ( meta ) {
  22483. var data = Light.prototype.toJSON.call( this, meta );
  22484. data.object.width = this.width;
  22485. data.object.height = this.height;
  22486. return data;
  22487. }
  22488. } );
  22489. /**
  22490. * @author mrdoob / http://mrdoob.com/
  22491. */
  22492. function MaterialLoader( manager ) {
  22493. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22494. this.textures = {};
  22495. }
  22496. Object.assign( MaterialLoader.prototype, {
  22497. load: function ( url, onLoad, onProgress, onError ) {
  22498. var scope = this;
  22499. var loader = new FileLoader( scope.manager );
  22500. loader.setPath( scope.path );
  22501. loader.load( url, function ( text ) {
  22502. onLoad( scope.parse( JSON.parse( text ) ) );
  22503. }, onProgress, onError );
  22504. },
  22505. parse: function ( json ) {
  22506. var textures = this.textures;
  22507. function getTexture( name ) {
  22508. if ( textures[ name ] === undefined ) {
  22509. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22510. }
  22511. return textures[ name ];
  22512. }
  22513. var material = new Materials[ json.type ]();
  22514. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22515. if ( json.name !== undefined ) material.name = json.name;
  22516. if ( json.color !== undefined ) material.color.setHex( json.color );
  22517. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22518. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22519. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22520. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22521. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22522. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22523. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22524. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22525. if ( json.fog !== undefined ) material.fog = json.fog;
  22526. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22527. if ( json.blending !== undefined ) material.blending = json.blending;
  22528. if ( json.combine !== undefined ) material.combine = json.combine;
  22529. if ( json.side !== undefined ) material.side = json.side;
  22530. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22531. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22532. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22533. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22534. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22535. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22536. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22537. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22538. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22539. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22540. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22541. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22542. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22543. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22544. if ( json.scale !== undefined ) material.scale = json.scale;
  22545. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22546. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22547. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22548. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22549. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22550. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22551. if ( json.visible !== undefined ) material.visible = json.visible;
  22552. if ( json.userData !== undefined ) material.userData = json.userData;
  22553. // Shader Material
  22554. if ( json.uniforms !== undefined ) {
  22555. for ( var name in json.uniforms ) {
  22556. var uniform = json.uniforms[ name ];
  22557. material.uniforms[ name ] = {};
  22558. switch ( uniform.type ) {
  22559. case 't':
  22560. material.uniforms[ name ].value = getTexture( uniform.value );
  22561. break;
  22562. case 'c':
  22563. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22564. break;
  22565. case 'v2':
  22566. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22567. break;
  22568. case 'v3':
  22569. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22570. break;
  22571. case 'v4':
  22572. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22573. break;
  22574. case 'm3':
  22575. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22576. case 'm4':
  22577. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22578. break;
  22579. default:
  22580. material.uniforms[ name ].value = uniform.value;
  22581. }
  22582. }
  22583. }
  22584. if ( json.defines !== undefined ) material.defines = json.defines;
  22585. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22586. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22587. if ( json.extensions !== undefined ) {
  22588. for ( var key in json.extensions ) {
  22589. material.extensions[ key ] = json.extensions[ key ];
  22590. }
  22591. }
  22592. // Deprecated
  22593. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22594. // for PointsMaterial
  22595. if ( json.size !== undefined ) material.size = json.size;
  22596. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22597. // maps
  22598. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22599. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22600. if ( json.alphaMap !== undefined ) {
  22601. material.alphaMap = getTexture( json.alphaMap );
  22602. material.transparent = true;
  22603. }
  22604. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22605. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22606. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22607. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22608. if ( json.normalScale !== undefined ) {
  22609. var normalScale = json.normalScale;
  22610. if ( Array.isArray( normalScale ) === false ) {
  22611. // Blender exporter used to export a scalar. See #7459
  22612. normalScale = [ normalScale, normalScale ];
  22613. }
  22614. material.normalScale = new Vector2().fromArray( normalScale );
  22615. }
  22616. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22617. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22618. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22619. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22620. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22621. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22622. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22623. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22624. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22625. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22626. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22627. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22628. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22629. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22630. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22631. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22632. return material;
  22633. },
  22634. setPath: function ( value ) {
  22635. this.path = value;
  22636. return this;
  22637. },
  22638. setTextures: function ( value ) {
  22639. this.textures = value;
  22640. return this;
  22641. }
  22642. } );
  22643. /**
  22644. * @author Don McCurdy / https://www.donmccurdy.com
  22645. */
  22646. var LoaderUtils = {
  22647. decodeText: function ( array ) {
  22648. if ( typeof TextDecoder !== 'undefined' ) {
  22649. return new TextDecoder().decode( array );
  22650. }
  22651. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22652. // throws a "maximum call stack size exceeded" error for large arrays.
  22653. var s = '';
  22654. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22655. // Implicitly assumes little-endian.
  22656. s += String.fromCharCode( array[ i ] );
  22657. }
  22658. // Merges multi-byte utf-8 characters.
  22659. return decodeURIComponent( escape( s ) );
  22660. },
  22661. extractUrlBase: function ( url ) {
  22662. var index = url.lastIndexOf( '/' );
  22663. if ( index === - 1 ) return './';
  22664. return url.substr( 0, index + 1 );
  22665. }
  22666. };
  22667. /**
  22668. * @author mrdoob / http://mrdoob.com/
  22669. */
  22670. function BufferGeometryLoader( manager ) {
  22671. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22672. }
  22673. Object.assign( BufferGeometryLoader.prototype, {
  22674. load: function ( url, onLoad, onProgress, onError ) {
  22675. var scope = this;
  22676. var loader = new FileLoader( scope.manager );
  22677. loader.setPath( scope.path );
  22678. loader.load( url, function ( text ) {
  22679. onLoad( scope.parse( JSON.parse( text ) ) );
  22680. }, onProgress, onError );
  22681. },
  22682. parse: function ( json ) {
  22683. var geometry = new BufferGeometry();
  22684. var index = json.data.index;
  22685. if ( index !== undefined ) {
  22686. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22687. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22688. }
  22689. var attributes = json.data.attributes;
  22690. for ( var key in attributes ) {
  22691. var attribute = attributes[ key ];
  22692. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22693. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22694. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22695. geometry.addAttribute( key, bufferAttribute );
  22696. }
  22697. var morphAttributes = json.data.morphAttributes;
  22698. if ( morphAttributes ) {
  22699. for ( var key in morphAttributes ) {
  22700. var attributeArray = morphAttributes[ key ];
  22701. var array = [];
  22702. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  22703. var attribute = attributeArray[ i ];
  22704. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22705. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22706. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22707. array.push( bufferAttribute );
  22708. }
  22709. geometry.morphAttributes[ key ] = array;
  22710. }
  22711. }
  22712. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22713. if ( groups !== undefined ) {
  22714. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22715. var group = groups[ i ];
  22716. geometry.addGroup( group.start, group.count, group.materialIndex );
  22717. }
  22718. }
  22719. var boundingSphere = json.data.boundingSphere;
  22720. if ( boundingSphere !== undefined ) {
  22721. var center = new Vector3();
  22722. if ( boundingSphere.center !== undefined ) {
  22723. center.fromArray( boundingSphere.center );
  22724. }
  22725. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22726. }
  22727. if ( json.name ) geometry.name = json.name;
  22728. if ( json.userData ) geometry.userData = json.userData;
  22729. return geometry;
  22730. },
  22731. setPath: function ( value ) {
  22732. this.path = value;
  22733. return this;
  22734. }
  22735. } );
  22736. var TYPED_ARRAYS = {
  22737. Int8Array: Int8Array,
  22738. Uint8Array: Uint8Array,
  22739. // Workaround for IE11 pre KB2929437. See #11440
  22740. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22741. Int16Array: Int16Array,
  22742. Uint16Array: Uint16Array,
  22743. Int32Array: Int32Array,
  22744. Uint32Array: Uint32Array,
  22745. Float32Array: Float32Array,
  22746. Float64Array: Float64Array
  22747. };
  22748. /**
  22749. * @author mrdoob / http://mrdoob.com/
  22750. */
  22751. function ObjectLoader( manager ) {
  22752. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22753. this.resourcePath = '';
  22754. }
  22755. Object.assign( ObjectLoader.prototype, {
  22756. crossOrigin: 'anonymous',
  22757. load: function ( url, onLoad, onProgress, onError ) {
  22758. var scope = this;
  22759. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22760. this.resourcePath = this.resourcePath || path;
  22761. var loader = new FileLoader( scope.manager );
  22762. loader.setPath( this.path );
  22763. loader.load( url, function ( text ) {
  22764. var json = null;
  22765. try {
  22766. json = JSON.parse( text );
  22767. } catch ( error ) {
  22768. if ( onError !== undefined ) onError( error );
  22769. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22770. return;
  22771. }
  22772. var metadata = json.metadata;
  22773. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22774. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22775. return;
  22776. }
  22777. scope.parse( json, onLoad );
  22778. }, onProgress, onError );
  22779. },
  22780. setPath: function ( value ) {
  22781. this.path = value;
  22782. return this;
  22783. },
  22784. setResourcePath: function ( value ) {
  22785. this.resourcePath = value;
  22786. return this;
  22787. },
  22788. setCrossOrigin: function ( value ) {
  22789. this.crossOrigin = value;
  22790. return this;
  22791. },
  22792. parse: function ( json, onLoad ) {
  22793. var shapes = this.parseShape( json.shapes );
  22794. var geometries = this.parseGeometries( json.geometries, shapes );
  22795. var images = this.parseImages( json.images, function () {
  22796. if ( onLoad !== undefined ) onLoad( object );
  22797. } );
  22798. var textures = this.parseTextures( json.textures, images );
  22799. var materials = this.parseMaterials( json.materials, textures );
  22800. var object = this.parseObject( json.object, geometries, materials );
  22801. if ( json.animations ) {
  22802. object.animations = this.parseAnimations( json.animations );
  22803. }
  22804. if ( json.images === undefined || json.images.length === 0 ) {
  22805. if ( onLoad !== undefined ) onLoad( object );
  22806. }
  22807. return object;
  22808. },
  22809. parseShape: function ( json ) {
  22810. var shapes = {};
  22811. if ( json !== undefined ) {
  22812. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22813. var shape = new Shape().fromJSON( json[ i ] );
  22814. shapes[ shape.uuid ] = shape;
  22815. }
  22816. }
  22817. return shapes;
  22818. },
  22819. parseGeometries: function ( json, shapes ) {
  22820. var geometries = {};
  22821. if ( json !== undefined ) {
  22822. var bufferGeometryLoader = new BufferGeometryLoader();
  22823. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22824. var geometry;
  22825. var data = json[ i ];
  22826. switch ( data.type ) {
  22827. case 'PlaneGeometry':
  22828. case 'PlaneBufferGeometry':
  22829. geometry = new Geometries[ data.type ](
  22830. data.width,
  22831. data.height,
  22832. data.widthSegments,
  22833. data.heightSegments
  22834. );
  22835. break;
  22836. case 'BoxGeometry':
  22837. case 'BoxBufferGeometry':
  22838. case 'CubeGeometry': // backwards compatible
  22839. geometry = new Geometries[ data.type ](
  22840. data.width,
  22841. data.height,
  22842. data.depth,
  22843. data.widthSegments,
  22844. data.heightSegments,
  22845. data.depthSegments
  22846. );
  22847. break;
  22848. case 'CircleGeometry':
  22849. case 'CircleBufferGeometry':
  22850. geometry = new Geometries[ data.type ](
  22851. data.radius,
  22852. data.segments,
  22853. data.thetaStart,
  22854. data.thetaLength
  22855. );
  22856. break;
  22857. case 'CylinderGeometry':
  22858. case 'CylinderBufferGeometry':
  22859. geometry = new Geometries[ data.type ](
  22860. data.radiusTop,
  22861. data.radiusBottom,
  22862. data.height,
  22863. data.radialSegments,
  22864. data.heightSegments,
  22865. data.openEnded,
  22866. data.thetaStart,
  22867. data.thetaLength
  22868. );
  22869. break;
  22870. case 'ConeGeometry':
  22871. case 'ConeBufferGeometry':
  22872. geometry = new Geometries[ data.type ](
  22873. data.radius,
  22874. data.height,
  22875. data.radialSegments,
  22876. data.heightSegments,
  22877. data.openEnded,
  22878. data.thetaStart,
  22879. data.thetaLength
  22880. );
  22881. break;
  22882. case 'SphereGeometry':
  22883. case 'SphereBufferGeometry':
  22884. geometry = new Geometries[ data.type ](
  22885. data.radius,
  22886. data.widthSegments,
  22887. data.heightSegments,
  22888. data.phiStart,
  22889. data.phiLength,
  22890. data.thetaStart,
  22891. data.thetaLength
  22892. );
  22893. break;
  22894. case 'DodecahedronGeometry':
  22895. case 'DodecahedronBufferGeometry':
  22896. case 'IcosahedronGeometry':
  22897. case 'IcosahedronBufferGeometry':
  22898. case 'OctahedronGeometry':
  22899. case 'OctahedronBufferGeometry':
  22900. case 'TetrahedronGeometry':
  22901. case 'TetrahedronBufferGeometry':
  22902. geometry = new Geometries[ data.type ](
  22903. data.radius,
  22904. data.detail
  22905. );
  22906. break;
  22907. case 'RingGeometry':
  22908. case 'RingBufferGeometry':
  22909. geometry = new Geometries[ data.type ](
  22910. data.innerRadius,
  22911. data.outerRadius,
  22912. data.thetaSegments,
  22913. data.phiSegments,
  22914. data.thetaStart,
  22915. data.thetaLength
  22916. );
  22917. break;
  22918. case 'TorusGeometry':
  22919. case 'TorusBufferGeometry':
  22920. geometry = new Geometries[ data.type ](
  22921. data.radius,
  22922. data.tube,
  22923. data.radialSegments,
  22924. data.tubularSegments,
  22925. data.arc
  22926. );
  22927. break;
  22928. case 'TorusKnotGeometry':
  22929. case 'TorusKnotBufferGeometry':
  22930. geometry = new Geometries[ data.type ](
  22931. data.radius,
  22932. data.tube,
  22933. data.tubularSegments,
  22934. data.radialSegments,
  22935. data.p,
  22936. data.q
  22937. );
  22938. break;
  22939. case 'TubeGeometry':
  22940. case 'TubeBufferGeometry':
  22941. // This only works for built-in curves (e.g. CatmullRomCurve3).
  22942. // User defined curves or instances of CurvePath will not be deserialized.
  22943. geometry = new Geometries[ data.type ](
  22944. new Curves[ data.path.type ]().fromJSON( data.path ),
  22945. data.tubularSegments,
  22946. data.radius,
  22947. data.radialSegments,
  22948. data.closed
  22949. );
  22950. break;
  22951. case 'LatheGeometry':
  22952. case 'LatheBufferGeometry':
  22953. geometry = new Geometries[ data.type ](
  22954. data.points,
  22955. data.segments,
  22956. data.phiStart,
  22957. data.phiLength
  22958. );
  22959. break;
  22960. case 'PolyhedronGeometry':
  22961. case 'PolyhedronBufferGeometry':
  22962. geometry = new Geometries[ data.type ](
  22963. data.vertices,
  22964. data.indices,
  22965. data.radius,
  22966. data.details
  22967. );
  22968. break;
  22969. case 'ShapeGeometry':
  22970. case 'ShapeBufferGeometry':
  22971. var geometryShapes = [];
  22972. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22973. var shape = shapes[ data.shapes[ j ] ];
  22974. geometryShapes.push( shape );
  22975. }
  22976. geometry = new Geometries[ data.type ](
  22977. geometryShapes,
  22978. data.curveSegments
  22979. );
  22980. break;
  22981. case 'ExtrudeGeometry':
  22982. case 'ExtrudeBufferGeometry':
  22983. var geometryShapes = [];
  22984. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22985. var shape = shapes[ data.shapes[ j ] ];
  22986. geometryShapes.push( shape );
  22987. }
  22988. var extrudePath = data.options.extrudePath;
  22989. if ( extrudePath !== undefined ) {
  22990. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  22991. }
  22992. geometry = new Geometries[ data.type ](
  22993. geometryShapes,
  22994. data.options
  22995. );
  22996. break;
  22997. case 'BufferGeometry':
  22998. geometry = bufferGeometryLoader.parse( data );
  22999. break;
  23000. case 'Geometry':
  23001. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23002. var geometryLoader = new THREE.LegacyJSONLoader();
  23003. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23004. } else {
  23005. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23006. }
  23007. break;
  23008. default:
  23009. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23010. continue;
  23011. }
  23012. geometry.uuid = data.uuid;
  23013. if ( data.name !== undefined ) geometry.name = data.name;
  23014. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23015. geometries[ data.uuid ] = geometry;
  23016. }
  23017. }
  23018. return geometries;
  23019. },
  23020. parseMaterials: function ( json, textures ) {
  23021. var cache = {}; // MultiMaterial
  23022. var materials = {};
  23023. if ( json !== undefined ) {
  23024. var loader = new MaterialLoader();
  23025. loader.setTextures( textures );
  23026. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23027. var data = json[ i ];
  23028. if ( data.type === 'MultiMaterial' ) {
  23029. // Deprecated
  23030. var array = [];
  23031. for ( var j = 0; j < data.materials.length; j ++ ) {
  23032. var material = data.materials[ j ];
  23033. if ( cache[ material.uuid ] === undefined ) {
  23034. cache[ material.uuid ] = loader.parse( material );
  23035. }
  23036. array.push( cache[ material.uuid ] );
  23037. }
  23038. materials[ data.uuid ] = array;
  23039. } else {
  23040. if ( cache[ data.uuid ] === undefined ) {
  23041. cache[ data.uuid ] = loader.parse( data );
  23042. }
  23043. materials[ data.uuid ] = cache[ data.uuid ];
  23044. }
  23045. }
  23046. }
  23047. return materials;
  23048. },
  23049. parseAnimations: function ( json ) {
  23050. var animations = [];
  23051. for ( var i = 0; i < json.length; i ++ ) {
  23052. var data = json[ i ];
  23053. var clip = AnimationClip.parse( data );
  23054. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23055. animations.push( clip );
  23056. }
  23057. return animations;
  23058. },
  23059. parseImages: function ( json, onLoad ) {
  23060. var scope = this;
  23061. var images = {};
  23062. function loadImage( url ) {
  23063. scope.manager.itemStart( url );
  23064. return loader.load( url, function () {
  23065. scope.manager.itemEnd( url );
  23066. }, undefined, function () {
  23067. scope.manager.itemError( url );
  23068. scope.manager.itemEnd( url );
  23069. } );
  23070. }
  23071. if ( json !== undefined && json.length > 0 ) {
  23072. var manager = new LoadingManager( onLoad );
  23073. var loader = new ImageLoader( manager );
  23074. loader.setCrossOrigin( this.crossOrigin );
  23075. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23076. var image = json[ i ];
  23077. var url = image.url;
  23078. if ( Array.isArray( url ) ) {
  23079. // load array of images e.g CubeTexture
  23080. images[ image.uuid ] = [];
  23081. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23082. var currentUrl = url[ j ];
  23083. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23084. images[ image.uuid ].push( loadImage( path ) );
  23085. }
  23086. } else {
  23087. // load single image
  23088. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23089. images[ image.uuid ] = loadImage( path );
  23090. }
  23091. }
  23092. }
  23093. return images;
  23094. },
  23095. parseTextures: function ( json, images ) {
  23096. function parseConstant( value, type ) {
  23097. if ( typeof value === 'number' ) return value;
  23098. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23099. return type[ value ];
  23100. }
  23101. var textures = {};
  23102. if ( json !== undefined ) {
  23103. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23104. var data = json[ i ];
  23105. if ( data.image === undefined ) {
  23106. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23107. }
  23108. if ( images[ data.image ] === undefined ) {
  23109. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23110. }
  23111. var texture;
  23112. if ( Array.isArray( images[ data.image ] ) ) {
  23113. texture = new CubeTexture( images[ data.image ] );
  23114. } else {
  23115. texture = new Texture( images[ data.image ] );
  23116. }
  23117. texture.needsUpdate = true;
  23118. texture.uuid = data.uuid;
  23119. if ( data.name !== undefined ) texture.name = data.name;
  23120. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23121. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23122. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23123. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23124. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23125. if ( data.wrap !== undefined ) {
  23126. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23127. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23128. }
  23129. if ( data.format !== undefined ) texture.format = data.format;
  23130. if ( data.type !== undefined ) texture.type = data.type;
  23131. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23132. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23133. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23134. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23135. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23136. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23137. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23138. textures[ data.uuid ] = texture;
  23139. }
  23140. }
  23141. return textures;
  23142. },
  23143. parseObject: function ( data, geometries, materials ) {
  23144. var object;
  23145. function getGeometry( name ) {
  23146. if ( geometries[ name ] === undefined ) {
  23147. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23148. }
  23149. return geometries[ name ];
  23150. }
  23151. function getMaterial( name ) {
  23152. if ( name === undefined ) return undefined;
  23153. if ( Array.isArray( name ) ) {
  23154. var array = [];
  23155. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23156. var uuid = name[ i ];
  23157. if ( materials[ uuid ] === undefined ) {
  23158. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23159. }
  23160. array.push( materials[ uuid ] );
  23161. }
  23162. return array;
  23163. }
  23164. if ( materials[ name ] === undefined ) {
  23165. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23166. }
  23167. return materials[ name ];
  23168. }
  23169. switch ( data.type ) {
  23170. case 'Scene':
  23171. object = new Scene();
  23172. if ( data.background !== undefined ) {
  23173. if ( Number.isInteger( data.background ) ) {
  23174. object.background = new Color( data.background );
  23175. }
  23176. }
  23177. if ( data.fog !== undefined ) {
  23178. if ( data.fog.type === 'Fog' ) {
  23179. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23180. } else if ( data.fog.type === 'FogExp2' ) {
  23181. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23182. }
  23183. }
  23184. break;
  23185. case 'PerspectiveCamera':
  23186. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23187. if ( data.focus !== undefined ) object.focus = data.focus;
  23188. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23189. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23190. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23191. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23192. break;
  23193. case 'OrthographicCamera':
  23194. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23195. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23196. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23197. break;
  23198. case 'AmbientLight':
  23199. object = new AmbientLight( data.color, data.intensity );
  23200. break;
  23201. case 'DirectionalLight':
  23202. object = new DirectionalLight( data.color, data.intensity );
  23203. break;
  23204. case 'PointLight':
  23205. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23206. break;
  23207. case 'RectAreaLight':
  23208. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23209. break;
  23210. case 'SpotLight':
  23211. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23212. break;
  23213. case 'HemisphereLight':
  23214. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23215. break;
  23216. case 'SkinnedMesh':
  23217. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23218. case 'Mesh':
  23219. var geometry = getGeometry( data.geometry );
  23220. var material = getMaterial( data.material );
  23221. if ( geometry.bones && geometry.bones.length > 0 ) {
  23222. object = new SkinnedMesh( geometry, material );
  23223. } else {
  23224. object = new Mesh( geometry, material );
  23225. }
  23226. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23227. break;
  23228. case 'LOD':
  23229. object = new LOD();
  23230. break;
  23231. case 'Line':
  23232. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23233. break;
  23234. case 'LineLoop':
  23235. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23236. break;
  23237. case 'LineSegments':
  23238. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23239. break;
  23240. case 'PointCloud':
  23241. case 'Points':
  23242. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23243. break;
  23244. case 'Sprite':
  23245. object = new Sprite( getMaterial( data.material ) );
  23246. break;
  23247. case 'Group':
  23248. object = new Group();
  23249. break;
  23250. default:
  23251. object = new Object3D();
  23252. }
  23253. object.uuid = data.uuid;
  23254. if ( data.name !== undefined ) object.name = data.name;
  23255. if ( data.matrix !== undefined ) {
  23256. object.matrix.fromArray( data.matrix );
  23257. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23258. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23259. } else {
  23260. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23261. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23262. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23263. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23264. }
  23265. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23266. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23267. if ( data.shadow ) {
  23268. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23269. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23270. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23271. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23272. }
  23273. if ( data.visible !== undefined ) object.visible = data.visible;
  23274. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23275. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23276. if ( data.userData !== undefined ) object.userData = data.userData;
  23277. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23278. if ( data.children !== undefined ) {
  23279. var children = data.children;
  23280. for ( var i = 0; i < children.length; i ++ ) {
  23281. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23282. }
  23283. }
  23284. if ( data.type === 'LOD' ) {
  23285. var levels = data.levels;
  23286. for ( var l = 0; l < levels.length; l ++ ) {
  23287. var level = levels[ l ];
  23288. var child = object.getObjectByProperty( 'uuid', level.object );
  23289. if ( child !== undefined ) {
  23290. object.addLevel( child, level.distance );
  23291. }
  23292. }
  23293. }
  23294. return object;
  23295. }
  23296. } );
  23297. var TEXTURE_MAPPING = {
  23298. UVMapping: UVMapping,
  23299. CubeReflectionMapping: CubeReflectionMapping,
  23300. CubeRefractionMapping: CubeRefractionMapping,
  23301. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23302. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23303. SphericalReflectionMapping: SphericalReflectionMapping,
  23304. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23305. CubeUVRefractionMapping: CubeUVRefractionMapping
  23306. };
  23307. var TEXTURE_WRAPPING = {
  23308. RepeatWrapping: RepeatWrapping,
  23309. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23310. MirroredRepeatWrapping: MirroredRepeatWrapping
  23311. };
  23312. var TEXTURE_FILTER = {
  23313. NearestFilter: NearestFilter,
  23314. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23315. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23316. LinearFilter: LinearFilter,
  23317. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23318. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23319. };
  23320. /**
  23321. * @author thespite / http://clicktorelease.com/
  23322. */
  23323. function ImageBitmapLoader( manager ) {
  23324. if ( typeof createImageBitmap === 'undefined' ) {
  23325. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23326. }
  23327. if ( typeof fetch === 'undefined' ) {
  23328. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23329. }
  23330. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23331. this.options = undefined;
  23332. }
  23333. ImageBitmapLoader.prototype = {
  23334. constructor: ImageBitmapLoader,
  23335. setOptions: function setOptions( options ) {
  23336. this.options = options;
  23337. return this;
  23338. },
  23339. load: function ( url, onLoad, onProgress, onError ) {
  23340. if ( url === undefined ) url = '';
  23341. if ( this.path !== undefined ) url = this.path + url;
  23342. url = this.manager.resolveURL( url );
  23343. var scope = this;
  23344. var cached = Cache.get( url );
  23345. if ( cached !== undefined ) {
  23346. scope.manager.itemStart( url );
  23347. setTimeout( function () {
  23348. if ( onLoad ) onLoad( cached );
  23349. scope.manager.itemEnd( url );
  23350. }, 0 );
  23351. return cached;
  23352. }
  23353. fetch( url ).then( function ( res ) {
  23354. return res.blob();
  23355. } ).then( function ( blob ) {
  23356. if ( scope.options === undefined ) {
  23357. // Workaround for FireFox. It causes an error if you pass options.
  23358. return createImageBitmap( blob );
  23359. } else {
  23360. return createImageBitmap( blob, scope.options );
  23361. }
  23362. } ).then( function ( imageBitmap ) {
  23363. Cache.add( url, imageBitmap );
  23364. if ( onLoad ) onLoad( imageBitmap );
  23365. scope.manager.itemEnd( url );
  23366. } ).catch( function ( e ) {
  23367. if ( onError ) onError( e );
  23368. scope.manager.itemError( url );
  23369. scope.manager.itemEnd( url );
  23370. } );
  23371. scope.manager.itemStart( url );
  23372. },
  23373. setCrossOrigin: function ( /* value */ ) {
  23374. return this;
  23375. },
  23376. setPath: function ( value ) {
  23377. this.path = value;
  23378. return this;
  23379. }
  23380. };
  23381. /**
  23382. * @author zz85 / http://www.lab4games.net/zz85/blog
  23383. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23384. **/
  23385. function ShapePath() {
  23386. this.type = 'ShapePath';
  23387. this.color = new Color();
  23388. this.subPaths = [];
  23389. this.currentPath = null;
  23390. }
  23391. Object.assign( ShapePath.prototype, {
  23392. moveTo: function ( x, y ) {
  23393. this.currentPath = new Path();
  23394. this.subPaths.push( this.currentPath );
  23395. this.currentPath.moveTo( x, y );
  23396. },
  23397. lineTo: function ( x, y ) {
  23398. this.currentPath.lineTo( x, y );
  23399. },
  23400. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23401. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23402. },
  23403. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23404. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23405. },
  23406. splineThru: function ( pts ) {
  23407. this.currentPath.splineThru( pts );
  23408. },
  23409. toShapes: function ( isCCW, noHoles ) {
  23410. function toShapesNoHoles( inSubpaths ) {
  23411. var shapes = [];
  23412. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23413. var tmpPath = inSubpaths[ i ];
  23414. var tmpShape = new Shape();
  23415. tmpShape.curves = tmpPath.curves;
  23416. shapes.push( tmpShape );
  23417. }
  23418. return shapes;
  23419. }
  23420. function isPointInsidePolygon( inPt, inPolygon ) {
  23421. var polyLen = inPolygon.length;
  23422. // inPt on polygon contour => immediate success or
  23423. // toggling of inside/outside at every single! intersection point of an edge
  23424. // with the horizontal line through inPt, left of inPt
  23425. // not counting lowerY endpoints of edges and whole edges on that line
  23426. var inside = false;
  23427. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23428. var edgeLowPt = inPolygon[ p ];
  23429. var edgeHighPt = inPolygon[ q ];
  23430. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23431. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23432. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23433. // not parallel
  23434. if ( edgeDy < 0 ) {
  23435. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23436. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23437. }
  23438. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23439. if ( inPt.y === edgeLowPt.y ) {
  23440. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23441. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23442. } else {
  23443. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23444. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23445. if ( perpEdge < 0 ) continue;
  23446. inside = ! inside; // true intersection left of inPt
  23447. }
  23448. } else {
  23449. // parallel or collinear
  23450. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23451. // edge lies on the same horizontal line as inPt
  23452. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23453. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23454. // continue;
  23455. }
  23456. }
  23457. return inside;
  23458. }
  23459. var isClockWise = ShapeUtils.isClockWise;
  23460. var subPaths = this.subPaths;
  23461. if ( subPaths.length === 0 ) return [];
  23462. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23463. var solid, tmpPath, tmpShape, shapes = [];
  23464. if ( subPaths.length === 1 ) {
  23465. tmpPath = subPaths[ 0 ];
  23466. tmpShape = new Shape();
  23467. tmpShape.curves = tmpPath.curves;
  23468. shapes.push( tmpShape );
  23469. return shapes;
  23470. }
  23471. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23472. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23473. // console.log("Holes first", holesFirst);
  23474. var betterShapeHoles = [];
  23475. var newShapes = [];
  23476. var newShapeHoles = [];
  23477. var mainIdx = 0;
  23478. var tmpPoints;
  23479. newShapes[ mainIdx ] = undefined;
  23480. newShapeHoles[ mainIdx ] = [];
  23481. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23482. tmpPath = subPaths[ i ];
  23483. tmpPoints = tmpPath.getPoints();
  23484. solid = isClockWise( tmpPoints );
  23485. solid = isCCW ? ! solid : solid;
  23486. if ( solid ) {
  23487. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23488. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23489. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23490. if ( holesFirst ) mainIdx ++;
  23491. newShapeHoles[ mainIdx ] = [];
  23492. //console.log('cw', i);
  23493. } else {
  23494. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23495. //console.log('ccw', i);
  23496. }
  23497. }
  23498. // only Holes? -> probably all Shapes with wrong orientation
  23499. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23500. if ( newShapes.length > 1 ) {
  23501. var ambiguous = false;
  23502. var toChange = [];
  23503. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23504. betterShapeHoles[ sIdx ] = [];
  23505. }
  23506. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23507. var sho = newShapeHoles[ sIdx ];
  23508. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23509. var ho = sho[ hIdx ];
  23510. var hole_unassigned = true;
  23511. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23512. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23513. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23514. if ( hole_unassigned ) {
  23515. hole_unassigned = false;
  23516. betterShapeHoles[ s2Idx ].push( ho );
  23517. } else {
  23518. ambiguous = true;
  23519. }
  23520. }
  23521. }
  23522. if ( hole_unassigned ) {
  23523. betterShapeHoles[ sIdx ].push( ho );
  23524. }
  23525. }
  23526. }
  23527. // console.log("ambiguous: ", ambiguous);
  23528. if ( toChange.length > 0 ) {
  23529. // console.log("to change: ", toChange);
  23530. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23531. }
  23532. }
  23533. var tmpHoles;
  23534. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23535. tmpShape = newShapes[ i ].s;
  23536. shapes.push( tmpShape );
  23537. tmpHoles = newShapeHoles[ i ];
  23538. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23539. tmpShape.holes.push( tmpHoles[ j ].h );
  23540. }
  23541. }
  23542. //console.log("shape", shapes);
  23543. return shapes;
  23544. }
  23545. } );
  23546. /**
  23547. * @author zz85 / http://www.lab4games.net/zz85/blog
  23548. * @author mrdoob / http://mrdoob.com/
  23549. */
  23550. function Font( data ) {
  23551. this.type = 'Font';
  23552. this.data = data;
  23553. }
  23554. Object.assign( Font.prototype, {
  23555. isFont: true,
  23556. generateShapes: function ( text, size ) {
  23557. if ( size === undefined ) size = 100;
  23558. var shapes = [];
  23559. var paths = createPaths( text, size, this.data );
  23560. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23561. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23562. }
  23563. return shapes;
  23564. }
  23565. } );
  23566. function createPaths( text, size, data ) {
  23567. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23568. var scale = size / data.resolution;
  23569. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23570. var paths = [];
  23571. var offsetX = 0, offsetY = 0;
  23572. for ( var i = 0; i < chars.length; i ++ ) {
  23573. var char = chars[ i ];
  23574. if ( char === '\n' ) {
  23575. offsetX = 0;
  23576. offsetY -= line_height;
  23577. } else {
  23578. var ret = createPath( char, scale, offsetX, offsetY, data );
  23579. offsetX += ret.offsetX;
  23580. paths.push( ret.path );
  23581. }
  23582. }
  23583. return paths;
  23584. }
  23585. function createPath( char, scale, offsetX, offsetY, data ) {
  23586. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23587. if ( ! glyph ) return;
  23588. var path = new ShapePath();
  23589. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23590. if ( glyph.o ) {
  23591. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23592. for ( var i = 0, l = outline.length; i < l; ) {
  23593. var action = outline[ i ++ ];
  23594. switch ( action ) {
  23595. case 'm': // moveTo
  23596. x = outline[ i ++ ] * scale + offsetX;
  23597. y = outline[ i ++ ] * scale + offsetY;
  23598. path.moveTo( x, y );
  23599. break;
  23600. case 'l': // lineTo
  23601. x = outline[ i ++ ] * scale + offsetX;
  23602. y = outline[ i ++ ] * scale + offsetY;
  23603. path.lineTo( x, y );
  23604. break;
  23605. case 'q': // quadraticCurveTo
  23606. cpx = outline[ i ++ ] * scale + offsetX;
  23607. cpy = outline[ i ++ ] * scale + offsetY;
  23608. cpx1 = outline[ i ++ ] * scale + offsetX;
  23609. cpy1 = outline[ i ++ ] * scale + offsetY;
  23610. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23611. break;
  23612. case 'b': // bezierCurveTo
  23613. cpx = outline[ i ++ ] * scale + offsetX;
  23614. cpy = outline[ i ++ ] * scale + offsetY;
  23615. cpx1 = outline[ i ++ ] * scale + offsetX;
  23616. cpy1 = outline[ i ++ ] * scale + offsetY;
  23617. cpx2 = outline[ i ++ ] * scale + offsetX;
  23618. cpy2 = outline[ i ++ ] * scale + offsetY;
  23619. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23620. break;
  23621. }
  23622. }
  23623. }
  23624. return { offsetX: glyph.ha * scale, path: path };
  23625. }
  23626. /**
  23627. * @author mrdoob / http://mrdoob.com/
  23628. */
  23629. function FontLoader( manager ) {
  23630. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23631. }
  23632. Object.assign( FontLoader.prototype, {
  23633. load: function ( url, onLoad, onProgress, onError ) {
  23634. var scope = this;
  23635. var loader = new FileLoader( this.manager );
  23636. loader.setPath( this.path );
  23637. loader.load( url, function ( text ) {
  23638. var json;
  23639. try {
  23640. json = JSON.parse( text );
  23641. } catch ( e ) {
  23642. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23643. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23644. }
  23645. var font = scope.parse( json );
  23646. if ( onLoad ) onLoad( font );
  23647. }, onProgress, onError );
  23648. },
  23649. parse: function ( json ) {
  23650. return new Font( json );
  23651. },
  23652. setPath: function ( value ) {
  23653. this.path = value;
  23654. return this;
  23655. }
  23656. } );
  23657. /**
  23658. * @author alteredq / http://alteredqualia.com/
  23659. */
  23660. function Loader() {}
  23661. Loader.Handlers = {
  23662. handlers: [],
  23663. add: function ( regex, loader ) {
  23664. this.handlers.push( regex, loader );
  23665. },
  23666. get: function ( file ) {
  23667. var handlers = this.handlers;
  23668. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23669. var regex = handlers[ i ];
  23670. var loader = handlers[ i + 1 ];
  23671. if ( regex.test( file ) ) {
  23672. return loader;
  23673. }
  23674. }
  23675. return null;
  23676. }
  23677. };
  23678. Object.assign( Loader.prototype, {
  23679. crossOrigin: 'anonymous',
  23680. onLoadStart: function () {},
  23681. onLoadProgress: function () {},
  23682. onLoadComplete: function () {},
  23683. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23684. var array = [];
  23685. for ( var i = 0; i < materials.length; ++ i ) {
  23686. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23687. }
  23688. return array;
  23689. },
  23690. createMaterial: ( function () {
  23691. var BlendingMode = {
  23692. NoBlending: NoBlending,
  23693. NormalBlending: NormalBlending,
  23694. AdditiveBlending: AdditiveBlending,
  23695. SubtractiveBlending: SubtractiveBlending,
  23696. MultiplyBlending: MultiplyBlending,
  23697. CustomBlending: CustomBlending
  23698. };
  23699. var color = new Color();
  23700. var textureLoader = new TextureLoader();
  23701. var materialLoader = new MaterialLoader();
  23702. return function createMaterial( m, texturePath, crossOrigin ) {
  23703. // convert from old material format
  23704. var textures = {};
  23705. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23706. var fullPath = texturePath + path;
  23707. var loader = Loader.Handlers.get( fullPath );
  23708. var texture;
  23709. if ( loader !== null ) {
  23710. texture = loader.load( fullPath );
  23711. } else {
  23712. textureLoader.setCrossOrigin( crossOrigin );
  23713. texture = textureLoader.load( fullPath );
  23714. }
  23715. if ( repeat !== undefined ) {
  23716. texture.repeat.fromArray( repeat );
  23717. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23718. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23719. }
  23720. if ( offset !== undefined ) {
  23721. texture.offset.fromArray( offset );
  23722. }
  23723. if ( wrap !== undefined ) {
  23724. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23725. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23726. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23727. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23728. }
  23729. if ( anisotropy !== undefined ) {
  23730. texture.anisotropy = anisotropy;
  23731. }
  23732. var uuid = _Math.generateUUID();
  23733. textures[ uuid ] = texture;
  23734. return uuid;
  23735. }
  23736. //
  23737. var json = {
  23738. uuid: _Math.generateUUID(),
  23739. type: 'MeshLambertMaterial'
  23740. };
  23741. for ( var name in m ) {
  23742. var value = m[ name ];
  23743. switch ( name ) {
  23744. case 'DbgColor':
  23745. case 'DbgIndex':
  23746. case 'opticalDensity':
  23747. case 'illumination':
  23748. break;
  23749. case 'DbgName':
  23750. json.name = value;
  23751. break;
  23752. case 'blending':
  23753. json.blending = BlendingMode[ value ];
  23754. break;
  23755. case 'colorAmbient':
  23756. case 'mapAmbient':
  23757. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23758. break;
  23759. case 'colorDiffuse':
  23760. json.color = color.fromArray( value ).getHex();
  23761. break;
  23762. case 'colorSpecular':
  23763. json.specular = color.fromArray( value ).getHex();
  23764. break;
  23765. case 'colorEmissive':
  23766. json.emissive = color.fromArray( value ).getHex();
  23767. break;
  23768. case 'specularCoef':
  23769. json.shininess = value;
  23770. break;
  23771. case 'shading':
  23772. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23773. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23774. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23775. break;
  23776. case 'mapDiffuse':
  23777. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23778. break;
  23779. case 'mapDiffuseRepeat':
  23780. case 'mapDiffuseOffset':
  23781. case 'mapDiffuseWrap':
  23782. case 'mapDiffuseAnisotropy':
  23783. break;
  23784. case 'mapEmissive':
  23785. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23786. break;
  23787. case 'mapEmissiveRepeat':
  23788. case 'mapEmissiveOffset':
  23789. case 'mapEmissiveWrap':
  23790. case 'mapEmissiveAnisotropy':
  23791. break;
  23792. case 'mapLight':
  23793. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23794. break;
  23795. case 'mapLightRepeat':
  23796. case 'mapLightOffset':
  23797. case 'mapLightWrap':
  23798. case 'mapLightAnisotropy':
  23799. break;
  23800. case 'mapAO':
  23801. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23802. break;
  23803. case 'mapAORepeat':
  23804. case 'mapAOOffset':
  23805. case 'mapAOWrap':
  23806. case 'mapAOAnisotropy':
  23807. break;
  23808. case 'mapBump':
  23809. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23810. break;
  23811. case 'mapBumpScale':
  23812. json.bumpScale = value;
  23813. break;
  23814. case 'mapBumpRepeat':
  23815. case 'mapBumpOffset':
  23816. case 'mapBumpWrap':
  23817. case 'mapBumpAnisotropy':
  23818. break;
  23819. case 'mapNormal':
  23820. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23821. break;
  23822. case 'mapNormalFactor':
  23823. json.normalScale = value;
  23824. break;
  23825. case 'mapNormalRepeat':
  23826. case 'mapNormalOffset':
  23827. case 'mapNormalWrap':
  23828. case 'mapNormalAnisotropy':
  23829. break;
  23830. case 'mapSpecular':
  23831. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23832. break;
  23833. case 'mapSpecularRepeat':
  23834. case 'mapSpecularOffset':
  23835. case 'mapSpecularWrap':
  23836. case 'mapSpecularAnisotropy':
  23837. break;
  23838. case 'mapMetalness':
  23839. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23840. break;
  23841. case 'mapMetalnessRepeat':
  23842. case 'mapMetalnessOffset':
  23843. case 'mapMetalnessWrap':
  23844. case 'mapMetalnessAnisotropy':
  23845. break;
  23846. case 'mapRoughness':
  23847. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23848. break;
  23849. case 'mapRoughnessRepeat':
  23850. case 'mapRoughnessOffset':
  23851. case 'mapRoughnessWrap':
  23852. case 'mapRoughnessAnisotropy':
  23853. break;
  23854. case 'mapAlpha':
  23855. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23856. break;
  23857. case 'mapAlphaRepeat':
  23858. case 'mapAlphaOffset':
  23859. case 'mapAlphaWrap':
  23860. case 'mapAlphaAnisotropy':
  23861. break;
  23862. case 'flipSided':
  23863. json.side = BackSide;
  23864. break;
  23865. case 'doubleSided':
  23866. json.side = DoubleSide;
  23867. break;
  23868. case 'transparency':
  23869. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23870. json.opacity = value;
  23871. break;
  23872. case 'depthTest':
  23873. case 'depthWrite':
  23874. case 'colorWrite':
  23875. case 'opacity':
  23876. case 'reflectivity':
  23877. case 'transparent':
  23878. case 'visible':
  23879. case 'wireframe':
  23880. json[ name ] = value;
  23881. break;
  23882. case 'vertexColors':
  23883. if ( value === true ) json.vertexColors = VertexColors;
  23884. if ( value === 'face' ) json.vertexColors = FaceColors;
  23885. break;
  23886. default:
  23887. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  23888. break;
  23889. }
  23890. }
  23891. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  23892. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  23893. if ( json.opacity < 1 ) json.transparent = true;
  23894. materialLoader.setTextures( textures );
  23895. return materialLoader.parse( json );
  23896. };
  23897. } )()
  23898. } );
  23899. /**
  23900. * @author mrdoob / http://mrdoob.com/
  23901. */
  23902. var context;
  23903. var AudioContext = {
  23904. getContext: function () {
  23905. if ( context === undefined ) {
  23906. context = new ( window.AudioContext || window.webkitAudioContext )();
  23907. }
  23908. return context;
  23909. },
  23910. setContext: function ( value ) {
  23911. context = value;
  23912. }
  23913. };
  23914. /**
  23915. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23916. */
  23917. function AudioLoader( manager ) {
  23918. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23919. }
  23920. Object.assign( AudioLoader.prototype, {
  23921. load: function ( url, onLoad, onProgress, onError ) {
  23922. var loader = new FileLoader( this.manager );
  23923. loader.setResponseType( 'arraybuffer' );
  23924. loader.setPath( this.path );
  23925. loader.load( url, function ( buffer ) {
  23926. // Create a copy of the buffer. The `decodeAudioData` method
  23927. // detaches the buffer when complete, preventing reuse.
  23928. var bufferCopy = buffer.slice( 0 );
  23929. var context = AudioContext.getContext();
  23930. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23931. onLoad( audioBuffer );
  23932. } );
  23933. }, onProgress, onError );
  23934. },
  23935. setPath: function ( value ) {
  23936. this.path = value;
  23937. return this;
  23938. }
  23939. } );
  23940. /**
  23941. * @author mrdoob / http://mrdoob.com/
  23942. */
  23943. function StereoCamera() {
  23944. this.type = 'StereoCamera';
  23945. this.aspect = 1;
  23946. this.eyeSep = 0.064;
  23947. this.cameraL = new PerspectiveCamera();
  23948. this.cameraL.layers.enable( 1 );
  23949. this.cameraL.matrixAutoUpdate = false;
  23950. this.cameraR = new PerspectiveCamera();
  23951. this.cameraR.layers.enable( 2 );
  23952. this.cameraR.matrixAutoUpdate = false;
  23953. }
  23954. Object.assign( StereoCamera.prototype, {
  23955. update: ( function () {
  23956. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  23957. var eyeRight = new Matrix4();
  23958. var eyeLeft = new Matrix4();
  23959. return function update( camera ) {
  23960. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  23961. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  23962. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  23963. if ( needsUpdate ) {
  23964. instance = this;
  23965. focus = camera.focus;
  23966. fov = camera.fov;
  23967. aspect = camera.aspect * this.aspect;
  23968. near = camera.near;
  23969. far = camera.far;
  23970. zoom = camera.zoom;
  23971. // Off-axis stereoscopic effect based on
  23972. // http://paulbourke.net/stereographics/stereorender/
  23973. var projectionMatrix = camera.projectionMatrix.clone();
  23974. eyeSep = this.eyeSep / 2;
  23975. var eyeSepOnProjection = eyeSep * near / focus;
  23976. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  23977. var xmin, xmax;
  23978. // translate xOffset
  23979. eyeLeft.elements[ 12 ] = - eyeSep;
  23980. eyeRight.elements[ 12 ] = eyeSep;
  23981. // for left eye
  23982. xmin = - ymax * aspect + eyeSepOnProjection;
  23983. xmax = ymax * aspect + eyeSepOnProjection;
  23984. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23985. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23986. this.cameraL.projectionMatrix.copy( projectionMatrix );
  23987. // for right eye
  23988. xmin = - ymax * aspect - eyeSepOnProjection;
  23989. xmax = ymax * aspect - eyeSepOnProjection;
  23990. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23991. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23992. this.cameraR.projectionMatrix.copy( projectionMatrix );
  23993. }
  23994. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  23995. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  23996. };
  23997. } )()
  23998. } );
  23999. /**
  24000. * Camera for rendering cube maps
  24001. * - renders scene into axis-aligned cube
  24002. *
  24003. * @author alteredq / http://alteredqualia.com/
  24004. */
  24005. var fov = 90, aspect = 1;
  24006. function CubeCamera( near, far, cubeResolution, options ) {
  24007. Object3D.call( this );
  24008. this.type = 'CubeCamera';
  24009. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  24010. cameraPX.up.set( 0, - 1, 0 );
  24011. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  24012. this.add( cameraPX );
  24013. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  24014. cameraNX.up.set( 0, - 1, 0 );
  24015. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  24016. this.add( cameraNX );
  24017. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  24018. cameraPY.up.set( 0, 0, 1 );
  24019. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  24020. this.add( cameraPY );
  24021. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  24022. cameraNY.up.set( 0, 0, - 1 );
  24023. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  24024. this.add( cameraNY );
  24025. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  24026. cameraPZ.up.set( 0, - 1, 0 );
  24027. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  24028. this.add( cameraPZ );
  24029. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  24030. cameraNZ.up.set( 0, - 1, 0 );
  24031. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  24032. this.add( cameraNZ );
  24033. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  24034. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  24035. this.renderTarget.texture.name = "CubeCamera";
  24036. this.update = function ( renderer, scene ) {
  24037. if ( this.parent === null ) this.updateMatrixWorld();
  24038. var currentRenderTarget = renderer.getRenderTarget();
  24039. var renderTarget = this.renderTarget;
  24040. var generateMipmaps = renderTarget.texture.generateMipmaps;
  24041. renderTarget.texture.generateMipmaps = false;
  24042. renderer.setRenderTarget( renderTarget, 0 );
  24043. renderer.render( scene, cameraPX );
  24044. renderer.setRenderTarget( renderTarget, 1 );
  24045. renderer.render( scene, cameraNX );
  24046. renderer.setRenderTarget( renderTarget, 2 );
  24047. renderer.render( scene, cameraPY );
  24048. renderer.setRenderTarget( renderTarget, 3 );
  24049. renderer.render( scene, cameraNY );
  24050. renderer.setRenderTarget( renderTarget, 4 );
  24051. renderer.render( scene, cameraPZ );
  24052. renderTarget.texture.generateMipmaps = generateMipmaps;
  24053. renderer.setRenderTarget( renderTarget, 5 );
  24054. renderer.render( scene, cameraNZ );
  24055. renderer.setRenderTarget( currentRenderTarget );
  24056. };
  24057. this.clear = function ( renderer, color, depth, stencil ) {
  24058. var currentRenderTarget = renderer.getRenderTarget();
  24059. var renderTarget = this.renderTarget;
  24060. for ( var i = 0; i < 6; i ++ ) {
  24061. renderer.setRenderTarget( renderTarget, i );
  24062. renderer.clear( color, depth, stencil );
  24063. }
  24064. renderer.setRenderTarget( currentRenderTarget );
  24065. };
  24066. }
  24067. CubeCamera.prototype = Object.create( Object3D.prototype );
  24068. CubeCamera.prototype.constructor = CubeCamera;
  24069. /**
  24070. * @author alteredq / http://alteredqualia.com/
  24071. */
  24072. function Clock( autoStart ) {
  24073. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24074. this.startTime = 0;
  24075. this.oldTime = 0;
  24076. this.elapsedTime = 0;
  24077. this.running = false;
  24078. }
  24079. Object.assign( Clock.prototype, {
  24080. start: function () {
  24081. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24082. this.oldTime = this.startTime;
  24083. this.elapsedTime = 0;
  24084. this.running = true;
  24085. },
  24086. stop: function () {
  24087. this.getElapsedTime();
  24088. this.running = false;
  24089. this.autoStart = false;
  24090. },
  24091. getElapsedTime: function () {
  24092. this.getDelta();
  24093. return this.elapsedTime;
  24094. },
  24095. getDelta: function () {
  24096. var diff = 0;
  24097. if ( this.autoStart && ! this.running ) {
  24098. this.start();
  24099. return 0;
  24100. }
  24101. if ( this.running ) {
  24102. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24103. diff = ( newTime - this.oldTime ) / 1000;
  24104. this.oldTime = newTime;
  24105. this.elapsedTime += diff;
  24106. }
  24107. return diff;
  24108. }
  24109. } );
  24110. /**
  24111. * @author mrdoob / http://mrdoob.com/
  24112. */
  24113. function AudioListener() {
  24114. Object3D.call( this );
  24115. this.type = 'AudioListener';
  24116. this.context = AudioContext.getContext();
  24117. this.gain = this.context.createGain();
  24118. this.gain.connect( this.context.destination );
  24119. this.filter = null;
  24120. this.timeDelta = 0;
  24121. }
  24122. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24123. constructor: AudioListener,
  24124. getInput: function () {
  24125. return this.gain;
  24126. },
  24127. removeFilter: function ( ) {
  24128. if ( this.filter !== null ) {
  24129. this.gain.disconnect( this.filter );
  24130. this.filter.disconnect( this.context.destination );
  24131. this.gain.connect( this.context.destination );
  24132. this.filter = null;
  24133. }
  24134. return this;
  24135. },
  24136. getFilter: function () {
  24137. return this.filter;
  24138. },
  24139. setFilter: function ( value ) {
  24140. if ( this.filter !== null ) {
  24141. this.gain.disconnect( this.filter );
  24142. this.filter.disconnect( this.context.destination );
  24143. } else {
  24144. this.gain.disconnect( this.context.destination );
  24145. }
  24146. this.filter = value;
  24147. this.gain.connect( this.filter );
  24148. this.filter.connect( this.context.destination );
  24149. return this;
  24150. },
  24151. getMasterVolume: function () {
  24152. return this.gain.gain.value;
  24153. },
  24154. setMasterVolume: function ( value ) {
  24155. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24156. return this;
  24157. },
  24158. updateMatrixWorld: ( function () {
  24159. var position = new Vector3();
  24160. var quaternion = new Quaternion();
  24161. var scale = new Vector3();
  24162. var orientation = new Vector3();
  24163. var clock = new Clock();
  24164. return function updateMatrixWorld( force ) {
  24165. Object3D.prototype.updateMatrixWorld.call( this, force );
  24166. var listener = this.context.listener;
  24167. var up = this.up;
  24168. this.timeDelta = clock.getDelta();
  24169. this.matrixWorld.decompose( position, quaternion, scale );
  24170. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24171. if ( listener.positionX ) {
  24172. // code path for Chrome (see #14393)
  24173. var endTime = this.context.currentTime + this.timeDelta;
  24174. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24175. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24176. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24177. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24178. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24179. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24180. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24181. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24182. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24183. } else {
  24184. listener.setPosition( position.x, position.y, position.z );
  24185. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24186. }
  24187. };
  24188. } )()
  24189. } );
  24190. /**
  24191. * @author mrdoob / http://mrdoob.com/
  24192. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24193. */
  24194. function Audio( listener ) {
  24195. Object3D.call( this );
  24196. this.type = 'Audio';
  24197. this.listener = listener;
  24198. this.context = listener.context;
  24199. this.gain = this.context.createGain();
  24200. this.gain.connect( listener.getInput() );
  24201. this.autoplay = false;
  24202. this.buffer = null;
  24203. this.detune = 0;
  24204. this.loop = false;
  24205. this.startTime = 0;
  24206. this.offset = 0;
  24207. this.playbackRate = 1;
  24208. this.isPlaying = false;
  24209. this.hasPlaybackControl = true;
  24210. this.sourceType = 'empty';
  24211. this.filters = [];
  24212. }
  24213. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24214. constructor: Audio,
  24215. getOutput: function () {
  24216. return this.gain;
  24217. },
  24218. setNodeSource: function ( audioNode ) {
  24219. this.hasPlaybackControl = false;
  24220. this.sourceType = 'audioNode';
  24221. this.source = audioNode;
  24222. this.connect();
  24223. return this;
  24224. },
  24225. setMediaElementSource: function ( mediaElement ) {
  24226. this.hasPlaybackControl = false;
  24227. this.sourceType = 'mediaNode';
  24228. this.source = this.context.createMediaElementSource( mediaElement );
  24229. this.connect();
  24230. return this;
  24231. },
  24232. setBuffer: function ( audioBuffer ) {
  24233. this.buffer = audioBuffer;
  24234. this.sourceType = 'buffer';
  24235. if ( this.autoplay ) this.play();
  24236. return this;
  24237. },
  24238. play: function () {
  24239. if ( this.isPlaying === true ) {
  24240. console.warn( 'THREE.Audio: Audio is already playing.' );
  24241. return;
  24242. }
  24243. if ( this.hasPlaybackControl === false ) {
  24244. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24245. return;
  24246. }
  24247. var source = this.context.createBufferSource();
  24248. source.buffer = this.buffer;
  24249. source.loop = this.loop;
  24250. source.onended = this.onEnded.bind( this );
  24251. this.startTime = this.context.currentTime;
  24252. source.start( this.startTime, this.offset );
  24253. this.isPlaying = true;
  24254. this.source = source;
  24255. this.setDetune( this.detune );
  24256. this.setPlaybackRate( this.playbackRate );
  24257. return this.connect();
  24258. },
  24259. pause: function () {
  24260. if ( this.hasPlaybackControl === false ) {
  24261. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24262. return;
  24263. }
  24264. if ( this.isPlaying === true ) {
  24265. this.source.stop();
  24266. this.source.onended = null;
  24267. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24268. this.isPlaying = false;
  24269. }
  24270. return this;
  24271. },
  24272. stop: function () {
  24273. if ( this.hasPlaybackControl === false ) {
  24274. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24275. return;
  24276. }
  24277. this.source.stop();
  24278. this.source.onended = null;
  24279. this.offset = 0;
  24280. this.isPlaying = false;
  24281. return this;
  24282. },
  24283. connect: function () {
  24284. if ( this.filters.length > 0 ) {
  24285. this.source.connect( this.filters[ 0 ] );
  24286. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24287. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24288. }
  24289. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24290. } else {
  24291. this.source.connect( this.getOutput() );
  24292. }
  24293. return this;
  24294. },
  24295. disconnect: function () {
  24296. if ( this.filters.length > 0 ) {
  24297. this.source.disconnect( this.filters[ 0 ] );
  24298. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24299. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24300. }
  24301. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24302. } else {
  24303. this.source.disconnect( this.getOutput() );
  24304. }
  24305. return this;
  24306. },
  24307. getFilters: function () {
  24308. return this.filters;
  24309. },
  24310. setFilters: function ( value ) {
  24311. if ( ! value ) value = [];
  24312. if ( this.isPlaying === true ) {
  24313. this.disconnect();
  24314. this.filters = value;
  24315. this.connect();
  24316. } else {
  24317. this.filters = value;
  24318. }
  24319. return this;
  24320. },
  24321. setDetune: function ( value ) {
  24322. this.detune = value;
  24323. if ( this.source.detune === undefined ) return; // only set detune when available
  24324. if ( this.isPlaying === true ) {
  24325. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24326. }
  24327. return this;
  24328. },
  24329. getDetune: function () {
  24330. return this.detune;
  24331. },
  24332. getFilter: function () {
  24333. return this.getFilters()[ 0 ];
  24334. },
  24335. setFilter: function ( filter ) {
  24336. return this.setFilters( filter ? [ filter ] : [] );
  24337. },
  24338. setPlaybackRate: function ( value ) {
  24339. if ( this.hasPlaybackControl === false ) {
  24340. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24341. return;
  24342. }
  24343. this.playbackRate = value;
  24344. if ( this.isPlaying === true ) {
  24345. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24346. }
  24347. return this;
  24348. },
  24349. getPlaybackRate: function () {
  24350. return this.playbackRate;
  24351. },
  24352. onEnded: function () {
  24353. this.isPlaying = false;
  24354. },
  24355. getLoop: function () {
  24356. if ( this.hasPlaybackControl === false ) {
  24357. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24358. return false;
  24359. }
  24360. return this.loop;
  24361. },
  24362. setLoop: function ( value ) {
  24363. if ( this.hasPlaybackControl === false ) {
  24364. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24365. return;
  24366. }
  24367. this.loop = value;
  24368. if ( this.isPlaying === true ) {
  24369. this.source.loop = this.loop;
  24370. }
  24371. return this;
  24372. },
  24373. getVolume: function () {
  24374. return this.gain.gain.value;
  24375. },
  24376. setVolume: function ( value ) {
  24377. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24378. return this;
  24379. }
  24380. } );
  24381. /**
  24382. * @author mrdoob / http://mrdoob.com/
  24383. */
  24384. function PositionalAudio( listener ) {
  24385. Audio.call( this, listener );
  24386. this.panner = this.context.createPanner();
  24387. this.panner.connect( this.gain );
  24388. }
  24389. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24390. constructor: PositionalAudio,
  24391. getOutput: function () {
  24392. return this.panner;
  24393. },
  24394. getRefDistance: function () {
  24395. return this.panner.refDistance;
  24396. },
  24397. setRefDistance: function ( value ) {
  24398. this.panner.refDistance = value;
  24399. return this;
  24400. },
  24401. getRolloffFactor: function () {
  24402. return this.panner.rolloffFactor;
  24403. },
  24404. setRolloffFactor: function ( value ) {
  24405. this.panner.rolloffFactor = value;
  24406. return this;
  24407. },
  24408. getDistanceModel: function () {
  24409. return this.panner.distanceModel;
  24410. },
  24411. setDistanceModel: function ( value ) {
  24412. this.panner.distanceModel = value;
  24413. return this;
  24414. },
  24415. getMaxDistance: function () {
  24416. return this.panner.maxDistance;
  24417. },
  24418. setMaxDistance: function ( value ) {
  24419. this.panner.maxDistance = value;
  24420. return this;
  24421. },
  24422. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24423. this.panner.coneInnerAngle = coneInnerAngle;
  24424. this.panner.coneOuterAngle = coneOuterAngle;
  24425. this.panner.coneOuterGain = coneOuterGain;
  24426. return this;
  24427. },
  24428. updateMatrixWorld: ( function () {
  24429. var position = new Vector3();
  24430. var quaternion = new Quaternion();
  24431. var scale = new Vector3();
  24432. var orientation = new Vector3();
  24433. return function updateMatrixWorld( force ) {
  24434. Object3D.prototype.updateMatrixWorld.call( this, force );
  24435. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24436. this.matrixWorld.decompose( position, quaternion, scale );
  24437. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24438. var panner = this.panner;
  24439. if ( panner.positionX ) {
  24440. // code path for Chrome and Firefox (see #14393)
  24441. var endTime = this.context.currentTime + this.listener.timeDelta;
  24442. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24443. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24444. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24445. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24446. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24447. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24448. } else {
  24449. panner.setPosition( position.x, position.y, position.z );
  24450. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24451. }
  24452. };
  24453. } )()
  24454. } );
  24455. /**
  24456. * @author mrdoob / http://mrdoob.com/
  24457. */
  24458. function AudioAnalyser( audio, fftSize ) {
  24459. this.analyser = audio.context.createAnalyser();
  24460. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24461. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24462. audio.getOutput().connect( this.analyser );
  24463. }
  24464. Object.assign( AudioAnalyser.prototype, {
  24465. getFrequencyData: function () {
  24466. this.analyser.getByteFrequencyData( this.data );
  24467. return this.data;
  24468. },
  24469. getAverageFrequency: function () {
  24470. var value = 0, data = this.getFrequencyData();
  24471. for ( var i = 0; i < data.length; i ++ ) {
  24472. value += data[ i ];
  24473. }
  24474. return value / data.length;
  24475. }
  24476. } );
  24477. /**
  24478. *
  24479. * Buffered scene graph property that allows weighted accumulation.
  24480. *
  24481. *
  24482. * @author Ben Houston / http://clara.io/
  24483. * @author David Sarno / http://lighthaus.us/
  24484. * @author tschw
  24485. */
  24486. function PropertyMixer( binding, typeName, valueSize ) {
  24487. this.binding = binding;
  24488. this.valueSize = valueSize;
  24489. var bufferType = Float64Array,
  24490. mixFunction;
  24491. switch ( typeName ) {
  24492. case 'quaternion':
  24493. mixFunction = this._slerp;
  24494. break;
  24495. case 'string':
  24496. case 'bool':
  24497. bufferType = Array;
  24498. mixFunction = this._select;
  24499. break;
  24500. default:
  24501. mixFunction = this._lerp;
  24502. }
  24503. this.buffer = new bufferType( valueSize * 4 );
  24504. // layout: [ incoming | accu0 | accu1 | orig ]
  24505. //
  24506. // interpolators can use .buffer as their .result
  24507. // the data then goes to 'incoming'
  24508. //
  24509. // 'accu0' and 'accu1' are used frame-interleaved for
  24510. // the cumulative result and are compared to detect
  24511. // changes
  24512. //
  24513. // 'orig' stores the original state of the property
  24514. this._mixBufferRegion = mixFunction;
  24515. this.cumulativeWeight = 0;
  24516. this.useCount = 0;
  24517. this.referenceCount = 0;
  24518. }
  24519. Object.assign( PropertyMixer.prototype, {
  24520. // accumulate data in the 'incoming' region into 'accu<i>'
  24521. accumulate: function ( accuIndex, weight ) {
  24522. // note: happily accumulating nothing when weight = 0, the caller knows
  24523. // the weight and shouldn't have made the call in the first place
  24524. var buffer = this.buffer,
  24525. stride = this.valueSize,
  24526. offset = accuIndex * stride + stride,
  24527. currentWeight = this.cumulativeWeight;
  24528. if ( currentWeight === 0 ) {
  24529. // accuN := incoming * weight
  24530. for ( var i = 0; i !== stride; ++ i ) {
  24531. buffer[ offset + i ] = buffer[ i ];
  24532. }
  24533. currentWeight = weight;
  24534. } else {
  24535. // accuN := accuN + incoming * weight
  24536. currentWeight += weight;
  24537. var mix = weight / currentWeight;
  24538. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24539. }
  24540. this.cumulativeWeight = currentWeight;
  24541. },
  24542. // apply the state of 'accu<i>' to the binding when accus differ
  24543. apply: function ( accuIndex ) {
  24544. var stride = this.valueSize,
  24545. buffer = this.buffer,
  24546. offset = accuIndex * stride + stride,
  24547. weight = this.cumulativeWeight,
  24548. binding = this.binding;
  24549. this.cumulativeWeight = 0;
  24550. if ( weight < 1 ) {
  24551. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24552. var originalValueOffset = stride * 3;
  24553. this._mixBufferRegion(
  24554. buffer, offset, originalValueOffset, 1 - weight, stride );
  24555. }
  24556. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24557. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24558. // value has changed -> update scene graph
  24559. binding.setValue( buffer, offset );
  24560. break;
  24561. }
  24562. }
  24563. },
  24564. // remember the state of the bound property and copy it to both accus
  24565. saveOriginalState: function () {
  24566. var binding = this.binding;
  24567. var buffer = this.buffer,
  24568. stride = this.valueSize,
  24569. originalValueOffset = stride * 3;
  24570. binding.getValue( buffer, originalValueOffset );
  24571. // accu[0..1] := orig -- initially detect changes against the original
  24572. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24573. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24574. }
  24575. this.cumulativeWeight = 0;
  24576. },
  24577. // apply the state previously taken via 'saveOriginalState' to the binding
  24578. restoreOriginalState: function () {
  24579. var originalValueOffset = this.valueSize * 3;
  24580. this.binding.setValue( this.buffer, originalValueOffset );
  24581. },
  24582. // mix functions
  24583. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24584. if ( t >= 0.5 ) {
  24585. for ( var i = 0; i !== stride; ++ i ) {
  24586. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24587. }
  24588. }
  24589. },
  24590. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24591. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24592. },
  24593. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24594. var s = 1 - t;
  24595. for ( var i = 0; i !== stride; ++ i ) {
  24596. var j = dstOffset + i;
  24597. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24598. }
  24599. }
  24600. } );
  24601. /**
  24602. *
  24603. * A reference to a real property in the scene graph.
  24604. *
  24605. *
  24606. * @author Ben Houston / http://clara.io/
  24607. * @author David Sarno / http://lighthaus.us/
  24608. * @author tschw
  24609. */
  24610. // Characters [].:/ are reserved for track binding syntax.
  24611. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24612. function Composite( targetGroup, path, optionalParsedPath ) {
  24613. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24614. this._targetGroup = targetGroup;
  24615. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24616. }
  24617. Object.assign( Composite.prototype, {
  24618. getValue: function ( array, offset ) {
  24619. this.bind(); // bind all binding
  24620. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24621. binding = this._bindings[ firstValidIndex ];
  24622. // and only call .getValue on the first
  24623. if ( binding !== undefined ) binding.getValue( array, offset );
  24624. },
  24625. setValue: function ( array, offset ) {
  24626. var bindings = this._bindings;
  24627. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24628. bindings[ i ].setValue( array, offset );
  24629. }
  24630. },
  24631. bind: function () {
  24632. var bindings = this._bindings;
  24633. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24634. bindings[ i ].bind();
  24635. }
  24636. },
  24637. unbind: function () {
  24638. var bindings = this._bindings;
  24639. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24640. bindings[ i ].unbind();
  24641. }
  24642. }
  24643. } );
  24644. function PropertyBinding( rootNode, path, parsedPath ) {
  24645. this.path = path;
  24646. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24647. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24648. this.rootNode = rootNode;
  24649. }
  24650. Object.assign( PropertyBinding, {
  24651. Composite: Composite,
  24652. create: function ( root, path, parsedPath ) {
  24653. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24654. return new PropertyBinding( root, path, parsedPath );
  24655. } else {
  24656. return new PropertyBinding.Composite( root, path, parsedPath );
  24657. }
  24658. },
  24659. /**
  24660. * Replaces spaces with underscores and removes unsupported characters from
  24661. * node names, to ensure compatibility with parseTrackName().
  24662. *
  24663. * @param {string} name Node name to be sanitized.
  24664. * @return {string}
  24665. */
  24666. sanitizeNodeName: ( function () {
  24667. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  24668. return function sanitizeNodeName( name ) {
  24669. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  24670. };
  24671. }() ),
  24672. parseTrackName: function () {
  24673. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24674. // only latin characters, and the unicode \p{L} is not yet supported. So
  24675. // instead, we exclude reserved characters and match everything else.
  24676. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  24677. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24678. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24679. // be matched to parse the rest of the track name.
  24680. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  24681. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24682. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  24683. // Object on target node, and accessor. May not contain reserved
  24684. // characters. Accessor may contain any character except closing bracket.
  24685. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  24686. // Property and accessor. May not contain reserved characters. Accessor may
  24687. // contain any non-bracket characters.
  24688. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  24689. var trackRe = new RegExp( ''
  24690. + '^'
  24691. + directoryRe
  24692. + nodeRe
  24693. + objectRe
  24694. + propertyRe
  24695. + '$'
  24696. );
  24697. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24698. return function parseTrackName( trackName ) {
  24699. var matches = trackRe.exec( trackName );
  24700. if ( ! matches ) {
  24701. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24702. }
  24703. var results = {
  24704. // directoryName: matches[ 1 ], // (tschw) currently unused
  24705. nodeName: matches[ 2 ],
  24706. objectName: matches[ 3 ],
  24707. objectIndex: matches[ 4 ],
  24708. propertyName: matches[ 5 ], // required
  24709. propertyIndex: matches[ 6 ]
  24710. };
  24711. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24712. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24713. var objectName = results.nodeName.substring( lastDot + 1 );
  24714. // Object names must be checked against a whitelist. Otherwise, there
  24715. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24716. // 'bar' could be the objectName, or part of a nodeName (which can
  24717. // include '.' characters).
  24718. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24719. results.nodeName = results.nodeName.substring( 0, lastDot );
  24720. results.objectName = objectName;
  24721. }
  24722. }
  24723. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24724. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24725. }
  24726. return results;
  24727. };
  24728. }(),
  24729. findNode: function ( root, nodeName ) {
  24730. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24731. return root;
  24732. }
  24733. // search into skeleton bones.
  24734. if ( root.skeleton ) {
  24735. var bone = root.skeleton.getBoneByName( nodeName );
  24736. if ( bone !== undefined ) {
  24737. return bone;
  24738. }
  24739. }
  24740. // search into node subtree.
  24741. if ( root.children ) {
  24742. var searchNodeSubtree = function ( children ) {
  24743. for ( var i = 0; i < children.length; i ++ ) {
  24744. var childNode = children[ i ];
  24745. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24746. return childNode;
  24747. }
  24748. var result = searchNodeSubtree( childNode.children );
  24749. if ( result ) return result;
  24750. }
  24751. return null;
  24752. };
  24753. var subTreeNode = searchNodeSubtree( root.children );
  24754. if ( subTreeNode ) {
  24755. return subTreeNode;
  24756. }
  24757. }
  24758. return null;
  24759. }
  24760. } );
  24761. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24762. // these are used to "bind" a nonexistent property
  24763. _getValue_unavailable: function () {},
  24764. _setValue_unavailable: function () {},
  24765. BindingType: {
  24766. Direct: 0,
  24767. EntireArray: 1,
  24768. ArrayElement: 2,
  24769. HasFromToArray: 3
  24770. },
  24771. Versioning: {
  24772. None: 0,
  24773. NeedsUpdate: 1,
  24774. MatrixWorldNeedsUpdate: 2
  24775. },
  24776. GetterByBindingType: [
  24777. function getValue_direct( buffer, offset ) {
  24778. buffer[ offset ] = this.node[ this.propertyName ];
  24779. },
  24780. function getValue_array( buffer, offset ) {
  24781. var source = this.resolvedProperty;
  24782. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  24783. buffer[ offset ++ ] = source[ i ];
  24784. }
  24785. },
  24786. function getValue_arrayElement( buffer, offset ) {
  24787. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  24788. },
  24789. function getValue_toArray( buffer, offset ) {
  24790. this.resolvedProperty.toArray( buffer, offset );
  24791. }
  24792. ],
  24793. SetterByBindingTypeAndVersioning: [
  24794. [
  24795. // Direct
  24796. function setValue_direct( buffer, offset ) {
  24797. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24798. },
  24799. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  24800. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24801. this.targetObject.needsUpdate = true;
  24802. },
  24803. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24804. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24805. this.targetObject.matrixWorldNeedsUpdate = true;
  24806. }
  24807. ], [
  24808. // EntireArray
  24809. function setValue_array( buffer, offset ) {
  24810. var dest = this.resolvedProperty;
  24811. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24812. dest[ i ] = buffer[ offset ++ ];
  24813. }
  24814. },
  24815. function setValue_array_setNeedsUpdate( buffer, offset ) {
  24816. var dest = this.resolvedProperty;
  24817. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24818. dest[ i ] = buffer[ offset ++ ];
  24819. }
  24820. this.targetObject.needsUpdate = true;
  24821. },
  24822. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24823. var dest = this.resolvedProperty;
  24824. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24825. dest[ i ] = buffer[ offset ++ ];
  24826. }
  24827. this.targetObject.matrixWorldNeedsUpdate = true;
  24828. }
  24829. ], [
  24830. // ArrayElement
  24831. function setValue_arrayElement( buffer, offset ) {
  24832. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24833. },
  24834. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  24835. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24836. this.targetObject.needsUpdate = true;
  24837. },
  24838. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24839. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24840. this.targetObject.matrixWorldNeedsUpdate = true;
  24841. }
  24842. ], [
  24843. // HasToFromArray
  24844. function setValue_fromArray( buffer, offset ) {
  24845. this.resolvedProperty.fromArray( buffer, offset );
  24846. },
  24847. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  24848. this.resolvedProperty.fromArray( buffer, offset );
  24849. this.targetObject.needsUpdate = true;
  24850. },
  24851. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24852. this.resolvedProperty.fromArray( buffer, offset );
  24853. this.targetObject.matrixWorldNeedsUpdate = true;
  24854. }
  24855. ]
  24856. ],
  24857. getValue: function getValue_unbound( targetArray, offset ) {
  24858. this.bind();
  24859. this.getValue( targetArray, offset );
  24860. // Note: This class uses a State pattern on a per-method basis:
  24861. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  24862. // prototype version of these methods with one that represents
  24863. // the bound state. When the property is not found, the methods
  24864. // become no-ops.
  24865. },
  24866. setValue: function getValue_unbound( sourceArray, offset ) {
  24867. this.bind();
  24868. this.setValue( sourceArray, offset );
  24869. },
  24870. // create getter / setter pair for a property in the scene graph
  24871. bind: function () {
  24872. var targetObject = this.node,
  24873. parsedPath = this.parsedPath,
  24874. objectName = parsedPath.objectName,
  24875. propertyName = parsedPath.propertyName,
  24876. propertyIndex = parsedPath.propertyIndex;
  24877. if ( ! targetObject ) {
  24878. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  24879. this.node = targetObject;
  24880. }
  24881. // set fail state so we can just 'return' on error
  24882. this.getValue = this._getValue_unavailable;
  24883. this.setValue = this._setValue_unavailable;
  24884. // ensure there is a value node
  24885. if ( ! targetObject ) {
  24886. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  24887. return;
  24888. }
  24889. if ( objectName ) {
  24890. var objectIndex = parsedPath.objectIndex;
  24891. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  24892. switch ( objectName ) {
  24893. case 'materials':
  24894. if ( ! targetObject.material ) {
  24895. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  24896. return;
  24897. }
  24898. if ( ! targetObject.material.materials ) {
  24899. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  24900. return;
  24901. }
  24902. targetObject = targetObject.material.materials;
  24903. break;
  24904. case 'bones':
  24905. if ( ! targetObject.skeleton ) {
  24906. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  24907. return;
  24908. }
  24909. // potential future optimization: skip this if propertyIndex is already an integer
  24910. // and convert the integer string to a true integer.
  24911. targetObject = targetObject.skeleton.bones;
  24912. // support resolving morphTarget names into indices.
  24913. for ( var i = 0; i < targetObject.length; i ++ ) {
  24914. if ( targetObject[ i ].name === objectIndex ) {
  24915. objectIndex = i;
  24916. break;
  24917. }
  24918. }
  24919. break;
  24920. default:
  24921. if ( targetObject[ objectName ] === undefined ) {
  24922. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  24923. return;
  24924. }
  24925. targetObject = targetObject[ objectName ];
  24926. }
  24927. if ( objectIndex !== undefined ) {
  24928. if ( targetObject[ objectIndex ] === undefined ) {
  24929. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  24930. return;
  24931. }
  24932. targetObject = targetObject[ objectIndex ];
  24933. }
  24934. }
  24935. // resolve property
  24936. var nodeProperty = targetObject[ propertyName ];
  24937. if ( nodeProperty === undefined ) {
  24938. var nodeName = parsedPath.nodeName;
  24939. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  24940. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  24941. return;
  24942. }
  24943. // determine versioning scheme
  24944. var versioning = this.Versioning.None;
  24945. this.targetObject = targetObject;
  24946. if ( targetObject.needsUpdate !== undefined ) { // material
  24947. versioning = this.Versioning.NeedsUpdate;
  24948. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  24949. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  24950. }
  24951. // determine how the property gets bound
  24952. var bindingType = this.BindingType.Direct;
  24953. if ( propertyIndex !== undefined ) {
  24954. // access a sub element of the property array (only primitives are supported right now)
  24955. if ( propertyName === "morphTargetInfluences" ) {
  24956. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  24957. // support resolving morphTarget names into indices.
  24958. if ( ! targetObject.geometry ) {
  24959. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  24960. return;
  24961. }
  24962. if ( targetObject.geometry.isBufferGeometry ) {
  24963. if ( ! targetObject.geometry.morphAttributes ) {
  24964. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  24965. return;
  24966. }
  24967. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  24968. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  24969. propertyIndex = i;
  24970. break;
  24971. }
  24972. }
  24973. } else {
  24974. if ( ! targetObject.geometry.morphTargets ) {
  24975. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  24976. return;
  24977. }
  24978. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  24979. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  24980. propertyIndex = i;
  24981. break;
  24982. }
  24983. }
  24984. }
  24985. }
  24986. bindingType = this.BindingType.ArrayElement;
  24987. this.resolvedProperty = nodeProperty;
  24988. this.propertyIndex = propertyIndex;
  24989. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  24990. // must use copy for Object3D.Euler/Quaternion
  24991. bindingType = this.BindingType.HasFromToArray;
  24992. this.resolvedProperty = nodeProperty;
  24993. } else if ( Array.isArray( nodeProperty ) ) {
  24994. bindingType = this.BindingType.EntireArray;
  24995. this.resolvedProperty = nodeProperty;
  24996. } else {
  24997. this.propertyName = propertyName;
  24998. }
  24999. // select getter / setter
  25000. this.getValue = this.GetterByBindingType[ bindingType ];
  25001. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25002. },
  25003. unbind: function () {
  25004. this.node = null;
  25005. // back to the prototype version of getValue / setValue
  25006. // note: avoiding to mutate the shape of 'this' via 'delete'
  25007. this.getValue = this._getValue_unbound;
  25008. this.setValue = this._setValue_unbound;
  25009. }
  25010. } );
  25011. //!\ DECLARE ALIAS AFTER assign prototype !
  25012. Object.assign( PropertyBinding.prototype, {
  25013. // initial state of these methods that calls 'bind'
  25014. _getValue_unbound: PropertyBinding.prototype.getValue,
  25015. _setValue_unbound: PropertyBinding.prototype.setValue,
  25016. } );
  25017. /**
  25018. *
  25019. * A group of objects that receives a shared animation state.
  25020. *
  25021. * Usage:
  25022. *
  25023. * - Add objects you would otherwise pass as 'root' to the
  25024. * constructor or the .clipAction method of AnimationMixer.
  25025. *
  25026. * - Instead pass this object as 'root'.
  25027. *
  25028. * - You can also add and remove objects later when the mixer
  25029. * is running.
  25030. *
  25031. * Note:
  25032. *
  25033. * Objects of this class appear as one object to the mixer,
  25034. * so cache control of the individual objects must be done
  25035. * on the group.
  25036. *
  25037. * Limitation:
  25038. *
  25039. * - The animated properties must be compatible among the
  25040. * all objects in the group.
  25041. *
  25042. * - A single property can either be controlled through a
  25043. * target group or directly, but not both.
  25044. *
  25045. * @author tschw
  25046. */
  25047. function AnimationObjectGroup() {
  25048. this.uuid = _Math.generateUUID();
  25049. // cached objects followed by the active ones
  25050. this._objects = Array.prototype.slice.call( arguments );
  25051. this.nCachedObjects_ = 0; // threshold
  25052. // note: read by PropertyBinding.Composite
  25053. var indices = {};
  25054. this._indicesByUUID = indices; // for bookkeeping
  25055. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25056. indices[ arguments[ i ].uuid ] = i;
  25057. }
  25058. this._paths = []; // inside: string
  25059. this._parsedPaths = []; // inside: { we don't care, here }
  25060. this._bindings = []; // inside: Array< PropertyBinding >
  25061. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25062. var scope = this;
  25063. this.stats = {
  25064. objects: {
  25065. get total() {
  25066. return scope._objects.length;
  25067. },
  25068. get inUse() {
  25069. return this.total - scope.nCachedObjects_;
  25070. }
  25071. },
  25072. get bindingsPerObject() {
  25073. return scope._bindings.length;
  25074. }
  25075. };
  25076. }
  25077. Object.assign( AnimationObjectGroup.prototype, {
  25078. isAnimationObjectGroup: true,
  25079. add: function () {
  25080. var objects = this._objects,
  25081. nObjects = objects.length,
  25082. nCachedObjects = this.nCachedObjects_,
  25083. indicesByUUID = this._indicesByUUID,
  25084. paths = this._paths,
  25085. parsedPaths = this._parsedPaths,
  25086. bindings = this._bindings,
  25087. nBindings = bindings.length,
  25088. knownObject = undefined;
  25089. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25090. var object = arguments[ i ],
  25091. uuid = object.uuid,
  25092. index = indicesByUUID[ uuid ];
  25093. if ( index === undefined ) {
  25094. // unknown object -> add it to the ACTIVE region
  25095. index = nObjects ++;
  25096. indicesByUUID[ uuid ] = index;
  25097. objects.push( object );
  25098. // accounting is done, now do the same for all bindings
  25099. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25100. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25101. }
  25102. } else if ( index < nCachedObjects ) {
  25103. knownObject = objects[ index ];
  25104. // move existing object to the ACTIVE region
  25105. var firstActiveIndex = -- nCachedObjects,
  25106. lastCachedObject = objects[ firstActiveIndex ];
  25107. indicesByUUID[ lastCachedObject.uuid ] = index;
  25108. objects[ index ] = lastCachedObject;
  25109. indicesByUUID[ uuid ] = firstActiveIndex;
  25110. objects[ firstActiveIndex ] = object;
  25111. // accounting is done, now do the same for all bindings
  25112. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25113. var bindingsForPath = bindings[ j ],
  25114. lastCached = bindingsForPath[ firstActiveIndex ],
  25115. binding = bindingsForPath[ index ];
  25116. bindingsForPath[ index ] = lastCached;
  25117. if ( binding === undefined ) {
  25118. // since we do not bother to create new bindings
  25119. // for objects that are cached, the binding may
  25120. // or may not exist
  25121. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25122. }
  25123. bindingsForPath[ firstActiveIndex ] = binding;
  25124. }
  25125. } else if ( objects[ index ] !== knownObject ) {
  25126. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25127. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25128. } // else the object is already where we want it to be
  25129. } // for arguments
  25130. this.nCachedObjects_ = nCachedObjects;
  25131. },
  25132. remove: function () {
  25133. var objects = this._objects,
  25134. nCachedObjects = this.nCachedObjects_,
  25135. indicesByUUID = this._indicesByUUID,
  25136. bindings = this._bindings,
  25137. nBindings = bindings.length;
  25138. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25139. var object = arguments[ i ],
  25140. uuid = object.uuid,
  25141. index = indicesByUUID[ uuid ];
  25142. if ( index !== undefined && index >= nCachedObjects ) {
  25143. // move existing object into the CACHED region
  25144. var lastCachedIndex = nCachedObjects ++,
  25145. firstActiveObject = objects[ lastCachedIndex ];
  25146. indicesByUUID[ firstActiveObject.uuid ] = index;
  25147. objects[ index ] = firstActiveObject;
  25148. indicesByUUID[ uuid ] = lastCachedIndex;
  25149. objects[ lastCachedIndex ] = object;
  25150. // accounting is done, now do the same for all bindings
  25151. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25152. var bindingsForPath = bindings[ j ],
  25153. firstActive = bindingsForPath[ lastCachedIndex ],
  25154. binding = bindingsForPath[ index ];
  25155. bindingsForPath[ index ] = firstActive;
  25156. bindingsForPath[ lastCachedIndex ] = binding;
  25157. }
  25158. }
  25159. } // for arguments
  25160. this.nCachedObjects_ = nCachedObjects;
  25161. },
  25162. // remove & forget
  25163. uncache: function () {
  25164. var objects = this._objects,
  25165. nObjects = objects.length,
  25166. nCachedObjects = this.nCachedObjects_,
  25167. indicesByUUID = this._indicesByUUID,
  25168. bindings = this._bindings,
  25169. nBindings = bindings.length;
  25170. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25171. var object = arguments[ i ],
  25172. uuid = object.uuid,
  25173. index = indicesByUUID[ uuid ];
  25174. if ( index !== undefined ) {
  25175. delete indicesByUUID[ uuid ];
  25176. if ( index < nCachedObjects ) {
  25177. // object is cached, shrink the CACHED region
  25178. var firstActiveIndex = -- nCachedObjects,
  25179. lastCachedObject = objects[ firstActiveIndex ],
  25180. lastIndex = -- nObjects,
  25181. lastObject = objects[ lastIndex ];
  25182. // last cached object takes this object's place
  25183. indicesByUUID[ lastCachedObject.uuid ] = index;
  25184. objects[ index ] = lastCachedObject;
  25185. // last object goes to the activated slot and pop
  25186. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25187. objects[ firstActiveIndex ] = lastObject;
  25188. objects.pop();
  25189. // accounting is done, now do the same for all bindings
  25190. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25191. var bindingsForPath = bindings[ j ],
  25192. lastCached = bindingsForPath[ firstActiveIndex ],
  25193. last = bindingsForPath[ lastIndex ];
  25194. bindingsForPath[ index ] = lastCached;
  25195. bindingsForPath[ firstActiveIndex ] = last;
  25196. bindingsForPath.pop();
  25197. }
  25198. } else {
  25199. // object is active, just swap with the last and pop
  25200. var lastIndex = -- nObjects,
  25201. lastObject = objects[ lastIndex ];
  25202. indicesByUUID[ lastObject.uuid ] = index;
  25203. objects[ index ] = lastObject;
  25204. objects.pop();
  25205. // accounting is done, now do the same for all bindings
  25206. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25207. var bindingsForPath = bindings[ j ];
  25208. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25209. bindingsForPath.pop();
  25210. }
  25211. } // cached or active
  25212. } // if object is known
  25213. } // for arguments
  25214. this.nCachedObjects_ = nCachedObjects;
  25215. },
  25216. // Internal interface used by befriended PropertyBinding.Composite:
  25217. subscribe_: function ( path, parsedPath ) {
  25218. // returns an array of bindings for the given path that is changed
  25219. // according to the contained objects in the group
  25220. var indicesByPath = this._bindingsIndicesByPath,
  25221. index = indicesByPath[ path ],
  25222. bindings = this._bindings;
  25223. if ( index !== undefined ) return bindings[ index ];
  25224. var paths = this._paths,
  25225. parsedPaths = this._parsedPaths,
  25226. objects = this._objects,
  25227. nObjects = objects.length,
  25228. nCachedObjects = this.nCachedObjects_,
  25229. bindingsForPath = new Array( nObjects );
  25230. index = bindings.length;
  25231. indicesByPath[ path ] = index;
  25232. paths.push( path );
  25233. parsedPaths.push( parsedPath );
  25234. bindings.push( bindingsForPath );
  25235. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25236. var object = objects[ i ];
  25237. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25238. }
  25239. return bindingsForPath;
  25240. },
  25241. unsubscribe_: function ( path ) {
  25242. // tells the group to forget about a property path and no longer
  25243. // update the array previously obtained with 'subscribe_'
  25244. var indicesByPath = this._bindingsIndicesByPath,
  25245. index = indicesByPath[ path ];
  25246. if ( index !== undefined ) {
  25247. var paths = this._paths,
  25248. parsedPaths = this._parsedPaths,
  25249. bindings = this._bindings,
  25250. lastBindingsIndex = bindings.length - 1,
  25251. lastBindings = bindings[ lastBindingsIndex ],
  25252. lastBindingsPath = path[ lastBindingsIndex ];
  25253. indicesByPath[ lastBindingsPath ] = index;
  25254. bindings[ index ] = lastBindings;
  25255. bindings.pop();
  25256. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25257. parsedPaths.pop();
  25258. paths[ index ] = paths[ lastBindingsIndex ];
  25259. paths.pop();
  25260. }
  25261. }
  25262. } );
  25263. /**
  25264. *
  25265. * Action provided by AnimationMixer for scheduling clip playback on specific
  25266. * objects.
  25267. *
  25268. * @author Ben Houston / http://clara.io/
  25269. * @author David Sarno / http://lighthaus.us/
  25270. * @author tschw
  25271. *
  25272. */
  25273. function AnimationAction( mixer, clip, localRoot ) {
  25274. this._mixer = mixer;
  25275. this._clip = clip;
  25276. this._localRoot = localRoot || null;
  25277. var tracks = clip.tracks,
  25278. nTracks = tracks.length,
  25279. interpolants = new Array( nTracks );
  25280. var interpolantSettings = {
  25281. endingStart: ZeroCurvatureEnding,
  25282. endingEnd: ZeroCurvatureEnding
  25283. };
  25284. for ( var i = 0; i !== nTracks; ++ i ) {
  25285. var interpolant = tracks[ i ].createInterpolant( null );
  25286. interpolants[ i ] = interpolant;
  25287. interpolant.settings = interpolantSettings;
  25288. }
  25289. this._interpolantSettings = interpolantSettings;
  25290. this._interpolants = interpolants; // bound by the mixer
  25291. // inside: PropertyMixer (managed by the mixer)
  25292. this._propertyBindings = new Array( nTracks );
  25293. this._cacheIndex = null; // for the memory manager
  25294. this._byClipCacheIndex = null; // for the memory manager
  25295. this._timeScaleInterpolant = null;
  25296. this._weightInterpolant = null;
  25297. this.loop = LoopRepeat;
  25298. this._loopCount = - 1;
  25299. // global mixer time when the action is to be started
  25300. // it's set back to 'null' upon start of the action
  25301. this._startTime = null;
  25302. // scaled local time of the action
  25303. // gets clamped or wrapped to 0..clip.duration according to loop
  25304. this.time = 0;
  25305. this.timeScale = 1;
  25306. this._effectiveTimeScale = 1;
  25307. this.weight = 1;
  25308. this._effectiveWeight = 1;
  25309. this.repetitions = Infinity; // no. of repetitions when looping
  25310. this.paused = false; // true -> zero effective time scale
  25311. this.enabled = true; // false -> zero effective weight
  25312. this.clampWhenFinished = false;// keep feeding the last frame?
  25313. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25314. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25315. }
  25316. Object.assign( AnimationAction.prototype, {
  25317. // State & Scheduling
  25318. play: function () {
  25319. this._mixer._activateAction( this );
  25320. return this;
  25321. },
  25322. stop: function () {
  25323. this._mixer._deactivateAction( this );
  25324. return this.reset();
  25325. },
  25326. reset: function () {
  25327. this.paused = false;
  25328. this.enabled = true;
  25329. this.time = 0; // restart clip
  25330. this._loopCount = - 1;// forget previous loops
  25331. this._startTime = null;// forget scheduling
  25332. return this.stopFading().stopWarping();
  25333. },
  25334. isRunning: function () {
  25335. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25336. this._startTime === null && this._mixer._isActiveAction( this );
  25337. },
  25338. // return true when play has been called
  25339. isScheduled: function () {
  25340. return this._mixer._isActiveAction( this );
  25341. },
  25342. startAt: function ( time ) {
  25343. this._startTime = time;
  25344. return this;
  25345. },
  25346. setLoop: function ( mode, repetitions ) {
  25347. this.loop = mode;
  25348. this.repetitions = repetitions;
  25349. return this;
  25350. },
  25351. // Weight
  25352. // set the weight stopping any scheduled fading
  25353. // although .enabled = false yields an effective weight of zero, this
  25354. // method does *not* change .enabled, because it would be confusing
  25355. setEffectiveWeight: function ( weight ) {
  25356. this.weight = weight;
  25357. // note: same logic as when updated at runtime
  25358. this._effectiveWeight = this.enabled ? weight : 0;
  25359. return this.stopFading();
  25360. },
  25361. // return the weight considering fading and .enabled
  25362. getEffectiveWeight: function () {
  25363. return this._effectiveWeight;
  25364. },
  25365. fadeIn: function ( duration ) {
  25366. return this._scheduleFading( duration, 0, 1 );
  25367. },
  25368. fadeOut: function ( duration ) {
  25369. return this._scheduleFading( duration, 1, 0 );
  25370. },
  25371. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25372. fadeOutAction.fadeOut( duration );
  25373. this.fadeIn( duration );
  25374. if ( warp ) {
  25375. var fadeInDuration = this._clip.duration,
  25376. fadeOutDuration = fadeOutAction._clip.duration,
  25377. startEndRatio = fadeOutDuration / fadeInDuration,
  25378. endStartRatio = fadeInDuration / fadeOutDuration;
  25379. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25380. this.warp( endStartRatio, 1.0, duration );
  25381. }
  25382. return this;
  25383. },
  25384. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25385. return fadeInAction.crossFadeFrom( this, duration, warp );
  25386. },
  25387. stopFading: function () {
  25388. var weightInterpolant = this._weightInterpolant;
  25389. if ( weightInterpolant !== null ) {
  25390. this._weightInterpolant = null;
  25391. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25392. }
  25393. return this;
  25394. },
  25395. // Time Scale Control
  25396. // set the time scale stopping any scheduled warping
  25397. // although .paused = true yields an effective time scale of zero, this
  25398. // method does *not* change .paused, because it would be confusing
  25399. setEffectiveTimeScale: function ( timeScale ) {
  25400. this.timeScale = timeScale;
  25401. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25402. return this.stopWarping();
  25403. },
  25404. // return the time scale considering warping and .paused
  25405. getEffectiveTimeScale: function () {
  25406. return this._effectiveTimeScale;
  25407. },
  25408. setDuration: function ( duration ) {
  25409. this.timeScale = this._clip.duration / duration;
  25410. return this.stopWarping();
  25411. },
  25412. syncWith: function ( action ) {
  25413. this.time = action.time;
  25414. this.timeScale = action.timeScale;
  25415. return this.stopWarping();
  25416. },
  25417. halt: function ( duration ) {
  25418. return this.warp( this._effectiveTimeScale, 0, duration );
  25419. },
  25420. warp: function ( startTimeScale, endTimeScale, duration ) {
  25421. var mixer = this._mixer, now = mixer.time,
  25422. interpolant = this._timeScaleInterpolant,
  25423. timeScale = this.timeScale;
  25424. if ( interpolant === null ) {
  25425. interpolant = mixer._lendControlInterpolant();
  25426. this._timeScaleInterpolant = interpolant;
  25427. }
  25428. var times = interpolant.parameterPositions,
  25429. values = interpolant.sampleValues;
  25430. times[ 0 ] = now;
  25431. times[ 1 ] = now + duration;
  25432. values[ 0 ] = startTimeScale / timeScale;
  25433. values[ 1 ] = endTimeScale / timeScale;
  25434. return this;
  25435. },
  25436. stopWarping: function () {
  25437. var timeScaleInterpolant = this._timeScaleInterpolant;
  25438. if ( timeScaleInterpolant !== null ) {
  25439. this._timeScaleInterpolant = null;
  25440. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25441. }
  25442. return this;
  25443. },
  25444. // Object Accessors
  25445. getMixer: function () {
  25446. return this._mixer;
  25447. },
  25448. getClip: function () {
  25449. return this._clip;
  25450. },
  25451. getRoot: function () {
  25452. return this._localRoot || this._mixer._root;
  25453. },
  25454. // Interna
  25455. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25456. // called by the mixer
  25457. if ( ! this.enabled ) {
  25458. // call ._updateWeight() to update ._effectiveWeight
  25459. this._updateWeight( time );
  25460. return;
  25461. }
  25462. var startTime = this._startTime;
  25463. if ( startTime !== null ) {
  25464. // check for scheduled start of action
  25465. var timeRunning = ( time - startTime ) * timeDirection;
  25466. if ( timeRunning < 0 || timeDirection === 0 ) {
  25467. return; // yet to come / don't decide when delta = 0
  25468. }
  25469. // start
  25470. this._startTime = null; // unschedule
  25471. deltaTime = timeDirection * timeRunning;
  25472. }
  25473. // apply time scale and advance time
  25474. deltaTime *= this._updateTimeScale( time );
  25475. var clipTime = this._updateTime( deltaTime );
  25476. // note: _updateTime may disable the action resulting in
  25477. // an effective weight of 0
  25478. var weight = this._updateWeight( time );
  25479. if ( weight > 0 ) {
  25480. var interpolants = this._interpolants;
  25481. var propertyMixers = this._propertyBindings;
  25482. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25483. interpolants[ j ].evaluate( clipTime );
  25484. propertyMixers[ j ].accumulate( accuIndex, weight );
  25485. }
  25486. }
  25487. },
  25488. _updateWeight: function ( time ) {
  25489. var weight = 0;
  25490. if ( this.enabled ) {
  25491. weight = this.weight;
  25492. var interpolant = this._weightInterpolant;
  25493. if ( interpolant !== null ) {
  25494. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25495. weight *= interpolantValue;
  25496. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25497. this.stopFading();
  25498. if ( interpolantValue === 0 ) {
  25499. // faded out, disable
  25500. this.enabled = false;
  25501. }
  25502. }
  25503. }
  25504. }
  25505. this._effectiveWeight = weight;
  25506. return weight;
  25507. },
  25508. _updateTimeScale: function ( time ) {
  25509. var timeScale = 0;
  25510. if ( ! this.paused ) {
  25511. timeScale = this.timeScale;
  25512. var interpolant = this._timeScaleInterpolant;
  25513. if ( interpolant !== null ) {
  25514. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25515. timeScale *= interpolantValue;
  25516. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25517. this.stopWarping();
  25518. if ( timeScale === 0 ) {
  25519. // motion has halted, pause
  25520. this.paused = true;
  25521. } else {
  25522. // warp done - apply final time scale
  25523. this.timeScale = timeScale;
  25524. }
  25525. }
  25526. }
  25527. }
  25528. this._effectiveTimeScale = timeScale;
  25529. return timeScale;
  25530. },
  25531. _updateTime: function ( deltaTime ) {
  25532. var time = this.time + deltaTime;
  25533. var duration = this._clip.duration;
  25534. var loop = this.loop;
  25535. var loopCount = this._loopCount;
  25536. var pingPong = ( loop === LoopPingPong );
  25537. if ( deltaTime === 0 ) {
  25538. if ( loopCount === - 1 ) return time;
  25539. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25540. }
  25541. if ( loop === LoopOnce ) {
  25542. if ( loopCount === - 1 ) {
  25543. // just started
  25544. this._loopCount = 0;
  25545. this._setEndings( true, true, false );
  25546. }
  25547. handle_stop: {
  25548. if ( time >= duration ) {
  25549. time = duration;
  25550. } else if ( time < 0 ) {
  25551. time = 0;
  25552. } else break handle_stop;
  25553. if ( this.clampWhenFinished ) this.paused = true;
  25554. else this.enabled = false;
  25555. this._mixer.dispatchEvent( {
  25556. type: 'finished', action: this,
  25557. direction: deltaTime < 0 ? - 1 : 1
  25558. } );
  25559. }
  25560. } else { // repetitive Repeat or PingPong
  25561. if ( loopCount === - 1 ) {
  25562. // just started
  25563. if ( deltaTime >= 0 ) {
  25564. loopCount = 0;
  25565. this._setEndings( true, this.repetitions === 0, pingPong );
  25566. } else {
  25567. // when looping in reverse direction, the initial
  25568. // transition through zero counts as a repetition,
  25569. // so leave loopCount at -1
  25570. this._setEndings( this.repetitions === 0, true, pingPong );
  25571. }
  25572. }
  25573. if ( time >= duration || time < 0 ) {
  25574. // wrap around
  25575. var loopDelta = Math.floor( time / duration ); // signed
  25576. time -= duration * loopDelta;
  25577. loopCount += Math.abs( loopDelta );
  25578. var pending = this.repetitions - loopCount;
  25579. if ( pending <= 0 ) {
  25580. // have to stop (switch state, clamp time, fire event)
  25581. if ( this.clampWhenFinished ) this.paused = true;
  25582. else this.enabled = false;
  25583. time = deltaTime > 0 ? duration : 0;
  25584. this._mixer.dispatchEvent( {
  25585. type: 'finished', action: this,
  25586. direction: deltaTime > 0 ? 1 : - 1
  25587. } );
  25588. } else {
  25589. // keep running
  25590. if ( pending === 1 ) {
  25591. // entering the last round
  25592. var atStart = deltaTime < 0;
  25593. this._setEndings( atStart, ! atStart, pingPong );
  25594. } else {
  25595. this._setEndings( false, false, pingPong );
  25596. }
  25597. this._loopCount = loopCount;
  25598. this._mixer.dispatchEvent( {
  25599. type: 'loop', action: this, loopDelta: loopDelta
  25600. } );
  25601. }
  25602. }
  25603. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25604. // invert time for the "pong round"
  25605. this.time = time;
  25606. return duration - time;
  25607. }
  25608. }
  25609. this.time = time;
  25610. return time;
  25611. },
  25612. _setEndings: function ( atStart, atEnd, pingPong ) {
  25613. var settings = this._interpolantSettings;
  25614. if ( pingPong ) {
  25615. settings.endingStart = ZeroSlopeEnding;
  25616. settings.endingEnd = ZeroSlopeEnding;
  25617. } else {
  25618. // assuming for LoopOnce atStart == atEnd == true
  25619. if ( atStart ) {
  25620. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25621. } else {
  25622. settings.endingStart = WrapAroundEnding;
  25623. }
  25624. if ( atEnd ) {
  25625. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25626. } else {
  25627. settings.endingEnd = WrapAroundEnding;
  25628. }
  25629. }
  25630. },
  25631. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25632. var mixer = this._mixer, now = mixer.time,
  25633. interpolant = this._weightInterpolant;
  25634. if ( interpolant === null ) {
  25635. interpolant = mixer._lendControlInterpolant();
  25636. this._weightInterpolant = interpolant;
  25637. }
  25638. var times = interpolant.parameterPositions,
  25639. values = interpolant.sampleValues;
  25640. times[ 0 ] = now;
  25641. values[ 0 ] = weightNow;
  25642. times[ 1 ] = now + duration;
  25643. values[ 1 ] = weightThen;
  25644. return this;
  25645. }
  25646. } );
  25647. /**
  25648. *
  25649. * Player for AnimationClips.
  25650. *
  25651. *
  25652. * @author Ben Houston / http://clara.io/
  25653. * @author David Sarno / http://lighthaus.us/
  25654. * @author tschw
  25655. */
  25656. function AnimationMixer( root ) {
  25657. this._root = root;
  25658. this._initMemoryManager();
  25659. this._accuIndex = 0;
  25660. this.time = 0;
  25661. this.timeScale = 1.0;
  25662. }
  25663. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25664. constructor: AnimationMixer,
  25665. _bindAction: function ( action, prototypeAction ) {
  25666. var root = action._localRoot || this._root,
  25667. tracks = action._clip.tracks,
  25668. nTracks = tracks.length,
  25669. bindings = action._propertyBindings,
  25670. interpolants = action._interpolants,
  25671. rootUuid = root.uuid,
  25672. bindingsByRoot = this._bindingsByRootAndName,
  25673. bindingsByName = bindingsByRoot[ rootUuid ];
  25674. if ( bindingsByName === undefined ) {
  25675. bindingsByName = {};
  25676. bindingsByRoot[ rootUuid ] = bindingsByName;
  25677. }
  25678. for ( var i = 0; i !== nTracks; ++ i ) {
  25679. var track = tracks[ i ],
  25680. trackName = track.name,
  25681. binding = bindingsByName[ trackName ];
  25682. if ( binding !== undefined ) {
  25683. bindings[ i ] = binding;
  25684. } else {
  25685. binding = bindings[ i ];
  25686. if ( binding !== undefined ) {
  25687. // existing binding, make sure the cache knows
  25688. if ( binding._cacheIndex === null ) {
  25689. ++ binding.referenceCount;
  25690. this._addInactiveBinding( binding, rootUuid, trackName );
  25691. }
  25692. continue;
  25693. }
  25694. var path = prototypeAction && prototypeAction.
  25695. _propertyBindings[ i ].binding.parsedPath;
  25696. binding = new PropertyMixer(
  25697. PropertyBinding.create( root, trackName, path ),
  25698. track.ValueTypeName, track.getValueSize() );
  25699. ++ binding.referenceCount;
  25700. this._addInactiveBinding( binding, rootUuid, trackName );
  25701. bindings[ i ] = binding;
  25702. }
  25703. interpolants[ i ].resultBuffer = binding.buffer;
  25704. }
  25705. },
  25706. _activateAction: function ( action ) {
  25707. if ( ! this._isActiveAction( action ) ) {
  25708. if ( action._cacheIndex === null ) {
  25709. // this action has been forgotten by the cache, but the user
  25710. // appears to be still using it -> rebind
  25711. var rootUuid = ( action._localRoot || this._root ).uuid,
  25712. clipUuid = action._clip.uuid,
  25713. actionsForClip = this._actionsByClip[ clipUuid ];
  25714. this._bindAction( action,
  25715. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25716. this._addInactiveAction( action, clipUuid, rootUuid );
  25717. }
  25718. var bindings = action._propertyBindings;
  25719. // increment reference counts / sort out state
  25720. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25721. var binding = bindings[ i ];
  25722. if ( binding.useCount ++ === 0 ) {
  25723. this._lendBinding( binding );
  25724. binding.saveOriginalState();
  25725. }
  25726. }
  25727. this._lendAction( action );
  25728. }
  25729. },
  25730. _deactivateAction: function ( action ) {
  25731. if ( this._isActiveAction( action ) ) {
  25732. var bindings = action._propertyBindings;
  25733. // decrement reference counts / sort out state
  25734. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25735. var binding = bindings[ i ];
  25736. if ( -- binding.useCount === 0 ) {
  25737. binding.restoreOriginalState();
  25738. this._takeBackBinding( binding );
  25739. }
  25740. }
  25741. this._takeBackAction( action );
  25742. }
  25743. },
  25744. // Memory manager
  25745. _initMemoryManager: function () {
  25746. this._actions = []; // 'nActiveActions' followed by inactive ones
  25747. this._nActiveActions = 0;
  25748. this._actionsByClip = {};
  25749. // inside:
  25750. // {
  25751. // knownActions: Array< AnimationAction > - used as prototypes
  25752. // actionByRoot: AnimationAction - lookup
  25753. // }
  25754. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25755. this._nActiveBindings = 0;
  25756. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25757. this._controlInterpolants = []; // same game as above
  25758. this._nActiveControlInterpolants = 0;
  25759. var scope = this;
  25760. this.stats = {
  25761. actions: {
  25762. get total() {
  25763. return scope._actions.length;
  25764. },
  25765. get inUse() {
  25766. return scope._nActiveActions;
  25767. }
  25768. },
  25769. bindings: {
  25770. get total() {
  25771. return scope._bindings.length;
  25772. },
  25773. get inUse() {
  25774. return scope._nActiveBindings;
  25775. }
  25776. },
  25777. controlInterpolants: {
  25778. get total() {
  25779. return scope._controlInterpolants.length;
  25780. },
  25781. get inUse() {
  25782. return scope._nActiveControlInterpolants;
  25783. }
  25784. }
  25785. };
  25786. },
  25787. // Memory management for AnimationAction objects
  25788. _isActiveAction: function ( action ) {
  25789. var index = action._cacheIndex;
  25790. return index !== null && index < this._nActiveActions;
  25791. },
  25792. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  25793. var actions = this._actions,
  25794. actionsByClip = this._actionsByClip,
  25795. actionsForClip = actionsByClip[ clipUuid ];
  25796. if ( actionsForClip === undefined ) {
  25797. actionsForClip = {
  25798. knownActions: [ action ],
  25799. actionByRoot: {}
  25800. };
  25801. action._byClipCacheIndex = 0;
  25802. actionsByClip[ clipUuid ] = actionsForClip;
  25803. } else {
  25804. var knownActions = actionsForClip.knownActions;
  25805. action._byClipCacheIndex = knownActions.length;
  25806. knownActions.push( action );
  25807. }
  25808. action._cacheIndex = actions.length;
  25809. actions.push( action );
  25810. actionsForClip.actionByRoot[ rootUuid ] = action;
  25811. },
  25812. _removeInactiveAction: function ( action ) {
  25813. var actions = this._actions,
  25814. lastInactiveAction = actions[ actions.length - 1 ],
  25815. cacheIndex = action._cacheIndex;
  25816. lastInactiveAction._cacheIndex = cacheIndex;
  25817. actions[ cacheIndex ] = lastInactiveAction;
  25818. actions.pop();
  25819. action._cacheIndex = null;
  25820. var clipUuid = action._clip.uuid,
  25821. actionsByClip = this._actionsByClip,
  25822. actionsForClip = actionsByClip[ clipUuid ],
  25823. knownActionsForClip = actionsForClip.knownActions,
  25824. lastKnownAction =
  25825. knownActionsForClip[ knownActionsForClip.length - 1 ],
  25826. byClipCacheIndex = action._byClipCacheIndex;
  25827. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  25828. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  25829. knownActionsForClip.pop();
  25830. action._byClipCacheIndex = null;
  25831. var actionByRoot = actionsForClip.actionByRoot,
  25832. rootUuid = ( action._localRoot || this._root ).uuid;
  25833. delete actionByRoot[ rootUuid ];
  25834. if ( knownActionsForClip.length === 0 ) {
  25835. delete actionsByClip[ clipUuid ];
  25836. }
  25837. this._removeInactiveBindingsForAction( action );
  25838. },
  25839. _removeInactiveBindingsForAction: function ( action ) {
  25840. var bindings = action._propertyBindings;
  25841. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25842. var binding = bindings[ i ];
  25843. if ( -- binding.referenceCount === 0 ) {
  25844. this._removeInactiveBinding( binding );
  25845. }
  25846. }
  25847. },
  25848. _lendAction: function ( action ) {
  25849. // [ active actions | inactive actions ]
  25850. // [ active actions >| inactive actions ]
  25851. // s a
  25852. // <-swap->
  25853. // a s
  25854. var actions = this._actions,
  25855. prevIndex = action._cacheIndex,
  25856. lastActiveIndex = this._nActiveActions ++,
  25857. firstInactiveAction = actions[ lastActiveIndex ];
  25858. action._cacheIndex = lastActiveIndex;
  25859. actions[ lastActiveIndex ] = action;
  25860. firstInactiveAction._cacheIndex = prevIndex;
  25861. actions[ prevIndex ] = firstInactiveAction;
  25862. },
  25863. _takeBackAction: function ( action ) {
  25864. // [ active actions | inactive actions ]
  25865. // [ active actions |< inactive actions ]
  25866. // a s
  25867. // <-swap->
  25868. // s a
  25869. var actions = this._actions,
  25870. prevIndex = action._cacheIndex,
  25871. firstInactiveIndex = -- this._nActiveActions,
  25872. lastActiveAction = actions[ firstInactiveIndex ];
  25873. action._cacheIndex = firstInactiveIndex;
  25874. actions[ firstInactiveIndex ] = action;
  25875. lastActiveAction._cacheIndex = prevIndex;
  25876. actions[ prevIndex ] = lastActiveAction;
  25877. },
  25878. // Memory management for PropertyMixer objects
  25879. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  25880. var bindingsByRoot = this._bindingsByRootAndName,
  25881. bindingByName = bindingsByRoot[ rootUuid ],
  25882. bindings = this._bindings;
  25883. if ( bindingByName === undefined ) {
  25884. bindingByName = {};
  25885. bindingsByRoot[ rootUuid ] = bindingByName;
  25886. }
  25887. bindingByName[ trackName ] = binding;
  25888. binding._cacheIndex = bindings.length;
  25889. bindings.push( binding );
  25890. },
  25891. _removeInactiveBinding: function ( binding ) {
  25892. var bindings = this._bindings,
  25893. propBinding = binding.binding,
  25894. rootUuid = propBinding.rootNode.uuid,
  25895. trackName = propBinding.path,
  25896. bindingsByRoot = this._bindingsByRootAndName,
  25897. bindingByName = bindingsByRoot[ rootUuid ],
  25898. lastInactiveBinding = bindings[ bindings.length - 1 ],
  25899. cacheIndex = binding._cacheIndex;
  25900. lastInactiveBinding._cacheIndex = cacheIndex;
  25901. bindings[ cacheIndex ] = lastInactiveBinding;
  25902. bindings.pop();
  25903. delete bindingByName[ trackName ];
  25904. remove_empty_map: {
  25905. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  25906. delete bindingsByRoot[ rootUuid ];
  25907. }
  25908. },
  25909. _lendBinding: function ( binding ) {
  25910. var bindings = this._bindings,
  25911. prevIndex = binding._cacheIndex,
  25912. lastActiveIndex = this._nActiveBindings ++,
  25913. firstInactiveBinding = bindings[ lastActiveIndex ];
  25914. binding._cacheIndex = lastActiveIndex;
  25915. bindings[ lastActiveIndex ] = binding;
  25916. firstInactiveBinding._cacheIndex = prevIndex;
  25917. bindings[ prevIndex ] = firstInactiveBinding;
  25918. },
  25919. _takeBackBinding: function ( binding ) {
  25920. var bindings = this._bindings,
  25921. prevIndex = binding._cacheIndex,
  25922. firstInactiveIndex = -- this._nActiveBindings,
  25923. lastActiveBinding = bindings[ firstInactiveIndex ];
  25924. binding._cacheIndex = firstInactiveIndex;
  25925. bindings[ firstInactiveIndex ] = binding;
  25926. lastActiveBinding._cacheIndex = prevIndex;
  25927. bindings[ prevIndex ] = lastActiveBinding;
  25928. },
  25929. // Memory management of Interpolants for weight and time scale
  25930. _lendControlInterpolant: function () {
  25931. var interpolants = this._controlInterpolants,
  25932. lastActiveIndex = this._nActiveControlInterpolants ++,
  25933. interpolant = interpolants[ lastActiveIndex ];
  25934. if ( interpolant === undefined ) {
  25935. interpolant = new LinearInterpolant(
  25936. new Float32Array( 2 ), new Float32Array( 2 ),
  25937. 1, this._controlInterpolantsResultBuffer );
  25938. interpolant.__cacheIndex = lastActiveIndex;
  25939. interpolants[ lastActiveIndex ] = interpolant;
  25940. }
  25941. return interpolant;
  25942. },
  25943. _takeBackControlInterpolant: function ( interpolant ) {
  25944. var interpolants = this._controlInterpolants,
  25945. prevIndex = interpolant.__cacheIndex,
  25946. firstInactiveIndex = -- this._nActiveControlInterpolants,
  25947. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  25948. interpolant.__cacheIndex = firstInactiveIndex;
  25949. interpolants[ firstInactiveIndex ] = interpolant;
  25950. lastActiveInterpolant.__cacheIndex = prevIndex;
  25951. interpolants[ prevIndex ] = lastActiveInterpolant;
  25952. },
  25953. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  25954. // return an action for a clip optionally using a custom root target
  25955. // object (this method allocates a lot of dynamic memory in case a
  25956. // previously unknown clip/root combination is specified)
  25957. clipAction: function ( clip, optionalRoot ) {
  25958. var root = optionalRoot || this._root,
  25959. rootUuid = root.uuid,
  25960. clipObject = typeof clip === 'string' ?
  25961. AnimationClip.findByName( root, clip ) : clip,
  25962. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  25963. actionsForClip = this._actionsByClip[ clipUuid ],
  25964. prototypeAction = null;
  25965. if ( actionsForClip !== undefined ) {
  25966. var existingAction =
  25967. actionsForClip.actionByRoot[ rootUuid ];
  25968. if ( existingAction !== undefined ) {
  25969. return existingAction;
  25970. }
  25971. // we know the clip, so we don't have to parse all
  25972. // the bindings again but can just copy
  25973. prototypeAction = actionsForClip.knownActions[ 0 ];
  25974. // also, take the clip from the prototype action
  25975. if ( clipObject === null )
  25976. clipObject = prototypeAction._clip;
  25977. }
  25978. // clip must be known when specified via string
  25979. if ( clipObject === null ) return null;
  25980. // allocate all resources required to run it
  25981. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  25982. this._bindAction( newAction, prototypeAction );
  25983. // and make the action known to the memory manager
  25984. this._addInactiveAction( newAction, clipUuid, rootUuid );
  25985. return newAction;
  25986. },
  25987. // get an existing action
  25988. existingAction: function ( clip, optionalRoot ) {
  25989. var root = optionalRoot || this._root,
  25990. rootUuid = root.uuid,
  25991. clipObject = typeof clip === 'string' ?
  25992. AnimationClip.findByName( root, clip ) : clip,
  25993. clipUuid = clipObject ? clipObject.uuid : clip,
  25994. actionsForClip = this._actionsByClip[ clipUuid ];
  25995. if ( actionsForClip !== undefined ) {
  25996. return actionsForClip.actionByRoot[ rootUuid ] || null;
  25997. }
  25998. return null;
  25999. },
  26000. // deactivates all previously scheduled actions
  26001. stopAllAction: function () {
  26002. var actions = this._actions,
  26003. nActions = this._nActiveActions,
  26004. bindings = this._bindings,
  26005. nBindings = this._nActiveBindings;
  26006. this._nActiveActions = 0;
  26007. this._nActiveBindings = 0;
  26008. for ( var i = 0; i !== nActions; ++ i ) {
  26009. actions[ i ].reset();
  26010. }
  26011. for ( var i = 0; i !== nBindings; ++ i ) {
  26012. bindings[ i ].useCount = 0;
  26013. }
  26014. return this;
  26015. },
  26016. // advance the time and update apply the animation
  26017. update: function ( deltaTime ) {
  26018. deltaTime *= this.timeScale;
  26019. var actions = this._actions,
  26020. nActions = this._nActiveActions,
  26021. time = this.time += deltaTime,
  26022. timeDirection = Math.sign( deltaTime ),
  26023. accuIndex = this._accuIndex ^= 1;
  26024. // run active actions
  26025. for ( var i = 0; i !== nActions; ++ i ) {
  26026. var action = actions[ i ];
  26027. action._update( time, deltaTime, timeDirection, accuIndex );
  26028. }
  26029. // update scene graph
  26030. var bindings = this._bindings,
  26031. nBindings = this._nActiveBindings;
  26032. for ( var i = 0; i !== nBindings; ++ i ) {
  26033. bindings[ i ].apply( accuIndex );
  26034. }
  26035. return this;
  26036. },
  26037. // return this mixer's root target object
  26038. getRoot: function () {
  26039. return this._root;
  26040. },
  26041. // free all resources specific to a particular clip
  26042. uncacheClip: function ( clip ) {
  26043. var actions = this._actions,
  26044. clipUuid = clip.uuid,
  26045. actionsByClip = this._actionsByClip,
  26046. actionsForClip = actionsByClip[ clipUuid ];
  26047. if ( actionsForClip !== undefined ) {
  26048. // note: just calling _removeInactiveAction would mess up the
  26049. // iteration state and also require updating the state we can
  26050. // just throw away
  26051. var actionsToRemove = actionsForClip.knownActions;
  26052. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26053. var action = actionsToRemove[ i ];
  26054. this._deactivateAction( action );
  26055. var cacheIndex = action._cacheIndex,
  26056. lastInactiveAction = actions[ actions.length - 1 ];
  26057. action._cacheIndex = null;
  26058. action._byClipCacheIndex = null;
  26059. lastInactiveAction._cacheIndex = cacheIndex;
  26060. actions[ cacheIndex ] = lastInactiveAction;
  26061. actions.pop();
  26062. this._removeInactiveBindingsForAction( action );
  26063. }
  26064. delete actionsByClip[ clipUuid ];
  26065. }
  26066. },
  26067. // free all resources specific to a particular root target object
  26068. uncacheRoot: function ( root ) {
  26069. var rootUuid = root.uuid,
  26070. actionsByClip = this._actionsByClip;
  26071. for ( var clipUuid in actionsByClip ) {
  26072. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26073. action = actionByRoot[ rootUuid ];
  26074. if ( action !== undefined ) {
  26075. this._deactivateAction( action );
  26076. this._removeInactiveAction( action );
  26077. }
  26078. }
  26079. var bindingsByRoot = this._bindingsByRootAndName,
  26080. bindingByName = bindingsByRoot[ rootUuid ];
  26081. if ( bindingByName !== undefined ) {
  26082. for ( var trackName in bindingByName ) {
  26083. var binding = bindingByName[ trackName ];
  26084. binding.restoreOriginalState();
  26085. this._removeInactiveBinding( binding );
  26086. }
  26087. }
  26088. },
  26089. // remove a targeted clip from the cache
  26090. uncacheAction: function ( clip, optionalRoot ) {
  26091. var action = this.existingAction( clip, optionalRoot );
  26092. if ( action !== null ) {
  26093. this._deactivateAction( action );
  26094. this._removeInactiveAction( action );
  26095. }
  26096. }
  26097. } );
  26098. /**
  26099. * @author mrdoob / http://mrdoob.com/
  26100. */
  26101. function Uniform( value ) {
  26102. if ( typeof value === 'string' ) {
  26103. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26104. value = arguments[ 1 ];
  26105. }
  26106. this.value = value;
  26107. }
  26108. Uniform.prototype.clone = function () {
  26109. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26110. };
  26111. /**
  26112. * @author benaadams / https://twitter.com/ben_a_adams
  26113. */
  26114. function InstancedBufferGeometry() {
  26115. BufferGeometry.call( this );
  26116. this.type = 'InstancedBufferGeometry';
  26117. this.maxInstancedCount = undefined;
  26118. }
  26119. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  26120. constructor: InstancedBufferGeometry,
  26121. isInstancedBufferGeometry: true,
  26122. copy: function ( source ) {
  26123. BufferGeometry.prototype.copy.call( this, source );
  26124. this.maxInstancedCount = source.maxInstancedCount;
  26125. return this;
  26126. },
  26127. clone: function () {
  26128. return new this.constructor().copy( this );
  26129. }
  26130. } );
  26131. /**
  26132. * @author benaadams / https://twitter.com/ben_a_adams
  26133. */
  26134. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26135. InterleavedBuffer.call( this, array, stride );
  26136. this.meshPerAttribute = meshPerAttribute || 1;
  26137. }
  26138. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26139. constructor: InstancedInterleavedBuffer,
  26140. isInstancedInterleavedBuffer: true,
  26141. copy: function ( source ) {
  26142. InterleavedBuffer.prototype.copy.call( this, source );
  26143. this.meshPerAttribute = source.meshPerAttribute;
  26144. return this;
  26145. }
  26146. } );
  26147. /**
  26148. * @author benaadams / https://twitter.com/ben_a_adams
  26149. */
  26150. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  26151. if ( typeof ( normalized ) === 'number' ) {
  26152. meshPerAttribute = normalized;
  26153. normalized = false;
  26154. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  26155. }
  26156. BufferAttribute.call( this, array, itemSize, normalized );
  26157. this.meshPerAttribute = meshPerAttribute || 1;
  26158. }
  26159. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  26160. constructor: InstancedBufferAttribute,
  26161. isInstancedBufferAttribute: true,
  26162. copy: function ( source ) {
  26163. BufferAttribute.prototype.copy.call( this, source );
  26164. this.meshPerAttribute = source.meshPerAttribute;
  26165. return this;
  26166. }
  26167. } );
  26168. /**
  26169. * @author mrdoob / http://mrdoob.com/
  26170. * @author bhouston / http://clara.io/
  26171. * @author stephomi / http://stephaneginier.com/
  26172. */
  26173. function Raycaster( origin, direction, near, far ) {
  26174. this.ray = new Ray( origin, direction );
  26175. // direction is assumed to be normalized (for accurate distance calculations)
  26176. this.near = near || 0;
  26177. this.far = far || Infinity;
  26178. this.params = {
  26179. Mesh: {},
  26180. Line: {},
  26181. LOD: {},
  26182. Points: { threshold: 1 },
  26183. Sprite: {}
  26184. };
  26185. Object.defineProperties( this.params, {
  26186. PointCloud: {
  26187. get: function () {
  26188. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26189. return this.Points;
  26190. }
  26191. }
  26192. } );
  26193. }
  26194. function ascSort( a, b ) {
  26195. return a.distance - b.distance;
  26196. }
  26197. function intersectObject( object, raycaster, intersects, recursive ) {
  26198. if ( object.visible === false ) return;
  26199. object.raycast( raycaster, intersects );
  26200. if ( recursive === true ) {
  26201. var children = object.children;
  26202. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26203. intersectObject( children[ i ], raycaster, intersects, true );
  26204. }
  26205. }
  26206. }
  26207. Object.assign( Raycaster.prototype, {
  26208. linePrecision: 1,
  26209. set: function ( origin, direction ) {
  26210. // direction is assumed to be normalized (for accurate distance calculations)
  26211. this.ray.set( origin, direction );
  26212. },
  26213. setFromCamera: function ( coords, camera ) {
  26214. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26215. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26216. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26217. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26218. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26219. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26220. } else {
  26221. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26222. }
  26223. },
  26224. intersectObject: function ( object, recursive, optionalTarget ) {
  26225. var intersects = optionalTarget || [];
  26226. intersectObject( object, this, intersects, recursive );
  26227. intersects.sort( ascSort );
  26228. return intersects;
  26229. },
  26230. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26231. var intersects = optionalTarget || [];
  26232. if ( Array.isArray( objects ) === false ) {
  26233. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26234. return intersects;
  26235. }
  26236. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26237. intersectObject( objects[ i ], this, intersects, recursive );
  26238. }
  26239. intersects.sort( ascSort );
  26240. return intersects;
  26241. }
  26242. } );
  26243. /**
  26244. * @author bhouston / http://clara.io
  26245. * @author WestLangley / http://github.com/WestLangley
  26246. *
  26247. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26248. *
  26249. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26250. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26251. */
  26252. function Spherical( radius, phi, theta ) {
  26253. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26254. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26255. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26256. return this;
  26257. }
  26258. Object.assign( Spherical.prototype, {
  26259. set: function ( radius, phi, theta ) {
  26260. this.radius = radius;
  26261. this.phi = phi;
  26262. this.theta = theta;
  26263. return this;
  26264. },
  26265. clone: function () {
  26266. return new this.constructor().copy( this );
  26267. },
  26268. copy: function ( other ) {
  26269. this.radius = other.radius;
  26270. this.phi = other.phi;
  26271. this.theta = other.theta;
  26272. return this;
  26273. },
  26274. // restrict phi to be betwee EPS and PI-EPS
  26275. makeSafe: function () {
  26276. var EPS = 0.000001;
  26277. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26278. return this;
  26279. },
  26280. setFromVector3: function ( v ) {
  26281. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26282. },
  26283. setFromCartesianCoords: function ( x, y, z ) {
  26284. this.radius = Math.sqrt( x * x + y * y + z * z );
  26285. if ( this.radius === 0 ) {
  26286. this.theta = 0;
  26287. this.phi = 0;
  26288. } else {
  26289. this.theta = Math.atan2( x, z );
  26290. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26291. }
  26292. return this;
  26293. }
  26294. } );
  26295. /**
  26296. * @author Mugen87 / https://github.com/Mugen87
  26297. *
  26298. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26299. *
  26300. */
  26301. function Cylindrical( radius, theta, y ) {
  26302. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26303. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26304. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26305. return this;
  26306. }
  26307. Object.assign( Cylindrical.prototype, {
  26308. set: function ( radius, theta, y ) {
  26309. this.radius = radius;
  26310. this.theta = theta;
  26311. this.y = y;
  26312. return this;
  26313. },
  26314. clone: function () {
  26315. return new this.constructor().copy( this );
  26316. },
  26317. copy: function ( other ) {
  26318. this.radius = other.radius;
  26319. this.theta = other.theta;
  26320. this.y = other.y;
  26321. return this;
  26322. },
  26323. setFromVector3: function ( v ) {
  26324. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26325. },
  26326. setFromCartesianCoords: function ( x, y, z ) {
  26327. this.radius = Math.sqrt( x * x + z * z );
  26328. this.theta = Math.atan2( x, z );
  26329. this.y = y;
  26330. return this;
  26331. }
  26332. } );
  26333. /**
  26334. * @author bhouston / http://clara.io
  26335. */
  26336. function Box2( min, max ) {
  26337. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26338. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26339. }
  26340. Object.assign( Box2.prototype, {
  26341. set: function ( min, max ) {
  26342. this.min.copy( min );
  26343. this.max.copy( max );
  26344. return this;
  26345. },
  26346. setFromPoints: function ( points ) {
  26347. this.makeEmpty();
  26348. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26349. this.expandByPoint( points[ i ] );
  26350. }
  26351. return this;
  26352. },
  26353. setFromCenterAndSize: function () {
  26354. var v1 = new Vector2();
  26355. return function setFromCenterAndSize( center, size ) {
  26356. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26357. this.min.copy( center ).sub( halfSize );
  26358. this.max.copy( center ).add( halfSize );
  26359. return this;
  26360. };
  26361. }(),
  26362. clone: function () {
  26363. return new this.constructor().copy( this );
  26364. },
  26365. copy: function ( box ) {
  26366. this.min.copy( box.min );
  26367. this.max.copy( box.max );
  26368. return this;
  26369. },
  26370. makeEmpty: function () {
  26371. this.min.x = this.min.y = + Infinity;
  26372. this.max.x = this.max.y = - Infinity;
  26373. return this;
  26374. },
  26375. isEmpty: function () {
  26376. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26377. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26378. },
  26379. getCenter: function ( target ) {
  26380. if ( target === undefined ) {
  26381. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26382. target = new Vector2();
  26383. }
  26384. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26385. },
  26386. getSize: function ( target ) {
  26387. if ( target === undefined ) {
  26388. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26389. target = new Vector2();
  26390. }
  26391. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26392. },
  26393. expandByPoint: function ( point ) {
  26394. this.min.min( point );
  26395. this.max.max( point );
  26396. return this;
  26397. },
  26398. expandByVector: function ( vector ) {
  26399. this.min.sub( vector );
  26400. this.max.add( vector );
  26401. return this;
  26402. },
  26403. expandByScalar: function ( scalar ) {
  26404. this.min.addScalar( - scalar );
  26405. this.max.addScalar( scalar );
  26406. return this;
  26407. },
  26408. containsPoint: function ( point ) {
  26409. return point.x < this.min.x || point.x > this.max.x ||
  26410. point.y < this.min.y || point.y > this.max.y ? false : true;
  26411. },
  26412. containsBox: function ( box ) {
  26413. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26414. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26415. },
  26416. getParameter: function ( point, target ) {
  26417. // This can potentially have a divide by zero if the box
  26418. // has a size dimension of 0.
  26419. if ( target === undefined ) {
  26420. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26421. target = new Vector2();
  26422. }
  26423. return target.set(
  26424. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26425. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26426. );
  26427. },
  26428. intersectsBox: function ( box ) {
  26429. // using 4 splitting planes to rule out intersections
  26430. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26431. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26432. },
  26433. clampPoint: function ( point, target ) {
  26434. if ( target === undefined ) {
  26435. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26436. target = new Vector2();
  26437. }
  26438. return target.copy( point ).clamp( this.min, this.max );
  26439. },
  26440. distanceToPoint: function () {
  26441. var v1 = new Vector2();
  26442. return function distanceToPoint( point ) {
  26443. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26444. return clampedPoint.sub( point ).length();
  26445. };
  26446. }(),
  26447. intersect: function ( box ) {
  26448. this.min.max( box.min );
  26449. this.max.min( box.max );
  26450. return this;
  26451. },
  26452. union: function ( box ) {
  26453. this.min.min( box.min );
  26454. this.max.max( box.max );
  26455. return this;
  26456. },
  26457. translate: function ( offset ) {
  26458. this.min.add( offset );
  26459. this.max.add( offset );
  26460. return this;
  26461. },
  26462. equals: function ( box ) {
  26463. return box.min.equals( this.min ) && box.max.equals( this.max );
  26464. }
  26465. } );
  26466. /**
  26467. * @author bhouston / http://clara.io
  26468. */
  26469. function Line3( start, end ) {
  26470. this.start = ( start !== undefined ) ? start : new Vector3();
  26471. this.end = ( end !== undefined ) ? end : new Vector3();
  26472. }
  26473. Object.assign( Line3.prototype, {
  26474. set: function ( start, end ) {
  26475. this.start.copy( start );
  26476. this.end.copy( end );
  26477. return this;
  26478. },
  26479. clone: function () {
  26480. return new this.constructor().copy( this );
  26481. },
  26482. copy: function ( line ) {
  26483. this.start.copy( line.start );
  26484. this.end.copy( line.end );
  26485. return this;
  26486. },
  26487. getCenter: function ( target ) {
  26488. if ( target === undefined ) {
  26489. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26490. target = new Vector3();
  26491. }
  26492. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26493. },
  26494. delta: function ( target ) {
  26495. if ( target === undefined ) {
  26496. console.warn( 'THREE.Line3: .delta() target is now required' );
  26497. target = new Vector3();
  26498. }
  26499. return target.subVectors( this.end, this.start );
  26500. },
  26501. distanceSq: function () {
  26502. return this.start.distanceToSquared( this.end );
  26503. },
  26504. distance: function () {
  26505. return this.start.distanceTo( this.end );
  26506. },
  26507. at: function ( t, target ) {
  26508. if ( target === undefined ) {
  26509. console.warn( 'THREE.Line3: .at() target is now required' );
  26510. target = new Vector3();
  26511. }
  26512. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26513. },
  26514. closestPointToPointParameter: function () {
  26515. var startP = new Vector3();
  26516. var startEnd = new Vector3();
  26517. return function closestPointToPointParameter( point, clampToLine ) {
  26518. startP.subVectors( point, this.start );
  26519. startEnd.subVectors( this.end, this.start );
  26520. var startEnd2 = startEnd.dot( startEnd );
  26521. var startEnd_startP = startEnd.dot( startP );
  26522. var t = startEnd_startP / startEnd2;
  26523. if ( clampToLine ) {
  26524. t = _Math.clamp( t, 0, 1 );
  26525. }
  26526. return t;
  26527. };
  26528. }(),
  26529. closestPointToPoint: function ( point, clampToLine, target ) {
  26530. var t = this.closestPointToPointParameter( point, clampToLine );
  26531. if ( target === undefined ) {
  26532. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26533. target = new Vector3();
  26534. }
  26535. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26536. },
  26537. applyMatrix4: function ( matrix ) {
  26538. this.start.applyMatrix4( matrix );
  26539. this.end.applyMatrix4( matrix );
  26540. return this;
  26541. },
  26542. equals: function ( line ) {
  26543. return line.start.equals( this.start ) && line.end.equals( this.end );
  26544. }
  26545. } );
  26546. /**
  26547. * @author alteredq / http://alteredqualia.com/
  26548. */
  26549. function ImmediateRenderObject( material ) {
  26550. Object3D.call( this );
  26551. this.material = material;
  26552. this.render = function ( /* renderCallback */ ) {};
  26553. }
  26554. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26555. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26556. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26557. /**
  26558. * @author mrdoob / http://mrdoob.com/
  26559. * @author WestLangley / http://github.com/WestLangley
  26560. */
  26561. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26562. this.object = object;
  26563. this.size = ( size !== undefined ) ? size : 1;
  26564. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26565. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26566. //
  26567. var nNormals = 0;
  26568. var objGeometry = this.object.geometry;
  26569. if ( objGeometry && objGeometry.isGeometry ) {
  26570. nNormals = objGeometry.faces.length * 3;
  26571. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26572. nNormals = objGeometry.attributes.normal.count;
  26573. }
  26574. //
  26575. var geometry = new BufferGeometry();
  26576. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26577. geometry.addAttribute( 'position', positions );
  26578. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26579. //
  26580. this.matrixAutoUpdate = false;
  26581. this.update();
  26582. }
  26583. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26584. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26585. VertexNormalsHelper.prototype.update = ( function () {
  26586. var v1 = new Vector3();
  26587. var v2 = new Vector3();
  26588. var normalMatrix = new Matrix3();
  26589. return function update() {
  26590. var keys = [ 'a', 'b', 'c' ];
  26591. this.object.updateMatrixWorld( true );
  26592. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26593. var matrixWorld = this.object.matrixWorld;
  26594. var position = this.geometry.attributes.position;
  26595. //
  26596. var objGeometry = this.object.geometry;
  26597. if ( objGeometry && objGeometry.isGeometry ) {
  26598. var vertices = objGeometry.vertices;
  26599. var faces = objGeometry.faces;
  26600. var idx = 0;
  26601. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26602. var face = faces[ i ];
  26603. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26604. var vertex = vertices[ face[ keys[ j ] ] ];
  26605. var normal = face.vertexNormals[ j ];
  26606. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26607. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26608. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26609. idx = idx + 1;
  26610. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26611. idx = idx + 1;
  26612. }
  26613. }
  26614. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26615. var objPos = objGeometry.attributes.position;
  26616. var objNorm = objGeometry.attributes.normal;
  26617. var idx = 0;
  26618. // for simplicity, ignore index and drawcalls, and render every normal
  26619. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26620. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26621. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26622. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26623. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26624. idx = idx + 1;
  26625. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26626. idx = idx + 1;
  26627. }
  26628. }
  26629. position.needsUpdate = true;
  26630. };
  26631. }() );
  26632. /**
  26633. * @author alteredq / http://alteredqualia.com/
  26634. * @author mrdoob / http://mrdoob.com/
  26635. * @author WestLangley / http://github.com/WestLangley
  26636. */
  26637. function SpotLightHelper( light, color ) {
  26638. Object3D.call( this );
  26639. this.light = light;
  26640. this.light.updateMatrixWorld();
  26641. this.matrix = light.matrixWorld;
  26642. this.matrixAutoUpdate = false;
  26643. this.color = color;
  26644. var geometry = new BufferGeometry();
  26645. var positions = [
  26646. 0, 0, 0, 0, 0, 1,
  26647. 0, 0, 0, 1, 0, 1,
  26648. 0, 0, 0, - 1, 0, 1,
  26649. 0, 0, 0, 0, 1, 1,
  26650. 0, 0, 0, 0, - 1, 1
  26651. ];
  26652. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26653. var p1 = ( i / l ) * Math.PI * 2;
  26654. var p2 = ( j / l ) * Math.PI * 2;
  26655. positions.push(
  26656. Math.cos( p1 ), Math.sin( p1 ), 1,
  26657. Math.cos( p2 ), Math.sin( p2 ), 1
  26658. );
  26659. }
  26660. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26661. var material = new LineBasicMaterial( { fog: false } );
  26662. this.cone = new LineSegments( geometry, material );
  26663. this.add( this.cone );
  26664. this.update();
  26665. }
  26666. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26667. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26668. SpotLightHelper.prototype.dispose = function () {
  26669. this.cone.geometry.dispose();
  26670. this.cone.material.dispose();
  26671. };
  26672. SpotLightHelper.prototype.update = function () {
  26673. var vector = new Vector3();
  26674. return function update() {
  26675. this.light.updateMatrixWorld();
  26676. var coneLength = this.light.distance ? this.light.distance : 1000;
  26677. var coneWidth = coneLength * Math.tan( this.light.angle );
  26678. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26679. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26680. this.cone.lookAt( vector );
  26681. if ( this.color !== undefined ) {
  26682. this.cone.material.color.set( this.color );
  26683. } else {
  26684. this.cone.material.color.copy( this.light.color );
  26685. }
  26686. };
  26687. }();
  26688. /**
  26689. * @author Sean Griffin / http://twitter.com/sgrif
  26690. * @author Michael Guerrero / http://realitymeltdown.com
  26691. * @author mrdoob / http://mrdoob.com/
  26692. * @author ikerr / http://verold.com
  26693. * @author Mugen87 / https://github.com/Mugen87
  26694. */
  26695. function getBoneList( object ) {
  26696. var boneList = [];
  26697. if ( object && object.isBone ) {
  26698. boneList.push( object );
  26699. }
  26700. for ( var i = 0; i < object.children.length; i ++ ) {
  26701. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26702. }
  26703. return boneList;
  26704. }
  26705. function SkeletonHelper( object ) {
  26706. var bones = getBoneList( object );
  26707. var geometry = new BufferGeometry();
  26708. var vertices = [];
  26709. var colors = [];
  26710. var color1 = new Color( 0, 0, 1 );
  26711. var color2 = new Color( 0, 1, 0 );
  26712. for ( var i = 0; i < bones.length; i ++ ) {
  26713. var bone = bones[ i ];
  26714. if ( bone.parent && bone.parent.isBone ) {
  26715. vertices.push( 0, 0, 0 );
  26716. vertices.push( 0, 0, 0 );
  26717. colors.push( color1.r, color1.g, color1.b );
  26718. colors.push( color2.r, color2.g, color2.b );
  26719. }
  26720. }
  26721. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26722. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26723. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  26724. LineSegments.call( this, geometry, material );
  26725. this.root = object;
  26726. this.bones = bones;
  26727. this.matrix = object.matrixWorld;
  26728. this.matrixAutoUpdate = false;
  26729. }
  26730. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  26731. SkeletonHelper.prototype.constructor = SkeletonHelper;
  26732. SkeletonHelper.prototype.updateMatrixWorld = function () {
  26733. var vector = new Vector3();
  26734. var boneMatrix = new Matrix4();
  26735. var matrixWorldInv = new Matrix4();
  26736. return function updateMatrixWorld( force ) {
  26737. var bones = this.bones;
  26738. var geometry = this.geometry;
  26739. var position = geometry.getAttribute( 'position' );
  26740. matrixWorldInv.getInverse( this.root.matrixWorld );
  26741. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  26742. var bone = bones[ i ];
  26743. if ( bone.parent && bone.parent.isBone ) {
  26744. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  26745. vector.setFromMatrixPosition( boneMatrix );
  26746. position.setXYZ( j, vector.x, vector.y, vector.z );
  26747. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  26748. vector.setFromMatrixPosition( boneMatrix );
  26749. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  26750. j += 2;
  26751. }
  26752. }
  26753. geometry.getAttribute( 'position' ).needsUpdate = true;
  26754. Object3D.prototype.updateMatrixWorld.call( this, force );
  26755. };
  26756. }();
  26757. /**
  26758. * @author alteredq / http://alteredqualia.com/
  26759. * @author mrdoob / http://mrdoob.com/
  26760. */
  26761. function PointLightHelper( light, sphereSize, color ) {
  26762. this.light = light;
  26763. this.light.updateMatrixWorld();
  26764. this.color = color;
  26765. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  26766. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26767. Mesh.call( this, geometry, material );
  26768. this.matrix = this.light.matrixWorld;
  26769. this.matrixAutoUpdate = false;
  26770. this.update();
  26771. /*
  26772. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  26773. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  26774. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  26775. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  26776. var d = light.distance;
  26777. if ( d === 0.0 ) {
  26778. this.lightDistance.visible = false;
  26779. } else {
  26780. this.lightDistance.scale.set( d, d, d );
  26781. }
  26782. this.add( this.lightDistance );
  26783. */
  26784. }
  26785. PointLightHelper.prototype = Object.create( Mesh.prototype );
  26786. PointLightHelper.prototype.constructor = PointLightHelper;
  26787. PointLightHelper.prototype.dispose = function () {
  26788. this.geometry.dispose();
  26789. this.material.dispose();
  26790. };
  26791. PointLightHelper.prototype.update = function () {
  26792. if ( this.color !== undefined ) {
  26793. this.material.color.set( this.color );
  26794. } else {
  26795. this.material.color.copy( this.light.color );
  26796. }
  26797. /*
  26798. var d = this.light.distance;
  26799. if ( d === 0.0 ) {
  26800. this.lightDistance.visible = false;
  26801. } else {
  26802. this.lightDistance.visible = true;
  26803. this.lightDistance.scale.set( d, d, d );
  26804. }
  26805. */
  26806. };
  26807. /**
  26808. * @author abelnation / http://github.com/abelnation
  26809. * @author Mugen87 / http://github.com/Mugen87
  26810. * @author WestLangley / http://github.com/WestLangley
  26811. *
  26812. * This helper must be added as a child of the light
  26813. */
  26814. function RectAreaLightHelper( light, color ) {
  26815. this.type = 'RectAreaLightHelper';
  26816. this.light = light;
  26817. this.color = color; // optional hardwired color for the helper
  26818. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  26819. var geometry = new BufferGeometry();
  26820. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26821. geometry.computeBoundingSphere();
  26822. var material = new LineBasicMaterial( { fog: false } );
  26823. Line.call( this, geometry, material );
  26824. //
  26825. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  26826. var geometry2 = new BufferGeometry();
  26827. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26828. geometry2.computeBoundingSphere();
  26829. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  26830. this.update();
  26831. }
  26832. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  26833. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  26834. RectAreaLightHelper.prototype.update = function () {
  26835. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  26836. if ( this.color !== undefined ) {
  26837. this.material.color.set( this.color );
  26838. this.children[ 0 ].material.color.set( this.color );
  26839. } else {
  26840. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  26841. // prevent hue shift
  26842. var c = this.material.color;
  26843. var max = Math.max( c.r, c.g, c.b );
  26844. if ( max > 1 ) c.multiplyScalar( 1 / max );
  26845. this.children[ 0 ].material.color.copy( this.material.color );
  26846. }
  26847. };
  26848. RectAreaLightHelper.prototype.dispose = function () {
  26849. this.geometry.dispose();
  26850. this.material.dispose();
  26851. this.children[ 0 ].geometry.dispose();
  26852. this.children[ 0 ].material.dispose();
  26853. };
  26854. /**
  26855. * @author alteredq / http://alteredqualia.com/
  26856. * @author mrdoob / http://mrdoob.com/
  26857. * @author Mugen87 / https://github.com/Mugen87
  26858. */
  26859. function HemisphereLightHelper( light, size, color ) {
  26860. Object3D.call( this );
  26861. this.light = light;
  26862. this.light.updateMatrixWorld();
  26863. this.matrix = light.matrixWorld;
  26864. this.matrixAutoUpdate = false;
  26865. this.color = color;
  26866. var geometry = new OctahedronBufferGeometry( size );
  26867. geometry.rotateY( Math.PI * 0.5 );
  26868. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26869. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  26870. var position = geometry.getAttribute( 'position' );
  26871. var colors = new Float32Array( position.count * 3 );
  26872. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  26873. this.add( new Mesh( geometry, this.material ) );
  26874. this.update();
  26875. }
  26876. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  26877. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  26878. HemisphereLightHelper.prototype.dispose = function () {
  26879. this.children[ 0 ].geometry.dispose();
  26880. this.children[ 0 ].material.dispose();
  26881. };
  26882. HemisphereLightHelper.prototype.update = function () {
  26883. var vector = new Vector3();
  26884. var color1 = new Color();
  26885. var color2 = new Color();
  26886. return function update() {
  26887. var mesh = this.children[ 0 ];
  26888. if ( this.color !== undefined ) {
  26889. this.material.color.set( this.color );
  26890. } else {
  26891. var colors = mesh.geometry.getAttribute( 'color' );
  26892. color1.copy( this.light.color );
  26893. color2.copy( this.light.groundColor );
  26894. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  26895. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  26896. colors.setXYZ( i, color.r, color.g, color.b );
  26897. }
  26898. colors.needsUpdate = true;
  26899. }
  26900. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  26901. };
  26902. }();
  26903. /**
  26904. * @author mrdoob / http://mrdoob.com/
  26905. */
  26906. function GridHelper( size, divisions, color1, color2 ) {
  26907. size = size || 10;
  26908. divisions = divisions || 10;
  26909. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26910. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26911. var center = divisions / 2;
  26912. var step = size / divisions;
  26913. var halfSize = size / 2;
  26914. var vertices = [], colors = [];
  26915. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  26916. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  26917. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26918. var color = i === center ? color1 : color2;
  26919. color.toArray( colors, j ); j += 3;
  26920. color.toArray( colors, j ); j += 3;
  26921. color.toArray( colors, j ); j += 3;
  26922. color.toArray( colors, j ); j += 3;
  26923. }
  26924. var geometry = new BufferGeometry();
  26925. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26926. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26927. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26928. LineSegments.call( this, geometry, material );
  26929. }
  26930. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  26931. constructor: GridHelper,
  26932. copy: function ( source ) {
  26933. LineSegments.prototype.copy.call( this, source );
  26934. this.geometry.copy( source.geometry );
  26935. this.material.copy( source.material );
  26936. return this;
  26937. },
  26938. clone: function () {
  26939. return new this.constructor().copy( this );
  26940. }
  26941. } );
  26942. /**
  26943. * @author mrdoob / http://mrdoob.com/
  26944. * @author Mugen87 / http://github.com/Mugen87
  26945. * @author Hectate / http://www.github.com/Hectate
  26946. */
  26947. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  26948. radius = radius || 10;
  26949. radials = radials || 16;
  26950. circles = circles || 8;
  26951. divisions = divisions || 64;
  26952. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26953. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26954. var vertices = [];
  26955. var colors = [];
  26956. var x, z;
  26957. var v, i, j, r, color;
  26958. // create the radials
  26959. for ( i = 0; i <= radials; i ++ ) {
  26960. v = ( i / radials ) * ( Math.PI * 2 );
  26961. x = Math.sin( v ) * radius;
  26962. z = Math.cos( v ) * radius;
  26963. vertices.push( 0, 0, 0 );
  26964. vertices.push( x, 0, z );
  26965. color = ( i & 1 ) ? color1 : color2;
  26966. colors.push( color.r, color.g, color.b );
  26967. colors.push( color.r, color.g, color.b );
  26968. }
  26969. // create the circles
  26970. for ( i = 0; i <= circles; i ++ ) {
  26971. color = ( i & 1 ) ? color1 : color2;
  26972. r = radius - ( radius / circles * i );
  26973. for ( j = 0; j < divisions; j ++ ) {
  26974. // first vertex
  26975. v = ( j / divisions ) * ( Math.PI * 2 );
  26976. x = Math.sin( v ) * r;
  26977. z = Math.cos( v ) * r;
  26978. vertices.push( x, 0, z );
  26979. colors.push( color.r, color.g, color.b );
  26980. // second vertex
  26981. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26982. x = Math.sin( v ) * r;
  26983. z = Math.cos( v ) * r;
  26984. vertices.push( x, 0, z );
  26985. colors.push( color.r, color.g, color.b );
  26986. }
  26987. }
  26988. var geometry = new BufferGeometry();
  26989. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26990. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26991. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26992. LineSegments.call( this, geometry, material );
  26993. }
  26994. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  26995. PolarGridHelper.prototype.constructor = PolarGridHelper;
  26996. /**
  26997. * @author Mugen87 / http://github.com/Mugen87
  26998. */
  26999. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27000. this.audio = audio;
  27001. this.range = range || 1;
  27002. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27003. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27004. var geometry = new BufferGeometry();
  27005. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27006. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27007. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27008. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27009. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27010. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27011. this.update();
  27012. }
  27013. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27014. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27015. PositionalAudioHelper.prototype.update = function () {
  27016. var audio = this.audio;
  27017. var range = this.range;
  27018. var divisionsInnerAngle = this.divisionsInnerAngle;
  27019. var divisionsOuterAngle = this.divisionsOuterAngle;
  27020. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27021. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27022. var halfConeInnerAngle = coneInnerAngle / 2;
  27023. var halfConeOuterAngle = coneOuterAngle / 2;
  27024. var start = 0;
  27025. var count = 0;
  27026. var i, stride;
  27027. var geometry = this.geometry;
  27028. var positionAttribute = geometry.attributes.position;
  27029. geometry.clearGroups();
  27030. //
  27031. function generateSegment( from, to, divisions, materialIndex ) {
  27032. var step = ( to - from ) / divisions;
  27033. positionAttribute.setXYZ( start, 0, 0, 0 );
  27034. count ++;
  27035. for ( i = from; i < to; i += step ) {
  27036. stride = start + count;
  27037. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27038. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27039. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27040. count += 3;
  27041. }
  27042. geometry.addGroup( start, count, materialIndex );
  27043. start += count;
  27044. count = 0;
  27045. }
  27046. //
  27047. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27048. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27049. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27050. //
  27051. positionAttribute.needsUpdate = true;
  27052. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27053. };
  27054. PositionalAudioHelper.prototype.dispose = function () {
  27055. this.geometry.dispose();
  27056. this.material[ 0 ].dispose();
  27057. this.material[ 1 ].dispose();
  27058. };
  27059. /**
  27060. * @author mrdoob / http://mrdoob.com/
  27061. * @author WestLangley / http://github.com/WestLangley
  27062. */
  27063. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27064. // FaceNormalsHelper only supports THREE.Geometry
  27065. this.object = object;
  27066. this.size = ( size !== undefined ) ? size : 1;
  27067. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27068. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27069. //
  27070. var nNormals = 0;
  27071. var objGeometry = this.object.geometry;
  27072. if ( objGeometry && objGeometry.isGeometry ) {
  27073. nNormals = objGeometry.faces.length;
  27074. } else {
  27075. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27076. }
  27077. //
  27078. var geometry = new BufferGeometry();
  27079. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27080. geometry.addAttribute( 'position', positions );
  27081. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27082. //
  27083. this.matrixAutoUpdate = false;
  27084. this.update();
  27085. }
  27086. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27087. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27088. FaceNormalsHelper.prototype.update = ( function () {
  27089. var v1 = new Vector3();
  27090. var v2 = new Vector3();
  27091. var normalMatrix = new Matrix3();
  27092. return function update() {
  27093. this.object.updateMatrixWorld( true );
  27094. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27095. var matrixWorld = this.object.matrixWorld;
  27096. var position = this.geometry.attributes.position;
  27097. //
  27098. var objGeometry = this.object.geometry;
  27099. var vertices = objGeometry.vertices;
  27100. var faces = objGeometry.faces;
  27101. var idx = 0;
  27102. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27103. var face = faces[ i ];
  27104. var normal = face.normal;
  27105. v1.copy( vertices[ face.a ] )
  27106. .add( vertices[ face.b ] )
  27107. .add( vertices[ face.c ] )
  27108. .divideScalar( 3 )
  27109. .applyMatrix4( matrixWorld );
  27110. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27111. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27112. idx = idx + 1;
  27113. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27114. idx = idx + 1;
  27115. }
  27116. position.needsUpdate = true;
  27117. };
  27118. }() );
  27119. /**
  27120. * @author alteredq / http://alteredqualia.com/
  27121. * @author mrdoob / http://mrdoob.com/
  27122. * @author WestLangley / http://github.com/WestLangley
  27123. */
  27124. function DirectionalLightHelper( light, size, color ) {
  27125. Object3D.call( this );
  27126. this.light = light;
  27127. this.light.updateMatrixWorld();
  27128. this.matrix = light.matrixWorld;
  27129. this.matrixAutoUpdate = false;
  27130. this.color = color;
  27131. if ( size === undefined ) size = 1;
  27132. var geometry = new BufferGeometry();
  27133. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27134. - size, size, 0,
  27135. size, size, 0,
  27136. size, - size, 0,
  27137. - size, - size, 0,
  27138. - size, size, 0
  27139. ], 3 ) );
  27140. var material = new LineBasicMaterial( { fog: false } );
  27141. this.lightPlane = new Line( geometry, material );
  27142. this.add( this.lightPlane );
  27143. geometry = new BufferGeometry();
  27144. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27145. this.targetLine = new Line( geometry, material );
  27146. this.add( this.targetLine );
  27147. this.update();
  27148. }
  27149. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27150. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27151. DirectionalLightHelper.prototype.dispose = function () {
  27152. this.lightPlane.geometry.dispose();
  27153. this.lightPlane.material.dispose();
  27154. this.targetLine.geometry.dispose();
  27155. this.targetLine.material.dispose();
  27156. };
  27157. DirectionalLightHelper.prototype.update = function () {
  27158. var v1 = new Vector3();
  27159. var v2 = new Vector3();
  27160. var v3 = new Vector3();
  27161. return function update() {
  27162. v1.setFromMatrixPosition( this.light.matrixWorld );
  27163. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27164. v3.subVectors( v2, v1 );
  27165. this.lightPlane.lookAt( v2 );
  27166. if ( this.color !== undefined ) {
  27167. this.lightPlane.material.color.set( this.color );
  27168. this.targetLine.material.color.set( this.color );
  27169. } else {
  27170. this.lightPlane.material.color.copy( this.light.color );
  27171. this.targetLine.material.color.copy( this.light.color );
  27172. }
  27173. this.targetLine.lookAt( v2 );
  27174. this.targetLine.scale.z = v3.length();
  27175. };
  27176. }();
  27177. /**
  27178. * @author alteredq / http://alteredqualia.com/
  27179. * @author Mugen87 / https://github.com/Mugen87
  27180. *
  27181. * - shows frustum, line of sight and up of the camera
  27182. * - suitable for fast updates
  27183. * - based on frustum visualization in lightgl.js shadowmap example
  27184. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27185. */
  27186. function CameraHelper( camera ) {
  27187. var geometry = new BufferGeometry();
  27188. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27189. var vertices = [];
  27190. var colors = [];
  27191. var pointMap = {};
  27192. // colors
  27193. var colorFrustum = new Color( 0xffaa00 );
  27194. var colorCone = new Color( 0xff0000 );
  27195. var colorUp = new Color( 0x00aaff );
  27196. var colorTarget = new Color( 0xffffff );
  27197. var colorCross = new Color( 0x333333 );
  27198. // near
  27199. addLine( 'n1', 'n2', colorFrustum );
  27200. addLine( 'n2', 'n4', colorFrustum );
  27201. addLine( 'n4', 'n3', colorFrustum );
  27202. addLine( 'n3', 'n1', colorFrustum );
  27203. // far
  27204. addLine( 'f1', 'f2', colorFrustum );
  27205. addLine( 'f2', 'f4', colorFrustum );
  27206. addLine( 'f4', 'f3', colorFrustum );
  27207. addLine( 'f3', 'f1', colorFrustum );
  27208. // sides
  27209. addLine( 'n1', 'f1', colorFrustum );
  27210. addLine( 'n2', 'f2', colorFrustum );
  27211. addLine( 'n3', 'f3', colorFrustum );
  27212. addLine( 'n4', 'f4', colorFrustum );
  27213. // cone
  27214. addLine( 'p', 'n1', colorCone );
  27215. addLine( 'p', 'n2', colorCone );
  27216. addLine( 'p', 'n3', colorCone );
  27217. addLine( 'p', 'n4', colorCone );
  27218. // up
  27219. addLine( 'u1', 'u2', colorUp );
  27220. addLine( 'u2', 'u3', colorUp );
  27221. addLine( 'u3', 'u1', colorUp );
  27222. // target
  27223. addLine( 'c', 't', colorTarget );
  27224. addLine( 'p', 'c', colorCross );
  27225. // cross
  27226. addLine( 'cn1', 'cn2', colorCross );
  27227. addLine( 'cn3', 'cn4', colorCross );
  27228. addLine( 'cf1', 'cf2', colorCross );
  27229. addLine( 'cf3', 'cf4', colorCross );
  27230. function addLine( a, b, color ) {
  27231. addPoint( a, color );
  27232. addPoint( b, color );
  27233. }
  27234. function addPoint( id, color ) {
  27235. vertices.push( 0, 0, 0 );
  27236. colors.push( color.r, color.g, color.b );
  27237. if ( pointMap[ id ] === undefined ) {
  27238. pointMap[ id ] = [];
  27239. }
  27240. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27241. }
  27242. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27243. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27244. LineSegments.call( this, geometry, material );
  27245. this.camera = camera;
  27246. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27247. this.matrix = camera.matrixWorld;
  27248. this.matrixAutoUpdate = false;
  27249. this.pointMap = pointMap;
  27250. this.update();
  27251. }
  27252. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27253. CameraHelper.prototype.constructor = CameraHelper;
  27254. CameraHelper.prototype.update = function () {
  27255. var geometry, pointMap;
  27256. var vector = new Vector3();
  27257. var camera = new Camera();
  27258. function setPoint( point, x, y, z ) {
  27259. vector.set( x, y, z ).unproject( camera );
  27260. var points = pointMap[ point ];
  27261. if ( points !== undefined ) {
  27262. var position = geometry.getAttribute( 'position' );
  27263. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27264. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27265. }
  27266. }
  27267. }
  27268. return function update() {
  27269. geometry = this.geometry;
  27270. pointMap = this.pointMap;
  27271. var w = 1, h = 1;
  27272. // we need just camera projection matrix inverse
  27273. // world matrix must be identity
  27274. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27275. // center / target
  27276. setPoint( 'c', 0, 0, - 1 );
  27277. setPoint( 't', 0, 0, 1 );
  27278. // near
  27279. setPoint( 'n1', - w, - h, - 1 );
  27280. setPoint( 'n2', w, - h, - 1 );
  27281. setPoint( 'n3', - w, h, - 1 );
  27282. setPoint( 'n4', w, h, - 1 );
  27283. // far
  27284. setPoint( 'f1', - w, - h, 1 );
  27285. setPoint( 'f2', w, - h, 1 );
  27286. setPoint( 'f3', - w, h, 1 );
  27287. setPoint( 'f4', w, h, 1 );
  27288. // up
  27289. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27290. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27291. setPoint( 'u3', 0, h * 2, - 1 );
  27292. // cross
  27293. setPoint( 'cf1', - w, 0, 1 );
  27294. setPoint( 'cf2', w, 0, 1 );
  27295. setPoint( 'cf3', 0, - h, 1 );
  27296. setPoint( 'cf4', 0, h, 1 );
  27297. setPoint( 'cn1', - w, 0, - 1 );
  27298. setPoint( 'cn2', w, 0, - 1 );
  27299. setPoint( 'cn3', 0, - h, - 1 );
  27300. setPoint( 'cn4', 0, h, - 1 );
  27301. geometry.getAttribute( 'position' ).needsUpdate = true;
  27302. };
  27303. }();
  27304. /**
  27305. * @author mrdoob / http://mrdoob.com/
  27306. * @author Mugen87 / http://github.com/Mugen87
  27307. */
  27308. function BoxHelper( object, color ) {
  27309. this.object = object;
  27310. if ( color === undefined ) color = 0xffff00;
  27311. 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 ] );
  27312. var positions = new Float32Array( 8 * 3 );
  27313. var geometry = new BufferGeometry();
  27314. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27315. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27316. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27317. this.matrixAutoUpdate = false;
  27318. this.update();
  27319. }
  27320. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27321. BoxHelper.prototype.constructor = BoxHelper;
  27322. BoxHelper.prototype.update = ( function () {
  27323. var box = new Box3();
  27324. return function update( object ) {
  27325. if ( object !== undefined ) {
  27326. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27327. }
  27328. if ( this.object !== undefined ) {
  27329. box.setFromObject( this.object );
  27330. }
  27331. if ( box.isEmpty() ) return;
  27332. var min = box.min;
  27333. var max = box.max;
  27334. /*
  27335. 5____4
  27336. 1/___0/|
  27337. | 6__|_7
  27338. 2/___3/
  27339. 0: max.x, max.y, max.z
  27340. 1: min.x, max.y, max.z
  27341. 2: min.x, min.y, max.z
  27342. 3: max.x, min.y, max.z
  27343. 4: max.x, max.y, min.z
  27344. 5: min.x, max.y, min.z
  27345. 6: min.x, min.y, min.z
  27346. 7: max.x, min.y, min.z
  27347. */
  27348. var position = this.geometry.attributes.position;
  27349. var array = position.array;
  27350. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27351. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27352. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27353. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27354. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27355. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27356. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27357. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27358. position.needsUpdate = true;
  27359. this.geometry.computeBoundingSphere();
  27360. };
  27361. } )();
  27362. BoxHelper.prototype.setFromObject = function ( object ) {
  27363. this.object = object;
  27364. this.update();
  27365. return this;
  27366. };
  27367. BoxHelper.prototype.copy = function ( source ) {
  27368. LineSegments.prototype.copy.call( this, source );
  27369. this.object = source.object;
  27370. return this;
  27371. };
  27372. BoxHelper.prototype.clone = function () {
  27373. return new this.constructor().copy( this );
  27374. };
  27375. /**
  27376. * @author WestLangley / http://github.com/WestLangley
  27377. */
  27378. function Box3Helper( box, hex ) {
  27379. this.type = 'Box3Helper';
  27380. this.box = box;
  27381. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27382. 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 ] );
  27383. 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 ];
  27384. var geometry = new BufferGeometry();
  27385. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27386. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27387. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27388. this.geometry.computeBoundingSphere();
  27389. }
  27390. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27391. Box3Helper.prototype.constructor = Box3Helper;
  27392. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27393. var box = this.box;
  27394. if ( box.isEmpty() ) return;
  27395. box.getCenter( this.position );
  27396. box.getSize( this.scale );
  27397. this.scale.multiplyScalar( 0.5 );
  27398. Object3D.prototype.updateMatrixWorld.call( this, force );
  27399. };
  27400. /**
  27401. * @author WestLangley / http://github.com/WestLangley
  27402. */
  27403. function PlaneHelper( plane, size, hex ) {
  27404. this.type = 'PlaneHelper';
  27405. this.plane = plane;
  27406. this.size = ( size === undefined ) ? 1 : size;
  27407. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27408. 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 ];
  27409. var geometry = new BufferGeometry();
  27410. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27411. geometry.computeBoundingSphere();
  27412. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27413. //
  27414. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27415. var geometry2 = new BufferGeometry();
  27416. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27417. geometry2.computeBoundingSphere();
  27418. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27419. }
  27420. PlaneHelper.prototype = Object.create( Line.prototype );
  27421. PlaneHelper.prototype.constructor = PlaneHelper;
  27422. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27423. var scale = - this.plane.constant;
  27424. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27425. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27426. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27427. this.lookAt( this.plane.normal );
  27428. Object3D.prototype.updateMatrixWorld.call( this, force );
  27429. };
  27430. /**
  27431. * @author WestLangley / http://github.com/WestLangley
  27432. * @author zz85 / http://github.com/zz85
  27433. * @author bhouston / http://clara.io
  27434. *
  27435. * Creates an arrow for visualizing directions
  27436. *
  27437. * Parameters:
  27438. * dir - Vector3
  27439. * origin - Vector3
  27440. * length - Number
  27441. * color - color in hex value
  27442. * headLength - Number
  27443. * headWidth - Number
  27444. */
  27445. var lineGeometry, coneGeometry;
  27446. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27447. // dir is assumed to be normalized
  27448. Object3D.call( this );
  27449. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27450. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27451. if ( length === undefined ) length = 1;
  27452. if ( color === undefined ) color = 0xffff00;
  27453. if ( headLength === undefined ) headLength = 0.2 * length;
  27454. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27455. if ( lineGeometry === undefined ) {
  27456. lineGeometry = new BufferGeometry();
  27457. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27458. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27459. coneGeometry.translate( 0, - 0.5, 0 );
  27460. }
  27461. this.position.copy( origin );
  27462. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27463. this.line.matrixAutoUpdate = false;
  27464. this.add( this.line );
  27465. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27466. this.cone.matrixAutoUpdate = false;
  27467. this.add( this.cone );
  27468. this.setDirection( dir );
  27469. this.setLength( length, headLength, headWidth );
  27470. }
  27471. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27472. ArrowHelper.prototype.constructor = ArrowHelper;
  27473. ArrowHelper.prototype.setDirection = ( function () {
  27474. var axis = new Vector3();
  27475. var radians;
  27476. return function setDirection( dir ) {
  27477. // dir is assumed to be normalized
  27478. if ( dir.y > 0.99999 ) {
  27479. this.quaternion.set( 0, 0, 0, 1 );
  27480. } else if ( dir.y < - 0.99999 ) {
  27481. this.quaternion.set( 1, 0, 0, 0 );
  27482. } else {
  27483. axis.set( dir.z, 0, - dir.x ).normalize();
  27484. radians = Math.acos( dir.y );
  27485. this.quaternion.setFromAxisAngle( axis, radians );
  27486. }
  27487. };
  27488. }() );
  27489. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27490. if ( headLength === undefined ) headLength = 0.2 * length;
  27491. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27492. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27493. this.line.updateMatrix();
  27494. this.cone.scale.set( headWidth, headLength, headWidth );
  27495. this.cone.position.y = length;
  27496. this.cone.updateMatrix();
  27497. };
  27498. ArrowHelper.prototype.setColor = function ( color ) {
  27499. this.line.material.color.copy( color );
  27500. this.cone.material.color.copy( color );
  27501. };
  27502. ArrowHelper.prototype.copy = function ( source ) {
  27503. Object3D.prototype.copy.call( this, source, false );
  27504. this.line.copy( source.line );
  27505. this.cone.copy( source.cone );
  27506. return this;
  27507. };
  27508. ArrowHelper.prototype.clone = function () {
  27509. return new this.constructor().copy( this );
  27510. };
  27511. /**
  27512. * @author sroucheray / http://sroucheray.org/
  27513. * @author mrdoob / http://mrdoob.com/
  27514. */
  27515. function AxesHelper( size ) {
  27516. size = size || 1;
  27517. var vertices = [
  27518. 0, 0, 0, size, 0, 0,
  27519. 0, 0, 0, 0, size, 0,
  27520. 0, 0, 0, 0, 0, size
  27521. ];
  27522. var colors = [
  27523. 1, 0, 0, 1, 0.6, 0,
  27524. 0, 1, 0, 0.6, 1, 0,
  27525. 0, 0, 1, 0, 0.6, 1
  27526. ];
  27527. var geometry = new BufferGeometry();
  27528. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27529. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27530. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27531. LineSegments.call( this, geometry, material );
  27532. }
  27533. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27534. AxesHelper.prototype.constructor = AxesHelper;
  27535. /**
  27536. * @author mrdoob / http://mrdoob.com/
  27537. */
  27538. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27539. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27540. return new Face3( a, b, c, normal, color, materialIndex );
  27541. }
  27542. var LineStrip = 0;
  27543. var LinePieces = 1;
  27544. function MeshFaceMaterial( materials ) {
  27545. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27546. return materials;
  27547. }
  27548. function MultiMaterial( materials ) {
  27549. if ( materials === undefined ) materials = [];
  27550. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27551. materials.isMultiMaterial = true;
  27552. materials.materials = materials;
  27553. materials.clone = function () {
  27554. return materials.slice();
  27555. };
  27556. return materials;
  27557. }
  27558. function PointCloud( geometry, material ) {
  27559. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27560. return new Points( geometry, material );
  27561. }
  27562. function Particle( material ) {
  27563. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27564. return new Sprite( material );
  27565. }
  27566. function ParticleSystem( geometry, material ) {
  27567. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27568. return new Points( geometry, material );
  27569. }
  27570. function PointCloudMaterial( parameters ) {
  27571. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27572. return new PointsMaterial( parameters );
  27573. }
  27574. function ParticleBasicMaterial( parameters ) {
  27575. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27576. return new PointsMaterial( parameters );
  27577. }
  27578. function ParticleSystemMaterial( parameters ) {
  27579. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27580. return new PointsMaterial( parameters );
  27581. }
  27582. function Vertex( x, y, z ) {
  27583. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27584. return new Vector3( x, y, z );
  27585. }
  27586. //
  27587. function DynamicBufferAttribute( array, itemSize ) {
  27588. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27589. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27590. }
  27591. function Int8Attribute( array, itemSize ) {
  27592. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27593. return new Int8BufferAttribute( array, itemSize );
  27594. }
  27595. function Uint8Attribute( array, itemSize ) {
  27596. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27597. return new Uint8BufferAttribute( array, itemSize );
  27598. }
  27599. function Uint8ClampedAttribute( array, itemSize ) {
  27600. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27601. return new Uint8ClampedBufferAttribute( array, itemSize );
  27602. }
  27603. function Int16Attribute( array, itemSize ) {
  27604. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27605. return new Int16BufferAttribute( array, itemSize );
  27606. }
  27607. function Uint16Attribute( array, itemSize ) {
  27608. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27609. return new Uint16BufferAttribute( array, itemSize );
  27610. }
  27611. function Int32Attribute( array, itemSize ) {
  27612. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27613. return new Int32BufferAttribute( array, itemSize );
  27614. }
  27615. function Uint32Attribute( array, itemSize ) {
  27616. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27617. return new Uint32BufferAttribute( array, itemSize );
  27618. }
  27619. function Float32Attribute( array, itemSize ) {
  27620. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27621. return new Float32BufferAttribute( array, itemSize );
  27622. }
  27623. function Float64Attribute( array, itemSize ) {
  27624. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27625. return new Float64BufferAttribute( array, itemSize );
  27626. }
  27627. //
  27628. Curve.create = function ( construct, getPoint ) {
  27629. console.log( 'THREE.Curve.create() has been deprecated' );
  27630. construct.prototype = Object.create( Curve.prototype );
  27631. construct.prototype.constructor = construct;
  27632. construct.prototype.getPoint = getPoint;
  27633. return construct;
  27634. };
  27635. //
  27636. Object.assign( CurvePath.prototype, {
  27637. createPointsGeometry: function ( divisions ) {
  27638. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27639. // generate geometry from path points (for Line or Points objects)
  27640. var pts = this.getPoints( divisions );
  27641. return this.createGeometry( pts );
  27642. },
  27643. createSpacedPointsGeometry: function ( divisions ) {
  27644. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27645. // generate geometry from equidistant sampling along the path
  27646. var pts = this.getSpacedPoints( divisions );
  27647. return this.createGeometry( pts );
  27648. },
  27649. createGeometry: function ( points ) {
  27650. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27651. var geometry = new Geometry();
  27652. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27653. var point = points[ i ];
  27654. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  27655. }
  27656. return geometry;
  27657. }
  27658. } );
  27659. //
  27660. Object.assign( Path.prototype, {
  27661. fromPoints: function ( points ) {
  27662. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27663. this.setFromPoints( points );
  27664. }
  27665. } );
  27666. //
  27667. function ClosedSplineCurve3( points ) {
  27668. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27669. CatmullRomCurve3.call( this, points );
  27670. this.type = 'catmullrom';
  27671. this.closed = true;
  27672. }
  27673. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27674. //
  27675. function SplineCurve3( points ) {
  27676. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27677. CatmullRomCurve3.call( this, points );
  27678. this.type = 'catmullrom';
  27679. }
  27680. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27681. //
  27682. function Spline( points ) {
  27683. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  27684. CatmullRomCurve3.call( this, points );
  27685. this.type = 'catmullrom';
  27686. }
  27687. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  27688. Object.assign( Spline.prototype, {
  27689. initFromArray: function ( /* a */ ) {
  27690. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  27691. },
  27692. getControlPointsArray: function ( /* optionalTarget */ ) {
  27693. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  27694. },
  27695. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  27696. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  27697. }
  27698. } );
  27699. //
  27700. function AxisHelper( size ) {
  27701. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  27702. return new AxesHelper( size );
  27703. }
  27704. function BoundingBoxHelper( object, color ) {
  27705. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  27706. return new BoxHelper( object, color );
  27707. }
  27708. function EdgesHelper( object, hex ) {
  27709. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  27710. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27711. }
  27712. GridHelper.prototype.setColors = function () {
  27713. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  27714. };
  27715. SkeletonHelper.prototype.update = function () {
  27716. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  27717. };
  27718. function WireframeHelper( object, hex ) {
  27719. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  27720. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27721. }
  27722. //
  27723. Object.assign( Loader.prototype, {
  27724. extractUrlBase: function ( url ) {
  27725. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  27726. return LoaderUtils.extractUrlBase( url );
  27727. }
  27728. } );
  27729. function XHRLoader( manager ) {
  27730. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  27731. return new FileLoader( manager );
  27732. }
  27733. function BinaryTextureLoader( manager ) {
  27734. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  27735. return new DataTextureLoader( manager );
  27736. }
  27737. Object.assign( ObjectLoader.prototype, {
  27738. setTexturePath: function ( value ) {
  27739. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  27740. return this.setResourcePath( value );
  27741. }
  27742. } );
  27743. //
  27744. Object.assign( Box2.prototype, {
  27745. center: function ( optionalTarget ) {
  27746. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  27747. return this.getCenter( optionalTarget );
  27748. },
  27749. empty: function () {
  27750. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  27751. return this.isEmpty();
  27752. },
  27753. isIntersectionBox: function ( box ) {
  27754. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27755. return this.intersectsBox( box );
  27756. },
  27757. size: function ( optionalTarget ) {
  27758. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  27759. return this.getSize( optionalTarget );
  27760. }
  27761. } );
  27762. Object.assign( Box3.prototype, {
  27763. center: function ( optionalTarget ) {
  27764. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  27765. return this.getCenter( optionalTarget );
  27766. },
  27767. empty: function () {
  27768. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  27769. return this.isEmpty();
  27770. },
  27771. isIntersectionBox: function ( box ) {
  27772. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27773. return this.intersectsBox( box );
  27774. },
  27775. isIntersectionSphere: function ( sphere ) {
  27776. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27777. return this.intersectsSphere( sphere );
  27778. },
  27779. size: function ( optionalTarget ) {
  27780. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  27781. return this.getSize( optionalTarget );
  27782. }
  27783. } );
  27784. Line3.prototype.center = function ( optionalTarget ) {
  27785. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  27786. return this.getCenter( optionalTarget );
  27787. };
  27788. Object.assign( _Math, {
  27789. random16: function () {
  27790. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  27791. return Math.random();
  27792. },
  27793. nearestPowerOfTwo: function ( value ) {
  27794. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  27795. return _Math.floorPowerOfTwo( value );
  27796. },
  27797. nextPowerOfTwo: function ( value ) {
  27798. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  27799. return _Math.ceilPowerOfTwo( value );
  27800. }
  27801. } );
  27802. Object.assign( Matrix3.prototype, {
  27803. flattenToArrayOffset: function ( array, offset ) {
  27804. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27805. return this.toArray( array, offset );
  27806. },
  27807. multiplyVector3: function ( vector ) {
  27808. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  27809. return vector.applyMatrix3( this );
  27810. },
  27811. multiplyVector3Array: function ( /* a */ ) {
  27812. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  27813. },
  27814. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27815. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27816. return this.applyToBufferAttribute( buffer );
  27817. },
  27818. applyToVector3Array: function ( /* array, offset, length */ ) {
  27819. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  27820. }
  27821. } );
  27822. Object.assign( Matrix4.prototype, {
  27823. extractPosition: function ( m ) {
  27824. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  27825. return this.copyPosition( m );
  27826. },
  27827. flattenToArrayOffset: function ( array, offset ) {
  27828. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27829. return this.toArray( array, offset );
  27830. },
  27831. getPosition: function () {
  27832. var v1;
  27833. return function getPosition() {
  27834. if ( v1 === undefined ) v1 = new Vector3();
  27835. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  27836. return v1.setFromMatrixColumn( this, 3 );
  27837. };
  27838. }(),
  27839. setRotationFromQuaternion: function ( q ) {
  27840. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  27841. return this.makeRotationFromQuaternion( q );
  27842. },
  27843. multiplyToArray: function () {
  27844. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  27845. },
  27846. multiplyVector3: function ( vector ) {
  27847. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27848. return vector.applyMatrix4( this );
  27849. },
  27850. multiplyVector4: function ( vector ) {
  27851. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27852. return vector.applyMatrix4( this );
  27853. },
  27854. multiplyVector3Array: function ( /* a */ ) {
  27855. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  27856. },
  27857. rotateAxis: function ( v ) {
  27858. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  27859. v.transformDirection( this );
  27860. },
  27861. crossVector: function ( vector ) {
  27862. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27863. return vector.applyMatrix4( this );
  27864. },
  27865. translate: function () {
  27866. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  27867. },
  27868. rotateX: function () {
  27869. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  27870. },
  27871. rotateY: function () {
  27872. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  27873. },
  27874. rotateZ: function () {
  27875. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  27876. },
  27877. rotateByAxis: function () {
  27878. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  27879. },
  27880. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27881. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27882. return this.applyToBufferAttribute( buffer );
  27883. },
  27884. applyToVector3Array: function ( /* array, offset, length */ ) {
  27885. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  27886. },
  27887. makeFrustum: function ( left, right, bottom, top, near, far ) {
  27888. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  27889. return this.makePerspective( left, right, top, bottom, near, far );
  27890. }
  27891. } );
  27892. Plane.prototype.isIntersectionLine = function ( line ) {
  27893. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  27894. return this.intersectsLine( line );
  27895. };
  27896. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  27897. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  27898. return vector.applyQuaternion( this );
  27899. };
  27900. Object.assign( Ray.prototype, {
  27901. isIntersectionBox: function ( box ) {
  27902. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27903. return this.intersectsBox( box );
  27904. },
  27905. isIntersectionPlane: function ( plane ) {
  27906. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  27907. return this.intersectsPlane( plane );
  27908. },
  27909. isIntersectionSphere: function ( sphere ) {
  27910. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27911. return this.intersectsSphere( sphere );
  27912. }
  27913. } );
  27914. Object.assign( Triangle.prototype, {
  27915. area: function () {
  27916. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  27917. return this.getArea();
  27918. },
  27919. barycoordFromPoint: function ( point, target ) {
  27920. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27921. return this.getBarycoord( point, target );
  27922. },
  27923. midpoint: function ( target ) {
  27924. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  27925. return this.getMidpoint( target );
  27926. },
  27927. normal: function ( target ) {
  27928. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27929. return this.getNormal( target );
  27930. },
  27931. plane: function ( target ) {
  27932. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  27933. return this.getPlane( target );
  27934. }
  27935. } );
  27936. Object.assign( Triangle, {
  27937. barycoordFromPoint: function ( point, a, b, c, target ) {
  27938. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27939. return Triangle.getBarycoord( point, a, b, c, target );
  27940. },
  27941. normal: function ( a, b, c, target ) {
  27942. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27943. return Triangle.getNormal( a, b, c, target );
  27944. }
  27945. } );
  27946. Object.assign( Shape.prototype, {
  27947. extractAllPoints: function ( divisions ) {
  27948. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  27949. return this.extractPoints( divisions );
  27950. },
  27951. extrude: function ( options ) {
  27952. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  27953. return new ExtrudeGeometry( this, options );
  27954. },
  27955. makeGeometry: function ( options ) {
  27956. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  27957. return new ShapeGeometry( this, options );
  27958. }
  27959. } );
  27960. Object.assign( Vector2.prototype, {
  27961. fromAttribute: function ( attribute, index, offset ) {
  27962. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27963. return this.fromBufferAttribute( attribute, index, offset );
  27964. },
  27965. distanceToManhattan: function ( v ) {
  27966. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27967. return this.manhattanDistanceTo( v );
  27968. },
  27969. lengthManhattan: function () {
  27970. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  27971. return this.manhattanLength();
  27972. }
  27973. } );
  27974. Object.assign( Vector3.prototype, {
  27975. setEulerFromRotationMatrix: function () {
  27976. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  27977. },
  27978. setEulerFromQuaternion: function () {
  27979. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  27980. },
  27981. getPositionFromMatrix: function ( m ) {
  27982. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  27983. return this.setFromMatrixPosition( m );
  27984. },
  27985. getScaleFromMatrix: function ( m ) {
  27986. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  27987. return this.setFromMatrixScale( m );
  27988. },
  27989. getColumnFromMatrix: function ( index, matrix ) {
  27990. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  27991. return this.setFromMatrixColumn( matrix, index );
  27992. },
  27993. applyProjection: function ( m ) {
  27994. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  27995. return this.applyMatrix4( m );
  27996. },
  27997. fromAttribute: function ( attribute, index, offset ) {
  27998. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27999. return this.fromBufferAttribute( attribute, index, offset );
  28000. },
  28001. distanceToManhattan: function ( v ) {
  28002. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28003. return this.manhattanDistanceTo( v );
  28004. },
  28005. lengthManhattan: function () {
  28006. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28007. return this.manhattanLength();
  28008. }
  28009. } );
  28010. Object.assign( Vector4.prototype, {
  28011. fromAttribute: function ( attribute, index, offset ) {
  28012. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28013. return this.fromBufferAttribute( attribute, index, offset );
  28014. },
  28015. lengthManhattan: function () {
  28016. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28017. return this.manhattanLength();
  28018. }
  28019. } );
  28020. //
  28021. Object.assign( Geometry.prototype, {
  28022. computeTangents: function () {
  28023. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28024. },
  28025. computeLineDistances: function () {
  28026. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28027. }
  28028. } );
  28029. Object.assign( Object3D.prototype, {
  28030. getChildByName: function ( name ) {
  28031. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28032. return this.getObjectByName( name );
  28033. },
  28034. renderDepth: function () {
  28035. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28036. },
  28037. translate: function ( distance, axis ) {
  28038. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28039. return this.translateOnAxis( axis, distance );
  28040. },
  28041. getWorldRotation: function () {
  28042. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28043. }
  28044. } );
  28045. Object.defineProperties( Object3D.prototype, {
  28046. eulerOrder: {
  28047. get: function () {
  28048. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28049. return this.rotation.order;
  28050. },
  28051. set: function ( value ) {
  28052. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28053. this.rotation.order = value;
  28054. }
  28055. },
  28056. useQuaternion: {
  28057. get: function () {
  28058. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28059. },
  28060. set: function () {
  28061. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28062. }
  28063. }
  28064. } );
  28065. Object.defineProperties( LOD.prototype, {
  28066. objects: {
  28067. get: function () {
  28068. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28069. return this.levels;
  28070. }
  28071. }
  28072. } );
  28073. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28074. get: function () {
  28075. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28076. },
  28077. set: function () {
  28078. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28079. }
  28080. } );
  28081. SkinnedMesh.prototype.initBones = function () {
  28082. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28083. };
  28084. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28085. get: function () {
  28086. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28087. return this.arcLengthDivisions;
  28088. },
  28089. set: function ( value ) {
  28090. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28091. this.arcLengthDivisions = value;
  28092. }
  28093. } );
  28094. //
  28095. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28096. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28097. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28098. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28099. this.setFocalLength( focalLength );
  28100. };
  28101. //
  28102. Object.defineProperties( Light.prototype, {
  28103. onlyShadow: {
  28104. set: function () {
  28105. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28106. }
  28107. },
  28108. shadowCameraFov: {
  28109. set: function ( value ) {
  28110. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28111. this.shadow.camera.fov = value;
  28112. }
  28113. },
  28114. shadowCameraLeft: {
  28115. set: function ( value ) {
  28116. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28117. this.shadow.camera.left = value;
  28118. }
  28119. },
  28120. shadowCameraRight: {
  28121. set: function ( value ) {
  28122. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28123. this.shadow.camera.right = value;
  28124. }
  28125. },
  28126. shadowCameraTop: {
  28127. set: function ( value ) {
  28128. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28129. this.shadow.camera.top = value;
  28130. }
  28131. },
  28132. shadowCameraBottom: {
  28133. set: function ( value ) {
  28134. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28135. this.shadow.camera.bottom = value;
  28136. }
  28137. },
  28138. shadowCameraNear: {
  28139. set: function ( value ) {
  28140. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28141. this.shadow.camera.near = value;
  28142. }
  28143. },
  28144. shadowCameraFar: {
  28145. set: function ( value ) {
  28146. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28147. this.shadow.camera.far = value;
  28148. }
  28149. },
  28150. shadowCameraVisible: {
  28151. set: function () {
  28152. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28153. }
  28154. },
  28155. shadowBias: {
  28156. set: function ( value ) {
  28157. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28158. this.shadow.bias = value;
  28159. }
  28160. },
  28161. shadowDarkness: {
  28162. set: function () {
  28163. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28164. }
  28165. },
  28166. shadowMapWidth: {
  28167. set: function ( value ) {
  28168. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28169. this.shadow.mapSize.width = value;
  28170. }
  28171. },
  28172. shadowMapHeight: {
  28173. set: function ( value ) {
  28174. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28175. this.shadow.mapSize.height = value;
  28176. }
  28177. }
  28178. } );
  28179. //
  28180. Object.defineProperties( BufferAttribute.prototype, {
  28181. length: {
  28182. get: function () {
  28183. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28184. return this.array.length;
  28185. }
  28186. },
  28187. copyIndicesArray: function ( /* indices */ ) {
  28188. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28189. }
  28190. } );
  28191. Object.assign( BufferGeometry.prototype, {
  28192. addIndex: function ( index ) {
  28193. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28194. this.setIndex( index );
  28195. },
  28196. addDrawCall: function ( start, count, indexOffset ) {
  28197. if ( indexOffset !== undefined ) {
  28198. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28199. }
  28200. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28201. this.addGroup( start, count );
  28202. },
  28203. clearDrawCalls: function () {
  28204. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28205. this.clearGroups();
  28206. },
  28207. computeTangents: function () {
  28208. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28209. },
  28210. computeOffsets: function () {
  28211. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28212. }
  28213. } );
  28214. Object.defineProperties( BufferGeometry.prototype, {
  28215. drawcalls: {
  28216. get: function () {
  28217. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28218. return this.groups;
  28219. }
  28220. },
  28221. offsets: {
  28222. get: function () {
  28223. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28224. return this.groups;
  28225. }
  28226. }
  28227. } );
  28228. //
  28229. Object.assign( ExtrudeBufferGeometry.prototype, {
  28230. getArrays: function () {
  28231. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28232. },
  28233. addShapeList: function () {
  28234. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28235. },
  28236. addShape: function () {
  28237. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28238. }
  28239. } );
  28240. //
  28241. Object.defineProperties( Uniform.prototype, {
  28242. dynamic: {
  28243. set: function () {
  28244. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28245. }
  28246. },
  28247. onUpdate: {
  28248. value: function () {
  28249. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28250. return this;
  28251. }
  28252. }
  28253. } );
  28254. //
  28255. Object.defineProperties( Material.prototype, {
  28256. wrapAround: {
  28257. get: function () {
  28258. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28259. },
  28260. set: function () {
  28261. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28262. }
  28263. },
  28264. overdraw: {
  28265. get: function () {
  28266. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28267. },
  28268. set: function () {
  28269. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28270. }
  28271. },
  28272. wrapRGB: {
  28273. get: function () {
  28274. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28275. return new Color();
  28276. }
  28277. },
  28278. shading: {
  28279. get: function () {
  28280. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28281. },
  28282. set: function ( value ) {
  28283. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28284. this.flatShading = ( value === FlatShading );
  28285. }
  28286. }
  28287. } );
  28288. Object.defineProperties( MeshPhongMaterial.prototype, {
  28289. metal: {
  28290. get: function () {
  28291. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28292. return false;
  28293. },
  28294. set: function () {
  28295. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28296. }
  28297. }
  28298. } );
  28299. Object.defineProperties( ShaderMaterial.prototype, {
  28300. derivatives: {
  28301. get: function () {
  28302. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28303. return this.extensions.derivatives;
  28304. },
  28305. set: function ( value ) {
  28306. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28307. this.extensions.derivatives = value;
  28308. }
  28309. }
  28310. } );
  28311. //
  28312. Object.assign( WebGLRenderer.prototype, {
  28313. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28314. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28315. this.setRenderTarget( renderTarget );
  28316. this.clear( color, depth, stencil );
  28317. },
  28318. animate: function ( callback ) {
  28319. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28320. this.setAnimationLoop( callback );
  28321. },
  28322. getCurrentRenderTarget: function () {
  28323. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28324. return this.getRenderTarget();
  28325. },
  28326. getMaxAnisotropy: function () {
  28327. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28328. return this.capabilities.getMaxAnisotropy();
  28329. },
  28330. getPrecision: function () {
  28331. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28332. return this.capabilities.precision;
  28333. },
  28334. resetGLState: function () {
  28335. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28336. return this.state.reset();
  28337. },
  28338. supportsFloatTextures: function () {
  28339. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28340. return this.extensions.get( 'OES_texture_float' );
  28341. },
  28342. supportsHalfFloatTextures: function () {
  28343. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28344. return this.extensions.get( 'OES_texture_half_float' );
  28345. },
  28346. supportsStandardDerivatives: function () {
  28347. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28348. return this.extensions.get( 'OES_standard_derivatives' );
  28349. },
  28350. supportsCompressedTextureS3TC: function () {
  28351. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28352. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28353. },
  28354. supportsCompressedTexturePVRTC: function () {
  28355. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28356. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28357. },
  28358. supportsBlendMinMax: function () {
  28359. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28360. return this.extensions.get( 'EXT_blend_minmax' );
  28361. },
  28362. supportsVertexTextures: function () {
  28363. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28364. return this.capabilities.vertexTextures;
  28365. },
  28366. supportsInstancedArrays: function () {
  28367. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28368. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28369. },
  28370. enableScissorTest: function ( boolean ) {
  28371. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28372. this.setScissorTest( boolean );
  28373. },
  28374. initMaterial: function () {
  28375. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28376. },
  28377. addPrePlugin: function () {
  28378. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28379. },
  28380. addPostPlugin: function () {
  28381. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28382. },
  28383. updateShadowMap: function () {
  28384. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28385. },
  28386. setFaceCulling: function () {
  28387. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28388. },
  28389. allocTextureUnit: function () {
  28390. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28391. },
  28392. setTexture: function () {
  28393. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28394. },
  28395. setTexture2D: function () {
  28396. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28397. },
  28398. setTextureCube: function () {
  28399. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28400. }
  28401. } );
  28402. Object.defineProperties( WebGLRenderer.prototype, {
  28403. shadowMapEnabled: {
  28404. get: function () {
  28405. return this.shadowMap.enabled;
  28406. },
  28407. set: function ( value ) {
  28408. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28409. this.shadowMap.enabled = value;
  28410. }
  28411. },
  28412. shadowMapType: {
  28413. get: function () {
  28414. return this.shadowMap.type;
  28415. },
  28416. set: function ( value ) {
  28417. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28418. this.shadowMap.type = value;
  28419. }
  28420. },
  28421. shadowMapCullFace: {
  28422. get: function () {
  28423. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28424. return undefined;
  28425. },
  28426. set: function ( /* value */ ) {
  28427. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28428. }
  28429. }
  28430. } );
  28431. Object.defineProperties( WebGLShadowMap.prototype, {
  28432. cullFace: {
  28433. get: function () {
  28434. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28435. return undefined;
  28436. },
  28437. set: function ( /* cullFace */ ) {
  28438. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28439. }
  28440. },
  28441. renderReverseSided: {
  28442. get: function () {
  28443. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28444. return undefined;
  28445. },
  28446. set: function () {
  28447. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28448. }
  28449. },
  28450. renderSingleSided: {
  28451. get: function () {
  28452. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28453. return undefined;
  28454. },
  28455. set: function () {
  28456. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28457. }
  28458. }
  28459. } );
  28460. //
  28461. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  28462. activeCubeFace: {
  28463. set: function ( /* value */ ) {
  28464. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  28465. }
  28466. },
  28467. activeMipMapLevel: {
  28468. set: function ( /* value */ ) {
  28469. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  28470. }
  28471. }
  28472. } );
  28473. //
  28474. Object.defineProperties( WebGLRenderTarget.prototype, {
  28475. wrapS: {
  28476. get: function () {
  28477. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28478. return this.texture.wrapS;
  28479. },
  28480. set: function ( value ) {
  28481. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28482. this.texture.wrapS = value;
  28483. }
  28484. },
  28485. wrapT: {
  28486. get: function () {
  28487. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28488. return this.texture.wrapT;
  28489. },
  28490. set: function ( value ) {
  28491. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28492. this.texture.wrapT = value;
  28493. }
  28494. },
  28495. magFilter: {
  28496. get: function () {
  28497. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28498. return this.texture.magFilter;
  28499. },
  28500. set: function ( value ) {
  28501. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28502. this.texture.magFilter = value;
  28503. }
  28504. },
  28505. minFilter: {
  28506. get: function () {
  28507. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28508. return this.texture.minFilter;
  28509. },
  28510. set: function ( value ) {
  28511. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28512. this.texture.minFilter = value;
  28513. }
  28514. },
  28515. anisotropy: {
  28516. get: function () {
  28517. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28518. return this.texture.anisotropy;
  28519. },
  28520. set: function ( value ) {
  28521. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28522. this.texture.anisotropy = value;
  28523. }
  28524. },
  28525. offset: {
  28526. get: function () {
  28527. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28528. return this.texture.offset;
  28529. },
  28530. set: function ( value ) {
  28531. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28532. this.texture.offset = value;
  28533. }
  28534. },
  28535. repeat: {
  28536. get: function () {
  28537. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28538. return this.texture.repeat;
  28539. },
  28540. set: function ( value ) {
  28541. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28542. this.texture.repeat = value;
  28543. }
  28544. },
  28545. format: {
  28546. get: function () {
  28547. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28548. return this.texture.format;
  28549. },
  28550. set: function ( value ) {
  28551. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28552. this.texture.format = value;
  28553. }
  28554. },
  28555. type: {
  28556. get: function () {
  28557. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28558. return this.texture.type;
  28559. },
  28560. set: function ( value ) {
  28561. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28562. this.texture.type = value;
  28563. }
  28564. },
  28565. generateMipmaps: {
  28566. get: function () {
  28567. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28568. return this.texture.generateMipmaps;
  28569. },
  28570. set: function ( value ) {
  28571. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28572. this.texture.generateMipmaps = value;
  28573. }
  28574. }
  28575. } );
  28576. //
  28577. Object.defineProperties( WebVRManager.prototype, {
  28578. standing: {
  28579. set: function ( /* value */ ) {
  28580. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28581. }
  28582. },
  28583. userHeight: {
  28584. set: function ( /* value */ ) {
  28585. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28586. }
  28587. }
  28588. } );
  28589. //
  28590. Audio.prototype.load = function ( file ) {
  28591. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28592. var scope = this;
  28593. var audioLoader = new AudioLoader();
  28594. audioLoader.load( file, function ( buffer ) {
  28595. scope.setBuffer( buffer );
  28596. } );
  28597. return this;
  28598. };
  28599. AudioAnalyser.prototype.getData = function () {
  28600. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28601. return this.getFrequencyData();
  28602. };
  28603. //
  28604. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28605. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28606. return this.update( renderer, scene );
  28607. };
  28608. //
  28609. var GeometryUtils = {
  28610. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  28611. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  28612. var matrix;
  28613. if ( geometry2.isMesh ) {
  28614. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  28615. matrix = geometry2.matrix;
  28616. geometry2 = geometry2.geometry;
  28617. }
  28618. geometry1.merge( geometry2, matrix, materialIndexOffset );
  28619. },
  28620. center: function ( geometry ) {
  28621. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  28622. return geometry.center();
  28623. }
  28624. };
  28625. ImageUtils.crossOrigin = undefined;
  28626. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  28627. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  28628. var loader = new TextureLoader();
  28629. loader.setCrossOrigin( this.crossOrigin );
  28630. var texture = loader.load( url, onLoad, undefined, onError );
  28631. if ( mapping ) texture.mapping = mapping;
  28632. return texture;
  28633. };
  28634. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  28635. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  28636. var loader = new CubeTextureLoader();
  28637. loader.setCrossOrigin( this.crossOrigin );
  28638. var texture = loader.load( urls, onLoad, undefined, onError );
  28639. if ( mapping ) texture.mapping = mapping;
  28640. return texture;
  28641. };
  28642. ImageUtils.loadCompressedTexture = function () {
  28643. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  28644. };
  28645. ImageUtils.loadCompressedTextureCube = function () {
  28646. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  28647. };
  28648. //
  28649. function Projector() {
  28650. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  28651. this.projectVector = function ( vector, camera ) {
  28652. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  28653. vector.project( camera );
  28654. };
  28655. this.unprojectVector = function ( vector, camera ) {
  28656. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  28657. vector.unproject( camera );
  28658. };
  28659. this.pickingRay = function () {
  28660. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  28661. };
  28662. }
  28663. //
  28664. function CanvasRenderer() {
  28665. console.error( 'THREE.CanvasRenderer has been removed' );
  28666. }
  28667. //
  28668. function JSONLoader() {
  28669. console.error( 'THREE.JSONLoader has been removed.' );
  28670. }
  28671. //
  28672. var SceneUtils = {
  28673. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  28674. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28675. },
  28676. detach: function ( /* child, parent, scene */ ) {
  28677. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28678. },
  28679. attach: function ( /* child, scene, parent */ ) {
  28680. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28681. }
  28682. };
  28683. //
  28684. function LensFlare() {
  28685. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  28686. }
  28687. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  28688. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  28689. exports.WebGLRenderTarget = WebGLRenderTarget;
  28690. exports.WebGLRenderer = WebGLRenderer;
  28691. exports.ShaderLib = ShaderLib;
  28692. exports.UniformsLib = UniformsLib;
  28693. exports.UniformsUtils = UniformsUtils;
  28694. exports.ShaderChunk = ShaderChunk;
  28695. exports.FogExp2 = FogExp2;
  28696. exports.Fog = Fog;
  28697. exports.Scene = Scene;
  28698. exports.Sprite = Sprite;
  28699. exports.LOD = LOD;
  28700. exports.SkinnedMesh = SkinnedMesh;
  28701. exports.Skeleton = Skeleton;
  28702. exports.Bone = Bone;
  28703. exports.Mesh = Mesh;
  28704. exports.LineSegments = LineSegments;
  28705. exports.LineLoop = LineLoop;
  28706. exports.Line = Line;
  28707. exports.Points = Points;
  28708. exports.Group = Group;
  28709. exports.VideoTexture = VideoTexture;
  28710. exports.DataTexture = DataTexture;
  28711. exports.DataTexture2DArray = DataTexture2DArray;
  28712. exports.DataTexture3D = DataTexture3D;
  28713. exports.CompressedTexture = CompressedTexture;
  28714. exports.CubeTexture = CubeTexture;
  28715. exports.CanvasTexture = CanvasTexture;
  28716. exports.DepthTexture = DepthTexture;
  28717. exports.Texture = Texture;
  28718. exports.AnimationLoader = AnimationLoader;
  28719. exports.CompressedTextureLoader = CompressedTextureLoader;
  28720. exports.DataTextureLoader = DataTextureLoader;
  28721. exports.CubeTextureLoader = CubeTextureLoader;
  28722. exports.TextureLoader = TextureLoader;
  28723. exports.ObjectLoader = ObjectLoader;
  28724. exports.MaterialLoader = MaterialLoader;
  28725. exports.BufferGeometryLoader = BufferGeometryLoader;
  28726. exports.DefaultLoadingManager = DefaultLoadingManager;
  28727. exports.LoadingManager = LoadingManager;
  28728. exports.ImageLoader = ImageLoader;
  28729. exports.ImageBitmapLoader = ImageBitmapLoader;
  28730. exports.FontLoader = FontLoader;
  28731. exports.FileLoader = FileLoader;
  28732. exports.Loader = Loader;
  28733. exports.LoaderUtils = LoaderUtils;
  28734. exports.Cache = Cache;
  28735. exports.AudioLoader = AudioLoader;
  28736. exports.SpotLightShadow = SpotLightShadow;
  28737. exports.SpotLight = SpotLight;
  28738. exports.PointLight = PointLight;
  28739. exports.RectAreaLight = RectAreaLight;
  28740. exports.HemisphereLight = HemisphereLight;
  28741. exports.DirectionalLightShadow = DirectionalLightShadow;
  28742. exports.DirectionalLight = DirectionalLight;
  28743. exports.AmbientLight = AmbientLight;
  28744. exports.LightShadow = LightShadow;
  28745. exports.Light = Light;
  28746. exports.StereoCamera = StereoCamera;
  28747. exports.PerspectiveCamera = PerspectiveCamera;
  28748. exports.OrthographicCamera = OrthographicCamera;
  28749. exports.CubeCamera = CubeCamera;
  28750. exports.ArrayCamera = ArrayCamera;
  28751. exports.Camera = Camera;
  28752. exports.AudioListener = AudioListener;
  28753. exports.PositionalAudio = PositionalAudio;
  28754. exports.AudioContext = AudioContext;
  28755. exports.AudioAnalyser = AudioAnalyser;
  28756. exports.Audio = Audio;
  28757. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  28758. exports.StringKeyframeTrack = StringKeyframeTrack;
  28759. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  28760. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  28761. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  28762. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  28763. exports.PropertyMixer = PropertyMixer;
  28764. exports.PropertyBinding = PropertyBinding;
  28765. exports.KeyframeTrack = KeyframeTrack;
  28766. exports.AnimationUtils = AnimationUtils;
  28767. exports.AnimationObjectGroup = AnimationObjectGroup;
  28768. exports.AnimationMixer = AnimationMixer;
  28769. exports.AnimationClip = AnimationClip;
  28770. exports.Uniform = Uniform;
  28771. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  28772. exports.BufferGeometry = BufferGeometry;
  28773. exports.Geometry = Geometry;
  28774. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  28775. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  28776. exports.InterleavedBuffer = InterleavedBuffer;
  28777. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  28778. exports.Face3 = Face3;
  28779. exports.Object3D = Object3D;
  28780. exports.Raycaster = Raycaster;
  28781. exports.Layers = Layers;
  28782. exports.EventDispatcher = EventDispatcher;
  28783. exports.Clock = Clock;
  28784. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  28785. exports.LinearInterpolant = LinearInterpolant;
  28786. exports.DiscreteInterpolant = DiscreteInterpolant;
  28787. exports.CubicInterpolant = CubicInterpolant;
  28788. exports.Interpolant = Interpolant;
  28789. exports.Triangle = Triangle;
  28790. exports.Math = _Math;
  28791. exports.Spherical = Spherical;
  28792. exports.Cylindrical = Cylindrical;
  28793. exports.Plane = Plane;
  28794. exports.Frustum = Frustum;
  28795. exports.Sphere = Sphere;
  28796. exports.Ray = Ray;
  28797. exports.Matrix4 = Matrix4;
  28798. exports.Matrix3 = Matrix3;
  28799. exports.Box3 = Box3;
  28800. exports.Box2 = Box2;
  28801. exports.Line3 = Line3;
  28802. exports.Euler = Euler;
  28803. exports.Vector4 = Vector4;
  28804. exports.Vector3 = Vector3;
  28805. exports.Vector2 = Vector2;
  28806. exports.Quaternion = Quaternion;
  28807. exports.Color = Color;
  28808. exports.ImmediateRenderObject = ImmediateRenderObject;
  28809. exports.VertexNormalsHelper = VertexNormalsHelper;
  28810. exports.SpotLightHelper = SpotLightHelper;
  28811. exports.SkeletonHelper = SkeletonHelper;
  28812. exports.PointLightHelper = PointLightHelper;
  28813. exports.RectAreaLightHelper = RectAreaLightHelper;
  28814. exports.HemisphereLightHelper = HemisphereLightHelper;
  28815. exports.GridHelper = GridHelper;
  28816. exports.PolarGridHelper = PolarGridHelper;
  28817. exports.PositionalAudioHelper = PositionalAudioHelper;
  28818. exports.FaceNormalsHelper = FaceNormalsHelper;
  28819. exports.DirectionalLightHelper = DirectionalLightHelper;
  28820. exports.CameraHelper = CameraHelper;
  28821. exports.BoxHelper = BoxHelper;
  28822. exports.Box3Helper = Box3Helper;
  28823. exports.PlaneHelper = PlaneHelper;
  28824. exports.ArrowHelper = ArrowHelper;
  28825. exports.AxesHelper = AxesHelper;
  28826. exports.Shape = Shape;
  28827. exports.Path = Path;
  28828. exports.ShapePath = ShapePath;
  28829. exports.Font = Font;
  28830. exports.CurvePath = CurvePath;
  28831. exports.Curve = Curve;
  28832. exports.ImageUtils = ImageUtils;
  28833. exports.ShapeUtils = ShapeUtils;
  28834. exports.WebGLUtils = WebGLUtils;
  28835. exports.WireframeGeometry = WireframeGeometry;
  28836. exports.ParametricGeometry = ParametricGeometry;
  28837. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  28838. exports.TetrahedronGeometry = TetrahedronGeometry;
  28839. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  28840. exports.OctahedronGeometry = OctahedronGeometry;
  28841. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  28842. exports.IcosahedronGeometry = IcosahedronGeometry;
  28843. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  28844. exports.DodecahedronGeometry = DodecahedronGeometry;
  28845. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  28846. exports.PolyhedronGeometry = PolyhedronGeometry;
  28847. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  28848. exports.TubeGeometry = TubeGeometry;
  28849. exports.TubeBufferGeometry = TubeBufferGeometry;
  28850. exports.TorusKnotGeometry = TorusKnotGeometry;
  28851. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  28852. exports.TorusGeometry = TorusGeometry;
  28853. exports.TorusBufferGeometry = TorusBufferGeometry;
  28854. exports.TextGeometry = TextGeometry;
  28855. exports.TextBufferGeometry = TextBufferGeometry;
  28856. exports.SphereGeometry = SphereGeometry;
  28857. exports.SphereBufferGeometry = SphereBufferGeometry;
  28858. exports.RingGeometry = RingGeometry;
  28859. exports.RingBufferGeometry = RingBufferGeometry;
  28860. exports.PlaneGeometry = PlaneGeometry;
  28861. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  28862. exports.LatheGeometry = LatheGeometry;
  28863. exports.LatheBufferGeometry = LatheBufferGeometry;
  28864. exports.ShapeGeometry = ShapeGeometry;
  28865. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  28866. exports.ExtrudeGeometry = ExtrudeGeometry;
  28867. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  28868. exports.EdgesGeometry = EdgesGeometry;
  28869. exports.ConeGeometry = ConeGeometry;
  28870. exports.ConeBufferGeometry = ConeBufferGeometry;
  28871. exports.CylinderGeometry = CylinderGeometry;
  28872. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  28873. exports.CircleGeometry = CircleGeometry;
  28874. exports.CircleBufferGeometry = CircleBufferGeometry;
  28875. exports.BoxGeometry = BoxGeometry;
  28876. exports.CubeGeometry = BoxGeometry;
  28877. exports.BoxBufferGeometry = BoxBufferGeometry;
  28878. exports.ShadowMaterial = ShadowMaterial;
  28879. exports.SpriteMaterial = SpriteMaterial;
  28880. exports.RawShaderMaterial = RawShaderMaterial;
  28881. exports.ShaderMaterial = ShaderMaterial;
  28882. exports.PointsMaterial = PointsMaterial;
  28883. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  28884. exports.MeshStandardMaterial = MeshStandardMaterial;
  28885. exports.MeshPhongMaterial = MeshPhongMaterial;
  28886. exports.MeshToonMaterial = MeshToonMaterial;
  28887. exports.MeshNormalMaterial = MeshNormalMaterial;
  28888. exports.MeshLambertMaterial = MeshLambertMaterial;
  28889. exports.MeshDepthMaterial = MeshDepthMaterial;
  28890. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  28891. exports.MeshBasicMaterial = MeshBasicMaterial;
  28892. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  28893. exports.LineDashedMaterial = LineDashedMaterial;
  28894. exports.LineBasicMaterial = LineBasicMaterial;
  28895. exports.Material = Material;
  28896. exports.Float64BufferAttribute = Float64BufferAttribute;
  28897. exports.Float32BufferAttribute = Float32BufferAttribute;
  28898. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  28899. exports.Int32BufferAttribute = Int32BufferAttribute;
  28900. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  28901. exports.Int16BufferAttribute = Int16BufferAttribute;
  28902. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  28903. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  28904. exports.Int8BufferAttribute = Int8BufferAttribute;
  28905. exports.BufferAttribute = BufferAttribute;
  28906. exports.ArcCurve = ArcCurve;
  28907. exports.CatmullRomCurve3 = CatmullRomCurve3;
  28908. exports.CubicBezierCurve = CubicBezierCurve;
  28909. exports.CubicBezierCurve3 = CubicBezierCurve3;
  28910. exports.EllipseCurve = EllipseCurve;
  28911. exports.LineCurve = LineCurve;
  28912. exports.LineCurve3 = LineCurve3;
  28913. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  28914. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  28915. exports.SplineCurve = SplineCurve;
  28916. exports.REVISION = REVISION;
  28917. exports.MOUSE = MOUSE;
  28918. exports.CullFaceNone = CullFaceNone;
  28919. exports.CullFaceBack = CullFaceBack;
  28920. exports.CullFaceFront = CullFaceFront;
  28921. exports.CullFaceFrontBack = CullFaceFrontBack;
  28922. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  28923. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  28924. exports.BasicShadowMap = BasicShadowMap;
  28925. exports.PCFShadowMap = PCFShadowMap;
  28926. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  28927. exports.FrontSide = FrontSide;
  28928. exports.BackSide = BackSide;
  28929. exports.DoubleSide = DoubleSide;
  28930. exports.FlatShading = FlatShading;
  28931. exports.SmoothShading = SmoothShading;
  28932. exports.NoColors = NoColors;
  28933. exports.FaceColors = FaceColors;
  28934. exports.VertexColors = VertexColors;
  28935. exports.NoBlending = NoBlending;
  28936. exports.NormalBlending = NormalBlending;
  28937. exports.AdditiveBlending = AdditiveBlending;
  28938. exports.SubtractiveBlending = SubtractiveBlending;
  28939. exports.MultiplyBlending = MultiplyBlending;
  28940. exports.CustomBlending = CustomBlending;
  28941. exports.AddEquation = AddEquation;
  28942. exports.SubtractEquation = SubtractEquation;
  28943. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  28944. exports.MinEquation = MinEquation;
  28945. exports.MaxEquation = MaxEquation;
  28946. exports.ZeroFactor = ZeroFactor;
  28947. exports.OneFactor = OneFactor;
  28948. exports.SrcColorFactor = SrcColorFactor;
  28949. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  28950. exports.SrcAlphaFactor = SrcAlphaFactor;
  28951. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  28952. exports.DstAlphaFactor = DstAlphaFactor;
  28953. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  28954. exports.DstColorFactor = DstColorFactor;
  28955. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  28956. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  28957. exports.NeverDepth = NeverDepth;
  28958. exports.AlwaysDepth = AlwaysDepth;
  28959. exports.LessDepth = LessDepth;
  28960. exports.LessEqualDepth = LessEqualDepth;
  28961. exports.EqualDepth = EqualDepth;
  28962. exports.GreaterEqualDepth = GreaterEqualDepth;
  28963. exports.GreaterDepth = GreaterDepth;
  28964. exports.NotEqualDepth = NotEqualDepth;
  28965. exports.MultiplyOperation = MultiplyOperation;
  28966. exports.MixOperation = MixOperation;
  28967. exports.AddOperation = AddOperation;
  28968. exports.NoToneMapping = NoToneMapping;
  28969. exports.LinearToneMapping = LinearToneMapping;
  28970. exports.ReinhardToneMapping = ReinhardToneMapping;
  28971. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  28972. exports.CineonToneMapping = CineonToneMapping;
  28973. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  28974. exports.UVMapping = UVMapping;
  28975. exports.CubeReflectionMapping = CubeReflectionMapping;
  28976. exports.CubeRefractionMapping = CubeRefractionMapping;
  28977. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  28978. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  28979. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  28980. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  28981. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  28982. exports.RepeatWrapping = RepeatWrapping;
  28983. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  28984. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  28985. exports.NearestFilter = NearestFilter;
  28986. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  28987. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  28988. exports.LinearFilter = LinearFilter;
  28989. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  28990. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  28991. exports.UnsignedByteType = UnsignedByteType;
  28992. exports.ByteType = ByteType;
  28993. exports.ShortType = ShortType;
  28994. exports.UnsignedShortType = UnsignedShortType;
  28995. exports.IntType = IntType;
  28996. exports.UnsignedIntType = UnsignedIntType;
  28997. exports.FloatType = FloatType;
  28998. exports.HalfFloatType = HalfFloatType;
  28999. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  29000. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  29001. exports.UnsignedShort565Type = UnsignedShort565Type;
  29002. exports.UnsignedInt248Type = UnsignedInt248Type;
  29003. exports.AlphaFormat = AlphaFormat;
  29004. exports.RGBFormat = RGBFormat;
  29005. exports.RGBAFormat = RGBAFormat;
  29006. exports.LuminanceFormat = LuminanceFormat;
  29007. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  29008. exports.RGBEFormat = RGBEFormat;
  29009. exports.DepthFormat = DepthFormat;
  29010. exports.DepthStencilFormat = DepthStencilFormat;
  29011. exports.RedFormat = RedFormat;
  29012. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  29013. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  29014. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  29015. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  29016. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  29017. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  29018. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  29019. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  29020. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  29021. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  29022. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  29023. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  29024. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  29025. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  29026. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  29027. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  29028. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  29029. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  29030. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  29031. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  29032. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  29033. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  29034. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  29035. exports.LoopOnce = LoopOnce;
  29036. exports.LoopRepeat = LoopRepeat;
  29037. exports.LoopPingPong = LoopPingPong;
  29038. exports.InterpolateDiscrete = InterpolateDiscrete;
  29039. exports.InterpolateLinear = InterpolateLinear;
  29040. exports.InterpolateSmooth = InterpolateSmooth;
  29041. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  29042. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  29043. exports.WrapAroundEnding = WrapAroundEnding;
  29044. exports.TrianglesDrawMode = TrianglesDrawMode;
  29045. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  29046. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  29047. exports.LinearEncoding = LinearEncoding;
  29048. exports.sRGBEncoding = sRGBEncoding;
  29049. exports.GammaEncoding = GammaEncoding;
  29050. exports.RGBEEncoding = RGBEEncoding;
  29051. exports.LogLuvEncoding = LogLuvEncoding;
  29052. exports.RGBM7Encoding = RGBM7Encoding;
  29053. exports.RGBM16Encoding = RGBM16Encoding;
  29054. exports.RGBDEncoding = RGBDEncoding;
  29055. exports.BasicDepthPacking = BasicDepthPacking;
  29056. exports.RGBADepthPacking = RGBADepthPacking;
  29057. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  29058. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  29059. exports.Face4 = Face4;
  29060. exports.LineStrip = LineStrip;
  29061. exports.LinePieces = LinePieces;
  29062. exports.MeshFaceMaterial = MeshFaceMaterial;
  29063. exports.MultiMaterial = MultiMaterial;
  29064. exports.PointCloud = PointCloud;
  29065. exports.Particle = Particle;
  29066. exports.ParticleSystem = ParticleSystem;
  29067. exports.PointCloudMaterial = PointCloudMaterial;
  29068. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  29069. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  29070. exports.Vertex = Vertex;
  29071. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  29072. exports.Int8Attribute = Int8Attribute;
  29073. exports.Uint8Attribute = Uint8Attribute;
  29074. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  29075. exports.Int16Attribute = Int16Attribute;
  29076. exports.Uint16Attribute = Uint16Attribute;
  29077. exports.Int32Attribute = Int32Attribute;
  29078. exports.Uint32Attribute = Uint32Attribute;
  29079. exports.Float32Attribute = Float32Attribute;
  29080. exports.Float64Attribute = Float64Attribute;
  29081. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  29082. exports.SplineCurve3 = SplineCurve3;
  29083. exports.Spline = Spline;
  29084. exports.AxisHelper = AxisHelper;
  29085. exports.BoundingBoxHelper = BoundingBoxHelper;
  29086. exports.EdgesHelper = EdgesHelper;
  29087. exports.WireframeHelper = WireframeHelper;
  29088. exports.XHRLoader = XHRLoader;
  29089. exports.BinaryTextureLoader = BinaryTextureLoader;
  29090. exports.GeometryUtils = GeometryUtils;
  29091. exports.Projector = Projector;
  29092. exports.CanvasRenderer = CanvasRenderer;
  29093. exports.JSONLoader = JSONLoader;
  29094. exports.SceneUtils = SceneUtils;
  29095. exports.LensFlare = LensFlare;
  29096. Object.defineProperty(exports, '__esModule', { value: true });
  29097. }));