three.js 872 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '74dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. if ( self.requestAnimationFrame === undefined || self.cancelAnimationFrame === undefined ) {
  14. // Missing in Android stock browser.
  15. ( function () {
  16. var lastTime = 0;
  17. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  18. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  19. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  20. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  21. }
  22. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  23. self.requestAnimationFrame = function ( callback ) {
  24. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  25. var id = self.setTimeout( function () {
  26. callback( currTime + timeToCall );
  27. }, timeToCall );
  28. lastTime = currTime + timeToCall;
  29. return id;
  30. };
  31. }
  32. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  33. self.cancelAnimationFrame = function ( id ) {
  34. self.clearTimeout( id );
  35. };
  36. }
  37. } )();
  38. }
  39. //
  40. if ( self.performance === undefined ) {
  41. self.performance = {};
  42. }
  43. if ( self.performance.now === undefined ) {
  44. ( function () {
  45. var start = Date.now();
  46. self.performance.now = function () {
  47. return Date.now() - start;
  48. }
  49. } )();
  50. }
  51. //
  52. if ( Number.EPSILON === undefined ) {
  53. Number.EPSILON = Math.pow( 2, - 52 );
  54. }
  55. //
  56. if ( Math.sign === undefined ) {
  57. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  58. Math.sign = function ( x ) {
  59. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  60. };
  61. }
  62. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  63. // Missing in IE9-11.
  64. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  65. Object.defineProperty( Function.prototype, 'name', {
  66. get: function () {
  67. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  68. }
  69. } );
  70. }
  71. if ( Object.assign === undefined ) {
  72. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  73. Object.defineProperty( Object, 'assign', {
  74. writable: true,
  75. configurable: true,
  76. value: function ( target ) {
  77. 'use strict';
  78. if ( target === undefined || target === null ) {
  79. throw new TypeError( "Cannot convert first argument to object" );
  80. }
  81. var to = Object( target );
  82. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  83. var nextSource = arguments[ i ];
  84. if ( nextSource === undefined || nextSource === null ) continue;
  85. nextSource = Object( nextSource );
  86. var keysArray = Object.keys( nextSource );
  87. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  88. var nextKey = keysArray[ nextIndex ];
  89. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  90. if ( desc !== undefined && desc.enumerable ) {
  91. to[ nextKey ] = nextSource[ nextKey ];
  92. }
  93. }
  94. }
  95. return to;
  96. }
  97. } );
  98. }
  99. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  100. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  101. // GL STATE CONSTANTS
  102. THREE.CullFaceNone = 0;
  103. THREE.CullFaceBack = 1;
  104. THREE.CullFaceFront = 2;
  105. THREE.CullFaceFrontBack = 3;
  106. THREE.FrontFaceDirectionCW = 0;
  107. THREE.FrontFaceDirectionCCW = 1;
  108. // SHADOWING TYPES
  109. THREE.BasicShadowMap = 0;
  110. THREE.PCFShadowMap = 1;
  111. THREE.PCFSoftShadowMap = 2;
  112. // MATERIAL CONSTANTS
  113. // side
  114. THREE.FrontSide = 0;
  115. THREE.BackSide = 1;
  116. THREE.DoubleSide = 2;
  117. // shading
  118. THREE.FlatShading = 1;
  119. THREE.SmoothShading = 2;
  120. // colors
  121. THREE.NoColors = 0;
  122. THREE.FaceColors = 1;
  123. THREE.VertexColors = 2;
  124. // blending modes
  125. THREE.NoBlending = 0;
  126. THREE.NormalBlending = 1;
  127. THREE.AdditiveBlending = 2;
  128. THREE.SubtractiveBlending = 3;
  129. THREE.MultiplyBlending = 4;
  130. THREE.CustomBlending = 5;
  131. // custom blending equations
  132. // (numbers start from 100 not to clash with other
  133. // mappings to OpenGL constants defined in Texture.js)
  134. THREE.AddEquation = 100;
  135. THREE.SubtractEquation = 101;
  136. THREE.ReverseSubtractEquation = 102;
  137. THREE.MinEquation = 103;
  138. THREE.MaxEquation = 104;
  139. // custom blending destination factors
  140. THREE.ZeroFactor = 200;
  141. THREE.OneFactor = 201;
  142. THREE.SrcColorFactor = 202;
  143. THREE.OneMinusSrcColorFactor = 203;
  144. THREE.SrcAlphaFactor = 204;
  145. THREE.OneMinusSrcAlphaFactor = 205;
  146. THREE.DstAlphaFactor = 206;
  147. THREE.OneMinusDstAlphaFactor = 207;
  148. // custom blending source factors
  149. //THREE.ZeroFactor = 200;
  150. //THREE.OneFactor = 201;
  151. //THREE.SrcAlphaFactor = 204;
  152. //THREE.OneMinusSrcAlphaFactor = 205;
  153. //THREE.DstAlphaFactor = 206;
  154. //THREE.OneMinusDstAlphaFactor = 207;
  155. THREE.DstColorFactor = 208;
  156. THREE.OneMinusDstColorFactor = 209;
  157. THREE.SrcAlphaSaturateFactor = 210;
  158. // depth modes
  159. THREE.NeverDepth = 0;
  160. THREE.AlwaysDepth = 1;
  161. THREE.LessDepth = 2;
  162. THREE.LessEqualDepth = 3;
  163. THREE.EqualDepth = 4;
  164. THREE.GreaterEqualDepth = 5;
  165. THREE.GreaterDepth = 6;
  166. THREE.NotEqualDepth = 7;
  167. // TEXTURE CONSTANTS
  168. THREE.MultiplyOperation = 0;
  169. THREE.MixOperation = 1;
  170. THREE.AddOperation = 2;
  171. // Mapping modes
  172. THREE.UVMapping = 300;
  173. THREE.CubeReflectionMapping = 301;
  174. THREE.CubeRefractionMapping = 302;
  175. THREE.EquirectangularReflectionMapping = 303;
  176. THREE.EquirectangularRefractionMapping = 304;
  177. THREE.SphericalReflectionMapping = 305;
  178. // Wrapping modes
  179. THREE.RepeatWrapping = 1000;
  180. THREE.ClampToEdgeWrapping = 1001;
  181. THREE.MirroredRepeatWrapping = 1002;
  182. // Filters
  183. THREE.NearestFilter = 1003;
  184. THREE.NearestMipMapNearestFilter = 1004;
  185. THREE.NearestMipMapLinearFilter = 1005;
  186. THREE.LinearFilter = 1006;
  187. THREE.LinearMipMapNearestFilter = 1007;
  188. THREE.LinearMipMapLinearFilter = 1008;
  189. // Data types
  190. THREE.UnsignedByteType = 1009;
  191. THREE.ByteType = 1010;
  192. THREE.ShortType = 1011;
  193. THREE.UnsignedShortType = 1012;
  194. THREE.IntType = 1013;
  195. THREE.UnsignedIntType = 1014;
  196. THREE.FloatType = 1015;
  197. THREE.HalfFloatType = 1025;
  198. // Pixel types
  199. //THREE.UnsignedByteType = 1009;
  200. THREE.UnsignedShort4444Type = 1016;
  201. THREE.UnsignedShort5551Type = 1017;
  202. THREE.UnsignedShort565Type = 1018;
  203. // Pixel formats
  204. THREE.AlphaFormat = 1019;
  205. THREE.RGBFormat = 1020;
  206. THREE.RGBAFormat = 1021;
  207. THREE.LuminanceFormat = 1022;
  208. THREE.LuminanceAlphaFormat = 1023;
  209. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  210. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  211. // DDS / ST3C Compressed texture formats
  212. THREE.RGB_S3TC_DXT1_Format = 2001;
  213. THREE.RGBA_S3TC_DXT1_Format = 2002;
  214. THREE.RGBA_S3TC_DXT3_Format = 2003;
  215. THREE.RGBA_S3TC_DXT5_Format = 2004;
  216. // PVRTC compressed texture formats
  217. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  218. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  219. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  220. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  221. // Loop styles for AnimationAction
  222. THREE.LoopOnce = 2200;
  223. THREE.LoopRepeat = 2201;
  224. THREE.LoopPingPong = 2202;
  225. // Interpolation
  226. THREE.InterpolateDiscrete = 2300;
  227. THREE.InterpolateLinear = 2301;
  228. THREE.InterpolateSmooth = 2302;
  229. // Interpolant ending modes
  230. THREE.ZeroCurvatureEnding = 2400;
  231. THREE.ZeroSlopeEnding = 2401;
  232. THREE.WrapAroundEnding = 2402;
  233. // Triangle Draw modes
  234. THREE.TrianglesDrawMode = 0;
  235. THREE.TriangleStripDrawMode = 1;
  236. THREE.TriangleFanDrawMode = 2;
  237. // File:src/math/Color.js
  238. /**
  239. * @author mrdoob / http://mrdoob.com/
  240. */
  241. THREE.Color = function ( color ) {
  242. if ( arguments.length === 3 ) {
  243. return this.fromArray( arguments );
  244. }
  245. return this.set( color );
  246. };
  247. THREE.Color.prototype = {
  248. constructor: THREE.Color,
  249. r: 1, g: 1, b: 1,
  250. set: function ( value ) {
  251. if ( value instanceof THREE.Color ) {
  252. this.copy( value );
  253. } else if ( typeof value === 'number' ) {
  254. this.setHex( value );
  255. } else if ( typeof value === 'string' ) {
  256. this.setStyle( value );
  257. }
  258. return this;
  259. },
  260. setScalar: function ( scalar ) {
  261. this.r = scalar;
  262. this.g = scalar;
  263. this.b = scalar;
  264. },
  265. setHex: function ( hex ) {
  266. hex = Math.floor( hex );
  267. this.r = ( hex >> 16 & 255 ) / 255;
  268. this.g = ( hex >> 8 & 255 ) / 255;
  269. this.b = ( hex & 255 ) / 255;
  270. return this;
  271. },
  272. setRGB: function ( r, g, b ) {
  273. this.r = r;
  274. this.g = g;
  275. this.b = b;
  276. return this;
  277. },
  278. setHSL: function () {
  279. function hue2rgb( p, q, t ) {
  280. if ( t < 0 ) t += 1;
  281. if ( t > 1 ) t -= 1;
  282. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  283. if ( t < 1 / 2 ) return q;
  284. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  285. return p;
  286. }
  287. return function ( h, s, l ) {
  288. // h,s,l ranges are in 0.0 - 1.0
  289. h = THREE.Math.euclideanModulo( h, 1 );
  290. s = THREE.Math.clamp( s, 0, 1 );
  291. l = THREE.Math.clamp( l, 0, 1 );
  292. if ( s === 0 ) {
  293. this.r = this.g = this.b = l;
  294. } else {
  295. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  296. var q = ( 2 * l ) - p;
  297. this.r = hue2rgb( q, p, h + 1 / 3 );
  298. this.g = hue2rgb( q, p, h );
  299. this.b = hue2rgb( q, p, h - 1 / 3 );
  300. }
  301. return this;
  302. };
  303. }(),
  304. setStyle: function ( style ) {
  305. function handleAlpha( string ) {
  306. if ( string === undefined ) return;
  307. if ( parseFloat( string ) < 1 ) {
  308. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  309. }
  310. }
  311. var m;
  312. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  313. // rgb / hsl
  314. var color;
  315. var name = m[ 1 ];
  316. var components = m[ 2 ];
  317. switch ( name ) {
  318. case 'rgb':
  319. case 'rgba':
  320. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  321. // rgb(255,0,0) rgba(255,0,0,0.5)
  322. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  323. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  324. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  325. handleAlpha( color[ 5 ] );
  326. return this;
  327. }
  328. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  329. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  330. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  331. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  332. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  333. handleAlpha( color[ 5 ] );
  334. return this;
  335. }
  336. break;
  337. case 'hsl':
  338. case 'hsla':
  339. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  340. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  341. var h = parseFloat( color[ 1 ] ) / 360;
  342. var s = parseInt( color[ 2 ], 10 ) / 100;
  343. var l = parseInt( color[ 3 ], 10 ) / 100;
  344. handleAlpha( color[ 5 ] );
  345. return this.setHSL( h, s, l );
  346. }
  347. break;
  348. }
  349. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  350. // hex color
  351. var hex = m[ 1 ];
  352. var size = hex.length;
  353. if ( size === 3 ) {
  354. // #ff0
  355. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  356. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  357. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  358. return this;
  359. } else if ( size === 6 ) {
  360. // #ff0000
  361. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  362. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  363. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  364. return this;
  365. }
  366. }
  367. if ( style && style.length > 0 ) {
  368. // color keywords
  369. var hex = THREE.ColorKeywords[ style ];
  370. if ( hex !== undefined ) {
  371. // red
  372. this.setHex( hex );
  373. } else {
  374. // unknown color
  375. console.warn( 'THREE.Color: Unknown color ' + style );
  376. }
  377. }
  378. return this;
  379. },
  380. clone: function () {
  381. return new this.constructor( this.r, this.g, this.b );
  382. },
  383. copy: function ( color ) {
  384. this.r = color.r;
  385. this.g = color.g;
  386. this.b = color.b;
  387. return this;
  388. },
  389. copyGammaToLinear: function ( color, gammaFactor ) {
  390. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  391. this.r = Math.pow( color.r, gammaFactor );
  392. this.g = Math.pow( color.g, gammaFactor );
  393. this.b = Math.pow( color.b, gammaFactor );
  394. return this;
  395. },
  396. copyLinearToGamma: function ( color, gammaFactor ) {
  397. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  398. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  399. this.r = Math.pow( color.r, safeInverse );
  400. this.g = Math.pow( color.g, safeInverse );
  401. this.b = Math.pow( color.b, safeInverse );
  402. return this;
  403. },
  404. convertGammaToLinear: function () {
  405. var r = this.r, g = this.g, b = this.b;
  406. this.r = r * r;
  407. this.g = g * g;
  408. this.b = b * b;
  409. return this;
  410. },
  411. convertLinearToGamma: function () {
  412. this.r = Math.sqrt( this.r );
  413. this.g = Math.sqrt( this.g );
  414. this.b = Math.sqrt( this.b );
  415. return this;
  416. },
  417. getHex: function () {
  418. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  419. },
  420. getHexString: function () {
  421. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  422. },
  423. getHSL: function ( optionalTarget ) {
  424. // h,s,l ranges are in 0.0 - 1.0
  425. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  426. var r = this.r, g = this.g, b = this.b;
  427. var max = Math.max( r, g, b );
  428. var min = Math.min( r, g, b );
  429. var hue, saturation;
  430. var lightness = ( min + max ) / 2.0;
  431. if ( min === max ) {
  432. hue = 0;
  433. saturation = 0;
  434. } else {
  435. var delta = max - min;
  436. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  437. switch ( max ) {
  438. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  439. case g: hue = ( b - r ) / delta + 2; break;
  440. case b: hue = ( r - g ) / delta + 4; break;
  441. }
  442. hue /= 6;
  443. }
  444. hsl.h = hue;
  445. hsl.s = saturation;
  446. hsl.l = lightness;
  447. return hsl;
  448. },
  449. getStyle: function () {
  450. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  451. },
  452. offsetHSL: function ( h, s, l ) {
  453. var hsl = this.getHSL();
  454. hsl.h += h; hsl.s += s; hsl.l += l;
  455. this.setHSL( hsl.h, hsl.s, hsl.l );
  456. return this;
  457. },
  458. add: function ( color ) {
  459. this.r += color.r;
  460. this.g += color.g;
  461. this.b += color.b;
  462. return this;
  463. },
  464. addColors: function ( color1, color2 ) {
  465. this.r = color1.r + color2.r;
  466. this.g = color1.g + color2.g;
  467. this.b = color1.b + color2.b;
  468. return this;
  469. },
  470. addScalar: function ( s ) {
  471. this.r += s;
  472. this.g += s;
  473. this.b += s;
  474. return this;
  475. },
  476. multiply: function ( color ) {
  477. this.r *= color.r;
  478. this.g *= color.g;
  479. this.b *= color.b;
  480. return this;
  481. },
  482. multiplyScalar: function ( s ) {
  483. this.r *= s;
  484. this.g *= s;
  485. this.b *= s;
  486. return this;
  487. },
  488. lerp: function ( color, alpha ) {
  489. this.r += ( color.r - this.r ) * alpha;
  490. this.g += ( color.g - this.g ) * alpha;
  491. this.b += ( color.b - this.b ) * alpha;
  492. return this;
  493. },
  494. equals: function ( c ) {
  495. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  496. },
  497. fromArray: function ( array, offset ) {
  498. if ( offset === undefined ) offset = 0;
  499. this.r = array[ offset ];
  500. this.g = array[ offset + 1 ];
  501. this.b = array[ offset + 2 ];
  502. return this;
  503. },
  504. toArray: function ( array, offset ) {
  505. if ( array === undefined ) array = [];
  506. if ( offset === undefined ) offset = 0;
  507. array[ offset ] = this.r;
  508. array[ offset + 1 ] = this.g;
  509. array[ offset + 2 ] = this.b;
  510. return array;
  511. }
  512. };
  513. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  514. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  515. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  516. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  517. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  518. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  519. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  520. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  521. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  522. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  523. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  524. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  525. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  526. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  527. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  528. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  529. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  530. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  531. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  532. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  533. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  534. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  535. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  536. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  537. // File:src/math/Quaternion.js
  538. /**
  539. * @author mikael emtinger / http://gomo.se/
  540. * @author alteredq / http://alteredqualia.com/
  541. * @author WestLangley / http://github.com/WestLangley
  542. * @author bhouston / http://clara.io
  543. */
  544. THREE.Quaternion = function ( x, y, z, w ) {
  545. this._x = x || 0;
  546. this._y = y || 0;
  547. this._z = z || 0;
  548. this._w = ( w !== undefined ) ? w : 1;
  549. };
  550. THREE.Quaternion.prototype = {
  551. constructor: THREE.Quaternion,
  552. get x () {
  553. return this._x;
  554. },
  555. set x ( value ) {
  556. this._x = value;
  557. this.onChangeCallback();
  558. },
  559. get y () {
  560. return this._y;
  561. },
  562. set y ( value ) {
  563. this._y = value;
  564. this.onChangeCallback();
  565. },
  566. get z () {
  567. return this._z;
  568. },
  569. set z ( value ) {
  570. this._z = value;
  571. this.onChangeCallback();
  572. },
  573. get w () {
  574. return this._w;
  575. },
  576. set w ( value ) {
  577. this._w = value;
  578. this.onChangeCallback();
  579. },
  580. set: function ( x, y, z, w ) {
  581. this._x = x;
  582. this._y = y;
  583. this._z = z;
  584. this._w = w;
  585. this.onChangeCallback();
  586. return this;
  587. },
  588. clone: function () {
  589. return new this.constructor( this._x, this._y, this._z, this._w );
  590. },
  591. copy: function ( quaternion ) {
  592. this._x = quaternion.x;
  593. this._y = quaternion.y;
  594. this._z = quaternion.z;
  595. this._w = quaternion.w;
  596. this.onChangeCallback();
  597. return this;
  598. },
  599. setFromEuler: function ( euler, update ) {
  600. if ( euler instanceof THREE.Euler === false ) {
  601. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  602. }
  603. // http://www.mathworks.com/matlabcentral/fileexchange/
  604. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  605. // content/SpinCalc.m
  606. var c1 = Math.cos( euler._x / 2 );
  607. var c2 = Math.cos( euler._y / 2 );
  608. var c3 = Math.cos( euler._z / 2 );
  609. var s1 = Math.sin( euler._x / 2 );
  610. var s2 = Math.sin( euler._y / 2 );
  611. var s3 = Math.sin( euler._z / 2 );
  612. var order = euler.order;
  613. if ( order === 'XYZ' ) {
  614. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  615. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  616. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  617. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  618. } else if ( order === 'YXZ' ) {
  619. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  620. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  621. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  622. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  623. } else if ( order === 'ZXY' ) {
  624. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  625. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  626. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  627. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  628. } else if ( order === 'ZYX' ) {
  629. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  632. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  633. } else if ( order === 'YZX' ) {
  634. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  635. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  636. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  637. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  638. } else if ( order === 'XZY' ) {
  639. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  640. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  641. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  642. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  643. }
  644. if ( update !== false ) this.onChangeCallback();
  645. return this;
  646. },
  647. setFromAxisAngle: function ( axis, angle ) {
  648. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  649. // assumes axis is normalized
  650. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  651. this._x = axis.x * s;
  652. this._y = axis.y * s;
  653. this._z = axis.z * s;
  654. this._w = Math.cos( halfAngle );
  655. this.onChangeCallback();
  656. return this;
  657. },
  658. setFromRotationMatrix: function ( m ) {
  659. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  660. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  661. var te = m.elements,
  662. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  663. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  664. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  665. trace = m11 + m22 + m33,
  666. s;
  667. if ( trace > 0 ) {
  668. s = 0.5 / Math.sqrt( trace + 1.0 );
  669. this._w = 0.25 / s;
  670. this._x = ( m32 - m23 ) * s;
  671. this._y = ( m13 - m31 ) * s;
  672. this._z = ( m21 - m12 ) * s;
  673. } else if ( m11 > m22 && m11 > m33 ) {
  674. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  675. this._w = ( m32 - m23 ) / s;
  676. this._x = 0.25 * s;
  677. this._y = ( m12 + m21 ) / s;
  678. this._z = ( m13 + m31 ) / s;
  679. } else if ( m22 > m33 ) {
  680. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  681. this._w = ( m13 - m31 ) / s;
  682. this._x = ( m12 + m21 ) / s;
  683. this._y = 0.25 * s;
  684. this._z = ( m23 + m32 ) / s;
  685. } else {
  686. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  687. this._w = ( m21 - m12 ) / s;
  688. this._x = ( m13 + m31 ) / s;
  689. this._y = ( m23 + m32 ) / s;
  690. this._z = 0.25 * s;
  691. }
  692. this.onChangeCallback();
  693. return this;
  694. },
  695. setFromUnitVectors: function () {
  696. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  697. // assumes direction vectors vFrom and vTo are normalized
  698. var v1, r;
  699. var EPS = 0.000001;
  700. return function ( vFrom, vTo ) {
  701. if ( v1 === undefined ) v1 = new THREE.Vector3();
  702. r = vFrom.dot( vTo ) + 1;
  703. if ( r < EPS ) {
  704. r = 0;
  705. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  706. v1.set( - vFrom.y, vFrom.x, 0 );
  707. } else {
  708. v1.set( 0, - vFrom.z, vFrom.y );
  709. }
  710. } else {
  711. v1.crossVectors( vFrom, vTo );
  712. }
  713. this._x = v1.x;
  714. this._y = v1.y;
  715. this._z = v1.z;
  716. this._w = r;
  717. this.normalize();
  718. return this;
  719. };
  720. }(),
  721. inverse: function () {
  722. this.conjugate().normalize();
  723. return this;
  724. },
  725. conjugate: function () {
  726. this._x *= - 1;
  727. this._y *= - 1;
  728. this._z *= - 1;
  729. this.onChangeCallback();
  730. return this;
  731. },
  732. dot: function ( v ) {
  733. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  734. },
  735. lengthSq: function () {
  736. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  737. },
  738. length: function () {
  739. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  740. },
  741. normalize: function () {
  742. var l = this.length();
  743. if ( l === 0 ) {
  744. this._x = 0;
  745. this._y = 0;
  746. this._z = 0;
  747. this._w = 1;
  748. } else {
  749. l = 1 / l;
  750. this._x = this._x * l;
  751. this._y = this._y * l;
  752. this._z = this._z * l;
  753. this._w = this._w * l;
  754. }
  755. this.onChangeCallback();
  756. return this;
  757. },
  758. multiply: function ( q, p ) {
  759. if ( p !== undefined ) {
  760. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  761. return this.multiplyQuaternions( q, p );
  762. }
  763. return this.multiplyQuaternions( this, q );
  764. },
  765. multiplyQuaternions: function ( a, b ) {
  766. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  767. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  768. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  769. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  770. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  771. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  772. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  773. this.onChangeCallback();
  774. return this;
  775. },
  776. slerp: function ( qb, t ) {
  777. if ( t === 0 ) return this;
  778. if ( t === 1 ) return this.copy( qb );
  779. var x = this._x, y = this._y, z = this._z, w = this._w;
  780. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  781. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  782. if ( cosHalfTheta < 0 ) {
  783. this._w = - qb._w;
  784. this._x = - qb._x;
  785. this._y = - qb._y;
  786. this._z = - qb._z;
  787. cosHalfTheta = - cosHalfTheta;
  788. } else {
  789. this.copy( qb );
  790. }
  791. if ( cosHalfTheta >= 1.0 ) {
  792. this._w = w;
  793. this._x = x;
  794. this._y = y;
  795. this._z = z;
  796. return this;
  797. }
  798. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  799. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  800. this._w = 0.5 * ( w + this._w );
  801. this._x = 0.5 * ( x + this._x );
  802. this._y = 0.5 * ( y + this._y );
  803. this._z = 0.5 * ( z + this._z );
  804. return this;
  805. }
  806. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  807. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  808. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  809. this._w = ( w * ratioA + this._w * ratioB );
  810. this._x = ( x * ratioA + this._x * ratioB );
  811. this._y = ( y * ratioA + this._y * ratioB );
  812. this._z = ( z * ratioA + this._z * ratioB );
  813. this.onChangeCallback();
  814. return this;
  815. },
  816. equals: function ( quaternion ) {
  817. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  818. },
  819. fromArray: function ( array, offset ) {
  820. if ( offset === undefined ) offset = 0;
  821. this._x = array[ offset ];
  822. this._y = array[ offset + 1 ];
  823. this._z = array[ offset + 2 ];
  824. this._w = array[ offset + 3 ];
  825. this.onChangeCallback();
  826. return this;
  827. },
  828. toArray: function ( array, offset ) {
  829. if ( array === undefined ) array = [];
  830. if ( offset === undefined ) offset = 0;
  831. array[ offset ] = this._x;
  832. array[ offset + 1 ] = this._y;
  833. array[ offset + 2 ] = this._z;
  834. array[ offset + 3 ] = this._w;
  835. return array;
  836. },
  837. onChange: function ( callback ) {
  838. this.onChangeCallback = callback;
  839. return this;
  840. },
  841. onChangeCallback: function () {}
  842. };
  843. Object.assign( THREE.Quaternion, {
  844. slerp: function( qa, qb, qm, t ) {
  845. return qm.copy( qa ).slerp( qb, t );
  846. },
  847. slerpFlat: function(
  848. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  849. // fuzz-free, array-based Quaternion SLERP operation
  850. var x0 = src0[ srcOffset0 + 0 ],
  851. y0 = src0[ srcOffset0 + 1 ],
  852. z0 = src0[ srcOffset0 + 2 ],
  853. w0 = src0[ srcOffset0 + 3 ],
  854. x1 = src1[ srcOffset1 + 0 ],
  855. y1 = src1[ srcOffset1 + 1 ],
  856. z1 = src1[ srcOffset1 + 2 ],
  857. w1 = src1[ srcOffset1 + 3 ];
  858. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  859. var s = 1 - t,
  860. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  861. dir = ( cos >= 0 ? 1 : - 1 ),
  862. sqrSin = 1 - cos * cos;
  863. // Skip the Slerp for tiny steps to avoid numeric problems:
  864. if ( sqrSin > Number.EPSILON ) {
  865. var sin = Math.sqrt( sqrSin ),
  866. len = Math.atan2( sin, cos * dir );
  867. s = Math.sin( s * len ) / sin;
  868. t = Math.sin( t * len ) / sin;
  869. }
  870. var tDir = t * dir;
  871. x0 = x0 * s + x1 * tDir;
  872. y0 = y0 * s + y1 * tDir;
  873. z0 = z0 * s + z1 * tDir;
  874. w0 = w0 * s + w1 * tDir;
  875. // Normalize in case we just did a lerp:
  876. if ( s === 1 - t ) {
  877. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  878. x0 *= f;
  879. y0 *= f;
  880. z0 *= f;
  881. w0 *= f;
  882. }
  883. }
  884. dst[ dstOffset ] = x0;
  885. dst[ dstOffset + 1 ] = y0;
  886. dst[ dstOffset + 2 ] = z0;
  887. dst[ dstOffset + 3 ] = w0;
  888. }
  889. } );
  890. // File:src/math/Vector2.js
  891. /**
  892. * @author mrdoob / http://mrdoob.com/
  893. * @author philogb / http://blog.thejit.org/
  894. * @author egraether / http://egraether.com/
  895. * @author zz85 / http://www.lab4games.net/zz85/blog
  896. */
  897. THREE.Vector2 = function ( x, y ) {
  898. this.x = x || 0;
  899. this.y = y || 0;
  900. };
  901. THREE.Vector2.prototype = {
  902. constructor: THREE.Vector2,
  903. get width() {
  904. return this.x;
  905. },
  906. set width( value ) {
  907. this.x = value;
  908. },
  909. get height() {
  910. return this.y;
  911. },
  912. set height( value ) {
  913. this.y = value;
  914. },
  915. //
  916. set: function ( x, y ) {
  917. this.x = x;
  918. this.y = y;
  919. return this;
  920. },
  921. setScalar: function ( scalar ) {
  922. this.x = scalar;
  923. this.y = scalar;
  924. return this;
  925. },
  926. setX: function ( x ) {
  927. this.x = x;
  928. return this;
  929. },
  930. setY: function ( y ) {
  931. this.y = y;
  932. return this;
  933. },
  934. setComponent: function ( index, value ) {
  935. switch ( index ) {
  936. case 0: this.x = value; break;
  937. case 1: this.y = value; break;
  938. default: throw new Error( 'index is out of range: ' + index );
  939. }
  940. },
  941. getComponent: function ( index ) {
  942. switch ( index ) {
  943. case 0: return this.x;
  944. case 1: return this.y;
  945. default: throw new Error( 'index is out of range: ' + index );
  946. }
  947. },
  948. clone: function () {
  949. return new this.constructor( this.x, this.y );
  950. },
  951. copy: function ( v ) {
  952. this.x = v.x;
  953. this.y = v.y;
  954. return this;
  955. },
  956. add: function ( v, w ) {
  957. if ( w !== undefined ) {
  958. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  959. return this.addVectors( v, w );
  960. }
  961. this.x += v.x;
  962. this.y += v.y;
  963. return this;
  964. },
  965. addScalar: function ( s ) {
  966. this.x += s;
  967. this.y += s;
  968. return this;
  969. },
  970. addVectors: function ( a, b ) {
  971. this.x = a.x + b.x;
  972. this.y = a.y + b.y;
  973. return this;
  974. },
  975. addScaledVector: function ( v, s ) {
  976. this.x += v.x * s;
  977. this.y += v.y * s;
  978. return this;
  979. },
  980. sub: function ( v, w ) {
  981. if ( w !== undefined ) {
  982. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  983. return this.subVectors( v, w );
  984. }
  985. this.x -= v.x;
  986. this.y -= v.y;
  987. return this;
  988. },
  989. subScalar: function ( s ) {
  990. this.x -= s;
  991. this.y -= s;
  992. return this;
  993. },
  994. subVectors: function ( a, b ) {
  995. this.x = a.x - b.x;
  996. this.y = a.y - b.y;
  997. return this;
  998. },
  999. multiply: function ( v ) {
  1000. this.x *= v.x;
  1001. this.y *= v.y;
  1002. return this;
  1003. },
  1004. multiplyScalar: function ( scalar ) {
  1005. if ( isFinite( scalar ) ) {
  1006. this.x *= scalar;
  1007. this.y *= scalar;
  1008. } else {
  1009. this.x = 0;
  1010. this.y = 0;
  1011. }
  1012. return this;
  1013. },
  1014. divide: function ( v ) {
  1015. this.x /= v.x;
  1016. this.y /= v.y;
  1017. return this;
  1018. },
  1019. divideScalar: function ( scalar ) {
  1020. return this.multiplyScalar( 1 / scalar );
  1021. },
  1022. min: function ( v ) {
  1023. this.x = Math.min( this.x, v.x );
  1024. this.y = Math.min( this.y, v.y );
  1025. return this;
  1026. },
  1027. max: function ( v ) {
  1028. this.x = Math.max( this.x, v.x );
  1029. this.y = Math.max( this.y, v.y );
  1030. return this;
  1031. },
  1032. clamp: function ( min, max ) {
  1033. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1034. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1035. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1036. return this;
  1037. },
  1038. clampScalar: function () {
  1039. var min, max;
  1040. return function clampScalar( minVal, maxVal ) {
  1041. if ( min === undefined ) {
  1042. min = new THREE.Vector2();
  1043. max = new THREE.Vector2();
  1044. }
  1045. min.set( minVal, minVal );
  1046. max.set( maxVal, maxVal );
  1047. return this.clamp( min, max );
  1048. };
  1049. }(),
  1050. clampLength: function ( min, max ) {
  1051. var length = this.length();
  1052. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1053. return this;
  1054. },
  1055. floor: function () {
  1056. this.x = Math.floor( this.x );
  1057. this.y = Math.floor( this.y );
  1058. return this;
  1059. },
  1060. ceil: function () {
  1061. this.x = Math.ceil( this.x );
  1062. this.y = Math.ceil( this.y );
  1063. return this;
  1064. },
  1065. round: function () {
  1066. this.x = Math.round( this.x );
  1067. this.y = Math.round( this.y );
  1068. return this;
  1069. },
  1070. roundToZero: function () {
  1071. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1072. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1073. return this;
  1074. },
  1075. negate: function () {
  1076. this.x = - this.x;
  1077. this.y = - this.y;
  1078. return this;
  1079. },
  1080. dot: function ( v ) {
  1081. return this.x * v.x + this.y * v.y;
  1082. },
  1083. lengthSq: function () {
  1084. return this.x * this.x + this.y * this.y;
  1085. },
  1086. length: function () {
  1087. return Math.sqrt( this.x * this.x + this.y * this.y );
  1088. },
  1089. lengthManhattan: function() {
  1090. return Math.abs( this.x ) + Math.abs( this.y );
  1091. },
  1092. normalize: function () {
  1093. return this.divideScalar( this.length() );
  1094. },
  1095. distanceTo: function ( v ) {
  1096. return Math.sqrt( this.distanceToSquared( v ) );
  1097. },
  1098. distanceToSquared: function ( v ) {
  1099. var dx = this.x - v.x, dy = this.y - v.y;
  1100. return dx * dx + dy * dy;
  1101. },
  1102. setLength: function ( length ) {
  1103. return this.multiplyScalar( length / this.length() );
  1104. },
  1105. lerp: function ( v, alpha ) {
  1106. this.x += ( v.x - this.x ) * alpha;
  1107. this.y += ( v.y - this.y ) * alpha;
  1108. return this;
  1109. },
  1110. lerpVectors: function ( v1, v2, alpha ) {
  1111. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1112. return this;
  1113. },
  1114. equals: function ( v ) {
  1115. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1116. },
  1117. fromArray: function ( array, offset ) {
  1118. if ( offset === undefined ) offset = 0;
  1119. this.x = array[ offset ];
  1120. this.y = array[ offset + 1 ];
  1121. return this;
  1122. },
  1123. toArray: function ( array, offset ) {
  1124. if ( array === undefined ) array = [];
  1125. if ( offset === undefined ) offset = 0;
  1126. array[ offset ] = this.x;
  1127. array[ offset + 1 ] = this.y;
  1128. return array;
  1129. },
  1130. fromAttribute: function ( attribute, index, offset ) {
  1131. if ( offset === undefined ) offset = 0;
  1132. index = index * attribute.itemSize + offset;
  1133. this.x = attribute.array[ index ];
  1134. this.y = attribute.array[ index + 1 ];
  1135. return this;
  1136. },
  1137. rotateAround: function ( center, angle ) {
  1138. var c = Math.cos( angle ), s = Math.sin( angle );
  1139. var x = this.x - center.x;
  1140. var y = this.y - center.y;
  1141. this.x = x * c - y * s + center.x;
  1142. this.y = x * s + y * c + center.y;
  1143. return this;
  1144. }
  1145. };
  1146. // File:src/math/Vector3.js
  1147. /**
  1148. * @author mrdoob / http://mrdoob.com/
  1149. * @author *kile / http://kile.stravaganza.org/
  1150. * @author philogb / http://blog.thejit.org/
  1151. * @author mikael emtinger / http://gomo.se/
  1152. * @author egraether / http://egraether.com/
  1153. * @author WestLangley / http://github.com/WestLangley
  1154. */
  1155. THREE.Vector3 = function ( x, y, z ) {
  1156. this.x = x || 0;
  1157. this.y = y || 0;
  1158. this.z = z || 0;
  1159. };
  1160. THREE.Vector3.prototype = {
  1161. constructor: THREE.Vector3,
  1162. set: function ( x, y, z ) {
  1163. this.x = x;
  1164. this.y = y;
  1165. this.z = z;
  1166. return this;
  1167. },
  1168. setScalar: function ( scalar ) {
  1169. this.x = scalar;
  1170. this.y = scalar;
  1171. this.z = scalar;
  1172. return this;
  1173. },
  1174. setX: function ( x ) {
  1175. this.x = x;
  1176. return this;
  1177. },
  1178. setY: function ( y ) {
  1179. this.y = y;
  1180. return this;
  1181. },
  1182. setZ: function ( z ) {
  1183. this.z = z;
  1184. return this;
  1185. },
  1186. setComponent: function ( index, value ) {
  1187. switch ( index ) {
  1188. case 0: this.x = value; break;
  1189. case 1: this.y = value; break;
  1190. case 2: this.z = value; break;
  1191. default: throw new Error( 'index is out of range: ' + index );
  1192. }
  1193. },
  1194. getComponent: function ( index ) {
  1195. switch ( index ) {
  1196. case 0: return this.x;
  1197. case 1: return this.y;
  1198. case 2: return this.z;
  1199. default: throw new Error( 'index is out of range: ' + index );
  1200. }
  1201. },
  1202. clone: function () {
  1203. return new this.constructor( this.x, this.y, this.z );
  1204. },
  1205. copy: function ( v ) {
  1206. this.x = v.x;
  1207. this.y = v.y;
  1208. this.z = v.z;
  1209. return this;
  1210. },
  1211. add: function ( v, w ) {
  1212. if ( w !== undefined ) {
  1213. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1214. return this.addVectors( v, w );
  1215. }
  1216. this.x += v.x;
  1217. this.y += v.y;
  1218. this.z += v.z;
  1219. return this;
  1220. },
  1221. addScalar: function ( s ) {
  1222. this.x += s;
  1223. this.y += s;
  1224. this.z += s;
  1225. return this;
  1226. },
  1227. addVectors: function ( a, b ) {
  1228. this.x = a.x + b.x;
  1229. this.y = a.y + b.y;
  1230. this.z = a.z + b.z;
  1231. return this;
  1232. },
  1233. addScaledVector: function ( v, s ) {
  1234. this.x += v.x * s;
  1235. this.y += v.y * s;
  1236. this.z += v.z * s;
  1237. return this;
  1238. },
  1239. sub: function ( v, w ) {
  1240. if ( w !== undefined ) {
  1241. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1242. return this.subVectors( v, w );
  1243. }
  1244. this.x -= v.x;
  1245. this.y -= v.y;
  1246. this.z -= v.z;
  1247. return this;
  1248. },
  1249. subScalar: function ( s ) {
  1250. this.x -= s;
  1251. this.y -= s;
  1252. this.z -= s;
  1253. return this;
  1254. },
  1255. subVectors: function ( a, b ) {
  1256. this.x = a.x - b.x;
  1257. this.y = a.y - b.y;
  1258. this.z = a.z - b.z;
  1259. return this;
  1260. },
  1261. multiply: function ( v, w ) {
  1262. if ( w !== undefined ) {
  1263. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1264. return this.multiplyVectors( v, w );
  1265. }
  1266. this.x *= v.x;
  1267. this.y *= v.y;
  1268. this.z *= v.z;
  1269. return this;
  1270. },
  1271. multiplyScalar: function ( scalar ) {
  1272. if ( isFinite( scalar ) ) {
  1273. this.x *= scalar;
  1274. this.y *= scalar;
  1275. this.z *= scalar;
  1276. } else {
  1277. this.x = 0;
  1278. this.y = 0;
  1279. this.z = 0;
  1280. }
  1281. return this;
  1282. },
  1283. multiplyVectors: function ( a, b ) {
  1284. this.x = a.x * b.x;
  1285. this.y = a.y * b.y;
  1286. this.z = a.z * b.z;
  1287. return this;
  1288. },
  1289. applyEuler: function () {
  1290. var quaternion;
  1291. return function applyEuler( euler ) {
  1292. if ( euler instanceof THREE.Euler === false ) {
  1293. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1294. }
  1295. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1296. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1297. return this;
  1298. };
  1299. }(),
  1300. applyAxisAngle: function () {
  1301. var quaternion;
  1302. return function applyAxisAngle( axis, angle ) {
  1303. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1304. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1305. return this;
  1306. };
  1307. }(),
  1308. applyMatrix3: function ( m ) {
  1309. var x = this.x;
  1310. var y = this.y;
  1311. var z = this.z;
  1312. var e = m.elements;
  1313. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1314. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1315. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1316. return this;
  1317. },
  1318. applyMatrix4: function ( m ) {
  1319. // input: THREE.Matrix4 affine matrix
  1320. var x = this.x, y = this.y, z = this.z;
  1321. var e = m.elements;
  1322. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1323. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1324. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1325. return this;
  1326. },
  1327. applyProjection: function ( m ) {
  1328. // input: THREE.Matrix4 projection matrix
  1329. var x = this.x, y = this.y, z = this.z;
  1330. var e = m.elements;
  1331. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1332. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1333. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1334. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1335. return this;
  1336. },
  1337. applyQuaternion: function ( q ) {
  1338. var x = this.x;
  1339. var y = this.y;
  1340. var z = this.z;
  1341. var qx = q.x;
  1342. var qy = q.y;
  1343. var qz = q.z;
  1344. var qw = q.w;
  1345. // calculate quat * vector
  1346. var ix = qw * x + qy * z - qz * y;
  1347. var iy = qw * y + qz * x - qx * z;
  1348. var iz = qw * z + qx * y - qy * x;
  1349. var iw = - qx * x - qy * y - qz * z;
  1350. // calculate result * inverse quat
  1351. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1352. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1353. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1354. return this;
  1355. },
  1356. project: function () {
  1357. var matrix;
  1358. return function project( camera ) {
  1359. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1360. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1361. return this.applyProjection( matrix );
  1362. };
  1363. }(),
  1364. unproject: function () {
  1365. var matrix;
  1366. return function unproject( camera ) {
  1367. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1368. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1369. return this.applyProjection( matrix );
  1370. };
  1371. }(),
  1372. transformDirection: function ( m ) {
  1373. // input: THREE.Matrix4 affine matrix
  1374. // vector interpreted as a direction
  1375. var x = this.x, y = this.y, z = this.z;
  1376. var e = m.elements;
  1377. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1378. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1379. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1380. this.normalize();
  1381. return this;
  1382. },
  1383. divide: function ( v ) {
  1384. this.x /= v.x;
  1385. this.y /= v.y;
  1386. this.z /= v.z;
  1387. return this;
  1388. },
  1389. divideScalar: function ( scalar ) {
  1390. return this.multiplyScalar( 1 / scalar );
  1391. },
  1392. min: function ( v ) {
  1393. this.x = Math.min( this.x, v.x );
  1394. this.y = Math.min( this.y, v.y );
  1395. this.z = Math.min( this.z, v.z );
  1396. return this;
  1397. },
  1398. max: function ( v ) {
  1399. this.x = Math.max( this.x, v.x );
  1400. this.y = Math.max( this.y, v.y );
  1401. this.z = Math.max( this.z, v.z );
  1402. return this;
  1403. },
  1404. clamp: function ( min, max ) {
  1405. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1406. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1407. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1408. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1409. return this;
  1410. },
  1411. clampScalar: function () {
  1412. var min, max;
  1413. return function clampScalar( minVal, maxVal ) {
  1414. if ( min === undefined ) {
  1415. min = new THREE.Vector3();
  1416. max = new THREE.Vector3();
  1417. }
  1418. min.set( minVal, minVal, minVal );
  1419. max.set( maxVal, maxVal, maxVal );
  1420. return this.clamp( min, max );
  1421. };
  1422. }(),
  1423. clampLength: function ( min, max ) {
  1424. var length = this.length();
  1425. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1426. return this;
  1427. },
  1428. floor: function () {
  1429. this.x = Math.floor( this.x );
  1430. this.y = Math.floor( this.y );
  1431. this.z = Math.floor( this.z );
  1432. return this;
  1433. },
  1434. ceil: function () {
  1435. this.x = Math.ceil( this.x );
  1436. this.y = Math.ceil( this.y );
  1437. this.z = Math.ceil( this.z );
  1438. return this;
  1439. },
  1440. round: function () {
  1441. this.x = Math.round( this.x );
  1442. this.y = Math.round( this.y );
  1443. this.z = Math.round( this.z );
  1444. return this;
  1445. },
  1446. roundToZero: function () {
  1447. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1448. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1449. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1450. return this;
  1451. },
  1452. negate: function () {
  1453. this.x = - this.x;
  1454. this.y = - this.y;
  1455. this.z = - this.z;
  1456. return this;
  1457. },
  1458. dot: function ( v ) {
  1459. return this.x * v.x + this.y * v.y + this.z * v.z;
  1460. },
  1461. lengthSq: function () {
  1462. return this.x * this.x + this.y * this.y + this.z * this.z;
  1463. },
  1464. length: function () {
  1465. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1466. },
  1467. lengthManhattan: function () {
  1468. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1469. },
  1470. normalize: function () {
  1471. return this.divideScalar( this.length() );
  1472. },
  1473. setLength: function ( length ) {
  1474. return this.multiplyScalar( length / this.length() );
  1475. },
  1476. lerp: function ( v, alpha ) {
  1477. this.x += ( v.x - this.x ) * alpha;
  1478. this.y += ( v.y - this.y ) * alpha;
  1479. this.z += ( v.z - this.z ) * alpha;
  1480. return this;
  1481. },
  1482. lerpVectors: function ( v1, v2, alpha ) {
  1483. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1484. return this;
  1485. },
  1486. cross: function ( v, w ) {
  1487. if ( w !== undefined ) {
  1488. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1489. return this.crossVectors( v, w );
  1490. }
  1491. var x = this.x, y = this.y, z = this.z;
  1492. this.x = y * v.z - z * v.y;
  1493. this.y = z * v.x - x * v.z;
  1494. this.z = x * v.y - y * v.x;
  1495. return this;
  1496. },
  1497. crossVectors: function ( a, b ) {
  1498. var ax = a.x, ay = a.y, az = a.z;
  1499. var bx = b.x, by = b.y, bz = b.z;
  1500. this.x = ay * bz - az * by;
  1501. this.y = az * bx - ax * bz;
  1502. this.z = ax * by - ay * bx;
  1503. return this;
  1504. },
  1505. projectOnVector: function () {
  1506. var v1, dot;
  1507. return function projectOnVector( vector ) {
  1508. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1509. v1.copy( vector ).normalize();
  1510. dot = this.dot( v1 );
  1511. return this.copy( v1 ).multiplyScalar( dot );
  1512. };
  1513. }(),
  1514. projectOnPlane: function () {
  1515. var v1;
  1516. return function projectOnPlane( planeNormal ) {
  1517. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1518. v1.copy( this ).projectOnVector( planeNormal );
  1519. return this.sub( v1 );
  1520. }
  1521. }(),
  1522. reflect: function () {
  1523. // reflect incident vector off plane orthogonal to normal
  1524. // normal is assumed to have unit length
  1525. var v1;
  1526. return function reflect( normal ) {
  1527. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1528. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1529. }
  1530. }(),
  1531. angleTo: function ( v ) {
  1532. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1533. // clamp, to handle numerical problems
  1534. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1535. },
  1536. distanceTo: function ( v ) {
  1537. return Math.sqrt( this.distanceToSquared( v ) );
  1538. },
  1539. distanceToSquared: function ( v ) {
  1540. var dx = this.x - v.x;
  1541. var dy = this.y - v.y;
  1542. var dz = this.z - v.z;
  1543. return dx * dx + dy * dy + dz * dz;
  1544. },
  1545. setFromMatrixPosition: function ( m ) {
  1546. this.x = m.elements[ 12 ];
  1547. this.y = m.elements[ 13 ];
  1548. this.z = m.elements[ 14 ];
  1549. return this;
  1550. },
  1551. setFromMatrixScale: function ( m ) {
  1552. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1553. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1554. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1555. this.x = sx;
  1556. this.y = sy;
  1557. this.z = sz;
  1558. return this;
  1559. },
  1560. setFromMatrixColumn: function ( index, matrix ) {
  1561. var offset = index * 4;
  1562. var me = matrix.elements;
  1563. this.x = me[ offset ];
  1564. this.y = me[ offset + 1 ];
  1565. this.z = me[ offset + 2 ];
  1566. return this;
  1567. },
  1568. equals: function ( v ) {
  1569. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1570. },
  1571. fromArray: function ( array, offset ) {
  1572. if ( offset === undefined ) offset = 0;
  1573. this.x = array[ offset ];
  1574. this.y = array[ offset + 1 ];
  1575. this.z = array[ offset + 2 ];
  1576. return this;
  1577. },
  1578. toArray: function ( array, offset ) {
  1579. if ( array === undefined ) array = [];
  1580. if ( offset === undefined ) offset = 0;
  1581. array[ offset ] = this.x;
  1582. array[ offset + 1 ] = this.y;
  1583. array[ offset + 2 ] = this.z;
  1584. return array;
  1585. },
  1586. fromAttribute: function ( attribute, index, offset ) {
  1587. if ( offset === undefined ) offset = 0;
  1588. index = index * attribute.itemSize + offset;
  1589. this.x = attribute.array[ index ];
  1590. this.y = attribute.array[ index + 1 ];
  1591. this.z = attribute.array[ index + 2 ];
  1592. return this;
  1593. }
  1594. };
  1595. // File:src/math/Vector4.js
  1596. /**
  1597. * @author supereggbert / http://www.paulbrunt.co.uk/
  1598. * @author philogb / http://blog.thejit.org/
  1599. * @author mikael emtinger / http://gomo.se/
  1600. * @author egraether / http://egraether.com/
  1601. * @author WestLangley / http://github.com/WestLangley
  1602. */
  1603. THREE.Vector4 = function ( x, y, z, w ) {
  1604. this.x = x || 0;
  1605. this.y = y || 0;
  1606. this.z = z || 0;
  1607. this.w = ( w !== undefined ) ? w : 1;
  1608. };
  1609. THREE.Vector4.prototype = {
  1610. constructor: THREE.Vector4,
  1611. set: function ( x, y, z, w ) {
  1612. this.x = x;
  1613. this.y = y;
  1614. this.z = z;
  1615. this.w = w;
  1616. return this;
  1617. },
  1618. setScalar: function ( scalar ) {
  1619. this.x = scalar;
  1620. this.y = scalar;
  1621. this.z = scalar;
  1622. this.w = scalar;
  1623. return this;
  1624. },
  1625. setX: function ( x ) {
  1626. this.x = x;
  1627. return this;
  1628. },
  1629. setY: function ( y ) {
  1630. this.y = y;
  1631. return this;
  1632. },
  1633. setZ: function ( z ) {
  1634. this.z = z;
  1635. return this;
  1636. },
  1637. setW: function ( w ) {
  1638. this.w = w;
  1639. return this;
  1640. },
  1641. setComponent: function ( index, value ) {
  1642. switch ( index ) {
  1643. case 0: this.x = value; break;
  1644. case 1: this.y = value; break;
  1645. case 2: this.z = value; break;
  1646. case 3: this.w = value; break;
  1647. default: throw new Error( 'index is out of range: ' + index );
  1648. }
  1649. },
  1650. getComponent: function ( index ) {
  1651. switch ( index ) {
  1652. case 0: return this.x;
  1653. case 1: return this.y;
  1654. case 2: return this.z;
  1655. case 3: return this.w;
  1656. default: throw new Error( 'index is out of range: ' + index );
  1657. }
  1658. },
  1659. clone: function () {
  1660. return new this.constructor( this.x, this.y, this.z, this.w );
  1661. },
  1662. copy: function ( v ) {
  1663. this.x = v.x;
  1664. this.y = v.y;
  1665. this.z = v.z;
  1666. this.w = ( v.w !== undefined ) ? v.w : 1;
  1667. return this;
  1668. },
  1669. add: function ( v, w ) {
  1670. if ( w !== undefined ) {
  1671. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1672. return this.addVectors( v, w );
  1673. }
  1674. this.x += v.x;
  1675. this.y += v.y;
  1676. this.z += v.z;
  1677. this.w += v.w;
  1678. return this;
  1679. },
  1680. addScalar: function ( s ) {
  1681. this.x += s;
  1682. this.y += s;
  1683. this.z += s;
  1684. this.w += s;
  1685. return this;
  1686. },
  1687. addVectors: function ( a, b ) {
  1688. this.x = a.x + b.x;
  1689. this.y = a.y + b.y;
  1690. this.z = a.z + b.z;
  1691. this.w = a.w + b.w;
  1692. return this;
  1693. },
  1694. addScaledVector: function ( v, s ) {
  1695. this.x += v.x * s;
  1696. this.y += v.y * s;
  1697. this.z += v.z * s;
  1698. this.w += v.w * s;
  1699. return this;
  1700. },
  1701. sub: function ( v, w ) {
  1702. if ( w !== undefined ) {
  1703. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1704. return this.subVectors( v, w );
  1705. }
  1706. this.x -= v.x;
  1707. this.y -= v.y;
  1708. this.z -= v.z;
  1709. this.w -= v.w;
  1710. return this;
  1711. },
  1712. subScalar: function ( s ) {
  1713. this.x -= s;
  1714. this.y -= s;
  1715. this.z -= s;
  1716. this.w -= s;
  1717. return this;
  1718. },
  1719. subVectors: function ( a, b ) {
  1720. this.x = a.x - b.x;
  1721. this.y = a.y - b.y;
  1722. this.z = a.z - b.z;
  1723. this.w = a.w - b.w;
  1724. return this;
  1725. },
  1726. multiplyScalar: function ( scalar ) {
  1727. if ( isFinite( scalar ) ) {
  1728. this.x *= scalar;
  1729. this.y *= scalar;
  1730. this.z *= scalar;
  1731. this.w *= scalar;
  1732. } else {
  1733. this.x = 0;
  1734. this.y = 0;
  1735. this.z = 0;
  1736. this.w = 0;
  1737. }
  1738. return this;
  1739. },
  1740. applyMatrix4: function ( m ) {
  1741. var x = this.x;
  1742. var y = this.y;
  1743. var z = this.z;
  1744. var w = this.w;
  1745. var e = m.elements;
  1746. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1747. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1748. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1749. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1750. return this;
  1751. },
  1752. divideScalar: function ( scalar ) {
  1753. return this.multiplyScalar( 1 / scalar );
  1754. },
  1755. setAxisAngleFromQuaternion: function ( q ) {
  1756. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1757. // q is assumed to be normalized
  1758. this.w = 2 * Math.acos( q.w );
  1759. var s = Math.sqrt( 1 - q.w * q.w );
  1760. if ( s < 0.0001 ) {
  1761. this.x = 1;
  1762. this.y = 0;
  1763. this.z = 0;
  1764. } else {
  1765. this.x = q.x / s;
  1766. this.y = q.y / s;
  1767. this.z = q.z / s;
  1768. }
  1769. return this;
  1770. },
  1771. setAxisAngleFromRotationMatrix: function ( m ) {
  1772. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1773. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1774. var angle, x, y, z, // variables for result
  1775. epsilon = 0.01, // margin to allow for rounding errors
  1776. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1777. te = m.elements,
  1778. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1779. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1780. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1781. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1782. && ( Math.abs( m13 - m31 ) < epsilon )
  1783. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1784. // singularity found
  1785. // first check for identity matrix which must have +1 for all terms
  1786. // in leading diagonal and zero in other terms
  1787. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1788. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1789. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1790. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1791. // this singularity is identity matrix so angle = 0
  1792. this.set( 1, 0, 0, 0 );
  1793. return this; // zero angle, arbitrary axis
  1794. }
  1795. // otherwise this singularity is angle = 180
  1796. angle = Math.PI;
  1797. var xx = ( m11 + 1 ) / 2;
  1798. var yy = ( m22 + 1 ) / 2;
  1799. var zz = ( m33 + 1 ) / 2;
  1800. var xy = ( m12 + m21 ) / 4;
  1801. var xz = ( m13 + m31 ) / 4;
  1802. var yz = ( m23 + m32 ) / 4;
  1803. if ( ( xx > yy ) && ( xx > zz ) ) {
  1804. // m11 is the largest diagonal term
  1805. if ( xx < epsilon ) {
  1806. x = 0;
  1807. y = 0.707106781;
  1808. z = 0.707106781;
  1809. } else {
  1810. x = Math.sqrt( xx );
  1811. y = xy / x;
  1812. z = xz / x;
  1813. }
  1814. } else if ( yy > zz ) {
  1815. // m22 is the largest diagonal term
  1816. if ( yy < epsilon ) {
  1817. x = 0.707106781;
  1818. y = 0;
  1819. z = 0.707106781;
  1820. } else {
  1821. y = Math.sqrt( yy );
  1822. x = xy / y;
  1823. z = yz / y;
  1824. }
  1825. } else {
  1826. // m33 is the largest diagonal term so base result on this
  1827. if ( zz < epsilon ) {
  1828. x = 0.707106781;
  1829. y = 0.707106781;
  1830. z = 0;
  1831. } else {
  1832. z = Math.sqrt( zz );
  1833. x = xz / z;
  1834. y = yz / z;
  1835. }
  1836. }
  1837. this.set( x, y, z, angle );
  1838. return this; // return 180 deg rotation
  1839. }
  1840. // as we have reached here there are no singularities so we can handle normally
  1841. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1842. + ( m13 - m31 ) * ( m13 - m31 )
  1843. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1844. if ( Math.abs( s ) < 0.001 ) s = 1;
  1845. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1846. // caught by singularity test above, but I've left it in just in case
  1847. this.x = ( m32 - m23 ) / s;
  1848. this.y = ( m13 - m31 ) / s;
  1849. this.z = ( m21 - m12 ) / s;
  1850. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1851. return this;
  1852. },
  1853. min: function ( v ) {
  1854. this.x = Math.min( this.x, v.x );
  1855. this.y = Math.min( this.y, v.y );
  1856. this.z = Math.min( this.z, v.z );
  1857. this.w = Math.min( this.w, v.w );
  1858. return this;
  1859. },
  1860. max: function ( v ) {
  1861. this.x = Math.max( this.x, v.x );
  1862. this.y = Math.max( this.y, v.y );
  1863. this.z = Math.max( this.z, v.z );
  1864. this.w = Math.max( this.w, v.w );
  1865. return this;
  1866. },
  1867. clamp: function ( min, max ) {
  1868. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1869. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1870. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1871. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1872. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1873. return this;
  1874. },
  1875. clampScalar: function () {
  1876. var min, max;
  1877. return function clampScalar( minVal, maxVal ) {
  1878. if ( min === undefined ) {
  1879. min = new THREE.Vector4();
  1880. max = new THREE.Vector4();
  1881. }
  1882. min.set( minVal, minVal, minVal, minVal );
  1883. max.set( maxVal, maxVal, maxVal, maxVal );
  1884. return this.clamp( min, max );
  1885. };
  1886. }(),
  1887. floor: function () {
  1888. this.x = Math.floor( this.x );
  1889. this.y = Math.floor( this.y );
  1890. this.z = Math.floor( this.z );
  1891. this.w = Math.floor( this.w );
  1892. return this;
  1893. },
  1894. ceil: function () {
  1895. this.x = Math.ceil( this.x );
  1896. this.y = Math.ceil( this.y );
  1897. this.z = Math.ceil( this.z );
  1898. this.w = Math.ceil( this.w );
  1899. return this;
  1900. },
  1901. round: function () {
  1902. this.x = Math.round( this.x );
  1903. this.y = Math.round( this.y );
  1904. this.z = Math.round( this.z );
  1905. this.w = Math.round( this.w );
  1906. return this;
  1907. },
  1908. roundToZero: function () {
  1909. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1910. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1911. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1912. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1913. return this;
  1914. },
  1915. negate: function () {
  1916. this.x = - this.x;
  1917. this.y = - this.y;
  1918. this.z = - this.z;
  1919. this.w = - this.w;
  1920. return this;
  1921. },
  1922. dot: function ( v ) {
  1923. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1924. },
  1925. lengthSq: function () {
  1926. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1927. },
  1928. length: function () {
  1929. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1930. },
  1931. lengthManhattan: function () {
  1932. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1933. },
  1934. normalize: function () {
  1935. return this.divideScalar( this.length() );
  1936. },
  1937. setLength: function ( length ) {
  1938. return this.multiplyScalar( length / this.length() );
  1939. },
  1940. lerp: function ( v, alpha ) {
  1941. this.x += ( v.x - this.x ) * alpha;
  1942. this.y += ( v.y - this.y ) * alpha;
  1943. this.z += ( v.z - this.z ) * alpha;
  1944. this.w += ( v.w - this.w ) * alpha;
  1945. return this;
  1946. },
  1947. lerpVectors: function ( v1, v2, alpha ) {
  1948. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1949. return this;
  1950. },
  1951. equals: function ( v ) {
  1952. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1953. },
  1954. fromArray: function ( array, offset ) {
  1955. if ( offset === undefined ) offset = 0;
  1956. this.x = array[ offset ];
  1957. this.y = array[ offset + 1 ];
  1958. this.z = array[ offset + 2 ];
  1959. this.w = array[ offset + 3 ];
  1960. return this;
  1961. },
  1962. toArray: function ( array, offset ) {
  1963. if ( array === undefined ) array = [];
  1964. if ( offset === undefined ) offset = 0;
  1965. array[ offset ] = this.x;
  1966. array[ offset + 1 ] = this.y;
  1967. array[ offset + 2 ] = this.z;
  1968. array[ offset + 3 ] = this.w;
  1969. return array;
  1970. },
  1971. fromAttribute: function ( attribute, index, offset ) {
  1972. if ( offset === undefined ) offset = 0;
  1973. index = index * attribute.itemSize + offset;
  1974. this.x = attribute.array[ index ];
  1975. this.y = attribute.array[ index + 1 ];
  1976. this.z = attribute.array[ index + 2 ];
  1977. this.w = attribute.array[ index + 3 ];
  1978. return this;
  1979. }
  1980. };
  1981. // File:src/math/Euler.js
  1982. /**
  1983. * @author mrdoob / http://mrdoob.com/
  1984. * @author WestLangley / http://github.com/WestLangley
  1985. * @author bhouston / http://clara.io
  1986. */
  1987. THREE.Euler = function ( x, y, z, order ) {
  1988. this._x = x || 0;
  1989. this._y = y || 0;
  1990. this._z = z || 0;
  1991. this._order = order || THREE.Euler.DefaultOrder;
  1992. };
  1993. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1994. THREE.Euler.DefaultOrder = 'XYZ';
  1995. THREE.Euler.prototype = {
  1996. constructor: THREE.Euler,
  1997. get x () {
  1998. return this._x;
  1999. },
  2000. set x ( value ) {
  2001. this._x = value;
  2002. this.onChangeCallback();
  2003. },
  2004. get y () {
  2005. return this._y;
  2006. },
  2007. set y ( value ) {
  2008. this._y = value;
  2009. this.onChangeCallback();
  2010. },
  2011. get z () {
  2012. return this._z;
  2013. },
  2014. set z ( value ) {
  2015. this._z = value;
  2016. this.onChangeCallback();
  2017. },
  2018. get order () {
  2019. return this._order;
  2020. },
  2021. set order ( value ) {
  2022. this._order = value;
  2023. this.onChangeCallback();
  2024. },
  2025. set: function ( x, y, z, order ) {
  2026. this._x = x;
  2027. this._y = y;
  2028. this._z = z;
  2029. this._order = order || this._order;
  2030. this.onChangeCallback();
  2031. return this;
  2032. },
  2033. clone: function () {
  2034. return new this.constructor( this._x, this._y, this._z, this._order);
  2035. },
  2036. copy: function ( euler ) {
  2037. this._x = euler._x;
  2038. this._y = euler._y;
  2039. this._z = euler._z;
  2040. this._order = euler._order;
  2041. this.onChangeCallback();
  2042. return this;
  2043. },
  2044. setFromRotationMatrix: function ( m, order, update ) {
  2045. var clamp = THREE.Math.clamp;
  2046. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2047. var te = m.elements;
  2048. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2049. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2050. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2051. order = order || this._order;
  2052. if ( order === 'XYZ' ) {
  2053. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2054. if ( Math.abs( m13 ) < 0.99999 ) {
  2055. this._x = Math.atan2( - m23, m33 );
  2056. this._z = Math.atan2( - m12, m11 );
  2057. } else {
  2058. this._x = Math.atan2( m32, m22 );
  2059. this._z = 0;
  2060. }
  2061. } else if ( order === 'YXZ' ) {
  2062. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2063. if ( Math.abs( m23 ) < 0.99999 ) {
  2064. this._y = Math.atan2( m13, m33 );
  2065. this._z = Math.atan2( m21, m22 );
  2066. } else {
  2067. this._y = Math.atan2( - m31, m11 );
  2068. this._z = 0;
  2069. }
  2070. } else if ( order === 'ZXY' ) {
  2071. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2072. if ( Math.abs( m32 ) < 0.99999 ) {
  2073. this._y = Math.atan2( - m31, m33 );
  2074. this._z = Math.atan2( - m12, m22 );
  2075. } else {
  2076. this._y = 0;
  2077. this._z = Math.atan2( m21, m11 );
  2078. }
  2079. } else if ( order === 'ZYX' ) {
  2080. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2081. if ( Math.abs( m31 ) < 0.99999 ) {
  2082. this._x = Math.atan2( m32, m33 );
  2083. this._z = Math.atan2( m21, m11 );
  2084. } else {
  2085. this._x = 0;
  2086. this._z = Math.atan2( - m12, m22 );
  2087. }
  2088. } else if ( order === 'YZX' ) {
  2089. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2090. if ( Math.abs( m21 ) < 0.99999 ) {
  2091. this._x = Math.atan2( - m23, m22 );
  2092. this._y = Math.atan2( - m31, m11 );
  2093. } else {
  2094. this._x = 0;
  2095. this._y = Math.atan2( m13, m33 );
  2096. }
  2097. } else if ( order === 'XZY' ) {
  2098. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2099. if ( Math.abs( m12 ) < 0.99999 ) {
  2100. this._x = Math.atan2( m32, m22 );
  2101. this._y = Math.atan2( m13, m11 );
  2102. } else {
  2103. this._x = Math.atan2( - m23, m33 );
  2104. this._y = 0;
  2105. }
  2106. } else {
  2107. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2108. }
  2109. this._order = order;
  2110. if ( update !== false ) this.onChangeCallback();
  2111. return this;
  2112. },
  2113. setFromQuaternion: function () {
  2114. var matrix;
  2115. return function ( q, order, update ) {
  2116. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2117. matrix.makeRotationFromQuaternion( q );
  2118. this.setFromRotationMatrix( matrix, order, update );
  2119. return this;
  2120. };
  2121. }(),
  2122. setFromVector3: function ( v, order ) {
  2123. return this.set( v.x, v.y, v.z, order || this._order );
  2124. },
  2125. reorder: function () {
  2126. // WARNING: this discards revolution information -bhouston
  2127. var q = new THREE.Quaternion();
  2128. return function ( newOrder ) {
  2129. q.setFromEuler( this );
  2130. this.setFromQuaternion( q, newOrder );
  2131. };
  2132. }(),
  2133. equals: function ( euler ) {
  2134. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2135. },
  2136. fromArray: function ( array ) {
  2137. this._x = array[ 0 ];
  2138. this._y = array[ 1 ];
  2139. this._z = array[ 2 ];
  2140. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2141. this.onChangeCallback();
  2142. return this;
  2143. },
  2144. toArray: function ( array, offset ) {
  2145. if ( array === undefined ) array = [];
  2146. if ( offset === undefined ) offset = 0;
  2147. array[ offset ] = this._x;
  2148. array[ offset + 1 ] = this._y;
  2149. array[ offset + 2 ] = this._z;
  2150. array[ offset + 3 ] = this._order;
  2151. return array;
  2152. },
  2153. toVector3: function ( optionalResult ) {
  2154. if ( optionalResult ) {
  2155. return optionalResult.set( this._x, this._y, this._z );
  2156. } else {
  2157. return new THREE.Vector3( this._x, this._y, this._z );
  2158. }
  2159. },
  2160. onChange: function ( callback ) {
  2161. this.onChangeCallback = callback;
  2162. return this;
  2163. },
  2164. onChangeCallback: function () {}
  2165. };
  2166. // File:src/math/Line3.js
  2167. /**
  2168. * @author bhouston / http://clara.io
  2169. */
  2170. THREE.Line3 = function ( start, end ) {
  2171. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2172. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2173. };
  2174. THREE.Line3.prototype = {
  2175. constructor: THREE.Line3,
  2176. set: function ( start, end ) {
  2177. this.start.copy( start );
  2178. this.end.copy( end );
  2179. return this;
  2180. },
  2181. clone: function () {
  2182. return new this.constructor().copy( this );
  2183. },
  2184. copy: function ( line ) {
  2185. this.start.copy( line.start );
  2186. this.end.copy( line.end );
  2187. return this;
  2188. },
  2189. center: function ( optionalTarget ) {
  2190. var result = optionalTarget || new THREE.Vector3();
  2191. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2192. },
  2193. delta: function ( optionalTarget ) {
  2194. var result = optionalTarget || new THREE.Vector3();
  2195. return result.subVectors( this.end, this.start );
  2196. },
  2197. distanceSq: function () {
  2198. return this.start.distanceToSquared( this.end );
  2199. },
  2200. distance: function () {
  2201. return this.start.distanceTo( this.end );
  2202. },
  2203. at: function ( t, optionalTarget ) {
  2204. var result = optionalTarget || new THREE.Vector3();
  2205. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2206. },
  2207. closestPointToPointParameter: function () {
  2208. var startP = new THREE.Vector3();
  2209. var startEnd = new THREE.Vector3();
  2210. return function ( point, clampToLine ) {
  2211. startP.subVectors( point, this.start );
  2212. startEnd.subVectors( this.end, this.start );
  2213. var startEnd2 = startEnd.dot( startEnd );
  2214. var startEnd_startP = startEnd.dot( startP );
  2215. var t = startEnd_startP / startEnd2;
  2216. if ( clampToLine ) {
  2217. t = THREE.Math.clamp( t, 0, 1 );
  2218. }
  2219. return t;
  2220. };
  2221. }(),
  2222. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2223. var t = this.closestPointToPointParameter( point, clampToLine );
  2224. var result = optionalTarget || new THREE.Vector3();
  2225. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2226. },
  2227. applyMatrix4: function ( matrix ) {
  2228. this.start.applyMatrix4( matrix );
  2229. this.end.applyMatrix4( matrix );
  2230. return this;
  2231. },
  2232. equals: function ( line ) {
  2233. return line.start.equals( this.start ) && line.end.equals( this.end );
  2234. }
  2235. };
  2236. // File:src/math/Box2.js
  2237. /**
  2238. * @author bhouston / http://clara.io
  2239. */
  2240. THREE.Box2 = function ( min, max ) {
  2241. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2242. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2243. };
  2244. THREE.Box2.prototype = {
  2245. constructor: THREE.Box2,
  2246. set: function ( min, max ) {
  2247. this.min.copy( min );
  2248. this.max.copy( max );
  2249. return this;
  2250. },
  2251. setFromPoints: function ( points ) {
  2252. this.makeEmpty();
  2253. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2254. this.expandByPoint( points[ i ] )
  2255. }
  2256. return this;
  2257. },
  2258. setFromCenterAndSize: function () {
  2259. var v1 = new THREE.Vector2();
  2260. return function ( center, size ) {
  2261. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2262. this.min.copy( center ).sub( halfSize );
  2263. this.max.copy( center ).add( halfSize );
  2264. return this;
  2265. };
  2266. }(),
  2267. clone: function () {
  2268. return new this.constructor().copy( this );
  2269. },
  2270. copy: function ( box ) {
  2271. this.min.copy( box.min );
  2272. this.max.copy( box.max );
  2273. return this;
  2274. },
  2275. makeEmpty: function () {
  2276. this.min.x = this.min.y = Infinity;
  2277. this.max.x = this.max.y = - Infinity;
  2278. return this;
  2279. },
  2280. empty: function () {
  2281. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2282. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2283. },
  2284. center: function ( optionalTarget ) {
  2285. var result = optionalTarget || new THREE.Vector2();
  2286. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2287. },
  2288. size: function ( optionalTarget ) {
  2289. var result = optionalTarget || new THREE.Vector2();
  2290. return result.subVectors( this.max, this.min );
  2291. },
  2292. expandByPoint: function ( point ) {
  2293. this.min.min( point );
  2294. this.max.max( point );
  2295. return this;
  2296. },
  2297. expandByVector: function ( vector ) {
  2298. this.min.sub( vector );
  2299. this.max.add( vector );
  2300. return this;
  2301. },
  2302. expandByScalar: function ( scalar ) {
  2303. this.min.addScalar( - scalar );
  2304. this.max.addScalar( scalar );
  2305. return this;
  2306. },
  2307. containsPoint: function ( point ) {
  2308. if ( point.x < this.min.x || point.x > this.max.x ||
  2309. point.y < this.min.y || point.y > this.max.y ) {
  2310. return false;
  2311. }
  2312. return true;
  2313. },
  2314. containsBox: function ( box ) {
  2315. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2316. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2317. return true;
  2318. }
  2319. return false;
  2320. },
  2321. getParameter: function ( point, optionalTarget ) {
  2322. // This can potentially have a divide by zero if the box
  2323. // has a size dimension of 0.
  2324. var result = optionalTarget || new THREE.Vector2();
  2325. return result.set(
  2326. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2327. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2328. );
  2329. },
  2330. intersectsBox: function ( box ) {
  2331. // using 6 splitting planes to rule out intersections.
  2332. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2333. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2334. return false;
  2335. }
  2336. return true;
  2337. },
  2338. clampPoint: function ( point, optionalTarget ) {
  2339. var result = optionalTarget || new THREE.Vector2();
  2340. return result.copy( point ).clamp( this.min, this.max );
  2341. },
  2342. distanceToPoint: function () {
  2343. var v1 = new THREE.Vector2();
  2344. return function ( point ) {
  2345. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2346. return clampedPoint.sub( point ).length();
  2347. };
  2348. }(),
  2349. intersect: function ( box ) {
  2350. this.min.max( box.min );
  2351. this.max.min( box.max );
  2352. return this;
  2353. },
  2354. union: function ( box ) {
  2355. this.min.min( box.min );
  2356. this.max.max( box.max );
  2357. return this;
  2358. },
  2359. translate: function ( offset ) {
  2360. this.min.add( offset );
  2361. this.max.add( offset );
  2362. return this;
  2363. },
  2364. equals: function ( box ) {
  2365. return box.min.equals( this.min ) && box.max.equals( this.max );
  2366. }
  2367. };
  2368. // File:src/math/Box3.js
  2369. /**
  2370. * @author bhouston / http://clara.io
  2371. * @author WestLangley / http://github.com/WestLangley
  2372. */
  2373. THREE.Box3 = function ( min, max ) {
  2374. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2375. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2376. };
  2377. THREE.Box3.prototype = {
  2378. constructor: THREE.Box3,
  2379. set: function ( min, max ) {
  2380. this.min.copy( min );
  2381. this.max.copy( max );
  2382. return this;
  2383. },
  2384. setFromPoints: function ( points ) {
  2385. this.makeEmpty();
  2386. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2387. this.expandByPoint( points[ i ] );
  2388. }
  2389. return this;
  2390. },
  2391. setFromCenterAndSize: function () {
  2392. var v1 = new THREE.Vector3();
  2393. return function ( center, size ) {
  2394. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2395. this.min.copy( center ).sub( halfSize );
  2396. this.max.copy( center ).add( halfSize );
  2397. return this;
  2398. };
  2399. }(),
  2400. setFromObject: function () {
  2401. // Computes the world-axis-aligned bounding box of an object (including its children),
  2402. // accounting for both the object's, and children's, world transforms
  2403. var box;
  2404. return function ( object ) {
  2405. if ( box === undefined ) box = new THREE.Box3();
  2406. var scope = this;
  2407. this.makeEmpty();
  2408. object.updateMatrixWorld( true );
  2409. object.traverse( function ( node ) {
  2410. var geometry = node.geometry;
  2411. if ( geometry !== undefined ) {
  2412. if ( geometry.boundingBox === null ) {
  2413. geometry.computeBoundingBox();
  2414. }
  2415. box.copy( geometry.boundingBox );
  2416. box.applyMatrix4( node.matrixWorld );
  2417. scope.union( box );
  2418. }
  2419. } );
  2420. return this;
  2421. };
  2422. }(),
  2423. clone: function () {
  2424. return new this.constructor().copy( this );
  2425. },
  2426. copy: function ( box ) {
  2427. this.min.copy( box.min );
  2428. this.max.copy( box.max );
  2429. return this;
  2430. },
  2431. makeEmpty: function () {
  2432. this.min.x = this.min.y = this.min.z = Infinity;
  2433. this.max.x = this.max.y = this.max.z = - Infinity;
  2434. return this;
  2435. },
  2436. empty: function () {
  2437. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2438. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2439. },
  2440. center: function ( optionalTarget ) {
  2441. var result = optionalTarget || new THREE.Vector3();
  2442. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2443. },
  2444. size: function ( optionalTarget ) {
  2445. var result = optionalTarget || new THREE.Vector3();
  2446. return result.subVectors( this.max, this.min );
  2447. },
  2448. expandByPoint: function ( point ) {
  2449. this.min.min( point );
  2450. this.max.max( point );
  2451. return this;
  2452. },
  2453. expandByVector: function ( vector ) {
  2454. this.min.sub( vector );
  2455. this.max.add( vector );
  2456. return this;
  2457. },
  2458. expandByScalar: function ( scalar ) {
  2459. this.min.addScalar( - scalar );
  2460. this.max.addScalar( scalar );
  2461. return this;
  2462. },
  2463. containsPoint: function ( point ) {
  2464. if ( point.x < this.min.x || point.x > this.max.x ||
  2465. point.y < this.min.y || point.y > this.max.y ||
  2466. point.z < this.min.z || point.z > this.max.z ) {
  2467. return false;
  2468. }
  2469. return true;
  2470. },
  2471. containsBox: function ( box ) {
  2472. if ( ( 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. return true;
  2476. }
  2477. return false;
  2478. },
  2479. getParameter: function ( point, optionalTarget ) {
  2480. // This can potentially have a divide by zero if the box
  2481. // has a size dimension of 0.
  2482. var result = optionalTarget || new THREE.Vector3();
  2483. return result.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. if ( 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 ) {
  2494. return false;
  2495. }
  2496. return true;
  2497. },
  2498. intersectsSphere: ( function () {
  2499. var closestPoint;
  2500. return function intersectsSphere( sphere ) {
  2501. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2502. // Find the point on the AABB closest to the sphere center.
  2503. this.clampPoint( sphere.center, closestPoint );
  2504. // If that point is inside the sphere, the AABB and sphere intersect.
  2505. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2506. };
  2507. } )(),
  2508. intersectsPlane: function ( plane ) {
  2509. // We compute the minimum and maximum dot product values. If those values
  2510. // are on the same side (back or front) of the plane, then there is no intersection.
  2511. var min, max;
  2512. if( plane.normal.x > 0 ) {
  2513. min = plane.normal.x * this.min.x;
  2514. max = plane.normal.x * this.max.x;
  2515. } else {
  2516. min = plane.normal.x * this.max.x;
  2517. max = plane.normal.x * this.min.x;
  2518. }
  2519. if( plane.normal.y > 0 ) {
  2520. min += plane.normal.y * this.min.y;
  2521. max += plane.normal.y * this.max.y;
  2522. } else {
  2523. min += plane.normal.y * this.max.y;
  2524. max += plane.normal.y * this.min.y;
  2525. }
  2526. if( plane.normal.z > 0 ) {
  2527. min += plane.normal.z * this.min.z;
  2528. max += plane.normal.z * this.max.z;
  2529. } else {
  2530. min += plane.normal.z * this.max.z;
  2531. max += plane.normal.z * this.min.z;
  2532. }
  2533. return ( min <= plane.constant && max >= plane.constant );
  2534. },
  2535. clampPoint: function ( point, optionalTarget ) {
  2536. var result = optionalTarget || new THREE.Vector3();
  2537. return result.copy( point ).clamp( this.min, this.max );
  2538. },
  2539. distanceToPoint: function () {
  2540. var v1 = new THREE.Vector3();
  2541. return function ( point ) {
  2542. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2543. return clampedPoint.sub( point ).length();
  2544. };
  2545. }(),
  2546. getBoundingSphere: function () {
  2547. var v1 = new THREE.Vector3();
  2548. return function ( optionalTarget ) {
  2549. var result = optionalTarget || new THREE.Sphere();
  2550. result.center = this.center();
  2551. result.radius = this.size( v1 ).length() * 0.5;
  2552. return result;
  2553. };
  2554. }(),
  2555. intersect: function ( box ) {
  2556. this.min.max( box.min );
  2557. this.max.min( box.max );
  2558. return this;
  2559. },
  2560. union: function ( box ) {
  2561. this.min.min( box.min );
  2562. this.max.max( box.max );
  2563. return this;
  2564. },
  2565. applyMatrix4: function () {
  2566. var points = [
  2567. new THREE.Vector3(),
  2568. new THREE.Vector3(),
  2569. new THREE.Vector3(),
  2570. new THREE.Vector3(),
  2571. new THREE.Vector3(),
  2572. new THREE.Vector3(),
  2573. new THREE.Vector3(),
  2574. new THREE.Vector3()
  2575. ];
  2576. return function ( matrix ) {
  2577. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2578. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2579. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2580. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2581. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2582. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2583. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2584. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2585. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2586. this.makeEmpty();
  2587. this.setFromPoints( points );
  2588. return this;
  2589. };
  2590. }(),
  2591. translate: function ( offset ) {
  2592. this.min.add( offset );
  2593. this.max.add( offset );
  2594. return this;
  2595. },
  2596. equals: function ( box ) {
  2597. return box.min.equals( this.min ) && box.max.equals( this.max );
  2598. }
  2599. };
  2600. // File:src/math/Matrix3.js
  2601. /**
  2602. * @author alteredq / http://alteredqualia.com/
  2603. * @author WestLangley / http://github.com/WestLangley
  2604. * @author bhouston / http://clara.io
  2605. */
  2606. THREE.Matrix3 = function () {
  2607. this.elements = new Float32Array( [
  2608. 1, 0, 0,
  2609. 0, 1, 0,
  2610. 0, 0, 1
  2611. ] );
  2612. if ( arguments.length > 0 ) {
  2613. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2614. }
  2615. };
  2616. THREE.Matrix3.prototype = {
  2617. constructor: THREE.Matrix3,
  2618. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2619. var te = this.elements;
  2620. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2621. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2622. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2623. return this;
  2624. },
  2625. identity: function () {
  2626. this.set(
  2627. 1, 0, 0,
  2628. 0, 1, 0,
  2629. 0, 0, 1
  2630. );
  2631. return this;
  2632. },
  2633. clone: function () {
  2634. return new this.constructor().fromArray( this.elements );
  2635. },
  2636. copy: function ( m ) {
  2637. var me = m.elements;
  2638. this.set(
  2639. me[ 0 ], me[ 3 ], me[ 6 ],
  2640. me[ 1 ], me[ 4 ], me[ 7 ],
  2641. me[ 2 ], me[ 5 ], me[ 8 ]
  2642. );
  2643. return this;
  2644. },
  2645. applyToVector3Array: function () {
  2646. var v1;
  2647. return function ( array, offset, length ) {
  2648. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2649. if ( offset === undefined ) offset = 0;
  2650. if ( length === undefined ) length = array.length;
  2651. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2652. v1.fromArray( array, j );
  2653. v1.applyMatrix3( this );
  2654. v1.toArray( array, j );
  2655. }
  2656. return array;
  2657. };
  2658. }(),
  2659. applyToBuffer: function () {
  2660. var v1;
  2661. return function applyToBuffer( buffer, offset, length ) {
  2662. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2663. if ( offset === undefined ) offset = 0;
  2664. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2665. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2666. v1.x = buffer.getX( j );
  2667. v1.y = buffer.getY( j );
  2668. v1.z = buffer.getZ( j );
  2669. v1.applyMatrix3( this );
  2670. buffer.setXYZ( v1.x, v1.y, v1.z );
  2671. }
  2672. return buffer;
  2673. };
  2674. }(),
  2675. multiplyScalar: function ( s ) {
  2676. var te = this.elements;
  2677. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2678. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2679. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2680. return this;
  2681. },
  2682. determinant: function () {
  2683. var te = this.elements;
  2684. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2685. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2686. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2687. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2688. },
  2689. getInverse: function ( matrix, throwOnDegenerate ) {
  2690. // input: THREE.Matrix4
  2691. // ( based on http://code.google.com/p/webgl-mjs/ )
  2692. var me = matrix.elements;
  2693. var te = this.elements;
  2694. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2695. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2696. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2697. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2698. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2699. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2700. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2701. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2702. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2703. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2704. // no inverse
  2705. if ( det === 0 ) {
  2706. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2707. if ( throwOnDegenerate || false ) {
  2708. throw new Error( msg );
  2709. } else {
  2710. console.warn( msg );
  2711. }
  2712. this.identity();
  2713. return this;
  2714. }
  2715. this.multiplyScalar( 1.0 / det );
  2716. return this;
  2717. },
  2718. transpose: function () {
  2719. var tmp, m = this.elements;
  2720. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2721. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2722. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2723. return this;
  2724. },
  2725. flattenToArrayOffset: function ( array, offset ) {
  2726. var te = this.elements;
  2727. array[ offset ] = te[ 0 ];
  2728. array[ offset + 1 ] = te[ 1 ];
  2729. array[ offset + 2 ] = te[ 2 ];
  2730. array[ offset + 3 ] = te[ 3 ];
  2731. array[ offset + 4 ] = te[ 4 ];
  2732. array[ offset + 5 ] = te[ 5 ];
  2733. array[ offset + 6 ] = te[ 6 ];
  2734. array[ offset + 7 ] = te[ 7 ];
  2735. array[ offset + 8 ] = te[ 8 ];
  2736. return array;
  2737. },
  2738. getNormalMatrix: function ( m ) {
  2739. // input: THREE.Matrix4
  2740. this.getInverse( m ).transpose();
  2741. return this;
  2742. },
  2743. transposeIntoArray: function ( r ) {
  2744. var m = this.elements;
  2745. r[ 0 ] = m[ 0 ];
  2746. r[ 1 ] = m[ 3 ];
  2747. r[ 2 ] = m[ 6 ];
  2748. r[ 3 ] = m[ 1 ];
  2749. r[ 4 ] = m[ 4 ];
  2750. r[ 5 ] = m[ 7 ];
  2751. r[ 6 ] = m[ 2 ];
  2752. r[ 7 ] = m[ 5 ];
  2753. r[ 8 ] = m[ 8 ];
  2754. return this;
  2755. },
  2756. fromArray: function ( array ) {
  2757. this.elements.set( array );
  2758. return this;
  2759. },
  2760. toArray: function () {
  2761. var te = this.elements;
  2762. return [
  2763. te[ 0 ], te[ 1 ], te[ 2 ],
  2764. te[ 3 ], te[ 4 ], te[ 5 ],
  2765. te[ 6 ], te[ 7 ], te[ 8 ]
  2766. ];
  2767. }
  2768. };
  2769. // File:src/math/Matrix4.js
  2770. /**
  2771. * @author mrdoob / http://mrdoob.com/
  2772. * @author supereggbert / http://www.paulbrunt.co.uk/
  2773. * @author philogb / http://blog.thejit.org/
  2774. * @author jordi_ros / http://plattsoft.com
  2775. * @author D1plo1d / http://github.com/D1plo1d
  2776. * @author alteredq / http://alteredqualia.com/
  2777. * @author mikael emtinger / http://gomo.se/
  2778. * @author timknip / http://www.floorplanner.com/
  2779. * @author bhouston / http://clara.io
  2780. * @author WestLangley / http://github.com/WestLangley
  2781. */
  2782. THREE.Matrix4 = function () {
  2783. this.elements = new Float32Array( [
  2784. 1, 0, 0, 0,
  2785. 0, 1, 0, 0,
  2786. 0, 0, 1, 0,
  2787. 0, 0, 0, 1
  2788. ] );
  2789. if ( arguments.length > 0 ) {
  2790. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2791. }
  2792. };
  2793. THREE.Matrix4.prototype = {
  2794. constructor: THREE.Matrix4,
  2795. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2796. var te = this.elements;
  2797. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2798. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2799. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2800. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2801. return this;
  2802. },
  2803. identity: function () {
  2804. this.set(
  2805. 1, 0, 0, 0,
  2806. 0, 1, 0, 0,
  2807. 0, 0, 1, 0,
  2808. 0, 0, 0, 1
  2809. );
  2810. return this;
  2811. },
  2812. clone: function () {
  2813. return new THREE.Matrix4().fromArray( this.elements );
  2814. },
  2815. copy: function ( m ) {
  2816. this.elements.set( m.elements );
  2817. return this;
  2818. },
  2819. copyPosition: function ( m ) {
  2820. var te = this.elements;
  2821. var me = m.elements;
  2822. te[ 12 ] = me[ 12 ];
  2823. te[ 13 ] = me[ 13 ];
  2824. te[ 14 ] = me[ 14 ];
  2825. return this;
  2826. },
  2827. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2828. var te = this.elements;
  2829. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2830. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2831. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2832. return this;
  2833. },
  2834. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2835. this.set(
  2836. xAxis.x, yAxis.x, zAxis.x, 0,
  2837. xAxis.y, yAxis.y, zAxis.y, 0,
  2838. xAxis.z, yAxis.z, zAxis.z, 0,
  2839. 0, 0, 0, 1
  2840. );
  2841. return this;
  2842. },
  2843. extractRotation: function () {
  2844. var v1;
  2845. return function ( m ) {
  2846. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2847. var te = this.elements;
  2848. var me = m.elements;
  2849. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2850. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2851. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2852. te[ 0 ] = me[ 0 ] * scaleX;
  2853. te[ 1 ] = me[ 1 ] * scaleX;
  2854. te[ 2 ] = me[ 2 ] * scaleX;
  2855. te[ 4 ] = me[ 4 ] * scaleY;
  2856. te[ 5 ] = me[ 5 ] * scaleY;
  2857. te[ 6 ] = me[ 6 ] * scaleY;
  2858. te[ 8 ] = me[ 8 ] * scaleZ;
  2859. te[ 9 ] = me[ 9 ] * scaleZ;
  2860. te[ 10 ] = me[ 10 ] * scaleZ;
  2861. return this;
  2862. };
  2863. }(),
  2864. makeRotationFromEuler: function ( euler ) {
  2865. if ( euler instanceof THREE.Euler === false ) {
  2866. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2867. }
  2868. var te = this.elements;
  2869. var x = euler.x, y = euler.y, z = euler.z;
  2870. var a = Math.cos( x ), b = Math.sin( x );
  2871. var c = Math.cos( y ), d = Math.sin( y );
  2872. var e = Math.cos( z ), f = Math.sin( z );
  2873. if ( euler.order === 'XYZ' ) {
  2874. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2875. te[ 0 ] = c * e;
  2876. te[ 4 ] = - c * f;
  2877. te[ 8 ] = d;
  2878. te[ 1 ] = af + be * d;
  2879. te[ 5 ] = ae - bf * d;
  2880. te[ 9 ] = - b * c;
  2881. te[ 2 ] = bf - ae * d;
  2882. te[ 6 ] = be + af * d;
  2883. te[ 10 ] = a * c;
  2884. } else if ( euler.order === 'YXZ' ) {
  2885. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2886. te[ 0 ] = ce + df * b;
  2887. te[ 4 ] = de * b - cf;
  2888. te[ 8 ] = a * d;
  2889. te[ 1 ] = a * f;
  2890. te[ 5 ] = a * e;
  2891. te[ 9 ] = - b;
  2892. te[ 2 ] = cf * b - de;
  2893. te[ 6 ] = df + ce * b;
  2894. te[ 10 ] = a * c;
  2895. } else if ( euler.order === 'ZXY' ) {
  2896. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2897. te[ 0 ] = ce - df * b;
  2898. te[ 4 ] = - a * f;
  2899. te[ 8 ] = de + cf * b;
  2900. te[ 1 ] = cf + de * b;
  2901. te[ 5 ] = a * e;
  2902. te[ 9 ] = df - ce * b;
  2903. te[ 2 ] = - a * d;
  2904. te[ 6 ] = b;
  2905. te[ 10 ] = a * c;
  2906. } else if ( euler.order === 'ZYX' ) {
  2907. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2908. te[ 0 ] = c * e;
  2909. te[ 4 ] = be * d - af;
  2910. te[ 8 ] = ae * d + bf;
  2911. te[ 1 ] = c * f;
  2912. te[ 5 ] = bf * d + ae;
  2913. te[ 9 ] = af * d - be;
  2914. te[ 2 ] = - d;
  2915. te[ 6 ] = b * c;
  2916. te[ 10 ] = a * c;
  2917. } else if ( euler.order === 'YZX' ) {
  2918. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2919. te[ 0 ] = c * e;
  2920. te[ 4 ] = bd - ac * f;
  2921. te[ 8 ] = bc * f + ad;
  2922. te[ 1 ] = f;
  2923. te[ 5 ] = a * e;
  2924. te[ 9 ] = - b * e;
  2925. te[ 2 ] = - d * e;
  2926. te[ 6 ] = ad * f + bc;
  2927. te[ 10 ] = ac - bd * f;
  2928. } else if ( euler.order === 'XZY' ) {
  2929. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2930. te[ 0 ] = c * e;
  2931. te[ 4 ] = - f;
  2932. te[ 8 ] = d * e;
  2933. te[ 1 ] = ac * f + bd;
  2934. te[ 5 ] = a * e;
  2935. te[ 9 ] = ad * f - bc;
  2936. te[ 2 ] = bc * f - ad;
  2937. te[ 6 ] = b * e;
  2938. te[ 10 ] = bd * f + ac;
  2939. }
  2940. // last column
  2941. te[ 3 ] = 0;
  2942. te[ 7 ] = 0;
  2943. te[ 11 ] = 0;
  2944. // bottom row
  2945. te[ 12 ] = 0;
  2946. te[ 13 ] = 0;
  2947. te[ 14 ] = 0;
  2948. te[ 15 ] = 1;
  2949. return this;
  2950. },
  2951. makeRotationFromQuaternion: function ( q ) {
  2952. var te = this.elements;
  2953. var x = q.x, y = q.y, z = q.z, w = q.w;
  2954. var x2 = x + x, y2 = y + y, z2 = z + z;
  2955. var xx = x * x2, xy = x * y2, xz = x * z2;
  2956. var yy = y * y2, yz = y * z2, zz = z * z2;
  2957. var wx = w * x2, wy = w * y2, wz = w * z2;
  2958. te[ 0 ] = 1 - ( yy + zz );
  2959. te[ 4 ] = xy - wz;
  2960. te[ 8 ] = xz + wy;
  2961. te[ 1 ] = xy + wz;
  2962. te[ 5 ] = 1 - ( xx + zz );
  2963. te[ 9 ] = yz - wx;
  2964. te[ 2 ] = xz - wy;
  2965. te[ 6 ] = yz + wx;
  2966. te[ 10 ] = 1 - ( xx + yy );
  2967. // last column
  2968. te[ 3 ] = 0;
  2969. te[ 7 ] = 0;
  2970. te[ 11 ] = 0;
  2971. // bottom row
  2972. te[ 12 ] = 0;
  2973. te[ 13 ] = 0;
  2974. te[ 14 ] = 0;
  2975. te[ 15 ] = 1;
  2976. return this;
  2977. },
  2978. lookAt: function () {
  2979. var x, y, z;
  2980. return function ( eye, target, up ) {
  2981. if ( x === undefined ) x = new THREE.Vector3();
  2982. if ( y === undefined ) y = new THREE.Vector3();
  2983. if ( z === undefined ) z = new THREE.Vector3();
  2984. var te = this.elements;
  2985. z.subVectors( eye, target ).normalize();
  2986. if ( z.lengthSq() === 0 ) {
  2987. z.z = 1;
  2988. }
  2989. x.crossVectors( up, z ).normalize();
  2990. if ( x.lengthSq() === 0 ) {
  2991. z.x += 0.0001;
  2992. x.crossVectors( up, z ).normalize();
  2993. }
  2994. y.crossVectors( z, x );
  2995. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2996. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2997. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2998. return this;
  2999. };
  3000. }(),
  3001. multiply: function ( m, n ) {
  3002. if ( n !== undefined ) {
  3003. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3004. return this.multiplyMatrices( m, n );
  3005. }
  3006. return this.multiplyMatrices( this, m );
  3007. },
  3008. multiplyMatrices: function ( a, b ) {
  3009. var ae = a.elements;
  3010. var be = b.elements;
  3011. var te = this.elements;
  3012. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3013. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3014. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3015. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3016. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3017. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3018. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3019. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3020. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3021. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3022. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3023. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3024. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3025. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3026. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3027. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3028. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3029. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3030. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3031. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3032. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3033. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3034. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3035. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3036. return this;
  3037. },
  3038. multiplyToArray: function ( a, b, r ) {
  3039. var te = this.elements;
  3040. this.multiplyMatrices( a, b );
  3041. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3042. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3043. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3044. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3045. return this;
  3046. },
  3047. multiplyScalar: function ( s ) {
  3048. var te = this.elements;
  3049. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3050. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3051. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3052. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3053. return this;
  3054. },
  3055. applyToVector3Array: function () {
  3056. var v1;
  3057. return function ( array, offset, length ) {
  3058. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3059. if ( offset === undefined ) offset = 0;
  3060. if ( length === undefined ) length = array.length;
  3061. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3062. v1.fromArray( array, j );
  3063. v1.applyMatrix4( this );
  3064. v1.toArray( array, j );
  3065. }
  3066. return array;
  3067. };
  3068. }(),
  3069. applyToBuffer: function () {
  3070. var v1;
  3071. return function applyToBuffer( buffer, offset, length ) {
  3072. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3073. if ( offset === undefined ) offset = 0;
  3074. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3075. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3076. v1.x = buffer.getX( j );
  3077. v1.y = buffer.getY( j );
  3078. v1.z = buffer.getZ( j );
  3079. v1.applyMatrix4( this );
  3080. buffer.setXYZ( v1.x, v1.y, v1.z );
  3081. }
  3082. return buffer;
  3083. };
  3084. }(),
  3085. determinant: function () {
  3086. var te = this.elements;
  3087. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3088. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3089. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3090. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3091. //TODO: make this more efficient
  3092. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3093. return (
  3094. n41 * (
  3095. + n14 * n23 * n32
  3096. - n13 * n24 * n32
  3097. - n14 * n22 * n33
  3098. + n12 * n24 * n33
  3099. + n13 * n22 * n34
  3100. - n12 * n23 * n34
  3101. ) +
  3102. n42 * (
  3103. + n11 * n23 * n34
  3104. - n11 * n24 * n33
  3105. + n14 * n21 * n33
  3106. - n13 * n21 * n34
  3107. + n13 * n24 * n31
  3108. - n14 * n23 * n31
  3109. ) +
  3110. n43 * (
  3111. + n11 * n24 * n32
  3112. - n11 * n22 * n34
  3113. - n14 * n21 * n32
  3114. + n12 * n21 * n34
  3115. + n14 * n22 * n31
  3116. - n12 * n24 * n31
  3117. ) +
  3118. n44 * (
  3119. - n13 * n22 * n31
  3120. - n11 * n23 * n32
  3121. + n11 * n22 * n33
  3122. + n13 * n21 * n32
  3123. - n12 * n21 * n33
  3124. + n12 * n23 * n31
  3125. )
  3126. );
  3127. },
  3128. transpose: function () {
  3129. var te = this.elements;
  3130. var tmp;
  3131. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3132. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3133. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3134. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3135. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3136. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3137. return this;
  3138. },
  3139. flattenToArrayOffset: function ( array, offset ) {
  3140. var te = this.elements;
  3141. array[ offset ] = te[ 0 ];
  3142. array[ offset + 1 ] = te[ 1 ];
  3143. array[ offset + 2 ] = te[ 2 ];
  3144. array[ offset + 3 ] = te[ 3 ];
  3145. array[ offset + 4 ] = te[ 4 ];
  3146. array[ offset + 5 ] = te[ 5 ];
  3147. array[ offset + 6 ] = te[ 6 ];
  3148. array[ offset + 7 ] = te[ 7 ];
  3149. array[ offset + 8 ] = te[ 8 ];
  3150. array[ offset + 9 ] = te[ 9 ];
  3151. array[ offset + 10 ] = te[ 10 ];
  3152. array[ offset + 11 ] = te[ 11 ];
  3153. array[ offset + 12 ] = te[ 12 ];
  3154. array[ offset + 13 ] = te[ 13 ];
  3155. array[ offset + 14 ] = te[ 14 ];
  3156. array[ offset + 15 ] = te[ 15 ];
  3157. return array;
  3158. },
  3159. getPosition: function () {
  3160. var v1;
  3161. return function () {
  3162. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3163. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3164. var te = this.elements;
  3165. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3166. };
  3167. }(),
  3168. setPosition: function ( v ) {
  3169. var te = this.elements;
  3170. te[ 12 ] = v.x;
  3171. te[ 13 ] = v.y;
  3172. te[ 14 ] = v.z;
  3173. return this;
  3174. },
  3175. getInverse: function ( m, throwOnInvertible ) {
  3176. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3177. var te = this.elements;
  3178. var me = m.elements;
  3179. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3180. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3181. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3182. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3183. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3184. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3185. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3186. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3187. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3188. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3189. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3190. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3191. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3192. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3193. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3194. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3195. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3196. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3197. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3198. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3199. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3200. if ( det === 0 ) {
  3201. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3202. if ( throwOnInvertible || false ) {
  3203. throw new Error( msg );
  3204. } else {
  3205. console.warn( msg );
  3206. }
  3207. this.identity();
  3208. return this;
  3209. }
  3210. this.multiplyScalar( 1 / det );
  3211. return this;
  3212. },
  3213. scale: function ( v ) {
  3214. var te = this.elements;
  3215. var x = v.x, y = v.y, z = v.z;
  3216. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3217. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3218. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3219. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3220. return this;
  3221. },
  3222. getMaxScaleOnAxis: function () {
  3223. var te = this.elements;
  3224. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3225. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3226. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3227. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3228. },
  3229. makeTranslation: function ( x, y, z ) {
  3230. this.set(
  3231. 1, 0, 0, x,
  3232. 0, 1, 0, y,
  3233. 0, 0, 1, z,
  3234. 0, 0, 0, 1
  3235. );
  3236. return this;
  3237. },
  3238. makeRotationX: function ( theta ) {
  3239. var c = Math.cos( theta ), s = Math.sin( theta );
  3240. this.set(
  3241. 1, 0, 0, 0,
  3242. 0, c, - s, 0,
  3243. 0, s, c, 0,
  3244. 0, 0, 0, 1
  3245. );
  3246. return this;
  3247. },
  3248. makeRotationY: function ( theta ) {
  3249. var c = Math.cos( theta ), s = Math.sin( theta );
  3250. this.set(
  3251. c, 0, s, 0,
  3252. 0, 1, 0, 0,
  3253. - s, 0, c, 0,
  3254. 0, 0, 0, 1
  3255. );
  3256. return this;
  3257. },
  3258. makeRotationZ: function ( theta ) {
  3259. var c = Math.cos( theta ), s = Math.sin( theta );
  3260. this.set(
  3261. c, - s, 0, 0,
  3262. s, c, 0, 0,
  3263. 0, 0, 1, 0,
  3264. 0, 0, 0, 1
  3265. );
  3266. return this;
  3267. },
  3268. makeRotationAxis: function ( axis, angle ) {
  3269. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3270. var c = Math.cos( angle );
  3271. var s = Math.sin( angle );
  3272. var t = 1 - c;
  3273. var x = axis.x, y = axis.y, z = axis.z;
  3274. var tx = t * x, ty = t * y;
  3275. this.set(
  3276. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3277. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3278. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3279. 0, 0, 0, 1
  3280. );
  3281. return this;
  3282. },
  3283. makeScale: function ( x, y, z ) {
  3284. this.set(
  3285. x, 0, 0, 0,
  3286. 0, y, 0, 0,
  3287. 0, 0, z, 0,
  3288. 0, 0, 0, 1
  3289. );
  3290. return this;
  3291. },
  3292. compose: function ( position, quaternion, scale ) {
  3293. this.makeRotationFromQuaternion( quaternion );
  3294. this.scale( scale );
  3295. this.setPosition( position );
  3296. return this;
  3297. },
  3298. decompose: function () {
  3299. var vector, matrix;
  3300. return function ( position, quaternion, scale ) {
  3301. if ( vector === undefined ) vector = new THREE.Vector3();
  3302. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3303. var te = this.elements;
  3304. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3305. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3306. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3307. // if determine is negative, we need to invert one scale
  3308. var det = this.determinant();
  3309. if ( det < 0 ) {
  3310. sx = - sx;
  3311. }
  3312. position.x = te[ 12 ];
  3313. position.y = te[ 13 ];
  3314. position.z = te[ 14 ];
  3315. // scale the rotation part
  3316. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3317. var invSX = 1 / sx;
  3318. var invSY = 1 / sy;
  3319. var invSZ = 1 / sz;
  3320. matrix.elements[ 0 ] *= invSX;
  3321. matrix.elements[ 1 ] *= invSX;
  3322. matrix.elements[ 2 ] *= invSX;
  3323. matrix.elements[ 4 ] *= invSY;
  3324. matrix.elements[ 5 ] *= invSY;
  3325. matrix.elements[ 6 ] *= invSY;
  3326. matrix.elements[ 8 ] *= invSZ;
  3327. matrix.elements[ 9 ] *= invSZ;
  3328. matrix.elements[ 10 ] *= invSZ;
  3329. quaternion.setFromRotationMatrix( matrix );
  3330. scale.x = sx;
  3331. scale.y = sy;
  3332. scale.z = sz;
  3333. return this;
  3334. };
  3335. }(),
  3336. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3337. var te = this.elements;
  3338. var x = 2 * near / ( right - left );
  3339. var y = 2 * near / ( top - bottom );
  3340. var a = ( right + left ) / ( right - left );
  3341. var b = ( top + bottom ) / ( top - bottom );
  3342. var c = - ( far + near ) / ( far - near );
  3343. var d = - 2 * far * near / ( far - near );
  3344. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3345. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3346. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3347. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3348. return this;
  3349. },
  3350. makePerspective: function ( fov, aspect, near, far ) {
  3351. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3352. var ymin = - ymax;
  3353. var xmin = ymin * aspect;
  3354. var xmax = ymax * aspect;
  3355. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3356. },
  3357. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3358. var te = this.elements;
  3359. var w = right - left;
  3360. var h = top - bottom;
  3361. var p = far - near;
  3362. var x = ( right + left ) / w;
  3363. var y = ( top + bottom ) / h;
  3364. var z = ( far + near ) / p;
  3365. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3366. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3367. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3368. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3369. return this;
  3370. },
  3371. equals: function ( matrix ) {
  3372. var te = this.elements;
  3373. var me = matrix.elements;
  3374. for ( var i = 0; i < 16; i ++ ) {
  3375. if ( te[ i ] !== me[ i ] ) return false;
  3376. }
  3377. return true;
  3378. },
  3379. fromArray: function ( array ) {
  3380. this.elements.set( array );
  3381. return this;
  3382. },
  3383. toArray: function () {
  3384. var te = this.elements;
  3385. return [
  3386. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3387. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3388. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3389. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3390. ];
  3391. }
  3392. };
  3393. // File:src/math/Ray.js
  3394. /**
  3395. * @author bhouston / http://clara.io
  3396. */
  3397. THREE.Ray = function ( origin, direction ) {
  3398. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3399. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3400. };
  3401. THREE.Ray.prototype = {
  3402. constructor: THREE.Ray,
  3403. set: function ( origin, direction ) {
  3404. this.origin.copy( origin );
  3405. this.direction.copy( direction );
  3406. return this;
  3407. },
  3408. clone: function () {
  3409. return new this.constructor().copy( this );
  3410. },
  3411. copy: function ( ray ) {
  3412. this.origin.copy( ray.origin );
  3413. this.direction.copy( ray.direction );
  3414. return this;
  3415. },
  3416. at: function ( t, optionalTarget ) {
  3417. var result = optionalTarget || new THREE.Vector3();
  3418. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3419. },
  3420. recast: function () {
  3421. var v1 = new THREE.Vector3();
  3422. return function ( t ) {
  3423. this.origin.copy( this.at( t, v1 ) );
  3424. return this;
  3425. };
  3426. }(),
  3427. closestPointToPoint: function ( point, optionalTarget ) {
  3428. var result = optionalTarget || new THREE.Vector3();
  3429. result.subVectors( point, this.origin );
  3430. var directionDistance = result.dot( this.direction );
  3431. if ( directionDistance < 0 ) {
  3432. return result.copy( this.origin );
  3433. }
  3434. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3435. },
  3436. distanceToPoint: function ( point ) {
  3437. return Math.sqrt( this.distanceSqToPoint( point ) );
  3438. },
  3439. distanceSqToPoint: function () {
  3440. var v1 = new THREE.Vector3();
  3441. return function ( point ) {
  3442. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3443. // point behind the ray
  3444. if ( directionDistance < 0 ) {
  3445. return this.origin.distanceToSquared( point );
  3446. }
  3447. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3448. return v1.distanceToSquared( point );
  3449. };
  3450. }(),
  3451. distanceSqToSegment: function () {
  3452. var segCenter = new THREE.Vector3();
  3453. var segDir = new THREE.Vector3();
  3454. var diff = new THREE.Vector3();
  3455. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3456. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3457. // It returns the min distance between the ray and the segment
  3458. // defined by v0 and v1
  3459. // It can also set two optional targets :
  3460. // - The closest point on the ray
  3461. // - The closest point on the segment
  3462. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3463. segDir.copy( v1 ).sub( v0 ).normalize();
  3464. diff.copy( this.origin ).sub( segCenter );
  3465. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3466. var a01 = - this.direction.dot( segDir );
  3467. var b0 = diff.dot( this.direction );
  3468. var b1 = - diff.dot( segDir );
  3469. var c = diff.lengthSq();
  3470. var det = Math.abs( 1 - a01 * a01 );
  3471. var s0, s1, sqrDist, extDet;
  3472. if ( det > 0 ) {
  3473. // The ray and segment are not parallel.
  3474. s0 = a01 * b1 - b0;
  3475. s1 = a01 * b0 - b1;
  3476. extDet = segExtent * det;
  3477. if ( s0 >= 0 ) {
  3478. if ( s1 >= - extDet ) {
  3479. if ( s1 <= extDet ) {
  3480. // region 0
  3481. // Minimum at interior points of ray and segment.
  3482. var invDet = 1 / det;
  3483. s0 *= invDet;
  3484. s1 *= invDet;
  3485. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3486. } else {
  3487. // region 1
  3488. s1 = segExtent;
  3489. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3490. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3491. }
  3492. } else {
  3493. // region 5
  3494. s1 = - segExtent;
  3495. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3496. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3497. }
  3498. } else {
  3499. if ( s1 <= - extDet ) {
  3500. // region 4
  3501. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3502. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3503. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3504. } else if ( s1 <= extDet ) {
  3505. // region 3
  3506. s0 = 0;
  3507. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3508. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3509. } else {
  3510. // region 2
  3511. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3512. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3513. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3514. }
  3515. }
  3516. } else {
  3517. // Ray and segment are parallel.
  3518. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3519. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3520. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3521. }
  3522. if ( optionalPointOnRay ) {
  3523. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3524. }
  3525. if ( optionalPointOnSegment ) {
  3526. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3527. }
  3528. return sqrDist;
  3529. };
  3530. }(),
  3531. intersectSphere: function () {
  3532. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3533. var v1 = new THREE.Vector3();
  3534. return function ( sphere, optionalTarget ) {
  3535. v1.subVectors( sphere.center, this.origin );
  3536. var tca = v1.dot( this.direction );
  3537. var d2 = v1.dot( v1 ) - tca * tca;
  3538. var radius2 = sphere.radius * sphere.radius;
  3539. if ( d2 > radius2 ) return null;
  3540. var thc = Math.sqrt( radius2 - d2 );
  3541. // t0 = first intersect point - entrance on front of sphere
  3542. var t0 = tca - thc;
  3543. // t1 = second intersect point - exit point on back of sphere
  3544. var t1 = tca + thc;
  3545. // test to see if both t0 and t1 are behind the ray - if so, return null
  3546. if ( t0 < 0 && t1 < 0 ) return null;
  3547. // test to see if t0 is behind the ray:
  3548. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3549. // in order to always return an intersect point that is in front of the ray.
  3550. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3551. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3552. return this.at( t0, optionalTarget );
  3553. }
  3554. }(),
  3555. intersectsSphere: function ( sphere ) {
  3556. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3557. },
  3558. distanceToPlane: function ( plane ) {
  3559. var denominator = plane.normal.dot( this.direction );
  3560. if ( denominator === 0 ) {
  3561. // line is coplanar, return origin
  3562. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3563. return 0;
  3564. }
  3565. // Null is preferable to undefined since undefined means.... it is undefined
  3566. return null;
  3567. }
  3568. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3569. // Return if the ray never intersects the plane
  3570. return t >= 0 ? t : null;
  3571. },
  3572. intersectPlane: function ( plane, optionalTarget ) {
  3573. var t = this.distanceToPlane( plane );
  3574. if ( t === null ) {
  3575. return null;
  3576. }
  3577. return this.at( t, optionalTarget );
  3578. },
  3579. intersectsPlane: function ( plane ) {
  3580. // check if the ray lies on the plane first
  3581. var distToPoint = plane.distanceToPoint( this.origin );
  3582. if ( distToPoint === 0 ) {
  3583. return true;
  3584. }
  3585. var denominator = plane.normal.dot( this.direction );
  3586. if ( denominator * distToPoint < 0 ) {
  3587. return true;
  3588. }
  3589. // ray origin is behind the plane (and is pointing behind it)
  3590. return false;
  3591. },
  3592. intersectBox: function ( box, optionalTarget ) {
  3593. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3594. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3595. var invdirx = 1 / this.direction.x,
  3596. invdiry = 1 / this.direction.y,
  3597. invdirz = 1 / this.direction.z;
  3598. var origin = this.origin;
  3599. if ( invdirx >= 0 ) {
  3600. tmin = ( box.min.x - origin.x ) * invdirx;
  3601. tmax = ( box.max.x - origin.x ) * invdirx;
  3602. } else {
  3603. tmin = ( box.max.x - origin.x ) * invdirx;
  3604. tmax = ( box.min.x - origin.x ) * invdirx;
  3605. }
  3606. if ( invdiry >= 0 ) {
  3607. tymin = ( box.min.y - origin.y ) * invdiry;
  3608. tymax = ( box.max.y - origin.y ) * invdiry;
  3609. } else {
  3610. tymin = ( box.max.y - origin.y ) * invdiry;
  3611. tymax = ( box.min.y - origin.y ) * invdiry;
  3612. }
  3613. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3614. // These lines also handle the case where tmin or tmax is NaN
  3615. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3616. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3617. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3618. if ( invdirz >= 0 ) {
  3619. tzmin = ( box.min.z - origin.z ) * invdirz;
  3620. tzmax = ( box.max.z - origin.z ) * invdirz;
  3621. } else {
  3622. tzmin = ( box.max.z - origin.z ) * invdirz;
  3623. tzmax = ( box.min.z - origin.z ) * invdirz;
  3624. }
  3625. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3626. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3627. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3628. //return point closest to the ray (positive side)
  3629. if ( tmax < 0 ) return null;
  3630. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3631. },
  3632. intersectsBox: ( function () {
  3633. var v = new THREE.Vector3();
  3634. return function ( box ) {
  3635. return this.intersectBox( box, v ) !== null;
  3636. };
  3637. } )(),
  3638. intersectTriangle: function () {
  3639. // Compute the offset origin, edges, and normal.
  3640. var diff = new THREE.Vector3();
  3641. var edge1 = new THREE.Vector3();
  3642. var edge2 = new THREE.Vector3();
  3643. var normal = new THREE.Vector3();
  3644. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3645. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3646. edge1.subVectors( b, a );
  3647. edge2.subVectors( c, a );
  3648. normal.crossVectors( edge1, edge2 );
  3649. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3650. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3651. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3652. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3653. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3654. var DdN = this.direction.dot( normal );
  3655. var sign;
  3656. if ( DdN > 0 ) {
  3657. if ( backfaceCulling ) return null;
  3658. sign = 1;
  3659. } else if ( DdN < 0 ) {
  3660. sign = - 1;
  3661. DdN = - DdN;
  3662. } else {
  3663. return null;
  3664. }
  3665. diff.subVectors( this.origin, a );
  3666. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3667. // b1 < 0, no intersection
  3668. if ( DdQxE2 < 0 ) {
  3669. return null;
  3670. }
  3671. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3672. // b2 < 0, no intersection
  3673. if ( DdE1xQ < 0 ) {
  3674. return null;
  3675. }
  3676. // b1+b2 > 1, no intersection
  3677. if ( DdQxE2 + DdE1xQ > DdN ) {
  3678. return null;
  3679. }
  3680. // Line intersects triangle, check if ray does.
  3681. var QdN = - sign * diff.dot( normal );
  3682. // t < 0, no intersection
  3683. if ( QdN < 0 ) {
  3684. return null;
  3685. }
  3686. // Ray intersects triangle.
  3687. return this.at( QdN / DdN, optionalTarget );
  3688. };
  3689. }(),
  3690. applyMatrix4: function ( matrix4 ) {
  3691. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3692. this.origin.applyMatrix4( matrix4 );
  3693. this.direction.sub( this.origin );
  3694. this.direction.normalize();
  3695. return this;
  3696. },
  3697. equals: function ( ray ) {
  3698. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3699. }
  3700. };
  3701. // File:src/math/Sphere.js
  3702. /**
  3703. * @author bhouston / http://clara.io
  3704. * @author mrdoob / http://mrdoob.com/
  3705. */
  3706. THREE.Sphere = function ( center, radius ) {
  3707. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3708. this.radius = ( radius !== undefined ) ? radius : 0;
  3709. };
  3710. THREE.Sphere.prototype = {
  3711. constructor: THREE.Sphere,
  3712. set: function ( center, radius ) {
  3713. this.center.copy( center );
  3714. this.radius = radius;
  3715. return this;
  3716. },
  3717. setFromPoints: function () {
  3718. var box = new THREE.Box3();
  3719. return function ( points, optionalCenter ) {
  3720. var center = this.center;
  3721. if ( optionalCenter !== undefined ) {
  3722. center.copy( optionalCenter );
  3723. } else {
  3724. box.setFromPoints( points ).center( center );
  3725. }
  3726. var maxRadiusSq = 0;
  3727. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3728. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3729. }
  3730. this.radius = Math.sqrt( maxRadiusSq );
  3731. return this;
  3732. };
  3733. }(),
  3734. clone: function () {
  3735. return new this.constructor().copy( this );
  3736. },
  3737. copy: function ( sphere ) {
  3738. this.center.copy( sphere.center );
  3739. this.radius = sphere.radius;
  3740. return this;
  3741. },
  3742. empty: function () {
  3743. return ( this.radius <= 0 );
  3744. },
  3745. containsPoint: function ( point ) {
  3746. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3747. },
  3748. distanceToPoint: function ( point ) {
  3749. return ( point.distanceTo( this.center ) - this.radius );
  3750. },
  3751. intersectsSphere: function ( sphere ) {
  3752. var radiusSum = this.radius + sphere.radius;
  3753. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3754. },
  3755. intersectsBox: function ( box ) {
  3756. return box.intersectsSphere( this );
  3757. },
  3758. intersectsPlane: function ( plane ) {
  3759. // We use the following equation to compute the signed distance from
  3760. // the center of the sphere to the plane.
  3761. //
  3762. // distance = q * n - d
  3763. //
  3764. // If this distance is greater than the radius of the sphere,
  3765. // then there is no intersection.
  3766. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3767. },
  3768. clampPoint: function ( point, optionalTarget ) {
  3769. var deltaLengthSq = this.center.distanceToSquared( point );
  3770. var result = optionalTarget || new THREE.Vector3();
  3771. result.copy( point );
  3772. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3773. result.sub( this.center ).normalize();
  3774. result.multiplyScalar( this.radius ).add( this.center );
  3775. }
  3776. return result;
  3777. },
  3778. getBoundingBox: function ( optionalTarget ) {
  3779. var box = optionalTarget || new THREE.Box3();
  3780. box.set( this.center, this.center );
  3781. box.expandByScalar( this.radius );
  3782. return box;
  3783. },
  3784. applyMatrix4: function ( matrix ) {
  3785. this.center.applyMatrix4( matrix );
  3786. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3787. return this;
  3788. },
  3789. translate: function ( offset ) {
  3790. this.center.add( offset );
  3791. return this;
  3792. },
  3793. equals: function ( sphere ) {
  3794. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3795. }
  3796. };
  3797. // File:src/math/Frustum.js
  3798. /**
  3799. * @author mrdoob / http://mrdoob.com/
  3800. * @author alteredq / http://alteredqualia.com/
  3801. * @author bhouston / http://clara.io
  3802. */
  3803. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3804. this.planes = [
  3805. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3806. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3807. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3808. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3809. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3810. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3811. ];
  3812. };
  3813. THREE.Frustum.prototype = {
  3814. constructor: THREE.Frustum,
  3815. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3816. var planes = this.planes;
  3817. planes[ 0 ].copy( p0 );
  3818. planes[ 1 ].copy( p1 );
  3819. planes[ 2 ].copy( p2 );
  3820. planes[ 3 ].copy( p3 );
  3821. planes[ 4 ].copy( p4 );
  3822. planes[ 5 ].copy( p5 );
  3823. return this;
  3824. },
  3825. clone: function () {
  3826. return new this.constructor().copy( this );
  3827. },
  3828. copy: function ( frustum ) {
  3829. var planes = this.planes;
  3830. for ( var i = 0; i < 6; i ++ ) {
  3831. planes[ i ].copy( frustum.planes[ i ] );
  3832. }
  3833. return this;
  3834. },
  3835. setFromMatrix: function ( m ) {
  3836. var planes = this.planes;
  3837. var me = m.elements;
  3838. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3839. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3840. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3841. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3842. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3843. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3844. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3845. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3846. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3847. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3848. return this;
  3849. },
  3850. intersectsObject: function () {
  3851. var sphere = new THREE.Sphere();
  3852. return function ( object ) {
  3853. var geometry = object.geometry;
  3854. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3855. sphere.copy( geometry.boundingSphere );
  3856. sphere.applyMatrix4( object.matrixWorld );
  3857. return this.intersectsSphere( sphere );
  3858. };
  3859. }(),
  3860. intersectsSphere: function ( sphere ) {
  3861. var planes = this.planes;
  3862. var center = sphere.center;
  3863. var negRadius = - sphere.radius;
  3864. for ( var i = 0; i < 6; i ++ ) {
  3865. var distance = planes[ i ].distanceToPoint( center );
  3866. if ( distance < negRadius ) {
  3867. return false;
  3868. }
  3869. }
  3870. return true;
  3871. },
  3872. intersectsBox: function () {
  3873. var p1 = new THREE.Vector3(),
  3874. p2 = new THREE.Vector3();
  3875. return function ( box ) {
  3876. var planes = this.planes;
  3877. for ( var i = 0; i < 6 ; i ++ ) {
  3878. var plane = planes[ i ];
  3879. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3880. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3881. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3882. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3883. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3884. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3885. var d1 = plane.distanceToPoint( p1 );
  3886. var d2 = plane.distanceToPoint( p2 );
  3887. // if both outside plane, no intersection
  3888. if ( d1 < 0 && d2 < 0 ) {
  3889. return false;
  3890. }
  3891. }
  3892. return true;
  3893. };
  3894. }(),
  3895. containsPoint: function ( point ) {
  3896. var planes = this.planes;
  3897. for ( var i = 0; i < 6; i ++ ) {
  3898. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3899. return false;
  3900. }
  3901. }
  3902. return true;
  3903. }
  3904. };
  3905. // File:src/math/Plane.js
  3906. /**
  3907. * @author bhouston / http://clara.io
  3908. */
  3909. THREE.Plane = function ( normal, constant ) {
  3910. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3911. this.constant = ( constant !== undefined ) ? constant : 0;
  3912. };
  3913. THREE.Plane.prototype = {
  3914. constructor: THREE.Plane,
  3915. set: function ( normal, constant ) {
  3916. this.normal.copy( normal );
  3917. this.constant = constant;
  3918. return this;
  3919. },
  3920. setComponents: function ( x, y, z, w ) {
  3921. this.normal.set( x, y, z );
  3922. this.constant = w;
  3923. return this;
  3924. },
  3925. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3926. this.normal.copy( normal );
  3927. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3928. return this;
  3929. },
  3930. setFromCoplanarPoints: function () {
  3931. var v1 = new THREE.Vector3();
  3932. var v2 = new THREE.Vector3();
  3933. return function ( a, b, c ) {
  3934. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3935. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3936. this.setFromNormalAndCoplanarPoint( normal, a );
  3937. return this;
  3938. };
  3939. }(),
  3940. clone: function () {
  3941. return new this.constructor().copy( this );
  3942. },
  3943. copy: function ( plane ) {
  3944. this.normal.copy( plane.normal );
  3945. this.constant = plane.constant;
  3946. return this;
  3947. },
  3948. normalize: function () {
  3949. // Note: will lead to a divide by zero if the plane is invalid.
  3950. var inverseNormalLength = 1.0 / this.normal.length();
  3951. this.normal.multiplyScalar( inverseNormalLength );
  3952. this.constant *= inverseNormalLength;
  3953. return this;
  3954. },
  3955. negate: function () {
  3956. this.constant *= - 1;
  3957. this.normal.negate();
  3958. return this;
  3959. },
  3960. distanceToPoint: function ( point ) {
  3961. return this.normal.dot( point ) + this.constant;
  3962. },
  3963. distanceToSphere: function ( sphere ) {
  3964. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3965. },
  3966. projectPoint: function ( point, optionalTarget ) {
  3967. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3968. },
  3969. orthoPoint: function ( point, optionalTarget ) {
  3970. var perpendicularMagnitude = this.distanceToPoint( point );
  3971. var result = optionalTarget || new THREE.Vector3();
  3972. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3973. },
  3974. intersectLine: function () {
  3975. var v1 = new THREE.Vector3();
  3976. return function ( line, optionalTarget ) {
  3977. var result = optionalTarget || new THREE.Vector3();
  3978. var direction = line.delta( v1 );
  3979. var denominator = this.normal.dot( direction );
  3980. if ( denominator === 0 ) {
  3981. // line is coplanar, return origin
  3982. if ( this.distanceToPoint( line.start ) === 0 ) {
  3983. return result.copy( line.start );
  3984. }
  3985. // Unsure if this is the correct method to handle this case.
  3986. return undefined;
  3987. }
  3988. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3989. if ( t < 0 || t > 1 ) {
  3990. return undefined;
  3991. }
  3992. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3993. };
  3994. }(),
  3995. intersectsLine: function ( line ) {
  3996. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3997. var startSign = this.distanceToPoint( line.start );
  3998. var endSign = this.distanceToPoint( line.end );
  3999. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4000. },
  4001. intersectsBox: function ( box ) {
  4002. return box.intersectsPlane( this );
  4003. },
  4004. intersectsSphere: function ( sphere ) {
  4005. return sphere.intersectsPlane( this );
  4006. },
  4007. coplanarPoint: function ( optionalTarget ) {
  4008. var result = optionalTarget || new THREE.Vector3();
  4009. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4010. },
  4011. applyMatrix4: function () {
  4012. var v1 = new THREE.Vector3();
  4013. var v2 = new THREE.Vector3();
  4014. var m1 = new THREE.Matrix3();
  4015. return function ( matrix, optionalNormalMatrix ) {
  4016. // compute new normal based on theory here:
  4017. // http://www.songho.ca/opengl/gl_normaltransform.html
  4018. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4019. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4020. var newCoplanarPoint = this.coplanarPoint( v2 );
  4021. newCoplanarPoint.applyMatrix4( matrix );
  4022. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4023. return this;
  4024. };
  4025. }(),
  4026. translate: function ( offset ) {
  4027. this.constant = this.constant - offset.dot( this.normal );
  4028. return this;
  4029. },
  4030. equals: function ( plane ) {
  4031. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4032. }
  4033. };
  4034. // File:src/math/Math.js
  4035. /**
  4036. * @author alteredq / http://alteredqualia.com/
  4037. * @author mrdoob / http://mrdoob.com/
  4038. */
  4039. THREE.Math = {
  4040. generateUUID: function () {
  4041. // http://www.broofa.com/Tools/Math.uuid.htm
  4042. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4043. var uuid = new Array( 36 );
  4044. var rnd = 0, r;
  4045. return function () {
  4046. for ( var i = 0; i < 36; i ++ ) {
  4047. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4048. uuid[ i ] = '-';
  4049. } else if ( i === 14 ) {
  4050. uuid[ i ] = '4';
  4051. } else {
  4052. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4053. r = rnd & 0xf;
  4054. rnd = rnd >> 4;
  4055. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4056. }
  4057. }
  4058. return uuid.join( '' );
  4059. };
  4060. }(),
  4061. clamp: function ( value, min, max ) {
  4062. return Math.max( min, Math.min( max, value ) );
  4063. },
  4064. // compute euclidian modulo of m % n
  4065. // https://en.wikipedia.org/wiki/Modulo_operation
  4066. euclideanModulo: function ( n, m ) {
  4067. return ( ( n % m ) + m ) % m;
  4068. },
  4069. // Linear mapping from range <a1, a2> to range <b1, b2>
  4070. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4071. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4072. },
  4073. // http://en.wikipedia.org/wiki/Smoothstep
  4074. smoothstep: function ( x, min, max ) {
  4075. if ( x <= min ) return 0;
  4076. if ( x >= max ) return 1;
  4077. x = ( x - min ) / ( max - min );
  4078. return x * x * ( 3 - 2 * x );
  4079. },
  4080. smootherstep: function ( x, min, max ) {
  4081. if ( x <= min ) return 0;
  4082. if ( x >= max ) return 1;
  4083. x = ( x - min ) / ( max - min );
  4084. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4085. },
  4086. // Random float from <0, 1> with 16 bits of randomness
  4087. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4088. random16: function () {
  4089. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4090. },
  4091. // Random integer from <low, high> interval
  4092. randInt: function ( low, high ) {
  4093. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4094. },
  4095. // Random float from <low, high> interval
  4096. randFloat: function ( low, high ) {
  4097. return low + Math.random() * ( high - low );
  4098. },
  4099. // Random float from <-range/2, range/2> interval
  4100. randFloatSpread: function ( range ) {
  4101. return range * ( 0.5 - Math.random() );
  4102. },
  4103. degToRad: function () {
  4104. var degreeToRadiansFactor = Math.PI / 180;
  4105. return function ( degrees ) {
  4106. return degrees * degreeToRadiansFactor;
  4107. };
  4108. }(),
  4109. radToDeg: function () {
  4110. var radianToDegreesFactor = 180 / Math.PI;
  4111. return function ( radians ) {
  4112. return radians * radianToDegreesFactor;
  4113. };
  4114. }(),
  4115. isPowerOfTwo: function ( value ) {
  4116. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4117. },
  4118. nearestPowerOfTwo: function ( value ) {
  4119. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4120. },
  4121. nextPowerOfTwo: function ( value ) {
  4122. value --;
  4123. value |= value >> 1;
  4124. value |= value >> 2;
  4125. value |= value >> 4;
  4126. value |= value >> 8;
  4127. value |= value >> 16;
  4128. value ++;
  4129. return value;
  4130. }
  4131. };
  4132. // File:src/math/Spline.js
  4133. /**
  4134. * Spline from Tween.js, slightly optimized (and trashed)
  4135. * http://sole.github.com/tween.js/examples/05_spline.html
  4136. *
  4137. * @author mrdoob / http://mrdoob.com/
  4138. * @author alteredq / http://alteredqualia.com/
  4139. */
  4140. THREE.Spline = function ( points ) {
  4141. this.points = points;
  4142. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4143. point, intPoint, weight, w2, w3,
  4144. pa, pb, pc, pd;
  4145. this.initFromArray = function ( a ) {
  4146. this.points = [];
  4147. for ( var i = 0; i < a.length; i ++ ) {
  4148. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4149. }
  4150. };
  4151. this.getPoint = function ( k ) {
  4152. point = ( this.points.length - 1 ) * k;
  4153. intPoint = Math.floor( point );
  4154. weight = point - intPoint;
  4155. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4156. c[ 1 ] = intPoint;
  4157. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4158. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4159. pa = this.points[ c[ 0 ] ];
  4160. pb = this.points[ c[ 1 ] ];
  4161. pc = this.points[ c[ 2 ] ];
  4162. pd = this.points[ c[ 3 ] ];
  4163. w2 = weight * weight;
  4164. w3 = weight * w2;
  4165. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4166. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4167. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4168. return v3;
  4169. };
  4170. this.getControlPointsArray = function () {
  4171. var i, p, l = this.points.length,
  4172. coords = [];
  4173. for ( i = 0; i < l; i ++ ) {
  4174. p = this.points[ i ];
  4175. coords[ i ] = [ p.x, p.y, p.z ];
  4176. }
  4177. return coords;
  4178. };
  4179. // approximate length by summing linear segments
  4180. this.getLength = function ( nSubDivisions ) {
  4181. var i, index, nSamples, position,
  4182. point = 0, intPoint = 0, oldIntPoint = 0,
  4183. oldPosition = new THREE.Vector3(),
  4184. tmpVec = new THREE.Vector3(),
  4185. chunkLengths = [],
  4186. totalLength = 0;
  4187. // first point has 0 length
  4188. chunkLengths[ 0 ] = 0;
  4189. if ( ! nSubDivisions ) nSubDivisions = 100;
  4190. nSamples = this.points.length * nSubDivisions;
  4191. oldPosition.copy( this.points[ 0 ] );
  4192. for ( i = 1; i < nSamples; i ++ ) {
  4193. index = i / nSamples;
  4194. position = this.getPoint( index );
  4195. tmpVec.copy( position );
  4196. totalLength += tmpVec.distanceTo( oldPosition );
  4197. oldPosition.copy( position );
  4198. point = ( this.points.length - 1 ) * index;
  4199. intPoint = Math.floor( point );
  4200. if ( intPoint !== oldIntPoint ) {
  4201. chunkLengths[ intPoint ] = totalLength;
  4202. oldIntPoint = intPoint;
  4203. }
  4204. }
  4205. // last point ends with total length
  4206. chunkLengths[ chunkLengths.length ] = totalLength;
  4207. return { chunks: chunkLengths, total: totalLength };
  4208. };
  4209. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4210. var i, j,
  4211. index, indexCurrent, indexNext,
  4212. realDistance,
  4213. sampling, position,
  4214. newpoints = [],
  4215. tmpVec = new THREE.Vector3(),
  4216. sl = this.getLength();
  4217. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4218. for ( i = 1; i < this.points.length; i ++ ) {
  4219. //tmpVec.copy( this.points[ i - 1 ] );
  4220. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4221. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4222. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4223. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4224. indexNext = i / ( this.points.length - 1 );
  4225. for ( j = 1; j < sampling - 1; j ++ ) {
  4226. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4227. position = this.getPoint( index );
  4228. newpoints.push( tmpVec.copy( position ).clone() );
  4229. }
  4230. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4231. }
  4232. this.points = newpoints;
  4233. };
  4234. // Catmull-Rom
  4235. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4236. var v0 = ( p2 - p0 ) * 0.5,
  4237. v1 = ( p3 - p1 ) * 0.5;
  4238. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4239. }
  4240. };
  4241. // File:src/math/Triangle.js
  4242. /**
  4243. * @author bhouston / http://clara.io
  4244. * @author mrdoob / http://mrdoob.com/
  4245. */
  4246. THREE.Triangle = function ( a, b, c ) {
  4247. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4248. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4249. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4250. };
  4251. THREE.Triangle.normal = function () {
  4252. var v0 = new THREE.Vector3();
  4253. return function ( a, b, c, optionalTarget ) {
  4254. var result = optionalTarget || new THREE.Vector3();
  4255. result.subVectors( c, b );
  4256. v0.subVectors( a, b );
  4257. result.cross( v0 );
  4258. var resultLengthSq = result.lengthSq();
  4259. if ( resultLengthSq > 0 ) {
  4260. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4261. }
  4262. return result.set( 0, 0, 0 );
  4263. };
  4264. }();
  4265. // static/instance method to calculate barycentric coordinates
  4266. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4267. THREE.Triangle.barycoordFromPoint = function () {
  4268. var v0 = new THREE.Vector3();
  4269. var v1 = new THREE.Vector3();
  4270. var v2 = new THREE.Vector3();
  4271. return function ( point, a, b, c, optionalTarget ) {
  4272. v0.subVectors( c, a );
  4273. v1.subVectors( b, a );
  4274. v2.subVectors( point, a );
  4275. var dot00 = v0.dot( v0 );
  4276. var dot01 = v0.dot( v1 );
  4277. var dot02 = v0.dot( v2 );
  4278. var dot11 = v1.dot( v1 );
  4279. var dot12 = v1.dot( v2 );
  4280. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4281. var result = optionalTarget || new THREE.Vector3();
  4282. // collinear or singular triangle
  4283. if ( denom === 0 ) {
  4284. // arbitrary location outside of triangle?
  4285. // not sure if this is the best idea, maybe should be returning undefined
  4286. return result.set( - 2, - 1, - 1 );
  4287. }
  4288. var invDenom = 1 / denom;
  4289. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4290. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4291. // barycentric coordinates must always sum to 1
  4292. return result.set( 1 - u - v, v, u );
  4293. };
  4294. }();
  4295. THREE.Triangle.containsPoint = function () {
  4296. var v1 = new THREE.Vector3();
  4297. return function ( point, a, b, c ) {
  4298. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4299. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4300. };
  4301. }();
  4302. THREE.Triangle.prototype = {
  4303. constructor: THREE.Triangle,
  4304. set: function ( a, b, c ) {
  4305. this.a.copy( a );
  4306. this.b.copy( b );
  4307. this.c.copy( c );
  4308. return this;
  4309. },
  4310. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4311. this.a.copy( points[ i0 ] );
  4312. this.b.copy( points[ i1 ] );
  4313. this.c.copy( points[ i2 ] );
  4314. return this;
  4315. },
  4316. clone: function () {
  4317. return new this.constructor().copy( this );
  4318. },
  4319. copy: function ( triangle ) {
  4320. this.a.copy( triangle.a );
  4321. this.b.copy( triangle.b );
  4322. this.c.copy( triangle.c );
  4323. return this;
  4324. },
  4325. area: function () {
  4326. var v0 = new THREE.Vector3();
  4327. var v1 = new THREE.Vector3();
  4328. return function () {
  4329. v0.subVectors( this.c, this.b );
  4330. v1.subVectors( this.a, this.b );
  4331. return v0.cross( v1 ).length() * 0.5;
  4332. };
  4333. }(),
  4334. midpoint: function ( optionalTarget ) {
  4335. var result = optionalTarget || new THREE.Vector3();
  4336. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4337. },
  4338. normal: function ( optionalTarget ) {
  4339. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4340. },
  4341. plane: function ( optionalTarget ) {
  4342. var result = optionalTarget || new THREE.Plane();
  4343. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4344. },
  4345. barycoordFromPoint: function ( point, optionalTarget ) {
  4346. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4347. },
  4348. containsPoint: function ( point ) {
  4349. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4350. },
  4351. equals: function ( triangle ) {
  4352. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4353. }
  4354. };
  4355. // File:src/math/Interpolant.js
  4356. /**
  4357. * Abstract base class of interpolants over parametric samples.
  4358. *
  4359. * The parameter domain is one dimensional, typically the time or a path
  4360. * along a curve defined by the data.
  4361. *
  4362. * The sample values can have any dimensionality and derived classes may
  4363. * apply special interpretations to the data.
  4364. *
  4365. * This class provides the interval seek in a Template Method, deferring
  4366. * the actual interpolation to derived classes.
  4367. *
  4368. * Time complexity is O(1) for linear access crossing at most two points
  4369. * and O(log N) for random access, where N is the number of positions.
  4370. *
  4371. * References:
  4372. *
  4373. * http://www.oodesign.com/template-method-pattern.html
  4374. *
  4375. * @author tschw
  4376. */
  4377. THREE.Interpolant = function(
  4378. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4379. this.parameterPositions = parameterPositions;
  4380. this._cachedIndex = 0;
  4381. this.resultBuffer = resultBuffer !== undefined ?
  4382. resultBuffer : new sampleValues.constructor( sampleSize );
  4383. this.sampleValues = sampleValues;
  4384. this.valueSize = sampleSize;
  4385. };
  4386. THREE.Interpolant.prototype = {
  4387. constructor: THREE.Intepolant,
  4388. evaluate: function( t ) {
  4389. var pp = this.parameterPositions,
  4390. i1 = this._cachedIndex,
  4391. t1 = pp[ i1 ],
  4392. t0 = pp[ i1 - 1 ];
  4393. validate_interval: {
  4394. seek: {
  4395. var right;
  4396. linear_scan: {
  4397. //- See http://jsperf.com/comparison-to-undefined/3
  4398. //- slower code:
  4399. //-
  4400. //- if ( t >= t1 || t1 === undefined ) {
  4401. forward_scan: if ( ! ( t < t1 ) ) {
  4402. for ( var giveUpAt = i1 + 2; ;) {
  4403. if ( t1 === undefined ) {
  4404. if ( t < t0 ) break forward_scan;
  4405. // after end
  4406. i1 = pp.length;
  4407. this._cachedIndex = i1;
  4408. return this.afterEnd_( i1 - 1, t, t0 );
  4409. }
  4410. if ( i1 === giveUpAt ) break; // this loop
  4411. t0 = t1;
  4412. t1 = pp[ ++ i1 ];
  4413. if ( t < t1 ) {
  4414. // we have arrived at the sought interval
  4415. break seek;
  4416. }
  4417. }
  4418. // prepare binary search on the right side of the index
  4419. right = pp.length;
  4420. break linear_scan;
  4421. }
  4422. //- slower code:
  4423. //- if ( t < t0 || t0 === undefined ) {
  4424. if ( ! ( t >= t0 ) ) {
  4425. // looping?
  4426. var t1global = pp[ 1 ];
  4427. if ( t < t1global ) {
  4428. i1 = 2; // + 1, using the scan for the details
  4429. t0 = t1global;
  4430. }
  4431. // linear reverse scan
  4432. for ( var giveUpAt = i1 - 2; ;) {
  4433. if ( t0 === undefined ) {
  4434. // before start
  4435. this._cachedIndex = 0;
  4436. return this.beforeStart_( 0, t, t1 );
  4437. }
  4438. if ( i1 === giveUpAt ) break; // this loop
  4439. t1 = t0;
  4440. t0 = pp[ -- i1 - 1 ];
  4441. if ( t >= t0 ) {
  4442. // we have arrived at the sought interval
  4443. break seek;
  4444. }
  4445. }
  4446. // prepare binary search on the left side of the index
  4447. right = i1;
  4448. i1 = 0;
  4449. break linear_scan;
  4450. }
  4451. // the interval is valid
  4452. break validate_interval;
  4453. } // linear scan
  4454. // binary search
  4455. while ( i1 < right ) {
  4456. var mid = ( i1 + right ) >>> 1;
  4457. if ( t < pp[ mid ] ) {
  4458. right = mid;
  4459. } else {
  4460. i1 = mid + 1;
  4461. }
  4462. }
  4463. t1 = pp[ i1 ];
  4464. t0 = pp[ i1 - 1 ];
  4465. // check boundary cases, again
  4466. if ( t0 === undefined ) {
  4467. this._cachedIndex = 0;
  4468. return this.beforeStart_( 0, t, t1 );
  4469. }
  4470. if ( t1 === undefined ) {
  4471. i1 = pp.length;
  4472. this._cachedIndex = i1;
  4473. return this.afterEnd_( i1 - 1, t0, t );
  4474. }
  4475. } // seek
  4476. this._cachedIndex = i1;
  4477. this.intervalChanged_( i1, t0, t1 );
  4478. } // validate_interval
  4479. return this.interpolate_( i1, t0, t, t1 );
  4480. },
  4481. settings: null, // optional, subclass-specific settings structure
  4482. // Note: The indirection allows central control of many interpolants.
  4483. // --- Protected interface
  4484. DefaultSettings_: {},
  4485. getSettings_: function() {
  4486. return this.settings || this.DefaultSettings_;
  4487. },
  4488. copySampleValue_: function( index ) {
  4489. // copies a sample value to the result buffer
  4490. var result = this.resultBuffer,
  4491. values = this.sampleValues,
  4492. stride = this.valueSize,
  4493. offset = index * stride;
  4494. for ( var i = 0; i !== stride; ++ i ) {
  4495. result[ i ] = values[ offset + i ];
  4496. }
  4497. return result;
  4498. },
  4499. // Template methods for derived classes:
  4500. interpolate_: function( i1, t0, t, t1 ) {
  4501. throw new Error( "call to abstract method" );
  4502. // implementations shall return this.resultBuffer
  4503. },
  4504. intervalChanged_: function( i1, t0, t1 ) {
  4505. // empty
  4506. }
  4507. };
  4508. Object.assign( THREE.Interpolant.prototype, {
  4509. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4510. THREE.Interpolant.prototype.copySampleValue_,
  4511. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4512. THREE.Interpolant.prototype.copySampleValue_
  4513. } );
  4514. // File:src/math/interpolants/CubicInterpolant.js
  4515. /**
  4516. * Fast and simple cubic spline interpolant.
  4517. *
  4518. * It was derived from a Hermitian construction setting the first derivative
  4519. * at each sample position to the linear slope between neighboring positions
  4520. * over their parameter interval.
  4521. *
  4522. * @author tschw
  4523. */
  4524. THREE.CubicInterpolant = function(
  4525. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4526. THREE.Interpolant.call(
  4527. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4528. this._weightPrev = -0;
  4529. this._offsetPrev = -0;
  4530. this._weightNext = -0;
  4531. this._offsetNext = -0;
  4532. };
  4533. THREE.CubicInterpolant.prototype =
  4534. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4535. constructor: THREE.CubicInterpolant,
  4536. DefaultSettings_: {
  4537. endingStart: THREE.ZeroCurvatureEnding,
  4538. endingEnd: THREE.ZeroCurvatureEnding
  4539. },
  4540. intervalChanged_: function( i1, t0, t1 ) {
  4541. var pp = this.parameterPositions,
  4542. iPrev = i1 - 2,
  4543. iNext = i1 + 1,
  4544. tPrev = pp[ iPrev ],
  4545. tNext = pp[ iNext ];
  4546. if ( tPrev === undefined ) {
  4547. switch ( this.getSettings_().endingStart ) {
  4548. case THREE.ZeroSlopeEnding:
  4549. // f'(t0) = 0
  4550. iPrev = i1;
  4551. tPrev = 2 * t0 - t1;
  4552. break;
  4553. case THREE.WrapAroundEnding:
  4554. // use the other end of the curve
  4555. iPrev = pp.length - 2;
  4556. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4557. break;
  4558. default: // ZeroCurvatureEnding
  4559. // f''(t0) = 0 a.k.a. Natural Spline
  4560. iPrev = i1;
  4561. tPrev = t1;
  4562. }
  4563. }
  4564. if ( tNext === undefined ) {
  4565. switch ( this.getSettings_().endingEnd ) {
  4566. case THREE.ZeroSlopeEnding:
  4567. // f'(tN) = 0
  4568. iNext = i1;
  4569. tNext = 2 * t1 - t0;
  4570. break;
  4571. case THREE.WrapAroundEnding:
  4572. // use the other end of the curve
  4573. iNext = 1;
  4574. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4575. break;
  4576. default: // ZeroCurvatureEnding
  4577. // f''(tN) = 0, a.k.a. Natural Spline
  4578. iNext = i1 - 1;
  4579. tNext = t0;
  4580. }
  4581. }
  4582. var halfDt = ( t1 - t0 ) * 0.5,
  4583. stride = this.valueSize;
  4584. this._weightPrev = halfDt / ( t0 - tPrev );
  4585. this._weightNext = halfDt / ( tNext - t1 );
  4586. this._offsetPrev = iPrev * stride;
  4587. this._offsetNext = iNext * stride;
  4588. },
  4589. interpolate_: function( i1, t0, t, t1 ) {
  4590. var result = this.resultBuffer,
  4591. values = this.sampleValues,
  4592. stride = this.valueSize,
  4593. o1 = i1 * stride, o0 = o1 - stride,
  4594. oP = this._offsetPrev, oN = this._offsetNext,
  4595. wP = this._weightPrev, wN = this._weightNext,
  4596. p = ( t - t0 ) / ( t1 - t0 ),
  4597. pp = p * p,
  4598. ppp = pp * p;
  4599. // evaluate polynomials
  4600. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4601. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4602. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4603. var sN = wN * ppp - wN * pp;
  4604. // combine data linearly
  4605. for ( var i = 0; i !== stride; ++ i ) {
  4606. result[ i ] =
  4607. sP * values[ oP + i ] +
  4608. s0 * values[ o0 + i ] +
  4609. s1 * values[ o1 + i ] +
  4610. sN * values[ oN + i ];
  4611. }
  4612. return result;
  4613. }
  4614. } );
  4615. // File:src/math/interpolants/DiscreteInterpolant.js
  4616. /**
  4617. *
  4618. * Interpolant that evaluates to the sample value at the position preceeding
  4619. * the parameter.
  4620. *
  4621. * @author tschw
  4622. */
  4623. THREE.DiscreteInterpolant = function(
  4624. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4625. THREE.Interpolant.call(
  4626. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4627. };
  4628. THREE.DiscreteInterpolant.prototype =
  4629. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4630. constructor: THREE.DiscreteInterpolant,
  4631. interpolate_: function( i1, t0, t, t1 ) {
  4632. return this.copySampleValue_( i1 - 1 );
  4633. }
  4634. } );
  4635. // File:src/math/interpolants/LinearInterpolant.js
  4636. /**
  4637. * @author tschw
  4638. */
  4639. THREE.LinearInterpolant = function(
  4640. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4641. THREE.Interpolant.call(
  4642. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4643. };
  4644. THREE.LinearInterpolant.prototype =
  4645. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4646. constructor: THREE.LinearInterpolant,
  4647. interpolate_: function( i1, t0, t, t1 ) {
  4648. var result = this.resultBuffer,
  4649. values = this.sampleValues,
  4650. stride = this.valueSize,
  4651. offset1 = i1 * stride,
  4652. offset0 = offset1 - stride,
  4653. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4654. weight0 = 1 - weight1;
  4655. for ( var i = 0; i !== stride; ++ i ) {
  4656. result[ i ] =
  4657. values[ offset0 + i ] * weight0 +
  4658. values[ offset1 + i ] * weight1;
  4659. }
  4660. return result;
  4661. }
  4662. } );
  4663. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4664. /**
  4665. * Spherical linear unit quaternion interpolant.
  4666. *
  4667. * @author tschw
  4668. */
  4669. THREE.QuaternionLinearInterpolant = function(
  4670. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4671. THREE.Interpolant.call(
  4672. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4673. };
  4674. THREE.QuaternionLinearInterpolant.prototype =
  4675. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4676. constructor: THREE.QuaternionLinearInterpolant,
  4677. interpolate_: function( i1, t0, t, t1 ) {
  4678. var result = this.resultBuffer,
  4679. values = this.sampleValues,
  4680. stride = this.valueSize,
  4681. offset = i1 * stride,
  4682. alpha = ( t - t0 ) / ( t1 - t0 );
  4683. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4684. THREE.Quaternion.slerpFlat( result, 0,
  4685. values, offset - stride, values, offset, alpha );
  4686. }
  4687. return result;
  4688. }
  4689. } );
  4690. // File:src/core/Clock.js
  4691. /**
  4692. * @author alteredq / http://alteredqualia.com/
  4693. */
  4694. THREE.Clock = function ( autoStart ) {
  4695. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4696. this.startTime = 0;
  4697. this.oldTime = 0;
  4698. this.elapsedTime = 0;
  4699. this.running = false;
  4700. };
  4701. THREE.Clock.prototype = {
  4702. constructor: THREE.Clock,
  4703. start: function () {
  4704. this.startTime = self.performance.now();
  4705. this.oldTime = this.startTime;
  4706. this.running = true;
  4707. },
  4708. stop: function () {
  4709. this.getElapsedTime();
  4710. this.running = false;
  4711. },
  4712. getElapsedTime: function () {
  4713. this.getDelta();
  4714. return this.elapsedTime;
  4715. },
  4716. getDelta: function () {
  4717. var diff = 0;
  4718. if ( this.autoStart && ! this.running ) {
  4719. this.start();
  4720. }
  4721. if ( this.running ) {
  4722. var newTime = self.performance.now();
  4723. diff = 0.001 * ( newTime - this.oldTime );
  4724. this.oldTime = newTime;
  4725. this.elapsedTime += diff;
  4726. }
  4727. return diff;
  4728. }
  4729. };
  4730. // File:src/core/EventDispatcher.js
  4731. /**
  4732. * https://github.com/mrdoob/eventdispatcher.js/
  4733. */
  4734. THREE.EventDispatcher = function () {};
  4735. THREE.EventDispatcher.prototype = {
  4736. constructor: THREE.EventDispatcher,
  4737. apply: function ( object ) {
  4738. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4739. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4740. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4741. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4742. },
  4743. addEventListener: function ( type, listener ) {
  4744. if ( this._listeners === undefined ) this._listeners = {};
  4745. var listeners = this._listeners;
  4746. if ( listeners[ type ] === undefined ) {
  4747. listeners[ type ] = [];
  4748. }
  4749. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4750. listeners[ type ].push( listener );
  4751. }
  4752. },
  4753. hasEventListener: function ( type, listener ) {
  4754. if ( this._listeners === undefined ) return false;
  4755. var listeners = this._listeners;
  4756. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4757. return true;
  4758. }
  4759. return false;
  4760. },
  4761. removeEventListener: function ( type, listener ) {
  4762. if ( this._listeners === undefined ) return;
  4763. var listeners = this._listeners;
  4764. var listenerArray = listeners[ type ];
  4765. if ( listenerArray !== undefined ) {
  4766. var index = listenerArray.indexOf( listener );
  4767. if ( index !== - 1 ) {
  4768. listenerArray.splice( index, 1 );
  4769. }
  4770. }
  4771. },
  4772. dispatchEvent: function ( event ) {
  4773. if ( this._listeners === undefined ) return;
  4774. var listeners = this._listeners;
  4775. var listenerArray = listeners[ event.type ];
  4776. if ( listenerArray !== undefined ) {
  4777. event.target = this;
  4778. var array = [];
  4779. var length = listenerArray.length;
  4780. for ( var i = 0; i < length; i ++ ) {
  4781. array[ i ] = listenerArray[ i ];
  4782. }
  4783. for ( var i = 0; i < length; i ++ ) {
  4784. array[ i ].call( this, event );
  4785. }
  4786. }
  4787. }
  4788. };
  4789. // File:src/core/Layers.js
  4790. /**
  4791. * @author mrdoob / http://mrdoob.com/
  4792. */
  4793. THREE.Layers = function () {
  4794. this.mask = 1;
  4795. };
  4796. THREE.Layers.prototype = {
  4797. constructor: THREE.Layers,
  4798. set: function ( channel ) {
  4799. this.mask = 1 << channel;
  4800. },
  4801. enable: function ( channel ) {
  4802. this.mask |= 1 << channel;
  4803. },
  4804. toggle: function ( channel ) {
  4805. this.mask ^= 1 << channel;
  4806. },
  4807. disable: function ( channel ) {
  4808. this.mask &= ~ ( 1 << channel );
  4809. },
  4810. test: function ( layers ) {
  4811. return ( this.mask & layers.mask ) !== 0;
  4812. }
  4813. };
  4814. // File:src/core/Raycaster.js
  4815. /**
  4816. * @author mrdoob / http://mrdoob.com/
  4817. * @author bhouston / http://clara.io/
  4818. * @author stephomi / http://stephaneginier.com/
  4819. */
  4820. ( function ( THREE ) {
  4821. THREE.Raycaster = function ( origin, direction, near, far ) {
  4822. this.ray = new THREE.Ray( origin, direction );
  4823. // direction is assumed to be normalized (for accurate distance calculations)
  4824. this.near = near || 0;
  4825. this.far = far || Infinity;
  4826. this.params = {
  4827. Mesh: {},
  4828. Line: {},
  4829. LOD: {},
  4830. Points: { threshold: 1 },
  4831. Sprite: {}
  4832. };
  4833. Object.defineProperties( this.params, {
  4834. PointCloud: {
  4835. get: function () {
  4836. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4837. return this.Points;
  4838. }
  4839. }
  4840. } );
  4841. };
  4842. function ascSort( a, b ) {
  4843. return a.distance - b.distance;
  4844. }
  4845. function intersectObject( object, raycaster, intersects, recursive ) {
  4846. if ( object.visible === false ) return;
  4847. object.raycast( raycaster, intersects );
  4848. if ( recursive === true ) {
  4849. var children = object.children;
  4850. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4851. intersectObject( children[ i ], raycaster, intersects, true );
  4852. }
  4853. }
  4854. }
  4855. //
  4856. THREE.Raycaster.prototype = {
  4857. constructor: THREE.Raycaster,
  4858. linePrecision: 1,
  4859. set: function ( origin, direction ) {
  4860. // direction is assumed to be normalized (for accurate distance calculations)
  4861. this.ray.set( origin, direction );
  4862. },
  4863. setFromCamera: function ( coords, camera ) {
  4864. if ( camera instanceof THREE.PerspectiveCamera ) {
  4865. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4866. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4867. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4868. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4869. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4870. } else {
  4871. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4872. }
  4873. },
  4874. intersectObject: function ( object, recursive ) {
  4875. var intersects = [];
  4876. intersectObject( object, this, intersects, recursive );
  4877. intersects.sort( ascSort );
  4878. return intersects;
  4879. },
  4880. intersectObjects: function ( objects, recursive ) {
  4881. var intersects = [];
  4882. if ( Array.isArray( objects ) === false ) {
  4883. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4884. return intersects;
  4885. }
  4886. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4887. intersectObject( objects[ i ], this, intersects, recursive );
  4888. }
  4889. intersects.sort( ascSort );
  4890. return intersects;
  4891. }
  4892. };
  4893. }( THREE ) );
  4894. // File:src/core/Object3D.js
  4895. /**
  4896. * @author mrdoob / http://mrdoob.com/
  4897. * @author mikael emtinger / http://gomo.se/
  4898. * @author alteredq / http://alteredqualia.com/
  4899. * @author WestLangley / http://github.com/WestLangley
  4900. * @author elephantatwork / www.elephantatwork.ch
  4901. */
  4902. THREE.Object3D = function () {
  4903. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4904. this.uuid = THREE.Math.generateUUID();
  4905. this.name = '';
  4906. this.type = 'Object3D';
  4907. this.parent = null;
  4908. this.children = [];
  4909. this.up = THREE.Object3D.DefaultUp.clone();
  4910. var position = new THREE.Vector3();
  4911. var rotation = new THREE.Euler();
  4912. var quaternion = new THREE.Quaternion();
  4913. var scale = new THREE.Vector3( 1, 1, 1 );
  4914. function onRotationChange() {
  4915. quaternion.setFromEuler( rotation, false );
  4916. }
  4917. function onQuaternionChange() {
  4918. rotation.setFromQuaternion( quaternion, undefined, false );
  4919. }
  4920. rotation.onChange( onRotationChange );
  4921. quaternion.onChange( onQuaternionChange );
  4922. Object.defineProperties( this, {
  4923. position: {
  4924. enumerable: true,
  4925. value: position
  4926. },
  4927. rotation: {
  4928. enumerable: true,
  4929. value: rotation
  4930. },
  4931. quaternion: {
  4932. enumerable: true,
  4933. value: quaternion
  4934. },
  4935. scale: {
  4936. enumerable: true,
  4937. value: scale
  4938. },
  4939. modelViewMatrix: {
  4940. value: new THREE.Matrix4()
  4941. },
  4942. normalMatrix: {
  4943. value: new THREE.Matrix3()
  4944. }
  4945. } );
  4946. this.rotationAutoUpdate = true;
  4947. this.matrix = new THREE.Matrix4();
  4948. this.matrixWorld = new THREE.Matrix4();
  4949. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4950. this.matrixWorldNeedsUpdate = false;
  4951. this.layers = new THREE.Layers();
  4952. this.visible = true;
  4953. this.castShadow = false;
  4954. this.receiveShadow = false;
  4955. this.frustumCulled = true;
  4956. this.renderOrder = 0;
  4957. this.userData = {};
  4958. };
  4959. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4960. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4961. THREE.Object3D.prototype = {
  4962. constructor: THREE.Object3D,
  4963. applyMatrix: function ( matrix ) {
  4964. this.matrix.multiplyMatrices( matrix, this.matrix );
  4965. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4966. },
  4967. setRotationFromAxisAngle: function ( axis, angle ) {
  4968. // assumes axis is normalized
  4969. this.quaternion.setFromAxisAngle( axis, angle );
  4970. },
  4971. setRotationFromEuler: function ( euler ) {
  4972. this.quaternion.setFromEuler( euler, true );
  4973. },
  4974. setRotationFromMatrix: function ( m ) {
  4975. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4976. this.quaternion.setFromRotationMatrix( m );
  4977. },
  4978. setRotationFromQuaternion: function ( q ) {
  4979. // assumes q is normalized
  4980. this.quaternion.copy( q );
  4981. },
  4982. rotateOnAxis: function () {
  4983. // rotate object on axis in object space
  4984. // axis is assumed to be normalized
  4985. var q1 = new THREE.Quaternion();
  4986. return function ( axis, angle ) {
  4987. q1.setFromAxisAngle( axis, angle );
  4988. this.quaternion.multiply( q1 );
  4989. return this;
  4990. };
  4991. }(),
  4992. rotateX: function () {
  4993. var v1 = new THREE.Vector3( 1, 0, 0 );
  4994. return function ( angle ) {
  4995. return this.rotateOnAxis( v1, angle );
  4996. };
  4997. }(),
  4998. rotateY: function () {
  4999. var v1 = new THREE.Vector3( 0, 1, 0 );
  5000. return function ( angle ) {
  5001. return this.rotateOnAxis( v1, angle );
  5002. };
  5003. }(),
  5004. rotateZ: function () {
  5005. var v1 = new THREE.Vector3( 0, 0, 1 );
  5006. return function ( angle ) {
  5007. return this.rotateOnAxis( v1, angle );
  5008. };
  5009. }(),
  5010. translateOnAxis: function () {
  5011. // translate object by distance along axis in object space
  5012. // axis is assumed to be normalized
  5013. var v1 = new THREE.Vector3();
  5014. return function ( axis, distance ) {
  5015. v1.copy( axis ).applyQuaternion( this.quaternion );
  5016. this.position.add( v1.multiplyScalar( distance ) );
  5017. return this;
  5018. };
  5019. }(),
  5020. translateX: function () {
  5021. var v1 = new THREE.Vector3( 1, 0, 0 );
  5022. return function ( distance ) {
  5023. return this.translateOnAxis( v1, distance );
  5024. };
  5025. }(),
  5026. translateY: function () {
  5027. var v1 = new THREE.Vector3( 0, 1, 0 );
  5028. return function ( distance ) {
  5029. return this.translateOnAxis( v1, distance );
  5030. };
  5031. }(),
  5032. translateZ: function () {
  5033. var v1 = new THREE.Vector3( 0, 0, 1 );
  5034. return function ( distance ) {
  5035. return this.translateOnAxis( v1, distance );
  5036. };
  5037. }(),
  5038. localToWorld: function ( vector ) {
  5039. return vector.applyMatrix4( this.matrixWorld );
  5040. },
  5041. worldToLocal: function () {
  5042. var m1 = new THREE.Matrix4();
  5043. return function ( vector ) {
  5044. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5045. };
  5046. }(),
  5047. lookAt: function () {
  5048. // This routine does not support objects with rotated and/or translated parent(s)
  5049. var m1 = new THREE.Matrix4();
  5050. return function ( vector ) {
  5051. m1.lookAt( vector, this.position, this.up );
  5052. this.quaternion.setFromRotationMatrix( m1 );
  5053. };
  5054. }(),
  5055. add: function ( object ) {
  5056. if ( arguments.length > 1 ) {
  5057. for ( var i = 0; i < arguments.length; i ++ ) {
  5058. this.add( arguments[ i ] );
  5059. }
  5060. return this;
  5061. }
  5062. if ( object === this ) {
  5063. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5064. return this;
  5065. }
  5066. if ( object instanceof THREE.Object3D ) {
  5067. if ( object.parent !== null ) {
  5068. object.parent.remove( object );
  5069. }
  5070. object.parent = this;
  5071. object.dispatchEvent( { type: 'added' } );
  5072. this.children.push( object );
  5073. } else {
  5074. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5075. }
  5076. return this;
  5077. },
  5078. remove: function ( object ) {
  5079. if ( arguments.length > 1 ) {
  5080. for ( var i = 0; i < arguments.length; i ++ ) {
  5081. this.remove( arguments[ i ] );
  5082. }
  5083. }
  5084. var index = this.children.indexOf( object );
  5085. if ( index !== - 1 ) {
  5086. object.parent = null;
  5087. object.dispatchEvent( { type: 'removed' } );
  5088. this.children.splice( index, 1 );
  5089. }
  5090. },
  5091. getObjectById: function ( id ) {
  5092. return this.getObjectByProperty( 'id', id );
  5093. },
  5094. getObjectByName: function ( name ) {
  5095. return this.getObjectByProperty( 'name', name );
  5096. },
  5097. getObjectByProperty: function ( name, value ) {
  5098. if ( this[ name ] === value ) return this;
  5099. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5100. var child = this.children[ i ];
  5101. var object = child.getObjectByProperty( name, value );
  5102. if ( object !== undefined ) {
  5103. return object;
  5104. }
  5105. }
  5106. return undefined;
  5107. },
  5108. getWorldPosition: function ( optionalTarget ) {
  5109. var result = optionalTarget || new THREE.Vector3();
  5110. this.updateMatrixWorld( true );
  5111. return result.setFromMatrixPosition( this.matrixWorld );
  5112. },
  5113. getWorldQuaternion: function () {
  5114. var position = new THREE.Vector3();
  5115. var scale = new THREE.Vector3();
  5116. return function ( optionalTarget ) {
  5117. var result = optionalTarget || new THREE.Quaternion();
  5118. this.updateMatrixWorld( true );
  5119. this.matrixWorld.decompose( position, result, scale );
  5120. return result;
  5121. };
  5122. }(),
  5123. getWorldRotation: function () {
  5124. var quaternion = new THREE.Quaternion();
  5125. return function ( optionalTarget ) {
  5126. var result = optionalTarget || new THREE.Euler();
  5127. this.getWorldQuaternion( quaternion );
  5128. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5129. };
  5130. }(),
  5131. getWorldScale: function () {
  5132. var position = new THREE.Vector3();
  5133. var quaternion = new THREE.Quaternion();
  5134. return function ( optionalTarget ) {
  5135. var result = optionalTarget || new THREE.Vector3();
  5136. this.updateMatrixWorld( true );
  5137. this.matrixWorld.decompose( position, quaternion, result );
  5138. return result;
  5139. };
  5140. }(),
  5141. getWorldDirection: function () {
  5142. var quaternion = new THREE.Quaternion();
  5143. return function ( optionalTarget ) {
  5144. var result = optionalTarget || new THREE.Vector3();
  5145. this.getWorldQuaternion( quaternion );
  5146. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5147. };
  5148. }(),
  5149. raycast: function () {},
  5150. traverse: function ( callback ) {
  5151. callback( this );
  5152. var children = this.children;
  5153. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5154. children[ i ].traverse( callback );
  5155. }
  5156. },
  5157. traverseVisible: function ( callback ) {
  5158. if ( this.visible === false ) return;
  5159. callback( this );
  5160. var children = this.children;
  5161. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5162. children[ i ].traverseVisible( callback );
  5163. }
  5164. },
  5165. traverseAncestors: function ( callback ) {
  5166. var parent = this.parent;
  5167. if ( parent !== null ) {
  5168. callback( parent );
  5169. parent.traverseAncestors( callback );
  5170. }
  5171. },
  5172. updateMatrix: function () {
  5173. this.matrix.compose( this.position, this.quaternion, this.scale );
  5174. this.matrixWorldNeedsUpdate = true;
  5175. },
  5176. updateMatrixWorld: function ( force ) {
  5177. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5178. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5179. if ( this.parent === null ) {
  5180. this.matrixWorld.copy( this.matrix );
  5181. } else {
  5182. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5183. }
  5184. this.matrixWorldNeedsUpdate = false;
  5185. force = true;
  5186. }
  5187. // update children
  5188. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5189. this.children[ i ].updateMatrixWorld( force );
  5190. }
  5191. },
  5192. toJSON: function ( meta ) {
  5193. var isRootObject = ( meta === undefined );
  5194. var output = {};
  5195. // meta is a hash used to collect geometries, materials.
  5196. // not providing it implies that this is the root object
  5197. // being serialized.
  5198. if ( isRootObject ) {
  5199. // initialize meta obj
  5200. meta = {
  5201. geometries: {},
  5202. materials: {},
  5203. textures: {},
  5204. images: {}
  5205. };
  5206. output.metadata = {
  5207. version: 4.4,
  5208. type: 'Object',
  5209. generator: 'Object3D.toJSON'
  5210. };
  5211. }
  5212. // standard Object3D serialization
  5213. var object = {};
  5214. object.uuid = this.uuid;
  5215. object.type = this.type;
  5216. if ( this.name !== '' ) object.name = this.name;
  5217. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5218. if ( this.castShadow === true ) object.castShadow = true;
  5219. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5220. if ( this.visible === false ) object.visible = false;
  5221. object.matrix = this.matrix.toArray();
  5222. //
  5223. if ( this.geometry !== undefined ) {
  5224. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5225. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5226. }
  5227. object.geometry = this.geometry.uuid;
  5228. }
  5229. if ( this.material !== undefined ) {
  5230. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5231. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5232. }
  5233. object.material = this.material.uuid;
  5234. }
  5235. //
  5236. if ( this.children.length > 0 ) {
  5237. object.children = [];
  5238. for ( var i = 0; i < this.children.length; i ++ ) {
  5239. object.children.push( this.children[ i ].toJSON( meta ).object );
  5240. }
  5241. }
  5242. if ( isRootObject ) {
  5243. var geometries = extractFromCache( meta.geometries );
  5244. var materials = extractFromCache( meta.materials );
  5245. var textures = extractFromCache( meta.textures );
  5246. var images = extractFromCache( meta.images );
  5247. if ( geometries.length > 0 ) output.geometries = geometries;
  5248. if ( materials.length > 0 ) output.materials = materials;
  5249. if ( textures.length > 0 ) output.textures = textures;
  5250. if ( images.length > 0 ) output.images = images;
  5251. }
  5252. output.object = object;
  5253. return output;
  5254. // extract data from the cache hash
  5255. // remove metadata on each item
  5256. // and return as array
  5257. function extractFromCache ( cache ) {
  5258. var values = [];
  5259. for ( var key in cache ) {
  5260. var data = cache[ key ];
  5261. delete data.metadata;
  5262. values.push( data );
  5263. }
  5264. return values;
  5265. }
  5266. },
  5267. clone: function ( recursive ) {
  5268. return new this.constructor().copy( this, recursive );
  5269. },
  5270. copy: function ( source, recursive ) {
  5271. if ( recursive === undefined ) recursive = true;
  5272. this.name = source.name;
  5273. this.up.copy( source.up );
  5274. this.position.copy( source.position );
  5275. this.quaternion.copy( source.quaternion );
  5276. this.scale.copy( source.scale );
  5277. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5278. this.matrix.copy( source.matrix );
  5279. this.matrixWorld.copy( source.matrixWorld );
  5280. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5281. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5282. this.visible = source.visible;
  5283. this.castShadow = source.castShadow;
  5284. this.receiveShadow = source.receiveShadow;
  5285. this.frustumCulled = source.frustumCulled;
  5286. this.renderOrder = source.renderOrder;
  5287. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5288. if ( recursive === true ) {
  5289. for ( var i = 0; i < source.children.length; i ++ ) {
  5290. var child = source.children[ i ];
  5291. this.add( child.clone() );
  5292. }
  5293. }
  5294. return this;
  5295. }
  5296. };
  5297. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5298. THREE.Object3DIdCount = 0;
  5299. // File:src/core/Face3.js
  5300. /**
  5301. * @author mrdoob / http://mrdoob.com/
  5302. * @author alteredq / http://alteredqualia.com/
  5303. */
  5304. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5305. this.a = a;
  5306. this.b = b;
  5307. this.c = c;
  5308. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5309. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5310. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5311. this.vertexColors = Array.isArray( color ) ? color : [];
  5312. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5313. };
  5314. THREE.Face3.prototype = {
  5315. constructor: THREE.Face3,
  5316. clone: function () {
  5317. return new this.constructor().copy( this );
  5318. },
  5319. copy: function ( source ) {
  5320. this.a = source.a;
  5321. this.b = source.b;
  5322. this.c = source.c;
  5323. this.normal.copy( source.normal );
  5324. this.color.copy( source.color );
  5325. this.materialIndex = source.materialIndex;
  5326. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5327. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5328. }
  5329. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5330. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5331. }
  5332. return this;
  5333. }
  5334. };
  5335. // File:src/core/Face4.js
  5336. /**
  5337. * @author mrdoob / http://mrdoob.com/
  5338. */
  5339. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5340. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5341. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5342. };
  5343. // File:src/core/BufferAttribute.js
  5344. /**
  5345. * @author mrdoob / http://mrdoob.com/
  5346. */
  5347. THREE.BufferAttribute = function ( array, itemSize ) {
  5348. this.uuid = THREE.Math.generateUUID();
  5349. this.array = array;
  5350. this.itemSize = itemSize;
  5351. this.dynamic = false;
  5352. this.updateRange = { offset: 0, count: - 1 };
  5353. this.version = 0;
  5354. };
  5355. THREE.BufferAttribute.prototype = {
  5356. constructor: THREE.BufferAttribute,
  5357. get count() {
  5358. return this.array.length / this.itemSize;
  5359. },
  5360. set needsUpdate( value ) {
  5361. if ( value === true ) this.version ++;
  5362. },
  5363. setDynamic: function ( value ) {
  5364. this.dynamic = value;
  5365. return this;
  5366. },
  5367. copy: function ( source ) {
  5368. this.array = new source.array.constructor( source.array );
  5369. this.itemSize = source.itemSize;
  5370. this.dynamic = source.dynamic;
  5371. return this;
  5372. },
  5373. copyAt: function ( index1, attribute, index2 ) {
  5374. index1 *= this.itemSize;
  5375. index2 *= attribute.itemSize;
  5376. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5377. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5378. }
  5379. return this;
  5380. },
  5381. copyArray: function ( array ) {
  5382. this.array.set( array );
  5383. return this;
  5384. },
  5385. copyColorsArray: function ( colors ) {
  5386. var array = this.array, offset = 0;
  5387. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5388. var color = colors[ i ];
  5389. if ( color === undefined ) {
  5390. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5391. color = new THREE.Color();
  5392. }
  5393. array[ offset ++ ] = color.r;
  5394. array[ offset ++ ] = color.g;
  5395. array[ offset ++ ] = color.b;
  5396. }
  5397. return this;
  5398. },
  5399. copyIndicesArray: function ( indices ) {
  5400. var array = this.array, offset = 0;
  5401. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5402. var index = indices[ i ];
  5403. array[ offset ++ ] = index.a;
  5404. array[ offset ++ ] = index.b;
  5405. array[ offset ++ ] = index.c;
  5406. }
  5407. return this;
  5408. },
  5409. copyVector2sArray: function ( vectors ) {
  5410. var array = this.array, offset = 0;
  5411. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5412. var vector = vectors[ i ];
  5413. if ( vector === undefined ) {
  5414. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5415. vector = new THREE.Vector2();
  5416. }
  5417. array[ offset ++ ] = vector.x;
  5418. array[ offset ++ ] = vector.y;
  5419. }
  5420. return this;
  5421. },
  5422. copyVector3sArray: function ( vectors ) {
  5423. var array = this.array, offset = 0;
  5424. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5425. var vector = vectors[ i ];
  5426. if ( vector === undefined ) {
  5427. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5428. vector = new THREE.Vector3();
  5429. }
  5430. array[ offset ++ ] = vector.x;
  5431. array[ offset ++ ] = vector.y;
  5432. array[ offset ++ ] = vector.z;
  5433. }
  5434. return this;
  5435. },
  5436. copyVector4sArray: function ( vectors ) {
  5437. var array = this.array, offset = 0;
  5438. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5439. var vector = vectors[ i ];
  5440. if ( vector === undefined ) {
  5441. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5442. vector = new THREE.Vector4();
  5443. }
  5444. array[ offset ++ ] = vector.x;
  5445. array[ offset ++ ] = vector.y;
  5446. array[ offset ++ ] = vector.z;
  5447. array[ offset ++ ] = vector.w;
  5448. }
  5449. return this;
  5450. },
  5451. set: function ( value, offset ) {
  5452. if ( offset === undefined ) offset = 0;
  5453. this.array.set( value, offset );
  5454. return this;
  5455. },
  5456. getX: function ( index ) {
  5457. return this.array[ index * this.itemSize ];
  5458. },
  5459. setX: function ( index, x ) {
  5460. this.array[ index * this.itemSize ] = x;
  5461. return this;
  5462. },
  5463. getY: function ( index ) {
  5464. return this.array[ index * this.itemSize + 1 ];
  5465. },
  5466. setY: function ( index, y ) {
  5467. this.array[ index * this.itemSize + 1 ] = y;
  5468. return this;
  5469. },
  5470. getZ: function ( index ) {
  5471. return this.array[ index * this.itemSize + 2 ];
  5472. },
  5473. setZ: function ( index, z ) {
  5474. this.array[ index * this.itemSize + 2 ] = z;
  5475. return this;
  5476. },
  5477. getW: function ( index ) {
  5478. return this.array[ index * this.itemSize + 3 ];
  5479. },
  5480. setW: function ( index, w ) {
  5481. this.array[ index * this.itemSize + 3 ] = w;
  5482. return this;
  5483. },
  5484. setXY: function ( index, x, y ) {
  5485. index *= this.itemSize;
  5486. this.array[ index + 0 ] = x;
  5487. this.array[ index + 1 ] = y;
  5488. return this;
  5489. },
  5490. setXYZ: function ( index, x, y, z ) {
  5491. index *= this.itemSize;
  5492. this.array[ index + 0 ] = x;
  5493. this.array[ index + 1 ] = y;
  5494. this.array[ index + 2 ] = z;
  5495. return this;
  5496. },
  5497. setXYZW: function ( index, x, y, z, w ) {
  5498. index *= this.itemSize;
  5499. this.array[ index + 0 ] = x;
  5500. this.array[ index + 1 ] = y;
  5501. this.array[ index + 2 ] = z;
  5502. this.array[ index + 3 ] = w;
  5503. return this;
  5504. },
  5505. clone: function () {
  5506. return new this.constructor().copy( this );
  5507. }
  5508. };
  5509. //
  5510. THREE.Int8Attribute = function ( array, itemSize ) {
  5511. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5512. };
  5513. THREE.Uint8Attribute = function ( array, itemSize ) {
  5514. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5515. };
  5516. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5517. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5518. };
  5519. THREE.Int16Attribute = function ( array, itemSize ) {
  5520. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5521. };
  5522. THREE.Uint16Attribute = function ( array, itemSize ) {
  5523. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5524. };
  5525. THREE.Int32Attribute = function ( array, itemSize ) {
  5526. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5527. };
  5528. THREE.Uint32Attribute = function ( array, itemSize ) {
  5529. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5530. };
  5531. THREE.Float32Attribute = function ( array, itemSize ) {
  5532. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5533. };
  5534. THREE.Float64Attribute = function ( array, itemSize ) {
  5535. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5536. };
  5537. // Deprecated
  5538. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5539. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5540. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5541. };
  5542. // File:src/core/InstancedBufferAttribute.js
  5543. /**
  5544. * @author benaadams / https://twitter.com/ben_a_adams
  5545. */
  5546. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5547. THREE.BufferAttribute.call( this, array, itemSize );
  5548. this.meshPerAttribute = meshPerAttribute || 1;
  5549. };
  5550. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5551. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5552. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5553. THREE.BufferAttribute.prototype.copy.call( this, source );
  5554. this.meshPerAttribute = source.meshPerAttribute;
  5555. return this;
  5556. };
  5557. // File:src/core/InterleavedBuffer.js
  5558. /**
  5559. * @author benaadams / https://twitter.com/ben_a_adams
  5560. */
  5561. THREE.InterleavedBuffer = function ( array, stride ) {
  5562. this.uuid = THREE.Math.generateUUID();
  5563. this.array = array;
  5564. this.stride = stride;
  5565. this.dynamic = false;
  5566. this.updateRange = { offset: 0, count: - 1 };
  5567. this.version = 0;
  5568. };
  5569. THREE.InterleavedBuffer.prototype = {
  5570. constructor: THREE.InterleavedBuffer,
  5571. get length () {
  5572. return this.array.length;
  5573. },
  5574. get count () {
  5575. return this.array.length / this.stride;
  5576. },
  5577. set needsUpdate( value ) {
  5578. if ( value === true ) this.version ++;
  5579. },
  5580. setDynamic: function ( value ) {
  5581. this.dynamic = value;
  5582. return this;
  5583. },
  5584. copy: function ( source ) {
  5585. this.array = new source.array.constructor( source.array );
  5586. this.stride = source.stride;
  5587. this.dynamic = source.dynamic;
  5588. return this;
  5589. },
  5590. copyAt: function ( index1, attribute, index2 ) {
  5591. index1 *= this.stride;
  5592. index2 *= attribute.stride;
  5593. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5594. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5595. }
  5596. return this;
  5597. },
  5598. set: function ( value, offset ) {
  5599. if ( offset === undefined ) offset = 0;
  5600. this.array.set( value, offset );
  5601. return this;
  5602. },
  5603. clone: function () {
  5604. return new this.constructor().copy( this );
  5605. }
  5606. };
  5607. // File:src/core/InstancedInterleavedBuffer.js
  5608. /**
  5609. * @author benaadams / https://twitter.com/ben_a_adams
  5610. */
  5611. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5612. THREE.InterleavedBuffer.call( this, array, stride );
  5613. this.meshPerAttribute = meshPerAttribute || 1;
  5614. };
  5615. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5616. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5617. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5618. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5619. this.meshPerAttribute = source.meshPerAttribute;
  5620. return this;
  5621. };
  5622. // File:src/core/InterleavedBufferAttribute.js
  5623. /**
  5624. * @author benaadams / https://twitter.com/ben_a_adams
  5625. */
  5626. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5627. this.uuid = THREE.Math.generateUUID();
  5628. this.data = interleavedBuffer;
  5629. this.itemSize = itemSize;
  5630. this.offset = offset;
  5631. };
  5632. THREE.InterleavedBufferAttribute.prototype = {
  5633. constructor: THREE.InterleavedBufferAttribute,
  5634. get length() {
  5635. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5636. return this.array.length;
  5637. },
  5638. get count() {
  5639. return this.data.count;
  5640. },
  5641. setX: function ( index, x ) {
  5642. this.data.array[ index * this.data.stride + this.offset ] = x;
  5643. return this;
  5644. },
  5645. setY: function ( index, y ) {
  5646. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5647. return this;
  5648. },
  5649. setZ: function ( index, z ) {
  5650. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5651. return this;
  5652. },
  5653. setW: function ( index, w ) {
  5654. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5655. return this;
  5656. },
  5657. getX: function ( index ) {
  5658. return this.data.array[ index * this.data.stride + this.offset ];
  5659. },
  5660. getY: function ( index ) {
  5661. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5662. },
  5663. getZ: function ( index ) {
  5664. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5665. },
  5666. getW: function ( index ) {
  5667. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5668. },
  5669. setXY: function ( index, x, y ) {
  5670. index = index * this.data.stride + this.offset;
  5671. this.data.array[ index + 0 ] = x;
  5672. this.data.array[ index + 1 ] = y;
  5673. return this;
  5674. },
  5675. setXYZ: function ( index, x, y, z ) {
  5676. index = index * this.data.stride + this.offset;
  5677. this.data.array[ index + 0 ] = x;
  5678. this.data.array[ index + 1 ] = y;
  5679. this.data.array[ index + 2 ] = z;
  5680. return this;
  5681. },
  5682. setXYZW: function ( index, x, y, z, w ) {
  5683. index = index * this.data.stride + this.offset;
  5684. this.data.array[ index + 0 ] = x;
  5685. this.data.array[ index + 1 ] = y;
  5686. this.data.array[ index + 2 ] = z;
  5687. this.data.array[ index + 3 ] = w;
  5688. return this;
  5689. }
  5690. };
  5691. // File:src/core/Geometry.js
  5692. /**
  5693. * @author mrdoob / http://mrdoob.com/
  5694. * @author kile / http://kile.stravaganza.org/
  5695. * @author alteredq / http://alteredqualia.com/
  5696. * @author mikael emtinger / http://gomo.se/
  5697. * @author zz85 / http://www.lab4games.net/zz85/blog
  5698. * @author bhouston / http://clara.io
  5699. */
  5700. THREE.Geometry = function () {
  5701. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5702. this.uuid = THREE.Math.generateUUID();
  5703. this.name = '';
  5704. this.type = 'Geometry';
  5705. this.vertices = [];
  5706. this.colors = [];
  5707. this.faces = [];
  5708. this.faceVertexUvs = [ [] ];
  5709. this.morphTargets = [];
  5710. this.morphNormals = [];
  5711. this.skinWeights = [];
  5712. this.skinIndices = [];
  5713. this.lineDistances = [];
  5714. this.boundingBox = null;
  5715. this.boundingSphere = null;
  5716. // update flags
  5717. this.verticesNeedUpdate = false;
  5718. this.elementsNeedUpdate = false;
  5719. this.uvsNeedUpdate = false;
  5720. this.normalsNeedUpdate = false;
  5721. this.colorsNeedUpdate = false;
  5722. this.lineDistancesNeedUpdate = false;
  5723. this.groupsNeedUpdate = false;
  5724. };
  5725. THREE.Geometry.prototype = {
  5726. constructor: THREE.Geometry,
  5727. applyMatrix: function ( matrix ) {
  5728. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5729. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5730. var vertex = this.vertices[ i ];
  5731. vertex.applyMatrix4( matrix );
  5732. }
  5733. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5734. var face = this.faces[ i ];
  5735. face.normal.applyMatrix3( normalMatrix ).normalize();
  5736. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5737. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5738. }
  5739. }
  5740. if ( this.boundingBox !== null ) {
  5741. this.computeBoundingBox();
  5742. }
  5743. if ( this.boundingSphere !== null ) {
  5744. this.computeBoundingSphere();
  5745. }
  5746. this.verticesNeedUpdate = true;
  5747. this.normalsNeedUpdate = true;
  5748. },
  5749. rotateX: function () {
  5750. // rotate geometry around world x-axis
  5751. var m1;
  5752. return function rotateX( angle ) {
  5753. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5754. m1.makeRotationX( angle );
  5755. this.applyMatrix( m1 );
  5756. return this;
  5757. };
  5758. }(),
  5759. rotateY: function () {
  5760. // rotate geometry around world y-axis
  5761. var m1;
  5762. return function rotateY( angle ) {
  5763. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5764. m1.makeRotationY( angle );
  5765. this.applyMatrix( m1 );
  5766. return this;
  5767. };
  5768. }(),
  5769. rotateZ: function () {
  5770. // rotate geometry around world z-axis
  5771. var m1;
  5772. return function rotateZ( angle ) {
  5773. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5774. m1.makeRotationZ( angle );
  5775. this.applyMatrix( m1 );
  5776. return this;
  5777. };
  5778. }(),
  5779. translate: function () {
  5780. // translate geometry
  5781. var m1;
  5782. return function translate( x, y, z ) {
  5783. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5784. m1.makeTranslation( x, y, z );
  5785. this.applyMatrix( m1 );
  5786. return this;
  5787. };
  5788. }(),
  5789. scale: function () {
  5790. // scale geometry
  5791. var m1;
  5792. return function scale( x, y, z ) {
  5793. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5794. m1.makeScale( x, y, z );
  5795. this.applyMatrix( m1 );
  5796. return this;
  5797. };
  5798. }(),
  5799. lookAt: function () {
  5800. var obj;
  5801. return function lookAt( vector ) {
  5802. if ( obj === undefined ) obj = new THREE.Object3D();
  5803. obj.lookAt( vector );
  5804. obj.updateMatrix();
  5805. this.applyMatrix( obj.matrix );
  5806. };
  5807. }(),
  5808. fromBufferGeometry: function ( geometry ) {
  5809. var scope = this;
  5810. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5811. var attributes = geometry.attributes;
  5812. var vertices = attributes.position.array;
  5813. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5814. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5815. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5816. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5817. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5818. var tempNormals = [];
  5819. var tempUVs = [];
  5820. var tempUVs2 = [];
  5821. for ( var i = 0, j = 0; i < vertices.length; i += 3, j += 2 ) {
  5822. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5823. if ( normals !== undefined ) {
  5824. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5825. }
  5826. if ( colors !== undefined ) {
  5827. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5828. }
  5829. if ( uvs !== undefined ) {
  5830. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5831. }
  5832. if ( uvs2 !== undefined ) {
  5833. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5834. }
  5835. }
  5836. function addFace( a, b, c ) {
  5837. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5838. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5839. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5840. scope.faces.push( face );
  5841. if ( uvs !== undefined ) {
  5842. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5843. }
  5844. if ( uvs2 !== undefined ) {
  5845. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5846. }
  5847. };
  5848. if ( indices !== undefined ) {
  5849. var groups = geometry.groups;
  5850. if ( groups.length > 0 ) {
  5851. for ( var i = 0; i < groups.length; i ++ ) {
  5852. var group = groups[ i ];
  5853. var start = group.start;
  5854. var count = group.count;
  5855. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5856. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5857. }
  5858. }
  5859. } else {
  5860. for ( var i = 0; i < indices.length; i += 3 ) {
  5861. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5862. }
  5863. }
  5864. } else {
  5865. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5866. addFace( i, i + 1, i + 2 );
  5867. }
  5868. }
  5869. this.computeFaceNormals();
  5870. if ( geometry.boundingBox !== null ) {
  5871. this.boundingBox = geometry.boundingBox.clone();
  5872. }
  5873. if ( geometry.boundingSphere !== null ) {
  5874. this.boundingSphere = geometry.boundingSphere.clone();
  5875. }
  5876. return this;
  5877. },
  5878. center: function () {
  5879. this.computeBoundingBox();
  5880. var offset = this.boundingBox.center().negate();
  5881. this.translate( offset.x, offset.y, offset.z );
  5882. return offset;
  5883. },
  5884. normalize: function () {
  5885. this.computeBoundingSphere();
  5886. var center = this.boundingSphere.center;
  5887. var radius = this.boundingSphere.radius;
  5888. var s = radius === 0 ? 1 : 1.0 / radius;
  5889. var matrix = new THREE.Matrix4();
  5890. matrix.set(
  5891. s, 0, 0, - s * center.x,
  5892. 0, s, 0, - s * center.y,
  5893. 0, 0, s, - s * center.z,
  5894. 0, 0, 0, 1
  5895. );
  5896. this.applyMatrix( matrix );
  5897. return this;
  5898. },
  5899. computeFaceNormals: function () {
  5900. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5901. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5902. var face = this.faces[ f ];
  5903. var vA = this.vertices[ face.a ];
  5904. var vB = this.vertices[ face.b ];
  5905. var vC = this.vertices[ face.c ];
  5906. cb.subVectors( vC, vB );
  5907. ab.subVectors( vA, vB );
  5908. cb.cross( ab );
  5909. cb.normalize();
  5910. face.normal.copy( cb );
  5911. }
  5912. },
  5913. computeVertexNormals: function ( areaWeighted ) {
  5914. var v, vl, f, fl, face, vertices;
  5915. vertices = new Array( this.vertices.length );
  5916. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5917. vertices[ v ] = new THREE.Vector3();
  5918. }
  5919. if ( areaWeighted ) {
  5920. // vertex normals weighted by triangle areas
  5921. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5922. var vA, vB, vC;
  5923. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5924. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5925. face = this.faces[ f ];
  5926. vA = this.vertices[ face.a ];
  5927. vB = this.vertices[ face.b ];
  5928. vC = this.vertices[ face.c ];
  5929. cb.subVectors( vC, vB );
  5930. ab.subVectors( vA, vB );
  5931. cb.cross( ab );
  5932. vertices[ face.a ].add( cb );
  5933. vertices[ face.b ].add( cb );
  5934. vertices[ face.c ].add( cb );
  5935. }
  5936. } else {
  5937. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5938. face = this.faces[ f ];
  5939. vertices[ face.a ].add( face.normal );
  5940. vertices[ face.b ].add( face.normal );
  5941. vertices[ face.c ].add( face.normal );
  5942. }
  5943. }
  5944. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5945. vertices[ v ].normalize();
  5946. }
  5947. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5948. face = this.faces[ f ];
  5949. var vertexNormals = face.vertexNormals;
  5950. if ( vertexNormals.length === 3 ) {
  5951. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5952. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5953. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5954. } else {
  5955. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5956. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5957. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5958. }
  5959. }
  5960. },
  5961. computeMorphNormals: function () {
  5962. var i, il, f, fl, face;
  5963. // save original normals
  5964. // - create temp variables on first access
  5965. // otherwise just copy (for faster repeated calls)
  5966. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5967. face = this.faces[ f ];
  5968. if ( ! face.__originalFaceNormal ) {
  5969. face.__originalFaceNormal = face.normal.clone();
  5970. } else {
  5971. face.__originalFaceNormal.copy( face.normal );
  5972. }
  5973. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5974. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5975. if ( ! face.__originalVertexNormals[ i ] ) {
  5976. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5977. } else {
  5978. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5979. }
  5980. }
  5981. }
  5982. // use temp geometry to compute face and vertex normals for each morph
  5983. var tmpGeo = new THREE.Geometry();
  5984. tmpGeo.faces = this.faces;
  5985. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5986. // create on first access
  5987. if ( ! this.morphNormals[ i ] ) {
  5988. this.morphNormals[ i ] = {};
  5989. this.morphNormals[ i ].faceNormals = [];
  5990. this.morphNormals[ i ].vertexNormals = [];
  5991. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5992. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5993. var faceNormal, vertexNormals;
  5994. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5995. faceNormal = new THREE.Vector3();
  5996. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5997. dstNormalsFace.push( faceNormal );
  5998. dstNormalsVertex.push( vertexNormals );
  5999. }
  6000. }
  6001. var morphNormals = this.morphNormals[ i ];
  6002. // set vertices to morph target
  6003. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6004. // compute morph normals
  6005. tmpGeo.computeFaceNormals();
  6006. tmpGeo.computeVertexNormals();
  6007. // store morph normals
  6008. var faceNormal, vertexNormals;
  6009. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6010. face = this.faces[ f ];
  6011. faceNormal = morphNormals.faceNormals[ f ];
  6012. vertexNormals = morphNormals.vertexNormals[ f ];
  6013. faceNormal.copy( face.normal );
  6014. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6015. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6016. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6017. }
  6018. }
  6019. // restore original normals
  6020. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6021. face = this.faces[ f ];
  6022. face.normal = face.__originalFaceNormal;
  6023. face.vertexNormals = face.__originalVertexNormals;
  6024. }
  6025. },
  6026. computeTangents: function () {
  6027. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6028. },
  6029. computeLineDistances: function () {
  6030. var d = 0;
  6031. var vertices = this.vertices;
  6032. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6033. if ( i > 0 ) {
  6034. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6035. }
  6036. this.lineDistances[ i ] = d;
  6037. }
  6038. },
  6039. computeBoundingBox: function () {
  6040. if ( this.boundingBox === null ) {
  6041. this.boundingBox = new THREE.Box3();
  6042. }
  6043. this.boundingBox.setFromPoints( this.vertices );
  6044. },
  6045. computeBoundingSphere: function () {
  6046. if ( this.boundingSphere === null ) {
  6047. this.boundingSphere = new THREE.Sphere();
  6048. }
  6049. this.boundingSphere.setFromPoints( this.vertices );
  6050. },
  6051. merge: function ( geometry, matrix, materialIndexOffset ) {
  6052. if ( geometry instanceof THREE.Geometry === false ) {
  6053. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6054. return;
  6055. }
  6056. var normalMatrix,
  6057. vertexOffset = this.vertices.length,
  6058. vertices1 = this.vertices,
  6059. vertices2 = geometry.vertices,
  6060. faces1 = this.faces,
  6061. faces2 = geometry.faces,
  6062. uvs1 = this.faceVertexUvs[ 0 ],
  6063. uvs2 = geometry.faceVertexUvs[ 0 ];
  6064. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6065. if ( matrix !== undefined ) {
  6066. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6067. }
  6068. // vertices
  6069. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6070. var vertex = vertices2[ i ];
  6071. var vertexCopy = vertex.clone();
  6072. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6073. vertices1.push( vertexCopy );
  6074. }
  6075. // faces
  6076. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6077. var face = faces2[ i ], faceCopy, normal, color,
  6078. faceVertexNormals = face.vertexNormals,
  6079. faceVertexColors = face.vertexColors;
  6080. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6081. faceCopy.normal.copy( face.normal );
  6082. if ( normalMatrix !== undefined ) {
  6083. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6084. }
  6085. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6086. normal = faceVertexNormals[ j ].clone();
  6087. if ( normalMatrix !== undefined ) {
  6088. normal.applyMatrix3( normalMatrix ).normalize();
  6089. }
  6090. faceCopy.vertexNormals.push( normal );
  6091. }
  6092. faceCopy.color.copy( face.color );
  6093. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6094. color = faceVertexColors[ j ];
  6095. faceCopy.vertexColors.push( color.clone() );
  6096. }
  6097. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6098. faces1.push( faceCopy );
  6099. }
  6100. // uvs
  6101. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6102. var uv = uvs2[ i ], uvCopy = [];
  6103. if ( uv === undefined ) {
  6104. continue;
  6105. }
  6106. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6107. uvCopy.push( uv[ j ].clone() );
  6108. }
  6109. uvs1.push( uvCopy );
  6110. }
  6111. },
  6112. mergeMesh: function ( mesh ) {
  6113. if ( mesh instanceof THREE.Mesh === false ) {
  6114. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6115. return;
  6116. }
  6117. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6118. this.merge( mesh.geometry, mesh.matrix );
  6119. },
  6120. /*
  6121. * Checks for duplicate vertices with hashmap.
  6122. * Duplicated vertices are removed
  6123. * and faces' vertices are updated.
  6124. */
  6125. mergeVertices: function () {
  6126. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6127. var unique = [], changes = [];
  6128. var v, key;
  6129. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6130. var precision = Math.pow( 10, precisionPoints );
  6131. var i, il, face;
  6132. var indices, j, jl;
  6133. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6134. v = this.vertices[ i ];
  6135. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6136. if ( verticesMap[ key ] === undefined ) {
  6137. verticesMap[ key ] = i;
  6138. unique.push( this.vertices[ i ] );
  6139. changes[ i ] = unique.length - 1;
  6140. } else {
  6141. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6142. changes[ i ] = changes[ verticesMap[ key ] ];
  6143. }
  6144. }
  6145. // if faces are completely degenerate after merging vertices, we
  6146. // have to remove them from the geometry.
  6147. var faceIndicesToRemove = [];
  6148. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6149. face = this.faces[ i ];
  6150. face.a = changes[ face.a ];
  6151. face.b = changes[ face.b ];
  6152. face.c = changes[ face.c ];
  6153. indices = [ face.a, face.b, face.c ];
  6154. var dupIndex = - 1;
  6155. // if any duplicate vertices are found in a Face3
  6156. // we have to remove the face as nothing can be saved
  6157. for ( var n = 0; n < 3; n ++ ) {
  6158. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6159. dupIndex = n;
  6160. faceIndicesToRemove.push( i );
  6161. break;
  6162. }
  6163. }
  6164. }
  6165. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6166. var idx = faceIndicesToRemove[ i ];
  6167. this.faces.splice( idx, 1 );
  6168. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6169. this.faceVertexUvs[ j ].splice( idx, 1 );
  6170. }
  6171. }
  6172. // Use unique set of vertices
  6173. var diff = this.vertices.length - unique.length;
  6174. this.vertices = unique;
  6175. return diff;
  6176. },
  6177. sortFacesByMaterialIndex: function () {
  6178. var faces = this.faces;
  6179. var length = faces.length;
  6180. // tag faces
  6181. for ( var i = 0; i < length; i ++ ) {
  6182. faces[ i ]._id = i;
  6183. }
  6184. // sort faces
  6185. function materialIndexSort( a, b ) {
  6186. return a.materialIndex - b.materialIndex;
  6187. }
  6188. faces.sort( materialIndexSort );
  6189. // sort uvs
  6190. var uvs1 = this.faceVertexUvs[ 0 ];
  6191. var uvs2 = this.faceVertexUvs[ 1 ];
  6192. var newUvs1, newUvs2;
  6193. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6194. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6195. for ( var i = 0; i < length; i ++ ) {
  6196. var id = faces[ i ]._id;
  6197. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6198. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6199. }
  6200. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6201. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6202. },
  6203. toJSON: function () {
  6204. var data = {
  6205. metadata: {
  6206. version: 4.4,
  6207. type: 'Geometry',
  6208. generator: 'Geometry.toJSON'
  6209. }
  6210. };
  6211. // standard Geometry serialization
  6212. data.uuid = this.uuid;
  6213. data.type = this.type;
  6214. if ( this.name !== '' ) data.name = this.name;
  6215. if ( this.parameters !== undefined ) {
  6216. var parameters = this.parameters;
  6217. for ( var key in parameters ) {
  6218. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6219. }
  6220. return data;
  6221. }
  6222. var vertices = [];
  6223. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6224. var vertex = this.vertices[ i ];
  6225. vertices.push( vertex.x, vertex.y, vertex.z );
  6226. }
  6227. var faces = [];
  6228. var normals = [];
  6229. var normalsHash = {};
  6230. var colors = [];
  6231. var colorsHash = {};
  6232. var uvs = [];
  6233. var uvsHash = {};
  6234. for ( var i = 0; i < this.faces.length; i ++ ) {
  6235. var face = this.faces[ i ];
  6236. var hasMaterial = true;
  6237. var hasFaceUv = false; // deprecated
  6238. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6239. var hasFaceNormal = face.normal.length() > 0;
  6240. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6241. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6242. var hasFaceVertexColor = face.vertexColors.length > 0;
  6243. var faceType = 0;
  6244. faceType = setBit( faceType, 0, 0 ); // isQuad
  6245. faceType = setBit( faceType, 1, hasMaterial );
  6246. faceType = setBit( faceType, 2, hasFaceUv );
  6247. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6248. faceType = setBit( faceType, 4, hasFaceNormal );
  6249. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6250. faceType = setBit( faceType, 6, hasFaceColor );
  6251. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6252. faces.push( faceType );
  6253. faces.push( face.a, face.b, face.c );
  6254. faces.push( face.materialIndex );
  6255. if ( hasFaceVertexUv ) {
  6256. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6257. faces.push(
  6258. getUvIndex( faceVertexUvs[ 0 ] ),
  6259. getUvIndex( faceVertexUvs[ 1 ] ),
  6260. getUvIndex( faceVertexUvs[ 2 ] )
  6261. );
  6262. }
  6263. if ( hasFaceNormal ) {
  6264. faces.push( getNormalIndex( face.normal ) );
  6265. }
  6266. if ( hasFaceVertexNormal ) {
  6267. var vertexNormals = face.vertexNormals;
  6268. faces.push(
  6269. getNormalIndex( vertexNormals[ 0 ] ),
  6270. getNormalIndex( vertexNormals[ 1 ] ),
  6271. getNormalIndex( vertexNormals[ 2 ] )
  6272. );
  6273. }
  6274. if ( hasFaceColor ) {
  6275. faces.push( getColorIndex( face.color ) );
  6276. }
  6277. if ( hasFaceVertexColor ) {
  6278. var vertexColors = face.vertexColors;
  6279. faces.push(
  6280. getColorIndex( vertexColors[ 0 ] ),
  6281. getColorIndex( vertexColors[ 1 ] ),
  6282. getColorIndex( vertexColors[ 2 ] )
  6283. );
  6284. }
  6285. }
  6286. function setBit( value, position, enabled ) {
  6287. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6288. }
  6289. function getNormalIndex( normal ) {
  6290. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6291. if ( normalsHash[ hash ] !== undefined ) {
  6292. return normalsHash[ hash ];
  6293. }
  6294. normalsHash[ hash ] = normals.length / 3;
  6295. normals.push( normal.x, normal.y, normal.z );
  6296. return normalsHash[ hash ];
  6297. }
  6298. function getColorIndex( color ) {
  6299. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6300. if ( colorsHash[ hash ] !== undefined ) {
  6301. return colorsHash[ hash ];
  6302. }
  6303. colorsHash[ hash ] = colors.length;
  6304. colors.push( color.getHex() );
  6305. return colorsHash[ hash ];
  6306. }
  6307. function getUvIndex( uv ) {
  6308. var hash = uv.x.toString() + uv.y.toString();
  6309. if ( uvsHash[ hash ] !== undefined ) {
  6310. return uvsHash[ hash ];
  6311. }
  6312. uvsHash[ hash ] = uvs.length / 2;
  6313. uvs.push( uv.x, uv.y );
  6314. return uvsHash[ hash ];
  6315. }
  6316. data.data = {};
  6317. data.data.vertices = vertices;
  6318. data.data.normals = normals;
  6319. if ( colors.length > 0 ) data.data.colors = colors;
  6320. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6321. data.data.faces = faces;
  6322. return data;
  6323. },
  6324. clone: function () {
  6325. /*
  6326. // Handle primitives
  6327. var parameters = this.parameters;
  6328. if ( parameters !== undefined ) {
  6329. var values = [];
  6330. for ( var key in parameters ) {
  6331. values.push( parameters[ key ] );
  6332. }
  6333. var geometry = Object.create( this.constructor.prototype );
  6334. this.constructor.apply( geometry, values );
  6335. return geometry;
  6336. }
  6337. return new this.constructor().copy( this );
  6338. */
  6339. return new THREE.Geometry().copy( this );
  6340. },
  6341. copy: function ( source ) {
  6342. this.vertices = [];
  6343. this.faces = [];
  6344. this.faceVertexUvs = [ [] ];
  6345. var vertices = source.vertices;
  6346. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6347. this.vertices.push( vertices[ i ].clone() );
  6348. }
  6349. var faces = source.faces;
  6350. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6351. this.faces.push( faces[ i ].clone() );
  6352. }
  6353. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6354. var faceVertexUvs = source.faceVertexUvs[ i ];
  6355. if ( this.faceVertexUvs[ i ] === undefined ) {
  6356. this.faceVertexUvs[ i ] = [];
  6357. }
  6358. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6359. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6360. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6361. var uv = uvs[ k ];
  6362. uvsCopy.push( uv.clone() );
  6363. }
  6364. this.faceVertexUvs[ i ].push( uvsCopy );
  6365. }
  6366. }
  6367. return this;
  6368. },
  6369. dispose: function () {
  6370. this.dispatchEvent( { type: 'dispose' } );
  6371. }
  6372. };
  6373. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6374. THREE.GeometryIdCount = 0;
  6375. // File:src/core/DirectGeometry.js
  6376. /**
  6377. * @author mrdoob / http://mrdoob.com/
  6378. */
  6379. THREE.DirectGeometry = function () {
  6380. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6381. this.uuid = THREE.Math.generateUUID();
  6382. this.name = '';
  6383. this.type = 'DirectGeometry';
  6384. this.indices = [];
  6385. this.vertices = [];
  6386. this.normals = [];
  6387. this.colors = [];
  6388. this.uvs = [];
  6389. this.uvs2 = [];
  6390. this.groups = [];
  6391. this.morphTargets = {};
  6392. this.skinWeights = [];
  6393. this.skinIndices = [];
  6394. // this.lineDistances = [];
  6395. this.boundingBox = null;
  6396. this.boundingSphere = null;
  6397. // update flags
  6398. this.verticesNeedUpdate = false;
  6399. this.normalsNeedUpdate = false;
  6400. this.colorsNeedUpdate = false;
  6401. this.uvsNeedUpdate = false;
  6402. this.groupsNeedUpdate = false;
  6403. };
  6404. THREE.DirectGeometry.prototype = {
  6405. constructor: THREE.DirectGeometry,
  6406. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6407. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6408. computeFaceNormals: function () {
  6409. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6410. },
  6411. computeVertexNormals: function () {
  6412. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6413. },
  6414. computeGroups: function ( geometry ) {
  6415. var group;
  6416. var groups = [];
  6417. var materialIndex;
  6418. var faces = geometry.faces;
  6419. for ( var i = 0; i < faces.length; i ++ ) {
  6420. var face = faces[ i ];
  6421. // materials
  6422. if ( face.materialIndex !== materialIndex ) {
  6423. materialIndex = face.materialIndex;
  6424. if ( group !== undefined ) {
  6425. group.count = ( i * 3 ) - group.start;
  6426. groups.push( group );
  6427. }
  6428. group = {
  6429. start: i * 3,
  6430. materialIndex: materialIndex
  6431. };
  6432. }
  6433. }
  6434. if ( group !== undefined ) {
  6435. group.count = ( i * 3 ) - group.start;
  6436. groups.push( group );
  6437. }
  6438. this.groups = groups;
  6439. },
  6440. fromGeometry: function ( geometry ) {
  6441. var faces = geometry.faces;
  6442. var vertices = geometry.vertices;
  6443. var faceVertexUvs = geometry.faceVertexUvs;
  6444. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6445. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6446. // morphs
  6447. var morphTargets = geometry.morphTargets;
  6448. var morphTargetsLength = morphTargets.length;
  6449. if ( morphTargetsLength > 0 ) {
  6450. var morphTargetsPosition = [];
  6451. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6452. morphTargetsPosition[ i ] = [];
  6453. }
  6454. this.morphTargets.position = morphTargetsPosition;
  6455. }
  6456. var morphNormals = geometry.morphNormals;
  6457. var morphNormalsLength = morphNormals.length;
  6458. if ( morphNormalsLength > 0 ) {
  6459. var morphTargetsNormal = [];
  6460. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6461. morphTargetsNormal[ i ] = [];
  6462. }
  6463. this.morphTargets.normal = morphTargetsNormal;
  6464. }
  6465. // skins
  6466. var skinIndices = geometry.skinIndices;
  6467. var skinWeights = geometry.skinWeights;
  6468. var hasSkinIndices = skinIndices.length === vertices.length;
  6469. var hasSkinWeights = skinWeights.length === vertices.length;
  6470. //
  6471. for ( var i = 0; i < faces.length; i ++ ) {
  6472. var face = faces[ i ];
  6473. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6474. var vertexNormals = face.vertexNormals;
  6475. if ( vertexNormals.length === 3 ) {
  6476. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6477. } else {
  6478. var normal = face.normal;
  6479. this.normals.push( normal, normal, normal );
  6480. }
  6481. var vertexColors = face.vertexColors;
  6482. if ( vertexColors.length === 3 ) {
  6483. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6484. } else {
  6485. var color = face.color;
  6486. this.colors.push( color, color, color );
  6487. }
  6488. if ( hasFaceVertexUv === true ) {
  6489. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6490. if ( vertexUvs !== undefined ) {
  6491. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6492. } else {
  6493. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6494. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6495. }
  6496. }
  6497. if ( hasFaceVertexUv2 === true ) {
  6498. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6499. if ( vertexUvs !== undefined ) {
  6500. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6501. } else {
  6502. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6503. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6504. }
  6505. }
  6506. // morphs
  6507. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6508. var morphTarget = morphTargets[ j ].vertices;
  6509. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6510. }
  6511. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6512. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6513. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6514. }
  6515. // skins
  6516. if ( hasSkinIndices ) {
  6517. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6518. }
  6519. if ( hasSkinWeights ) {
  6520. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6521. }
  6522. }
  6523. this.computeGroups( geometry );
  6524. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6525. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6526. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6527. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6528. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6529. return this;
  6530. },
  6531. dispose: function () {
  6532. this.dispatchEvent( { type: 'dispose' } );
  6533. }
  6534. };
  6535. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6536. // File:src/core/BufferGeometry.js
  6537. /**
  6538. * @author alteredq / http://alteredqualia.com/
  6539. * @author mrdoob / http://mrdoob.com/
  6540. */
  6541. THREE.BufferGeometry = function () {
  6542. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6543. this.uuid = THREE.Math.generateUUID();
  6544. this.name = '';
  6545. this.type = 'BufferGeometry';
  6546. this.index = null;
  6547. this.attributes = {};
  6548. this.morphAttributes = {};
  6549. this.groups = [];
  6550. this.boundingBox = null;
  6551. this.boundingSphere = null;
  6552. this.drawRange = { start: 0, count: Infinity };
  6553. };
  6554. THREE.BufferGeometry.prototype = {
  6555. constructor: THREE.BufferGeometry,
  6556. addIndex: function ( index ) {
  6557. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6558. this.setIndex( index );
  6559. },
  6560. getIndex: function () {
  6561. return this.index;
  6562. },
  6563. setIndex: function ( index ) {
  6564. this.index = index;
  6565. },
  6566. addAttribute: function ( name, attribute ) {
  6567. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6568. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6569. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6570. return;
  6571. }
  6572. if ( name === 'index' ) {
  6573. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6574. this.setIndex( attribute );
  6575. return;
  6576. }
  6577. this.attributes[ name ] = attribute;
  6578. },
  6579. getAttribute: function ( name ) {
  6580. return this.attributes[ name ];
  6581. },
  6582. removeAttribute: function ( name ) {
  6583. delete this.attributes[ name ];
  6584. },
  6585. get drawcalls() {
  6586. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6587. return this.groups;
  6588. },
  6589. get offsets() {
  6590. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6591. return this.groups;
  6592. },
  6593. addDrawCall: function ( start, count, indexOffset ) {
  6594. if ( indexOffset !== undefined ) {
  6595. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6596. }
  6597. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6598. this.addGroup( start, count );
  6599. },
  6600. clearDrawCalls: function () {
  6601. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6602. this.clearGroups();
  6603. },
  6604. addGroup: function ( start, count, materialIndex ) {
  6605. this.groups.push( {
  6606. start: start,
  6607. count: count,
  6608. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6609. } );
  6610. },
  6611. clearGroups: function () {
  6612. this.groups = [];
  6613. },
  6614. setDrawRange: function ( start, count ) {
  6615. this.drawRange.start = start;
  6616. this.drawRange.count = count;
  6617. },
  6618. applyMatrix: function ( matrix ) {
  6619. var position = this.attributes.position;
  6620. if ( position !== undefined ) {
  6621. matrix.applyToVector3Array( position.array );
  6622. position.needsUpdate = true;
  6623. }
  6624. var normal = this.attributes.normal;
  6625. if ( normal !== undefined ) {
  6626. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6627. normalMatrix.applyToVector3Array( normal.array );
  6628. normal.needsUpdate = true;
  6629. }
  6630. if ( this.boundingBox !== null ) {
  6631. this.computeBoundingBox();
  6632. }
  6633. if ( this.boundingSphere !== null ) {
  6634. this.computeBoundingSphere();
  6635. }
  6636. },
  6637. rotateX: function () {
  6638. // rotate geometry around world x-axis
  6639. var m1;
  6640. return function rotateX( angle ) {
  6641. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6642. m1.makeRotationX( angle );
  6643. this.applyMatrix( m1 );
  6644. return this;
  6645. };
  6646. }(),
  6647. rotateY: function () {
  6648. // rotate geometry around world y-axis
  6649. var m1;
  6650. return function rotateY( angle ) {
  6651. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6652. m1.makeRotationY( angle );
  6653. this.applyMatrix( m1 );
  6654. return this;
  6655. };
  6656. }(),
  6657. rotateZ: function () {
  6658. // rotate geometry around world z-axis
  6659. var m1;
  6660. return function rotateZ( angle ) {
  6661. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6662. m1.makeRotationZ( angle );
  6663. this.applyMatrix( m1 );
  6664. return this;
  6665. };
  6666. }(),
  6667. translate: function () {
  6668. // translate geometry
  6669. var m1;
  6670. return function translate( x, y, z ) {
  6671. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6672. m1.makeTranslation( x, y, z );
  6673. this.applyMatrix( m1 );
  6674. return this;
  6675. };
  6676. }(),
  6677. scale: function () {
  6678. // scale geometry
  6679. var m1;
  6680. return function scale( x, y, z ) {
  6681. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6682. m1.makeScale( x, y, z );
  6683. this.applyMatrix( m1 );
  6684. return this;
  6685. };
  6686. }(),
  6687. lookAt: function () {
  6688. var obj;
  6689. return function lookAt( vector ) {
  6690. if ( obj === undefined ) obj = new THREE.Object3D();
  6691. obj.lookAt( vector );
  6692. obj.updateMatrix();
  6693. this.applyMatrix( obj.matrix );
  6694. };
  6695. }(),
  6696. center: function () {
  6697. this.computeBoundingBox();
  6698. var offset = this.boundingBox.center().negate();
  6699. this.translate( offset.x, offset.y, offset.z );
  6700. return offset;
  6701. },
  6702. setFromObject: function ( object ) {
  6703. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6704. var geometry = object.geometry;
  6705. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6706. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6707. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6708. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6709. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6710. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6711. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6712. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6713. }
  6714. if ( geometry.boundingSphere !== null ) {
  6715. this.boundingSphere = geometry.boundingSphere.clone();
  6716. }
  6717. if ( geometry.boundingBox !== null ) {
  6718. this.boundingBox = geometry.boundingBox.clone();
  6719. }
  6720. } else if ( object instanceof THREE.Mesh ) {
  6721. if ( geometry instanceof THREE.Geometry ) {
  6722. this.fromGeometry( geometry );
  6723. }
  6724. }
  6725. return this;
  6726. },
  6727. updateFromObject: function ( object ) {
  6728. var geometry = object.geometry;
  6729. if ( object instanceof THREE.Mesh ) {
  6730. var direct = geometry.__directGeometry;
  6731. if ( direct === undefined ) {
  6732. return this.fromGeometry( geometry );
  6733. }
  6734. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6735. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6736. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6737. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6738. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6739. geometry.verticesNeedUpdate = false;
  6740. geometry.normalsNeedUpdate = false;
  6741. geometry.colorsNeedUpdate = false;
  6742. geometry.uvsNeedUpdate = false;
  6743. geometry.groupsNeedUpdate = false;
  6744. geometry = direct;
  6745. }
  6746. if ( geometry.verticesNeedUpdate === true ) {
  6747. var attribute = this.attributes.position;
  6748. if ( attribute !== undefined ) {
  6749. attribute.copyVector3sArray( geometry.vertices );
  6750. attribute.needsUpdate = true;
  6751. }
  6752. geometry.verticesNeedUpdate = false;
  6753. }
  6754. if ( geometry.normalsNeedUpdate === true ) {
  6755. var attribute = this.attributes.normal;
  6756. if ( attribute !== undefined ) {
  6757. attribute.copyVector3sArray( geometry.normals );
  6758. attribute.needsUpdate = true;
  6759. }
  6760. geometry.normalsNeedUpdate = false;
  6761. }
  6762. if ( geometry.colorsNeedUpdate === true ) {
  6763. var attribute = this.attributes.color;
  6764. if ( attribute !== undefined ) {
  6765. attribute.copyColorsArray( geometry.colors );
  6766. attribute.needsUpdate = true;
  6767. }
  6768. geometry.colorsNeedUpdate = false;
  6769. }
  6770. if ( geometry.uvsNeedUpdate ) {
  6771. var attribute = this.attributes.uv;
  6772. if ( attribute !== undefined ) {
  6773. attribute.copyVector2sArray( geometry.uvs );
  6774. attribute.needsUpdate = true;
  6775. }
  6776. geometry.uvsNeedUpdate = false;
  6777. }
  6778. if ( geometry.lineDistancesNeedUpdate ) {
  6779. var attribute = this.attributes.lineDistance;
  6780. if ( attribute !== undefined ) {
  6781. attribute.copyArray( geometry.lineDistances );
  6782. attribute.needsUpdate = true;
  6783. }
  6784. geometry.lineDistancesNeedUpdate = false;
  6785. }
  6786. if ( geometry.groupsNeedUpdate ) {
  6787. geometry.computeGroups( object.geometry );
  6788. this.groups = geometry.groups;
  6789. geometry.groupsNeedUpdate = false;
  6790. }
  6791. return this;
  6792. },
  6793. fromGeometry: function ( geometry ) {
  6794. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6795. return this.fromDirectGeometry( geometry.__directGeometry );
  6796. },
  6797. fromDirectGeometry: function ( geometry ) {
  6798. var positions = new Float32Array( geometry.vertices.length * 3 );
  6799. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6800. if ( geometry.normals.length > 0 ) {
  6801. var normals = new Float32Array( geometry.normals.length * 3 );
  6802. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6803. }
  6804. if ( geometry.colors.length > 0 ) {
  6805. var colors = new Float32Array( geometry.colors.length * 3 );
  6806. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6807. }
  6808. if ( geometry.uvs.length > 0 ) {
  6809. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6810. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6811. }
  6812. if ( geometry.uvs2.length > 0 ) {
  6813. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6814. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6815. }
  6816. if ( geometry.indices.length > 0 ) {
  6817. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6818. var indices = new TypeArray( geometry.indices.length * 3 );
  6819. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6820. }
  6821. // groups
  6822. this.groups = geometry.groups;
  6823. // morphs
  6824. for ( var name in geometry.morphTargets ) {
  6825. var array = [];
  6826. var morphTargets = geometry.morphTargets[ name ];
  6827. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6828. var morphTarget = morphTargets[ i ];
  6829. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6830. array.push( attribute.copyVector3sArray( morphTarget ) );
  6831. }
  6832. this.morphAttributes[ name ] = array;
  6833. }
  6834. // skinning
  6835. if ( geometry.skinIndices.length > 0 ) {
  6836. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6837. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6838. }
  6839. if ( geometry.skinWeights.length > 0 ) {
  6840. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6841. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6842. }
  6843. //
  6844. if ( geometry.boundingSphere !== null ) {
  6845. this.boundingSphere = geometry.boundingSphere.clone();
  6846. }
  6847. if ( geometry.boundingBox !== null ) {
  6848. this.boundingBox = geometry.boundingBox.clone();
  6849. }
  6850. return this;
  6851. },
  6852. computeBoundingBox: function () {
  6853. var vector = new THREE.Vector3();
  6854. return function () {
  6855. if ( this.boundingBox === null ) {
  6856. this.boundingBox = new THREE.Box3();
  6857. }
  6858. var positions = this.attributes.position.array;
  6859. if ( positions ) {
  6860. var bb = this.boundingBox;
  6861. bb.makeEmpty();
  6862. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6863. vector.fromArray( positions, i );
  6864. bb.expandByPoint( vector );
  6865. }
  6866. }
  6867. if ( positions === undefined || positions.length === 0 ) {
  6868. this.boundingBox.min.set( 0, 0, 0 );
  6869. this.boundingBox.max.set( 0, 0, 0 );
  6870. }
  6871. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6872. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6873. }
  6874. };
  6875. }(),
  6876. computeBoundingSphere: function () {
  6877. var box = new THREE.Box3();
  6878. var vector = new THREE.Vector3();
  6879. return function () {
  6880. if ( this.boundingSphere === null ) {
  6881. this.boundingSphere = new THREE.Sphere();
  6882. }
  6883. var positions = this.attributes.position.array;
  6884. if ( positions ) {
  6885. box.makeEmpty();
  6886. var center = this.boundingSphere.center;
  6887. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6888. vector.fromArray( positions, i );
  6889. box.expandByPoint( vector );
  6890. }
  6891. box.center( center );
  6892. // hoping to find a boundingSphere with a radius smaller than the
  6893. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6894. var maxRadiusSq = 0;
  6895. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6896. vector.fromArray( positions, i );
  6897. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6898. }
  6899. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6900. if ( isNaN( this.boundingSphere.radius ) ) {
  6901. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6902. }
  6903. }
  6904. };
  6905. }(),
  6906. computeFaceNormals: function () {
  6907. // backwards compatibility
  6908. },
  6909. computeVertexNormals: function () {
  6910. var index = this.index;
  6911. var attributes = this.attributes;
  6912. var groups = this.groups;
  6913. if ( attributes.position ) {
  6914. var positions = attributes.position.array;
  6915. if ( attributes.normal === undefined ) {
  6916. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6917. } else {
  6918. // reset existing normals to zero
  6919. var array = attributes.normal.array;
  6920. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6921. array[ i ] = 0;
  6922. }
  6923. }
  6924. var normals = attributes.normal.array;
  6925. var vA, vB, vC,
  6926. pA = new THREE.Vector3(),
  6927. pB = new THREE.Vector3(),
  6928. pC = new THREE.Vector3(),
  6929. cb = new THREE.Vector3(),
  6930. ab = new THREE.Vector3();
  6931. // indexed elements
  6932. if ( index ) {
  6933. var indices = index.array;
  6934. if ( groups.length === 0 ) {
  6935. this.addGroup( 0, indices.length );
  6936. }
  6937. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6938. var group = groups[ j ];
  6939. var start = group.start;
  6940. var count = group.count;
  6941. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6942. vA = indices[ i + 0 ] * 3;
  6943. vB = indices[ i + 1 ] * 3;
  6944. vC = indices[ i + 2 ] * 3;
  6945. pA.fromArray( positions, vA );
  6946. pB.fromArray( positions, vB );
  6947. pC.fromArray( positions, vC );
  6948. cb.subVectors( pC, pB );
  6949. ab.subVectors( pA, pB );
  6950. cb.cross( ab );
  6951. normals[ vA ] += cb.x;
  6952. normals[ vA + 1 ] += cb.y;
  6953. normals[ vA + 2 ] += cb.z;
  6954. normals[ vB ] += cb.x;
  6955. normals[ vB + 1 ] += cb.y;
  6956. normals[ vB + 2 ] += cb.z;
  6957. normals[ vC ] += cb.x;
  6958. normals[ vC + 1 ] += cb.y;
  6959. normals[ vC + 2 ] += cb.z;
  6960. }
  6961. }
  6962. } else {
  6963. // non-indexed elements (unconnected triangle soup)
  6964. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6965. pA.fromArray( positions, i );
  6966. pB.fromArray( positions, i + 3 );
  6967. pC.fromArray( positions, i + 6 );
  6968. cb.subVectors( pC, pB );
  6969. ab.subVectors( pA, pB );
  6970. cb.cross( ab );
  6971. normals[ i ] = cb.x;
  6972. normals[ i + 1 ] = cb.y;
  6973. normals[ i + 2 ] = cb.z;
  6974. normals[ i + 3 ] = cb.x;
  6975. normals[ i + 4 ] = cb.y;
  6976. normals[ i + 5 ] = cb.z;
  6977. normals[ i + 6 ] = cb.x;
  6978. normals[ i + 7 ] = cb.y;
  6979. normals[ i + 8 ] = cb.z;
  6980. }
  6981. }
  6982. this.normalizeNormals();
  6983. attributes.normal.needsUpdate = true;
  6984. }
  6985. },
  6986. computeTangents: function () {
  6987. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6988. },
  6989. computeOffsets: function ( size ) {
  6990. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  6991. },
  6992. merge: function ( geometry, offset ) {
  6993. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6994. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6995. return;
  6996. }
  6997. if ( offset === undefined ) offset = 0;
  6998. var attributes = this.attributes;
  6999. for ( var key in attributes ) {
  7000. if ( geometry.attributes[ key ] === undefined ) continue;
  7001. var attribute1 = attributes[ key ];
  7002. var attributeArray1 = attribute1.array;
  7003. var attribute2 = geometry.attributes[ key ];
  7004. var attributeArray2 = attribute2.array;
  7005. var attributeSize = attribute2.itemSize;
  7006. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7007. attributeArray1[ j ] = attributeArray2[ i ];
  7008. }
  7009. }
  7010. return this;
  7011. },
  7012. normalizeNormals: function () {
  7013. var normals = this.attributes.normal.array;
  7014. var x, y, z, n;
  7015. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7016. x = normals[ i ];
  7017. y = normals[ i + 1 ];
  7018. z = normals[ i + 2 ];
  7019. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7020. normals[ i ] *= n;
  7021. normals[ i + 1 ] *= n;
  7022. normals[ i + 2 ] *= n;
  7023. }
  7024. },
  7025. toJSON: function () {
  7026. var data = {
  7027. metadata: {
  7028. version: 4.4,
  7029. type: 'BufferGeometry',
  7030. generator: 'BufferGeometry.toJSON'
  7031. }
  7032. };
  7033. // standard BufferGeometry serialization
  7034. data.uuid = this.uuid;
  7035. data.type = this.type;
  7036. if ( this.name !== '' ) data.name = this.name;
  7037. if ( this.parameters !== undefined ) {
  7038. var parameters = this.parameters;
  7039. for ( var key in parameters ) {
  7040. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7041. }
  7042. return data;
  7043. }
  7044. data.data = { attributes: {} };
  7045. var index = this.index;
  7046. if ( index !== null ) {
  7047. var array = Array.prototype.slice.call( index.array );
  7048. data.data.index = {
  7049. type: index.array.constructor.name,
  7050. array: array
  7051. };
  7052. }
  7053. var attributes = this.attributes;
  7054. for ( var key in attributes ) {
  7055. var attribute = attributes[ key ];
  7056. var array = Array.prototype.slice.call( attribute.array );
  7057. data.data.attributes[ key ] = {
  7058. itemSize: attribute.itemSize,
  7059. type: attribute.array.constructor.name,
  7060. array: array
  7061. };
  7062. }
  7063. var groups = this.groups;
  7064. if ( groups.length > 0 ) {
  7065. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7066. }
  7067. var boundingSphere = this.boundingSphere;
  7068. if ( boundingSphere !== null ) {
  7069. data.data.boundingSphere = {
  7070. center: boundingSphere.center.toArray(),
  7071. radius: boundingSphere.radius
  7072. };
  7073. }
  7074. return data;
  7075. },
  7076. clone: function () {
  7077. /*
  7078. // Handle primitives
  7079. var parameters = this.parameters;
  7080. if ( parameters !== undefined ) {
  7081. var values = [];
  7082. for ( var key in parameters ) {
  7083. values.push( parameters[ key ] );
  7084. }
  7085. var geometry = Object.create( this.constructor.prototype );
  7086. this.constructor.apply( geometry, values );
  7087. return geometry;
  7088. }
  7089. return new this.constructor().copy( this );
  7090. */
  7091. return new THREE.BufferGeometry().copy( this );
  7092. },
  7093. copy: function ( source ) {
  7094. var index = source.index;
  7095. if ( index !== null ) {
  7096. this.setIndex( index.clone() );
  7097. }
  7098. var attributes = source.attributes;
  7099. for ( var name in attributes ) {
  7100. var attribute = attributes[ name ];
  7101. this.addAttribute( name, attribute.clone() );
  7102. }
  7103. var groups = source.groups;
  7104. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7105. var group = groups[ i ];
  7106. this.addGroup( group.start, group.count );
  7107. }
  7108. return this;
  7109. },
  7110. dispose: function () {
  7111. this.dispatchEvent( { type: 'dispose' } );
  7112. }
  7113. };
  7114. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7115. THREE.BufferGeometry.MaxIndex = 65535;
  7116. // File:src/core/InstancedBufferGeometry.js
  7117. /**
  7118. * @author benaadams / https://twitter.com/ben_a_adams
  7119. */
  7120. THREE.InstancedBufferGeometry = function () {
  7121. THREE.BufferGeometry.call( this );
  7122. this.type = 'InstancedBufferGeometry';
  7123. this.maxInstancedCount = undefined;
  7124. };
  7125. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7126. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7127. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7128. this.groups.push( {
  7129. start: start,
  7130. count: count,
  7131. instances: instances
  7132. } );
  7133. };
  7134. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7135. var index = source.index;
  7136. if ( index !== null ) {
  7137. this.setIndex( index.clone() );
  7138. }
  7139. var attributes = source.attributes;
  7140. for ( var name in attributes ) {
  7141. var attribute = attributes[ name ];
  7142. this.addAttribute( name, attribute.clone() );
  7143. }
  7144. var groups = source.groups;
  7145. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7146. var group = groups[ i ];
  7147. this.addGroup( group.start, group.count, group.instances );
  7148. }
  7149. return this;
  7150. };
  7151. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7152. // File:src/core/Uniform.js
  7153. /**
  7154. * @author mrdoob / http://mrdoob.com/
  7155. */
  7156. THREE.Uniform = function ( type, value ) {
  7157. this.type = type;
  7158. this.value = value;
  7159. this.dynamic = false;
  7160. };
  7161. THREE.Uniform.prototype = {
  7162. constructor: THREE.Uniform,
  7163. onUpdate: function ( callback ) {
  7164. this.dynamic = true;
  7165. this.onUpdateCallback = callback;
  7166. return this;
  7167. }
  7168. };
  7169. // File:src/animation/AnimationClip.js
  7170. /**
  7171. *
  7172. * Reusable set of Tracks that represent an animation.
  7173. *
  7174. * @author Ben Houston / http://clara.io/
  7175. * @author David Sarno / http://lighthaus.us/
  7176. */
  7177. THREE.AnimationClip = function ( name, duration, tracks ) {
  7178. this.name = name || THREE.Math.generateUUID();
  7179. this.tracks = tracks;
  7180. this.duration = ( duration !== undefined ) ? duration : -1;
  7181. // this means it should figure out its duration by scanning the tracks
  7182. if ( this.duration < 0 ) {
  7183. this.resetDuration();
  7184. }
  7185. // maybe only do these on demand, as doing them here could potentially slow down loading
  7186. // but leaving these here during development as this ensures a lot of testing of these functions
  7187. this.trim();
  7188. this.optimize();
  7189. };
  7190. THREE.AnimationClip.prototype = {
  7191. constructor: THREE.AnimationClip,
  7192. resetDuration: function() {
  7193. var tracks = this.tracks,
  7194. duration = 0;
  7195. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7196. var track = this.tracks[ i ];
  7197. duration = Math.max(
  7198. duration, track.times[ track.times.length - 1 ] );
  7199. }
  7200. this.duration = duration;
  7201. },
  7202. trim: function() {
  7203. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7204. this.tracks[ i ].trim( 0, this.duration );
  7205. }
  7206. return this;
  7207. },
  7208. optimize: function() {
  7209. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7210. this.tracks[ i ].optimize();
  7211. }
  7212. return this;
  7213. }
  7214. };
  7215. // Static methods:
  7216. Object.assign( THREE.AnimationClip, {
  7217. parse: function( json ) {
  7218. var tracks = [],
  7219. jsonTracks = json.tracks,
  7220. frameTime = 1.0 / ( json.fps || 1.0 );
  7221. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7222. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7223. }
  7224. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7225. },
  7226. toJSON: function( clip ) {
  7227. var tracks = [],
  7228. clipTracks = clip.tracks;
  7229. var json = {
  7230. 'name': clip.name,
  7231. 'duration': clip.duration,
  7232. 'tracks': tracks
  7233. };
  7234. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7235. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7236. }
  7237. return json;
  7238. },
  7239. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7240. var numMorphTargets = morphTargetSequence.length;
  7241. var tracks = [];
  7242. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7243. var times = [];
  7244. var values = [];
  7245. times.push(
  7246. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7247. i,
  7248. ( i + 1 ) % numMorphTargets );
  7249. values.push( 0, 1, 0 );
  7250. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7251. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7252. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7253. // if there is a key at the first frame, duplicate it as the
  7254. // last frame as well for perfect loop.
  7255. if ( times[ 0 ] === 0 ) {
  7256. times.push( numMorphTargets );
  7257. values.push( values[ 0 ] );
  7258. }
  7259. tracks.push(
  7260. new THREE.NumberKeyframeTrack(
  7261. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7262. times, values
  7263. ).scale( 1.0 / fps ) );
  7264. }
  7265. return new THREE.AnimationClip( name, -1, tracks );
  7266. },
  7267. findByName: function( clipArray, name ) {
  7268. for ( var i = 0; i < clipArray.length; i ++ ) {
  7269. if ( clipArray[ i ].name === name ) {
  7270. return clipArray[ i ];
  7271. }
  7272. }
  7273. return null;
  7274. },
  7275. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7276. var animationToMorphTargets = {};
  7277. // tested with https://regex101.com/ on trick sequences
  7278. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7279. var pattern = /^([\w-]*?)([\d]+)$/;
  7280. // sort morph target names into animation groups based
  7281. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7282. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7283. var morphTarget = morphTargets[ i ];
  7284. var parts = morphTarget.name.match( pattern );
  7285. if ( parts && parts.length > 1 ) {
  7286. var name = parts[ 1 ];
  7287. var animationMorphTargets = animationToMorphTargets[ name ];
  7288. if ( ! animationMorphTargets ) {
  7289. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7290. }
  7291. animationMorphTargets.push( morphTarget );
  7292. }
  7293. }
  7294. var clips = [];
  7295. for ( var name in animationToMorphTargets ) {
  7296. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7297. }
  7298. return clips;
  7299. },
  7300. // parse the animation.hierarchy format
  7301. parseAnimation: function( animation, bones, nodeName ) {
  7302. if ( ! animation ) {
  7303. console.error( " no animation in JSONLoader data" );
  7304. return null;
  7305. }
  7306. var addNonemptyTrack = function(
  7307. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7308. // only return track if there are actually keys.
  7309. if ( animationKeys.length !== 0 ) {
  7310. var times = [];
  7311. var values = [];
  7312. THREE.AnimationUtils.flattenJSON(
  7313. animationKeys, times, values, propertyName );
  7314. // empty keys are filtered out, so check again
  7315. if ( times.length !== 0 ) {
  7316. destTracks.push( new trackType( trackName, times, values ) );
  7317. }
  7318. }
  7319. };
  7320. var tracks = [];
  7321. var clipName = animation.name || 'default';
  7322. // automatic length determination in AnimationClip.
  7323. var duration = animation.length || -1;
  7324. var fps = animation.fps || 30;
  7325. var hierarchyTracks = animation.hierarchy || [];
  7326. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7327. var animationKeys = hierarchyTracks[ h ].keys;
  7328. // skip empty tracks
  7329. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7330. // process morph targets in a way exactly compatible
  7331. // with AnimationHandler.init( animation )
  7332. if ( animationKeys[0].morphTargets ) {
  7333. // figure out all morph targets used in this track
  7334. var morphTargetNames = {};
  7335. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7336. if ( animationKeys[k].morphTargets ) {
  7337. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7338. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7339. }
  7340. }
  7341. }
  7342. // create a track for each morph target with all zero
  7343. // morphTargetInfluences except for the keys in which
  7344. // the morphTarget is named.
  7345. for ( var morphTargetName in morphTargetNames ) {
  7346. var times = [];
  7347. var values = [];
  7348. for ( var m = 0;
  7349. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7350. var animationKey = animationKeys[k];
  7351. times.push( animationKey.time );
  7352. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7353. }
  7354. tracks.push( new THREE.NumberKeyframeTrack(
  7355. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7356. }
  7357. duration = morphTargetNames.length * ( fps || 1.0 );
  7358. } else {
  7359. // ...assume skeletal animation
  7360. var boneName = '.bones[' + bones[ h ].name + ']';
  7361. addNonemptyTrack(
  7362. THREE.VectorKeyframeTrack, boneName + '.position',
  7363. animationKeys, 'pos', tracks );
  7364. addNonemptyTrack(
  7365. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7366. animationKeys, 'rot', tracks );
  7367. addNonemptyTrack(
  7368. THREE.VectorKeyframeTrack, boneName + '.scale',
  7369. animationKeys, 'scl', tracks );
  7370. }
  7371. }
  7372. if ( tracks.length === 0 ) {
  7373. return null;
  7374. }
  7375. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7376. return clip;
  7377. }
  7378. } );
  7379. // File:src/animation/AnimationMixer.js
  7380. /**
  7381. *
  7382. * Player for AnimationClips.
  7383. *
  7384. *
  7385. * @author Ben Houston / http://clara.io/
  7386. * @author David Sarno / http://lighthaus.us/
  7387. * @author tschw
  7388. */
  7389. THREE.AnimationMixer = function( root ) {
  7390. this._root = root;
  7391. this._initMemoryManager();
  7392. this._accuIndex = 0;
  7393. this.time = 0;
  7394. this.timeScale = 1.0;
  7395. };
  7396. THREE.AnimationMixer.prototype = {
  7397. constructor: THREE.AnimationMixer,
  7398. // return an action for a clip optionally using a custom root target
  7399. // object (this method allocates a lot of dynamic memory in case a
  7400. // previously unknown clip/root combination is specified)
  7401. clipAction: function( clip, optionalRoot ) {
  7402. var root = optionalRoot || this._root,
  7403. rootUuid = root.uuid,
  7404. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7405. clipObject = ( clip !== clipName ) ? clip : null,
  7406. actionsForClip = this._actionsByClip[ clipName ],
  7407. prototypeAction;
  7408. if ( actionsForClip !== undefined ) {
  7409. var existingAction =
  7410. actionsForClip.actionByRoot[ rootUuid ];
  7411. if ( existingAction !== undefined ) {
  7412. return existingAction;
  7413. }
  7414. // we know the clip, so we don't have to parse all
  7415. // the bindings again but can just copy
  7416. prototypeAction = actionsForClip.knownActions[ 0 ];
  7417. // also, take the clip from the prototype action
  7418. clipObject = prototypeAction._clip;
  7419. if ( clip !== clipName && clip !== clipObject ) {
  7420. throw new Error(
  7421. "Different clips with the same name detected!" );
  7422. }
  7423. }
  7424. // clip must be known when specified via string
  7425. if ( clipObject === null ) return null;
  7426. // allocate all resources required to run it
  7427. var newAction = new THREE.
  7428. AnimationMixer._Action( this, clipObject, optionalRoot );
  7429. this._bindAction( newAction, prototypeAction );
  7430. // and make the action known to the memory manager
  7431. this._addInactiveAction( newAction, clipName, rootUuid );
  7432. return newAction;
  7433. },
  7434. // get an existing action
  7435. existingAction: function( clip, optionalRoot ) {
  7436. var root = optionalRoot || this._root,
  7437. rootUuid = root.uuid,
  7438. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7439. actionsForClip = this._actionsByClip[ clipName ];
  7440. if ( actionsForClip !== undefined ) {
  7441. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7442. }
  7443. return null;
  7444. },
  7445. // deactivates all previously scheduled actions
  7446. stopAllAction: function() {
  7447. var actions = this._actions,
  7448. nActions = this._nActiveActions,
  7449. bindings = this._bindings,
  7450. nBindings = this._nActiveBindings;
  7451. this._nActiveActions = 0;
  7452. this._nActiveBindings = 0;
  7453. for ( var i = 0; i !== nActions; ++ i ) {
  7454. actions[ i ].reset();
  7455. }
  7456. for ( var i = 0; i !== nBindings; ++ i ) {
  7457. bindings[ i ].useCount = 0;
  7458. }
  7459. return this;
  7460. },
  7461. // advance the time and update apply the animation
  7462. update: function( deltaTime ) {
  7463. deltaTime *= this.timeScale;
  7464. var actions = this._actions,
  7465. nActions = this._nActiveActions,
  7466. time = this.time += deltaTime,
  7467. timeDirection = Math.sign( deltaTime ),
  7468. accuIndex = this._accuIndex ^= 1;
  7469. // run active actions
  7470. for ( var i = 0; i !== nActions; ++ i ) {
  7471. var action = actions[ i ];
  7472. if ( action.enabled ) {
  7473. action._update( time, deltaTime, timeDirection, accuIndex );
  7474. }
  7475. }
  7476. // update scene graph
  7477. var bindings = this._bindings,
  7478. nBindings = this._nActiveBindings;
  7479. for ( var i = 0; i !== nBindings; ++ i ) {
  7480. bindings[ i ].apply( accuIndex );
  7481. }
  7482. return this;
  7483. },
  7484. // return this mixer's root target object
  7485. getRoot: function() {
  7486. return this._root;
  7487. },
  7488. // free all resources specific to a particular clip
  7489. uncacheClip: function( clip ) {
  7490. var actions = this._actions,
  7491. clipName = clip.name,
  7492. actionsByClip = this._actionsByClip,
  7493. actionsForClip = actionsByClip[ clipName ];
  7494. if ( actionsForClip !== undefined ) {
  7495. // note: just calling _removeInactiveAction would mess up the
  7496. // iteration state and also require updating the state we can
  7497. // just throw away
  7498. var actionsToRemove = actionsForClip.knownActions;
  7499. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7500. var action = actionsToRemove[ i ];
  7501. this._deactivateAction( action );
  7502. var cacheIndex = action._cacheIndex,
  7503. lastInactiveAction = actions[ actions.length - 1 ];
  7504. action._cacheIndex = null;
  7505. action._byClipCacheIndex = null;
  7506. lastInactiveAction._cacheIndex = cacheIndex;
  7507. actions[ cacheIndex ] = lastInactiveAction;
  7508. actions.pop();
  7509. this._removeInactiveBindingsForAction( action );
  7510. }
  7511. delete actionsByClip[ clipName ];
  7512. }
  7513. },
  7514. // free all resources specific to a particular root target object
  7515. uncacheRoot: function( root ) {
  7516. var rootUuid = root.uuid,
  7517. actionsByClip = this._actionsByClip;
  7518. for ( var clipName in actionsByClip ) {
  7519. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7520. action = actionByRoot[ rootUuid ];
  7521. if ( action !== undefined ) {
  7522. this._deactivateAction( action );
  7523. this._removeInactiveAction( action );
  7524. }
  7525. }
  7526. var bindingsByRoot = this._bindingsByRootAndName,
  7527. bindingByName = bindingsByRoot[ rootUuid ];
  7528. if ( bindingByName !== undefined ) {
  7529. for ( var trackName in bindingByName ) {
  7530. var binding = bindingByName[ trackName ];
  7531. binding.restoreOriginalState();
  7532. this._removeInactiveBinding( binding );
  7533. }
  7534. }
  7535. },
  7536. // remove a targeted clip from the cache
  7537. uncacheAction: function( clip, optionalRoot ) {
  7538. var action = this.existingAction( clip, optionalRoot );
  7539. if ( action !== null ) {
  7540. this._deactivateAction( action );
  7541. this._removeInactiveAction( action );
  7542. }
  7543. }
  7544. };
  7545. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7546. THREE.AnimationMixer._Action =
  7547. function( mixer, clip, localRoot ) {
  7548. this._mixer = mixer;
  7549. this._clip = clip;
  7550. this._localRoot = localRoot || null;
  7551. var tracks = clip.tracks,
  7552. nTracks = tracks.length,
  7553. interpolants = new Array( nTracks );
  7554. var interpolantSettings = {
  7555. endingStart: THREE.ZeroCurvatureEnding,
  7556. endingEnd: THREE.ZeroCurvatureEnding
  7557. };
  7558. for ( var i = 0; i !== nTracks; ++ i ) {
  7559. var interpolant = tracks[ i ].createInterpolant( null );
  7560. interpolants[ i ] = interpolant;
  7561. interpolant.settings = interpolantSettings
  7562. }
  7563. this._interpolantSettings = interpolantSettings;
  7564. this._interpolants = interpolants; // bound by the mixer
  7565. // inside: PropertyMixer (managed by the mixer)
  7566. this._propertyBindings = new Array( nTracks );
  7567. this._cacheIndex = null; // for the memory manager
  7568. this._byClipCacheIndex = null; // for the memory manager
  7569. this._timeScaleInterpolant = null;
  7570. this._weightInterpolant = null;
  7571. this.loop = THREE.LoopRepeat;
  7572. this._loopCount = -1;
  7573. // global mixer time when the action is to be started
  7574. // it's set back to 'null' upon start of the action
  7575. this._startTime = null;
  7576. // scaled local time of the action
  7577. // gets clamped or wrapped to 0..clip.duration according to loop
  7578. this.time = 0;
  7579. this.timeScale = 1;
  7580. this._effectiveTimeScale = 1;
  7581. this.weight = 1;
  7582. this._effectiveWeight = 1;
  7583. this.repetitions = Infinity; // no. of repetitions when looping
  7584. this.paused = false; // false -> zero effective time scale
  7585. this.enabled = true; // true -> zero effective weight
  7586. this.clampWhenFinished = false; // keep feeding the last frame?
  7587. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7588. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7589. };
  7590. THREE.AnimationMixer._Action.prototype = {
  7591. constructor: THREE.AnimationMixer._Action,
  7592. // State & Scheduling
  7593. play: function() {
  7594. this._mixer._activateAction( this );
  7595. return this;
  7596. },
  7597. stop: function() {
  7598. this._mixer._deactivateAction( this );
  7599. return this.reset();
  7600. },
  7601. reset: function() {
  7602. this.paused = false;
  7603. this.enabled = true;
  7604. this.time = 0; // restart clip
  7605. this._loopCount = -1; // forget previous loops
  7606. this._startTime = null; // forget scheduling
  7607. return this.stopFading().stopWarping();
  7608. },
  7609. isRunning: function() {
  7610. var start = this._startTime;
  7611. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7612. this._startTime === null && this._mixer._isActiveAction( this )
  7613. },
  7614. // return true when play has been called
  7615. isScheduled: function() {
  7616. return this._mixer._isActiveAction( this );
  7617. },
  7618. startAt: function( time ) {
  7619. this._startTime = time;
  7620. return this;
  7621. },
  7622. setLoop: function( mode, repetitions ) {
  7623. this.loop = mode;
  7624. this.repetitions = repetitions;
  7625. return this;
  7626. },
  7627. // Weight
  7628. // set the weight stopping any scheduled fading
  7629. // although .enabled = false yields an effective weight of zero, this
  7630. // method does *not* change .enabled, because it would be confusing
  7631. setEffectiveWeight: function( weight ) {
  7632. this.weight = weight;
  7633. // note: same logic as when updated at runtime
  7634. this._effectiveWeight = this.enabled ? weight : 0;
  7635. return this.stopFading();
  7636. },
  7637. // return the weight considering fading and .enabled
  7638. getEffectiveWeight: function() {
  7639. return this._effectiveWeight;
  7640. },
  7641. fadeIn: function( duration ) {
  7642. return this._scheduleFading( duration, 0, 1 );
  7643. },
  7644. fadeOut: function( duration ) {
  7645. return this._scheduleFading( duration, 1, 0 );
  7646. },
  7647. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7648. var mixer = this._mixer;
  7649. fadeOutAction.fadeOut( duration );
  7650. this.fadeIn( duration );
  7651. if( warp ) {
  7652. var fadeInDuration = this._clip.duration,
  7653. fadeOutDuration = fadeOutAction._clip.duration,
  7654. startEndRatio = fadeOutDuration / fadeInDuration,
  7655. endStartRatio = fadeInDuration / fadeOutDuration;
  7656. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7657. this.warp( endStartRatio, 1.0, duration );
  7658. }
  7659. return this;
  7660. },
  7661. crossFadeTo: function( fadeInAction, duration, warp ) {
  7662. return fadeInAction.crossFadeFrom( this, duration, warp );
  7663. },
  7664. stopFading: function() {
  7665. var weightInterpolant = this._weightInterpolant;
  7666. if ( weightInterpolant !== null ) {
  7667. this._weightInterpolant = null;
  7668. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7669. }
  7670. return this;
  7671. },
  7672. // Time Scale Control
  7673. // set the weight stopping any scheduled warping
  7674. // although .paused = true yields an effective time scale of zero, this
  7675. // method does *not* change .paused, because it would be confusing
  7676. setEffectiveTimeScale: function( timeScale ) {
  7677. this.timeScale = timeScale;
  7678. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7679. return this.stopWarping();
  7680. },
  7681. // return the time scale considering warping and .paused
  7682. getEffectiveTimeScale: function() {
  7683. return this._effectiveTimeScale;
  7684. },
  7685. setDuration: function( duration ) {
  7686. this.timeScale = this._clip.duration / duration;
  7687. return this.stopWarping();
  7688. },
  7689. syncWith: function( action ) {
  7690. this.time = action.time;
  7691. this.timeScale = action.timeScale;
  7692. return this.stopWarping();
  7693. },
  7694. halt: function( duration ) {
  7695. return this.warp( this._currentTimeScale, 0, duration );
  7696. },
  7697. warp: function( startTimeScale, endTimeScale, duration ) {
  7698. var mixer = this._mixer, now = mixer.time,
  7699. interpolant = this._timeScaleInterpolant,
  7700. timeScale = this.timeScale;
  7701. if ( interpolant === null ) {
  7702. interpolant = mixer._lendControlInterpolant(),
  7703. this._timeScaleInterpolant = interpolant;
  7704. }
  7705. var times = interpolant.parameterPositions,
  7706. values = interpolant.sampleValues;
  7707. times[ 0 ] = now;
  7708. times[ 1 ] = now + duration;
  7709. values[ 0 ] = startTimeScale / timeScale;
  7710. values[ 1 ] = endTimeScale / timeScale;
  7711. return this;
  7712. },
  7713. stopWarping: function() {
  7714. var timeScaleInterpolant = this._timeScaleInterpolant;
  7715. if ( timeScaleInterpolant !== null ) {
  7716. this._timeScaleInterpolant = null;
  7717. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7718. }
  7719. return this;
  7720. },
  7721. // Object Accessors
  7722. getMixer: function() {
  7723. return this._mixer;
  7724. },
  7725. getClip: function() {
  7726. return this._clip;
  7727. },
  7728. getRoot: function() {
  7729. return this._localRoot || this._mixer._root;
  7730. },
  7731. // Interna
  7732. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7733. // called by the mixer
  7734. var startTime = this._startTime;
  7735. if ( startTime !== null ) {
  7736. // check for scheduled start of action
  7737. var timeRunning = ( time - startTime ) * timeDirection;
  7738. if ( timeRunning < 0 || timeDirection === 0 ) {
  7739. return; // yet to come / don't decide when delta = 0
  7740. }
  7741. // start
  7742. this._startTime = null; // unschedule
  7743. deltaTime = timeDirection * timeRunning;
  7744. }
  7745. // apply time scale and advance time
  7746. deltaTime *= this._updateTimeScale( time );
  7747. var clipTime = this._updateTime( deltaTime );
  7748. // note: _updateTime may disable the action resulting in
  7749. // an effective weight of 0
  7750. var weight = this._updateWeight( time );
  7751. if ( weight > 0 ) {
  7752. var interpolants = this._interpolants;
  7753. var propertyMixers = this._propertyBindings;
  7754. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7755. interpolants[ j ].evaluate( clipTime );
  7756. propertyMixers[ j ].accumulate( accuIndex, weight );
  7757. }
  7758. }
  7759. },
  7760. _updateWeight: function( time ) {
  7761. var weight = 0;
  7762. if ( this.enabled ) {
  7763. weight = this.weight;
  7764. var interpolant = this._weightInterpolant;
  7765. if ( interpolant !== null ) {
  7766. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7767. weight *= interpolantValue;
  7768. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7769. this.stopFading();
  7770. if ( interpolantValue === 0 ) {
  7771. // faded out, disable
  7772. this.enabled = false;
  7773. }
  7774. }
  7775. }
  7776. }
  7777. this._effectiveWeight = weight;
  7778. return weight;
  7779. },
  7780. _updateTimeScale: function( time ) {
  7781. var timeScale = 0;
  7782. if ( ! this.paused ) {
  7783. timeScale = this.timeScale;
  7784. var interpolant = this._timeScaleInterpolant;
  7785. if ( interpolant !== null ) {
  7786. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7787. timeScale *= interpolantValue;
  7788. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7789. this.stopWarping();
  7790. if ( timeScale === 0 ) {
  7791. // motion has halted, pause
  7792. this.pause = true;
  7793. } else {
  7794. // warp done - apply final time scale
  7795. this.timeScale = timeScale;
  7796. }
  7797. }
  7798. }
  7799. }
  7800. this._effectiveTimeScale = timeScale;
  7801. return timeScale;
  7802. },
  7803. _updateTime: function( deltaTime ) {
  7804. var time = this.time + deltaTime;
  7805. if ( deltaTime === 0 ) return time;
  7806. var duration = this._clip.duration,
  7807. loop = this.loop,
  7808. loopCount = this._loopCount,
  7809. pingPong = false;
  7810. switch ( loop ) {
  7811. case THREE.LoopOnce:
  7812. case THREE.LoopOnceClamp:
  7813. if ( loopCount === -1 ) {
  7814. // just started
  7815. this.loopCount = 0;
  7816. this._setEndings( true, true, false );
  7817. }
  7818. if ( time >= duration ) {
  7819. time = duration;
  7820. } else if ( time < 0 ) {
  7821. time = 0;
  7822. } else break;
  7823. // reached the end
  7824. if ( this.clampWhenFinished ) this.pause = true;
  7825. else this.enabled = false;
  7826. this._mixer.dispatchEvent( {
  7827. type: 'finished', action: this,
  7828. direction: deltaTime < 0 ? -1 : 1
  7829. } );
  7830. break;
  7831. case THREE.LoopPingPong:
  7832. pingPong = true;
  7833. case THREE.LoopRepeat:
  7834. if ( loopCount === -1 ) {
  7835. // just started
  7836. if ( deltaTime > 0 ) {
  7837. loopCount = 0;
  7838. this._setEndings(
  7839. true, this.repetitions === 0, pingPong );
  7840. } else {
  7841. // when looping in reverse direction, the initial
  7842. // transition through zero counts as a repetition,
  7843. // so leave loopCount at -1
  7844. this._setEndings(
  7845. this.repetitions === 0, true, pingPong );
  7846. }
  7847. }
  7848. if ( time >= duration || time < 0 ) {
  7849. // wrap around
  7850. var loopDelta = Math.floor( time / duration ); // signed
  7851. time -= duration * loopDelta;
  7852. loopCount += Math.abs( loopDelta );
  7853. var pending = this.repetitions - loopCount;
  7854. if ( pending < 0 ) {
  7855. // stop (switch state, clamp time, fire event)
  7856. if ( this.clampWhenFinished ) this.paused = true;
  7857. else this.enabled = false;
  7858. time = deltaTime > 0 ? duration : 0;
  7859. this._mixer.dispatchEvent( {
  7860. type: 'finished', action: this,
  7861. direction: deltaTime > 0 ? 1 : -1
  7862. } );
  7863. break;
  7864. } else if ( pending === 0 ) {
  7865. // transition to last round
  7866. var atStart = deltaTime < 0;
  7867. this._setEndings( atStart, ! atStart, pingPong );
  7868. } else {
  7869. this._setEndings( false, false, pingPong );
  7870. }
  7871. this._loopCount = loopCount;
  7872. this._mixer.dispatchEvent( {
  7873. type: 'loop', action: this, loopDelta: loopDelta
  7874. } );
  7875. }
  7876. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7877. // invert time for the "pong round"
  7878. this.time = time;
  7879. return duration - time;
  7880. }
  7881. break;
  7882. }
  7883. this.time = time;
  7884. return time;
  7885. },
  7886. _setEndings: function( atStart, atEnd, pingPong ) {
  7887. var settings = this._interpolantSettings;
  7888. if ( pingPong ) {
  7889. settings.endingStart = THREE.ZeroSlopeEnding;
  7890. settings.endingEnd = THREE.ZeroSlopeEnding;
  7891. } else {
  7892. // assuming for LoopOnce atStart == atEnd == true
  7893. if ( atStart ) {
  7894. settings.endingStart = this.zeroSlopeAtStart ?
  7895. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7896. } else {
  7897. settings.endingStart = THREE.WrapAroundEnding;
  7898. }
  7899. if ( atEnd ) {
  7900. settings.endingEnd = this.zeroSlopeAtEnd ?
  7901. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7902. } else {
  7903. settings.endingEnd = THREE.WrapAroundEnding;
  7904. }
  7905. }
  7906. },
  7907. _scheduleFading: function( duration, weightNow, weightThen ) {
  7908. var mixer = this._mixer, now = mixer.time,
  7909. interpolant = this._weightInterpolant;
  7910. if ( interpolant === null ) {
  7911. interpolant = mixer._lendControlInterpolant(),
  7912. this._weightInterpolant = interpolant;
  7913. }
  7914. var times = interpolant.parameterPositions,
  7915. values = interpolant.sampleValues;
  7916. times[ 0 ] = now; values[ 0 ] = weightNow;
  7917. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7918. return this;
  7919. }
  7920. };
  7921. // Implementation details:
  7922. Object.assign( THREE.AnimationMixer.prototype, {
  7923. _bindAction: function( action, prototypeAction ) {
  7924. var root = action._localRoot || this._root,
  7925. tracks = action._clip.tracks,
  7926. nTracks = tracks.length,
  7927. bindings = action._propertyBindings,
  7928. interpolants = action._interpolants,
  7929. rootUuid = root.uuid,
  7930. bindingsByRoot = this._bindingsByRootAndName,
  7931. bindingsByName = bindingsByRoot[ rootUuid ];
  7932. if ( bindingsByName === undefined ) {
  7933. bindingsByName = {};
  7934. bindingsByRoot[ rootUuid ] = bindingsByName;
  7935. }
  7936. for ( var i = 0; i !== nTracks; ++ i ) {
  7937. var track = tracks[ i ],
  7938. trackName = track.name,
  7939. binding = bindingsByName[ trackName ];
  7940. if ( binding !== undefined ) {
  7941. bindings[ i ] = binding;
  7942. } else {
  7943. binding = bindings[ i ];
  7944. if ( binding !== undefined ) {
  7945. // existing binding, make sure the cache knows
  7946. if ( binding._cacheIndex === null ) {
  7947. ++ binding.referenceCount;
  7948. this._addInactiveBinding( binding, rootUuid, trackName );
  7949. }
  7950. continue;
  7951. }
  7952. var path = prototypeAction && prototypeAction.
  7953. _propertyBindings[ i ].binding.parsedPath;
  7954. binding = new THREE.PropertyMixer(
  7955. THREE.PropertyBinding.create( root, trackName, path ),
  7956. track.ValueTypeName, track.getValueSize() );
  7957. ++ binding.referenceCount;
  7958. this._addInactiveBinding( binding, rootUuid, trackName );
  7959. bindings[ i ] = binding;
  7960. }
  7961. interpolants[ i ].resultBuffer = binding.buffer;
  7962. }
  7963. },
  7964. _activateAction: function( action ) {
  7965. if ( ! this._isActiveAction( action ) ) {
  7966. if ( action._cacheIndex === null ) {
  7967. // this action has been forgotten by the cache, but the user
  7968. // appears to be still using it -> rebind
  7969. var rootUuid = ( action._localRoot || this._root ).uuid,
  7970. clipName = action._clip.name,
  7971. actionsForClip = this._actionsByClip[ clipName ];
  7972. this._bindAction( action,
  7973. actionsForClip && actionsForClip.knownActions[ 0 ] );
  7974. this._addInactiveAction( action, clipName, rootUuid );
  7975. }
  7976. var bindings = action._propertyBindings;
  7977. // increment reference counts / sort out state
  7978. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7979. var binding = bindings[ i ];
  7980. if ( binding.useCount ++ === 0 ) {
  7981. this._lendBinding( binding );
  7982. binding.saveOriginalState();
  7983. }
  7984. }
  7985. this._lendAction( action );
  7986. }
  7987. },
  7988. _deactivateAction: function( action ) {
  7989. if ( this._isActiveAction( action ) ) {
  7990. var bindings = action._propertyBindings;
  7991. // decrement reference counts / sort out state
  7992. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7993. var binding = bindings[ i ];
  7994. if ( -- binding.useCount === 0 ) {
  7995. binding.restoreOriginalState();
  7996. this._takeBackBinding( binding );
  7997. }
  7998. }
  7999. this._takeBackAction( action );
  8000. }
  8001. },
  8002. // Memory manager
  8003. _initMemoryManager: function() {
  8004. this._actions = []; // 'nActiveActions' followed by inactive ones
  8005. this._nActiveActions = 0;
  8006. this._actionsByClip = {};
  8007. // inside:
  8008. // {
  8009. // knownActions: Array< _Action > - used as prototypes
  8010. // actionByRoot: _Action - lookup
  8011. // }
  8012. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8013. this._nActiveBindings = 0;
  8014. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8015. this._controlInterpolants = []; // same game as above
  8016. this._nActiveControlInterpolants = 0;
  8017. var scope = this;
  8018. this.stats = {
  8019. actions: {
  8020. get total() { return scope._actions.length; },
  8021. get inUse() { return scope._nActiveActions; }
  8022. },
  8023. bindings: {
  8024. get total() { return scope._bindings.length; },
  8025. get inUse() { return scope._nActiveBindings; }
  8026. },
  8027. controlInterpolants: {
  8028. get total() { return scope._controlInterpolants.length; },
  8029. get inUse() { return scope._nActiveControlInterpolants; }
  8030. }
  8031. };
  8032. },
  8033. // Memory management for _Action objects
  8034. _isActiveAction: function( action ) {
  8035. var index = action._cacheIndex;
  8036. return index !== null && index < this._nActiveActions;
  8037. },
  8038. _addInactiveAction: function( action, clipName, rootUuid ) {
  8039. var actions = this._actions,
  8040. actionsByClip = this._actionsByClip,
  8041. actionsForClip = actionsByClip[ clipName ];
  8042. if ( actionsForClip === undefined ) {
  8043. actionsForClip = {
  8044. knownActions: [ action ],
  8045. actionByRoot: {}
  8046. };
  8047. action._byClipCacheIndex = 0;
  8048. actionsByClip[ clipName ] = actionsForClip;
  8049. } else {
  8050. var knownActions = actionsForClip.knownActions;
  8051. action._byClipCacheIndex = knownActions.length;
  8052. knownActions.push( action );
  8053. }
  8054. action._cacheIndex = actions.length;
  8055. actions.push( action );
  8056. actionsForClip.actionByRoot[ rootUuid ] = action;
  8057. },
  8058. _removeInactiveAction: function( action ) {
  8059. var actions = this._actions,
  8060. lastInactiveAction = actions[ actions.length - 1 ],
  8061. cacheIndex = action._cacheIndex;
  8062. lastInactiveAction._cacheIndex = cacheIndex;
  8063. actions[ cacheIndex ] = lastInactiveAction;
  8064. actions.pop();
  8065. action._cacheIndex = null;
  8066. var clipName = action._clip.name,
  8067. actionsByClip = this._actionsByClip,
  8068. actionsForClip = actionsByClip[ clipName ],
  8069. knownActionsForClip = actionsForClip.knownActions,
  8070. lastKnownAction =
  8071. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8072. byClipCacheIndex = action._byClipCacheIndex;
  8073. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8074. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8075. knownActionsForClip.pop();
  8076. action._byClipCacheIndex = null;
  8077. var actionByRoot = actionsForClip.actionByRoot,
  8078. rootUuid = ( actions._localRoot || this._root ).uuid;
  8079. delete actionByRoot[ rootUuid ];
  8080. if ( knownActionsForClip.length === 0 ) {
  8081. delete actionsByClip[ clipName ];
  8082. }
  8083. this._removeInactiveBindingsForAction( action );
  8084. },
  8085. _removeInactiveBindingsForAction: function( action ) {
  8086. var bindings = action._propertyBindings;
  8087. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8088. var binding = bindings[ i ];
  8089. if ( -- binding.referenceCount === 0 ) {
  8090. this._removeInactiveBinding( binding );
  8091. }
  8092. }
  8093. },
  8094. _lendAction: function( action ) {
  8095. // [ active actions | inactive actions ]
  8096. // [ active actions >| inactive actions ]
  8097. // s a
  8098. // <-swap->
  8099. // a s
  8100. var actions = this._actions,
  8101. prevIndex = action._cacheIndex,
  8102. lastActiveIndex = this._nActiveActions ++,
  8103. firstInactiveAction = actions[ lastActiveIndex ];
  8104. action._cacheIndex = lastActiveIndex;
  8105. actions[ lastActiveIndex ] = action;
  8106. firstInactiveAction._cacheIndex = prevIndex;
  8107. actions[ prevIndex ] = firstInactiveAction;
  8108. },
  8109. _takeBackAction: function( action ) {
  8110. // [ active actions | inactive actions ]
  8111. // [ active actions |< inactive actions ]
  8112. // a s
  8113. // <-swap->
  8114. // s a
  8115. var actions = this._actions,
  8116. prevIndex = action._cacheIndex,
  8117. firstInactiveIndex = -- this._nActiveActions,
  8118. lastActiveAction = actions[ firstInactiveIndex ];
  8119. action._cacheIndex = firstInactiveIndex;
  8120. actions[ firstInactiveIndex ] = action;
  8121. lastActiveAction._cacheIndex = prevIndex;
  8122. actions[ prevIndex ] = lastActiveAction;
  8123. },
  8124. // Memory management for PropertyMixer objects
  8125. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8126. var bindingsByRoot = this._bindingsByRootAndName,
  8127. bindingByName = bindingsByRoot[ rootUuid ],
  8128. bindings = this._bindings;
  8129. if ( bindingByName === undefined ) {
  8130. bindingByName = {};
  8131. bindingsByRoot[ rootUuid ] = bindingByName;
  8132. }
  8133. bindingByName[ trackName ] = binding;
  8134. binding._cacheIndex = bindings.length;
  8135. bindings.push( binding );
  8136. },
  8137. _removeInactiveBinding: function( binding ) {
  8138. var bindings = this._bindings,
  8139. propBinding = binding.binding,
  8140. rootUuid = propBinding.rootNode.uuid,
  8141. trackName = propBinding.path,
  8142. bindingsByRoot = this._bindingsByRootAndName,
  8143. bindingByName = bindingsByRoot[ rootUuid ],
  8144. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8145. cacheIndex = binding._cacheIndex;
  8146. lastInactiveBinding._cacheIndex = cacheIndex;
  8147. bindings[ cacheIndex ] = lastInactiveBinding;
  8148. bindings.pop();
  8149. delete bindingByName[ trackName ];
  8150. remove_empty_map: {
  8151. for ( var _ in bindingByName ) break remove_empty_map;
  8152. delete bindingsByRoot[ rootUuid ];
  8153. }
  8154. },
  8155. _lendBinding: function( binding ) {
  8156. var bindings = this._bindings,
  8157. prevIndex = binding._cacheIndex,
  8158. lastActiveIndex = this._nActiveBindings ++,
  8159. firstInactiveBinding = bindings[ lastActiveIndex ];
  8160. binding._cacheIndex = lastActiveIndex;
  8161. bindings[ lastActiveIndex ] = binding;
  8162. firstInactiveBinding._cacheIndex = prevIndex;
  8163. bindings[ prevIndex ] = firstInactiveBinding;
  8164. },
  8165. _takeBackBinding: function( binding ) {
  8166. var bindings = this._bindings,
  8167. prevIndex = binding._cacheIndex,
  8168. firstInactiveIndex = -- this._nActiveBindings,
  8169. lastActiveBinding = bindings[ firstInactiveIndex ];
  8170. binding._cacheIndex = firstInactiveIndex;
  8171. bindings[ firstInactiveIndex ] = binding;
  8172. lastActiveBinding._cacheIndex = prevIndex;
  8173. bindings[ prevIndex ] = lastActiveBinding;
  8174. },
  8175. // Memory management of Interpolants for weight and time scale
  8176. _lendControlInterpolant: function() {
  8177. var interpolants = this._controlInterpolants,
  8178. lastActiveIndex = this._nActiveControlInterpolants ++,
  8179. interpolant = interpolants[ lastActiveIndex ];
  8180. if ( interpolant === undefined ) {
  8181. interpolant = new THREE.LinearInterpolant(
  8182. new Float32Array( 2 ), new Float32Array( 2 ),
  8183. 1, this._controlInterpolantsResultBuffer );
  8184. interpolant.__cacheIndex = lastActiveIndex;
  8185. interpolants[ lastActiveIndex ] = interpolant;
  8186. }
  8187. return interpolant;
  8188. },
  8189. _takeBackControlInterpolant: function( interpolant ) {
  8190. var interpolants = this._controlInterpolants,
  8191. prevIndex = interpolant.__cacheIndex,
  8192. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8193. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8194. interpolant.__cacheIndex = firstInactiveIndex;
  8195. interpolants[ firstInactiveIndex ] = interpolant;
  8196. lastActiveInterpolant.__cacheIndex = prevIndex;
  8197. interpolants[ prevIndex ] = lastActiveInterpolant;
  8198. },
  8199. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8200. } );
  8201. // File:src/animation/AnimationObjectGroup.js
  8202. /**
  8203. *
  8204. * A group of objects that receives a shared animation state.
  8205. *
  8206. * Usage:
  8207. *
  8208. * - Add objects you would otherwise pass as 'root' to the
  8209. * constructor or the .clipAction method of AnimationMixer.
  8210. *
  8211. * - Instead pass this object as 'root'.
  8212. *
  8213. * - You can also add and remove objects later when the mixer
  8214. * is running.
  8215. *
  8216. * Note:
  8217. *
  8218. * Objects of this class appear as one object to the mixer,
  8219. * so cache control of the individual objects must be done
  8220. * on the group.
  8221. *
  8222. * Limitation:
  8223. *
  8224. * - The animated properties must be compatible among the
  8225. * all objects in the group.
  8226. *
  8227. * - A single property can either be controlled through a
  8228. * target group or directly, but not both.
  8229. *
  8230. * @author tschw
  8231. */
  8232. THREE.AnimationObjectGroup = function( var_args ) {
  8233. this.uuid = THREE.Math.generateUUID();
  8234. // cached objects followed by the active ones
  8235. this._objects = Array.prototype.slice.call( arguments );
  8236. this.nCachedObjects_ = 0; // threshold
  8237. // note: read by PropertyBinding.Composite
  8238. var indices = {};
  8239. this._indicesByUUID = indices; // for bookkeeping
  8240. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8241. indices[ arguments[ i ].uuid ] = i;
  8242. }
  8243. this._paths = []; // inside: string
  8244. this._parsedPaths = []; // inside: { we don't care, here }
  8245. this._bindings = []; // inside: Array< PropertyBinding >
  8246. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8247. var scope = this;
  8248. this.stats = {
  8249. objects: {
  8250. get total() { return scope._objects.length; },
  8251. get inUse() { return this.total - scope.nCachedObjects_; }
  8252. },
  8253. get bindingsPerObject() { return scope._bindings.length; }
  8254. };
  8255. };
  8256. THREE.AnimationObjectGroup.prototype = {
  8257. constructor: THREE.AnimationObjectGroup,
  8258. add: function( var_args ) {
  8259. var objects = this._objects,
  8260. nObjects = objects.length,
  8261. nCachedObjects = this.nCachedObjects_,
  8262. indicesByUUID = this._indicesByUUID,
  8263. paths = this._paths,
  8264. parsedPaths = this._parsedPaths,
  8265. bindings = this._bindings,
  8266. nBindings = bindings.length;
  8267. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8268. var object = arguments[ i ],
  8269. uuid = object.uuid,
  8270. index = indicesByUUID[ uuid ];
  8271. if ( index === undefined ) {
  8272. // unknown object -> add it to the ACTIVE region
  8273. index = nObjects ++;
  8274. indicesByUUID[ uuid ] = index;
  8275. objects.push( object );
  8276. // accounting is done, now do the same for all bindings
  8277. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8278. bindings[ j ].push(
  8279. new THREE.PropertyBinding(
  8280. object, paths[ j ], parsedPaths[ j ] ) );
  8281. }
  8282. } else if ( index < nCachedObjects ) {
  8283. var knownObject = objects[ index ];
  8284. // move existing object to the ACTIVE region
  8285. var firstActiveIndex = -- nCachedObjects,
  8286. lastCachedObject = objects[ firstActiveIndex ];
  8287. indicesByUUID[ lastCachedObject.uuid ] = index;
  8288. objects[ index ] = lastCachedObject;
  8289. indicesByUUID[ uuid ] = firstActiveIndex;
  8290. objects[ firstActiveIndex ] = object;
  8291. // accounting is done, now do the same for all bindings
  8292. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8293. var bindingsForPath = bindings[ j ],
  8294. lastCached = bindingsForPath[ firstActiveIndex ],
  8295. binding = bindingsForPath[ index ];
  8296. bindingsForPath[ index ] = lastCached;
  8297. if ( binding === undefined ) {
  8298. // since we do not bother to create new bindings
  8299. // for objects that are cached, the binding may
  8300. // or may not exist
  8301. binding = new THREE.PropertyBinding(
  8302. object, paths[ j ], parsedPaths[ j ] );
  8303. }
  8304. bindingsForPath[ firstActiveIndex ] = binding;
  8305. }
  8306. } else if ( objects[ index ] !== knownObject) {
  8307. console.error( "Different objects with the same UUID " +
  8308. "detected. Clean the caches or recreate your " +
  8309. "infrastructure when reloading scenes..." );
  8310. } // else the object is already where we want it to be
  8311. } // for arguments
  8312. this.nCachedObjects_ = nCachedObjects;
  8313. },
  8314. remove: function( var_args ) {
  8315. var objects = this._objects,
  8316. nObjects = objects.length,
  8317. nCachedObjects = this.nCachedObjects_,
  8318. indicesByUUID = this._indicesByUUID,
  8319. bindings = this._bindings,
  8320. nBindings = bindings.length;
  8321. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8322. var object = arguments[ i ],
  8323. uuid = object.uuid,
  8324. index = indicesByUUID[ uuid ];
  8325. if ( index !== undefined && index >= nCachedObjects ) {
  8326. // move existing object into the CACHED region
  8327. var lastCachedIndex = nCachedObjects ++,
  8328. firstActiveObject = objects[ lastCachedIndex ];
  8329. indicesByUUID[ firstActiveObject.uuid ] = index;
  8330. objects[ index ] = firstActiveObject;
  8331. indicesByUUID[ uuid ] = lastCachedIndex;
  8332. objects[ lastCachedIndex ] = object;
  8333. // accounting is done, now do the same for all bindings
  8334. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8335. var bindingsForPath = bindings[ j ],
  8336. firstActive = bindingsForPath[ lastCachedIndex ],
  8337. binding = bindingsForPath[ index ];
  8338. bindingsForPath[ index ] = firstActive;
  8339. bindingsForPath[ lastCachedIndex ] = binding;
  8340. }
  8341. }
  8342. } // for arguments
  8343. this.nCachedObjects_ = nCachedObjects;
  8344. },
  8345. // remove & forget
  8346. uncache: function( var_args ) {
  8347. var objects = this._objects,
  8348. nObjects = objects.length,
  8349. nCachedObjects = this.nCachedObjects_,
  8350. indicesByUUID = this._indicesByUUID,
  8351. bindings = this._bindings,
  8352. nBindings = bindings.length;
  8353. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8354. var object = arguments[ i ],
  8355. uuid = object.uuid,
  8356. index = indicesByUUID[ uuid ];
  8357. if ( index !== undefined ) {
  8358. delete indicesByUUID[ uuid ];
  8359. if ( index < nCachedObjects ) {
  8360. // object is cached, shrink the CACHED region
  8361. var firstActiveIndex = -- nCachedObjects,
  8362. lastCachedObject = objects[ firstActiveIndex ],
  8363. lastIndex = -- nObjects,
  8364. lastObject = objects[ lastIndex ];
  8365. // last cached object takes this object's place
  8366. indicesByUUID[ lastCachedObject.uuid ] = index;
  8367. objects[ index ] = lastCachedObject;
  8368. // last object goes to the activated slot and pop
  8369. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8370. objects[ firstActiveIndex ] = lastObject;
  8371. objects.pop();
  8372. // accounting is done, now do the same for all bindings
  8373. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8374. var bindingsForPath = bindings[ j ],
  8375. lastCached = bindingsForPath[ firstActiveIndex ],
  8376. last = bindingsForPath[ lastIndex ];
  8377. bindingsForPath[ index ] = lastCached;
  8378. bindingsForPath[ firstActiveIndex ] = last;
  8379. bindingsForPath.pop();
  8380. }
  8381. } else {
  8382. // object is active, just swap with the last and pop
  8383. var lastIndex = -- nObjects,
  8384. lastObject = objects[ lastIndex ];
  8385. indicesByUUID[ lastObject.uuid ] = index;
  8386. objects[ index ] = lastObject;
  8387. objects.pop();
  8388. // accounting is done, now do the same for all bindings
  8389. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8390. var bindingsForPath = bindings[ j ];
  8391. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8392. bindingsForPath.pop();
  8393. }
  8394. } // cached or active
  8395. } // if object is known
  8396. } // for arguments
  8397. this.nCachedObjects_ = nCachedObjects;
  8398. },
  8399. // Internal interface used by befriended PropertyBinding.Composite:
  8400. subscribe_: function( path, parsedPath ) {
  8401. // returns an array of bindings for the given path that is changed
  8402. // according to the contained objects in the group
  8403. var indicesByPath = this._bindingsIndicesByPath,
  8404. index = indicesByPath[ path ],
  8405. bindings = this._bindings;
  8406. if ( index !== undefined ) return bindings[ index ];
  8407. var paths = this._paths,
  8408. parsedPaths = this._parsedPaths,
  8409. objects = this._objects,
  8410. nObjects = objects.length,
  8411. nCachedObjects = this.nCachedObjects_,
  8412. bindingsForPath = new Array( nObjects );
  8413. index = bindings.length;
  8414. indicesByPath[ path ] = index;
  8415. paths.push( path );
  8416. parsedPaths.push( parsedPath );
  8417. bindings.push( bindingsForPath );
  8418. for ( var i = nCachedObjects,
  8419. n = objects.length; i !== n; ++ i ) {
  8420. var object = objects[ i ];
  8421. bindingsForPath[ i ] =
  8422. new THREE.PropertyBinding( object, path, parsedPath );
  8423. }
  8424. return bindingsForPath;
  8425. },
  8426. unsubscribe_: function( path ) {
  8427. // tells the group to forget about a property path and no longer
  8428. // update the array previously obtained with 'subscribe_'
  8429. var indicesByPath = this._bindingsIndicesByPath,
  8430. index = indicesByPath[ path ];
  8431. if ( index !== undefined ) {
  8432. var paths = this._paths,
  8433. parsedPaths = this._parsedPaths,
  8434. bindings = this._bindings,
  8435. lastBindingsIndex = bindings.length - 1,
  8436. lastBindings = bindings[ lastBindingsIndex ],
  8437. lastBindingsPath = path[ lastBindingsIndex ];
  8438. indicesByPath[ lastBindingsPath ] = index;
  8439. bindings[ index ] = lastBindings;
  8440. bindings.pop();
  8441. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8442. parsedPaths.pop();
  8443. paths[ index ] = paths[ lastBindingsIndex ];
  8444. paths.pop();
  8445. }
  8446. }
  8447. };
  8448. // File:src/animation/AnimationUtils.js
  8449. /**
  8450. * @author tschw
  8451. * @author Ben Houston / http://clara.io/
  8452. * @author David Sarno / http://lighthaus.us/
  8453. */
  8454. THREE.AnimationUtils = {
  8455. // same as Array.prototype.slice, but also works on typed arrays
  8456. arraySlice: function( array, from, to ) {
  8457. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8458. return new array.constructor( array.subarray( from, to ) );
  8459. }
  8460. return array.slice( from, to );
  8461. },
  8462. // converts an array to a specific type
  8463. convertArray: function( array, type, forceClone ) {
  8464. if ( ! array || // let 'undefined' and 'null' pass
  8465. ! forceClone && array.constructor === type ) return array;
  8466. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8467. return new type( array ); // create typed array
  8468. }
  8469. return Array.prototype.slice.call( array ); // create Array
  8470. },
  8471. isTypedArray: function( object ) {
  8472. return ArrayBuffer.isView( object ) &&
  8473. ! ( object instanceof DataView );
  8474. },
  8475. // returns an array by which times and values can be sorted
  8476. getKeyframeOrder: function( times ) {
  8477. function compareTime( i, j ) {
  8478. return times[ i ] - times[ j ];
  8479. }
  8480. var n = times.length;
  8481. var result = new Array( n );
  8482. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8483. result.sort( compareTime );
  8484. return result;
  8485. },
  8486. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8487. sortedArray: function( values, stride, order ) {
  8488. var nValues = values.length;
  8489. var result = new values.constructor( nValues );
  8490. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8491. var srcOffset = order[ i ] * stride;
  8492. for ( var j = 0; j !== stride; ++ j ) {
  8493. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8494. }
  8495. }
  8496. return result;
  8497. },
  8498. // function for parsing AOS keyframe formats
  8499. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8500. var i = 1, key = jsonKeys[ 0 ];
  8501. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8502. key = jsonKeys[ i ++ ];
  8503. }
  8504. if ( key === undefined ) return; // no data
  8505. var value = key[ valuePropertyName ];
  8506. if ( value === undefined ) return; // no data
  8507. if ( Array.isArray( value ) ) {
  8508. do {
  8509. value = key[ valuePropertyName ];
  8510. if ( value !== undefined ) {
  8511. times.push( key.time );
  8512. values.push.apply( values, value ); // push all elements
  8513. }
  8514. key = jsonKeys[ i ++ ];
  8515. } while ( key !== undefined );
  8516. } else if ( value.toArray !== undefined ) {
  8517. // ...assume THREE.Math-ish
  8518. do {
  8519. value = key[ valuePropertyName ];
  8520. if ( value !== undefined ) {
  8521. times.push( key.time );
  8522. value.toArray( values, values.length );
  8523. }
  8524. key = jsonKeys[ i ++ ];
  8525. } while ( key !== undefined );
  8526. } else {
  8527. // otherwise push as-is
  8528. do {
  8529. value = key[ valuePropertyName ];
  8530. if ( value !== undefined ) {
  8531. times.push( key.time );
  8532. values.push( value );
  8533. }
  8534. key = jsonKeys[ i ++ ];
  8535. } while ( key !== undefined );
  8536. }
  8537. }
  8538. };
  8539. // File:src/animation/KeyframeTrack.js
  8540. /**
  8541. *
  8542. * A timed sequence of keyframes for a specific property.
  8543. *
  8544. *
  8545. * @author Ben Houston / http://clara.io/
  8546. * @author David Sarno / http://lighthaus.us/
  8547. * @author tschw
  8548. */
  8549. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8550. if( name === undefined ) throw new Error( "track name is undefined" );
  8551. if( times === undefined || times.length === 0 ) {
  8552. throw new Error( "no keyframes in track named " + name );
  8553. }
  8554. this.name = name;
  8555. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8556. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8557. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8558. this.validate();
  8559. this.optimize();
  8560. };
  8561. THREE.KeyframeTrack.prototype = {
  8562. constructor: THREE.KeyframeTrack,
  8563. TimeBufferType: Float32Array,
  8564. ValueBufferType: Float32Array,
  8565. DefaultInterpolation: THREE.InterpolateLinear,
  8566. InterpolantFactoryMethodDiscrete: function( result ) {
  8567. return new THREE.DiscreteInterpolant(
  8568. this.times, this.values, this.getValueSize(), result );
  8569. },
  8570. InterpolantFactoryMethodLinear: function( result ) {
  8571. return new THREE.LinearInterpolant(
  8572. this.times, this.values, this.getValueSize(), result );
  8573. },
  8574. InterpolantFactoryMethodSmooth: function( result ) {
  8575. return new THREE.CubicInterpolant(
  8576. this.times, this.values, this.getValueSize(), result );
  8577. },
  8578. setInterpolation: function( interpolation ) {
  8579. var factoryMethod = undefined;
  8580. switch ( interpolation ) {
  8581. case THREE.InterpolateDiscrete:
  8582. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8583. break;
  8584. case THREE.InterpolateLinear:
  8585. factoryMethod = this.InterpolantFactoryMethodLinear;
  8586. break;
  8587. case THREE.InterpolateSmooth:
  8588. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8589. break;
  8590. }
  8591. if ( factoryMethod === undefined ) {
  8592. var message = "unsupported interpolation for " +
  8593. this.ValueTypeName + " keyframe track named " + this.name;
  8594. if ( this.createInterpolant === undefined ) {
  8595. // fall back to default, unless the default itself is messed up
  8596. if ( interpolation !== this.DefaultInterpolation ) {
  8597. this.setInterpolation( this.DefaultInterpolation );
  8598. } else {
  8599. throw new Error( message ); // fatal, in this case
  8600. }
  8601. }
  8602. console.warn( message );
  8603. return;
  8604. }
  8605. this.createInterpolant = factoryMethod;
  8606. },
  8607. getInterpolation: function() {
  8608. switch ( this.createInterpolant ) {
  8609. case this.InterpolantFactoryMethodDiscrete:
  8610. return THREE.InterpolateDiscrete;
  8611. case this.InterpolantFactoryMethodLinear:
  8612. return THREE.InterpolateLinear;
  8613. case this.InterpolantFactoryMethodSmooth:
  8614. return THREE.InterpolateSmooth;
  8615. }
  8616. },
  8617. getValueSize: function() {
  8618. return this.values.length / this.times.length;
  8619. },
  8620. // move all keyframes either forwards or backwards in time
  8621. shift: function( timeOffset ) {
  8622. if( timeOffset !== 0.0 ) {
  8623. var times = this.times;
  8624. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8625. times[ i ] += timeOffset;
  8626. }
  8627. }
  8628. return this;
  8629. },
  8630. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8631. scale: function( timeScale ) {
  8632. if( timeScale !== 1.0 ) {
  8633. var times = this.times;
  8634. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8635. times[ i ] *= timeScale;
  8636. }
  8637. }
  8638. return this;
  8639. },
  8640. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8641. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8642. trim: function( startTime, endTime ) {
  8643. var times = this.times;
  8644. var nKeys = times.length;
  8645. var firstKeysToRemove = 0;
  8646. for ( var i = 1; i !== nKeys; ++ i ) {
  8647. if ( times[i] <= startTime ) ++ firstKeysToRemove;
  8648. }
  8649. var lastKeysToRemove = 0;
  8650. for ( var i = nKeys - 2; i !== 0; -- i ) {
  8651. if ( times[i] >= endTime ) ++ lastKeysToRemove;
  8652. else break;
  8653. }
  8654. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  8655. if( ( firstKeysToRemove + lastKeysToRemove ) !== 0 ) {
  8656. var from = firstKeysToRemove;
  8657. var to = nKeys - lastKeysToRemove - firstKeysToRemove;
  8658. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8659. var values = this.values;
  8660. var stride = this.getValueSize();
  8661. this.values = THREE.AnimationUtils.arraySlice( values, from * stride, to * stride );
  8662. }
  8663. return this;
  8664. },
  8665. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8666. validate: function() {
  8667. var valid = true;
  8668. var valueSize = this.getValueSize();
  8669. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8670. console.error( "invalid value size in track", this );
  8671. valid = false;
  8672. }
  8673. var times = this.times,
  8674. values = this.values,
  8675. nKeys = times.length;
  8676. if( nKeys === 0 ) {
  8677. console.error( "track is empty", this );
  8678. valid = false;
  8679. }
  8680. var prevTime = null;
  8681. for( var i = 0; i !== nKeys; i ++ ) {
  8682. var currTime = times[ i ];
  8683. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8684. console.error( "time is not a valid number", this, i, currTime );
  8685. valid = false;
  8686. break;
  8687. }
  8688. if( prevTime !== null && prevTime > currTime ) {
  8689. console.error( "out of order keys", this, i, currTime, prevTime );
  8690. valid = false;
  8691. break;
  8692. }
  8693. prevTime = currTime;
  8694. }
  8695. if ( values !== undefined ) {
  8696. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8697. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8698. var value = values[ i ];
  8699. if ( isNaN( value ) ) {
  8700. console.error( "value is not a valid number", this, i, value );
  8701. valid = false;
  8702. break;
  8703. }
  8704. }
  8705. }
  8706. }
  8707. return valid;
  8708. },
  8709. // removes equivalent sequential keys as common in morph target sequences
  8710. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8711. optimize: function() {
  8712. var times = this.times,
  8713. values = this.values,
  8714. stride = this.getValueSize(),
  8715. writeIndex = 1;
  8716. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8717. var keep = false;
  8718. var time = times[ i ];
  8719. var timeNext = times[ i + 1 ];
  8720. // remove adjacent keyframes scheduled at the same time
  8721. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8722. // remove unnecessary keyframes same as their neighbors
  8723. var offset = i * stride,
  8724. offsetP = offset - stride,
  8725. offsetN = offset + stride;
  8726. for ( var j = 0; j !== stride; ++ j ) {
  8727. var value = values[ offset + j ];
  8728. if ( value !== values[ offsetP + j ] ||
  8729. value !== values[ offsetN + j ] ) {
  8730. keep = true;
  8731. break;
  8732. }
  8733. }
  8734. }
  8735. // in-place compaction
  8736. if ( keep ) {
  8737. if ( i !== writeIndex ) {
  8738. times[ writeIndex ] = times[ i ];
  8739. var readOffset = i * stride,
  8740. writeOffset = writeIndex * stride;
  8741. for ( var j = 0; j !== stride; ++ j ) {
  8742. values[ writeOffset + j ] = values[ readOffset + j ];
  8743. }
  8744. }
  8745. ++ writeIndex;
  8746. }
  8747. }
  8748. if ( writeIndex !== times.length ) {
  8749. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8750. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8751. }
  8752. return this;
  8753. }
  8754. };
  8755. // Static methods:
  8756. Object.assign( THREE.KeyframeTrack, {
  8757. // Serialization (in static context, because of constructor invocation
  8758. // and automatic invocation of .toJSON):
  8759. parse: function( json ) {
  8760. if( json.type === undefined ) {
  8761. throw new Error( "track type undefined, can not parse" );
  8762. }
  8763. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8764. if ( json.times === undefined ) {
  8765. console.warn( "legacy JSON format detected, converting" );
  8766. var times = [], values = [];
  8767. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8768. json.times = times;
  8769. json.values = values;
  8770. }
  8771. // derived classes can define a static parse method
  8772. if ( trackType.parse !== undefined ) {
  8773. return trackType.parse( json );
  8774. } else {
  8775. // by default, we asssume a constructor compatible with the base
  8776. return new trackType(
  8777. json.name, json.times, json.values, json.interpolation );
  8778. }
  8779. },
  8780. toJSON: function( track ) {
  8781. var trackType = track.constructor;
  8782. var json;
  8783. // derived classes can define a static toJSON method
  8784. if ( trackType.toJSON !== undefined ) {
  8785. json = trackType.toJSON( track );
  8786. } else {
  8787. // by default, we assume the data can be serialized as-is
  8788. json = {
  8789. 'name': track.name,
  8790. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8791. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8792. };
  8793. var interpolation = track.getInterpolation();
  8794. if ( interpolation !== track.DefaultInterpolation ) {
  8795. json.interpolation = interpolation;
  8796. }
  8797. }
  8798. json.type = track.ValueTypeName; // mandatory
  8799. return json;
  8800. },
  8801. _getTrackTypeForValueTypeName: function( typeName ) {
  8802. switch( typeName.toLowerCase() ) {
  8803. case "scalar":
  8804. case "double":
  8805. case "float":
  8806. case "number":
  8807. case "integer":
  8808. return THREE.NumberKeyframeTrack;
  8809. case "vector":
  8810. case "vector2":
  8811. case "vector3":
  8812. case "vector4":
  8813. return THREE.VectorKeyframeTrack;
  8814. case "color":
  8815. return THREE.ColorKeyframeTrack;
  8816. case "quaternion":
  8817. return THREE.QuaternionKeyframeTrack;
  8818. case "bool":
  8819. case "boolean":
  8820. return THREE.BooleanKeyframeTrack;
  8821. case "string":
  8822. return THREE.StringKeyframeTrack;
  8823. };
  8824. throw new Error( "Unsupported typeName: " + typeName );
  8825. }
  8826. } );
  8827. // File:src/animation/PropertyBinding.js
  8828. /**
  8829. *
  8830. * A reference to a real property in the scene graph.
  8831. *
  8832. *
  8833. * @author Ben Houston / http://clara.io/
  8834. * @author David Sarno / http://lighthaus.us/
  8835. * @author tschw
  8836. */
  8837. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8838. this.path = path;
  8839. this.parsedPath = parsedPath ||
  8840. THREE.PropertyBinding.parseTrackName( path );
  8841. this.node = THREE.PropertyBinding.findNode(
  8842. rootNode, this.parsedPath.nodeName ) || rootNode;
  8843. this.rootNode = rootNode;
  8844. };
  8845. THREE.PropertyBinding.prototype = {
  8846. constructor: THREE.PropertyBinding,
  8847. getValue: function getValue_unbound( targetArray, offset ) {
  8848. this.bind();
  8849. this.getValue( targetArray, offset );
  8850. // Note: This class uses a State pattern on a per-method basis:
  8851. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8852. // prototype version of these methods with one that represents
  8853. // the bound state. When the property is not found, the methods
  8854. // become no-ops.
  8855. },
  8856. setValue: function getValue_unbound( sourceArray, offset ) {
  8857. this.bind();
  8858. this.setValue( sourceArray, offset );
  8859. },
  8860. // create getter / setter pair for a property in the scene graph
  8861. bind: function() {
  8862. var targetObject = this.node,
  8863. parsedPath = this.parsedPath,
  8864. objectName = parsedPath.objectName,
  8865. propertyName = parsedPath.propertyName,
  8866. propertyIndex = parsedPath.propertyIndex;
  8867. if ( ! targetObject ) {
  8868. targetObject = THREE.PropertyBinding.findNode(
  8869. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8870. this.node = targetObject;
  8871. }
  8872. // set fail state so we can just 'return' on error
  8873. this.getValue = this._getValue_unavailable;
  8874. this.setValue = this._setValue_unavailable;
  8875. // ensure there is a value node
  8876. if ( ! targetObject ) {
  8877. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8878. return;
  8879. }
  8880. if( objectName ) {
  8881. var objectIndex = parsedPath.objectIndex;
  8882. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8883. switch ( objectName ) {
  8884. case 'materials':
  8885. if( ! targetObject.material ) {
  8886. console.error( ' can not bind to material as node does not have a material', this );
  8887. return;
  8888. }
  8889. if( ! targetObject.material.materials ) {
  8890. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8891. return;
  8892. }
  8893. targetObject = targetObject.material.materials;
  8894. break;
  8895. case 'bones':
  8896. if( ! targetObject.skeleton ) {
  8897. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8898. return;
  8899. }
  8900. // potential future optimization: skip this if propertyIndex is already an integer
  8901. // and convert the integer string to a true integer.
  8902. targetObject = targetObject.skeleton.bones;
  8903. // support resolving morphTarget names into indices.
  8904. for ( var i = 0; i < targetObject.length; i ++ ) {
  8905. if ( targetObject[i].name === objectIndex ) {
  8906. objectIndex = i;
  8907. break;
  8908. }
  8909. }
  8910. break;
  8911. default:
  8912. if ( targetObject[ objectName ] === undefined ) {
  8913. console.error( ' can not bind to objectName of node, undefined', this );
  8914. return;
  8915. }
  8916. targetObject = targetObject[ objectName ];
  8917. }
  8918. if ( objectIndex !== undefined ) {
  8919. if( targetObject[ objectIndex ] === undefined ) {
  8920. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8921. return;
  8922. }
  8923. targetObject = targetObject[ objectIndex ];
  8924. }
  8925. }
  8926. // resolve property
  8927. var nodeProperty = targetObject[ propertyName ];
  8928. if ( ! nodeProperty ) {
  8929. var nodeName = parsedPath.nodeName;
  8930. console.error( " trying to update property for track: " + nodeName +
  8931. '.' + propertyName + " but it wasn't found.", targetObject );
  8932. return;
  8933. }
  8934. // determine versioning scheme
  8935. var versioning = this.Versioning.None;
  8936. if ( targetObject.needsUpdate !== undefined ) { // material
  8937. versioning = this.Versioning.NeedsUpdate;
  8938. this.targetObject = targetObject;
  8939. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8940. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  8941. this.targetObject = targetObject;
  8942. }
  8943. // determine how the property gets bound
  8944. var bindingType = this.BindingType.Direct;
  8945. if ( propertyIndex !== undefined ) {
  8946. // access a sub element of the property array (only primitives are supported right now)
  8947. if ( propertyName === "morphTargetInfluences" ) {
  8948. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  8949. // support resolving morphTarget names into indices.
  8950. if ( ! targetObject.geometry ) {
  8951. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  8952. return;
  8953. }
  8954. if ( ! targetObject.geometry.morphTargets ) {
  8955. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  8956. return;
  8957. }
  8958. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  8959. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  8960. propertyIndex = i;
  8961. break;
  8962. }
  8963. }
  8964. }
  8965. bindingType = this.BindingType.ArrayElement;
  8966. this.resolvedProperty = nodeProperty;
  8967. this.propertyIndex = propertyIndex;
  8968. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  8969. // must use copy for Object3D.Euler/Quaternion
  8970. bindingType = this.BindingType.HasFromToArray;
  8971. this.resolvedProperty = nodeProperty;
  8972. } else if ( nodeProperty.length !== undefined ) {
  8973. bindingType = this.BindingType.EntireArray;
  8974. this.resolvedProperty = nodeProperty;
  8975. } else {
  8976. this.propertyName = propertyName;
  8977. }
  8978. // select getter / setter
  8979. this.getValue = this.GetterByBindingType[ bindingType ];
  8980. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  8981. },
  8982. unbind: function() {
  8983. this.node = null;
  8984. // back to the prototype version of getValue / setValue
  8985. // note: avoiding to mutate the shape of 'this' via 'delete'
  8986. this.getValue = this._getValue_unbound;
  8987. this.setValue = this._setValue_unbound;
  8988. }
  8989. };
  8990. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  8991. // these are used to "bind" a nonexistent property
  8992. _getValue_unavailable: function() {},
  8993. _setValue_unavailable: function() {},
  8994. // initial state of these methods that calls 'bind'
  8995. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  8996. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  8997. BindingType: {
  8998. Direct: 0,
  8999. EntireArray: 1,
  9000. ArrayElement: 2,
  9001. HasFromToArray: 3
  9002. },
  9003. Versioning: {
  9004. None: 0,
  9005. NeedsUpdate: 1,
  9006. MatrixWorldNeedsUpdate: 2
  9007. },
  9008. GetterByBindingType: [
  9009. function getValue_direct( buffer, offset ) {
  9010. buffer[ offset ] = this.node[ this.propertyName ];
  9011. },
  9012. function getValue_array( buffer, offset ) {
  9013. var source = this.resolvedProperty;
  9014. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9015. buffer[ offset ++ ] = source[ i ];
  9016. }
  9017. },
  9018. function getValue_arrayElement( buffer, offset ) {
  9019. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9020. },
  9021. function getValue_toArray( buffer, offset ) {
  9022. this.resolvedProperty.toArray( buffer, offset );
  9023. }
  9024. ],
  9025. SetterByBindingTypeAndVersioning: [
  9026. [
  9027. // Direct
  9028. function setValue_direct( buffer, offset ) {
  9029. this.node[ this.propertyName ] = buffer[ offset ];
  9030. },
  9031. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9032. this.node[ this.propertyName ] = buffer[ offset ];
  9033. this.targetObject.needsUpdate = true;
  9034. },
  9035. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9036. this.node[ this.propertyName ] = buffer[ offset ];
  9037. this.targetObject.matrixWorldNeedsUpdate = true;
  9038. }
  9039. ], [
  9040. // EntireArray
  9041. function setValue_array( buffer, offset ) {
  9042. var dest = this.resolvedProperty;
  9043. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9044. dest[ i ] = buffer[ offset ++ ];
  9045. }
  9046. },
  9047. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9048. var dest = this.resolvedProperty;
  9049. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9050. dest[ i ] = buffer[ offset ++ ];
  9051. }
  9052. this.targetObject.needsUpdate = true;
  9053. },
  9054. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9055. var dest = this.resolvedProperty;
  9056. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9057. dest[ i ] = buffer[ offset ++ ];
  9058. }
  9059. this.targetObject.matrixWorldNeedsUpdate = true;
  9060. }
  9061. ], [
  9062. // ArrayElement
  9063. function setValue_arrayElement( buffer, offset ) {
  9064. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9065. },
  9066. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9067. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9068. this.targetObject.needsUpdate = true;
  9069. },
  9070. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9071. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9072. this.targetObject.matrixWorldNeedsUpdate = true;
  9073. }
  9074. ], [
  9075. // HasToFromArray
  9076. function setValue_fromArray( buffer, offset ) {
  9077. this.resolvedProperty.fromArray( buffer, offset );
  9078. },
  9079. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9080. this.resolvedProperty.fromArray( buffer, offset );
  9081. this.targetObject.needsUpdate = true;
  9082. },
  9083. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9084. this.resolvedProperty.fromArray( buffer, offset );
  9085. this.targetObject.matrixWorldNeedsUpdate = true;
  9086. }
  9087. ]
  9088. ]
  9089. } );
  9090. THREE.PropertyBinding.Composite =
  9091. function( targetGroup, path, optionalParsedPath ) {
  9092. var parsedPath = optionalParsedPath ||
  9093. THREE.PropertyBinding.parseTrackName( path );
  9094. this._targetGroup = targetGroup;
  9095. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9096. };
  9097. THREE.PropertyBinding.Composite.prototype = {
  9098. constructor: THREE.PropertyBinding.Composite,
  9099. getValue: function( array, offset ) {
  9100. this.bind(); // bind all binding
  9101. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9102. binding = this._bindings[ firstValidIndex ];
  9103. // and only call .getValue on the first
  9104. if ( binding !== undefined ) binding.getValue( array, offset );
  9105. },
  9106. setValue: function( array, offset ) {
  9107. var bindings = this._bindings;
  9108. for ( var i = this._targetGroup.nCachedObjects_,
  9109. n = bindings.length; i !== n; ++ i ) {
  9110. bindings[ i ].setValue( array, offset );
  9111. }
  9112. },
  9113. bind: function() {
  9114. var bindings = this._bindings;
  9115. for ( var i = this._targetGroup.nCachedObjects_,
  9116. n = bindings.length; i !== n; ++ i ) {
  9117. bindings[ i ].bind();
  9118. }
  9119. },
  9120. unbind: function() {
  9121. var bindings = this._bindings;
  9122. for ( var i = this._targetGroup.nCachedObjects_,
  9123. n = bindings.length; i !== n; ++ i ) {
  9124. bindings[ i ].unbind();
  9125. }
  9126. }
  9127. };
  9128. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9129. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9130. return new THREE.PropertyBinding( root, path, parsedPath );
  9131. } else {
  9132. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9133. }
  9134. };
  9135. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9136. // matches strings in the form of:
  9137. // nodeName.property
  9138. // nodeName.property[accessor]
  9139. // nodeName.material.property[accessor]
  9140. // uuid.property[accessor]
  9141. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9142. // parentName/nodeName.property
  9143. // parentName/parentName/nodeName.property[index]
  9144. // .bone[Armature.DEF_cog].position
  9145. // created and tested via https://regex101.com/#javascript
  9146. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9147. var matches = re.exec(trackName);
  9148. if( ! matches ) {
  9149. throw new Error( "cannot parse trackName at all: " + trackName );
  9150. }
  9151. if (matches.index === re.lastIndex) {
  9152. re.lastIndex++;
  9153. }
  9154. var results = {
  9155. // directoryName: matches[1], // (tschw) currently unused
  9156. nodeName: matches[3], // allowed to be null, specified root node.
  9157. objectName: matches[5],
  9158. objectIndex: matches[7],
  9159. propertyName: matches[9],
  9160. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9161. };
  9162. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9163. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9164. }
  9165. return results;
  9166. };
  9167. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9168. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9169. return root;
  9170. }
  9171. // search into skeleton bones.
  9172. if( root.skeleton ) {
  9173. var searchSkeleton = function( skeleton ) {
  9174. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9175. var bone = skeleton.bones[i];
  9176. if( bone.name === nodeName ) {
  9177. return bone;
  9178. }
  9179. }
  9180. return null;
  9181. };
  9182. var bone = searchSkeleton( root.skeleton );
  9183. if( bone ) {
  9184. return bone;
  9185. }
  9186. }
  9187. // search into node subtree.
  9188. if( root.children ) {
  9189. var searchNodeSubtree = function( children ) {
  9190. for( var i = 0; i < children.length; i ++ ) {
  9191. var childNode = children[i];
  9192. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9193. return childNode;
  9194. }
  9195. var result = searchNodeSubtree( childNode.children );
  9196. if( result ) return result;
  9197. }
  9198. return null;
  9199. };
  9200. var subTreeNode = searchNodeSubtree( root.children );
  9201. if( subTreeNode ) {
  9202. return subTreeNode;
  9203. }
  9204. }
  9205. return null;
  9206. }
  9207. // File:src/animation/PropertyMixer.js
  9208. /**
  9209. *
  9210. * Buffered scene graph property that allows weighted accumulation.
  9211. *
  9212. *
  9213. * @author Ben Houston / http://clara.io/
  9214. * @author David Sarno / http://lighthaus.us/
  9215. * @author tschw
  9216. */
  9217. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9218. this.binding = binding;
  9219. this.valueSize = valueSize;
  9220. var bufferType = Float64Array,
  9221. mixFunction;
  9222. switch ( typeName ) {
  9223. case 'quaternion': mixFunction = this._slerp; break;
  9224. case 'string':
  9225. case 'bool':
  9226. bufferType = Array, mixFunction = this._select; break;
  9227. default: mixFunction = this._lerp;
  9228. }
  9229. this.buffer = new bufferType( valueSize * 4 );
  9230. // layout: [ incoming | accu0 | accu1 | orig ]
  9231. //
  9232. // interpolators can use .buffer as their .result
  9233. // the data then goes to 'incoming'
  9234. //
  9235. // 'accu0' and 'accu1' are used frame-interleaved for
  9236. // the cumulative result and are compared to detect
  9237. // changes
  9238. //
  9239. // 'orig' stores the original state of the property
  9240. this._mixBufferRegion = mixFunction;
  9241. this.cumulativeWeight = 0;
  9242. this.useCount = 0;
  9243. this.referenceCount = 0;
  9244. };
  9245. THREE.PropertyMixer.prototype = {
  9246. constructor: THREE.PropertyMixer,
  9247. // accumulate data in the 'incoming' region into 'accu<i>'
  9248. accumulate: function( accuIndex, weight ) {
  9249. // note: happily accumulating nothing when weight = 0, the caller knows
  9250. // the weight and shouldn't have made the call in the first place
  9251. var buffer = this.buffer,
  9252. stride = this.valueSize,
  9253. offset = accuIndex * stride + stride,
  9254. currentWeight = this.cumulativeWeight;
  9255. if ( currentWeight === 0 ) {
  9256. // accuN := incoming * weight
  9257. for ( var i = 0; i !== stride; ++ i ) {
  9258. buffer[ offset + i ] = buffer[ i ];
  9259. }
  9260. currentWeight = weight;
  9261. } else {
  9262. // accuN := accuN + incoming * weight
  9263. currentWeight += weight;
  9264. var mix = weight / currentWeight;
  9265. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9266. }
  9267. this.cumulativeWeight = currentWeight;
  9268. },
  9269. // apply the state of 'accu<i>' to the binding when accus differ
  9270. apply: function( accuIndex ) {
  9271. var stride = this.valueSize,
  9272. buffer = this.buffer,
  9273. offset = accuIndex * stride + stride,
  9274. weight = this.cumulativeWeight,
  9275. binding = this.binding;
  9276. this.cumulativeWeight = 0;
  9277. if ( weight < 1 ) {
  9278. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9279. var originalValueOffset = stride * 3;
  9280. this._mixBufferRegion(
  9281. buffer, offset, originalValueOffset, 1 - weight, stride );
  9282. }
  9283. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9284. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9285. // value has changed -> update scene graph
  9286. binding.setValue( buffer, offset );
  9287. break;
  9288. }
  9289. }
  9290. },
  9291. // remember the state of the bound property and copy it to both accus
  9292. saveOriginalState: function() {
  9293. var binding = this.binding;
  9294. var buffer = this.buffer,
  9295. stride = this.valueSize,
  9296. originalValueOffset = stride * 3;
  9297. binding.getValue( buffer, originalValueOffset );
  9298. // accu[0..1] := orig -- initially detect changes against the original
  9299. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9300. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9301. }
  9302. this.cumulativeWeight = 0;
  9303. },
  9304. // apply the state previously taken via 'saveOriginalState' to the binding
  9305. restoreOriginalState: function() {
  9306. var originalValueOffset = this.valueSize * 3;
  9307. this.binding.setValue( this.buffer, originalValueOffset );
  9308. },
  9309. // mix functions
  9310. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9311. if ( t >= 0.5 ) {
  9312. for ( var i = 0; i !== stride; ++ i ) {
  9313. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9314. }
  9315. }
  9316. },
  9317. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9318. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9319. buffer, dstOffset, buffer, srcOffset, t );
  9320. },
  9321. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9322. var s = 1 - t;
  9323. for ( var i = 0; i !== stride; ++ i ) {
  9324. var j = dstOffset + i;
  9325. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9326. }
  9327. }
  9328. };
  9329. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9330. /**
  9331. *
  9332. * A Track of Boolean keyframe values.
  9333. *
  9334. *
  9335. * @author Ben Houston / http://clara.io/
  9336. * @author David Sarno / http://lighthaus.us/
  9337. * @author tschw
  9338. */
  9339. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9340. THREE.KeyframeTrack.call( this, name, times, values );
  9341. };
  9342. THREE.BooleanKeyframeTrack.prototype =
  9343. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9344. constructor: THREE.BooleanKeyframeTrack,
  9345. ValueTypeName: 'bool',
  9346. ValueBufferType: Array,
  9347. DefaultInterpolation: THREE.IntepolateDiscrete,
  9348. InterpolantFactoryMethodLinear: undefined,
  9349. InterpolantFactoryMethodSmooth: undefined
  9350. // Note: Actually this track could have a optimized / compressed
  9351. // representation of a single value and a custom interpolant that
  9352. // computes "firstValue ^ isOdd( index )".
  9353. } );
  9354. // File:src/animation/tracks/NumberKeyframeTrack.js
  9355. /**
  9356. *
  9357. * A Track of numeric keyframe values.
  9358. *
  9359. * @author Ben Houston / http://clara.io/
  9360. * @author David Sarno / http://lighthaus.us/
  9361. * @author tschw
  9362. */
  9363. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9364. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9365. };
  9366. THREE.NumberKeyframeTrack.prototype =
  9367. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9368. constructor: THREE.NumberKeyframeTrack,
  9369. ValueTypeName: 'number',
  9370. // ValueBufferType is inherited
  9371. // DefaultInterpolation is inherited
  9372. } );
  9373. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9374. /**
  9375. *
  9376. * A Track of quaternion keyframe values.
  9377. *
  9378. * @author Ben Houston / http://clara.io/
  9379. * @author David Sarno / http://lighthaus.us/
  9380. * @author tschw
  9381. */
  9382. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9383. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9384. };
  9385. THREE.QuaternionKeyframeTrack.prototype =
  9386. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9387. constructor: THREE.QuaternionKeyframeTrack,
  9388. ValueTypeName: 'quaternion',
  9389. // ValueBufferType is inherited
  9390. DefaultInterpolation: THREE.InterpolateLinear,
  9391. InterpolantFactoryMethodLinear: function( result ) {
  9392. return new THREE.QuaternionLinearInterpolant(
  9393. this.times, this.values, this.getValueSize(), result );
  9394. },
  9395. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9396. } );
  9397. // File:src/animation/tracks/StringKeyframeTrack.js
  9398. /**
  9399. *
  9400. * A Track that interpolates Strings
  9401. *
  9402. *
  9403. * @author Ben Houston / http://clara.io/
  9404. * @author David Sarno / http://lighthaus.us/
  9405. * @author tschw
  9406. */
  9407. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9408. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9409. };
  9410. THREE.StringKeyframeTrack.prototype =
  9411. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9412. constructor: THREE.StringKeyframeTrack,
  9413. ValueTypeName: 'string',
  9414. ValueBufferType: Array,
  9415. DefaultInterpolation: THREE.IntepolateDiscrete,
  9416. InterpolantFactoryMethodLinear: undefined,
  9417. InterpolantFactoryMethodSmooth: undefined
  9418. } );
  9419. // File:src/animation/tracks/VectorKeyframeTrack.js
  9420. /**
  9421. *
  9422. * A Track of vectored keyframe values.
  9423. *
  9424. *
  9425. * @author Ben Houston / http://clara.io/
  9426. * @author David Sarno / http://lighthaus.us/
  9427. * @author tschw
  9428. */
  9429. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9430. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9431. };
  9432. THREE.VectorKeyframeTrack.prototype =
  9433. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9434. constructor: THREE.VectorKeyframeTrack,
  9435. ValueTypeName: 'vector'
  9436. // ValueBufferType is inherited
  9437. // DefaultInterpolation is inherited
  9438. } );
  9439. // File:src/audio/Audio.js
  9440. /**
  9441. * @author mrdoob / http://mrdoob.com/
  9442. */
  9443. THREE.Audio = function ( listener ) {
  9444. THREE.Object3D.call( this );
  9445. this.type = 'Audio';
  9446. this.context = listener.context;
  9447. this.source = this.context.createBufferSource();
  9448. this.source.onended = this.onEnded.bind( this );
  9449. this.gain = this.context.createGain();
  9450. this.gain.connect( listener.getInput() );
  9451. this.autoplay = false;
  9452. this.startTime = 0;
  9453. this.playbackRate = 1;
  9454. this.isPlaying = false;
  9455. this.hasPlaybackControl = true;
  9456. this.sourceType = 'empty';
  9457. this.filter = null;
  9458. };
  9459. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9460. THREE.Audio.prototype.constructor = THREE.Audio;
  9461. THREE.Audio.prototype.getOutput = function () {
  9462. return this.gain;
  9463. };
  9464. THREE.Audio.prototype.load = function ( file ) {
  9465. var buffer = new THREE.AudioBuffer( this.context );
  9466. buffer.load( file );
  9467. this.setBuffer( buffer );
  9468. return this;
  9469. };
  9470. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9471. this.hasPlaybackControl = false;
  9472. this.sourceType = 'audioNode';
  9473. this.source = audioNode;
  9474. this.connect();
  9475. return this;
  9476. };
  9477. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9478. var scope = this;
  9479. audioBuffer.onReady( function( buffer ) {
  9480. scope.source.buffer = buffer;
  9481. scope.sourceType = 'buffer';
  9482. if ( scope.autoplay ) scope.play();
  9483. } );
  9484. return this;
  9485. };
  9486. THREE.Audio.prototype.play = function () {
  9487. if ( this.isPlaying === true ) {
  9488. console.warn( 'THREE.Audio: Audio is already playing.' );
  9489. return;
  9490. }
  9491. if ( this.hasPlaybackControl === false ) {
  9492. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9493. return;
  9494. }
  9495. var source = this.context.createBufferSource();
  9496. source.buffer = this.source.buffer;
  9497. source.loop = this.source.loop;
  9498. source.onended = this.source.onended;
  9499. source.start( 0, this.startTime );
  9500. source.playbackRate.value = this.playbackRate;
  9501. this.isPlaying = true;
  9502. this.source = source;
  9503. this.connect();
  9504. };
  9505. THREE.Audio.prototype.pause = function () {
  9506. if ( this.hasPlaybackControl === false ) {
  9507. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9508. return;
  9509. }
  9510. this.source.stop();
  9511. this.startTime = this.context.currentTime;
  9512. };
  9513. THREE.Audio.prototype.stop = function () {
  9514. if ( this.hasPlaybackControl === false ) {
  9515. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9516. return;
  9517. }
  9518. this.source.stop();
  9519. this.startTime = 0;
  9520. };
  9521. THREE.Audio.prototype.connect = function () {
  9522. if ( this.filter !== null ) {
  9523. this.source.connect( this.filter );
  9524. this.filter.connect( this.getOutput() );
  9525. } else {
  9526. this.source.connect( this.getOutput() );
  9527. }
  9528. };
  9529. THREE.Audio.prototype.disconnect = function () {
  9530. if ( this.filter !== null ) {
  9531. this.source.disconnect( this.filter );
  9532. this.filter.disconnect( this.getOutput() );
  9533. } else {
  9534. this.source.disconnect( this.getOutput() );
  9535. }
  9536. };
  9537. THREE.Audio.prototype.getFilter = function () {
  9538. return this.filter;
  9539. };
  9540. THREE.Audio.prototype.setFilter = function ( value ) {
  9541. if ( value === undefined ) value = null;
  9542. if ( this.isPlaying === true ) {
  9543. this.disconnect();
  9544. this.filter = value;
  9545. this.connect();
  9546. } else {
  9547. this.filter = value;
  9548. }
  9549. };
  9550. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9551. if ( this.hasPlaybackControl === false ) {
  9552. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9553. return;
  9554. }
  9555. this.playbackRate = value;
  9556. if ( this.isPlaying === true ) {
  9557. this.source.playbackRate.value = this.playbackRate;
  9558. }
  9559. };
  9560. THREE.Audio.prototype.getPlaybackRate = function () {
  9561. return this.playbackRate;
  9562. };
  9563. THREE.Audio.prototype.onEnded = function() {
  9564. this.isPlaying = false;
  9565. };
  9566. THREE.Audio.prototype.setLoop = function ( value ) {
  9567. if ( this.hasPlaybackControl === false ) {
  9568. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9569. return;
  9570. }
  9571. this.source.loop = value;
  9572. };
  9573. THREE.Audio.prototype.getLoop = function () {
  9574. if ( this.hasPlaybackControl === false ) {
  9575. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9576. return false;
  9577. }
  9578. return this.source.loop;
  9579. };
  9580. THREE.Audio.prototype.setVolume = function ( value ) {
  9581. this.gain.gain.value = value;
  9582. };
  9583. THREE.Audio.prototype.getVolume = function () {
  9584. return this.gain.gain.value;
  9585. };
  9586. // File:src/audio/AudioAnalyser.js
  9587. /**
  9588. * @author mrdoob / http://mrdoob.com/
  9589. */
  9590. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9591. this.analyser = audio.context.createAnalyser();
  9592. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9593. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9594. audio.getOutput().connect( this.analyser );
  9595. };
  9596. THREE.AudioAnalyser.prototype = {
  9597. constructor: THREE.AudioAnalyser,
  9598. getData: function () {
  9599. this.analyser.getByteFrequencyData( this.data );
  9600. return this.data;
  9601. }
  9602. };
  9603. // File:src/audio/AudioBuffer.js
  9604. /**
  9605. * @author mrdoob / http://mrdoob.com/
  9606. */
  9607. THREE.AudioBuffer = function ( context ) {
  9608. this.context = context;
  9609. this.ready = false;
  9610. this.readyCallbacks = [];
  9611. };
  9612. THREE.AudioBuffer.prototype.load = function ( file ) {
  9613. var scope = this;
  9614. var request = new XMLHttpRequest();
  9615. request.open( 'GET', file, true );
  9616. request.responseType = 'arraybuffer';
  9617. request.onload = function ( e ) {
  9618. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9619. scope.buffer = buffer;
  9620. scope.ready = true;
  9621. for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
  9622. scope.readyCallbacks[ i ]( scope.buffer );
  9623. }
  9624. scope.readyCallbacks = [];
  9625. } );
  9626. };
  9627. request.send();
  9628. return this;
  9629. };
  9630. THREE.AudioBuffer.prototype.onReady = function ( callback ) {
  9631. if ( this.ready ) {
  9632. callback( this.buffer );
  9633. } else {
  9634. this.readyCallbacks.push( callback );
  9635. }
  9636. };
  9637. // File:src/audio/PositionalAudio.js
  9638. /**
  9639. * @author mrdoob / http://mrdoob.com/
  9640. */
  9641. THREE.PositionalAudio = function ( listener ) {
  9642. THREE.Audio.call( this, listener );
  9643. this.panner = this.context.createPanner();
  9644. this.panner.connect( this.gain );
  9645. };
  9646. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9647. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9648. THREE.PositionalAudio.prototype.getOutput = function () {
  9649. return this.panner;
  9650. };
  9651. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9652. this.panner.refDistance = value;
  9653. };
  9654. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9655. return this.panner.refDistance;
  9656. };
  9657. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9658. this.panner.rolloffFactor = value;
  9659. };
  9660. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9661. return this.panner.rolloffFactor;
  9662. };
  9663. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9664. this.panner.distanceModel = value;
  9665. };
  9666. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9667. return this.panner.distanceModel;
  9668. };
  9669. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9670. this.panner.maxDistance = value;
  9671. };
  9672. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9673. return this.panner.maxDistance;
  9674. };
  9675. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9676. var position = new THREE.Vector3();
  9677. return function updateMatrixWorld( force ) {
  9678. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9679. position.setFromMatrixPosition( this.matrixWorld );
  9680. this.panner.setPosition( position.x, position.y, position.z );
  9681. };
  9682. } )();
  9683. // File:src/audio/AudioListener.js
  9684. /**
  9685. * @author mrdoob / http://mrdoob.com/
  9686. */
  9687. THREE.AudioListener = function () {
  9688. THREE.Object3D.call( this );
  9689. this.type = 'AudioListener';
  9690. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9691. this.gain = this.context.createGain();
  9692. this.gain.connect( this.context.destination );
  9693. this.filter = null;
  9694. };
  9695. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9696. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9697. THREE.AudioListener.prototype.getInput = function () {
  9698. return this.gain;
  9699. };
  9700. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9701. if ( this.filter !== null ) {
  9702. this.gain.disconnect( this.filter );
  9703. this.filter.disconnect( this.context.destination );
  9704. this.gain.connect( this.context.destination );
  9705. this.filter = null;
  9706. }
  9707. };
  9708. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9709. if ( this.filter !== null ) {
  9710. this.gain.disconnect( this.filter );
  9711. this.filter.disconnect( this.context.destination );
  9712. } else {
  9713. this.gain.disconnect( this.context.destination );
  9714. }
  9715. this.filter = value;
  9716. this.gain.connect( this.filter );
  9717. this.filter.connect( this.context.destination );
  9718. };
  9719. THREE.AudioListener.prototype.getFilter = function () {
  9720. return this.filter;
  9721. };
  9722. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9723. this.gain.gain.value = value;
  9724. };
  9725. THREE.AudioListener.prototype.getMasterVolume = function () {
  9726. return this.gain.gain.value;
  9727. };
  9728. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9729. var position = new THREE.Vector3();
  9730. var quaternion = new THREE.Quaternion();
  9731. var scale = new THREE.Vector3();
  9732. var orientation = new THREE.Vector3();
  9733. return function updateMatrixWorld( force ) {
  9734. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9735. var listener = this.context.listener;
  9736. var up = this.up;
  9737. this.matrixWorld.decompose( position, quaternion, scale );
  9738. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9739. listener.setPosition( position.x, position.y, position.z );
  9740. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9741. };
  9742. } )();
  9743. // File:src/cameras/Camera.js
  9744. /**
  9745. * @author mrdoob / http://mrdoob.com/
  9746. * @author mikael emtinger / http://gomo.se/
  9747. * @author WestLangley / http://github.com/WestLangley
  9748. */
  9749. THREE.Camera = function () {
  9750. THREE.Object3D.call( this );
  9751. this.type = 'Camera';
  9752. this.matrixWorldInverse = new THREE.Matrix4();
  9753. this.projectionMatrix = new THREE.Matrix4();
  9754. };
  9755. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9756. THREE.Camera.prototype.constructor = THREE.Camera;
  9757. THREE.Camera.prototype.getWorldDirection = function () {
  9758. var quaternion = new THREE.Quaternion();
  9759. return function ( optionalTarget ) {
  9760. var result = optionalTarget || new THREE.Vector3();
  9761. this.getWorldQuaternion( quaternion );
  9762. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9763. };
  9764. }();
  9765. THREE.Camera.prototype.lookAt = function () {
  9766. // This routine does not support cameras with rotated and/or translated parent(s)
  9767. var m1 = new THREE.Matrix4();
  9768. return function ( vector ) {
  9769. m1.lookAt( this.position, vector, this.up );
  9770. this.quaternion.setFromRotationMatrix( m1 );
  9771. };
  9772. }();
  9773. THREE.Camera.prototype.clone = function () {
  9774. return new this.constructor().copy( this );
  9775. };
  9776. THREE.Camera.prototype.copy = function ( source ) {
  9777. THREE.Object3D.prototype.copy.call( this, source );
  9778. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9779. this.projectionMatrix.copy( source.projectionMatrix );
  9780. return this;
  9781. };
  9782. // File:src/cameras/CubeCamera.js
  9783. /**
  9784. * Camera for rendering cube maps
  9785. * - renders scene into axis-aligned cube
  9786. *
  9787. * @author alteredq / http://alteredqualia.com/
  9788. */
  9789. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9790. THREE.Object3D.call( this );
  9791. this.type = 'CubeCamera';
  9792. var fov = 90, aspect = 1;
  9793. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9794. cameraPX.up.set( 0, - 1, 0 );
  9795. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9796. this.add( cameraPX );
  9797. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9798. cameraNX.up.set( 0, - 1, 0 );
  9799. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9800. this.add( cameraNX );
  9801. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9802. cameraPY.up.set( 0, 0, 1 );
  9803. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9804. this.add( cameraPY );
  9805. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9806. cameraNY.up.set( 0, 0, - 1 );
  9807. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9808. this.add( cameraNY );
  9809. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9810. cameraPZ.up.set( 0, - 1, 0 );
  9811. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9812. this.add( cameraPZ );
  9813. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9814. cameraNZ.up.set( 0, - 1, 0 );
  9815. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9816. this.add( cameraNZ );
  9817. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  9818. this.updateCubeMap = function ( renderer, scene ) {
  9819. if ( this.parent === null ) this.updateMatrixWorld();
  9820. var renderTarget = this.renderTarget;
  9821. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9822. renderTarget.texture.generateMipmaps = false;
  9823. renderTarget.activeCubeFace = 0;
  9824. renderer.render( scene, cameraPX, renderTarget );
  9825. renderTarget.activeCubeFace = 1;
  9826. renderer.render( scene, cameraNX, renderTarget );
  9827. renderTarget.activeCubeFace = 2;
  9828. renderer.render( scene, cameraPY, renderTarget );
  9829. renderTarget.activeCubeFace = 3;
  9830. renderer.render( scene, cameraNY, renderTarget );
  9831. renderTarget.activeCubeFace = 4;
  9832. renderer.render( scene, cameraPZ, renderTarget );
  9833. renderTarget.texture.generateMipmaps = generateMipmaps;
  9834. renderTarget.activeCubeFace = 5;
  9835. renderer.render( scene, cameraNZ, renderTarget );
  9836. renderer.setRenderTarget( null );
  9837. };
  9838. };
  9839. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9840. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9841. // File:src/cameras/OrthographicCamera.js
  9842. /**
  9843. * @author alteredq / http://alteredqualia.com/
  9844. */
  9845. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9846. THREE.Camera.call( this );
  9847. this.type = 'OrthographicCamera';
  9848. this.zoom = 1;
  9849. this.left = left;
  9850. this.right = right;
  9851. this.top = top;
  9852. this.bottom = bottom;
  9853. this.near = ( near !== undefined ) ? near : 0.1;
  9854. this.far = ( far !== undefined ) ? far : 2000;
  9855. this.updateProjectionMatrix();
  9856. };
  9857. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9858. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9859. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9860. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9861. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9862. var cx = ( this.right + this.left ) / 2;
  9863. var cy = ( this.top + this.bottom ) / 2;
  9864. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9865. };
  9866. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9867. THREE.Camera.prototype.copy.call( this, source );
  9868. this.left = source.left;
  9869. this.right = source.right;
  9870. this.top = source.top;
  9871. this.bottom = source.bottom;
  9872. this.near = source.near;
  9873. this.far = source.far;
  9874. this.zoom = source.zoom;
  9875. return this;
  9876. };
  9877. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9878. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9879. data.object.zoom = this.zoom;
  9880. data.object.left = this.left;
  9881. data.object.right = this.right;
  9882. data.object.top = this.top;
  9883. data.object.bottom = this.bottom;
  9884. data.object.near = this.near;
  9885. data.object.far = this.far;
  9886. return data;
  9887. };
  9888. // File:src/cameras/PerspectiveCamera.js
  9889. /**
  9890. * @author mrdoob / http://mrdoob.com/
  9891. * @author greggman / http://games.greggman.com/
  9892. * @author zz85 / http://www.lab4games.net/zz85/blog
  9893. */
  9894. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9895. THREE.Camera.call( this );
  9896. this.type = 'PerspectiveCamera';
  9897. this.zoom = 1;
  9898. this.fov = fov !== undefined ? fov : 50;
  9899. this.aspect = aspect !== undefined ? aspect : 1;
  9900. this.near = near !== undefined ? near : 0.1;
  9901. this.far = far !== undefined ? far : 2000;
  9902. this.updateProjectionMatrix();
  9903. };
  9904. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9905. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9906. /**
  9907. * Uses Focal Length (in mm) to estimate and set FOV
  9908. * 35mm (full-frame) camera is used if frame size is not specified;
  9909. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9910. */
  9911. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9912. if ( frameHeight === undefined ) frameHeight = 24;
  9913. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9914. this.updateProjectionMatrix();
  9915. };
  9916. /**
  9917. * Sets an offset in a larger frustum. This is useful for multi-window or
  9918. * multi-monitor/multi-machine setups.
  9919. *
  9920. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9921. * the monitors are in grid like this
  9922. *
  9923. * +---+---+---+
  9924. * | A | B | C |
  9925. * +---+---+---+
  9926. * | D | E | F |
  9927. * +---+---+---+
  9928. *
  9929. * then for each monitor you would call it like this
  9930. *
  9931. * var w = 1920;
  9932. * var h = 1080;
  9933. * var fullWidth = w * 3;
  9934. * var fullHeight = h * 2;
  9935. *
  9936. * --A--
  9937. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9938. * --B--
  9939. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9940. * --C--
  9941. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9942. * --D--
  9943. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9944. * --E--
  9945. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9946. * --F--
  9947. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9948. *
  9949. * Note there is no reason monitors have to be the same size or in a grid.
  9950. */
  9951. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  9952. this.fullWidth = fullWidth;
  9953. this.fullHeight = fullHeight;
  9954. this.x = x;
  9955. this.y = y;
  9956. this.width = width;
  9957. this.height = height;
  9958. this.updateProjectionMatrix();
  9959. };
  9960. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  9961. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  9962. if ( this.fullWidth ) {
  9963. var aspect = this.fullWidth / this.fullHeight;
  9964. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  9965. var bottom = - top;
  9966. var left = aspect * bottom;
  9967. var right = aspect * top;
  9968. var width = Math.abs( right - left );
  9969. var height = Math.abs( top - bottom );
  9970. this.projectionMatrix.makeFrustum(
  9971. left + this.x * width / this.fullWidth,
  9972. left + ( this.x + this.width ) * width / this.fullWidth,
  9973. top - ( this.y + this.height ) * height / this.fullHeight,
  9974. top - this.y * height / this.fullHeight,
  9975. this.near,
  9976. this.far
  9977. );
  9978. } else {
  9979. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  9980. }
  9981. };
  9982. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  9983. THREE.Camera.prototype.copy.call( this, source );
  9984. this.fov = source.fov;
  9985. this.aspect = source.aspect;
  9986. this.near = source.near;
  9987. this.far = source.far;
  9988. this.zoom = source.zoom;
  9989. return this;
  9990. };
  9991. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  9992. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9993. data.object.zoom = this.zoom;
  9994. data.object.fov = this.fov;
  9995. data.object.aspect = this.aspect;
  9996. data.object.near = this.near;
  9997. data.object.far = this.far;
  9998. return data;
  9999. };
  10000. // File:src/lights/Light.js
  10001. /**
  10002. * @author mrdoob / http://mrdoob.com/
  10003. * @author alteredq / http://alteredqualia.com/
  10004. */
  10005. THREE.Light = function ( color, intensity ) {
  10006. THREE.Object3D.call( this );
  10007. this.type = 'Light';
  10008. this.color = new THREE.Color( color );
  10009. this.intensity = intensity !== undefined ? intensity : 1;
  10010. this.receiveShadow = undefined;
  10011. };
  10012. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10013. THREE.Light.prototype.constructor = THREE.Light;
  10014. THREE.Light.prototype.copy = function ( source ) {
  10015. THREE.Object3D.prototype.copy.call( this, source );
  10016. this.color.copy( source.color );
  10017. this.intensity = source.intensity;
  10018. return this;
  10019. };
  10020. THREE.Light.prototype.toJSON = function ( meta ) {
  10021. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10022. data.object.color = this.color.getHex();
  10023. data.object.intensity = this.intensity;
  10024. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10025. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10026. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10027. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10028. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  10029. return data;
  10030. };
  10031. // File:src/lights/LightShadow.js
  10032. /**
  10033. * @author mrdoob / http://mrdoob.com/
  10034. */
  10035. THREE.LightShadow = function ( camera ) {
  10036. this.camera = camera;
  10037. this.bias = 0;
  10038. this.darkness = 1;
  10039. this.mapSize = new THREE.Vector2( 512, 512 );
  10040. this.map = null;
  10041. this.matrix = null;
  10042. };
  10043. THREE.LightShadow.prototype = {
  10044. constructor: THREE.LightShadow,
  10045. copy: function ( source ) {
  10046. this.camera = source.camera.clone();
  10047. this.bias = source.bias;
  10048. this.darkness = source.darkness;
  10049. this.mapSize.copy( source.mapSize );
  10050. return this;
  10051. },
  10052. clone: function () {
  10053. return new this.constructor().copy( this );
  10054. }
  10055. };
  10056. // File:src/lights/AmbientLight.js
  10057. /**
  10058. * @author mrdoob / http://mrdoob.com/
  10059. */
  10060. THREE.AmbientLight = function ( color, intensity ) {
  10061. THREE.Light.call( this, color, intensity );
  10062. this.type = 'AmbientLight';
  10063. this.castShadow = undefined;
  10064. };
  10065. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10066. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10067. // File:src/lights/DirectionalLight.js
  10068. /**
  10069. * @author mrdoob / http://mrdoob.com/
  10070. * @author alteredq / http://alteredqualia.com/
  10071. */
  10072. THREE.DirectionalLight = function ( color, intensity ) {
  10073. THREE.Light.call( this, color, intensity );
  10074. this.type = 'DirectionalLight';
  10075. this.position.set( 0, 1, 0 );
  10076. this.updateMatrix();
  10077. this.target = new THREE.Object3D();
  10078. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 500, 500, 500, - 500, 50, 5000 ) );
  10079. };
  10080. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10081. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10082. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10083. THREE.Light.prototype.copy.call( this, source );
  10084. this.target = source.target.clone();
  10085. this.shadow = source.shadow.clone();
  10086. return this;
  10087. };
  10088. // File:src/lights/HemisphereLight.js
  10089. /**
  10090. * @author alteredq / http://alteredqualia.com/
  10091. */
  10092. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10093. THREE.Light.call( this, skyColor, intensity );
  10094. this.type = 'HemisphereLight';
  10095. this.castShadow = undefined;
  10096. this.position.set( 0, 1, 0 );
  10097. this.updateMatrix();
  10098. this.groundColor = new THREE.Color( groundColor );
  10099. };
  10100. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10101. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10102. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10103. THREE.Light.prototype.copy.call( this, source );
  10104. this.groundColor.copy( source.groundColor );
  10105. return this;
  10106. };
  10107. // File:src/lights/PointLight.js
  10108. /**
  10109. * @author mrdoob / http://mrdoob.com/
  10110. */
  10111. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10112. THREE.Light.call( this, color, intensity );
  10113. this.type = 'PointLight';
  10114. this.distance = ( distance !== undefined ) ? distance : 0;
  10115. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10116. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 1, 500 ) );
  10117. };
  10118. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10119. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10120. THREE.PointLight.prototype.copy = function ( source ) {
  10121. THREE.Light.prototype.copy.call( this, source );
  10122. this.distance = source.distance;
  10123. this.decay = source.decay;
  10124. this.shadow = source.shadow.clone();
  10125. return this;
  10126. };
  10127. // File:src/lights/SpotLight.js
  10128. /**
  10129. * @author alteredq / http://alteredqualia.com/
  10130. */
  10131. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  10132. THREE.Light.call( this, color, intensity );
  10133. this.type = 'SpotLight';
  10134. this.position.set( 0, 1, 0 );
  10135. this.updateMatrix();
  10136. this.target = new THREE.Object3D();
  10137. this.distance = ( distance !== undefined ) ? distance : 0;
  10138. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10139. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  10140. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10141. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 50, 5000 ) );
  10142. };
  10143. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10144. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10145. THREE.SpotLight.prototype.copy = function ( source ) {
  10146. THREE.Light.prototype.copy.call( this, source );
  10147. this.distance = source.distance;
  10148. this.angle = source.angle;
  10149. this.exponent = source.exponent;
  10150. this.decay = source.decay;
  10151. this.target = source.target.clone();
  10152. this.shadow = source.shadow.clone();
  10153. return this;
  10154. };
  10155. // File:src/loaders/Cache.js
  10156. /**
  10157. * @author mrdoob / http://mrdoob.com/
  10158. */
  10159. THREE.Cache = {
  10160. enabled: false,
  10161. files: {},
  10162. add: function ( key, file ) {
  10163. if ( this.enabled === false ) return;
  10164. // console.log( 'THREE.Cache', 'Adding key:', key );
  10165. this.files[ key ] = file;
  10166. },
  10167. get: function ( key ) {
  10168. if ( this.enabled === false ) return;
  10169. // console.log( 'THREE.Cache', 'Checking key:', key );
  10170. return this.files[ key ];
  10171. },
  10172. remove: function ( key ) {
  10173. delete this.files[ key ];
  10174. },
  10175. clear: function () {
  10176. this.files = {};
  10177. }
  10178. };
  10179. // File:src/loaders/Loader.js
  10180. /**
  10181. * @author alteredq / http://alteredqualia.com/
  10182. */
  10183. THREE.Loader = function () {
  10184. this.onLoadStart = function () {};
  10185. this.onLoadProgress = function () {};
  10186. this.onLoadComplete = function () {};
  10187. };
  10188. THREE.Loader.prototype = {
  10189. constructor: THREE.Loader,
  10190. crossOrigin: undefined,
  10191. extractUrlBase: function ( url ) {
  10192. var parts = url.split( '/' );
  10193. if ( parts.length === 1 ) return './';
  10194. parts.pop();
  10195. return parts.join( '/' ) + '/';
  10196. },
  10197. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10198. var array = [];
  10199. for ( var i = 0; i < materials.length; ++ i ) {
  10200. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10201. }
  10202. return array;
  10203. },
  10204. createMaterial: ( function () {
  10205. var color, textureLoader, materialLoader;
  10206. return function ( m, texturePath, crossOrigin ) {
  10207. if ( color === undefined ) color = new THREE.Color();
  10208. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10209. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10210. // convert from old material format
  10211. var textures = {};
  10212. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10213. var fullPath = texturePath + path;
  10214. var loader = THREE.Loader.Handlers.get( fullPath );
  10215. var texture;
  10216. if ( loader !== null ) {
  10217. texture = loader.load( fullPath );
  10218. } else {
  10219. textureLoader.setCrossOrigin( crossOrigin );
  10220. texture = textureLoader.load( fullPath );
  10221. }
  10222. if ( repeat !== undefined ) {
  10223. texture.repeat.fromArray( repeat );
  10224. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10225. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10226. }
  10227. if ( offset !== undefined ) {
  10228. texture.offset.fromArray( offset );
  10229. }
  10230. if ( wrap !== undefined ) {
  10231. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10232. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10233. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10234. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10235. }
  10236. if ( anisotropy !== undefined ) {
  10237. texture.anisotropy = anisotropy;
  10238. }
  10239. var uuid = THREE.Math.generateUUID();
  10240. textures[ uuid ] = texture;
  10241. return uuid;
  10242. }
  10243. //
  10244. var json = {
  10245. uuid: THREE.Math.generateUUID(),
  10246. type: 'MeshLambertMaterial'
  10247. };
  10248. for ( var name in m ) {
  10249. var value = m[ name ];
  10250. switch ( name ) {
  10251. case 'DbgColor':
  10252. case 'DbgIndex':
  10253. case 'opticalDensity':
  10254. case 'illumination':
  10255. break;
  10256. case 'DbgName':
  10257. json.name = value;
  10258. break;
  10259. case 'blending':
  10260. json.blending = THREE[ value ];
  10261. break;
  10262. case 'colorAmbient':
  10263. console.warn( 'THREE.Loader.createMaterial: colorAmbient is no longer supported' );
  10264. break;
  10265. case 'colorDiffuse':
  10266. json.color = color.fromArray( value ).getHex();
  10267. break;
  10268. case 'colorSpecular':
  10269. json.specular = color.fromArray( value ).getHex();
  10270. break;
  10271. case 'colorEmissive':
  10272. json.emissive = color.fromArray( value ).getHex();
  10273. break;
  10274. case 'specularCoef':
  10275. json.shininess = value;
  10276. break;
  10277. case 'shading':
  10278. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10279. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10280. break;
  10281. case 'mapDiffuse':
  10282. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10283. break;
  10284. case 'mapDiffuseRepeat':
  10285. case 'mapDiffuseOffset':
  10286. case 'mapDiffuseWrap':
  10287. case 'mapDiffuseAnisotropy':
  10288. break;
  10289. case 'mapLight':
  10290. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10291. break;
  10292. case 'mapLightRepeat':
  10293. case 'mapLightOffset':
  10294. case 'mapLightWrap':
  10295. case 'mapLightAnisotropy':
  10296. break;
  10297. case 'mapAO':
  10298. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10299. break;
  10300. case 'mapAORepeat':
  10301. case 'mapAOOffset':
  10302. case 'mapAOWrap':
  10303. case 'mapAOAnisotropy':
  10304. break;
  10305. case 'mapBump':
  10306. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10307. break;
  10308. case 'mapBumpScale':
  10309. json.bumpScale = value;
  10310. break;
  10311. case 'mapBumpRepeat':
  10312. case 'mapBumpOffset':
  10313. case 'mapBumpWrap':
  10314. case 'mapBumpAnisotropy':
  10315. break;
  10316. case 'mapNormal':
  10317. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10318. break;
  10319. case 'mapNormalFactor':
  10320. json.normalScale = [ value, value ];
  10321. break;
  10322. case 'mapNormalRepeat':
  10323. case 'mapNormalOffset':
  10324. case 'mapNormalWrap':
  10325. case 'mapNormalAnisotropy':
  10326. break;
  10327. case 'mapSpecular':
  10328. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10329. break;
  10330. case 'mapSpecularRepeat':
  10331. case 'mapSpecularOffset':
  10332. case 'mapSpecularWrap':
  10333. case 'mapSpecularAnisotropy':
  10334. break;
  10335. case 'mapAlpha':
  10336. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10337. break;
  10338. case 'mapAlphaRepeat':
  10339. case 'mapAlphaOffset':
  10340. case 'mapAlphaWrap':
  10341. case 'mapAlphaAnisotropy':
  10342. break;
  10343. case 'flipSided':
  10344. json.side = THREE.BackSide;
  10345. break;
  10346. case 'doubleSided':
  10347. json.side = THREE.DoubleSide;
  10348. break;
  10349. case 'transparency':
  10350. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10351. json.opacity = value;
  10352. break;
  10353. case 'depthTest':
  10354. case 'depthWrite':
  10355. case 'opacity':
  10356. case 'reflectivity':
  10357. case 'transparent':
  10358. case 'visible':
  10359. case 'wireframe':
  10360. json[ name ] = value;
  10361. break;
  10362. case 'vertexColors':
  10363. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10364. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10365. break;
  10366. default:
  10367. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10368. break;
  10369. }
  10370. }
  10371. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10372. if ( json.opacity < 1 ) json.transparent = true;
  10373. materialLoader.setTextures( textures );
  10374. return materialLoader.parse( json );
  10375. };
  10376. } )()
  10377. };
  10378. THREE.Loader.Handlers = {
  10379. handlers: [],
  10380. add: function ( regex, loader ) {
  10381. this.handlers.push( regex, loader );
  10382. },
  10383. get: function ( file ) {
  10384. var handlers = this.handlers;
  10385. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10386. var regex = handlers[ i ];
  10387. var loader = handlers[ i + 1 ];
  10388. if ( regex.test( file ) ) {
  10389. return loader;
  10390. }
  10391. }
  10392. return null;
  10393. }
  10394. };
  10395. // File:src/loaders/XHRLoader.js
  10396. /**
  10397. * @author mrdoob / http://mrdoob.com/
  10398. */
  10399. THREE.XHRLoader = function ( manager ) {
  10400. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10401. };
  10402. THREE.XHRLoader.prototype = {
  10403. constructor: THREE.XHRLoader,
  10404. load: function ( url, onLoad, onProgress, onError ) {
  10405. if ( this.path !== undefined ) url = this.path + url;
  10406. var scope = this;
  10407. var cached = THREE.Cache.get( url );
  10408. if ( cached !== undefined ) {
  10409. if ( onLoad ) {
  10410. setTimeout( function () {
  10411. onLoad( cached );
  10412. }, 0 );
  10413. }
  10414. return cached;
  10415. }
  10416. var request = new XMLHttpRequest();
  10417. request.overrideMimeType( 'text/plain' );
  10418. request.open( 'GET', url, true );
  10419. request.addEventListener( 'load', function ( event ) {
  10420. var response = event.target.response;
  10421. THREE.Cache.add( url, response );
  10422. if ( this.status === 200 && this.readyState === 4 ) {
  10423. if ( onLoad ) onLoad( response );
  10424. scope.manager.itemEnd( url );
  10425. } else {
  10426. if ( onError ) onError( event );
  10427. scope.manager.itemError( url );
  10428. }
  10429. }, false );
  10430. if ( onProgress !== undefined ) {
  10431. request.addEventListener( 'progress', function ( event ) {
  10432. onProgress( event );
  10433. }, false );
  10434. }
  10435. request.addEventListener( 'error', function ( event ) {
  10436. if ( onError ) onError( event );
  10437. scope.manager.itemError( url );
  10438. }, false );
  10439. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10440. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10441. request.send( null );
  10442. scope.manager.itemStart( url );
  10443. return request;
  10444. },
  10445. setPath: function ( value ) {
  10446. this.path = value;
  10447. },
  10448. setResponseType: function ( value ) {
  10449. this.responseType = value;
  10450. },
  10451. setWithCredentials: function ( value ) {
  10452. this.withCredentials = value;
  10453. }
  10454. };
  10455. // File:src/loaders/ImageLoader.js
  10456. /**
  10457. * @author mrdoob / http://mrdoob.com/
  10458. */
  10459. THREE.ImageLoader = function ( manager ) {
  10460. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10461. };
  10462. THREE.ImageLoader.prototype = {
  10463. constructor: THREE.ImageLoader,
  10464. load: function ( url, onLoad, onProgress, onError ) {
  10465. if ( this.path !== undefined ) url = this.path + url;
  10466. var scope = this;
  10467. var cached = THREE.Cache.get( url );
  10468. if ( cached !== undefined ) {
  10469. scope.manager.itemStart( url );
  10470. if ( onLoad ) {
  10471. setTimeout( function () {
  10472. onLoad( cached );
  10473. scope.manager.itemEnd( url );
  10474. }, 0 );
  10475. } else {
  10476. scope.manager.itemEnd( url );
  10477. }
  10478. return cached;
  10479. }
  10480. var image = document.createElement( 'img' );
  10481. image.addEventListener( 'load', function ( event ) {
  10482. THREE.Cache.add( url, this );
  10483. if ( onLoad ) onLoad( this );
  10484. scope.manager.itemEnd( url );
  10485. }, false );
  10486. if ( onProgress !== undefined ) {
  10487. image.addEventListener( 'progress', function ( event ) {
  10488. onProgress( event );
  10489. }, false );
  10490. }
  10491. image.addEventListener( 'error', function ( event ) {
  10492. if ( onError ) onError( event );
  10493. scope.manager.itemError( url );
  10494. }, false );
  10495. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10496. scope.manager.itemStart( url );
  10497. image.src = url;
  10498. return image;
  10499. },
  10500. setCrossOrigin: function ( value ) {
  10501. this.crossOrigin = value;
  10502. },
  10503. setPath: function ( value ) {
  10504. this.path = value;
  10505. }
  10506. };
  10507. // File:src/loaders/JSONLoader.js
  10508. /**
  10509. * @author mrdoob / http://mrdoob.com/
  10510. * @author alteredq / http://alteredqualia.com/
  10511. */
  10512. THREE.JSONLoader = function ( manager ) {
  10513. if ( typeof manager === 'boolean' ) {
  10514. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10515. manager = undefined;
  10516. }
  10517. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10518. this.withCredentials = false;
  10519. };
  10520. THREE.JSONLoader.prototype = {
  10521. constructor: THREE.JSONLoader,
  10522. // Deprecated
  10523. get statusDomElement () {
  10524. if ( this._statusDomElement === undefined ) {
  10525. this._statusDomElement = document.createElement( 'div' );
  10526. }
  10527. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10528. return this._statusDomElement;
  10529. },
  10530. load: function( url, onLoad, onProgress, onError ) {
  10531. var scope = this;
  10532. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10533. var loader = new THREE.XHRLoader( this.manager );
  10534. loader.setWithCredentials( this.withCredentials );
  10535. loader.load( url, function ( text ) {
  10536. var json = JSON.parse( text );
  10537. var metadata = json.metadata;
  10538. if ( metadata !== undefined ) {
  10539. var type = metadata.type;
  10540. if ( type !== undefined ) {
  10541. if ( type.toLowerCase() === 'object' ) {
  10542. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10543. return;
  10544. }
  10545. if ( type.toLowerCase() === 'scene' ) {
  10546. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10547. return;
  10548. }
  10549. }
  10550. }
  10551. var object = scope.parse( json, texturePath );
  10552. onLoad( object.geometry, object.materials );
  10553. }, onProgress, onError );
  10554. },
  10555. setTexturePath: function ( value ) {
  10556. this.texturePath = value;
  10557. },
  10558. parse: function ( json, texturePath ) {
  10559. var geometry = new THREE.Geometry(),
  10560. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10561. parseModel( scale );
  10562. parseSkin();
  10563. parseMorphing( scale );
  10564. parseAnimations();
  10565. geometry.computeFaceNormals();
  10566. geometry.computeBoundingSphere();
  10567. function parseModel( scale ) {
  10568. function isBitSet( value, position ) {
  10569. return value & ( 1 << position );
  10570. }
  10571. var i, j, fi,
  10572. offset, zLength,
  10573. colorIndex, normalIndex, uvIndex, materialIndex,
  10574. type,
  10575. isQuad,
  10576. hasMaterial,
  10577. hasFaceVertexUv,
  10578. hasFaceNormal, hasFaceVertexNormal,
  10579. hasFaceColor, hasFaceVertexColor,
  10580. vertex, face, faceA, faceB, hex, normal,
  10581. uvLayer, uv, u, v,
  10582. faces = json.faces,
  10583. vertices = json.vertices,
  10584. normals = json.normals,
  10585. colors = json.colors,
  10586. nUvLayers = 0;
  10587. if ( json.uvs !== undefined ) {
  10588. // disregard empty arrays
  10589. for ( i = 0; i < json.uvs.length; i ++ ) {
  10590. if ( json.uvs[ i ].length ) nUvLayers ++;
  10591. }
  10592. for ( i = 0; i < nUvLayers; i ++ ) {
  10593. geometry.faceVertexUvs[ i ] = [];
  10594. }
  10595. }
  10596. offset = 0;
  10597. zLength = vertices.length;
  10598. while ( offset < zLength ) {
  10599. vertex = new THREE.Vector3();
  10600. vertex.x = vertices[ offset ++ ] * scale;
  10601. vertex.y = vertices[ offset ++ ] * scale;
  10602. vertex.z = vertices[ offset ++ ] * scale;
  10603. geometry.vertices.push( vertex );
  10604. }
  10605. offset = 0;
  10606. zLength = faces.length;
  10607. while ( offset < zLength ) {
  10608. type = faces[ offset ++ ];
  10609. isQuad = isBitSet( type, 0 );
  10610. hasMaterial = isBitSet( type, 1 );
  10611. hasFaceVertexUv = isBitSet( type, 3 );
  10612. hasFaceNormal = isBitSet( type, 4 );
  10613. hasFaceVertexNormal = isBitSet( type, 5 );
  10614. hasFaceColor = isBitSet( type, 6 );
  10615. hasFaceVertexColor = isBitSet( type, 7 );
  10616. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10617. if ( isQuad ) {
  10618. faceA = new THREE.Face3();
  10619. faceA.a = faces[ offset ];
  10620. faceA.b = faces[ offset + 1 ];
  10621. faceA.c = faces[ offset + 3 ];
  10622. faceB = new THREE.Face3();
  10623. faceB.a = faces[ offset + 1 ];
  10624. faceB.b = faces[ offset + 2 ];
  10625. faceB.c = faces[ offset + 3 ];
  10626. offset += 4;
  10627. if ( hasMaterial ) {
  10628. materialIndex = faces[ offset ++ ];
  10629. faceA.materialIndex = materialIndex;
  10630. faceB.materialIndex = materialIndex;
  10631. }
  10632. // to get face <=> uv index correspondence
  10633. fi = geometry.faces.length;
  10634. if ( hasFaceVertexUv ) {
  10635. for ( i = 0; i < nUvLayers; i ++ ) {
  10636. uvLayer = json.uvs[ i ];
  10637. geometry.faceVertexUvs[ i ][ fi ] = [];
  10638. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10639. for ( j = 0; j < 4; j ++ ) {
  10640. uvIndex = faces[ offset ++ ];
  10641. u = uvLayer[ uvIndex * 2 ];
  10642. v = uvLayer[ uvIndex * 2 + 1 ];
  10643. uv = new THREE.Vector2( u, v );
  10644. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10645. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10646. }
  10647. }
  10648. }
  10649. if ( hasFaceNormal ) {
  10650. normalIndex = faces[ offset ++ ] * 3;
  10651. faceA.normal.set(
  10652. normals[ normalIndex ++ ],
  10653. normals[ normalIndex ++ ],
  10654. normals[ normalIndex ]
  10655. );
  10656. faceB.normal.copy( faceA.normal );
  10657. }
  10658. if ( hasFaceVertexNormal ) {
  10659. for ( i = 0; i < 4; i ++ ) {
  10660. normalIndex = faces[ offset ++ ] * 3;
  10661. normal = new THREE.Vector3(
  10662. normals[ normalIndex ++ ],
  10663. normals[ normalIndex ++ ],
  10664. normals[ normalIndex ]
  10665. );
  10666. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10667. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10668. }
  10669. }
  10670. if ( hasFaceColor ) {
  10671. colorIndex = faces[ offset ++ ];
  10672. hex = colors[ colorIndex ];
  10673. faceA.color.setHex( hex );
  10674. faceB.color.setHex( hex );
  10675. }
  10676. if ( hasFaceVertexColor ) {
  10677. for ( i = 0; i < 4; i ++ ) {
  10678. colorIndex = faces[ offset ++ ];
  10679. hex = colors[ colorIndex ];
  10680. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10681. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10682. }
  10683. }
  10684. geometry.faces.push( faceA );
  10685. geometry.faces.push( faceB );
  10686. } else {
  10687. face = new THREE.Face3();
  10688. face.a = faces[ offset ++ ];
  10689. face.b = faces[ offset ++ ];
  10690. face.c = faces[ offset ++ ];
  10691. if ( hasMaterial ) {
  10692. materialIndex = faces[ offset ++ ];
  10693. face.materialIndex = materialIndex;
  10694. }
  10695. // to get face <=> uv index correspondence
  10696. fi = geometry.faces.length;
  10697. if ( hasFaceVertexUv ) {
  10698. for ( i = 0; i < nUvLayers; i ++ ) {
  10699. uvLayer = json.uvs[ i ];
  10700. geometry.faceVertexUvs[ i ][ fi ] = [];
  10701. for ( j = 0; j < 3; j ++ ) {
  10702. uvIndex = faces[ offset ++ ];
  10703. u = uvLayer[ uvIndex * 2 ];
  10704. v = uvLayer[ uvIndex * 2 + 1 ];
  10705. uv = new THREE.Vector2( u, v );
  10706. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10707. }
  10708. }
  10709. }
  10710. if ( hasFaceNormal ) {
  10711. normalIndex = faces[ offset ++ ] * 3;
  10712. face.normal.set(
  10713. normals[ normalIndex ++ ],
  10714. normals[ normalIndex ++ ],
  10715. normals[ normalIndex ]
  10716. );
  10717. }
  10718. if ( hasFaceVertexNormal ) {
  10719. for ( i = 0; i < 3; i ++ ) {
  10720. normalIndex = faces[ offset ++ ] * 3;
  10721. normal = new THREE.Vector3(
  10722. normals[ normalIndex ++ ],
  10723. normals[ normalIndex ++ ],
  10724. normals[ normalIndex ]
  10725. );
  10726. face.vertexNormals.push( normal );
  10727. }
  10728. }
  10729. if ( hasFaceColor ) {
  10730. colorIndex = faces[ offset ++ ];
  10731. face.color.setHex( colors[ colorIndex ] );
  10732. }
  10733. if ( hasFaceVertexColor ) {
  10734. for ( i = 0; i < 3; i ++ ) {
  10735. colorIndex = faces[ offset ++ ];
  10736. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10737. }
  10738. }
  10739. geometry.faces.push( face );
  10740. }
  10741. }
  10742. };
  10743. function parseSkin() {
  10744. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10745. if ( json.skinWeights ) {
  10746. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10747. var x = json.skinWeights[ i ];
  10748. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10749. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10750. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10751. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10752. }
  10753. }
  10754. if ( json.skinIndices ) {
  10755. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10756. var a = json.skinIndices[ i ];
  10757. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10758. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10759. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10760. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10761. }
  10762. }
  10763. geometry.bones = json.bones;
  10764. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10765. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10766. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10767. }
  10768. };
  10769. function parseMorphing( scale ) {
  10770. if ( json.morphTargets !== undefined ) {
  10771. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10772. geometry.morphTargets[ i ] = {};
  10773. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10774. geometry.morphTargets[ i ].vertices = [];
  10775. var dstVertices = geometry.morphTargets[ i ].vertices;
  10776. var srcVertices = json.morphTargets[ i ].vertices;
  10777. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10778. var vertex = new THREE.Vector3();
  10779. vertex.x = srcVertices[ v ] * scale;
  10780. vertex.y = srcVertices[ v + 1 ] * scale;
  10781. vertex.z = srcVertices[ v + 2 ] * scale;
  10782. dstVertices.push( vertex );
  10783. }
  10784. }
  10785. }
  10786. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10787. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10788. var faces = geometry.faces;
  10789. var morphColors = json.morphColors[ 0 ].colors;
  10790. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10791. faces[ i ].color.fromArray( morphColors, i * 3 );
  10792. }
  10793. }
  10794. }
  10795. function parseAnimations() {
  10796. var outputAnimations = [];
  10797. // parse old style Bone/Hierarchy animations
  10798. var animations = [];
  10799. if ( json.animation !== undefined ) {
  10800. animations.push( json.animation );
  10801. }
  10802. if ( json.animations !== undefined ) {
  10803. if ( json.animations.length ) {
  10804. animations = animations.concat( json.animations );
  10805. } else {
  10806. animations.push( json.animations );
  10807. }
  10808. }
  10809. for ( var i = 0; i < animations.length; i ++ ) {
  10810. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  10811. if ( clip ) outputAnimations.push( clip );
  10812. }
  10813. // parse implicit morph animations
  10814. if ( geometry.morphTargets ) {
  10815. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10816. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10817. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10818. }
  10819. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10820. };
  10821. if ( json.materials === undefined || json.materials.length === 0 ) {
  10822. return { geometry: geometry };
  10823. } else {
  10824. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10825. return { geometry: geometry, materials: materials };
  10826. }
  10827. }
  10828. };
  10829. // File:src/loaders/LoadingManager.js
  10830. /**
  10831. * @author mrdoob / http://mrdoob.com/
  10832. */
  10833. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  10834. var scope = this;
  10835. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  10836. this.onStart = undefined;
  10837. this.onLoad = onLoad;
  10838. this.onProgress = onProgress;
  10839. this.onError = onError;
  10840. this.itemStart = function ( url ) {
  10841. itemsTotal ++;
  10842. if ( isLoading === false ) {
  10843. if ( scope.onStart !== undefined ) {
  10844. scope.onStart( url, itemsLoaded, itemsTotal );
  10845. }
  10846. }
  10847. isLoading = true;
  10848. };
  10849. this.itemEnd = function ( url ) {
  10850. itemsLoaded ++;
  10851. if ( scope.onProgress !== undefined ) {
  10852. scope.onProgress( url, itemsLoaded, itemsTotal );
  10853. }
  10854. if ( itemsLoaded === itemsTotal ) {
  10855. isLoading = false;
  10856. if ( scope.onLoad !== undefined ) {
  10857. scope.onLoad();
  10858. }
  10859. }
  10860. };
  10861. this.itemError = function ( url ) {
  10862. if ( scope.onError !== undefined ) {
  10863. scope.onError( url );
  10864. }
  10865. };
  10866. };
  10867. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  10868. // File:src/loaders/BufferGeometryLoader.js
  10869. /**
  10870. * @author mrdoob / http://mrdoob.com/
  10871. */
  10872. THREE.BufferGeometryLoader = function ( manager ) {
  10873. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10874. };
  10875. THREE.BufferGeometryLoader.prototype = {
  10876. constructor: THREE.BufferGeometryLoader,
  10877. load: function ( url, onLoad, onProgress, onError ) {
  10878. var scope = this;
  10879. var loader = new THREE.XHRLoader( scope.manager );
  10880. loader.load( url, function ( text ) {
  10881. onLoad( scope.parse( JSON.parse( text ) ) );
  10882. }, onProgress, onError );
  10883. },
  10884. parse: function ( json ) {
  10885. var geometry = new THREE.BufferGeometry();
  10886. var index = json.data.index;
  10887. if ( index !== undefined ) {
  10888. var typedArray = new self[ index.type ]( index.array );
  10889. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  10890. }
  10891. var attributes = json.data.attributes;
  10892. for ( var key in attributes ) {
  10893. var attribute = attributes[ key ];
  10894. var typedArray = new self[ attribute.type ]( attribute.array );
  10895. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  10896. }
  10897. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  10898. if ( groups !== undefined ) {
  10899. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  10900. var group = groups[ i ];
  10901. geometry.addGroup( group.start, group.count, group.materialIndex );
  10902. }
  10903. }
  10904. var boundingSphere = json.data.boundingSphere;
  10905. if ( boundingSphere !== undefined ) {
  10906. var center = new THREE.Vector3();
  10907. if ( boundingSphere.center !== undefined ) {
  10908. center.fromArray( boundingSphere.center );
  10909. }
  10910. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  10911. }
  10912. return geometry;
  10913. }
  10914. };
  10915. // File:src/loaders/MaterialLoader.js
  10916. /**
  10917. * @author mrdoob / http://mrdoob.com/
  10918. */
  10919. THREE.MaterialLoader = function ( manager ) {
  10920. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10921. this.textures = {};
  10922. };
  10923. THREE.MaterialLoader.prototype = {
  10924. constructor: THREE.MaterialLoader,
  10925. load: function ( url, onLoad, onProgress, onError ) {
  10926. var scope = this;
  10927. var loader = new THREE.XHRLoader( scope.manager );
  10928. loader.load( url, function ( text ) {
  10929. onLoad( scope.parse( JSON.parse( text ) ) );
  10930. }, onProgress, onError );
  10931. },
  10932. setTextures: function ( value ) {
  10933. this.textures = value;
  10934. },
  10935. getTexture: function ( name ) {
  10936. var textures = this.textures;
  10937. if ( textures[ name ] === undefined ) {
  10938. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  10939. }
  10940. return textures[ name ];
  10941. },
  10942. parse: function ( json ) {
  10943. var material = new THREE[ json.type ];
  10944. material.uuid = json.uuid;
  10945. if ( json.name !== undefined ) material.name = json.name;
  10946. if ( json.color !== undefined ) material.color.setHex( json.color );
  10947. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  10948. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  10949. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  10950. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  10951. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  10952. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  10953. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  10954. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  10955. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  10956. if ( json.shading !== undefined ) material.shading = json.shading;
  10957. if ( json.blending !== undefined ) material.blending = json.blending;
  10958. if ( json.side !== undefined ) material.side = json.side;
  10959. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  10960. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  10961. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  10962. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  10963. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  10964. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  10965. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  10966. // for PointsMaterial
  10967. if ( json.size !== undefined ) material.size = json.size;
  10968. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  10969. // maps
  10970. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  10971. if ( json.alphaMap !== undefined ) {
  10972. material.alphaMap = this.getTexture( json.alphaMap );
  10973. material.transparent = true;
  10974. }
  10975. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  10976. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  10977. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  10978. if ( json.normalScale !== undefined ) {
  10979. var normalScale = json.normalScale;
  10980. if ( Array.isArray( normalScale ) === false ) {
  10981. // Blender exporter used to export a scalar. See #7459
  10982. normalScale = [ normalScale, normalScale ];
  10983. }
  10984. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  10985. }
  10986. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  10987. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  10988. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  10989. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  10990. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  10991. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  10992. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  10993. if ( json.envMap !== undefined ) {
  10994. material.envMap = this.getTexture( json.envMap );
  10995. material.combine = THREE.MultiplyOperation;
  10996. }
  10997. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  10998. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  10999. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11000. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11001. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11002. // MeshFaceMaterial
  11003. if ( json.materials !== undefined ) {
  11004. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11005. material.materials.push( this.parse( json.materials[ i ] ) );
  11006. }
  11007. }
  11008. return material;
  11009. }
  11010. };
  11011. // File:src/loaders/ObjectLoader.js
  11012. /**
  11013. * @author mrdoob / http://mrdoob.com/
  11014. */
  11015. THREE.ObjectLoader = function ( manager ) {
  11016. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11017. this.texturePath = '';
  11018. };
  11019. THREE.ObjectLoader.prototype = {
  11020. constructor: THREE.ObjectLoader,
  11021. load: function ( url, onLoad, onProgress, onError ) {
  11022. if ( this.texturePath === '' ) {
  11023. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11024. }
  11025. var scope = this;
  11026. var loader = new THREE.XHRLoader( scope.manager );
  11027. loader.load( url, function ( text ) {
  11028. scope.parse( JSON.parse( text ), onLoad );
  11029. }, onProgress, onError );
  11030. },
  11031. setTexturePath: function ( value ) {
  11032. this.texturePath = value;
  11033. },
  11034. setCrossOrigin: function ( value ) {
  11035. this.crossOrigin = value;
  11036. },
  11037. parse: function ( json, onLoad ) {
  11038. var geometries = this.parseGeometries( json.geometries );
  11039. var images = this.parseImages( json.images, function () {
  11040. if ( onLoad !== undefined ) onLoad( object );
  11041. } );
  11042. var textures = this.parseTextures( json.textures, images );
  11043. var materials = this.parseMaterials( json.materials, textures );
  11044. var object = this.parseObject( json.object, geometries, materials );
  11045. if ( json.animations ) {
  11046. object.animations = this.parseAnimations( json.animations );
  11047. }
  11048. if ( json.images === undefined || json.images.length === 0 ) {
  11049. if ( onLoad !== undefined ) onLoad( object );
  11050. }
  11051. return object;
  11052. },
  11053. parseGeometries: function ( json ) {
  11054. var geometries = {};
  11055. if ( json !== undefined ) {
  11056. var geometryLoader = new THREE.JSONLoader();
  11057. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11058. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11059. var geometry;
  11060. var data = json[ i ];
  11061. switch ( data.type ) {
  11062. case 'PlaneGeometry':
  11063. case 'PlaneBufferGeometry':
  11064. geometry = new THREE[ data.type ](
  11065. data.width,
  11066. data.height,
  11067. data.widthSegments,
  11068. data.heightSegments
  11069. );
  11070. break;
  11071. case 'BoxGeometry':
  11072. case 'CubeGeometry': // backwards compatible
  11073. geometry = new THREE.BoxGeometry(
  11074. data.width,
  11075. data.height,
  11076. data.depth,
  11077. data.widthSegments,
  11078. data.heightSegments,
  11079. data.depthSegments
  11080. );
  11081. break;
  11082. case 'CircleBufferGeometry':
  11083. geometry = new THREE.CircleBufferGeometry(
  11084. data.radius,
  11085. data.segments,
  11086. data.thetaStart,
  11087. data.thetaLength
  11088. );
  11089. break;
  11090. case 'CircleGeometry':
  11091. geometry = new THREE.CircleGeometry(
  11092. data.radius,
  11093. data.segments,
  11094. data.thetaStart,
  11095. data.thetaLength
  11096. );
  11097. break;
  11098. case 'CylinderGeometry':
  11099. geometry = new THREE.CylinderGeometry(
  11100. data.radiusTop,
  11101. data.radiusBottom,
  11102. data.height,
  11103. data.radialSegments,
  11104. data.heightSegments,
  11105. data.openEnded,
  11106. data.thetaStart,
  11107. data.thetaLength
  11108. );
  11109. break;
  11110. case 'SphereGeometry':
  11111. geometry = new THREE.SphereGeometry(
  11112. data.radius,
  11113. data.widthSegments,
  11114. data.heightSegments,
  11115. data.phiStart,
  11116. data.phiLength,
  11117. data.thetaStart,
  11118. data.thetaLength
  11119. );
  11120. break;
  11121. case 'SphereBufferGeometry':
  11122. geometry = new THREE.SphereBufferGeometry(
  11123. data.radius,
  11124. data.widthSegments,
  11125. data.heightSegments,
  11126. data.phiStart,
  11127. data.phiLength,
  11128. data.thetaStart,
  11129. data.thetaLength
  11130. );
  11131. break;
  11132. case 'DodecahedronGeometry':
  11133. geometry = new THREE.DodecahedronGeometry(
  11134. data.radius,
  11135. data.detail
  11136. );
  11137. break;
  11138. case 'IcosahedronGeometry':
  11139. geometry = new THREE.IcosahedronGeometry(
  11140. data.radius,
  11141. data.detail
  11142. );
  11143. break;
  11144. case 'OctahedronGeometry':
  11145. geometry = new THREE.OctahedronGeometry(
  11146. data.radius,
  11147. data.detail
  11148. );
  11149. break;
  11150. case 'TetrahedronGeometry':
  11151. geometry = new THREE.TetrahedronGeometry(
  11152. data.radius,
  11153. data.detail
  11154. );
  11155. break;
  11156. case 'RingGeometry':
  11157. geometry = new THREE.RingGeometry(
  11158. data.innerRadius,
  11159. data.outerRadius,
  11160. data.thetaSegments,
  11161. data.phiSegments,
  11162. data.thetaStart,
  11163. data.thetaLength
  11164. );
  11165. break;
  11166. case 'TorusGeometry':
  11167. geometry = new THREE.TorusGeometry(
  11168. data.radius,
  11169. data.tube,
  11170. data.radialSegments,
  11171. data.tubularSegments,
  11172. data.arc
  11173. );
  11174. break;
  11175. case 'TorusKnotGeometry':
  11176. geometry = new THREE.TorusKnotGeometry(
  11177. data.radius,
  11178. data.tube,
  11179. data.radialSegments,
  11180. data.tubularSegments,
  11181. data.p,
  11182. data.q,
  11183. data.heightScale
  11184. );
  11185. break;
  11186. case 'BufferGeometry':
  11187. geometry = bufferGeometryLoader.parse( data );
  11188. break;
  11189. case 'Geometry':
  11190. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11191. break;
  11192. default:
  11193. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11194. continue;
  11195. }
  11196. geometry.uuid = data.uuid;
  11197. if ( data.name !== undefined ) geometry.name = data.name;
  11198. geometries[ data.uuid ] = geometry;
  11199. }
  11200. }
  11201. return geometries;
  11202. },
  11203. parseMaterials: function ( json, textures ) {
  11204. var materials = {};
  11205. if ( json !== undefined ) {
  11206. var loader = new THREE.MaterialLoader();
  11207. loader.setTextures( textures );
  11208. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11209. var material = loader.parse( json[ i ] );
  11210. materials[ material.uuid ] = material;
  11211. }
  11212. }
  11213. return materials;
  11214. },
  11215. parseAnimations: function ( json ) {
  11216. var animations = [];
  11217. for ( var i = 0; i < json.length; i ++ ) {
  11218. var clip = THREE.AnimationClip.parse( json[ i ] );
  11219. animations.push( clip );
  11220. }
  11221. return animations;
  11222. },
  11223. parseImages: function ( json, onLoad ) {
  11224. var scope = this;
  11225. var images = {};
  11226. function loadImage( url ) {
  11227. scope.manager.itemStart( url );
  11228. return loader.load( url, function () {
  11229. scope.manager.itemEnd( url );
  11230. } );
  11231. }
  11232. if ( json !== undefined && json.length > 0 ) {
  11233. var manager = new THREE.LoadingManager( onLoad );
  11234. var loader = new THREE.ImageLoader( manager );
  11235. loader.setCrossOrigin( this.crossOrigin );
  11236. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11237. var image = json[ i ];
  11238. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11239. images[ image.uuid ] = loadImage( path );
  11240. }
  11241. }
  11242. return images;
  11243. },
  11244. parseTextures: function ( json, images ) {
  11245. function parseConstant( value ) {
  11246. if ( typeof( value ) === 'number' ) return value;
  11247. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11248. return THREE[ value ];
  11249. }
  11250. var textures = {};
  11251. if ( json !== undefined ) {
  11252. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11253. var data = json[ i ];
  11254. if ( data.image === undefined ) {
  11255. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11256. }
  11257. if ( images[ data.image ] === undefined ) {
  11258. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11259. }
  11260. var texture = new THREE.Texture( images[ data.image ] );
  11261. texture.needsUpdate = true;
  11262. texture.uuid = data.uuid;
  11263. if ( data.name !== undefined ) texture.name = data.name;
  11264. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11265. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11266. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11267. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11268. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11269. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11270. if ( Array.isArray( data.wrap ) ) {
  11271. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11272. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11273. }
  11274. textures[ data.uuid ] = texture;
  11275. }
  11276. }
  11277. return textures;
  11278. },
  11279. parseObject: function () {
  11280. var matrix = new THREE.Matrix4();
  11281. return function ( data, geometries, materials ) {
  11282. var object;
  11283. function getGeometry( name ) {
  11284. if ( geometries[ name ] === undefined ) {
  11285. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11286. }
  11287. return geometries[ name ];
  11288. }
  11289. function getMaterial( name ) {
  11290. if ( name === undefined ) return undefined;
  11291. if ( materials[ name ] === undefined ) {
  11292. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11293. }
  11294. return materials[ name ];
  11295. }
  11296. switch ( data.type ) {
  11297. case 'Scene':
  11298. object = new THREE.Scene();
  11299. break;
  11300. case 'PerspectiveCamera':
  11301. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11302. break;
  11303. case 'OrthographicCamera':
  11304. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11305. break;
  11306. case 'AmbientLight':
  11307. object = new THREE.AmbientLight( data.color, data.intensity );
  11308. break;
  11309. case 'DirectionalLight':
  11310. object = new THREE.DirectionalLight( data.color, data.intensity );
  11311. break;
  11312. case 'PointLight':
  11313. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11314. break;
  11315. case 'SpotLight':
  11316. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  11317. break;
  11318. case 'HemisphereLight':
  11319. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11320. break;
  11321. case 'Mesh':
  11322. var geometry = getGeometry( data.geometry );
  11323. var material = getMaterial( data.material );
  11324. if ( geometry.bones && geometry.bones.length > 0 ) {
  11325. object = new THREE.SkinnedMesh( geometry, material );
  11326. } else {
  11327. object = new THREE.Mesh( geometry, material );
  11328. }
  11329. break;
  11330. case 'LOD':
  11331. object = new THREE.LOD();
  11332. break;
  11333. case 'Line':
  11334. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11335. break;
  11336. case 'PointCloud':
  11337. case 'Points':
  11338. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11339. break;
  11340. case 'Sprite':
  11341. object = new THREE.Sprite( getMaterial( data.material ) );
  11342. break;
  11343. case 'Group':
  11344. object = new THREE.Group();
  11345. break;
  11346. default:
  11347. object = new THREE.Object3D();
  11348. }
  11349. object.uuid = data.uuid;
  11350. if ( data.name !== undefined ) object.name = data.name;
  11351. if ( data.matrix !== undefined ) {
  11352. matrix.fromArray( data.matrix );
  11353. matrix.decompose( object.position, object.quaternion, object.scale );
  11354. } else {
  11355. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11356. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11357. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11358. }
  11359. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11360. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11361. if ( data.visible !== undefined ) object.visible = data.visible;
  11362. if ( data.userData !== undefined ) object.userData = data.userData;
  11363. if ( data.children !== undefined ) {
  11364. for ( var child in data.children ) {
  11365. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11366. }
  11367. }
  11368. if ( data.type === 'LOD' ) {
  11369. var levels = data.levels;
  11370. for ( var l = 0; l < levels.length; l ++ ) {
  11371. var level = levels[ l ];
  11372. var child = object.getObjectByProperty( 'uuid', level.object );
  11373. if ( child !== undefined ) {
  11374. object.addLevel( child, level.distance );
  11375. }
  11376. }
  11377. }
  11378. return object;
  11379. }
  11380. }()
  11381. };
  11382. // File:src/loaders/TextureLoader.js
  11383. /**
  11384. * @author mrdoob / http://mrdoob.com/
  11385. */
  11386. THREE.TextureLoader = function ( manager ) {
  11387. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11388. };
  11389. THREE.TextureLoader.prototype = {
  11390. constructor: THREE.TextureLoader,
  11391. load: function ( url, onLoad, onProgress, onError ) {
  11392. var texture = new THREE.Texture();
  11393. var loader = new THREE.ImageLoader( this.manager );
  11394. loader.setCrossOrigin( this.crossOrigin );
  11395. loader.setPath( this.path );
  11396. loader.load( url, function ( image ) {
  11397. texture.image = image;
  11398. texture.needsUpdate = true;
  11399. if ( onLoad !== undefined ) {
  11400. onLoad( texture );
  11401. }
  11402. }, onProgress, onError );
  11403. return texture;
  11404. },
  11405. setCrossOrigin: function ( value ) {
  11406. this.crossOrigin = value;
  11407. },
  11408. setPath: function ( value ) {
  11409. this.path = value;
  11410. }
  11411. };
  11412. // File:src/loaders/CubeTextureLoader.js
  11413. /**
  11414. * @author mrdoob / http://mrdoob.com/
  11415. */
  11416. THREE.CubeTextureLoader = function ( manager ) {
  11417. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11418. };
  11419. THREE.CubeTextureLoader.prototype = {
  11420. constructor: THREE.CubeTextureLoader,
  11421. load: function ( urls, onLoad, onProgress, onError ) {
  11422. var texture = new THREE.CubeTexture( [] );
  11423. var loader = new THREE.ImageLoader();
  11424. loader.setCrossOrigin( this.crossOrigin );
  11425. loader.setPath( this.path );
  11426. var loaded = 0;
  11427. function loadTexture( i ) {
  11428. loader.load( urls[ i ], function ( image ) {
  11429. texture.images[ i ] = image;
  11430. loaded ++;
  11431. if ( loaded === 6 ) {
  11432. texture.needsUpdate = true;
  11433. if ( onLoad ) onLoad( texture );
  11434. }
  11435. }, undefined, onError );
  11436. }
  11437. for ( var i = 0; i < urls.length; ++ i ) {
  11438. loadTexture( i );
  11439. }
  11440. return texture;
  11441. },
  11442. setCrossOrigin: function ( value ) {
  11443. this.crossOrigin = value;
  11444. },
  11445. setPath: function ( value ) {
  11446. this.path = value;
  11447. }
  11448. };
  11449. // File:src/loaders/BinaryTextureLoader.js
  11450. /**
  11451. * @author Nikos M. / https://github.com/foo123/
  11452. *
  11453. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11454. */
  11455. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11456. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11457. // override in sub classes
  11458. this._parser = null;
  11459. };
  11460. THREE.BinaryTextureLoader.prototype = {
  11461. constructor: THREE.BinaryTextureLoader,
  11462. load: function ( url, onLoad, onProgress, onError ) {
  11463. var scope = this;
  11464. var texture = new THREE.DataTexture();
  11465. var loader = new THREE.XHRLoader( this.manager );
  11466. loader.setResponseType( 'arraybuffer' );
  11467. loader.load( url, function ( buffer ) {
  11468. var texData = scope._parser( buffer );
  11469. if ( ! texData ) return;
  11470. if ( undefined !== texData.image ) {
  11471. texture.image = texData.image;
  11472. } else if ( undefined !== texData.data ) {
  11473. texture.image.width = texData.width;
  11474. texture.image.height = texData.height;
  11475. texture.image.data = texData.data;
  11476. }
  11477. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11478. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11479. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11480. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11481. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11482. if ( undefined !== texData.format ) {
  11483. texture.format = texData.format;
  11484. }
  11485. if ( undefined !== texData.type ) {
  11486. texture.type = texData.type;
  11487. }
  11488. if ( undefined !== texData.mipmaps ) {
  11489. texture.mipmaps = texData.mipmaps;
  11490. }
  11491. if ( 1 === texData.mipmapCount ) {
  11492. texture.minFilter = THREE.LinearFilter;
  11493. }
  11494. texture.needsUpdate = true;
  11495. if ( onLoad ) onLoad( texture, texData );
  11496. }, onProgress, onError );
  11497. return texture;
  11498. }
  11499. };
  11500. // File:src/loaders/CompressedTextureLoader.js
  11501. /**
  11502. * @author mrdoob / http://mrdoob.com/
  11503. *
  11504. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11505. */
  11506. THREE.CompressedTextureLoader = function ( manager ) {
  11507. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11508. // override in sub classes
  11509. this._parser = null;
  11510. };
  11511. THREE.CompressedTextureLoader.prototype = {
  11512. constructor: THREE.CompressedTextureLoader,
  11513. load: function ( url, onLoad, onProgress, onError ) {
  11514. var scope = this;
  11515. var images = [];
  11516. var texture = new THREE.CompressedTexture();
  11517. texture.image = images;
  11518. var loader = new THREE.XHRLoader( this.manager );
  11519. loader.setPath( this.path );
  11520. loader.setResponseType( 'arraybuffer' );
  11521. function loadTexture( i ) {
  11522. loader.load( url[ i ], function ( buffer ) {
  11523. var texDatas = scope._parser( buffer, true );
  11524. images[ i ] = {
  11525. width: texDatas.width,
  11526. height: texDatas.height,
  11527. format: texDatas.format,
  11528. mipmaps: texDatas.mipmaps
  11529. };
  11530. loaded += 1;
  11531. if ( loaded === 6 ) {
  11532. if ( texDatas.mipmapCount === 1 )
  11533. texture.minFilter = THREE.LinearFilter;
  11534. texture.format = texDatas.format;
  11535. texture.needsUpdate = true;
  11536. if ( onLoad ) onLoad( texture );
  11537. }
  11538. }, onProgress, onError );
  11539. }
  11540. if ( Array.isArray( url ) ) {
  11541. var loaded = 0;
  11542. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11543. loadTexture( i );
  11544. }
  11545. } else {
  11546. // compressed cubemap texture stored in a single DDS file
  11547. loader.load( url, function ( buffer ) {
  11548. var texDatas = scope._parser( buffer, true );
  11549. if ( texDatas.isCubemap ) {
  11550. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11551. for ( var f = 0; f < faces; f ++ ) {
  11552. images[ f ] = { mipmaps : [] };
  11553. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11554. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11555. images[ f ].format = texDatas.format;
  11556. images[ f ].width = texDatas.width;
  11557. images[ f ].height = texDatas.height;
  11558. }
  11559. }
  11560. } else {
  11561. texture.image.width = texDatas.width;
  11562. texture.image.height = texDatas.height;
  11563. texture.mipmaps = texDatas.mipmaps;
  11564. }
  11565. if ( texDatas.mipmapCount === 1 ) {
  11566. texture.minFilter = THREE.LinearFilter;
  11567. }
  11568. texture.format = texDatas.format;
  11569. texture.needsUpdate = true;
  11570. if ( onLoad ) onLoad( texture );
  11571. }, onProgress, onError );
  11572. }
  11573. return texture;
  11574. },
  11575. setPath: function ( value ) {
  11576. this.path = value;
  11577. }
  11578. };
  11579. // File:src/materials/Material.js
  11580. /**
  11581. * @author mrdoob / http://mrdoob.com/
  11582. * @author alteredq / http://alteredqualia.com/
  11583. */
  11584. THREE.Material = function () {
  11585. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11586. this.uuid = THREE.Math.generateUUID();
  11587. this.name = '';
  11588. this.type = 'Material';
  11589. this.side = THREE.FrontSide;
  11590. this.opacity = 1;
  11591. this.transparent = false;
  11592. this.blending = THREE.NormalBlending;
  11593. this.blendSrc = THREE.SrcAlphaFactor;
  11594. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11595. this.blendEquation = THREE.AddEquation;
  11596. this.blendSrcAlpha = null;
  11597. this.blendDstAlpha = null;
  11598. this.blendEquationAlpha = null;
  11599. this.depthFunc = THREE.LessEqualDepth;
  11600. this.depthTest = true;
  11601. this.depthWrite = true;
  11602. this.colorWrite = true;
  11603. this.precision = null; // override the renderer's default precision for this material
  11604. this.polygonOffset = false;
  11605. this.polygonOffsetFactor = 0;
  11606. this.polygonOffsetUnits = 0;
  11607. this.alphaTest = 0;
  11608. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11609. this.visible = true;
  11610. this._needsUpdate = true;
  11611. };
  11612. THREE.Material.prototype = {
  11613. constructor: THREE.Material,
  11614. get needsUpdate () {
  11615. return this._needsUpdate;
  11616. },
  11617. set needsUpdate ( value ) {
  11618. if ( value === true ) this.update();
  11619. this._needsUpdate = value;
  11620. },
  11621. setValues: function ( values ) {
  11622. if ( values === undefined ) return;
  11623. for ( var key in values ) {
  11624. var newValue = values[ key ];
  11625. if ( newValue === undefined ) {
  11626. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11627. continue;
  11628. }
  11629. var currentValue = this[ key ];
  11630. if ( currentValue === undefined ) {
  11631. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11632. continue;
  11633. }
  11634. if ( currentValue instanceof THREE.Color ) {
  11635. currentValue.set( newValue );
  11636. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11637. currentValue.copy( newValue );
  11638. } else if ( key === 'overdraw' ) {
  11639. // ensure overdraw is backwards-compatible with legacy boolean type
  11640. this[ key ] = Number( newValue );
  11641. } else {
  11642. this[ key ] = newValue;
  11643. }
  11644. }
  11645. },
  11646. toJSON: function ( meta ) {
  11647. var isRoot = meta === undefined;
  11648. if ( isRoot ) {
  11649. meta = {
  11650. textures: {},
  11651. images: {}
  11652. };
  11653. }
  11654. var data = {
  11655. metadata: {
  11656. version: 4.4,
  11657. type: 'Material',
  11658. generator: 'Material.toJSON'
  11659. }
  11660. };
  11661. // standard Material serialization
  11662. data.uuid = this.uuid;
  11663. data.type = this.type;
  11664. if ( this.name !== '' ) data.name = this.name;
  11665. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11666. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11667. if ( this.metalness > 0 ) data.metalness = this.metalness;
  11668. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11669. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11670. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11671. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11672. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11673. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11674. if ( this.bumpMap instanceof THREE.Texture ) {
  11675. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11676. data.bumpScale = this.bumpScale;
  11677. }
  11678. if ( this.normalMap instanceof THREE.Texture ) {
  11679. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11680. data.normalScale = this.normalScale.toArray();
  11681. }
  11682. if ( this.displacementMap instanceof THREE.Texture ) {
  11683. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11684. data.displacementScale = this.displacementScale;
  11685. data.displacementBias = this.displacementBias;
  11686. }
  11687. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11688. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11689. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11690. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11691. if ( this.envMap instanceof THREE.Texture ) {
  11692. data.envMap = this.envMap.toJSON( meta ).uuid;
  11693. data.reflectivity = this.reflectivity; // Scale behind envMap
  11694. }
  11695. if ( this.size !== undefined ) data.size = this.size;
  11696. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11697. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11698. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11699. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11700. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11701. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11702. if ( this.transparent === true ) data.transparent = this.transparent;
  11703. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11704. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11705. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11706. // TODO: Copied from Object3D.toJSON
  11707. function extractFromCache ( cache ) {
  11708. var values = [];
  11709. for ( var key in cache ) {
  11710. var data = cache[ key ];
  11711. delete data.metadata;
  11712. values.push( data );
  11713. }
  11714. return values;
  11715. }
  11716. if ( isRoot ) {
  11717. var textures = extractFromCache( meta.textures );
  11718. var images = extractFromCache( meta.images );
  11719. if ( textures.length > 0 ) data.textures = textures;
  11720. if ( images.length > 0 ) data.images = images;
  11721. }
  11722. return data;
  11723. },
  11724. clone: function () {
  11725. return new this.constructor().copy( this );
  11726. },
  11727. copy: function ( source ) {
  11728. this.name = source.name;
  11729. this.side = source.side;
  11730. this.opacity = source.opacity;
  11731. this.transparent = source.transparent;
  11732. this.blending = source.blending;
  11733. this.blendSrc = source.blendSrc;
  11734. this.blendDst = source.blendDst;
  11735. this.blendEquation = source.blendEquation;
  11736. this.blendSrcAlpha = source.blendSrcAlpha;
  11737. this.blendDstAlpha = source.blendDstAlpha;
  11738. this.blendEquationAlpha = source.blendEquationAlpha;
  11739. this.depthFunc = source.depthFunc;
  11740. this.depthTest = source.depthTest;
  11741. this.depthWrite = source.depthWrite;
  11742. this.precision = source.precision;
  11743. this.polygonOffset = source.polygonOffset;
  11744. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11745. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11746. this.alphaTest = source.alphaTest;
  11747. this.overdraw = source.overdraw;
  11748. this.visible = source.visible;
  11749. return this;
  11750. },
  11751. update: function () {
  11752. this.dispatchEvent( { type: 'update' } );
  11753. },
  11754. dispose: function () {
  11755. this.dispatchEvent( { type: 'dispose' } );
  11756. }
  11757. };
  11758. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11759. THREE.MaterialIdCount = 0;
  11760. // File:src/materials/LineBasicMaterial.js
  11761. /**
  11762. * @author mrdoob / http://mrdoob.com/
  11763. * @author alteredq / http://alteredqualia.com/
  11764. *
  11765. * parameters = {
  11766. * color: <hex>,
  11767. * opacity: <float>,
  11768. *
  11769. * blending: THREE.NormalBlending,
  11770. * depthTest: <bool>,
  11771. * depthWrite: <bool>,
  11772. *
  11773. * linewidth: <float>,
  11774. * linecap: "round",
  11775. * linejoin: "round",
  11776. *
  11777. * vertexColors: <bool>
  11778. *
  11779. * fog: <bool>
  11780. * }
  11781. */
  11782. THREE.LineBasicMaterial = function ( parameters ) {
  11783. THREE.Material.call( this );
  11784. this.type = 'LineBasicMaterial';
  11785. this.color = new THREE.Color( 0xffffff );
  11786. this.linewidth = 1;
  11787. this.linecap = 'round';
  11788. this.linejoin = 'round';
  11789. this.vertexColors = THREE.NoColors;
  11790. this.fog = true;
  11791. this.setValues( parameters );
  11792. };
  11793. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11794. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11795. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11796. THREE.Material.prototype.copy.call( this, source );
  11797. this.color.copy( source.color );
  11798. this.linewidth = source.linewidth;
  11799. this.linecap = source.linecap;
  11800. this.linejoin = source.linejoin;
  11801. this.vertexColors = source.vertexColors;
  11802. this.fog = source.fog;
  11803. return this;
  11804. };
  11805. // File:src/materials/LineDashedMaterial.js
  11806. /**
  11807. * @author alteredq / http://alteredqualia.com/
  11808. *
  11809. * parameters = {
  11810. * color: <hex>,
  11811. * opacity: <float>,
  11812. *
  11813. * blending: THREE.NormalBlending,
  11814. * depthTest: <bool>,
  11815. * depthWrite: <bool>,
  11816. *
  11817. * linewidth: <float>,
  11818. *
  11819. * scale: <float>,
  11820. * dashSize: <float>,
  11821. * gapSize: <float>,
  11822. *
  11823. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  11824. *
  11825. * fog: <bool>
  11826. * }
  11827. */
  11828. THREE.LineDashedMaterial = function ( parameters ) {
  11829. THREE.Material.call( this );
  11830. this.type = 'LineDashedMaterial';
  11831. this.color = new THREE.Color( 0xffffff );
  11832. this.linewidth = 1;
  11833. this.scale = 1;
  11834. this.dashSize = 3;
  11835. this.gapSize = 1;
  11836. this.vertexColors = THREE.NoColors;
  11837. this.fog = true;
  11838. this.setValues( parameters );
  11839. };
  11840. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  11841. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  11842. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  11843. THREE.Material.prototype.copy.call( this, source );
  11844. this.color.copy( source.color );
  11845. this.linewidth = source.linewidth;
  11846. this.scale = source.scale;
  11847. this.dashSize = source.dashSize;
  11848. this.gapSize = source.gapSize;
  11849. this.vertexColors = source.vertexColors;
  11850. this.fog = source.fog;
  11851. return this;
  11852. };
  11853. // File:src/materials/MeshBasicMaterial.js
  11854. /**
  11855. * @author mrdoob / http://mrdoob.com/
  11856. * @author alteredq / http://alteredqualia.com/
  11857. *
  11858. * parameters = {
  11859. * color: <hex>,
  11860. * opacity: <float>,
  11861. * map: new THREE.Texture( <Image> ),
  11862. *
  11863. * aoMap: new THREE.Texture( <Image> ),
  11864. * aoMapIntensity: <float>
  11865. *
  11866. * specularMap: new THREE.Texture( <Image> ),
  11867. *
  11868. * alphaMap: new THREE.Texture( <Image> ),
  11869. *
  11870. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11871. * combine: THREE.Multiply,
  11872. * reflectivity: <float>,
  11873. * refractionRatio: <float>,
  11874. *
  11875. * shading: THREE.SmoothShading,
  11876. * blending: THREE.NormalBlending,
  11877. * depthTest: <bool>,
  11878. * depthWrite: <bool>,
  11879. *
  11880. * wireframe: <boolean>,
  11881. * wireframeLinewidth: <float>,
  11882. *
  11883. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11884. *
  11885. * skinning: <bool>,
  11886. * morphTargets: <bool>,
  11887. *
  11888. * fog: <bool>
  11889. * }
  11890. */
  11891. THREE.MeshBasicMaterial = function ( parameters ) {
  11892. THREE.Material.call( this );
  11893. this.type = 'MeshBasicMaterial';
  11894. this.color = new THREE.Color( 0xffffff ); // emissive
  11895. this.map = null;
  11896. this.aoMap = null;
  11897. this.aoMapIntensity = 1.0;
  11898. this.specularMap = null;
  11899. this.alphaMap = null;
  11900. this.envMap = null;
  11901. this.combine = THREE.MultiplyOperation;
  11902. this.reflectivity = 1;
  11903. this.refractionRatio = 0.98;
  11904. this.fog = true;
  11905. this.shading = THREE.SmoothShading;
  11906. this.wireframe = false;
  11907. this.wireframeLinewidth = 1;
  11908. this.wireframeLinecap = 'round';
  11909. this.wireframeLinejoin = 'round';
  11910. this.vertexColors = THREE.NoColors;
  11911. this.skinning = false;
  11912. this.morphTargets = false;
  11913. this.setValues( parameters );
  11914. };
  11915. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11916. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  11917. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  11918. THREE.Material.prototype.copy.call( this, source );
  11919. this.color.copy( source.color );
  11920. this.map = source.map;
  11921. this.aoMap = source.aoMap;
  11922. this.aoMapIntensity = source.aoMapIntensity;
  11923. this.specularMap = source.specularMap;
  11924. this.alphaMap = source.alphaMap;
  11925. this.envMap = source.envMap;
  11926. this.combine = source.combine;
  11927. this.reflectivity = source.reflectivity;
  11928. this.refractionRatio = source.refractionRatio;
  11929. this.fog = source.fog;
  11930. this.shading = source.shading;
  11931. this.wireframe = source.wireframe;
  11932. this.wireframeLinewidth = source.wireframeLinewidth;
  11933. this.wireframeLinecap = source.wireframeLinecap;
  11934. this.wireframeLinejoin = source.wireframeLinejoin;
  11935. this.vertexColors = source.vertexColors;
  11936. this.skinning = source.skinning;
  11937. this.morphTargets = source.morphTargets;
  11938. return this;
  11939. };
  11940. // File:src/materials/MeshLambertMaterial.js
  11941. /**
  11942. * @author mrdoob / http://mrdoob.com/
  11943. * @author alteredq / http://alteredqualia.com/
  11944. *
  11945. * parameters = {
  11946. * color: <hex>,
  11947. * emissive: <hex>,
  11948. * opacity: <float>,
  11949. *
  11950. * map: new THREE.Texture( <Image> ),
  11951. *
  11952. * specularMap: new THREE.Texture( <Image> ),
  11953. *
  11954. * alphaMap: new THREE.Texture( <Image> ),
  11955. *
  11956. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11957. * combine: THREE.Multiply,
  11958. * reflectivity: <float>,
  11959. * refractionRatio: <float>,
  11960. *
  11961. * blending: THREE.NormalBlending,
  11962. * depthTest: <bool>,
  11963. * depthWrite: <bool>,
  11964. *
  11965. * wireframe: <boolean>,
  11966. * wireframeLinewidth: <float>,
  11967. *
  11968. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11969. *
  11970. * skinning: <bool>,
  11971. * morphTargets: <bool>,
  11972. * morphNormals: <bool>,
  11973. *
  11974. * fog: <bool>
  11975. * }
  11976. */
  11977. THREE.MeshLambertMaterial = function ( parameters ) {
  11978. THREE.Material.call( this );
  11979. this.type = 'MeshLambertMaterial';
  11980. this.color = new THREE.Color( 0xffffff ); // diffuse
  11981. this.emissive = new THREE.Color( 0x000000 );
  11982. this.map = null;
  11983. this.specularMap = null;
  11984. this.alphaMap = null;
  11985. this.envMap = null;
  11986. this.combine = THREE.MultiplyOperation;
  11987. this.reflectivity = 1;
  11988. this.refractionRatio = 0.98;
  11989. this.fog = true;
  11990. this.wireframe = false;
  11991. this.wireframeLinewidth = 1;
  11992. this.wireframeLinecap = 'round';
  11993. this.wireframeLinejoin = 'round';
  11994. this.vertexColors = THREE.NoColors;
  11995. this.skinning = false;
  11996. this.morphTargets = false;
  11997. this.morphNormals = false;
  11998. this.setValues( parameters );
  11999. };
  12000. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12001. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12002. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12003. THREE.Material.prototype.copy.call( this, source );
  12004. this.color.copy( source.color );
  12005. this.emissive.copy( source.emissive );
  12006. this.map = source.map;
  12007. this.specularMap = source.specularMap;
  12008. this.alphaMap = source.alphaMap;
  12009. this.envMap = source.envMap;
  12010. this.combine = source.combine;
  12011. this.reflectivity = source.reflectivity;
  12012. this.refractionRatio = source.refractionRatio;
  12013. this.fog = source.fog;
  12014. this.wireframe = source.wireframe;
  12015. this.wireframeLinewidth = source.wireframeLinewidth;
  12016. this.wireframeLinecap = source.wireframeLinecap;
  12017. this.wireframeLinejoin = source.wireframeLinejoin;
  12018. this.vertexColors = source.vertexColors;
  12019. this.skinning = source.skinning;
  12020. this.morphTargets = source.morphTargets;
  12021. this.morphNormals = source.morphNormals;
  12022. return this;
  12023. };
  12024. // File:src/materials/MeshPhongMaterial.js
  12025. /**
  12026. * @author mrdoob / http://mrdoob.com/
  12027. * @author alteredq / http://alteredqualia.com/
  12028. *
  12029. * parameters = {
  12030. * color: <hex>,
  12031. * emissive: <hex>,
  12032. * specular: <hex>,
  12033. * shininess: <float>,
  12034. * opacity: <float>,
  12035. *
  12036. * map: new THREE.Texture( <Image> ),
  12037. *
  12038. * lightMap: new THREE.Texture( <Image> ),
  12039. * lightMapIntensity: <float>
  12040. *
  12041. * aoMap: new THREE.Texture( <Image> ),
  12042. * aoMapIntensity: <float>
  12043. *
  12044. * emissiveMap: new THREE.Texture( <Image> ),
  12045. *
  12046. * bumpMap: new THREE.Texture( <Image> ),
  12047. * bumpScale: <float>,
  12048. *
  12049. * normalMap: new THREE.Texture( <Image> ),
  12050. * normalScale: <Vector2>,
  12051. *
  12052. * displacementMap: new THREE.Texture( <Image> ),
  12053. * displacementScale: <float>,
  12054. * displacementBias: <float>,
  12055. *
  12056. * specularMap: new THREE.Texture( <Image> ),
  12057. *
  12058. * alphaMap: new THREE.Texture( <Image> ),
  12059. *
  12060. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12061. * combine: THREE.Multiply,
  12062. * reflectivity: <float>,
  12063. * refractionRatio: <float>,
  12064. *
  12065. * shading: THREE.SmoothShading,
  12066. * blending: THREE.NormalBlending,
  12067. * depthTest: <bool>,
  12068. * depthWrite: <bool>,
  12069. *
  12070. * wireframe: <boolean>,
  12071. * wireframeLinewidth: <float>,
  12072. *
  12073. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12074. *
  12075. * skinning: <bool>,
  12076. * morphTargets: <bool>,
  12077. * morphNormals: <bool>,
  12078. *
  12079. * fog: <bool>
  12080. * }
  12081. */
  12082. THREE.MeshPhongMaterial = function ( parameters ) {
  12083. THREE.Material.call( this );
  12084. this.type = 'MeshPhongMaterial';
  12085. this.color = new THREE.Color( 0xffffff ); // diffuse
  12086. this.emissive = new THREE.Color( 0x000000 );
  12087. this.specular = new THREE.Color( 0x111111 );
  12088. this.shininess = 30;
  12089. this.map = null;
  12090. this.lightMap = null;
  12091. this.lightMapIntensity = 1.0;
  12092. this.aoMap = null;
  12093. this.aoMapIntensity = 1.0;
  12094. this.emissiveMap = null;
  12095. this.bumpMap = null;
  12096. this.bumpScale = 1;
  12097. this.normalMap = null;
  12098. this.normalScale = new THREE.Vector2( 1, 1 );
  12099. this.displacementMap = null;
  12100. this.displacementScale = 1;
  12101. this.displacementBias = 0;
  12102. this.specularMap = null;
  12103. this.alphaMap = null;
  12104. this.envMap = null;
  12105. this.combine = THREE.MultiplyOperation;
  12106. this.reflectivity = 1;
  12107. this.refractionRatio = 0.98;
  12108. this.fog = true;
  12109. this.shading = THREE.SmoothShading;
  12110. this.wireframe = false;
  12111. this.wireframeLinewidth = 1;
  12112. this.wireframeLinecap = 'round';
  12113. this.wireframeLinejoin = 'round';
  12114. this.vertexColors = THREE.NoColors;
  12115. this.skinning = false;
  12116. this.morphTargets = false;
  12117. this.morphNormals = false;
  12118. this.setValues( parameters );
  12119. };
  12120. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12121. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12122. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12123. THREE.Material.prototype.copy.call( this, source );
  12124. this.color.copy( source.color );
  12125. this.emissive.copy( source.emissive );
  12126. this.specular.copy( source.specular );
  12127. this.shininess = source.shininess;
  12128. this.map = source.map;
  12129. this.lightMap = source.lightMap;
  12130. this.lightMapIntensity = source.lightMapIntensity;
  12131. this.aoMap = source.aoMap;
  12132. this.aoMapIntensity = source.aoMapIntensity;
  12133. this.emissiveMap = source.emissiveMap;
  12134. this.bumpMap = source.bumpMap;
  12135. this.bumpScale = source.bumpScale;
  12136. this.normalMap = source.normalMap;
  12137. this.normalScale.copy( source.normalScale );
  12138. this.displacementMap = source.displacementMap;
  12139. this.displacementScale = source.displacementScale;
  12140. this.displacementBias = source.displacementBias;
  12141. this.specularMap = source.specularMap;
  12142. this.alphaMap = source.alphaMap;
  12143. this.envMap = source.envMap;
  12144. this.combine = source.combine;
  12145. this.reflectivity = source.reflectivity;
  12146. this.refractionRatio = source.refractionRatio;
  12147. this.fog = source.fog;
  12148. this.shading = source.shading;
  12149. this.wireframe = source.wireframe;
  12150. this.wireframeLinewidth = source.wireframeLinewidth;
  12151. this.wireframeLinecap = source.wireframeLinecap;
  12152. this.wireframeLinejoin = source.wireframeLinejoin;
  12153. this.vertexColors = source.vertexColors;
  12154. this.skinning = source.skinning;
  12155. this.morphTargets = source.morphTargets;
  12156. this.morphNormals = source.morphNormals;
  12157. return this;
  12158. };
  12159. // File:src/materials/MeshStandardMaterial.js
  12160. /**
  12161. * @author WestLangley / http://github.com/WestLangley
  12162. *
  12163. * parameters = {
  12164. * color: <hex>,
  12165. * roughness: <float>,
  12166. * metalness: <float>,
  12167. * emissive: <hex>,
  12168. * opacity: <float>,
  12169. *
  12170. * map: new THREE.Texture( <Image> ),
  12171. *
  12172. * lightMap: new THREE.Texture( <Image> ),
  12173. * lightMapIntensity: <float>
  12174. *
  12175. * aoMap: new THREE.Texture( <Image> ),
  12176. * aoMapIntensity: <float>
  12177. *
  12178. * emissiveMap: new THREE.Texture( <Image> ),
  12179. *
  12180. * bumpMap: new THREE.Texture( <Image> ),
  12181. * bumpScale: <float>,
  12182. *
  12183. * normalMap: new THREE.Texture( <Image> ),
  12184. * normalScale: <Vector2>,
  12185. *
  12186. * displacementMap: new THREE.Texture( <Image> ),
  12187. * displacementScale: <float>,
  12188. * displacementBias: <float>,
  12189. *
  12190. * roughnessMap: new THREE.Texture( <Image> ),
  12191. *
  12192. * metalnessMap: new THREE.Texture( <Image> ),
  12193. *
  12194. * alphaMap: new THREE.Texture( <Image> ),
  12195. *
  12196. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12197. * envMapIntensity: <float>
  12198. *
  12199. * refractionRatio: <float>,
  12200. *
  12201. * shading: THREE.SmoothShading,
  12202. * blending: THREE.NormalBlending,
  12203. * depthTest: <bool>,
  12204. * depthWrite: <bool>,
  12205. *
  12206. * wireframe: <boolean>,
  12207. * wireframeLinewidth: <float>,
  12208. *
  12209. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12210. *
  12211. * skinning: <bool>,
  12212. * morphTargets: <bool>,
  12213. * morphNormals: <bool>,
  12214. *
  12215. * fog: <bool>
  12216. * }
  12217. */
  12218. THREE.MeshStandardMaterial = function ( parameters ) {
  12219. THREE.Material.call( this );
  12220. this.type = 'MeshStandardMaterial';
  12221. this.color = new THREE.Color( 0xffffff ); // diffuse
  12222. this.roughness = 0.5;
  12223. this.metalness = 0.5;
  12224. this.emissive = new THREE.Color( 0x000000 );
  12225. this.map = null;
  12226. this.lightMap = null;
  12227. this.lightMapIntensity = 1.0;
  12228. this.aoMap = null;
  12229. this.aoMapIntensity = 1.0;
  12230. this.emissiveMap = null;
  12231. this.bumpMap = null;
  12232. this.bumpScale = 1;
  12233. this.normalMap = null;
  12234. this.normalScale = new THREE.Vector2( 1, 1 );
  12235. this.displacementMap = null;
  12236. this.displacementScale = 1;
  12237. this.displacementBias = 0;
  12238. this.roughnessMap = null;
  12239. this.metalnessMap = null;
  12240. this.alphaMap = null;
  12241. this.envMap = null;
  12242. this.envMapIntensity = 1.0;
  12243. this.refractionRatio = 0.98;
  12244. this.fog = true;
  12245. this.shading = THREE.SmoothShading;
  12246. this.wireframe = false;
  12247. this.wireframeLinewidth = 1;
  12248. this.wireframeLinecap = 'round';
  12249. this.wireframeLinejoin = 'round';
  12250. this.vertexColors = THREE.NoColors;
  12251. this.skinning = false;
  12252. this.morphTargets = false;
  12253. this.morphNormals = false;
  12254. this.setValues( parameters );
  12255. };
  12256. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12257. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12258. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12259. THREE.Material.prototype.copy.call( this, source );
  12260. this.color.copy( source.color );
  12261. this.roughness = source.roughness;
  12262. this.metalness = source.metalness;
  12263. this.emissive.copy( source.emissive );
  12264. this.map = source.map;
  12265. this.lightMap = source.lightMap;
  12266. this.lightMapIntensity = source.lightMapIntensity;
  12267. this.aoMap = source.aoMap;
  12268. this.aoMapIntensity = source.aoMapIntensity;
  12269. this.emissiveMap = source.emissiveMap;
  12270. this.bumpMap = source.bumpMap;
  12271. this.bumpScale = source.bumpScale;
  12272. this.normalMap = source.normalMap;
  12273. this.normalScale.copy( source.normalScale );
  12274. this.displacementMap = source.displacementMap;
  12275. this.displacementScale = source.displacementScale;
  12276. this.displacementBias = source.displacementBias;
  12277. this.roughnessMap = source.roughnessMap;
  12278. this.metalnessMap = source.metalnessMap;
  12279. this.alphaMap = source.alphaMap;
  12280. this.envMap = source.envMap;
  12281. this.envMapIntensity = source.envMapIntensity;
  12282. this.refractionRatio = source.refractionRatio;
  12283. this.fog = source.fog;
  12284. this.shading = source.shading;
  12285. this.wireframe = source.wireframe;
  12286. this.wireframeLinewidth = source.wireframeLinewidth;
  12287. this.wireframeLinecap = source.wireframeLinecap;
  12288. this.wireframeLinejoin = source.wireframeLinejoin;
  12289. this.vertexColors = source.vertexColors;
  12290. this.skinning = source.skinning;
  12291. this.morphTargets = source.morphTargets;
  12292. this.morphNormals = source.morphNormals;
  12293. return this;
  12294. };
  12295. // File:src/materials/MeshDepthMaterial.js
  12296. /**
  12297. * @author mrdoob / http://mrdoob.com/
  12298. * @author alteredq / http://alteredqualia.com/
  12299. *
  12300. * parameters = {
  12301. * opacity: <float>,
  12302. *
  12303. * blending: THREE.NormalBlending,
  12304. * depthTest: <bool>,
  12305. * depthWrite: <bool>,
  12306. *
  12307. * wireframe: <boolean>,
  12308. * wireframeLinewidth: <float>
  12309. * }
  12310. */
  12311. THREE.MeshDepthMaterial = function ( parameters ) {
  12312. THREE.Material.call( this );
  12313. this.type = 'MeshDepthMaterial';
  12314. this.morphTargets = false;
  12315. this.wireframe = false;
  12316. this.wireframeLinewidth = 1;
  12317. this.setValues( parameters );
  12318. };
  12319. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12320. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12321. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12322. THREE.Material.prototype.copy.call( this, source );
  12323. this.wireframe = source.wireframe;
  12324. this.wireframeLinewidth = source.wireframeLinewidth;
  12325. return this;
  12326. };
  12327. // File:src/materials/MeshNormalMaterial.js
  12328. /**
  12329. * @author mrdoob / http://mrdoob.com/
  12330. *
  12331. * parameters = {
  12332. * opacity: <float>,
  12333. *
  12334. * shading: THREE.FlatShading,
  12335. * blending: THREE.NormalBlending,
  12336. * depthTest: <bool>,
  12337. * depthWrite: <bool>,
  12338. *
  12339. * wireframe: <boolean>,
  12340. * wireframeLinewidth: <float>
  12341. * }
  12342. */
  12343. THREE.MeshNormalMaterial = function ( parameters ) {
  12344. THREE.Material.call( this, parameters );
  12345. this.type = 'MeshNormalMaterial';
  12346. this.wireframe = false;
  12347. this.wireframeLinewidth = 1;
  12348. this.morphTargets = false;
  12349. this.setValues( parameters );
  12350. };
  12351. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12352. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12353. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12354. THREE.Material.prototype.copy.call( this, source );
  12355. this.wireframe = source.wireframe;
  12356. this.wireframeLinewidth = source.wireframeLinewidth;
  12357. return this;
  12358. };
  12359. // File:src/materials/MultiMaterial.js
  12360. /**
  12361. * @author mrdoob / http://mrdoob.com/
  12362. */
  12363. THREE.MultiMaterial = function ( materials ) {
  12364. this.uuid = THREE.Math.generateUUID();
  12365. this.type = 'MultiMaterial';
  12366. this.materials = materials instanceof Array ? materials : [];
  12367. this.visible = true;
  12368. };
  12369. THREE.MultiMaterial.prototype = {
  12370. constructor: THREE.MultiMaterial,
  12371. toJSON: function ( meta ) {
  12372. var output = {
  12373. metadata: {
  12374. version: 4.2,
  12375. type: 'material',
  12376. generator: 'MaterialExporter'
  12377. },
  12378. uuid: this.uuid,
  12379. type: this.type,
  12380. materials: []
  12381. };
  12382. var materials = this.materials;
  12383. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12384. var material = materials[ i ].toJSON( meta );
  12385. delete material.metadata;
  12386. output.materials.push( material );
  12387. }
  12388. output.visible = this.visible;
  12389. return output;
  12390. },
  12391. clone: function () {
  12392. var material = new this.constructor();
  12393. for ( var i = 0; i < this.materials.length; i ++ ) {
  12394. material.materials.push( this.materials[ i ].clone() );
  12395. }
  12396. material.visible = this.visible;
  12397. return material;
  12398. }
  12399. };
  12400. // backwards compatibility
  12401. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  12402. // File:src/materials/PointsMaterial.js
  12403. /**
  12404. * @author mrdoob / http://mrdoob.com/
  12405. * @author alteredq / http://alteredqualia.com/
  12406. *
  12407. * parameters = {
  12408. * color: <hex>,
  12409. * opacity: <float>,
  12410. * map: new THREE.Texture( <Image> ),
  12411. *
  12412. * size: <float>,
  12413. * sizeAttenuation: <bool>,
  12414. *
  12415. * blending: THREE.NormalBlending,
  12416. * depthTest: <bool>,
  12417. * depthWrite: <bool>,
  12418. *
  12419. * vertexColors: <bool>,
  12420. *
  12421. * fog: <bool>
  12422. * }
  12423. */
  12424. THREE.PointsMaterial = function ( parameters ) {
  12425. THREE.Material.call( this );
  12426. this.type = 'PointsMaterial';
  12427. this.color = new THREE.Color( 0xffffff );
  12428. this.map = null;
  12429. this.size = 1;
  12430. this.sizeAttenuation = true;
  12431. this.vertexColors = THREE.NoColors;
  12432. this.fog = true;
  12433. this.setValues( parameters );
  12434. };
  12435. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12436. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12437. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12438. THREE.Material.prototype.copy.call( this, source );
  12439. this.color.copy( source.color );
  12440. this.map = source.map;
  12441. this.size = source.size;
  12442. this.sizeAttenuation = source.sizeAttenuation;
  12443. this.vertexColors = source.vertexColors;
  12444. this.fog = source.fog;
  12445. return this;
  12446. };
  12447. // File:src/materials/ShaderMaterial.js
  12448. /**
  12449. * @author alteredq / http://alteredqualia.com/
  12450. *
  12451. * parameters = {
  12452. * defines: { "label" : "value" },
  12453. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12454. *
  12455. * fragmentShader: <string>,
  12456. * vertexShader: <string>,
  12457. *
  12458. * shading: THREE.SmoothShading,
  12459. * blending: THREE.NormalBlending,
  12460. * depthTest: <bool>,
  12461. * depthWrite: <bool>,
  12462. *
  12463. * wireframe: <boolean>,
  12464. * wireframeLinewidth: <float>,
  12465. *
  12466. * lights: <bool>,
  12467. *
  12468. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12469. *
  12470. * skinning: <bool>,
  12471. * morphTargets: <bool>,
  12472. * morphNormals: <bool>,
  12473. *
  12474. * fog: <bool>
  12475. * }
  12476. */
  12477. THREE.ShaderMaterial = function ( parameters ) {
  12478. THREE.Material.call( this );
  12479. this.type = 'ShaderMaterial';
  12480. this.defines = {};
  12481. this.uniforms = {};
  12482. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12483. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12484. this.shading = THREE.SmoothShading;
  12485. this.linewidth = 1;
  12486. this.wireframe = false;
  12487. this.wireframeLinewidth = 1;
  12488. this.fog = false; // set to use scene fog
  12489. this.lights = false; // set to use scene lights
  12490. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12491. this.skinning = false; // set to use skinning attribute streams
  12492. this.morphTargets = false; // set to use morph targets
  12493. this.morphNormals = false; // set to use morph normals
  12494. this.extensions = {
  12495. derivatives: false, // set to use derivatives
  12496. fragDepth: false, // set to use fragment depth values
  12497. drawBuffers: false, // set to use draw buffers
  12498. shaderTextureLOD: false // set to use shader texture LOD
  12499. };
  12500. // When rendered geometry doesn't include these attributes but the material does,
  12501. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12502. this.defaultAttributeValues = {
  12503. 'color': [ 1, 1, 1 ],
  12504. 'uv': [ 0, 0 ],
  12505. 'uv2': [ 0, 0 ]
  12506. };
  12507. this.index0AttributeName = undefined;
  12508. if ( parameters !== undefined ) {
  12509. if ( parameters.attributes !== undefined ) {
  12510. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12511. }
  12512. this.setValues( parameters );
  12513. }
  12514. };
  12515. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12516. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12517. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12518. THREE.Material.prototype.copy.call( this, source );
  12519. this.fragmentShader = source.fragmentShader;
  12520. this.vertexShader = source.vertexShader;
  12521. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12522. this.attributes = source.attributes;
  12523. this.defines = source.defines;
  12524. this.shading = source.shading;
  12525. this.wireframe = source.wireframe;
  12526. this.wireframeLinewidth = source.wireframeLinewidth;
  12527. this.fog = source.fog;
  12528. this.lights = source.lights;
  12529. this.vertexColors = source.vertexColors;
  12530. this.skinning = source.skinning;
  12531. this.morphTargets = source.morphTargets;
  12532. this.morphNormals = source.morphNormals;
  12533. this.extensions = source.extensions;
  12534. return this;
  12535. };
  12536. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12537. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12538. data.uniforms = this.uniforms;
  12539. data.attributes = this.attributes;
  12540. data.vertexShader = this.vertexShader;
  12541. data.fragmentShader = this.fragmentShader;
  12542. return data;
  12543. };
  12544. // File:src/materials/RawShaderMaterial.js
  12545. /**
  12546. * @author mrdoob / http://mrdoob.com/
  12547. */
  12548. THREE.RawShaderMaterial = function ( parameters ) {
  12549. THREE.ShaderMaterial.call( this, parameters );
  12550. this.type = 'RawShaderMaterial';
  12551. };
  12552. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12553. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12554. // File:src/materials/SpriteMaterial.js
  12555. /**
  12556. * @author alteredq / http://alteredqualia.com/
  12557. *
  12558. * parameters = {
  12559. * color: <hex>,
  12560. * opacity: <float>,
  12561. * map: new THREE.Texture( <Image> ),
  12562. *
  12563. * blending: THREE.NormalBlending,
  12564. * depthTest: <bool>,
  12565. * depthWrite: <bool>,
  12566. *
  12567. * uvOffset: new THREE.Vector2(),
  12568. * uvScale: new THREE.Vector2(),
  12569. *
  12570. * fog: <bool>
  12571. * }
  12572. */
  12573. THREE.SpriteMaterial = function ( parameters ) {
  12574. THREE.Material.call( this );
  12575. this.type = 'SpriteMaterial';
  12576. this.color = new THREE.Color( 0xffffff );
  12577. this.map = null;
  12578. this.rotation = 0;
  12579. this.fog = false;
  12580. // set parameters
  12581. this.setValues( parameters );
  12582. };
  12583. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12584. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12585. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12586. THREE.Material.prototype.copy.call( this, source );
  12587. this.color.copy( source.color );
  12588. this.map = source.map;
  12589. this.rotation = source.rotation;
  12590. this.fog = source.fog;
  12591. return this;
  12592. };
  12593. // File:src/textures/Texture.js
  12594. /**
  12595. * @author mrdoob / http://mrdoob.com/
  12596. * @author alteredq / http://alteredqualia.com/
  12597. * @author szimek / https://github.com/szimek/
  12598. */
  12599. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12600. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12601. this.uuid = THREE.Math.generateUUID();
  12602. this.name = '';
  12603. this.sourceFile = '';
  12604. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12605. this.mipmaps = [];
  12606. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12607. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12608. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12609. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12610. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12611. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12612. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12613. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12614. this.offset = new THREE.Vector2( 0, 0 );
  12615. this.repeat = new THREE.Vector2( 1, 1 );
  12616. this.generateMipmaps = true;
  12617. this.premultiplyAlpha = false;
  12618. this.flipY = true;
  12619. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12620. this.version = 0;
  12621. this.onUpdate = null;
  12622. };
  12623. THREE.Texture.DEFAULT_IMAGE = undefined;
  12624. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12625. THREE.Texture.prototype = {
  12626. constructor: THREE.Texture,
  12627. set needsUpdate ( value ) {
  12628. if ( value === true ) this.version ++;
  12629. },
  12630. clone: function () {
  12631. return new this.constructor().copy( this );
  12632. },
  12633. copy: function ( source ) {
  12634. this.image = source.image;
  12635. this.mipmaps = source.mipmaps.slice( 0 );
  12636. this.mapping = source.mapping;
  12637. this.wrapS = source.wrapS;
  12638. this.wrapT = source.wrapT;
  12639. this.magFilter = source.magFilter;
  12640. this.minFilter = source.minFilter;
  12641. this.anisotropy = source.anisotropy;
  12642. this.format = source.format;
  12643. this.type = source.type;
  12644. this.offset.copy( source.offset );
  12645. this.repeat.copy( source.repeat );
  12646. this.generateMipmaps = source.generateMipmaps;
  12647. this.premultiplyAlpha = source.premultiplyAlpha;
  12648. this.flipY = source.flipY;
  12649. this.unpackAlignment = source.unpackAlignment;
  12650. return this;
  12651. },
  12652. toJSON: function ( meta ) {
  12653. if ( meta.textures[ this.uuid ] !== undefined ) {
  12654. return meta.textures[ this.uuid ];
  12655. }
  12656. function getDataURL( image ) {
  12657. var canvas;
  12658. if ( image.toDataURL !== undefined ) {
  12659. canvas = image;
  12660. } else {
  12661. canvas = document.createElement( 'canvas' );
  12662. canvas.width = image.width;
  12663. canvas.height = image.height;
  12664. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12665. }
  12666. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12667. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12668. } else {
  12669. return canvas.toDataURL( 'image/png' );
  12670. }
  12671. }
  12672. var output = {
  12673. metadata: {
  12674. version: 4.4,
  12675. type: 'Texture',
  12676. generator: 'Texture.toJSON'
  12677. },
  12678. uuid: this.uuid,
  12679. name: this.name,
  12680. mapping: this.mapping,
  12681. repeat: [ this.repeat.x, this.repeat.y ],
  12682. offset: [ this.offset.x, this.offset.y ],
  12683. wrap: [ this.wrapS, this.wrapT ],
  12684. minFilter: this.minFilter,
  12685. magFilter: this.magFilter,
  12686. anisotropy: this.anisotropy
  12687. };
  12688. if ( this.image !== undefined ) {
  12689. // TODO: Move to THREE.Image
  12690. var image = this.image;
  12691. if ( image.uuid === undefined ) {
  12692. image.uuid = THREE.Math.generateUUID(); // UGH
  12693. }
  12694. if ( meta.images[ image.uuid ] === undefined ) {
  12695. meta.images[ image.uuid ] = {
  12696. uuid: image.uuid,
  12697. url: getDataURL( image )
  12698. };
  12699. }
  12700. output.image = image.uuid;
  12701. }
  12702. meta.textures[ this.uuid ] = output;
  12703. return output;
  12704. },
  12705. dispose: function () {
  12706. this.dispatchEvent( { type: 'dispose' } );
  12707. },
  12708. transformUv: function ( uv ) {
  12709. if ( this.mapping !== THREE.UVMapping ) return;
  12710. uv.multiply( this.repeat );
  12711. uv.add( this.offset );
  12712. if ( uv.x < 0 || uv.x > 1 ) {
  12713. switch ( this.wrapS ) {
  12714. case THREE.RepeatWrapping:
  12715. uv.x = uv.x - Math.floor( uv.x );
  12716. break;
  12717. case THREE.ClampToEdgeWrapping:
  12718. uv.x = uv.x < 0 ? 0 : 1;
  12719. break;
  12720. case THREE.MirroredRepeatWrapping:
  12721. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12722. uv.x = Math.ceil( uv.x ) - uv.x;
  12723. } else {
  12724. uv.x = uv.x - Math.floor( uv.x );
  12725. }
  12726. break;
  12727. }
  12728. }
  12729. if ( uv.y < 0 || uv.y > 1 ) {
  12730. switch ( this.wrapT ) {
  12731. case THREE.RepeatWrapping:
  12732. uv.y = uv.y - Math.floor( uv.y );
  12733. break;
  12734. case THREE.ClampToEdgeWrapping:
  12735. uv.y = uv.y < 0 ? 0 : 1;
  12736. break;
  12737. case THREE.MirroredRepeatWrapping:
  12738. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12739. uv.y = Math.ceil( uv.y ) - uv.y;
  12740. } else {
  12741. uv.y = uv.y - Math.floor( uv.y );
  12742. }
  12743. break;
  12744. }
  12745. }
  12746. if ( this.flipY ) {
  12747. uv.y = 1 - uv.y;
  12748. }
  12749. }
  12750. };
  12751. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12752. THREE.TextureIdCount = 0;
  12753. // File:src/textures/CanvasTexture.js
  12754. /**
  12755. * @author mrdoob / http://mrdoob.com/
  12756. */
  12757. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12758. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12759. this.needsUpdate = true;
  12760. };
  12761. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12762. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12763. // File:src/textures/CubeTexture.js
  12764. /**
  12765. * @author mrdoob / http://mrdoob.com/
  12766. */
  12767. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12768. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12769. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12770. this.images = images;
  12771. this.flipY = false;
  12772. };
  12773. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12774. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12775. THREE.CubeTexture.prototype.copy = function ( source ) {
  12776. THREE.Texture.prototype.copy.call( this, source );
  12777. this.images = source.images;
  12778. return this;
  12779. };
  12780. // File:src/textures/CompressedTexture.js
  12781. /**
  12782. * @author alteredq / http://alteredqualia.com/
  12783. */
  12784. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12785. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12786. this.image = { width: width, height: height };
  12787. this.mipmaps = mipmaps;
  12788. // no flipping for cube textures
  12789. // (also flipping doesn't work for compressed textures )
  12790. this.flipY = false;
  12791. // can't generate mipmaps for compressed textures
  12792. // mips must be embedded in DDS files
  12793. this.generateMipmaps = false;
  12794. };
  12795. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  12796. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  12797. // File:src/textures/DataTexture.js
  12798. /**
  12799. * @author alteredq / http://alteredqualia.com/
  12800. */
  12801. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12802. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12803. this.image = { data: data, width: width, height: height };
  12804. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  12805. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  12806. this.flipY = false;
  12807. this.generateMipmaps = false;
  12808. };
  12809. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  12810. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  12811. // File:src/textures/VideoTexture.js
  12812. /**
  12813. * @author mrdoob / http://mrdoob.com/
  12814. */
  12815. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12816. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12817. this.generateMipmaps = false;
  12818. var scope = this;
  12819. function update() {
  12820. requestAnimationFrame( update );
  12821. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  12822. scope.needsUpdate = true;
  12823. }
  12824. }
  12825. update();
  12826. };
  12827. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  12828. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  12829. // File:src/objects/Group.js
  12830. /**
  12831. * @author mrdoob / http://mrdoob.com/
  12832. */
  12833. THREE.Group = function () {
  12834. THREE.Object3D.call( this );
  12835. this.type = 'Group';
  12836. };
  12837. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  12838. THREE.Group.prototype.constructor = THREE.Group;
  12839. // File:src/objects/Points.js
  12840. /**
  12841. * @author alteredq / http://alteredqualia.com/
  12842. */
  12843. THREE.Points = function ( geometry, material ) {
  12844. THREE.Object3D.call( this );
  12845. this.type = 'Points';
  12846. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12847. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  12848. };
  12849. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  12850. THREE.Points.prototype.constructor = THREE.Points;
  12851. THREE.Points.prototype.raycast = ( function () {
  12852. var inverseMatrix = new THREE.Matrix4();
  12853. var ray = new THREE.Ray();
  12854. return function raycast( raycaster, intersects ) {
  12855. var object = this;
  12856. var geometry = object.geometry;
  12857. var threshold = raycaster.params.Points.threshold;
  12858. inverseMatrix.getInverse( this.matrixWorld );
  12859. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12860. if ( geometry.boundingBox !== null ) {
  12861. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  12862. }
  12863. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  12864. var localThresholdSq = localThreshold * localThreshold;
  12865. var position = new THREE.Vector3();
  12866. function testPoint( point, index ) {
  12867. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  12868. if ( rayPointDistanceSq < localThresholdSq ) {
  12869. var intersectPoint = ray.closestPointToPoint( point );
  12870. intersectPoint.applyMatrix4( object.matrixWorld );
  12871. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  12872. if ( distance < raycaster.near || distance > raycaster.far ) return;
  12873. intersects.push( {
  12874. distance: distance,
  12875. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  12876. point: intersectPoint.clone(),
  12877. index: index,
  12878. face: null,
  12879. object: object
  12880. } );
  12881. }
  12882. }
  12883. if ( geometry instanceof THREE.BufferGeometry ) {
  12884. var index = geometry.index;
  12885. var attributes = geometry.attributes;
  12886. var positions = attributes.position.array;
  12887. if ( index !== null ) {
  12888. var indices = index.array;
  12889. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  12890. var a = indices[ i ];
  12891. position.fromArray( positions, a * 3 );
  12892. testPoint( position, a );
  12893. }
  12894. } else {
  12895. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  12896. position.fromArray( positions, i * 3 );
  12897. testPoint( position, i );
  12898. }
  12899. }
  12900. } else {
  12901. var vertices = geometry.vertices;
  12902. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  12903. testPoint( vertices[ i ], i );
  12904. }
  12905. }
  12906. };
  12907. }() );
  12908. THREE.Points.prototype.clone = function () {
  12909. return new this.constructor( this.geometry, this.material ).copy( this );
  12910. };
  12911. // File:src/objects/Line.js
  12912. /**
  12913. * @author mrdoob / http://mrdoob.com/
  12914. */
  12915. THREE.Line = function ( geometry, material, mode ) {
  12916. if ( mode === 1 ) {
  12917. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  12918. return new THREE.LineSegments( geometry, material );
  12919. }
  12920. THREE.Object3D.call( this );
  12921. this.type = 'Line';
  12922. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12923. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  12924. };
  12925. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  12926. THREE.Line.prototype.constructor = THREE.Line;
  12927. THREE.Line.prototype.raycast = ( function () {
  12928. var inverseMatrix = new THREE.Matrix4();
  12929. var ray = new THREE.Ray();
  12930. var sphere = new THREE.Sphere();
  12931. return function raycast( raycaster, intersects ) {
  12932. var precision = raycaster.linePrecision;
  12933. var precisionSq = precision * precision;
  12934. var geometry = this.geometry;
  12935. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12936. // Checking boundingSphere distance to ray
  12937. sphere.copy( geometry.boundingSphere );
  12938. sphere.applyMatrix4( this.matrixWorld );
  12939. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12940. inverseMatrix.getInverse( this.matrixWorld );
  12941. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12942. var vStart = new THREE.Vector3();
  12943. var vEnd = new THREE.Vector3();
  12944. var interSegment = new THREE.Vector3();
  12945. var interRay = new THREE.Vector3();
  12946. var step = this instanceof THREE.LineSegments ? 2 : 1;
  12947. if ( geometry instanceof THREE.BufferGeometry ) {
  12948. var index = geometry.index;
  12949. var attributes = geometry.attributes;
  12950. if ( index !== null ) {
  12951. var indices = index.array;
  12952. var positions = attributes.position.array;
  12953. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  12954. var a = indices[ i ];
  12955. var b = indices[ i + 1 ];
  12956. vStart.fromArray( positions, a * 3 );
  12957. vEnd.fromArray( positions, b * 3 );
  12958. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  12959. if ( distSq > precisionSq ) continue;
  12960. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12961. var distance = raycaster.ray.origin.distanceTo( interRay );
  12962. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12963. intersects.push( {
  12964. distance: distance,
  12965. // What do we want? intersection point on the ray or on the segment??
  12966. // point: raycaster.ray.at( distance ),
  12967. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12968. index: i,
  12969. face: null,
  12970. faceIndex: null,
  12971. object: this
  12972. } );
  12973. }
  12974. } else {
  12975. var positions = attributes.position.array;
  12976. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  12977. vStart.fromArray( positions, 3 * i );
  12978. vEnd.fromArray( positions, 3 * i + 3 );
  12979. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  12980. if ( distSq > precisionSq ) continue;
  12981. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12982. var distance = raycaster.ray.origin.distanceTo( interRay );
  12983. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12984. intersects.push( {
  12985. distance: distance,
  12986. // What do we want? intersection point on the ray or on the segment??
  12987. // point: raycaster.ray.at( distance ),
  12988. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12989. index: i,
  12990. face: null,
  12991. faceIndex: null,
  12992. object: this
  12993. } );
  12994. }
  12995. }
  12996. } else if ( geometry instanceof THREE.Geometry ) {
  12997. var vertices = geometry.vertices;
  12998. var nbVertices = vertices.length;
  12999. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13000. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13001. if ( distSq > precisionSq ) continue;
  13002. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13003. var distance = raycaster.ray.origin.distanceTo( interRay );
  13004. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13005. intersects.push( {
  13006. distance: distance,
  13007. // What do we want? intersection point on the ray or on the segment??
  13008. // point: raycaster.ray.at( distance ),
  13009. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13010. index: i,
  13011. face: null,
  13012. faceIndex: null,
  13013. object: this
  13014. } );
  13015. }
  13016. }
  13017. };
  13018. }() );
  13019. THREE.Line.prototype.clone = function () {
  13020. return new this.constructor( this.geometry, this.material ).copy( this );
  13021. };
  13022. // DEPRECATED
  13023. THREE.LineStrip = 0;
  13024. THREE.LinePieces = 1;
  13025. // File:src/objects/LineSegments.js
  13026. /**
  13027. * @author mrdoob / http://mrdoob.com/
  13028. */
  13029. THREE.LineSegments = function ( geometry, material ) {
  13030. THREE.Line.call( this, geometry, material );
  13031. this.type = 'LineSegments';
  13032. };
  13033. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13034. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13035. // File:src/objects/Mesh.js
  13036. /**
  13037. * @author mrdoob / http://mrdoob.com/
  13038. * @author alteredq / http://alteredqualia.com/
  13039. * @author mikael emtinger / http://gomo.se/
  13040. * @author jonobr1 / http://jonobr1.com/
  13041. */
  13042. THREE.Mesh = function ( geometry, material ) {
  13043. THREE.Object3D.call( this );
  13044. this.type = 'Mesh';
  13045. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13046. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13047. this.drawMode = THREE.TrianglesDrawMode;
  13048. this.updateMorphTargets();
  13049. };
  13050. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13051. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13052. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13053. this.drawMode = value;
  13054. };
  13055. THREE.Mesh.prototype.updateMorphTargets = function () {
  13056. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13057. this.morphTargetBase = - 1;
  13058. this.morphTargetInfluences = [];
  13059. this.morphTargetDictionary = {};
  13060. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13061. this.morphTargetInfluences.push( 0 );
  13062. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13063. }
  13064. }
  13065. };
  13066. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13067. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13068. return this.morphTargetDictionary[ name ];
  13069. }
  13070. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13071. return 0;
  13072. };
  13073. THREE.Mesh.prototype.raycast = ( function () {
  13074. var inverseMatrix = new THREE.Matrix4();
  13075. var ray = new THREE.Ray();
  13076. var sphere = new THREE.Sphere();
  13077. var vA = new THREE.Vector3();
  13078. var vB = new THREE.Vector3();
  13079. var vC = new THREE.Vector3();
  13080. var tempA = new THREE.Vector3();
  13081. var tempB = new THREE.Vector3();
  13082. var tempC = new THREE.Vector3();
  13083. var uvA = new THREE.Vector2();
  13084. var uvB = new THREE.Vector2();
  13085. var uvC = new THREE.Vector2();
  13086. var barycoord = new THREE.Vector3();
  13087. var intersectionPoint = new THREE.Vector3();
  13088. var intersectionPointWorld = new THREE.Vector3();
  13089. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13090. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13091. uv1.multiplyScalar( barycoord.x );
  13092. uv2.multiplyScalar( barycoord.y );
  13093. uv3.multiplyScalar( barycoord.z );
  13094. uv1.add( uv2 ).add( uv3 );
  13095. return uv1.clone();
  13096. }
  13097. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ){
  13098. var intersect;
  13099. var material = object.material;
  13100. if ( material.side === THREE.BackSide ) {
  13101. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13102. } else {
  13103. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13104. }
  13105. if ( intersect === null ) return null;
  13106. intersectionPointWorld.copy( point );
  13107. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13108. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13109. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13110. return {
  13111. distance: distance,
  13112. point: intersectionPointWorld.clone(),
  13113. object: object
  13114. };
  13115. }
  13116. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13117. vA.fromArray( positions, a * 3 );
  13118. vB.fromArray( positions, b * 3 );
  13119. vC.fromArray( positions, c * 3 );
  13120. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13121. if ( intersection ) {
  13122. if ( uvs ) {
  13123. uvA.fromArray( uvs, a * 2 );
  13124. uvB.fromArray( uvs, b * 2 );
  13125. uvC.fromArray( uvs, c * 2 );
  13126. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13127. }
  13128. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13129. intersection.faceIndex = a;
  13130. }
  13131. return intersection;
  13132. }
  13133. return function raycast( raycaster, intersects ) {
  13134. var geometry = this.geometry;
  13135. var material = this.material;
  13136. if ( material === undefined ) return;
  13137. // Checking boundingSphere distance to ray
  13138. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13139. var matrixWorld = this.matrixWorld;
  13140. sphere.copy( geometry.boundingSphere );
  13141. sphere.applyMatrix4( matrixWorld );
  13142. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13143. // Check boundingBox before continuing
  13144. inverseMatrix.getInverse( matrixWorld );
  13145. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13146. if ( geometry.boundingBox !== null ) {
  13147. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13148. }
  13149. var uvs, intersection;
  13150. if ( geometry instanceof THREE.BufferGeometry ) {
  13151. var a, b, c;
  13152. var index = geometry.index;
  13153. var attributes = geometry.attributes;
  13154. var positions = attributes.position.array;
  13155. if ( attributes.uv !== undefined ){
  13156. uvs = attributes.uv.array;
  13157. }
  13158. if ( index !== null ) {
  13159. var indices = index.array;
  13160. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13161. a = indices[ i ];
  13162. b = indices[ i + 1 ];
  13163. c = indices[ i + 2 ];
  13164. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13165. if ( intersection ) {
  13166. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13167. intersects.push( intersection );
  13168. }
  13169. }
  13170. } else {
  13171. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13172. a = i / 3;
  13173. b = a + 1;
  13174. c = a + 2;
  13175. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13176. if ( intersection ) {
  13177. intersection.index = a; // triangle number in positions buffer semantics
  13178. intersects.push( intersection );
  13179. }
  13180. }
  13181. }
  13182. } else if ( geometry instanceof THREE.Geometry ) {
  13183. var fvA, fvB, fvC;
  13184. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  13185. var materials = isFaceMaterial === true ? material.materials : null;
  13186. var vertices = geometry.vertices;
  13187. var faces = geometry.faces;
  13188. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13189. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13190. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13191. var face = faces[ f ];
  13192. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13193. if ( faceMaterial === undefined ) continue;
  13194. fvA = vertices[ face.a ];
  13195. fvB = vertices[ face.b ];
  13196. fvC = vertices[ face.c ];
  13197. if ( faceMaterial.morphTargets === true ) {
  13198. var morphTargets = geometry.morphTargets;
  13199. var morphInfluences = this.morphTargetInfluences;
  13200. vA.set( 0, 0, 0 );
  13201. vB.set( 0, 0, 0 );
  13202. vC.set( 0, 0, 0 );
  13203. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13204. var influence = morphInfluences[ t ];
  13205. if ( influence === 0 ) continue;
  13206. var targets = morphTargets[ t ].vertices;
  13207. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13208. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13209. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13210. }
  13211. vA.add( fvA );
  13212. vB.add( fvB );
  13213. vC.add( fvC );
  13214. fvA = vA;
  13215. fvB = vB;
  13216. fvC = vC;
  13217. }
  13218. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13219. if ( intersection ) {
  13220. if ( uvs ) {
  13221. var uvs_f = uvs[ f ];
  13222. uvA.copy( uvs_f[ 0 ] );
  13223. uvB.copy( uvs_f[ 1 ] );
  13224. uvC.copy( uvs_f[ 2 ] );
  13225. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13226. }
  13227. intersection.face = face;
  13228. intersection.faceIndex = f;
  13229. intersects.push( intersection );
  13230. }
  13231. }
  13232. }
  13233. };
  13234. }() );
  13235. THREE.Mesh.prototype.clone = function () {
  13236. return new this.constructor( this.geometry, this.material ).copy( this );
  13237. };
  13238. // File:src/objects/Bone.js
  13239. /**
  13240. * @author mikael emtinger / http://gomo.se/
  13241. * @author alteredq / http://alteredqualia.com/
  13242. * @author ikerr / http://verold.com
  13243. */
  13244. THREE.Bone = function ( skin ) {
  13245. THREE.Object3D.call( this );
  13246. this.type = 'Bone';
  13247. this.skin = skin;
  13248. };
  13249. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13250. THREE.Bone.prototype.constructor = THREE.Bone;
  13251. THREE.Bone.prototype.copy = function ( source ) {
  13252. THREE.Object3D.prototype.copy.call( this, source );
  13253. this.skin = source.skin;
  13254. return this;
  13255. };
  13256. // File:src/objects/Skeleton.js
  13257. /**
  13258. * @author mikael emtinger / http://gomo.se/
  13259. * @author alteredq / http://alteredqualia.com/
  13260. * @author michael guerrero / http://realitymeltdown.com
  13261. * @author ikerr / http://verold.com
  13262. */
  13263. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13264. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13265. this.identityMatrix = new THREE.Matrix4();
  13266. // copy the bone array
  13267. bones = bones || [];
  13268. this.bones = bones.slice( 0 );
  13269. // create a bone texture or an array of floats
  13270. if ( this.useVertexTexture ) {
  13271. // layout (1 matrix = 4 pixels)
  13272. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13273. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13274. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13275. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13276. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13277. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13278. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13279. size = Math.max( size, 4 );
  13280. this.boneTextureWidth = size;
  13281. this.boneTextureHeight = size;
  13282. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13283. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13284. } else {
  13285. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13286. }
  13287. // use the supplied bone inverses or calculate the inverses
  13288. if ( boneInverses === undefined ) {
  13289. this.calculateInverses();
  13290. } else {
  13291. if ( this.bones.length === boneInverses.length ) {
  13292. this.boneInverses = boneInverses.slice( 0 );
  13293. } else {
  13294. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13295. this.boneInverses = [];
  13296. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13297. this.boneInverses.push( new THREE.Matrix4() );
  13298. }
  13299. }
  13300. }
  13301. };
  13302. THREE.Skeleton.prototype.calculateInverses = function () {
  13303. this.boneInverses = [];
  13304. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13305. var inverse = new THREE.Matrix4();
  13306. if ( this.bones[ b ] ) {
  13307. inverse.getInverse( this.bones[ b ].matrixWorld );
  13308. }
  13309. this.boneInverses.push( inverse );
  13310. }
  13311. };
  13312. THREE.Skeleton.prototype.pose = function () {
  13313. var bone;
  13314. // recover the bind-time world matrices
  13315. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13316. bone = this.bones[ b ];
  13317. if ( bone ) {
  13318. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13319. }
  13320. }
  13321. // compute the local matrices, positions, rotations and scales
  13322. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13323. bone = this.bones[ b ];
  13324. if ( bone ) {
  13325. if ( bone.parent ) {
  13326. bone.matrix.getInverse( bone.parent.matrixWorld );
  13327. bone.matrix.multiply( bone.matrixWorld );
  13328. } else {
  13329. bone.matrix.copy( bone.matrixWorld );
  13330. }
  13331. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13332. }
  13333. }
  13334. };
  13335. THREE.Skeleton.prototype.update = ( function () {
  13336. var offsetMatrix = new THREE.Matrix4();
  13337. return function update() {
  13338. // flatten bone matrices to array
  13339. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13340. // compute the offset between the current and the original transform
  13341. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13342. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13343. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13344. }
  13345. if ( this.useVertexTexture ) {
  13346. this.boneTexture.needsUpdate = true;
  13347. }
  13348. };
  13349. } )();
  13350. THREE.Skeleton.prototype.clone = function () {
  13351. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13352. };
  13353. // File:src/objects/SkinnedMesh.js
  13354. /**
  13355. * @author mikael emtinger / http://gomo.se/
  13356. * @author alteredq / http://alteredqualia.com/
  13357. * @author ikerr / http://verold.com
  13358. */
  13359. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13360. THREE.Mesh.call( this, geometry, material );
  13361. this.type = 'SkinnedMesh';
  13362. this.bindMode = "attached";
  13363. this.bindMatrix = new THREE.Matrix4();
  13364. this.bindMatrixInverse = new THREE.Matrix4();
  13365. // init bones
  13366. // TODO: remove bone creation as there is no reason (other than
  13367. // convenience) for THREE.SkinnedMesh to do this.
  13368. var bones = [];
  13369. if ( this.geometry && this.geometry.bones !== undefined ) {
  13370. var bone, gbone;
  13371. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13372. gbone = this.geometry.bones[ b ];
  13373. bone = new THREE.Bone( this );
  13374. bones.push( bone );
  13375. bone.name = gbone.name;
  13376. bone.position.fromArray( gbone.pos );
  13377. bone.quaternion.fromArray( gbone.rotq );
  13378. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13379. }
  13380. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13381. gbone = this.geometry.bones[ b ];
  13382. if ( gbone.parent !== - 1 && gbone.parent !== null) {
  13383. bones[ gbone.parent ].add( bones[ b ] );
  13384. } else {
  13385. this.add( bones[ b ] );
  13386. }
  13387. }
  13388. }
  13389. this.normalizeSkinWeights();
  13390. this.updateMatrixWorld( true );
  13391. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13392. };
  13393. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13394. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13395. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13396. this.skeleton = skeleton;
  13397. if ( bindMatrix === undefined ) {
  13398. this.updateMatrixWorld( true );
  13399. this.skeleton.calculateInverses();
  13400. bindMatrix = this.matrixWorld;
  13401. }
  13402. this.bindMatrix.copy( bindMatrix );
  13403. this.bindMatrixInverse.getInverse( bindMatrix );
  13404. };
  13405. THREE.SkinnedMesh.prototype.pose = function () {
  13406. this.skeleton.pose();
  13407. };
  13408. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13409. if ( this.geometry instanceof THREE.Geometry ) {
  13410. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  13411. var sw = this.geometry.skinWeights[ i ];
  13412. var scale = 1.0 / sw.lengthManhattan();
  13413. if ( scale !== Infinity ) {
  13414. sw.multiplyScalar( scale );
  13415. } else {
  13416. sw.set( 1 ); // this will be normalized by the shader anyway
  13417. }
  13418. }
  13419. } else {
  13420. // skinning weights assumed to be normalized for THREE.BufferGeometry
  13421. }
  13422. };
  13423. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13424. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13425. if ( this.bindMode === "attached" ) {
  13426. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13427. } else if ( this.bindMode === "detached" ) {
  13428. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13429. } else {
  13430. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13431. }
  13432. };
  13433. THREE.SkinnedMesh.prototype.clone = function() {
  13434. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13435. };
  13436. // File:src/objects/LOD.js
  13437. /**
  13438. * @author mikael emtinger / http://gomo.se/
  13439. * @author alteredq / http://alteredqualia.com/
  13440. * @author mrdoob / http://mrdoob.com/
  13441. */
  13442. THREE.LOD = function () {
  13443. THREE.Object3D.call( this );
  13444. this.type = 'LOD';
  13445. Object.defineProperties( this, {
  13446. levels: {
  13447. enumerable: true,
  13448. value: []
  13449. },
  13450. objects: {
  13451. get: function () {
  13452. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13453. return this.levels;
  13454. }
  13455. }
  13456. } );
  13457. };
  13458. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13459. THREE.LOD.prototype.constructor = THREE.LOD;
  13460. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13461. if ( distance === undefined ) distance = 0;
  13462. distance = Math.abs( distance );
  13463. var levels = this.levels;
  13464. for ( var l = 0; l < levels.length; l ++ ) {
  13465. if ( distance < levels[ l ].distance ) {
  13466. break;
  13467. }
  13468. }
  13469. levels.splice( l, 0, { distance: distance, object: object } );
  13470. this.add( object );
  13471. };
  13472. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13473. var levels = this.levels;
  13474. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13475. if ( distance < levels[ i ].distance ) {
  13476. break;
  13477. }
  13478. }
  13479. return levels[ i - 1 ].object;
  13480. };
  13481. THREE.LOD.prototype.raycast = ( function () {
  13482. var matrixPosition = new THREE.Vector3();
  13483. return function raycast( raycaster, intersects ) {
  13484. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13485. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13486. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13487. };
  13488. }() );
  13489. THREE.LOD.prototype.update = function () {
  13490. var v1 = new THREE.Vector3();
  13491. var v2 = new THREE.Vector3();
  13492. return function update( camera ) {
  13493. var levels = this.levels;
  13494. if ( levels.length > 1 ) {
  13495. v1.setFromMatrixPosition( camera.matrixWorld );
  13496. v2.setFromMatrixPosition( this.matrixWorld );
  13497. var distance = v1.distanceTo( v2 );
  13498. levels[ 0 ].object.visible = true;
  13499. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13500. if ( distance >= levels[ i ].distance ) {
  13501. levels[ i - 1 ].object.visible = false;
  13502. levels[ i ].object.visible = true;
  13503. } else {
  13504. break;
  13505. }
  13506. }
  13507. for ( ; i < l; i ++ ) {
  13508. levels[ i ].object.visible = false;
  13509. }
  13510. }
  13511. };
  13512. }();
  13513. THREE.LOD.prototype.copy = function ( source ) {
  13514. THREE.Object3D.prototype.copy.call( this, source, false );
  13515. var levels = source.levels;
  13516. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13517. var level = levels[ i ];
  13518. this.addLevel( level.object.clone(), level.distance );
  13519. }
  13520. return this;
  13521. };
  13522. THREE.LOD.prototype.toJSON = function ( meta ) {
  13523. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13524. data.object.levels = [];
  13525. var levels = this.levels;
  13526. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13527. var level = levels[ i ];
  13528. data.object.levels.push( {
  13529. object: level.object.uuid,
  13530. distance: level.distance
  13531. } );
  13532. }
  13533. return data;
  13534. };
  13535. // File:src/objects/Sprite.js
  13536. /**
  13537. * @author mikael emtinger / http://gomo.se/
  13538. * @author alteredq / http://alteredqualia.com/
  13539. */
  13540. THREE.Sprite = ( function () {
  13541. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13542. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13543. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13544. var geometry = new THREE.BufferGeometry();
  13545. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13546. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13547. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13548. return function Sprite( material ) {
  13549. THREE.Object3D.call( this );
  13550. this.type = 'Sprite';
  13551. this.geometry = geometry;
  13552. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13553. };
  13554. } )();
  13555. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13556. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13557. THREE.Sprite.prototype.raycast = ( function () {
  13558. var matrixPosition = new THREE.Vector3();
  13559. return function raycast( raycaster, intersects ) {
  13560. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13561. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13562. var guessSizeSq = this.scale.x * this.scale.y;
  13563. if ( distanceSq > guessSizeSq ) {
  13564. return;
  13565. }
  13566. intersects.push( {
  13567. distance: Math.sqrt( distanceSq ),
  13568. point: this.position,
  13569. face: null,
  13570. object: this
  13571. } );
  13572. };
  13573. }() );
  13574. THREE.Sprite.prototype.clone = function () {
  13575. return new this.constructor( this.material ).copy( this );
  13576. };
  13577. // Backwards compatibility
  13578. THREE.Particle = THREE.Sprite;
  13579. // File:src/objects/LensFlare.js
  13580. /**
  13581. * @author mikael emtinger / http://gomo.se/
  13582. * @author alteredq / http://alteredqualia.com/
  13583. */
  13584. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13585. THREE.Object3D.call( this );
  13586. this.lensFlares = [];
  13587. this.positionScreen = new THREE.Vector3();
  13588. this.customUpdateCallback = undefined;
  13589. if ( texture !== undefined ) {
  13590. this.add( texture, size, distance, blending, color );
  13591. }
  13592. };
  13593. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13594. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13595. /*
  13596. * Add: adds another flare
  13597. */
  13598. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13599. if ( size === undefined ) size = - 1;
  13600. if ( distance === undefined ) distance = 0;
  13601. if ( opacity === undefined ) opacity = 1;
  13602. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13603. if ( blending === undefined ) blending = THREE.NormalBlending;
  13604. distance = Math.min( distance, Math.max( 0, distance ) );
  13605. this.lensFlares.push( {
  13606. texture: texture, // THREE.Texture
  13607. size: size, // size in pixels (-1 = use texture.width)
  13608. distance: distance, // distance (0-1) from light source (0=at light source)
  13609. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13610. scale: 1, // scale
  13611. rotation: 0, // rotation
  13612. opacity: opacity, // opacity
  13613. color: color, // color
  13614. blending: blending // blending
  13615. } );
  13616. };
  13617. /*
  13618. * Update lens flares update positions on all flares based on the screen position
  13619. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13620. */
  13621. THREE.LensFlare.prototype.updateLensFlares = function () {
  13622. var f, fl = this.lensFlares.length;
  13623. var flare;
  13624. var vecX = - this.positionScreen.x * 2;
  13625. var vecY = - this.positionScreen.y * 2;
  13626. for ( f = 0; f < fl; f ++ ) {
  13627. flare = this.lensFlares[ f ];
  13628. flare.x = this.positionScreen.x + vecX * flare.distance;
  13629. flare.y = this.positionScreen.y + vecY * flare.distance;
  13630. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13631. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13632. }
  13633. };
  13634. THREE.LensFlare.prototype.copy = function ( source ) {
  13635. THREE.Object3D.prototype.copy.call( this, source );
  13636. this.positionScreen.copy( source.positionScreen );
  13637. this.customUpdateCallback = source.customUpdateCallback;
  13638. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13639. this.lensFlares.push( source.lensFlares[ i ] );
  13640. }
  13641. return this;
  13642. };
  13643. // File:src/scenes/Scene.js
  13644. /**
  13645. * @author mrdoob / http://mrdoob.com/
  13646. */
  13647. THREE.Scene = function () {
  13648. THREE.Object3D.call( this );
  13649. this.type = 'Scene';
  13650. this.fog = null;
  13651. this.overrideMaterial = null;
  13652. this.autoUpdate = true; // checked by the renderer
  13653. };
  13654. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13655. THREE.Scene.prototype.constructor = THREE.Scene;
  13656. THREE.Scene.prototype.copy = function ( source ) {
  13657. THREE.Object3D.prototype.copy.call( this, source );
  13658. if ( source.fog !== null ) this.fog = source.fog.clone();
  13659. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13660. this.autoUpdate = source.autoUpdate;
  13661. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13662. return this;
  13663. };
  13664. // File:src/scenes/Fog.js
  13665. /**
  13666. * @author mrdoob / http://mrdoob.com/
  13667. * @author alteredq / http://alteredqualia.com/
  13668. */
  13669. THREE.Fog = function ( color, near, far ) {
  13670. this.name = '';
  13671. this.color = new THREE.Color( color );
  13672. this.near = ( near !== undefined ) ? near : 1;
  13673. this.far = ( far !== undefined ) ? far : 1000;
  13674. };
  13675. THREE.Fog.prototype.clone = function () {
  13676. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13677. };
  13678. // File:src/scenes/FogExp2.js
  13679. /**
  13680. * @author mrdoob / http://mrdoob.com/
  13681. * @author alteredq / http://alteredqualia.com/
  13682. */
  13683. THREE.FogExp2 = function ( color, density ) {
  13684. this.name = '';
  13685. this.color = new THREE.Color( color );
  13686. this.density = ( density !== undefined ) ? density : 0.00025;
  13687. };
  13688. THREE.FogExp2.prototype.clone = function () {
  13689. return new THREE.FogExp2( this.color.getHex(), this.density );
  13690. };
  13691. // File:src/renderers/shaders/ShaderChunk.js
  13692. THREE.ShaderChunk = {};
  13693. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13694. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13695. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13696. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13697. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13698. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13699. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13700. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n reflectedLight.indirectDiffuse *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n#endif\n";
  13701. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13702. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13703. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13704. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  13705. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13706. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  13707. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13708. THREE.ShaderChunk[ 'bsdfs'] = "float calcLightAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if ( decayExponent > 0.0 ) {\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = alpha * alpha;\n float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 );\n float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 );\n return 1.0 / ( gl * gv );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = alpha * alpha;\n float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / ( denom * denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float alpha = roughness * roughness;\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_Smith( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n return specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return 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 vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / square( ggxRoughness + 0.0001 ) - 2.0 );\n}";
  13709. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13710. THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n float Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n return vec2( dBx, dBy );\n }\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm;\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n float fDet = dot( vSigmaX, R1 );\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif\n";
  13711. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13712. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13713. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13714. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13715. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13716. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13717. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13718. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13719. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13720. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\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 square( const in float x ) { return x*x; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nvec3 inputToLinear( in vec3 a ) {\n #ifdef GAMMA_INPUT\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\nvec3 linearToOutput( in vec3 a ) {\n #ifdef GAMMA_OUTPUT\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\n";
  13721. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13722. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13723. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13724. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13725. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13726. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13727. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13728. THREE.ShaderChunk[ 'emissivemap_fragment'] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = inputToLinear( emissiveColor.rgb );\n totalEmissiveLight *= emissiveColor.rgb;\n#endif\n";
  13729. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13730. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13731. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13732. THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envColor = texture2D( envMap, sampleUV );\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n envColor.xyz = inputToLinear( envColor.xyz );\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif\n";
  13733. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13734. THREE.ShaderChunk[ 'envmap_pars_fragment'] = "#if defined( USE_ENVMAP ) || defined( STANDARD )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( STANDARD )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  13735. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13736. THREE.ShaderChunk[ 'envmap_pars_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n varying vec3 vReflect;\n uniform float refractionRatio;\n#endif\n";
  13737. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13738. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n#endif\n";
  13739. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13740. THREE.ShaderChunk[ 'fog_fragment'] = "#ifdef USE_FOG\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n #ifdef FOG_EXP2\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n #endif\n \n outgoingLight = mix( outgoingLight, fogColor, fogFactor );\n#endif";
  13741. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13742. THREE.ShaderChunk[ 'fog_pars_fragment'] = "#ifdef USE_FOG\n uniform vec3 fogColor;\n #ifdef FOG_EXP2\n uniform float fogDensity;\n #else\n uniform float fogNear;\n uniform float fogFar;\n #endif\n#endif";
  13743. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13744. THREE.ShaderChunk[ 'lights_pars'] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n return PI * ambientLightColor;\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLight( const in DirectionalLight directionalLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n return directLight;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n IncidentLight getPointDirectLight( const in PointLight pointLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n directLight.color = pointLight.color;\n directLight.color *= calcLightAttenuation( length( lVector ), pointLight.distance, pointLight.decay );\n return directLight;\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float angleCos;\n float exponent;\n int shadow;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLight( const in SpotLight spotLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float spotEffect = dot( directLight.direction, spotLight.direction );\n if ( spotEffect > spotLight.angleCos ) {\n float spotEffect = dot( spotLight.direction, directLight.direction );\n spotEffect = saturate( pow( saturate( spotEffect ), spotLight.exponent ) );\n directLight.color = spotLight.color;\n directLight.color *= ( spotEffect * calcLightAttenuation( length( lVector ), spotLight.distance, spotLight.decay ) );\n } else {\n directLight.color = vec3( 0.0 );\n }\n return directLight;\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n return PI * mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( STANDARD )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n #else\n vec3 envMapColor = vec3( 0.0 );\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( square( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  13745. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13746. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13747. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13748. THREE.ShaderChunk[ '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 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n {\n #if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n #endif\n }\n";
  13749. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13750. THREE.ShaderChunk[ 'lights_phong_fragment'] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  13751. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13752. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * PI * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.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 reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material ) (0)\n";
  13753. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13754. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n";
  13755. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  13756. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  13757. // File:src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl
  13758. THREE.ShaderChunk[ 'lights_standard_fragment'] = "StandardMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\nmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n";
  13759. // File:src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl
  13760. THREE.ShaderChunk[ 'lights_standard_pars_fragment'] = "struct StandardMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n};\nvoid RE_Direct_Standard( const in IncidentLight directLight, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * PI * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Standard( const in vec3 irradiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Standard( const in vec3 radiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Standard\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Standard\n#define RE_IndirectSpecular RE_IndirectSpecular_Standard\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n";
  13761. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  13762. THREE.ShaderChunk[ 'lights_template'] = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n PointLight pointLight = pointLights[ i ];\n IncidentLight directLight = getPointDirectLight( pointLight, geometry );\n #ifdef USE_SHADOWMAP\n if ( pointLight.shadow > - 1 ) {\n for ( int j = 0; j < NUM_SHADOWS; j ++ ) {\n if ( j == pointLight.shadow ) {\n directLight.color *= shadows[ j ];\n }\n }\n }\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n SpotLight spotLight = spotLights[ i ];\n IncidentLight directLight = getSpotDirectLight( spotLight, geometry );\n #ifdef USE_SHADOWMAP\n if ( spotLight.shadow > - 1 ) {\n for ( int j = 0; j < NUM_SHADOWS; j ++ ) {\n if ( j == spotLight.shadow ) {\n directLight.color *= shadows[ j ];\n }\n }\n }\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n DirectionalLight directionalLight = directionalLights[ i ];\n IncidentLight directLight = getDirectionalDirectLight( directionalLight, geometry );\n #ifdef USE_SHADOWMAP\n if ( directionalLight.shadow > - 1 ) {\n for ( int j = 0; j < NUM_SHADOWS; j ++ ) {\n if ( j == directionalLight.shadow ) {\n directLight.color *= shadows[ j ];\n }\n }\n }\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n {\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n irradiance += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n {\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n }\n#endif\n";
  13763. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  13764. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  13765. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  13766. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  13767. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  13768. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n uniform float logDepthBufFC;\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n #endif\n#endif\n";
  13769. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  13770. THREE.ShaderChunk[ 'logdepthbuf_pars_vertex'] = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n #endif\n uniform float logDepthBufFC;\n#endif";
  13771. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  13772. THREE.ShaderChunk[ 'logdepthbuf_vertex'] = "#ifdef USE_LOGDEPTHBUF\n gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n #ifdef USE_LOGDEPTHBUF_EXT\n vFragDepth = 1.0 + gl_Position.w;\n #else\n gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n #endif\n#endif\n";
  13773. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  13774. THREE.ShaderChunk[ 'map_fragment'] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor.xyz = inputToLinear( texelColor.xyz );\n diffuseColor *= texelColor;\n#endif\n";
  13775. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  13776. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif";
  13777. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  13778. THREE.ShaderChunk[ 'map_particle_fragment'] = "#ifdef USE_MAP\n diffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n#endif\n";
  13779. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  13780. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  13781. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  13782. THREE.ShaderChunk[ 'metalnessmap_fragment'] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  13783. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  13784. THREE.ShaderChunk[ 'metalnessmap_pars_fragment'] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  13785. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  13786. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif\n";
  13787. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  13788. THREE.ShaderChunk[ 'morphtarget_pars_vertex'] = "#ifdef USE_MORPHTARGETS\n #ifndef USE_MORPHNORMALS\n uniform float morphTargetInfluences[ 8 ];\n #else\n uniform float morphTargetInfluences[ 4 ];\n #endif\n#endif";
  13789. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  13790. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n transformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n transformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n transformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n #ifndef USE_MORPHNORMALS\n transformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n transformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n transformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n transformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n #endif\n#endif\n";
  13791. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  13792. THREE.ShaderChunk[ 'normal_fragment'] = "#ifdef FLAT_SHADED\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#endif\n#ifdef USE_NORMALMAP\n normal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  13793. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  13794. THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( vUv.st );\n vec2 st1 = dFdy( vUv.st );\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normalize( surf_norm );\n vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n mapN.xy = normalScale * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n }\n#endif\n";
  13795. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  13796. THREE.ShaderChunk[ 'project_vertex'] = "#ifdef USE_SKINNING\n vec4 mvPosition = modelViewMatrix * skinned;\n#else\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n#endif\ngl_Position = projectionMatrix * mvPosition;\n";
  13797. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  13798. THREE.ShaderChunk[ 'roughnessmap_fragment'] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  13799. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  13800. THREE.ShaderChunk[ 'roughnessmap_pars_fragment'] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  13801. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  13802. THREE.ShaderChunk[ 'shadowmap_fragment'] = "vec3 shadowMask = vec3( 1.0 );\n#ifdef USE_SHADOWMAP\n float shadows[ NUM_SHADOWS ];\n for ( int i = 0; i < NUM_SHADOWS; i ++ ) {\n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n float shadow = 0.0;\n#ifdef POINT_LIGHT_SHADOWS\n bool isPointLight = shadowDarkness[ i ] < 0.0;\n if ( isPointLight ) {\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n #if defined( SHADOWMAP_TYPE_PCF )\n const float Dr = 1.25;\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n const float Dr = 2.25;\n #endif\n float os = Dr * 2.0 * texelSizeY;\n const vec3 Gsd = vec3( - 1, 0, 1 );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n shadow *= realShadowDarkness * ( 1.0 / 21.0 );\n #else\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n shadow *= realShadowDarkness;\n #endif\n } else {\n#endif\n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n shadowCoord.z += shadowBias[ i ];\n const float ShadowDelta = 1.0 / 9.0;\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n float dx0 = - 1.25 * xPixelOffset;\n float dy0 = - 1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n float fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n shadow *= shadowDarkness[ i ];\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n shadowCoord.z += shadowBias[ i ];\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n float dx0 = - 1.0 * xPixelOffset;\n float dy0 = - 1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n mat3 shadowKernel;\n mat3 depthKernel;\n depthKernel[ 0 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[ 0 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[ 0 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[ 1 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[ 1 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[ 1 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[ 2 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[ 2 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[ 2 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[ 0 ] = vec3( lessThan( depthKernel[ 0 ], shadowZ ) );\n shadowKernel[ 0 ] *= vec3( 0.25 );\n shadowKernel[ 1 ] = vec3( lessThan( depthKernel[ 1 ], shadowZ ) );\n shadowKernel[ 1 ] *= vec3( 0.25 );\n shadowKernel[ 2 ] = vec3( lessThan( depthKernel[ 2 ], shadowZ ) );\n shadowKernel[ 2 ] *= vec3( 0.25 );\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[ i ].xy );\n shadowKernel[ 0 ] = mix( shadowKernel[ 1 ], shadowKernel[ 0 ], fractionalCoord.x );\n shadowKernel[ 1 ] = mix( shadowKernel[ 2 ], shadowKernel[ 1 ], fractionalCoord.x );\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[ 0 ][ 1 ], shadowKernel[ 0 ][ 0 ], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[ 0 ][ 2 ], shadowKernel[ 0 ][ 1 ], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[ 1 ][ 1 ], shadowKernel[ 1 ][ 0 ], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[ 1 ][ 2 ], shadowKernel[ 1 ][ 1 ], fractionalCoord.y );\n shadow = dot( shadowValues, vec4( 1.0 ) ) * shadowDarkness[ i ];\n #else\n shadowCoord.z += shadowBias[ i ];\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow = shadowDarkness[ i ];\n #endif\n }\n#ifdef SHADOWMAP_DEBUG\n if ( inFrustum ) {\n if ( i == 0 ) {\n outgoingLight *= vec3( 1.0, 0.5, 0.0 );\n } else if ( i == 1 ) {\n outgoingLight *= vec3( 0.0, 1.0, 0.8 );\n } else {\n outgoingLight *= vec3( 0.0, 0.5, 1.0 );\n }\n }\n#endif\n#ifdef POINT_LIGHT_SHADOWS\n }\n#endif\n shadowMask = shadowMask * vec3( 1.0 - shadow );\n shadows[ i ] = 1.0 - shadow;\n }\n#endif\n";
  13803. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  13804. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n uniform sampler2D shadowMap[ NUM_SHADOWS ];\n uniform vec2 shadowMapSize[ NUM_SHADOWS ];\n uniform float shadowDarkness[ NUM_SHADOWS ];\n uniform float shadowBias[ NUM_SHADOWS ];\n varying vec4 vShadowCoord[ NUM_SHADOWS ];\n float unpackDepth( const in vec4 rgba_depth ) {\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n }\n #ifdef POINT_LIGHT_SHADOWS\n void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n if ( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )\n shadowValue += 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n #endif\n#endif\n";
  13805. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  13806. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n uniform float shadowDarkness[ NUM_SHADOWS ];\n uniform mat4 shadowMatrix[ NUM_SHADOWS ];\n varying vec4 vShadowCoord[ NUM_SHADOWS ];\n#endif";
  13807. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  13808. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n for ( int i = 0; i < NUM_SHADOWS; i ++ ) {\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n }\n#endif";
  13809. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  13810. THREE.ShaderChunk[ 'skinbase_vertex'] = "#ifdef USE_SKINNING\n mat4 boneMatX = getBoneMatrix( skinIndex.x );\n mat4 boneMatY = getBoneMatrix( skinIndex.y );\n mat4 boneMatZ = getBoneMatrix( skinIndex.z );\n mat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  13811. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  13812. THREE.ShaderChunk[ 'skinning_pars_vertex'] = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n #ifdef BONE_TEXTURE\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n y = dy * ( y + 0.5 );\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n #else\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n mat4 getBoneMatrix( const in float i ) {\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n }\n #endif\n#endif\n";
  13813. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  13814. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n#endif\n";
  13815. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  13816. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n#endif\n";
  13817. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  13818. THREE.ShaderChunk[ 'specularmap_fragment'] = "float specularStrength;\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture2D( specularMap, vUv );\n specularStrength = texelSpecular.r;\n#else\n specularStrength = 1.0;\n#endif";
  13819. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  13820. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  13821. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  13822. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  13823. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  13824. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  13825. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  13826. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  13827. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  13828. THREE.ShaderChunk[ '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 varying vec2 vUv;\n#endif";
  13829. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  13830. THREE.ShaderChunk[ '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 varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  13831. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  13832. THREE.ShaderChunk[ '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 vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  13833. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  13834. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( STANDARD ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  13835. // File:src/renderers/shaders/UniformsUtils.js
  13836. /**
  13837. * Uniform Utilities
  13838. */
  13839. THREE.UniformsUtils = {
  13840. merge: function ( uniforms ) {
  13841. var merged = {};
  13842. for ( var u = 0; u < uniforms.length; u ++ ) {
  13843. var tmp = this.clone( uniforms[ u ] );
  13844. for ( var p in tmp ) {
  13845. merged[ p ] = tmp[ p ];
  13846. }
  13847. }
  13848. return merged;
  13849. },
  13850. clone: function ( uniforms_src ) {
  13851. var uniforms_dst = {};
  13852. for ( var u in uniforms_src ) {
  13853. uniforms_dst[ u ] = {};
  13854. for ( var p in uniforms_src[ u ] ) {
  13855. var parameter_src = uniforms_src[ u ][ p ];
  13856. if ( parameter_src instanceof THREE.Color ||
  13857. parameter_src instanceof THREE.Vector2 ||
  13858. parameter_src instanceof THREE.Vector3 ||
  13859. parameter_src instanceof THREE.Vector4 ||
  13860. parameter_src instanceof THREE.Matrix3 ||
  13861. parameter_src instanceof THREE.Matrix4 ||
  13862. parameter_src instanceof THREE.Texture ) {
  13863. uniforms_dst[ u ][ p ] = parameter_src.clone();
  13864. } else if ( Array.isArray( parameter_src ) ) {
  13865. uniforms_dst[ u ][ p ] = parameter_src.slice();
  13866. } else {
  13867. uniforms_dst[ u ][ p ] = parameter_src;
  13868. }
  13869. }
  13870. }
  13871. return uniforms_dst;
  13872. }
  13873. };
  13874. // File:src/renderers/shaders/UniformsLib.js
  13875. /**
  13876. * Uniforms library for shared webgl shaders
  13877. */
  13878. THREE.UniformsLib = {
  13879. common: {
  13880. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  13881. "opacity" : { type: "f", value: 1.0 },
  13882. "map" : { type: "t", value: null },
  13883. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  13884. "specularMap" : { type: "t", value: null },
  13885. "alphaMap" : { type: "t", value: null },
  13886. "envMap" : { type: "t", value: null },
  13887. "flipEnvMap" : { type: "f", value: - 1 },
  13888. "reflectivity" : { type: "f", value: 1.0 },
  13889. "refractionRatio" : { type: "f", value: 0.98 }
  13890. },
  13891. aomap: {
  13892. "aoMap" : { type: "t", value: null },
  13893. "aoMapIntensity" : { type: "f", value: 1 },
  13894. },
  13895. lightmap: {
  13896. "lightMap" : { type: "t", value: null },
  13897. "lightMapIntensity" : { type: "f", value: 1 },
  13898. },
  13899. emissivemap: {
  13900. "emissiveMap" : { type: "t", value: null },
  13901. },
  13902. bumpmap: {
  13903. "bumpMap" : { type: "t", value: null },
  13904. "bumpScale" : { type: "f", value: 1 }
  13905. },
  13906. normalmap: {
  13907. "normalMap" : { type: "t", value: null },
  13908. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  13909. },
  13910. displacementmap: {
  13911. "displacementMap" : { type: "t", value: null },
  13912. "displacementScale" : { type: "f", value: 1 },
  13913. "displacementBias" : { type: "f", value: 0 }
  13914. },
  13915. roughnessmap: {
  13916. "roughnessMap" : { type: "t", value: null }
  13917. },
  13918. metalnessmap: {
  13919. "metalnessMap" : { type: "t", value: null }
  13920. },
  13921. fog: {
  13922. "fogDensity" : { type: "f", value: 0.00025 },
  13923. "fogNear" : { type: "f", value: 1 },
  13924. "fogFar" : { type: "f", value: 2000 },
  13925. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  13926. },
  13927. lights: {
  13928. "ambientLightColor" : { type: "fv", value: [] },
  13929. "directionalLights" : { type: "sa", value: [], properties: {
  13930. "direction": { type: "v3" },
  13931. "color": { type: "c" },
  13932. "shadow": { type: "i" }
  13933. } },
  13934. "hemisphereLights" : { type: "sa", value: [], properties: {
  13935. "direction": { type: "v3" },
  13936. "skyColor": { type: "c" },
  13937. "groundColor": { type: "c" }
  13938. } },
  13939. "pointLights" : { type: "sa", value: [], properties: {
  13940. "color": { type: "c" },
  13941. "position": { type: "v3" },
  13942. "decay": { type: "f" },
  13943. "distance": { type: "f" },
  13944. "shadow": { type: "i" }
  13945. } },
  13946. "spotLights" : { type: "sa", value: [], properties: {
  13947. "color": { type: "c" },
  13948. "position": { type: "v3" },
  13949. "direction": { type: "v3" },
  13950. "distance": { type: "f" },
  13951. "angleCos": { type: "f" },
  13952. "exponent": { type: "f" },
  13953. "decay": { type: "f" },
  13954. "shadow": { type: "i" }
  13955. } }
  13956. },
  13957. points: {
  13958. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  13959. "opacity" : { type: "f", value: 1.0 },
  13960. "size" : { type: "f", value: 1.0 },
  13961. "scale" : { type: "f", value: 1.0 },
  13962. "map" : { type: "t", value: null },
  13963. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  13964. "fogDensity" : { type: "f", value: 0.00025 },
  13965. "fogNear" : { type: "f", value: 1 },
  13966. "fogFar" : { type: "f", value: 2000 },
  13967. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  13968. },
  13969. shadowmap: {
  13970. "shadowMap": { type: "tv", value: [] },
  13971. "shadowMapSize": { type: "v2v", value: [] },
  13972. "shadowBias" : { type: "fv1", value: [] },
  13973. "shadowDarkness": { type: "fv1", value: [] },
  13974. "shadowMatrix" : { type: "m4v", value: [] }
  13975. }
  13976. };
  13977. // File:src/renderers/shaders/ShaderLib.js
  13978. /**
  13979. * Webgl Shader Library for three.js
  13980. *
  13981. * @author alteredq / http://alteredqualia.com/
  13982. * @author mrdoob / http://mrdoob.com/
  13983. * @author mikael emtinger / http://gomo.se/
  13984. */
  13985. THREE.ShaderLib = {
  13986. 'basic': {
  13987. uniforms: THREE.UniformsUtils.merge( [
  13988. THREE.UniformsLib[ "common" ],
  13989. THREE.UniformsLib[ "aomap" ],
  13990. THREE.UniformsLib[ "fog" ],
  13991. THREE.UniformsLib[ "shadowmap" ]
  13992. ] ),
  13993. vertexShader: [
  13994. THREE.ShaderChunk[ "common" ],
  13995. THREE.ShaderChunk[ "uv_pars_vertex" ],
  13996. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  13997. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  13998. THREE.ShaderChunk[ "color_pars_vertex" ],
  13999. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14000. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14001. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14002. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14003. "void main() {",
  14004. THREE.ShaderChunk[ "uv_vertex" ],
  14005. THREE.ShaderChunk[ "uv2_vertex" ],
  14006. THREE.ShaderChunk[ "color_vertex" ],
  14007. THREE.ShaderChunk[ "skinbase_vertex" ],
  14008. " #ifdef USE_ENVMAP",
  14009. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14010. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14011. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14012. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14013. " #endif",
  14014. THREE.ShaderChunk[ "begin_vertex" ],
  14015. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14016. THREE.ShaderChunk[ "skinning_vertex" ],
  14017. THREE.ShaderChunk[ "project_vertex" ],
  14018. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14019. THREE.ShaderChunk[ "worldpos_vertex" ],
  14020. THREE.ShaderChunk[ "envmap_vertex" ],
  14021. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14022. "}"
  14023. ].join( "\n" ),
  14024. fragmentShader: [
  14025. "uniform vec3 diffuse;",
  14026. "uniform float opacity;",
  14027. "#ifndef FLAT_SHADED",
  14028. " varying vec3 vNormal;",
  14029. "#endif",
  14030. THREE.ShaderChunk[ "common" ],
  14031. THREE.ShaderChunk[ "color_pars_fragment" ],
  14032. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14033. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14034. THREE.ShaderChunk[ "map_pars_fragment" ],
  14035. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14036. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14037. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14038. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14039. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14040. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14041. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14042. "void main() {",
  14043. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14044. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14045. THREE.ShaderChunk[ "map_fragment" ],
  14046. THREE.ShaderChunk[ "color_fragment" ],
  14047. THREE.ShaderChunk[ "alphamap_fragment" ],
  14048. THREE.ShaderChunk[ "alphatest_fragment" ],
  14049. THREE.ShaderChunk[ "specularmap_fragment" ],
  14050. " ReflectedLight reflectedLight;",
  14051. " reflectedLight.directDiffuse = vec3( 0.0 );",
  14052. " reflectedLight.directSpecular = vec3( 0.0 );",
  14053. " reflectedLight.indirectDiffuse = diffuseColor.rgb;",
  14054. " reflectedLight.indirectSpecular = vec3( 0.0 );",
  14055. THREE.ShaderChunk[ "aomap_fragment" ],
  14056. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14057. "reflectedLight.indirectDiffuse *= shadowMask;",
  14058. "vec3 outgoingLight = reflectedLight.indirectDiffuse;",
  14059. THREE.ShaderChunk[ "envmap_fragment" ],
  14060. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14061. THREE.ShaderChunk[ "fog_fragment" ],
  14062. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14063. "}"
  14064. ].join( "\n" )
  14065. },
  14066. 'lambert': {
  14067. uniforms: THREE.UniformsUtils.merge( [
  14068. THREE.UniformsLib[ "common" ],
  14069. THREE.UniformsLib[ "fog" ],
  14070. THREE.UniformsLib[ "lights" ],
  14071. THREE.UniformsLib[ "shadowmap" ],
  14072. {
  14073. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14074. }
  14075. ] ),
  14076. vertexShader: [
  14077. "#define LAMBERT",
  14078. "varying vec3 vLightFront;",
  14079. "#ifdef DOUBLE_SIDED",
  14080. " varying vec3 vLightBack;",
  14081. "#endif",
  14082. THREE.ShaderChunk[ "common" ],
  14083. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14084. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14085. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14086. THREE.ShaderChunk[ "bsdfs" ],
  14087. THREE.ShaderChunk[ "lights_pars" ],
  14088. THREE.ShaderChunk[ "color_pars_vertex" ],
  14089. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14090. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14091. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14092. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14093. "void main() {",
  14094. THREE.ShaderChunk[ "uv_vertex" ],
  14095. THREE.ShaderChunk[ "uv2_vertex" ],
  14096. THREE.ShaderChunk[ "color_vertex" ],
  14097. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14098. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14099. THREE.ShaderChunk[ "skinbase_vertex" ],
  14100. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14101. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14102. THREE.ShaderChunk[ "begin_vertex" ],
  14103. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14104. THREE.ShaderChunk[ "skinning_vertex" ],
  14105. THREE.ShaderChunk[ "project_vertex" ],
  14106. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14107. THREE.ShaderChunk[ "worldpos_vertex" ],
  14108. THREE.ShaderChunk[ "envmap_vertex" ],
  14109. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  14110. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14111. "}"
  14112. ].join( "\n" ),
  14113. fragmentShader: [
  14114. "uniform vec3 diffuse;",
  14115. "uniform vec3 emissive;",
  14116. "uniform float opacity;",
  14117. "uniform vec3 ambientLightColor;",
  14118. "varying vec3 vLightFront;",
  14119. "#ifdef DOUBLE_SIDED",
  14120. " varying vec3 vLightBack;",
  14121. "#endif",
  14122. THREE.ShaderChunk[ "common" ],
  14123. THREE.ShaderChunk[ "color_pars_fragment" ],
  14124. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14125. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14126. THREE.ShaderChunk[ "map_pars_fragment" ],
  14127. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14128. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14129. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14130. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14131. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14132. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14133. "void main() {",
  14134. " vec3 outgoingLight = vec3( 0.0 );",
  14135. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14136. " vec3 totalAmbientLight = PI * ambientLightColor;",
  14137. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14138. THREE.ShaderChunk[ "map_fragment" ],
  14139. THREE.ShaderChunk[ "color_fragment" ],
  14140. THREE.ShaderChunk[ "alphamap_fragment" ],
  14141. THREE.ShaderChunk[ "alphatest_fragment" ],
  14142. THREE.ShaderChunk[ "specularmap_fragment" ],
  14143. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14144. " #ifdef DOUBLE_SIDED",
  14145. " if ( gl_FrontFacing )",
  14146. " outgoingLight += RECIPROCAL_PI * diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",
  14147. " else",
  14148. " outgoingLight += RECIPROCAL_PI * diffuseColor.rgb * ( vLightBack * shadowMask + totalAmbientLight ) + emissive;",
  14149. " #else",
  14150. " outgoingLight += RECIPROCAL_PI * diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",
  14151. " #endif",
  14152. THREE.ShaderChunk[ "envmap_fragment" ],
  14153. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14154. THREE.ShaderChunk[ "fog_fragment" ],
  14155. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14156. "}"
  14157. ].join( "\n" )
  14158. },
  14159. 'phong': {
  14160. uniforms: THREE.UniformsUtils.merge( [
  14161. THREE.UniformsLib[ "common" ],
  14162. THREE.UniformsLib[ "aomap" ],
  14163. THREE.UniformsLib[ "lightmap" ],
  14164. THREE.UniformsLib[ "emissivemap" ],
  14165. THREE.UniformsLib[ "bumpmap" ],
  14166. THREE.UniformsLib[ "normalmap" ],
  14167. THREE.UniformsLib[ "displacementmap" ],
  14168. THREE.UniformsLib[ "fog" ],
  14169. THREE.UniformsLib[ "lights" ],
  14170. THREE.UniformsLib[ "shadowmap" ],
  14171. {
  14172. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14173. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14174. "shininess": { type: "f", value: 30 }
  14175. }
  14176. ] ),
  14177. vertexShader: [
  14178. "#define PHONG",
  14179. "varying vec3 vViewPosition;",
  14180. "#ifndef FLAT_SHADED",
  14181. " varying vec3 vNormal;",
  14182. "#endif",
  14183. THREE.ShaderChunk[ "common" ],
  14184. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14185. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14186. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14187. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14188. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  14189. THREE.ShaderChunk[ "color_pars_vertex" ],
  14190. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14191. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14192. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14193. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14194. "void main() {",
  14195. THREE.ShaderChunk[ "uv_vertex" ],
  14196. THREE.ShaderChunk[ "uv2_vertex" ],
  14197. THREE.ShaderChunk[ "color_vertex" ],
  14198. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14199. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14200. THREE.ShaderChunk[ "skinbase_vertex" ],
  14201. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14202. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14203. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14204. " vNormal = normalize( transformedNormal );",
  14205. "#endif",
  14206. THREE.ShaderChunk[ "begin_vertex" ],
  14207. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14208. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14209. THREE.ShaderChunk[ "skinning_vertex" ],
  14210. THREE.ShaderChunk[ "project_vertex" ],
  14211. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14212. " vViewPosition = - mvPosition.xyz;",
  14213. THREE.ShaderChunk[ "worldpos_vertex" ],
  14214. THREE.ShaderChunk[ "envmap_vertex" ],
  14215. THREE.ShaderChunk[ "lights_phong_vertex" ],
  14216. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14217. "}"
  14218. ].join( "\n" ),
  14219. fragmentShader: [
  14220. "#define PHONG",
  14221. "uniform vec3 diffuse;",
  14222. "uniform vec3 emissive;",
  14223. "uniform vec3 specular;",
  14224. "uniform float shininess;",
  14225. "uniform float opacity;",
  14226. THREE.ShaderChunk[ "common" ],
  14227. THREE.ShaderChunk[ "color_pars_fragment" ],
  14228. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14229. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14230. THREE.ShaderChunk[ "map_pars_fragment" ],
  14231. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14232. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14233. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14234. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14235. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14236. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14237. THREE.ShaderChunk[ "bsdfs" ],
  14238. THREE.ShaderChunk[ "lights_pars" ],
  14239. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  14240. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14241. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14242. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14243. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14244. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14245. "void main() {",
  14246. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14247. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14248. " vec3 totalEmissiveLight = emissive;",
  14249. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14250. THREE.ShaderChunk[ "map_fragment" ],
  14251. THREE.ShaderChunk[ "color_fragment" ],
  14252. THREE.ShaderChunk[ "alphamap_fragment" ],
  14253. THREE.ShaderChunk[ "alphatest_fragment" ],
  14254. THREE.ShaderChunk[ "specularmap_fragment" ],
  14255. THREE.ShaderChunk[ "normal_fragment" ],
  14256. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14257. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14258. // accumulation
  14259. THREE.ShaderChunk[ "lights_phong_fragment" ],
  14260. THREE.ShaderChunk[ "lights_template" ],
  14261. THREE.ShaderChunk[ "lightmap_fragment" ],
  14262. // modulation
  14263. THREE.ShaderChunk[ "aomap_fragment" ],
  14264. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14265. THREE.ShaderChunk[ "envmap_fragment" ],
  14266. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14267. THREE.ShaderChunk[ "fog_fragment" ],
  14268. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14269. "}"
  14270. ].join( "\n" )
  14271. },
  14272. 'standard': {
  14273. uniforms: THREE.UniformsUtils.merge( [
  14274. THREE.UniformsLib[ "common" ],
  14275. THREE.UniformsLib[ "aomap" ],
  14276. THREE.UniformsLib[ "lightmap" ],
  14277. THREE.UniformsLib[ "emissivemap" ],
  14278. THREE.UniformsLib[ "bumpmap" ],
  14279. THREE.UniformsLib[ "normalmap" ],
  14280. THREE.UniformsLib[ "displacementmap" ],
  14281. THREE.UniformsLib[ "roughnessmap" ],
  14282. THREE.UniformsLib[ "metalnessmap" ],
  14283. THREE.UniformsLib[ "fog" ],
  14284. THREE.UniformsLib[ "lights" ],
  14285. THREE.UniformsLib[ "shadowmap" ],
  14286. {
  14287. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14288. "roughness": { type: "f", value: 0.5 },
  14289. "metalness": { type: "f", value: 0 },
  14290. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14291. }
  14292. ] ),
  14293. vertexShader: [
  14294. "#define STANDARD",
  14295. "varying vec3 vViewPosition;",
  14296. "#ifndef FLAT_SHADED",
  14297. " varying vec3 vNormal;",
  14298. "#endif",
  14299. THREE.ShaderChunk[ "common" ],
  14300. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14301. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14302. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14303. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14304. THREE.ShaderChunk[ "color_pars_vertex" ],
  14305. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14306. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14307. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14308. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14309. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14310. "void main() {", // STANDARD
  14311. THREE.ShaderChunk[ "uv_vertex" ],
  14312. THREE.ShaderChunk[ "uv2_vertex" ],
  14313. THREE.ShaderChunk[ "color_vertex" ],
  14314. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14315. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14316. THREE.ShaderChunk[ "skinbase_vertex" ],
  14317. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14318. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14319. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14320. " vNormal = normalize( transformedNormal );",
  14321. "#endif",
  14322. THREE.ShaderChunk[ "begin_vertex" ],
  14323. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14324. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14325. THREE.ShaderChunk[ "skinning_vertex" ],
  14326. THREE.ShaderChunk[ "project_vertex" ],
  14327. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14328. " vViewPosition = - mvPosition.xyz;",
  14329. THREE.ShaderChunk[ "worldpos_vertex" ],
  14330. THREE.ShaderChunk[ "envmap_vertex" ],
  14331. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14332. "}"
  14333. ].join( "\n" ),
  14334. fragmentShader: [
  14335. "#define STANDARD",
  14336. "uniform vec3 diffuse;",
  14337. "uniform vec3 emissive;",
  14338. "uniform float roughness;",
  14339. "uniform float metalness;",
  14340. "uniform float opacity;",
  14341. "uniform float envMapIntensity;", // temporary
  14342. "varying vec3 vViewPosition;",
  14343. "#ifndef FLAT_SHADED",
  14344. " varying vec3 vNormal;",
  14345. "#endif",
  14346. THREE.ShaderChunk[ "common" ],
  14347. THREE.ShaderChunk[ "color_pars_fragment" ],
  14348. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14349. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14350. THREE.ShaderChunk[ "map_pars_fragment" ],
  14351. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14352. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14353. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14354. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14355. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14356. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14357. THREE.ShaderChunk[ "bsdfs" ],
  14358. THREE.ShaderChunk[ "lights_pars" ],
  14359. THREE.ShaderChunk[ "lights_standard_pars_fragment" ],
  14360. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14361. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14362. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14363. THREE.ShaderChunk[ "roughnessmap_pars_fragment" ],
  14364. THREE.ShaderChunk[ "metalnessmap_pars_fragment" ],
  14365. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14366. "void main() {",
  14367. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14368. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14369. " vec3 totalEmissiveLight = emissive;",
  14370. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14371. THREE.ShaderChunk[ "map_fragment" ],
  14372. THREE.ShaderChunk[ "color_fragment" ],
  14373. THREE.ShaderChunk[ "alphamap_fragment" ],
  14374. THREE.ShaderChunk[ "alphatest_fragment" ],
  14375. THREE.ShaderChunk[ "specularmap_fragment" ],
  14376. THREE.ShaderChunk[ "roughnessmap_fragment" ],
  14377. THREE.ShaderChunk[ "metalnessmap_fragment" ],
  14378. THREE.ShaderChunk[ "normal_fragment" ],
  14379. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14380. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14381. // accumulation
  14382. THREE.ShaderChunk[ "lights_standard_fragment" ],
  14383. THREE.ShaderChunk[ "lights_template" ],
  14384. THREE.ShaderChunk[ "lightmap_fragment" ],
  14385. // modulation
  14386. THREE.ShaderChunk[ "aomap_fragment" ],
  14387. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14388. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14389. THREE.ShaderChunk[ "fog_fragment" ],
  14390. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14391. "}"
  14392. ].join( "\n" )
  14393. },
  14394. 'points': {
  14395. uniforms: THREE.UniformsUtils.merge( [
  14396. THREE.UniformsLib[ "points" ],
  14397. THREE.UniformsLib[ "shadowmap" ]
  14398. ] ),
  14399. vertexShader: [
  14400. "uniform float size;",
  14401. "uniform float scale;",
  14402. THREE.ShaderChunk[ "common" ],
  14403. THREE.ShaderChunk[ "color_pars_vertex" ],
  14404. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14405. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14406. "void main() {",
  14407. THREE.ShaderChunk[ "color_vertex" ],
  14408. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14409. " #ifdef USE_SIZEATTENUATION",
  14410. " gl_PointSize = size * ( scale / -mvPosition.z );",
  14411. " #else",
  14412. " gl_PointSize = size;",
  14413. " #endif",
  14414. " gl_Position = projectionMatrix * mvPosition;",
  14415. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14416. THREE.ShaderChunk[ "worldpos_vertex" ],
  14417. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14418. "}"
  14419. ].join( "\n" ),
  14420. fragmentShader: [
  14421. "uniform vec3 psColor;",
  14422. "uniform float opacity;",
  14423. THREE.ShaderChunk[ "common" ],
  14424. THREE.ShaderChunk[ "color_pars_fragment" ],
  14425. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  14426. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14427. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14428. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14429. "void main() {",
  14430. " vec3 outgoingLight = vec3( 0.0 );",
  14431. " vec4 diffuseColor = vec4( psColor, opacity );",
  14432. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14433. THREE.ShaderChunk[ "map_particle_fragment" ],
  14434. THREE.ShaderChunk[ "color_fragment" ],
  14435. THREE.ShaderChunk[ "alphatest_fragment" ],
  14436. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14437. " outgoingLight = diffuseColor.rgb * shadowMask;",
  14438. THREE.ShaderChunk[ "fog_fragment" ],
  14439. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14440. "}"
  14441. ].join( "\n" )
  14442. },
  14443. 'dashed': {
  14444. uniforms: THREE.UniformsUtils.merge( [
  14445. THREE.UniformsLib[ "common" ],
  14446. THREE.UniformsLib[ "fog" ],
  14447. {
  14448. "scale" : { type: "f", value: 1 },
  14449. "dashSize" : { type: "f", value: 1 },
  14450. "totalSize": { type: "f", value: 2 }
  14451. }
  14452. ] ),
  14453. vertexShader: [
  14454. "uniform float scale;",
  14455. "attribute float lineDistance;",
  14456. "varying float vLineDistance;",
  14457. THREE.ShaderChunk[ "common" ],
  14458. THREE.ShaderChunk[ "color_pars_vertex" ],
  14459. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14460. "void main() {",
  14461. THREE.ShaderChunk[ "color_vertex" ],
  14462. " vLineDistance = scale * lineDistance;",
  14463. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14464. " gl_Position = projectionMatrix * mvPosition;",
  14465. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14466. "}"
  14467. ].join( "\n" ),
  14468. fragmentShader: [
  14469. "uniform vec3 diffuse;",
  14470. "uniform float opacity;",
  14471. "uniform float dashSize;",
  14472. "uniform float totalSize;",
  14473. "varying float vLineDistance;",
  14474. THREE.ShaderChunk[ "common" ],
  14475. THREE.ShaderChunk[ "color_pars_fragment" ],
  14476. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14477. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14478. "void main() {",
  14479. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  14480. " discard;",
  14481. " }",
  14482. " vec3 outgoingLight = vec3( 0.0 );",
  14483. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14484. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14485. THREE.ShaderChunk[ "color_fragment" ],
  14486. " outgoingLight = diffuseColor.rgb;", // simple shader
  14487. THREE.ShaderChunk[ "fog_fragment" ],
  14488. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14489. "}"
  14490. ].join( "\n" )
  14491. },
  14492. 'depth': {
  14493. uniforms: {
  14494. "mNear": { type: "f", value: 1.0 },
  14495. "mFar" : { type: "f", value: 2000.0 },
  14496. "opacity" : { type: "f", value: 1.0 }
  14497. },
  14498. vertexShader: [
  14499. THREE.ShaderChunk[ "common" ],
  14500. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14501. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14502. "void main() {",
  14503. THREE.ShaderChunk[ "begin_vertex" ],
  14504. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14505. THREE.ShaderChunk[ "project_vertex" ],
  14506. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14507. "}"
  14508. ].join( "\n" ),
  14509. fragmentShader: [
  14510. "uniform float mNear;",
  14511. "uniform float mFar;",
  14512. "uniform float opacity;",
  14513. THREE.ShaderChunk[ "common" ],
  14514. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14515. "void main() {",
  14516. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14517. " #ifdef USE_LOGDEPTHBUF_EXT",
  14518. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  14519. " #else",
  14520. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  14521. " #endif",
  14522. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  14523. " gl_FragColor = vec4( vec3( color ), opacity );",
  14524. "}"
  14525. ].join( "\n" )
  14526. },
  14527. 'normal': {
  14528. uniforms: {
  14529. "opacity" : { type: "f", value: 1.0 }
  14530. },
  14531. vertexShader: [
  14532. "varying vec3 vNormal;",
  14533. THREE.ShaderChunk[ "common" ],
  14534. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14535. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14536. "void main() {",
  14537. " vNormal = normalize( normalMatrix * normal );",
  14538. THREE.ShaderChunk[ "begin_vertex" ],
  14539. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14540. THREE.ShaderChunk[ "project_vertex" ],
  14541. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14542. "}"
  14543. ].join( "\n" ),
  14544. fragmentShader: [
  14545. "uniform float opacity;",
  14546. "varying vec3 vNormal;",
  14547. THREE.ShaderChunk[ "common" ],
  14548. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14549. "void main() {",
  14550. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  14551. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14552. "}"
  14553. ].join( "\n" )
  14554. },
  14555. /* -------------------------------------------------------------------------
  14556. // Cube map shader
  14557. ------------------------------------------------------------------------- */
  14558. 'cube': {
  14559. uniforms: { "tCube": { type: "t", value: null },
  14560. "tFlip": { type: "f", value: - 1 } },
  14561. vertexShader: [
  14562. "varying vec3 vWorldPosition;",
  14563. THREE.ShaderChunk[ "common" ],
  14564. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14565. "void main() {",
  14566. " vWorldPosition = transformDirection( position, modelMatrix );",
  14567. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14568. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14569. "}"
  14570. ].join( "\n" ),
  14571. fragmentShader: [
  14572. "uniform samplerCube tCube;",
  14573. "uniform float tFlip;",
  14574. "varying vec3 vWorldPosition;",
  14575. THREE.ShaderChunk[ "common" ],
  14576. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14577. "void main() {",
  14578. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14579. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14580. "}"
  14581. ].join( "\n" )
  14582. },
  14583. /* -------------------------------------------------------------------------
  14584. // Cube map shader
  14585. ------------------------------------------------------------------------- */
  14586. 'equirect': {
  14587. uniforms: { "tEquirect": { type: "t", value: null },
  14588. "tFlip": { type: "f", value: - 1 } },
  14589. vertexShader: [
  14590. "varying vec3 vWorldPosition;",
  14591. THREE.ShaderChunk[ "common" ],
  14592. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14593. "void main() {",
  14594. " vWorldPosition = transformDirection( position, modelMatrix );",
  14595. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14596. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14597. "}"
  14598. ].join( "\n" ),
  14599. fragmentShader: [
  14600. "uniform sampler2D tEquirect;",
  14601. "uniform float tFlip;",
  14602. "varying vec3 vWorldPosition;",
  14603. THREE.ShaderChunk[ "common" ],
  14604. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14605. "void main() {",
  14606. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14607. "vec3 direction = normalize( vWorldPosition );",
  14608. "vec2 sampleUV;",
  14609. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  14610. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  14611. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  14612. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14613. "}"
  14614. ].join( "\n" )
  14615. },
  14616. /* Depth encoding into RGBA texture
  14617. *
  14618. * based on SpiderGL shadow map example
  14619. * http://spidergl.org/example.php?id=6
  14620. *
  14621. * originally from
  14622. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14623. *
  14624. * see also
  14625. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14626. */
  14627. 'depthRGBA': {
  14628. uniforms: {},
  14629. vertexShader: [
  14630. THREE.ShaderChunk[ "common" ],
  14631. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14632. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14633. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14634. "void main() {",
  14635. THREE.ShaderChunk[ "skinbase_vertex" ],
  14636. THREE.ShaderChunk[ "begin_vertex" ],
  14637. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14638. THREE.ShaderChunk[ "skinning_vertex" ],
  14639. THREE.ShaderChunk[ "project_vertex" ],
  14640. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14641. "}"
  14642. ].join( "\n" ),
  14643. fragmentShader: [
  14644. THREE.ShaderChunk[ "common" ],
  14645. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14646. "vec4 pack_depth( const in float depth ) {",
  14647. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14648. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14649. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  14650. " res -= res.xxyz * bit_mask;",
  14651. " return res;",
  14652. "}",
  14653. "void main() {",
  14654. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14655. " #ifdef USE_LOGDEPTHBUF_EXT",
  14656. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  14657. " #else",
  14658. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  14659. " #endif",
  14660. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  14661. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  14662. //"gl_FragData[ 0 ] = pack_depth( z );",
  14663. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  14664. "}"
  14665. ].join( "\n" )
  14666. },
  14667. 'distanceRGBA': {
  14668. uniforms: {
  14669. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14670. },
  14671. vertexShader: [
  14672. "varying vec4 vWorldPosition;",
  14673. THREE.ShaderChunk[ "common" ],
  14674. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14675. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14676. "void main() {",
  14677. THREE.ShaderChunk[ "skinbase_vertex" ],
  14678. THREE.ShaderChunk[ "begin_vertex" ],
  14679. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14680. THREE.ShaderChunk[ "skinning_vertex" ],
  14681. THREE.ShaderChunk[ "project_vertex" ],
  14682. THREE.ShaderChunk[ "worldpos_vertex" ],
  14683. "vWorldPosition = worldPosition;",
  14684. "}"
  14685. ].join( "\n" ),
  14686. fragmentShader: [
  14687. "uniform vec3 lightPos;",
  14688. "varying vec4 vWorldPosition;",
  14689. THREE.ShaderChunk[ "common" ],
  14690. "vec4 pack1K ( float depth ) {",
  14691. " depth /= 1000.0;",
  14692. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14693. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14694. " vec4 res = fract( depth * bitSh );",
  14695. " res -= res.xxyz * bitMsk;",
  14696. " return res; ",
  14697. "}",
  14698. "float unpack1K ( vec4 color ) {",
  14699. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  14700. " return dot( color, bitSh ) * 1000.0;",
  14701. "}",
  14702. "void main () {",
  14703. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  14704. "}"
  14705. ].join( "\n" )
  14706. }
  14707. };
  14708. // File:src/renderers/WebGLRenderer.js
  14709. /**
  14710. * @author supereggbert / http://www.paulbrunt.co.uk/
  14711. * @author mrdoob / http://mrdoob.com/
  14712. * @author alteredq / http://alteredqualia.com/
  14713. * @author szimek / https://github.com/szimek/
  14714. */
  14715. THREE.WebGLRenderer = function ( parameters ) {
  14716. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14717. parameters = parameters || {};
  14718. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14719. _context = parameters.context !== undefined ? parameters.context : null,
  14720. _width = _canvas.width,
  14721. _height = _canvas.height,
  14722. pixelRatio = 1,
  14723. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14724. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14725. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14726. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14727. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14728. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14729. _clearColor = new THREE.Color( 0x000000 ),
  14730. _clearAlpha = 0;
  14731. var lights = [];
  14732. var opaqueObjects = [];
  14733. var opaqueObjectsLastIndex = - 1;
  14734. var transparentObjects = [];
  14735. var transparentObjectsLastIndex = - 1;
  14736. var morphInfluences = new Float32Array( 8 );
  14737. var sprites = [];
  14738. var lensFlares = [];
  14739. // public properties
  14740. this.domElement = _canvas;
  14741. this.context = null;
  14742. // clearing
  14743. this.autoClear = true;
  14744. this.autoClearColor = true;
  14745. this.autoClearDepth = true;
  14746. this.autoClearStencil = true;
  14747. // scene graph
  14748. this.sortObjects = true;
  14749. // physically based shading
  14750. this.gammaFactor = 2.0; // for backwards compatibility
  14751. this.gammaInput = false;
  14752. this.gammaOutput = false;
  14753. // morphs
  14754. this.maxMorphTargets = 8;
  14755. this.maxMorphNormals = 4;
  14756. // flags
  14757. this.autoScaleCubemaps = true;
  14758. // internal properties
  14759. var _this = this,
  14760. // internal state cache
  14761. _currentProgram = null,
  14762. _currentFramebuffer = null,
  14763. _currentMaterialId = - 1,
  14764. _currentGeometryProgram = '',
  14765. _currentCamera = null,
  14766. _usedTextureUnits = 0,
  14767. _viewportX = 0,
  14768. _viewportY = 0,
  14769. _viewportWidth = _canvas.width,
  14770. _viewportHeight = _canvas.height,
  14771. _currentWidth = 0,
  14772. _currentHeight = 0,
  14773. // frustum
  14774. _frustum = new THREE.Frustum(),
  14775. // camera matrices cache
  14776. _projScreenMatrix = new THREE.Matrix4(),
  14777. _vector3 = new THREE.Vector3(),
  14778. // light arrays cache
  14779. _lights = {
  14780. hash: '',
  14781. ambient: [ 0, 0, 0 ],
  14782. directional: [],
  14783. point: [],
  14784. spot: [],
  14785. hemi: [],
  14786. shadows: [],
  14787. shadowsPointLight: 0
  14788. },
  14789. // info
  14790. _infoMemory = {
  14791. geometries: 0,
  14792. textures: 0
  14793. },
  14794. _infoRender = {
  14795. calls: 0,
  14796. vertices: 0,
  14797. faces: 0,
  14798. points: 0
  14799. };
  14800. this.info = {
  14801. render: _infoRender,
  14802. memory: _infoMemory,
  14803. programs: null
  14804. };
  14805. // initialize
  14806. var _gl;
  14807. try {
  14808. var attributes = {
  14809. alpha: _alpha,
  14810. depth: _depth,
  14811. stencil: _stencil,
  14812. antialias: _antialias,
  14813. premultipliedAlpha: _premultipliedAlpha,
  14814. preserveDrawingBuffer: _preserveDrawingBuffer
  14815. };
  14816. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14817. if ( _gl === null ) {
  14818. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14819. throw 'Error creating WebGL context with your selected attributes.';
  14820. } else {
  14821. throw 'Error creating WebGL context.';
  14822. }
  14823. }
  14824. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14825. } catch ( error ) {
  14826. console.error( 'THREE.WebGLRenderer: ' + error );
  14827. }
  14828. var extensions = new THREE.WebGLExtensions( _gl );
  14829. extensions.get( 'OES_texture_float' );
  14830. extensions.get( 'OES_texture_float_linear' );
  14831. extensions.get( 'OES_texture_half_float' );
  14832. extensions.get( 'OES_texture_half_float_linear' );
  14833. extensions.get( 'OES_standard_derivatives' );
  14834. extensions.get( 'ANGLE_instanced_arrays' );
  14835. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14836. THREE.BufferGeometry.MaxIndex = 4294967296;
  14837. }
  14838. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14839. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14840. var properties = new THREE.WebGLProperties();
  14841. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14842. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14843. var lightCache = new THREE.WebGLLights();
  14844. this.info.programs = programCache.programs;
  14845. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14846. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14847. //
  14848. function glClearColor( r, g, b, a ) {
  14849. if ( _premultipliedAlpha === true ) {
  14850. r *= a; g *= a; b *= a;
  14851. }
  14852. _gl.clearColor( r, g, b, a );
  14853. }
  14854. function setDefaultGLState() {
  14855. state.init();
  14856. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  14857. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14858. }
  14859. function resetGLState() {
  14860. _currentProgram = null;
  14861. _currentCamera = null;
  14862. _currentGeometryProgram = '';
  14863. _currentMaterialId = - 1;
  14864. state.reset();
  14865. }
  14866. setDefaultGLState();
  14867. this.context = _gl;
  14868. this.capabilities = capabilities;
  14869. this.extensions = extensions;
  14870. this.state = state;
  14871. // shadow map
  14872. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14873. this.shadowMap = shadowMap;
  14874. // Plugins
  14875. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14876. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14877. // API
  14878. this.getContext = function () {
  14879. return _gl;
  14880. };
  14881. this.getContextAttributes = function () {
  14882. return _gl.getContextAttributes();
  14883. };
  14884. this.forceContextLoss = function () {
  14885. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14886. };
  14887. this.getMaxAnisotropy = ( function () {
  14888. var value;
  14889. return function getMaxAnisotropy() {
  14890. if ( value !== undefined ) return value;
  14891. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14892. if ( extension !== null ) {
  14893. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14894. } else {
  14895. value = 0;
  14896. }
  14897. return value;
  14898. }
  14899. } )();
  14900. this.getPrecision = function () {
  14901. return capabilities.precision;
  14902. };
  14903. this.getPixelRatio = function () {
  14904. return pixelRatio;
  14905. };
  14906. this.setPixelRatio = function ( value ) {
  14907. if ( value !== undefined ) pixelRatio = value;
  14908. };
  14909. this.getSize = function () {
  14910. return {
  14911. width: _width,
  14912. height: _height
  14913. };
  14914. };
  14915. this.setSize = function ( width, height, updateStyle ) {
  14916. _width = width;
  14917. _height = height;
  14918. _canvas.width = width * pixelRatio;
  14919. _canvas.height = height * pixelRatio;
  14920. if ( updateStyle !== false ) {
  14921. _canvas.style.width = width + 'px';
  14922. _canvas.style.height = height + 'px';
  14923. }
  14924. this.setViewport( 0, 0, width, height );
  14925. };
  14926. this.setViewport = function ( x, y, width, height ) {
  14927. _viewportX = x * pixelRatio;
  14928. _viewportY = y * pixelRatio;
  14929. _viewportWidth = width * pixelRatio;
  14930. _viewportHeight = height * pixelRatio;
  14931. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  14932. };
  14933. this.getViewport = function ( dimensions ) {
  14934. dimensions.x = _viewportX / pixelRatio;
  14935. dimensions.y = _viewportY / pixelRatio;
  14936. dimensions.z = _viewportWidth / pixelRatio;
  14937. dimensions.w = _viewportHeight / pixelRatio;
  14938. };
  14939. this.setScissor = function ( x, y, width, height ) {
  14940. _gl.scissor(
  14941. x * pixelRatio,
  14942. y * pixelRatio,
  14943. width * pixelRatio,
  14944. height * pixelRatio
  14945. );
  14946. };
  14947. this.enableScissorTest = function ( boolean ) {
  14948. state.setScissorTest( boolean );
  14949. };
  14950. // Clearing
  14951. this.getClearColor = function () {
  14952. return _clearColor;
  14953. };
  14954. this.setClearColor = function ( color, alpha ) {
  14955. _clearColor.set( color );
  14956. _clearAlpha = alpha !== undefined ? alpha : 1;
  14957. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14958. };
  14959. this.getClearAlpha = function () {
  14960. return _clearAlpha;
  14961. };
  14962. this.setClearAlpha = function ( alpha ) {
  14963. _clearAlpha = alpha;
  14964. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14965. };
  14966. this.clear = function ( color, depth, stencil ) {
  14967. var bits = 0;
  14968. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14969. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14970. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14971. _gl.clear( bits );
  14972. };
  14973. this.clearColor = function () {
  14974. _gl.clear( _gl.COLOR_BUFFER_BIT );
  14975. };
  14976. this.clearDepth = function () {
  14977. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  14978. };
  14979. this.clearStencil = function () {
  14980. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  14981. };
  14982. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14983. this.setRenderTarget( renderTarget );
  14984. this.clear( color, depth, stencil );
  14985. };
  14986. // Reset
  14987. this.resetGLState = resetGLState;
  14988. this.dispose = function() {
  14989. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14990. };
  14991. // Events
  14992. function onContextLost( event ) {
  14993. event.preventDefault();
  14994. resetGLState();
  14995. setDefaultGLState();
  14996. properties.clear();
  14997. };
  14998. function onTextureDispose( event ) {
  14999. var texture = event.target;
  15000. texture.removeEventListener( 'dispose', onTextureDispose );
  15001. deallocateTexture( texture );
  15002. _infoMemory.textures --;
  15003. }
  15004. function onRenderTargetDispose( event ) {
  15005. var renderTarget = event.target;
  15006. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  15007. deallocateRenderTarget( renderTarget );
  15008. _infoMemory.textures --;
  15009. }
  15010. function onMaterialDispose( event ) {
  15011. var material = event.target;
  15012. material.removeEventListener( 'dispose', onMaterialDispose );
  15013. deallocateMaterial( material );
  15014. }
  15015. // Buffer deallocation
  15016. function deallocateTexture( texture ) {
  15017. var textureProperties = properties.get( texture );
  15018. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  15019. // cube texture
  15020. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  15021. } else {
  15022. // 2D texture
  15023. if ( textureProperties.__webglInit === undefined ) return;
  15024. _gl.deleteTexture( textureProperties.__webglTexture );
  15025. }
  15026. // remove all webgl properties
  15027. properties.delete( texture );
  15028. }
  15029. function deallocateRenderTarget( renderTarget ) {
  15030. var renderTargetProperties = properties.get( renderTarget );
  15031. var textureProperties = properties.get( renderTarget.texture );
  15032. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  15033. _gl.deleteTexture( textureProperties.__webglTexture );
  15034. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  15035. for ( var i = 0; i < 6; i ++ ) {
  15036. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  15037. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  15038. }
  15039. } else {
  15040. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  15041. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  15042. }
  15043. properties.delete( renderTarget.texture );
  15044. properties.delete( renderTarget );
  15045. }
  15046. function deallocateMaterial( material ) {
  15047. releaseMaterialProgramReference( material );
  15048. properties.delete( material );
  15049. }
  15050. function releaseMaterialProgramReference( material ) {
  15051. var programInfo = properties.get( material ).program;
  15052. material.program = undefined;
  15053. if ( programInfo !== undefined ) {
  15054. programCache.releaseProgram( programInfo );
  15055. }
  15056. }
  15057. // Buffer rendering
  15058. this.renderBufferImmediate = function ( object, program, material ) {
  15059. state.initAttributes();
  15060. var buffers = properties.get( object );
  15061. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15062. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15063. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15064. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15065. var attributes = program.getAttributes();
  15066. if ( object.hasPositions ) {
  15067. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  15068. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  15069. state.enableAttribute( attributes.position );
  15070. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  15071. }
  15072. if ( object.hasNormals ) {
  15073. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15074. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.shading === THREE.FlatShading ) {
  15075. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15076. var array = object.normalArray;
  15077. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15078. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15079. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15080. array[ i + 0 ] = nx;
  15081. array[ i + 1 ] = ny;
  15082. array[ i + 2 ] = nz;
  15083. array[ i + 3 ] = nx;
  15084. array[ i + 4 ] = ny;
  15085. array[ i + 5 ] = nz;
  15086. array[ i + 6 ] = nx;
  15087. array[ i + 7 ] = ny;
  15088. array[ i + 8 ] = nz;
  15089. }
  15090. }
  15091. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15092. state.enableAttribute( attributes.normal );
  15093. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15094. }
  15095. if ( object.hasUvs && material.map ) {
  15096. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15097. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15098. state.enableAttribute( attributes.uv );
  15099. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15100. }
  15101. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15102. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15103. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15104. state.enableAttribute( attributes.color );
  15105. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15106. }
  15107. state.disableUnusedAttributes();
  15108. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15109. object.count = 0;
  15110. };
  15111. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15112. setMaterial( material );
  15113. var program = setProgram( camera, fog, material, object );
  15114. var updateBuffers = false;
  15115. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15116. if ( geometryProgram !== _currentGeometryProgram ) {
  15117. _currentGeometryProgram = geometryProgram;
  15118. updateBuffers = true;
  15119. }
  15120. // morph targets
  15121. var morphTargetInfluences = object.morphTargetInfluences;
  15122. if ( morphTargetInfluences !== undefined ) {
  15123. var activeInfluences = [];
  15124. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15125. var influence = morphTargetInfluences[ i ];
  15126. activeInfluences.push( [ influence, i ] );
  15127. }
  15128. activeInfluences.sort( numericalSort );
  15129. if ( activeInfluences.length > 8 ) {
  15130. activeInfluences.length = 8;
  15131. }
  15132. var morphAttributes = geometry.morphAttributes;
  15133. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15134. var influence = activeInfluences[ i ];
  15135. morphInfluences[ i ] = influence[ 0 ];
  15136. if ( influence[ 0 ] !== 0 ) {
  15137. var index = influence[ 1 ];
  15138. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15139. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15140. } else {
  15141. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15142. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15143. }
  15144. }
  15145. var uniforms = program.getUniforms();
  15146. if ( uniforms.morphTargetInfluences !== null ) {
  15147. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  15148. }
  15149. updateBuffers = true;
  15150. }
  15151. //
  15152. var index = geometry.index;
  15153. var position = geometry.attributes.position;
  15154. if ( material.wireframe === true ) {
  15155. index = objects.getWireframeAttribute( geometry );
  15156. }
  15157. var renderer;
  15158. if ( index !== null ) {
  15159. renderer = indexedBufferRenderer;
  15160. renderer.setIndex( index );
  15161. } else {
  15162. renderer = bufferRenderer;
  15163. }
  15164. if ( updateBuffers ) {
  15165. setupVertexAttributes( material, program, geometry );
  15166. if ( index !== null ) {
  15167. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15168. }
  15169. }
  15170. //
  15171. var dataStart = 0;
  15172. var dataCount = Infinity;
  15173. if ( index !== null ) {
  15174. dataCount = index.count
  15175. } else if ( position !== undefined ) {
  15176. dataCount = position.count;
  15177. }
  15178. var rangeStart = geometry.drawRange.start;
  15179. var rangeCount = geometry.drawRange.count;
  15180. var groupStart = group !== null ? group.start : 0;
  15181. var groupCount = group !== null ? group.count : Infinity;
  15182. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15183. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15184. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15185. //
  15186. if ( object instanceof THREE.Mesh ) {
  15187. if ( material.wireframe === true ) {
  15188. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  15189. renderer.setMode( _gl.LINES );
  15190. } else {
  15191. switch ( object.drawMode ) {
  15192. case THREE.TrianglesDrawMode:
  15193. renderer.setMode( _gl.TRIANGLES );
  15194. break;
  15195. case THREE.TriangleStripDrawMode:
  15196. renderer.setMode( _gl.TRIANGLE_STRIP );
  15197. break;
  15198. case THREE.TriangleFanDrawMode:
  15199. renderer.setMode( _gl.TRIANGLE_FAN );
  15200. break;
  15201. }
  15202. }
  15203. } else if ( object instanceof THREE.Line ) {
  15204. var lineWidth = material.linewidth;
  15205. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15206. state.setLineWidth( lineWidth * pixelRatio );
  15207. if ( object instanceof THREE.LineSegments ) {
  15208. renderer.setMode( _gl.LINES );
  15209. } else {
  15210. renderer.setMode( _gl.LINE_STRIP );
  15211. }
  15212. } else if ( object instanceof THREE.Points ) {
  15213. renderer.setMode( _gl.POINTS );
  15214. }
  15215. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  15216. renderer.renderInstances( geometry, drawStart, drawCount );
  15217. } else {
  15218. renderer.render( drawStart, drawCount );
  15219. }
  15220. };
  15221. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15222. var extension;
  15223. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15224. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15225. if ( extension === null ) {
  15226. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15227. return;
  15228. }
  15229. }
  15230. if ( startIndex === undefined ) startIndex = 0;
  15231. state.initAttributes();
  15232. var geometryAttributes = geometry.attributes;
  15233. var programAttributes = program.getAttributes();
  15234. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15235. for ( var name in programAttributes ) {
  15236. var programAttribute = programAttributes[ name ];
  15237. if ( programAttribute >= 0 ) {
  15238. var geometryAttribute = geometryAttributes[ name ];
  15239. if ( geometryAttribute !== undefined ) {
  15240. var size = geometryAttribute.itemSize;
  15241. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15242. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15243. var data = geometryAttribute.data;
  15244. var stride = data.stride;
  15245. var offset = geometryAttribute.offset;
  15246. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15247. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15248. if ( geometry.maxInstancedCount === undefined ) {
  15249. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15250. }
  15251. } else {
  15252. state.enableAttribute( programAttribute );
  15253. }
  15254. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15255. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15256. } else {
  15257. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15258. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15259. if ( geometry.maxInstancedCount === undefined ) {
  15260. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15261. }
  15262. } else {
  15263. state.enableAttribute( programAttribute );
  15264. }
  15265. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15266. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15267. }
  15268. } else if ( materialDefaultAttributeValues !== undefined ) {
  15269. var value = materialDefaultAttributeValues[ name ];
  15270. if ( value !== undefined ) {
  15271. switch ( value.length ) {
  15272. case 2:
  15273. _gl.vertexAttrib2fv( programAttribute, value );
  15274. break;
  15275. case 3:
  15276. _gl.vertexAttrib3fv( programAttribute, value );
  15277. break;
  15278. case 4:
  15279. _gl.vertexAttrib4fv( programAttribute, value );
  15280. break;
  15281. default:
  15282. _gl.vertexAttrib1fv( programAttribute, value );
  15283. }
  15284. }
  15285. }
  15286. }
  15287. }
  15288. state.disableUnusedAttributes();
  15289. }
  15290. // Sorting
  15291. function numericalSort ( a, b ) {
  15292. return b[ 0 ] - a[ 0 ];
  15293. }
  15294. function painterSortStable ( a, b ) {
  15295. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15296. return a.object.renderOrder - b.object.renderOrder;
  15297. } else if ( a.material.id !== b.material.id ) {
  15298. return a.material.id - b.material.id;
  15299. } else if ( a.z !== b.z ) {
  15300. return a.z - b.z;
  15301. } else {
  15302. return a.id - b.id;
  15303. }
  15304. }
  15305. function reversePainterSortStable ( a, b ) {
  15306. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15307. return a.object.renderOrder - b.object.renderOrder;
  15308. } if ( a.z !== b.z ) {
  15309. return b.z - a.z;
  15310. } else {
  15311. return a.id - b.id;
  15312. }
  15313. }
  15314. // Rendering
  15315. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15316. if ( camera instanceof THREE.Camera === false ) {
  15317. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15318. return;
  15319. }
  15320. var fog = scene.fog;
  15321. // reset caching for this frame
  15322. _currentGeometryProgram = '';
  15323. _currentMaterialId = - 1;
  15324. _currentCamera = null;
  15325. // update scene graph
  15326. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15327. // update camera matrices and frustum
  15328. if ( camera.parent === null ) camera.updateMatrixWorld();
  15329. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15330. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15331. _frustum.setFromMatrix( _projScreenMatrix );
  15332. lights.length = 0;
  15333. opaqueObjectsLastIndex = - 1;
  15334. transparentObjectsLastIndex = - 1;
  15335. sprites.length = 0;
  15336. lensFlares.length = 0;
  15337. projectObject( scene, camera );
  15338. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15339. transparentObjects.length = transparentObjectsLastIndex + 1;
  15340. if ( _this.sortObjects === true ) {
  15341. opaqueObjects.sort( painterSortStable );
  15342. transparentObjects.sort( reversePainterSortStable );
  15343. }
  15344. setupLights( lights, camera );
  15345. //
  15346. shadowMap.render( scene, camera );
  15347. //
  15348. _infoRender.calls = 0;
  15349. _infoRender.vertices = 0;
  15350. _infoRender.faces = 0;
  15351. _infoRender.points = 0;
  15352. this.setRenderTarget( renderTarget );
  15353. if ( this.autoClear || forceClear ) {
  15354. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15355. }
  15356. //
  15357. if ( scene.overrideMaterial ) {
  15358. var overrideMaterial = scene.overrideMaterial;
  15359. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15360. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15361. } else {
  15362. // opaque pass (front-to-back order)
  15363. state.setBlending( THREE.NoBlending );
  15364. renderObjects( opaqueObjects, camera, fog );
  15365. // transparent pass (back-to-front order)
  15366. renderObjects( transparentObjects, camera, fog );
  15367. }
  15368. // custom render plugins (post pass)
  15369. spritePlugin.render( scene, camera );
  15370. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  15371. // Generate mipmap if we're using any kind of mipmap filtering
  15372. if ( renderTarget ) {
  15373. var texture = renderTarget.texture;
  15374. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15375. texture.minFilter !== THREE.NearestFilter &&
  15376. texture.minFilter !== THREE.LinearFilter ) {
  15377. updateRenderTargetMipmap( renderTarget );
  15378. }
  15379. }
  15380. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15381. state.setDepthTest( true );
  15382. state.setDepthWrite( true );
  15383. state.setColorWrite( true );
  15384. // _gl.finish();
  15385. };
  15386. function pushRenderItem( object, geometry, material, z, group ) {
  15387. var array, index;
  15388. // allocate the next position in the appropriate array
  15389. if ( material.transparent ) {
  15390. array = transparentObjects;
  15391. index = ++ transparentObjectsLastIndex;
  15392. } else {
  15393. array = opaqueObjects;
  15394. index = ++ opaqueObjectsLastIndex;
  15395. }
  15396. // recycle existing render item or grow the array
  15397. var renderItem = array[ index ];
  15398. if ( renderItem !== undefined ) {
  15399. renderItem.id = object.id;
  15400. renderItem.object = object;
  15401. renderItem.geometry = geometry;
  15402. renderItem.material = material;
  15403. renderItem.z = _vector3.z;
  15404. renderItem.group = group;
  15405. } else {
  15406. renderItem = {
  15407. id: object.id,
  15408. object: object,
  15409. geometry: geometry,
  15410. material: material,
  15411. z: _vector3.z,
  15412. group: group
  15413. };
  15414. // assert( index === array.length );
  15415. array.push( renderItem );
  15416. }
  15417. }
  15418. function projectObject( object, camera ) {
  15419. if ( object.visible === false ) return;
  15420. if ( object.layers.test( camera.layers ) ) {
  15421. if ( object instanceof THREE.Light ) {
  15422. lights.push( object );
  15423. } else if ( object instanceof THREE.Sprite ) {
  15424. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15425. sprites.push( object );
  15426. }
  15427. } else if ( object instanceof THREE.LensFlare ) {
  15428. lensFlares.push( object );
  15429. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15430. if ( _this.sortObjects === true ) {
  15431. _vector3.setFromMatrixPosition( object.matrixWorld );
  15432. _vector3.applyProjection( _projScreenMatrix );
  15433. }
  15434. pushRenderItem( object, null, object.material, _vector3.z, null );
  15435. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15436. if ( object instanceof THREE.SkinnedMesh ) {
  15437. object.skeleton.update();
  15438. }
  15439. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15440. var material = object.material;
  15441. if ( material.visible === true ) {
  15442. if ( _this.sortObjects === true ) {
  15443. _vector3.setFromMatrixPosition( object.matrixWorld );
  15444. _vector3.applyProjection( _projScreenMatrix );
  15445. }
  15446. var geometry = objects.update( object );
  15447. if ( material instanceof THREE.MeshFaceMaterial ) {
  15448. var groups = geometry.groups;
  15449. var materials = material.materials;
  15450. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15451. var group = groups[ i ];
  15452. var groupMaterial = materials[ group.materialIndex ];
  15453. if ( groupMaterial.visible === true ) {
  15454. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15455. }
  15456. }
  15457. } else {
  15458. pushRenderItem( object, geometry, material, _vector3.z, null );
  15459. }
  15460. }
  15461. }
  15462. }
  15463. }
  15464. var children = object.children;
  15465. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15466. projectObject( children[ i ], camera );
  15467. }
  15468. }
  15469. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15470. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15471. var renderItem = renderList[ i ];
  15472. var object = renderItem.object;
  15473. var geometry = renderItem.geometry;
  15474. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15475. var group = renderItem.group;
  15476. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15477. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15478. if ( object instanceof THREE.ImmediateRenderObject ) {
  15479. setMaterial( material );
  15480. var program = setProgram( camera, fog, material, object );
  15481. _currentGeometryProgram = '';
  15482. object.render( function ( object ) {
  15483. _this.renderBufferImmediate( object, program, material );
  15484. } );
  15485. } else {
  15486. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15487. }
  15488. }
  15489. }
  15490. function initMaterial( material, fog, object ) {
  15491. var materialProperties = properties.get( material );
  15492. var parameters = programCache.getParameters( material, _lights, fog, object );
  15493. var code = programCache.getProgramCode( material, parameters );
  15494. var program = materialProperties.program;
  15495. var programChange = true;
  15496. if ( program === undefined ) {
  15497. // new material
  15498. material.addEventListener( 'dispose', onMaterialDispose );
  15499. } else if ( program.code !== code ) {
  15500. // changed glsl or parameters
  15501. releaseMaterialProgramReference( material );
  15502. } else if ( parameters.shaderID !== undefined ) {
  15503. // same glsl and uniform list
  15504. return;
  15505. } else {
  15506. // only rebuild uniform list
  15507. programChange = false;
  15508. }
  15509. if ( programChange ) {
  15510. if ( parameters.shaderID ) {
  15511. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15512. materialProperties.__webglShader = {
  15513. name: material.type,
  15514. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15515. vertexShader: shader.vertexShader,
  15516. fragmentShader: shader.fragmentShader
  15517. };
  15518. } else {
  15519. materialProperties.__webglShader = {
  15520. name: material.type,
  15521. uniforms: material.uniforms,
  15522. vertexShader: material.vertexShader,
  15523. fragmentShader: material.fragmentShader
  15524. };
  15525. }
  15526. material.__webglShader = materialProperties.__webglShader;
  15527. program = programCache.acquireProgram( material, parameters, code );
  15528. materialProperties.program = program;
  15529. material.program = program;
  15530. }
  15531. var attributes = program.getAttributes();
  15532. if ( material.morphTargets ) {
  15533. material.numSupportedMorphTargets = 0;
  15534. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15535. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15536. material.numSupportedMorphTargets ++;
  15537. }
  15538. }
  15539. }
  15540. if ( material.morphNormals ) {
  15541. material.numSupportedMorphNormals = 0;
  15542. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  15543. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15544. material.numSupportedMorphNormals ++;
  15545. }
  15546. }
  15547. }
  15548. materialProperties.uniformsList = [];
  15549. var uniforms = materialProperties.__webglShader.uniforms,
  15550. uniformLocations = materialProperties.program.getUniforms();
  15551. for ( var u in uniforms ) {
  15552. var location = uniformLocations[ u ];
  15553. if ( location ) {
  15554. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15555. }
  15556. }
  15557. if ( material instanceof THREE.MeshPhongMaterial ||
  15558. material instanceof THREE.MeshLambertMaterial ||
  15559. material instanceof THREE.MeshStandardMaterial ||
  15560. material.lights ) {
  15561. // store the light setup it was created for
  15562. materialProperties.lightsHash = _lights.hash;
  15563. // wire up the material to this renderer's lighting state
  15564. uniforms.ambientLightColor.value = _lights.ambient;
  15565. uniforms.directionalLights.value = _lights.directional;
  15566. uniforms.pointLights.value = _lights.point;
  15567. uniforms.spotLights.value = _lights.spot;
  15568. uniforms.hemisphereLights.value = _lights.hemi;
  15569. }
  15570. // detect dynamic uniforms
  15571. materialProperties.hasDynamicUniforms = false;
  15572. for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
  15573. var uniform = materialProperties.uniformsList[ j ][ 0 ];
  15574. if ( uniform.dynamic === true ) {
  15575. materialProperties.hasDynamicUniforms = true;
  15576. break;
  15577. }
  15578. }
  15579. }
  15580. function setMaterial( material ) {
  15581. setMaterialFaces( material );
  15582. if ( material.transparent === true ) {
  15583. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  15584. } else {
  15585. state.setBlending( THREE.NoBlending );
  15586. }
  15587. state.setDepthFunc( material.depthFunc );
  15588. state.setDepthTest( material.depthTest );
  15589. state.setDepthWrite( material.depthWrite );
  15590. state.setColorWrite( material.colorWrite );
  15591. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15592. }
  15593. function setMaterialFaces( material ) {
  15594. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15595. state.setFlipSided( material.side === THREE.BackSide );
  15596. }
  15597. function setProgram( camera, fog, material, object ) {
  15598. _usedTextureUnits = 0;
  15599. var materialProperties = properties.get( material );
  15600. if ( materialProperties.program === undefined ) {
  15601. material.needsUpdate = true;
  15602. }
  15603. if ( materialProperties.lightsHash !== undefined &&
  15604. materialProperties.lightsHash !== _lights.hash ) {
  15605. material.needsUpdate = true;
  15606. }
  15607. if ( material.needsUpdate ) {
  15608. initMaterial( material, fog, object );
  15609. material.needsUpdate = false;
  15610. }
  15611. var refreshProgram = false;
  15612. var refreshMaterial = false;
  15613. var refreshLights = false;
  15614. var program = materialProperties.program,
  15615. p_uniforms = program.getUniforms(),
  15616. m_uniforms = materialProperties.__webglShader.uniforms;
  15617. if ( program.id !== _currentProgram ) {
  15618. _gl.useProgram( program.program );
  15619. _currentProgram = program.id;
  15620. refreshProgram = true;
  15621. refreshMaterial = true;
  15622. refreshLights = true;
  15623. }
  15624. if ( material.id !== _currentMaterialId ) {
  15625. _currentMaterialId = material.id;
  15626. refreshMaterial = true;
  15627. }
  15628. if ( refreshProgram || camera !== _currentCamera ) {
  15629. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15630. if ( capabilities.logarithmicDepthBuffer ) {
  15631. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15632. }
  15633. if ( camera !== _currentCamera ) {
  15634. _currentCamera = camera;
  15635. // lighting uniforms depend on the camera so enforce an update
  15636. // now, in case this material supports lights - or later, when
  15637. // the next material that does gets activated:
  15638. refreshMaterial = true; // set to true on material change
  15639. refreshLights = true; // remains set until update done
  15640. }
  15641. // load material specific uniforms
  15642. // (shader material also gets them for the sake of genericity)
  15643. if ( material instanceof THREE.ShaderMaterial ||
  15644. material instanceof THREE.MeshPhongMaterial ||
  15645. material instanceof THREE.MeshStandardMaterial ||
  15646. material.envMap ) {
  15647. if ( p_uniforms.cameraPosition !== undefined ) {
  15648. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15649. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15650. }
  15651. }
  15652. if ( material instanceof THREE.MeshPhongMaterial ||
  15653. material instanceof THREE.MeshLambertMaterial ||
  15654. material instanceof THREE.MeshBasicMaterial ||
  15655. material instanceof THREE.MeshStandardMaterial ||
  15656. material instanceof THREE.ShaderMaterial ||
  15657. material.skinning ) {
  15658. if ( p_uniforms.viewMatrix !== undefined ) {
  15659. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15660. }
  15661. }
  15662. }
  15663. // skinning uniforms must be set even if material didn't change
  15664. // auto-setting of texture unit for bone texture must go before other textures
  15665. // not sure why, but otherwise weird things happen
  15666. if ( material.skinning ) {
  15667. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15668. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15669. }
  15670. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15671. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15672. }
  15673. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15674. if ( p_uniforms.boneTexture !== undefined ) {
  15675. var textureUnit = getTextureUnit();
  15676. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15677. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15678. }
  15679. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15680. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15681. }
  15682. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15683. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15684. }
  15685. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15686. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15687. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15688. }
  15689. }
  15690. }
  15691. if ( refreshMaterial ) {
  15692. if ( material instanceof THREE.MeshPhongMaterial ||
  15693. material instanceof THREE.MeshLambertMaterial ||
  15694. material instanceof THREE.MeshStandardMaterial ||
  15695. material.lights ) {
  15696. // the current material requires lighting info
  15697. // note: all lighting uniforms are always set correctly
  15698. // they simply reference the renderer's state for their
  15699. // values
  15700. //
  15701. // use the current material's .needsUpdate flags to set
  15702. // the GL state when required
  15703. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15704. }
  15705. // refresh uniforms common to several materials
  15706. if ( fog && material.fog ) {
  15707. refreshUniformsFog( m_uniforms, fog );
  15708. }
  15709. if ( material instanceof THREE.MeshBasicMaterial ||
  15710. material instanceof THREE.MeshLambertMaterial ||
  15711. material instanceof THREE.MeshPhongMaterial ||
  15712. material instanceof THREE.MeshStandardMaterial ) {
  15713. refreshUniformsCommon( m_uniforms, material );
  15714. }
  15715. // refresh single material specific uniforms
  15716. if ( material instanceof THREE.LineBasicMaterial ) {
  15717. refreshUniformsLine( m_uniforms, material );
  15718. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15719. refreshUniformsLine( m_uniforms, material );
  15720. refreshUniformsDash( m_uniforms, material );
  15721. } else if ( material instanceof THREE.PointsMaterial ) {
  15722. refreshUniformsPoints( m_uniforms, material );
  15723. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15724. refreshUniformsPhong( m_uniforms, material );
  15725. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15726. refreshUniformsStandard( m_uniforms, material );
  15727. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15728. m_uniforms.mNear.value = camera.near;
  15729. m_uniforms.mFar.value = camera.far;
  15730. m_uniforms.opacity.value = material.opacity;
  15731. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15732. m_uniforms.opacity.value = material.opacity;
  15733. }
  15734. if ( shadowMap.enabled ) {
  15735. if ( object.receiveShadow && ! material._shadowPass ) {
  15736. refreshUniformsShadow( m_uniforms, camera );
  15737. }
  15738. }
  15739. // load common uniforms
  15740. loadUniformsGeneric( materialProperties.uniformsList );
  15741. }
  15742. loadUniformsMatrices( p_uniforms, object );
  15743. if ( p_uniforms.modelMatrix !== undefined ) {
  15744. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15745. }
  15746. if ( materialProperties.hasDynamicUniforms === true ) {
  15747. updateDynamicUniforms( materialProperties.uniformsList, object, camera );
  15748. }
  15749. return program;
  15750. }
  15751. function updateDynamicUniforms ( uniforms, object, camera ) {
  15752. var dynamicUniforms = [];
  15753. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15754. var uniform = uniforms[ j ][ 0 ];
  15755. var onUpdateCallback = uniform.onUpdateCallback;
  15756. if ( onUpdateCallback !== undefined ) {
  15757. onUpdateCallback.bind( uniform )( object, camera );
  15758. dynamicUniforms.push( uniforms[ j ] );
  15759. }
  15760. }
  15761. loadUniformsGeneric( dynamicUniforms );
  15762. }
  15763. // Uniforms (refresh uniforms objects)
  15764. function refreshUniformsCommon ( uniforms, material ) {
  15765. uniforms.opacity.value = material.opacity;
  15766. uniforms.diffuse.value = material.color;
  15767. if ( material.emissive ) {
  15768. uniforms.emissive.value = material.emissive;
  15769. }
  15770. uniforms.map.value = material.map;
  15771. uniforms.specularMap.value = material.specularMap;
  15772. uniforms.alphaMap.value = material.alphaMap;
  15773. if ( material.aoMap ) {
  15774. uniforms.aoMap.value = material.aoMap;
  15775. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15776. }
  15777. // uv repeat and offset setting priorities
  15778. // 1. color map
  15779. // 2. specular map
  15780. // 3. normal map
  15781. // 4. bump map
  15782. // 5. alpha map
  15783. // 6. emissive map
  15784. var uvScaleMap;
  15785. if ( material.map ) {
  15786. uvScaleMap = material.map;
  15787. } else if ( material.specularMap ) {
  15788. uvScaleMap = material.specularMap;
  15789. } else if ( material.displacementMap ) {
  15790. uvScaleMap = material.displacementMap;
  15791. } else if ( material.normalMap ) {
  15792. uvScaleMap = material.normalMap;
  15793. } else if ( material.bumpMap ) {
  15794. uvScaleMap = material.bumpMap;
  15795. } else if ( material.roughnessMap ) {
  15796. uvScaleMap = material.roughnessMap;
  15797. } else if ( material.metalnessMap ) {
  15798. uvScaleMap = material.metalnessMap;
  15799. } else if ( material.alphaMap ) {
  15800. uvScaleMap = material.alphaMap;
  15801. } else if ( material.emissiveMap ) {
  15802. uvScaleMap = material.emissiveMap;
  15803. }
  15804. if ( uvScaleMap !== undefined ) {
  15805. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15806. uvScaleMap = uvScaleMap.texture;
  15807. }
  15808. var offset = uvScaleMap.offset;
  15809. var repeat = uvScaleMap.repeat;
  15810. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15811. }
  15812. uniforms.envMap.value = material.envMap;
  15813. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15814. uniforms.reflectivity.value = material.reflectivity;
  15815. uniforms.refractionRatio.value = material.refractionRatio;
  15816. }
  15817. function refreshUniformsLine ( uniforms, material ) {
  15818. uniforms.diffuse.value = material.color;
  15819. uniforms.opacity.value = material.opacity;
  15820. }
  15821. function refreshUniformsDash ( uniforms, material ) {
  15822. uniforms.dashSize.value = material.dashSize;
  15823. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15824. uniforms.scale.value = material.scale;
  15825. }
  15826. function refreshUniformsPoints ( uniforms, material ) {
  15827. uniforms.psColor.value = material.color;
  15828. uniforms.opacity.value = material.opacity;
  15829. uniforms.size.value = material.size * pixelRatio;
  15830. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  15831. uniforms.map.value = material.map;
  15832. if ( material.map !== null ) {
  15833. var offset = material.map.offset;
  15834. var repeat = material.map.repeat;
  15835. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15836. }
  15837. }
  15838. function refreshUniformsFog ( uniforms, fog ) {
  15839. uniforms.fogColor.value = fog.color;
  15840. if ( fog instanceof THREE.Fog ) {
  15841. uniforms.fogNear.value = fog.near;
  15842. uniforms.fogFar.value = fog.far;
  15843. } else if ( fog instanceof THREE.FogExp2 ) {
  15844. uniforms.fogDensity.value = fog.density;
  15845. }
  15846. }
  15847. function refreshUniformsPhong ( uniforms, material ) {
  15848. uniforms.specular.value = material.specular;
  15849. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15850. if ( material.lightMap ) {
  15851. uniforms.lightMap.value = material.lightMap;
  15852. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15853. }
  15854. if ( material.emissiveMap ) {
  15855. uniforms.emissiveMap.value = material.emissiveMap;
  15856. }
  15857. if ( material.bumpMap ) {
  15858. uniforms.bumpMap.value = material.bumpMap;
  15859. uniforms.bumpScale.value = material.bumpScale;
  15860. }
  15861. if ( material.normalMap ) {
  15862. uniforms.normalMap.value = material.normalMap;
  15863. uniforms.normalScale.value.copy( material.normalScale );
  15864. }
  15865. if ( material.displacementMap ) {
  15866. uniforms.displacementMap.value = material.displacementMap;
  15867. uniforms.displacementScale.value = material.displacementScale;
  15868. uniforms.displacementBias.value = material.displacementBias;
  15869. }
  15870. }
  15871. function refreshUniformsStandard ( uniforms, material ) {
  15872. uniforms.roughness.value = material.roughness;
  15873. uniforms.metalness.value = material.metalness;
  15874. if ( material.roughnessMap ) {
  15875. uniforms.roughnessMap.value = material.roughnessMap;
  15876. }
  15877. if ( material.metalnessMap ) {
  15878. uniforms.metalnessMap.value = material.metalnessMap;
  15879. }
  15880. if ( material.lightMap ) {
  15881. uniforms.lightMap.value = material.lightMap;
  15882. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15883. }
  15884. if ( material.emissiveMap ) {
  15885. uniforms.emissiveMap.value = material.emissiveMap;
  15886. }
  15887. if ( material.bumpMap ) {
  15888. uniforms.bumpMap.value = material.bumpMap;
  15889. uniforms.bumpScale.value = material.bumpScale;
  15890. }
  15891. if ( material.normalMap ) {
  15892. uniforms.normalMap.value = material.normalMap;
  15893. uniforms.normalScale.value.copy( material.normalScale );
  15894. }
  15895. if ( material.displacementMap ) {
  15896. uniforms.displacementMap.value = material.displacementMap;
  15897. uniforms.displacementScale.value = material.displacementScale;
  15898. uniforms.displacementBias.value = material.displacementBias;
  15899. }
  15900. if ( material.envMap ) {
  15901. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15902. uniforms.envMapIntensity.value = material.envMapIntensity;
  15903. }
  15904. }
  15905. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15906. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15907. uniforms.ambientLightColor.needsUpdate = value;
  15908. uniforms.directionalLights.needsUpdate = value;
  15909. uniforms.pointLights.needsUpdate = value;
  15910. uniforms.spotLights.needsUpdate = value;
  15911. uniforms.hemisphereLights.needsUpdate = value;
  15912. }
  15913. function refreshUniformsShadow ( uniforms, camera ) {
  15914. if ( uniforms.shadowMatrix ) {
  15915. var shadows = _lights.shadows;
  15916. for ( var i = 0, l = shadows.length; i < l; i ++ ) {
  15917. var light = shadows[ i ];
  15918. var shadow = light.shadow;
  15919. if ( light instanceof THREE.PointLight ) {
  15920. // for point lights we set the shadow matrix to be a translation-only matrix
  15921. // equal to inverse of the light's position
  15922. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  15923. shadow.matrix.identity().setPosition( _vector3 );
  15924. // for point lights we set the sign of the shadowDarkness uniform to be negative
  15925. uniforms.shadowDarkness.value[ i ] = - shadow.darkness;
  15926. } else {
  15927. uniforms.shadowDarkness.value[ i ] = shadow.darkness;
  15928. }
  15929. uniforms.shadowBias.value[ i ] = shadow.bias;
  15930. uniforms.shadowMap.value[ i ] = shadow.map;
  15931. uniforms.shadowMapSize.value[ i ] = shadow.mapSize;
  15932. uniforms.shadowMatrix.value[ i ] = shadow.matrix;
  15933. }
  15934. }
  15935. }
  15936. // Uniforms (load to GPU)
  15937. function loadUniformsMatrices ( uniforms, object ) {
  15938. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  15939. if ( uniforms.normalMatrix ) {
  15940. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  15941. }
  15942. }
  15943. function getTextureUnit() {
  15944. var textureUnit = _usedTextureUnits;
  15945. if ( textureUnit >= capabilities.maxTextures ) {
  15946. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  15947. }
  15948. _usedTextureUnits += 1;
  15949. return textureUnit;
  15950. }
  15951. function loadUniformsGeneric ( uniforms ) {
  15952. var texture, textureUnit;
  15953. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15954. var uniform = uniforms[ j ][ 0 ];
  15955. // needsUpdate property is not added to all uniforms.
  15956. if ( uniform.needsUpdate === false ) continue;
  15957. var type = uniform.type;
  15958. var value = uniform.value;
  15959. var location = uniforms[ j ][ 1 ];
  15960. switch ( type ) {
  15961. case '1i':
  15962. _gl.uniform1i( location, value );
  15963. break;
  15964. case '1f':
  15965. _gl.uniform1f( location, value );
  15966. break;
  15967. case '2f':
  15968. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  15969. break;
  15970. case '3f':
  15971. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  15972. break;
  15973. case '4f':
  15974. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  15975. break;
  15976. case '1iv':
  15977. _gl.uniform1iv( location, value );
  15978. break;
  15979. case '3iv':
  15980. _gl.uniform3iv( location, value );
  15981. break;
  15982. case '1fv':
  15983. _gl.uniform1fv( location, value );
  15984. break;
  15985. case '2fv':
  15986. _gl.uniform2fv( location, value );
  15987. break;
  15988. case '3fv':
  15989. _gl.uniform3fv( location, value );
  15990. break;
  15991. case '4fv':
  15992. _gl.uniform4fv( location, value );
  15993. break;
  15994. case 'Matrix2fv':
  15995. _gl.uniformMatrix2fv( location, false, value );
  15996. break;
  15997. case 'Matrix3fv':
  15998. _gl.uniformMatrix3fv( location, false, value );
  15999. break;
  16000. case 'Matrix4fv':
  16001. _gl.uniformMatrix4fv( location, false, value );
  16002. break;
  16003. //
  16004. case 'i':
  16005. // single integer
  16006. _gl.uniform1i( location, value );
  16007. break;
  16008. case 'f':
  16009. // single float
  16010. _gl.uniform1f( location, value );
  16011. break;
  16012. case 'v2':
  16013. // single THREE.Vector2
  16014. _gl.uniform2f( location, value.x, value.y );
  16015. break;
  16016. case 'v3':
  16017. // single THREE.Vector3
  16018. _gl.uniform3f( location, value.x, value.y, value.z );
  16019. break;
  16020. case 'v4':
  16021. // single THREE.Vector4
  16022. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  16023. break;
  16024. case 'c':
  16025. // single THREE.Color
  16026. _gl.uniform3f( location, value.r, value.g, value.b );
  16027. break;
  16028. /*
  16029. case 's':
  16030. // TODO: Optimize this.
  16031. for( var propertyName in uniform.properties ) {
  16032. var property = uniform.properties[ propertyName ];
  16033. var locationProperty = location[ propertyName ];
  16034. var valueProperty = value[ propertyName ];
  16035. switch( property.type ) {
  16036. case 'i':
  16037. _gl.uniform1i( locationProperty, valueProperty );
  16038. break;
  16039. case 'f':
  16040. _gl.uniform1f( locationProperty, valueProperty );
  16041. break;
  16042. case 'v2':
  16043. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  16044. break;
  16045. case 'v3':
  16046. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  16047. break;
  16048. case 'v4':
  16049. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  16050. break;
  16051. case 'c':
  16052. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  16053. break;
  16054. };
  16055. }
  16056. break;
  16057. */
  16058. case 'sa':
  16059. // TODO: Optimize this.
  16060. for ( var i = 0; i < value.length; i ++ ) {
  16061. for ( var propertyName in uniform.properties ) {
  16062. var property = uniform.properties[ propertyName ];
  16063. var locationProperty = location[ i ][ propertyName ];
  16064. var valueProperty = value[ i ][ propertyName ];
  16065. switch ( property.type ) {
  16066. case 'i':
  16067. _gl.uniform1i( locationProperty, valueProperty );
  16068. break;
  16069. case 'f':
  16070. _gl.uniform1f( locationProperty, valueProperty );
  16071. break;
  16072. case 'v2':
  16073. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  16074. break;
  16075. case 'v3':
  16076. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  16077. break;
  16078. case 'v4':
  16079. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  16080. break;
  16081. case 'c':
  16082. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  16083. break;
  16084. };
  16085. }
  16086. }
  16087. break;
  16088. case 'iv1':
  16089. // flat array of integers (JS or typed array)
  16090. _gl.uniform1iv( location, value );
  16091. break;
  16092. case 'iv':
  16093. // flat array of integers with 3 x N size (JS or typed array)
  16094. _gl.uniform3iv( location, value );
  16095. break;
  16096. case 'fv1':
  16097. // flat array of floats (JS or typed array)
  16098. _gl.uniform1fv( location, value );
  16099. break;
  16100. case 'fv':
  16101. // flat array of floats with 3 x N size (JS or typed array)
  16102. _gl.uniform3fv( location, value );
  16103. break;
  16104. case 'v2v':
  16105. // array of THREE.Vector2
  16106. if ( uniform._array === undefined ) {
  16107. uniform._array = new Float32Array( 2 * value.length );
  16108. }
  16109. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  16110. uniform._array[ i2 + 0 ] = value[ i ].x;
  16111. uniform._array[ i2 + 1 ] = value[ i ].y;
  16112. }
  16113. _gl.uniform2fv( location, uniform._array );
  16114. break;
  16115. case 'v3v':
  16116. // array of THREE.Vector3
  16117. if ( uniform._array === undefined ) {
  16118. uniform._array = new Float32Array( 3 * value.length );
  16119. }
  16120. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  16121. uniform._array[ i3 + 0 ] = value[ i ].x;
  16122. uniform._array[ i3 + 1 ] = value[ i ].y;
  16123. uniform._array[ i3 + 2 ] = value[ i ].z;
  16124. }
  16125. _gl.uniform3fv( location, uniform._array );
  16126. break;
  16127. case 'v4v':
  16128. // array of THREE.Vector4
  16129. if ( uniform._array === undefined ) {
  16130. uniform._array = new Float32Array( 4 * value.length );
  16131. }
  16132. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  16133. uniform._array[ i4 + 0 ] = value[ i ].x;
  16134. uniform._array[ i4 + 1 ] = value[ i ].y;
  16135. uniform._array[ i4 + 2 ] = value[ i ].z;
  16136. uniform._array[ i4 + 3 ] = value[ i ].w;
  16137. }
  16138. _gl.uniform4fv( location, uniform._array );
  16139. break;
  16140. case 'm2':
  16141. // single THREE.Matrix2
  16142. _gl.uniformMatrix2fv( location, false, value.elements );
  16143. break;
  16144. case 'm3':
  16145. // single THREE.Matrix3
  16146. _gl.uniformMatrix3fv( location, false, value.elements );
  16147. break;
  16148. case 'm3v':
  16149. // array of THREE.Matrix3
  16150. if ( uniform._array === undefined ) {
  16151. uniform._array = new Float32Array( 9 * value.length );
  16152. }
  16153. for ( var i = 0, il = value.length; i < il; i ++ ) {
  16154. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  16155. }
  16156. _gl.uniformMatrix3fv( location, false, uniform._array );
  16157. break;
  16158. case 'm4':
  16159. // single THREE.Matrix4
  16160. _gl.uniformMatrix4fv( location, false, value.elements );
  16161. break;
  16162. case 'm4v':
  16163. // array of THREE.Matrix4
  16164. if ( uniform._array === undefined ) {
  16165. uniform._array = new Float32Array( 16 * value.length );
  16166. }
  16167. for ( var i = 0, il = value.length; i < il; i ++ ) {
  16168. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  16169. }
  16170. _gl.uniformMatrix4fv( location, false, uniform._array );
  16171. break;
  16172. case 't':
  16173. // single THREE.Texture (2d or cube)
  16174. texture = value;
  16175. textureUnit = getTextureUnit();
  16176. _gl.uniform1i( location, textureUnit );
  16177. if ( ! texture ) continue;
  16178. if ( texture instanceof THREE.CubeTexture ||
  16179. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16180. // CompressedTexture can have Array in image :/
  16181. setCubeTexture( texture, textureUnit );
  16182. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16183. setCubeTextureDynamic( texture.texture, textureUnit );
  16184. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16185. _this.setTexture( texture.texture, textureUnit );
  16186. } else {
  16187. _this.setTexture( texture, textureUnit );
  16188. }
  16189. break;
  16190. case 'tv':
  16191. // array of THREE.Texture (2d or cube)
  16192. if ( uniform._array === undefined ) {
  16193. uniform._array = [];
  16194. }
  16195. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16196. uniform._array[ i ] = getTextureUnit();
  16197. }
  16198. _gl.uniform1iv( location, uniform._array );
  16199. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16200. texture = uniform.value[ i ];
  16201. textureUnit = uniform._array[ i ];
  16202. if ( ! texture ) continue;
  16203. if ( texture instanceof THREE.CubeTexture ||
  16204. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  16205. // CompressedTexture can have Array in image :/
  16206. setCubeTexture( texture, textureUnit );
  16207. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16208. _this.setTexture( texture.texture, textureUnit );
  16209. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16210. setCubeTextureDynamic( texture.texture, textureUnit );
  16211. } else {
  16212. _this.setTexture( texture, textureUnit );
  16213. }
  16214. }
  16215. break;
  16216. default:
  16217. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  16218. }
  16219. }
  16220. }
  16221. function setupLights ( lights, camera ) {
  16222. var l, ll, light,
  16223. r = 0, g = 0, b = 0,
  16224. color,
  16225. intensity,
  16226. distance,
  16227. viewMatrix = camera.matrixWorldInverse,
  16228. directionalLength = 0,
  16229. pointLength = 0,
  16230. spotLength = 0,
  16231. hemiLength = 0,
  16232. shadowsLength = 0;
  16233. _lights.shadowsPointLight = 0;
  16234. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  16235. light = lights[ l ];
  16236. color = light.color;
  16237. intensity = light.intensity;
  16238. distance = light.distance;
  16239. if ( light instanceof THREE.AmbientLight ) {
  16240. r += color.r * intensity;
  16241. g += color.g * intensity;
  16242. b += color.b * intensity;
  16243. } else if ( light instanceof THREE.DirectionalLight ) {
  16244. var uniforms = lightCache.get( light );
  16245. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16246. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16247. uniforms.direction.sub( _vector3 );
  16248. uniforms.direction.transformDirection( viewMatrix );
  16249. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16250. if ( light.castShadow ) {
  16251. uniforms.shadow = shadowsLength;
  16252. _lights.shadows[ shadowsLength ++ ] = light;
  16253. } else {
  16254. uniforms.shadow = - 1;
  16255. }
  16256. _lights.directional[ directionalLength ++ ] = uniforms;
  16257. } else if ( light instanceof THREE.PointLight ) {
  16258. var uniforms = lightCache.get( light );
  16259. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16260. uniforms.position.applyMatrix4( viewMatrix );
  16261. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16262. uniforms.distance = light.distance;
  16263. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16264. if ( light.castShadow ) {
  16265. uniforms.shadow = shadowsLength;
  16266. _lights.shadows[ shadowsLength ++ ] = light;
  16267. _lights.shadowsPointLight ++;
  16268. } else {
  16269. uniforms.shadow = - 1;
  16270. }
  16271. _lights.point[ pointLength ++ ] = uniforms;
  16272. } else if ( light instanceof THREE.SpotLight ) {
  16273. var uniforms = lightCache.get( light );
  16274. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16275. uniforms.position.applyMatrix4( viewMatrix );
  16276. uniforms.color.copy( color ).multiplyScalar( intensity );
  16277. uniforms.distance = distance;
  16278. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16279. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16280. uniforms.direction.sub( _vector3 );
  16281. uniforms.direction.transformDirection( viewMatrix );
  16282. uniforms.angleCos = Math.cos( light.angle );
  16283. uniforms.exponent = light.exponent;
  16284. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16285. if ( light.castShadow ) {
  16286. uniforms.shadow = shadowsLength;
  16287. _lights.shadows[ shadowsLength ++ ] = light;
  16288. } else {
  16289. uniforms.shadow = - 1;
  16290. }
  16291. _lights.spot[ spotLength ++ ] = uniforms;
  16292. } else if ( light instanceof THREE.HemisphereLight ) {
  16293. var uniforms = lightCache.get( light );
  16294. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16295. uniforms.direction.transformDirection( viewMatrix );
  16296. uniforms.direction.normalize();
  16297. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16298. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16299. _lights.hemi[ hemiLength ++ ] = uniforms;
  16300. }
  16301. }
  16302. _lights.ambient[ 0 ] = r;
  16303. _lights.ambient[ 1 ] = g;
  16304. _lights.ambient[ 2 ] = b;
  16305. _lights.directional.length = directionalLength;
  16306. _lights.point.length = pointLength;
  16307. _lights.spot.length = spotLength;
  16308. _lights.hemi.length = hemiLength;
  16309. _lights.shadows.length = shadowsLength;
  16310. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + shadowsLength;
  16311. }
  16312. // GL state setting
  16313. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16314. if ( cullFace === THREE.CullFaceNone ) {
  16315. state.disable( _gl.CULL_FACE );
  16316. } else {
  16317. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16318. _gl.frontFace( _gl.CW );
  16319. } else {
  16320. _gl.frontFace( _gl.CCW );
  16321. }
  16322. if ( cullFace === THREE.CullFaceBack ) {
  16323. _gl.cullFace( _gl.BACK );
  16324. } else if ( cullFace === THREE.CullFaceFront ) {
  16325. _gl.cullFace( _gl.FRONT );
  16326. } else {
  16327. _gl.cullFace( _gl.FRONT_AND_BACK );
  16328. }
  16329. state.enable( _gl.CULL_FACE );
  16330. }
  16331. };
  16332. // Textures
  16333. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  16334. var extension;
  16335. if ( isImagePowerOfTwo ) {
  16336. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16337. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16338. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16339. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16340. } else {
  16341. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16342. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16343. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16344. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16345. }
  16346. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16347. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16348. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16349. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16350. }
  16351. }
  16352. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16353. if ( extension ) {
  16354. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16355. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16356. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16357. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16358. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16359. }
  16360. }
  16361. }
  16362. function uploadTexture( textureProperties, texture, slot ) {
  16363. if ( textureProperties.__webglInit === undefined ) {
  16364. textureProperties.__webglInit = true;
  16365. texture.addEventListener( 'dispose', onTextureDispose );
  16366. textureProperties.__webglTexture = _gl.createTexture();
  16367. _infoMemory.textures ++;
  16368. }
  16369. state.activeTexture( _gl.TEXTURE0 + slot );
  16370. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16371. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16372. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16373. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16374. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16375. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false ) {
  16376. texture.image = makePowerOfTwo( texture.image );
  16377. }
  16378. var image = texture.image,
  16379. isImagePowerOfTwo = isPowerOfTwo( image ),
  16380. glFormat = paramThreeToGL( texture.format ),
  16381. glType = paramThreeToGL( texture.type );
  16382. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  16383. var mipmap, mipmaps = texture.mipmaps;
  16384. if ( texture instanceof THREE.DataTexture ) {
  16385. // use manually created mipmaps if available
  16386. // if there are no manual mipmaps
  16387. // set 0 level mipmap and then use GL to generate other mipmap levels
  16388. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  16389. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16390. mipmap = mipmaps[ i ];
  16391. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16392. }
  16393. texture.generateMipmaps = false;
  16394. } else {
  16395. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16396. }
  16397. } else if ( texture instanceof THREE.CompressedTexture ) {
  16398. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16399. mipmap = mipmaps[ i ];
  16400. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16401. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16402. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16403. } else {
  16404. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16405. }
  16406. } else {
  16407. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16408. }
  16409. }
  16410. } else {
  16411. // regular Texture (image, video, canvas)
  16412. // use manually created mipmaps if available
  16413. // if there are no manual mipmaps
  16414. // set 0 level mipmap and then use GL to generate other mipmap levels
  16415. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  16416. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16417. mipmap = mipmaps[ i ];
  16418. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16419. }
  16420. texture.generateMipmaps = false;
  16421. } else {
  16422. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  16423. }
  16424. }
  16425. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16426. textureProperties.__version = texture.version;
  16427. if ( texture.onUpdate ) texture.onUpdate( texture );
  16428. }
  16429. this.setTexture = function ( texture, slot ) {
  16430. var textureProperties = properties.get( texture );
  16431. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16432. var image = texture.image;
  16433. if ( image === undefined ) {
  16434. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16435. return;
  16436. }
  16437. if ( image.complete === false ) {
  16438. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16439. return;
  16440. }
  16441. uploadTexture( textureProperties, texture, slot );
  16442. return;
  16443. }
  16444. state.activeTexture( _gl.TEXTURE0 + slot );
  16445. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16446. };
  16447. function clampToMaxSize ( image, maxSize ) {
  16448. if ( image.width > maxSize || image.height > maxSize ) {
  16449. // Warning: Scaling through the canvas will only work with images that use
  16450. // premultiplied alpha.
  16451. var scale = maxSize / Math.max( image.width, image.height );
  16452. var canvas = document.createElement( 'canvas' );
  16453. canvas.width = Math.floor( image.width * scale );
  16454. canvas.height = Math.floor( image.height * scale );
  16455. var context = canvas.getContext( '2d' );
  16456. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16457. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16458. return canvas;
  16459. }
  16460. return image;
  16461. }
  16462. function isPowerOfTwo( image ) {
  16463. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16464. }
  16465. function textureNeedsPowerOfTwo( texture ) {
  16466. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16467. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16468. return false;
  16469. }
  16470. function makePowerOfTwo( image ) {
  16471. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16472. var canvas = document.createElement( 'canvas' );
  16473. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16474. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16475. var context = canvas.getContext( '2d' );
  16476. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16477. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16478. return canvas;
  16479. }
  16480. return image;
  16481. }
  16482. function setCubeTexture ( texture, slot ) {
  16483. var textureProperties = properties.get( texture );
  16484. if ( texture.image.length === 6 ) {
  16485. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16486. if ( ! textureProperties.__image__webglTextureCube ) {
  16487. texture.addEventListener( 'dispose', onTextureDispose );
  16488. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16489. _infoMemory.textures ++;
  16490. }
  16491. state.activeTexture( _gl.TEXTURE0 + slot );
  16492. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16493. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16494. var isCompressed = texture instanceof THREE.CompressedTexture;
  16495. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16496. var cubeImage = [];
  16497. for ( var i = 0; i < 6; i ++ ) {
  16498. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16499. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16500. } else {
  16501. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16502. }
  16503. }
  16504. var image = cubeImage[ 0 ],
  16505. isImagePowerOfTwo = isPowerOfTwo( image ),
  16506. glFormat = paramThreeToGL( texture.format ),
  16507. glType = paramThreeToGL( texture.type );
  16508. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  16509. for ( var i = 0; i < 6; i ++ ) {
  16510. if ( ! isCompressed ) {
  16511. if ( isDataTexture ) {
  16512. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16513. } else {
  16514. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16515. }
  16516. } else {
  16517. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16518. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16519. mipmap = mipmaps[ j ];
  16520. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16521. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16522. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16523. } else {
  16524. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16525. }
  16526. } else {
  16527. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16528. }
  16529. }
  16530. }
  16531. }
  16532. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  16533. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16534. }
  16535. textureProperties.__version = texture.version;
  16536. if ( texture.onUpdate ) texture.onUpdate( texture );
  16537. } else {
  16538. state.activeTexture( _gl.TEXTURE0 + slot );
  16539. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16540. }
  16541. }
  16542. }
  16543. function setCubeTextureDynamic ( texture, slot ) {
  16544. state.activeTexture( _gl.TEXTURE0 + slot );
  16545. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16546. }
  16547. // Render targets
  16548. // Setup storage for target texture and bind it to correct framebuffer
  16549. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16550. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16551. var glType = paramThreeToGL( renderTarget.texture.type );
  16552. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16553. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16554. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16555. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16556. }
  16557. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16558. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16559. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16560. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16561. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16562. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16563. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16564. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16565. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16566. } else {
  16567. // FIXME: We don't support !depth !stencil
  16568. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16569. }
  16570. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16571. }
  16572. // Setup GL resources for a non-texture depth buffer
  16573. function setupDepthRenderbuffer( renderTarget ) {
  16574. var renderTargetProperties = properties.get( renderTarget );
  16575. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16576. if ( isCube ) {
  16577. renderTargetProperties.__webglDepthbuffer = [];
  16578. for ( var i = 0; i < 6; i ++ ) {
  16579. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16580. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16581. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16582. }
  16583. } else {
  16584. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16585. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16586. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16587. }
  16588. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16589. }
  16590. // Set up GL resources for the render target
  16591. function setupRenderTarget( renderTarget ) {
  16592. var renderTargetProperties = properties.get( renderTarget );
  16593. var textureProperties = properties.get( renderTarget.texture );
  16594. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16595. textureProperties.__webglTexture = _gl.createTexture();
  16596. _infoMemory.textures ++;
  16597. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16598. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16599. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16600. var glType = paramThreeToGL( renderTarget.texture.type );
  16601. // Setup framebuffer
  16602. if ( isCube ) {
  16603. renderTargetProperties.__webglFramebuffer = [];
  16604. for ( var i = 0; i < 6; i ++ ) {
  16605. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16606. }
  16607. } else {
  16608. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16609. }
  16610. // Setup color buffer
  16611. if ( isCube ) {
  16612. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16613. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16614. for ( var i = 0; i < 6; i ++ ) {
  16615. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16616. }
  16617. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16618. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16619. } else {
  16620. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16621. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16622. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16623. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16624. state.bindTexture( _gl.TEXTURE_2D, null );
  16625. }
  16626. // Setup depth and stencil buffers
  16627. if ( renderTarget.depthBuffer ) {
  16628. setupDepthRenderbuffer( renderTarget );
  16629. }
  16630. }
  16631. this.setRenderTarget = function ( renderTarget ) {
  16632. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16633. setupRenderTarget( renderTarget );
  16634. }
  16635. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16636. var framebuffer, width, height, vx, vy;
  16637. if ( renderTarget ) {
  16638. var renderTargetProperties = properties.get( renderTarget );
  16639. if ( isCube ) {
  16640. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16641. } else {
  16642. framebuffer = renderTargetProperties.__webglFramebuffer;
  16643. }
  16644. width = renderTarget.width;
  16645. height = renderTarget.height;
  16646. vx = 0;
  16647. vy = 0;
  16648. } else {
  16649. framebuffer = null;
  16650. width = _viewportWidth;
  16651. height = _viewportHeight;
  16652. vx = _viewportX;
  16653. vy = _viewportY;
  16654. }
  16655. if ( framebuffer !== _currentFramebuffer ) {
  16656. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16657. _gl.viewport( vx, vy, width, height );
  16658. _currentFramebuffer = framebuffer;
  16659. }
  16660. if ( isCube ) {
  16661. var textureProperties = properties.get( renderTarget.texture );
  16662. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  16663. }
  16664. _currentWidth = width;
  16665. _currentHeight = height;
  16666. };
  16667. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16668. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16669. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16670. return;
  16671. }
  16672. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16673. if ( framebuffer ) {
  16674. var restore = false;
  16675. if ( framebuffer !== _currentFramebuffer ) {
  16676. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16677. restore = true;
  16678. }
  16679. try {
  16680. var texture = renderTarget.texture;
  16681. if ( texture.format !== THREE.RGBAFormat
  16682. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16683. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16684. return;
  16685. }
  16686. if ( texture.type !== THREE.UnsignedByteType
  16687. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16688. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16689. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16690. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16691. return;
  16692. }
  16693. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16694. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16695. } else {
  16696. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16697. }
  16698. } finally {
  16699. if ( restore ) {
  16700. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16701. }
  16702. }
  16703. }
  16704. };
  16705. function updateRenderTargetMipmap( renderTarget ) {
  16706. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16707. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16708. state.bindTexture( target, texture );
  16709. _gl.generateMipmap( target );
  16710. state.bindTexture( target, null );
  16711. }
  16712. // Fallback filters for non-power-of-2 textures
  16713. function filterFallback ( f ) {
  16714. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16715. return _gl.NEAREST;
  16716. }
  16717. return _gl.LINEAR;
  16718. }
  16719. // Map three.js constants to WebGL constants
  16720. function paramThreeToGL ( p ) {
  16721. var extension;
  16722. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16723. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16724. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16725. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16726. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16727. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16728. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16729. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16730. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16731. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16732. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16733. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16734. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16735. if ( p === THREE.ByteType ) return _gl.BYTE;
  16736. if ( p === THREE.ShortType ) return _gl.SHORT;
  16737. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16738. if ( p === THREE.IntType ) return _gl.INT;
  16739. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16740. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16741. extension = extensions.get( 'OES_texture_half_float' );
  16742. if ( extension !== null ) {
  16743. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16744. }
  16745. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16746. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16747. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16748. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16749. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16750. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16751. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16752. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16753. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16754. if ( p === THREE.OneFactor ) return _gl.ONE;
  16755. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16756. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16757. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16758. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16759. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16760. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16761. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16762. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16763. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16764. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16765. if ( extension !== null ) {
  16766. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16767. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16768. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16769. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16770. }
  16771. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16772. if ( extension !== null ) {
  16773. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16774. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16775. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16776. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16777. }
  16778. extension = extensions.get( 'EXT_blend_minmax' );
  16779. if ( extension !== null ) {
  16780. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16781. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16782. }
  16783. return 0;
  16784. }
  16785. };
  16786. // File:src/renderers/WebGLRenderTarget.js
  16787. /**
  16788. * @author szimek / https://github.com/szimek/
  16789. * @author alteredq / http://alteredqualia.com/
  16790. * @author Marius Kintel / https://github.com/kintel
  16791. */
  16792. /*
  16793. In options, we can specify:
  16794. * Texture parameters for an auto-generated target texture
  16795. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16796. */
  16797. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16798. this.uuid = THREE.Math.generateUUID();
  16799. this.width = width;
  16800. this.height = height;
  16801. options = options || {};
  16802. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16803. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16804. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16805. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16806. };
  16807. THREE.WebGLRenderTarget.prototype = {
  16808. constructor: THREE.WebGLRenderTarget,
  16809. setSize: function ( width, height ) {
  16810. if ( this.width !== width || this.height !== height ) {
  16811. this.width = width;
  16812. this.height = height;
  16813. this.dispose();
  16814. }
  16815. },
  16816. clone: function () {
  16817. return new this.constructor().copy( this );
  16818. },
  16819. copy: function ( source ) {
  16820. this.width = source.width;
  16821. this.height = source.height;
  16822. this.texture = source.texture.clone();
  16823. this.depthBuffer = source.depthBuffer;
  16824. this.stencilBuffer = source.stencilBuffer;
  16825. this.shareDepthFrom = source.shareDepthFrom;
  16826. return this;
  16827. },
  16828. dispose: function () {
  16829. this.dispatchEvent( { type: 'dispose' } );
  16830. }
  16831. };
  16832. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16833. // File:src/renderers/WebGLRenderTargetCube.js
  16834. /**
  16835. * @author alteredq / http://alteredqualia.com
  16836. */
  16837. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16838. THREE.WebGLRenderTarget.call( this, width, height, options );
  16839. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16840. };
  16841. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16842. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16843. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16844. /**
  16845. * @author mrdoob / http://mrdoob.com/
  16846. */
  16847. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16848. var mode;
  16849. function setMode( value ) {
  16850. mode = value;
  16851. }
  16852. function render( start, count ) {
  16853. _gl.drawArrays( mode, start, count );
  16854. _infoRender.calls ++;
  16855. _infoRender.vertices += count;
  16856. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16857. }
  16858. function renderInstances( geometry ) {
  16859. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16860. if ( extension === null ) {
  16861. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16862. return;
  16863. }
  16864. var position = geometry.attributes.position;
  16865. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16866. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  16867. } else {
  16868. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  16869. }
  16870. }
  16871. this.setMode = setMode;
  16872. this.render = render;
  16873. this.renderInstances = renderInstances;
  16874. };
  16875. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16876. /**
  16877. * @author mrdoob / http://mrdoob.com/
  16878. */
  16879. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16880. var mode;
  16881. function setMode( value ) {
  16882. mode = value;
  16883. }
  16884. var type, size;
  16885. function setIndex( index ) {
  16886. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16887. type = _gl.UNSIGNED_INT;
  16888. size = 4;
  16889. } else {
  16890. type = _gl.UNSIGNED_SHORT;
  16891. size = 2;
  16892. }
  16893. }
  16894. function render( start, count ) {
  16895. _gl.drawElements( mode, count, type, start * size );
  16896. _infoRender.calls ++;
  16897. _infoRender.vertices += count;
  16898. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16899. }
  16900. function renderInstances( geometry, start, count ) {
  16901. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16902. if ( extension === null ) {
  16903. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16904. return;
  16905. }
  16906. var index = geometry.index;
  16907. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16908. }
  16909. this.setMode = setMode;
  16910. this.setIndex = setIndex;
  16911. this.render = render;
  16912. this.renderInstances = renderInstances;
  16913. };
  16914. // File:src/renderers/webgl/WebGLExtensions.js
  16915. /**
  16916. * @author mrdoob / http://mrdoob.com/
  16917. */
  16918. THREE.WebGLExtensions = function ( gl ) {
  16919. var extensions = {};
  16920. this.get = function ( name ) {
  16921. if ( extensions[ name ] !== undefined ) {
  16922. return extensions[ name ];
  16923. }
  16924. var extension;
  16925. switch ( name ) {
  16926. case 'EXT_texture_filter_anisotropic':
  16927. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16928. break;
  16929. case 'WEBGL_compressed_texture_s3tc':
  16930. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16931. break;
  16932. case 'WEBGL_compressed_texture_pvrtc':
  16933. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16934. break;
  16935. default:
  16936. extension = gl.getExtension( name );
  16937. }
  16938. if ( extension === null ) {
  16939. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16940. }
  16941. extensions[ name ] = extension;
  16942. return extension;
  16943. };
  16944. };
  16945. // File:src/renderers/webgl/WebGLCapabilities.js
  16946. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16947. function getMaxPrecision( precision ) {
  16948. if ( precision === 'highp' ) {
  16949. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16950. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16951. return 'highp';
  16952. }
  16953. precision = 'mediump';
  16954. }
  16955. if ( precision === 'mediump' ) {
  16956. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16957. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16958. return 'mediump';
  16959. }
  16960. }
  16961. return 'lowp';
  16962. }
  16963. this.getMaxPrecision = getMaxPrecision;
  16964. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16965. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16966. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16967. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16968. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16969. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16970. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16971. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16972. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16973. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16974. this.vertexTextures = this.maxVertexTextures > 0;
  16975. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16976. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16977. var _maxPrecision = getMaxPrecision( this.precision );
  16978. if ( _maxPrecision !== this.precision ) {
  16979. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16980. this.precision = _maxPrecision;
  16981. }
  16982. if ( this.logarithmicDepthBuffer ) {
  16983. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16984. }
  16985. };
  16986. // File:src/renderers/webgl/WebGLGeometries.js
  16987. /**
  16988. * @author mrdoob / http://mrdoob.com/
  16989. */
  16990. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16991. var geometries = {};
  16992. function get( object ) {
  16993. var geometry = object.geometry;
  16994. if ( geometries[ geometry.id ] !== undefined ) {
  16995. return geometries[ geometry.id ];
  16996. }
  16997. geometry.addEventListener( 'dispose', onGeometryDispose );
  16998. var buffergeometry;
  16999. if ( geometry instanceof THREE.BufferGeometry ) {
  17000. buffergeometry = geometry;
  17001. } else if ( geometry instanceof THREE.Geometry ) {
  17002. if ( geometry._bufferGeometry === undefined ) {
  17003. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  17004. }
  17005. buffergeometry = geometry._bufferGeometry;
  17006. }
  17007. geometries[ geometry.id ] = buffergeometry;
  17008. info.memory.geometries ++;
  17009. return buffergeometry;
  17010. }
  17011. function onGeometryDispose( event ) {
  17012. var geometry = event.target;
  17013. var buffergeometry = geometries[ geometry.id ];
  17014. if ( buffergeometry.index !== null ) {
  17015. deleteAttribute( buffergeometry.index );
  17016. }
  17017. deleteAttributes( buffergeometry.attributes );
  17018. geometry.removeEventListener( 'dispose', onGeometryDispose );
  17019. delete geometries[ geometry.id ];
  17020. var property = properties.get( geometry );
  17021. if ( property.wireframe ) deleteAttribute( property.wireframe );
  17022. properties.delete( geometry );
  17023. info.memory.geometries --;
  17024. }
  17025. function getAttributeBuffer( attribute ) {
  17026. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17027. return properties.get( attribute.data ).__webglBuffer;
  17028. }
  17029. return properties.get( attribute ).__webglBuffer;
  17030. }
  17031. function deleteAttribute( attribute ) {
  17032. var buffer = getAttributeBuffer( attribute );
  17033. if ( buffer !== undefined ) {
  17034. gl.deleteBuffer( buffer );
  17035. removeAttributeBuffer( attribute );
  17036. }
  17037. }
  17038. function deleteAttributes( attributes ) {
  17039. for ( var name in attributes ) {
  17040. deleteAttribute( attributes[ name ] );
  17041. }
  17042. }
  17043. function removeAttributeBuffer( attribute ) {
  17044. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17045. properties.delete( attribute.data );
  17046. } else {
  17047. properties.delete( attribute );
  17048. }
  17049. }
  17050. this.get = get;
  17051. };
  17052. // File:src/renderers/webgl/WebGLLights.js
  17053. /**
  17054. * @author mrdoob / http://mrdoob.com/
  17055. */
  17056. THREE.WebGLLights = function () {
  17057. var lights = {};
  17058. this.get = function ( light ) {
  17059. if ( lights[ light.id ] !== undefined ) {
  17060. return lights[ light.id ];
  17061. }
  17062. var uniforms;
  17063. switch ( light.type ) {
  17064. case 'DirectionalLight':
  17065. uniforms = {
  17066. direction: new THREE.Vector3(),
  17067. color: new THREE.Color(),
  17068. shadow: -1
  17069. };
  17070. break;
  17071. case 'PointLight':
  17072. uniforms = {
  17073. position: new THREE.Vector3(),
  17074. color: new THREE.Color(),
  17075. distance: 0,
  17076. decay: 0,
  17077. shadow: -1
  17078. };
  17079. break;
  17080. case 'SpotLight':
  17081. uniforms = {
  17082. position: new THREE.Vector3(),
  17083. direction: new THREE.Vector3(),
  17084. color: new THREE.Color(),
  17085. distance: 0,
  17086. decay: 0,
  17087. angleCos: 0
  17088. };
  17089. break;
  17090. case 'HemisphereLight':
  17091. uniforms = {
  17092. direction: new THREE.Vector3(),
  17093. skyColor: new THREE.Color(),
  17094. groundColor: new THREE.Color()
  17095. };
  17096. break;
  17097. }
  17098. lights[ light.id ] = uniforms;
  17099. return uniforms;
  17100. };
  17101. };
  17102. // File:src/renderers/webgl/WebGLObjects.js
  17103. /**
  17104. * @author mrdoob / http://mrdoob.com/
  17105. */
  17106. THREE.WebGLObjects = function ( gl, properties, info ) {
  17107. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  17108. //
  17109. function update( object ) {
  17110. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  17111. var geometry = geometries.get( object );
  17112. if ( object.geometry instanceof THREE.Geometry ) {
  17113. geometry.updateFromObject( object );
  17114. }
  17115. var index = geometry.index;
  17116. var attributes = geometry.attributes;
  17117. if ( index !== null ) {
  17118. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  17119. }
  17120. for ( var name in attributes ) {
  17121. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  17122. }
  17123. // morph targets
  17124. var morphAttributes = geometry.morphAttributes;
  17125. for ( var name in morphAttributes ) {
  17126. var array = morphAttributes[ name ];
  17127. for ( var i = 0, l = array.length; i < l; i ++ ) {
  17128. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  17129. }
  17130. }
  17131. return geometry;
  17132. }
  17133. function updateAttribute( attribute, bufferType ) {
  17134. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  17135. var attributeProperties = properties.get( data );
  17136. if ( attributeProperties.__webglBuffer === undefined ) {
  17137. createBuffer( attributeProperties, data, bufferType );
  17138. } else if ( attributeProperties.version !== data.version ) {
  17139. updateBuffer( attributeProperties, data, bufferType );
  17140. }
  17141. }
  17142. function createBuffer( attributeProperties, data, bufferType ) {
  17143. attributeProperties.__webglBuffer = gl.createBuffer();
  17144. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17145. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  17146. gl.bufferData( bufferType, data.array, usage );
  17147. attributeProperties.version = data.version;
  17148. }
  17149. function updateBuffer( attributeProperties, data, bufferType ) {
  17150. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17151. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  17152. // Not using update ranges
  17153. gl.bufferSubData( bufferType, 0, data.array );
  17154. } else if ( data.updateRange.count === 0 ) {
  17155. 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.' );
  17156. } else {
  17157. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  17158. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  17159. data.updateRange.count = 0; // reset range
  17160. }
  17161. attributeProperties.version = data.version;
  17162. }
  17163. function getAttributeBuffer( attribute ) {
  17164. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17165. return properties.get( attribute.data ).__webglBuffer;
  17166. }
  17167. return properties.get( attribute ).__webglBuffer;
  17168. }
  17169. function getWireframeAttribute( geometry ) {
  17170. var property = properties.get( geometry );
  17171. if ( property.wireframe !== undefined ) {
  17172. return property.wireframe;
  17173. }
  17174. var indices = [];
  17175. var index = geometry.index;
  17176. var attributes = geometry.attributes;
  17177. var position = attributes.position;
  17178. // console.time( 'wireframe' );
  17179. if ( index !== null ) {
  17180. var edges = {};
  17181. var array = index.array;
  17182. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  17183. var a = array[ i + 0 ];
  17184. var b = array[ i + 1 ];
  17185. var c = array[ i + 2 ];
  17186. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  17187. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  17188. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  17189. }
  17190. } else {
  17191. var array = attributes.position.array;
  17192. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  17193. var a = i + 0;
  17194. var b = i + 1;
  17195. var c = i + 2;
  17196. indices.push( a, b, b, c, c, a );
  17197. }
  17198. }
  17199. // console.timeEnd( 'wireframe' );
  17200. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  17201. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  17202. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  17203. property.wireframe = attribute;
  17204. return attribute;
  17205. }
  17206. function checkEdge( edges, a, b ) {
  17207. if ( a > b ) {
  17208. var tmp = a;
  17209. a = b;
  17210. b = tmp;
  17211. }
  17212. var list = edges[ a ];
  17213. if ( list === undefined ) {
  17214. edges[ a ] = [ b ];
  17215. return true;
  17216. } else if ( list.indexOf( b ) === -1 ) {
  17217. list.push( b );
  17218. return true;
  17219. }
  17220. return false;
  17221. }
  17222. this.getAttributeBuffer = getAttributeBuffer;
  17223. this.getWireframeAttribute = getWireframeAttribute;
  17224. this.update = update;
  17225. };
  17226. // File:src/renderers/webgl/WebGLProgram.js
  17227. THREE.WebGLProgram = ( function () {
  17228. var programIdCount = 0;
  17229. // TODO: Combine the regex
  17230. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  17231. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  17232. var arrayRe = /^([\w\d_]+)\[0\]$/;
  17233. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17234. extensions = extensions || {};
  17235. var chunks = [
  17236. ( extensions.derivatives || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17237. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17238. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17239. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17240. ];
  17241. return chunks.filter( filterEmptyLine ).join( '\n' );
  17242. }
  17243. function generateDefines( defines ) {
  17244. var chunks = [];
  17245. for ( var name in defines ) {
  17246. var value = defines[ name ];
  17247. if ( value === false ) continue;
  17248. chunks.push( '#define ' + name + ' ' + value );
  17249. }
  17250. return chunks.join( '\n' );
  17251. }
  17252. function fetchUniformLocations( gl, program, identifiers ) {
  17253. var uniforms = {};
  17254. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17255. for ( var i = 0; i < n; i ++ ) {
  17256. var info = gl.getActiveUniform( program, i );
  17257. var name = info.name;
  17258. var location = gl.getUniformLocation( program, name );
  17259. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17260. var matches = structRe.exec( name );
  17261. if ( matches ) {
  17262. var structName = matches[ 1 ];
  17263. var structProperty = matches[ 2 ];
  17264. var uniformsStruct = uniforms[ structName ];
  17265. if ( ! uniformsStruct ) {
  17266. uniformsStruct = uniforms[ structName ] = {};
  17267. }
  17268. uniformsStruct[ structProperty ] = location;
  17269. continue;
  17270. }
  17271. matches = arrayStructRe.exec( name );
  17272. if ( matches ) {
  17273. var arrayName = matches[ 1 ];
  17274. var arrayIndex = matches[ 2 ];
  17275. var arrayProperty = matches[ 3 ];
  17276. var uniformsArray = uniforms[ arrayName ];
  17277. if ( ! uniformsArray ) {
  17278. uniformsArray = uniforms[ arrayName ] = [];
  17279. }
  17280. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17281. if ( ! uniformsArrayIndex ) {
  17282. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17283. }
  17284. uniformsArrayIndex[ arrayProperty ] = location;
  17285. continue;
  17286. }
  17287. matches = arrayRe.exec( name );
  17288. if ( matches ) {
  17289. var arrayName = matches[ 1 ];
  17290. uniforms[ arrayName ] = location;
  17291. continue;
  17292. }
  17293. uniforms[ name ] = location;
  17294. }
  17295. return uniforms;
  17296. }
  17297. function fetchAttributeLocations( gl, program, identifiers ) {
  17298. var attributes = {};
  17299. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17300. for ( var i = 0; i < n; i ++ ) {
  17301. var info = gl.getActiveAttrib( program, i );
  17302. var name = info.name;
  17303. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17304. attributes[ name ] = gl.getAttribLocation( program, name );
  17305. }
  17306. return attributes;
  17307. }
  17308. function filterEmptyLine( string ) {
  17309. return string !== '';
  17310. }
  17311. return function WebGLProgram( renderer, code, material, parameters ) {
  17312. var gl = renderer.context;
  17313. var extensions = material.extensions;
  17314. var defines = material.defines;
  17315. var vertexShader = material.__webglShader.vertexShader;
  17316. var fragmentShader = material.__webglShader.fragmentShader;
  17317. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17318. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17319. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17320. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17321. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17322. }
  17323. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17324. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17325. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17326. if ( parameters.envMap ) {
  17327. switch ( material.envMap.mapping ) {
  17328. case THREE.CubeReflectionMapping:
  17329. case THREE.CubeRefractionMapping:
  17330. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17331. break;
  17332. case THREE.EquirectangularReflectionMapping:
  17333. case THREE.EquirectangularRefractionMapping:
  17334. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17335. break;
  17336. case THREE.SphericalReflectionMapping:
  17337. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17338. break;
  17339. }
  17340. switch ( material.envMap.mapping ) {
  17341. case THREE.CubeRefractionMapping:
  17342. case THREE.EquirectangularRefractionMapping:
  17343. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17344. break;
  17345. }
  17346. switch ( material.combine ) {
  17347. case THREE.MultiplyOperation:
  17348. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17349. break;
  17350. case THREE.MixOperation:
  17351. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17352. break;
  17353. case THREE.AddOperation:
  17354. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17355. break;
  17356. }
  17357. }
  17358. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17359. // console.log( 'building new program ' );
  17360. //
  17361. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17362. var customDefines = generateDefines( defines );
  17363. //
  17364. var program = gl.createProgram();
  17365. var prefixVertex, prefixFragment;
  17366. if ( material instanceof THREE.RawShaderMaterial ) {
  17367. prefixVertex = '';
  17368. prefixFragment = '';
  17369. } else {
  17370. prefixVertex = [
  17371. 'precision ' + parameters.precision + ' float;',
  17372. 'precision ' + parameters.precision + ' int;',
  17373. '#define SHADER_NAME ' + material.__webglShader.name,
  17374. customDefines,
  17375. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17376. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17377. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17378. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17379. '#define NUM_DIR_LIGHTS ' + parameters.numDirLights,
  17380. '#define NUM_POINT_LIGHTS ' + parameters.numPointLights,
  17381. '#define NUM_SPOT_LIGHTS ' + parameters.numSpotLights,
  17382. '#define NUM_HEMI_LIGHTS ' + parameters.numHemiLights,
  17383. '#define NUM_SHADOWS ' + parameters.numShadows,
  17384. '#define MAX_BONES ' + parameters.maxBones,
  17385. parameters.map ? '#define USE_MAP' : '',
  17386. parameters.envMap ? '#define USE_ENVMAP' : '',
  17387. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17388. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17389. parameters.aoMap ? '#define USE_AOMAP' : '',
  17390. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17391. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17392. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17393. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17394. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17395. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17396. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17397. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17398. parameters.vertexColors ? '#define USE_COLOR' : '',
  17399. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17400. parameters.skinning ? '#define USE_SKINNING' : '',
  17401. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17402. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17403. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17404. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17405. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17406. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17407. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17408. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  17409. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17410. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17411. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17412. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17413. 'uniform mat4 modelMatrix;',
  17414. 'uniform mat4 modelViewMatrix;',
  17415. 'uniform mat4 projectionMatrix;',
  17416. 'uniform mat4 viewMatrix;',
  17417. 'uniform mat3 normalMatrix;',
  17418. 'uniform vec3 cameraPosition;',
  17419. 'attribute vec3 position;',
  17420. 'attribute vec3 normal;',
  17421. 'attribute vec2 uv;',
  17422. '#ifdef USE_COLOR',
  17423. ' attribute vec3 color;',
  17424. '#endif',
  17425. '#ifdef USE_MORPHTARGETS',
  17426. ' attribute vec3 morphTarget0;',
  17427. ' attribute vec3 morphTarget1;',
  17428. ' attribute vec3 morphTarget2;',
  17429. ' attribute vec3 morphTarget3;',
  17430. ' #ifdef USE_MORPHNORMALS',
  17431. ' attribute vec3 morphNormal0;',
  17432. ' attribute vec3 morphNormal1;',
  17433. ' attribute vec3 morphNormal2;',
  17434. ' attribute vec3 morphNormal3;',
  17435. ' #else',
  17436. ' attribute vec3 morphTarget4;',
  17437. ' attribute vec3 morphTarget5;',
  17438. ' attribute vec3 morphTarget6;',
  17439. ' attribute vec3 morphTarget7;',
  17440. ' #endif',
  17441. '#endif',
  17442. '#ifdef USE_SKINNING',
  17443. ' attribute vec4 skinIndex;',
  17444. ' attribute vec4 skinWeight;',
  17445. '#endif',
  17446. '\n'
  17447. ].filter( filterEmptyLine ).join( '\n' );
  17448. prefixFragment = [
  17449. customExtensions,
  17450. 'precision ' + parameters.precision + ' float;',
  17451. 'precision ' + parameters.precision + ' int;',
  17452. '#define SHADER_NAME ' + material.__webglShader.name,
  17453. customDefines,
  17454. '#define NUM_DIR_LIGHTS ' + parameters.numDirLights,
  17455. '#define NUM_POINT_LIGHTS ' + parameters.numPointLights,
  17456. '#define NUM_SPOT_LIGHTS ' + parameters.numSpotLights,
  17457. '#define NUM_HEMI_LIGHTS ' + parameters.numHemiLights,
  17458. '#define NUM_SHADOWS ' + parameters.numShadows,
  17459. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17460. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17461. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17462. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17463. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17464. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17465. parameters.map ? '#define USE_MAP' : '',
  17466. parameters.envMap ? '#define USE_ENVMAP' : '',
  17467. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17468. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17469. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17470. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17471. parameters.aoMap ? '#define USE_AOMAP' : '',
  17472. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17473. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17474. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17475. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17476. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17477. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17478. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17479. parameters.vertexColors ? '#define USE_COLOR' : '',
  17480. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17481. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17482. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17483. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17484. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17485. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  17486. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17487. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17488. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17489. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17490. 'uniform mat4 viewMatrix;',
  17491. 'uniform vec3 cameraPosition;',
  17492. '\n'
  17493. ].filter( filterEmptyLine ).join( '\n' );
  17494. }
  17495. var vertexGlsl = prefixVertex + vertexShader;
  17496. var fragmentGlsl = prefixFragment + fragmentShader;
  17497. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17498. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17499. gl.attachShader( program, glVertexShader );
  17500. gl.attachShader( program, glFragmentShader );
  17501. // Force a particular attribute to index 0.
  17502. if ( material.index0AttributeName !== undefined ) {
  17503. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17504. } else if ( parameters.morphTargets === true ) {
  17505. // programs with morphTargets displace position out of attribute 0
  17506. gl.bindAttribLocation( program, 0, 'position' );
  17507. }
  17508. gl.linkProgram( program );
  17509. var programLog = gl.getProgramInfoLog( program );
  17510. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17511. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17512. var runnable = true;
  17513. var haveDiagnostics = true;
  17514. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17515. runnable = false;
  17516. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17517. } else if ( programLog !== '' ) {
  17518. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17519. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17520. haveDiagnostics = false;
  17521. }
  17522. if ( haveDiagnostics ) {
  17523. this.diagnostics = {
  17524. runnable: runnable,
  17525. material: material,
  17526. programLog: programLog,
  17527. vertexShader: {
  17528. log: vertexLog,
  17529. prefix: prefixVertex
  17530. },
  17531. fragmentShader: {
  17532. log: fragmentLog,
  17533. prefix: prefixFragment
  17534. }
  17535. };
  17536. }
  17537. // clean up
  17538. gl.deleteShader( glVertexShader );
  17539. gl.deleteShader( glFragmentShader );
  17540. // set up caching for uniform locations
  17541. var cachedUniforms;
  17542. this.getUniforms = function() {
  17543. if ( cachedUniforms === undefined ) {
  17544. cachedUniforms = fetchUniformLocations( gl, program );
  17545. }
  17546. return cachedUniforms;
  17547. };
  17548. // set up caching for attribute locations
  17549. var cachedAttributes;
  17550. this.getAttributes = function() {
  17551. if ( cachedAttributes === undefined ) {
  17552. cachedAttributes = fetchAttributeLocations( gl, program );
  17553. }
  17554. return cachedAttributes;
  17555. };
  17556. // free resource
  17557. this.destroy = function() {
  17558. gl.deleteProgram( program );
  17559. this.program = undefined;
  17560. };
  17561. // DEPRECATED
  17562. Object.defineProperties( this, {
  17563. uniforms: {
  17564. get: function() {
  17565. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17566. return this.getUniforms();
  17567. }
  17568. },
  17569. attributes: {
  17570. get: function() {
  17571. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17572. return this.getAttributes();
  17573. }
  17574. }
  17575. } );
  17576. //
  17577. this.id = programIdCount ++;
  17578. this.code = code;
  17579. this.usedTimes = 1;
  17580. this.program = program;
  17581. this.vertexShader = glVertexShader;
  17582. this.fragmentShader = glFragmentShader;
  17583. return this;
  17584. };
  17585. } )();
  17586. // File:src/renderers/webgl/WebGLPrograms.js
  17587. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17588. var programs = [];
  17589. var shaderIDs = {
  17590. MeshDepthMaterial: 'depth',
  17591. MeshNormalMaterial: 'normal',
  17592. MeshBasicMaterial: 'basic',
  17593. MeshLambertMaterial: 'lambert',
  17594. MeshPhongMaterial: 'phong',
  17595. MeshStandardMaterial: 'standard',
  17596. LineBasicMaterial: 'basic',
  17597. LineDashedMaterial: 'dashed',
  17598. PointsMaterial: 'points'
  17599. };
  17600. var parameterNames = [
  17601. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  17602. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17603. "roughnessMap", "metalnessMap",
  17604. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17605. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17606. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17607. "maxMorphTargets", "maxMorphNormals",
  17608. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17609. "numShadows", "shadowMapEnabled", "pointLightShadows",
  17610. "shadowMapType", "shadowMapDebug",
  17611. "alphaTest", "doubleSided", "flipSided"
  17612. ];
  17613. function allocateBones ( object ) {
  17614. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17615. return 1024;
  17616. } else {
  17617. // default for when object is not specified
  17618. // ( for example when prebuilding shader to be used with multiple objects )
  17619. //
  17620. // - leave some extra space for other uniforms
  17621. // - limit here is ANGLE's 254 max uniform vectors
  17622. // (up to 54 should be safe)
  17623. var nVertexUniforms = capabilities.maxVertexUniforms;
  17624. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17625. var maxBones = nVertexMatrices;
  17626. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17627. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17628. if ( maxBones < object.skeleton.bones.length ) {
  17629. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17630. }
  17631. }
  17632. return maxBones;
  17633. }
  17634. }
  17635. this.getParameters = function ( material, lights, fog, object ) {
  17636. var shaderID = shaderIDs[ material.type ];
  17637. // heuristics to create shader parameters according to lights in the scene
  17638. // (not to blow over maxLights budget)
  17639. var maxBones = allocateBones( object );
  17640. var precision = renderer.getPrecision();
  17641. if ( material.precision !== null ) {
  17642. precision = capabilities.getMaxPrecision( material.precision );
  17643. if ( precision !== material.precision ) {
  17644. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17645. }
  17646. }
  17647. var parameters = {
  17648. shaderID: shaderID,
  17649. precision: precision,
  17650. supportsVertexTextures: capabilities.vertexTextures,
  17651. map: !! material.map,
  17652. envMap: !! material.envMap,
  17653. envMapMode: material.envMap && material.envMap.mapping,
  17654. lightMap: !! material.lightMap,
  17655. aoMap: !! material.aoMap,
  17656. emissiveMap: !! material.emissiveMap,
  17657. bumpMap: !! material.bumpMap,
  17658. normalMap: !! material.normalMap,
  17659. displacementMap: !! material.displacementMap,
  17660. roughnessMap: !! material.roughnessMap,
  17661. metalnessMap: !! material.metalnessMap,
  17662. specularMap: !! material.specularMap,
  17663. alphaMap: !! material.alphaMap,
  17664. combine: material.combine,
  17665. vertexColors: material.vertexColors,
  17666. fog: fog,
  17667. useFog: material.fog,
  17668. fogExp: fog instanceof THREE.FogExp2,
  17669. flatShading: material.shading === THREE.FlatShading,
  17670. sizeAttenuation: material.sizeAttenuation,
  17671. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17672. skinning: material.skinning,
  17673. maxBones: maxBones,
  17674. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17675. morphTargets: material.morphTargets,
  17676. morphNormals: material.morphNormals,
  17677. maxMorphTargets: renderer.maxMorphTargets,
  17678. maxMorphNormals: renderer.maxMorphNormals,
  17679. numDirLights: lights.directional.length,
  17680. numPointLights: lights.point.length,
  17681. numSpotLights: lights.spot.length,
  17682. numHemiLights: lights.hemi.length,
  17683. numShadows: lights.shadows.length,
  17684. pointLightShadows: lights.shadowsPointLight,
  17685. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17686. shadowMapType: renderer.shadowMap.type,
  17687. shadowMapDebug: renderer.shadowMap.debug,
  17688. alphaTest: material.alphaTest,
  17689. doubleSided: material.side === THREE.DoubleSide,
  17690. flipSided: material.side === THREE.BackSide
  17691. };
  17692. return parameters;
  17693. };
  17694. this.getProgramCode = function ( material, parameters ) {
  17695. var chunks = [];
  17696. if ( parameters.shaderID ) {
  17697. chunks.push( parameters.shaderID );
  17698. } else {
  17699. chunks.push( material.fragmentShader );
  17700. chunks.push( material.vertexShader );
  17701. }
  17702. if ( material.defines !== undefined ) {
  17703. for ( var name in material.defines ) {
  17704. chunks.push( name );
  17705. chunks.push( material.defines[ name ] );
  17706. }
  17707. }
  17708. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17709. var parameterName = parameterNames[ i ];
  17710. chunks.push( parameterName );
  17711. chunks.push( parameters[ parameterName ] );
  17712. }
  17713. return chunks.join();
  17714. };
  17715. this.acquireProgram = function ( material, parameters, code ) {
  17716. var program;
  17717. // Check if code has been already compiled
  17718. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17719. var programInfo = programs[ p ];
  17720. if ( programInfo.code === code ) {
  17721. program = programInfo;
  17722. ++ program.usedTimes;
  17723. break;
  17724. }
  17725. }
  17726. if ( program === undefined ) {
  17727. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17728. programs.push( program );
  17729. }
  17730. return program;
  17731. };
  17732. this.releaseProgram = function( program ) {
  17733. if ( -- program.usedTimes === 0 ) {
  17734. // Remove from unordered set
  17735. var i = programs.indexOf( program );
  17736. programs[ i ] = programs[ programs.length - 1 ];
  17737. programs.pop();
  17738. // Free WebGL resources
  17739. program.destroy();
  17740. }
  17741. };
  17742. // Exposed for resource monitoring & error feedback via renderer.info:
  17743. this.programs = programs;
  17744. };
  17745. // File:src/renderers/webgl/WebGLProperties.js
  17746. /**
  17747. * @author fordacious / fordacious.github.io
  17748. */
  17749. THREE.WebGLProperties = function () {
  17750. var properties = {};
  17751. this.get = function ( object ) {
  17752. var uuid = object.uuid;
  17753. var map = properties[ uuid ];
  17754. if ( map === undefined ) {
  17755. map = {};
  17756. properties[ uuid ] = map;
  17757. }
  17758. return map;
  17759. };
  17760. this.delete = function ( object ) {
  17761. delete properties[ object.uuid ];
  17762. };
  17763. this.clear = function () {
  17764. properties = {};
  17765. };
  17766. };
  17767. // File:src/renderers/webgl/WebGLShader.js
  17768. THREE.WebGLShader = ( function () {
  17769. function addLineNumbers( string ) {
  17770. var lines = string.split( '\n' );
  17771. for ( var i = 0; i < lines.length; i ++ ) {
  17772. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17773. }
  17774. return lines.join( '\n' );
  17775. }
  17776. return function WebGLShader( gl, type, string ) {
  17777. var shader = gl.createShader( type );
  17778. gl.shaderSource( shader, string );
  17779. gl.compileShader( shader );
  17780. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17781. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17782. }
  17783. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17784. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17785. }
  17786. // --enable-privileged-webgl-extension
  17787. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17788. return shader;
  17789. };
  17790. } )();
  17791. // File:src/renderers/webgl/WebGLShadowMap.js
  17792. /**
  17793. * @author alteredq / http://alteredqualia.com/
  17794. * @author mrdoob / http://mrdoob.com/
  17795. */
  17796. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17797. var _gl = _renderer.context,
  17798. _state = _renderer.state,
  17799. _frustum = new THREE.Frustum(),
  17800. _projScreenMatrix = new THREE.Matrix4(),
  17801. _min = new THREE.Vector3(),
  17802. _max = new THREE.Vector3(),
  17803. _lookTarget = new THREE.Vector3(),
  17804. _lightPositionWorld = new THREE.Vector3(),
  17805. _renderList = [],
  17806. _MorphingFlag = 1,
  17807. _SkinningFlag = 2,
  17808. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17809. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17810. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  17811. var cubeDirections = [
  17812. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17813. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17814. ];
  17815. var cubeUps = [
  17816. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17817. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17818. ];
  17819. var cube2DViewPorts = [
  17820. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17821. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17822. ];
  17823. var _vector4 = new THREE.Vector4();
  17824. // init
  17825. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  17826. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  17827. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17828. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17829. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17830. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17831. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17832. var depthMaterial = new THREE.ShaderMaterial( {
  17833. uniforms: depthUniforms,
  17834. vertexShader: depthShader.vertexShader,
  17835. fragmentShader: depthShader.fragmentShader,
  17836. morphTargets: useMorphing,
  17837. skinning: useSkinning
  17838. } );
  17839. depthMaterial._shadowPass = true;
  17840. _depthMaterials[ i ] = depthMaterial;
  17841. var distanceMaterial = new THREE.ShaderMaterial( {
  17842. uniforms: distanceUniforms,
  17843. vertexShader: distanceShader.vertexShader,
  17844. fragmentShader: distanceShader.fragmentShader,
  17845. morphTargets: useMorphing,
  17846. skinning: useSkinning
  17847. } );
  17848. distanceMaterial._shadowPass = true;
  17849. _distanceMaterials[ i ] = distanceMaterial;
  17850. }
  17851. //
  17852. var scope = this;
  17853. this.enabled = false;
  17854. this.autoUpdate = true;
  17855. this.needsUpdate = false;
  17856. this.type = THREE.PCFShadowMap;
  17857. this.cullFace = THREE.CullFaceFront;
  17858. this.render = function ( scene, camera ) {
  17859. var faceCount, isPointLight;
  17860. if ( scope.enabled === false ) return;
  17861. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17862. // Save GL state
  17863. var currentScissorTest = _state.getScissorTest();
  17864. // save the existing viewport so it can be restored later
  17865. _renderer.getViewport( _vector4 );
  17866. // Set GL state for depth map.
  17867. _gl.clearColor( 1, 1, 1, 1 );
  17868. _state.disable( _gl.BLEND );
  17869. _state.enable( _gl.CULL_FACE );
  17870. _gl.frontFace( _gl.CCW );
  17871. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17872. _state.setDepthTest( true );
  17873. _state.setScissorTest( false );
  17874. // render depth map
  17875. var shadows = _lights.shadows;
  17876. for ( var i = 0, il = shadows.length; i < il; i ++ ) {
  17877. var light = shadows[ i ];
  17878. var shadow = light.shadow;
  17879. var shadowCamera = shadow.camera;
  17880. var shadowMapSize = shadow.mapSize;
  17881. if ( light instanceof THREE.PointLight ) {
  17882. faceCount = 6;
  17883. isPointLight = true;
  17884. var vpWidth = shadowMapSize.x / 4.0;
  17885. var vpHeight = shadowMapSize.y / 2.0;
  17886. // These viewports map a cube-map onto a 2D texture with the
  17887. // following orientation:
  17888. //
  17889. // xzXZ
  17890. // y Y
  17891. //
  17892. // X - Positive x direction
  17893. // x - Negative x direction
  17894. // Y - Positive y direction
  17895. // y - Negative y direction
  17896. // Z - Positive z direction
  17897. // z - Negative z direction
  17898. // positive X
  17899. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17900. // negative X
  17901. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17902. // positive Z
  17903. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17904. // negative Z
  17905. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17906. // positive Y
  17907. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17908. // negative Y
  17909. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17910. } else {
  17911. faceCount = 1;
  17912. isPointLight = false;
  17913. }
  17914. if ( shadow.map === null ) {
  17915. var shadowFilter = THREE.LinearFilter;
  17916. if ( scope.type === THREE.PCFSoftShadowMap ) {
  17917. shadowFilter = THREE.NearestFilter;
  17918. }
  17919. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  17920. shadow.map = new THREE.WebGLRenderTarget( shadowMapSize.x, shadowMapSize.y, pars );
  17921. shadow.matrix = new THREE.Matrix4();
  17922. //
  17923. if ( light instanceof THREE.SpotLight ) {
  17924. shadowCamera.aspect = shadowMapSize.x / shadowMapSize.y;
  17925. }
  17926. shadowCamera.updateProjectionMatrix();
  17927. }
  17928. var shadowMap = shadow.map;
  17929. var shadowMatrix = shadow.matrix;
  17930. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17931. shadowCamera.position.copy( _lightPositionWorld );
  17932. _renderer.setRenderTarget( shadowMap );
  17933. _renderer.clear();
  17934. // render shadow map for each cube face (if omni-directional) or
  17935. // run a single pass if not
  17936. for ( var face = 0; face < faceCount; face ++ ) {
  17937. if ( isPointLight ) {
  17938. _lookTarget.copy( shadowCamera.position );
  17939. _lookTarget.add( cubeDirections[ face ] );
  17940. shadowCamera.up.copy( cubeUps[ face ] );
  17941. shadowCamera.lookAt( _lookTarget );
  17942. var vpDimensions = cube2DViewPorts[ face ];
  17943. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  17944. } else {
  17945. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17946. shadowCamera.lookAt( _lookTarget );
  17947. }
  17948. shadowCamera.updateMatrixWorld();
  17949. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17950. // compute shadow matrix
  17951. shadowMatrix.set(
  17952. 0.5, 0.0, 0.0, 0.5,
  17953. 0.0, 0.5, 0.0, 0.5,
  17954. 0.0, 0.0, 0.5, 0.5,
  17955. 0.0, 0.0, 0.0, 1.0
  17956. );
  17957. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17958. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17959. // update camera matrices and frustum
  17960. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17961. _frustum.setFromMatrix( _projScreenMatrix );
  17962. // set object matrices & frustum culling
  17963. _renderList.length = 0;
  17964. projectObject( scene, camera, shadowCamera );
  17965. // render shadow map
  17966. // render regular objects
  17967. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17968. var object = _renderList[ j ];
  17969. var geometry = _objects.update( object );
  17970. var material = object.material;
  17971. if ( material instanceof THREE.MeshFaceMaterial ) {
  17972. var groups = geometry.groups;
  17973. var materials = material.materials;
  17974. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17975. var group = groups[ k ];
  17976. var groupMaterial = materials[ group.materialIndex ];
  17977. if ( groupMaterial.visible === true ) {
  17978. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17979. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17980. }
  17981. }
  17982. } else {
  17983. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17984. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17985. }
  17986. }
  17987. }
  17988. // We must call _renderer.resetGLState() at the end of each iteration of
  17989. // the light loop in order to force material updates for each light.
  17990. _renderer.resetGLState();
  17991. }
  17992. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  17993. // Restore GL state.
  17994. var clearColor = _renderer.getClearColor(),
  17995. clearAlpha = _renderer.getClearAlpha();
  17996. _renderer.setClearColor( clearColor, clearAlpha );
  17997. _state.enable( _gl.BLEND );
  17998. if ( currentScissorTest === true ) {
  17999. _state.setScissorTest( true );
  18000. }
  18001. if ( scope.cullFace === THREE.CullFaceFront ) {
  18002. _gl.cullFace( _gl.BACK );
  18003. }
  18004. _renderer.resetGLState();
  18005. scope.needsUpdate = false;
  18006. };
  18007. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  18008. var geometry = object.geometry;
  18009. var newMaterial = null;
  18010. var materialVariants = _depthMaterials;
  18011. var customMaterial = object.customDepthMaterial;
  18012. if ( isPointLight ) {
  18013. materialVariants = _distanceMaterials;
  18014. customMaterial = object.customDistanceMaterial;
  18015. }
  18016. if ( ! customMaterial ) {
  18017. var useMorphing = geometry.morphTargets !== undefined &&
  18018. geometry.morphTargets.length > 0 && material.morphTargets;
  18019. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  18020. var variantIndex = 0;
  18021. if ( useMorphing ) variantIndex |= _MorphingFlag;
  18022. if ( useSkinning ) variantIndex |= _SkinningFlag;
  18023. newMaterial = materialVariants[ variantIndex ];
  18024. } else {
  18025. newMaterial = customMaterial;
  18026. }
  18027. newMaterial.visible = material.visible;
  18028. newMaterial.wireframe = material.wireframe;
  18029. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  18030. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  18031. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  18032. }
  18033. return newMaterial;
  18034. }
  18035. function projectObject( object, camera, shadowCamera ) {
  18036. if ( object.visible === false ) return;
  18037. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  18038. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  18039. var material = object.material;
  18040. if ( material.visible === true ) {
  18041. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  18042. _renderList.push( object );
  18043. }
  18044. }
  18045. }
  18046. var children = object.children;
  18047. for ( var i = 0, l = children.length; i < l; i ++ ) {
  18048. projectObject( children[ i ], camera, shadowCamera );
  18049. }
  18050. }
  18051. };
  18052. // File:src/renderers/webgl/WebGLState.js
  18053. /**
  18054. * @author mrdoob / http://mrdoob.com/
  18055. */
  18056. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  18057. var _this = this;
  18058. var newAttributes = new Uint8Array( 16 );
  18059. var enabledAttributes = new Uint8Array( 16 );
  18060. var attributeDivisors = new Uint8Array( 16 );
  18061. var capabilities = {};
  18062. var compressedTextureFormats = null;
  18063. var currentBlending = null;
  18064. var currentBlendEquation = null;
  18065. var currentBlendSrc = null;
  18066. var currentBlendDst = null;
  18067. var currentBlendEquationAlpha = null;
  18068. var currentBlendSrcAlpha = null;
  18069. var currentBlendDstAlpha = null;
  18070. var currentDepthFunc = null;
  18071. var currentDepthWrite = null;
  18072. var currentColorWrite = null;
  18073. var currentFlipSided = null;
  18074. var currentLineWidth = null;
  18075. var currentPolygonOffsetFactor = null;
  18076. var currentPolygonOffsetUnits = null;
  18077. var currentScissorTest = null;
  18078. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  18079. var currentTextureSlot = undefined;
  18080. var currentBoundTextures = {};
  18081. this.init = function () {
  18082. gl.clearColor( 0, 0, 0, 1 );
  18083. gl.clearDepth( 1 );
  18084. gl.clearStencil( 0 );
  18085. this.enable( gl.DEPTH_TEST );
  18086. gl.depthFunc( gl.LEQUAL );
  18087. gl.frontFace( gl.CCW );
  18088. gl.cullFace( gl.BACK );
  18089. this.enable( gl.CULL_FACE );
  18090. this.enable( gl.BLEND );
  18091. gl.blendEquation( gl.FUNC_ADD );
  18092. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  18093. };
  18094. this.initAttributes = function () {
  18095. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  18096. newAttributes[ i ] = 0;
  18097. }
  18098. };
  18099. this.enableAttribute = function ( attribute ) {
  18100. newAttributes[ attribute ] = 1;
  18101. if ( enabledAttributes[ attribute ] === 0 ) {
  18102. gl.enableVertexAttribArray( attribute );
  18103. enabledAttributes[ attribute ] = 1;
  18104. }
  18105. if ( attributeDivisors[ attribute ] !== 0 ) {
  18106. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  18107. extension.vertexAttribDivisorANGLE( attribute, 0 );
  18108. attributeDivisors[ attribute ] = 0;
  18109. }
  18110. };
  18111. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  18112. newAttributes[ attribute ] = 1;
  18113. if ( enabledAttributes[ attribute ] === 0 ) {
  18114. gl.enableVertexAttribArray( attribute );
  18115. enabledAttributes[ attribute ] = 1;
  18116. }
  18117. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  18118. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  18119. attributeDivisors[ attribute ] = meshPerAttribute;
  18120. }
  18121. };
  18122. this.disableUnusedAttributes = function () {
  18123. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  18124. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  18125. gl.disableVertexAttribArray( i );
  18126. enabledAttributes[ i ] = 0;
  18127. }
  18128. }
  18129. };
  18130. this.enable = function ( id ) {
  18131. if ( capabilities[ id ] !== true ) {
  18132. gl.enable( id );
  18133. capabilities[ id ] = true;
  18134. }
  18135. };
  18136. this.disable = function ( id ) {
  18137. if ( capabilities[ id ] !== false ) {
  18138. gl.disable( id );
  18139. capabilities[ id ] = false;
  18140. }
  18141. };
  18142. this.getCompressedTextureFormats = function () {
  18143. if ( compressedTextureFormats === null ) {
  18144. compressedTextureFormats = [];
  18145. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  18146. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  18147. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  18148. for ( var i = 0; i < formats.length; i ++ ) {
  18149. compressedTextureFormats.push( formats[ i ] );
  18150. }
  18151. }
  18152. }
  18153. return compressedTextureFormats;
  18154. };
  18155. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  18156. if ( blending !== currentBlending ) {
  18157. if ( blending === THREE.NoBlending ) {
  18158. this.disable( gl.BLEND );
  18159. } else if ( blending === THREE.AdditiveBlending ) {
  18160. this.enable( gl.BLEND );
  18161. gl.blendEquation( gl.FUNC_ADD );
  18162. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18163. } else if ( blending === THREE.SubtractiveBlending ) {
  18164. // TODO: Find blendFuncSeparate() combination
  18165. this.enable( gl.BLEND );
  18166. gl.blendEquation( gl.FUNC_ADD );
  18167. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18168. } else if ( blending === THREE.MultiplyBlending ) {
  18169. // TODO: Find blendFuncSeparate() combination
  18170. this.enable( gl.BLEND );
  18171. gl.blendEquation( gl.FUNC_ADD );
  18172. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18173. } else if ( blending === THREE.CustomBlending ) {
  18174. this.enable( gl.BLEND );
  18175. } else {
  18176. this.enable( gl.BLEND );
  18177. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18178. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18179. }
  18180. currentBlending = blending;
  18181. }
  18182. if ( blending === THREE.CustomBlending ) {
  18183. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18184. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18185. blendDstAlpha = blendDstAlpha || blendDst;
  18186. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18187. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18188. currentBlendEquation = blendEquation;
  18189. currentBlendEquationAlpha = blendEquationAlpha;
  18190. }
  18191. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18192. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18193. currentBlendSrc = blendSrc;
  18194. currentBlendDst = blendDst;
  18195. currentBlendSrcAlpha = blendSrcAlpha;
  18196. currentBlendDstAlpha = blendDstAlpha;
  18197. }
  18198. } else {
  18199. currentBlendEquation = null;
  18200. currentBlendSrc = null;
  18201. currentBlendDst = null;
  18202. currentBlendEquationAlpha = null;
  18203. currentBlendSrcAlpha = null;
  18204. currentBlendDstAlpha = null;
  18205. }
  18206. };
  18207. this.setDepthFunc = function ( depthFunc ) {
  18208. if ( currentDepthFunc !== depthFunc ) {
  18209. if ( depthFunc ) {
  18210. switch ( depthFunc ) {
  18211. case THREE.NeverDepth:
  18212. gl.depthFunc( gl.NEVER );
  18213. break;
  18214. case THREE.AlwaysDepth:
  18215. gl.depthFunc( gl.ALWAYS );
  18216. break;
  18217. case THREE.LessDepth:
  18218. gl.depthFunc( gl.LESS );
  18219. break;
  18220. case THREE.LessEqualDepth:
  18221. gl.depthFunc( gl.LEQUAL );
  18222. break;
  18223. case THREE.EqualDepth:
  18224. gl.depthFunc( gl.EQUAL );
  18225. break;
  18226. case THREE.GreaterEqualDepth:
  18227. gl.depthFunc( gl.GEQUAL );
  18228. break;
  18229. case THREE.GreaterDepth:
  18230. gl.depthFunc( gl.GREATER );
  18231. break;
  18232. case THREE.NotEqualDepth:
  18233. gl.depthFunc( gl.NOTEQUAL );
  18234. break;
  18235. default:
  18236. gl.depthFunc( gl.LEQUAL );
  18237. }
  18238. } else {
  18239. gl.depthFunc( gl.LEQUAL );
  18240. }
  18241. currentDepthFunc = depthFunc;
  18242. }
  18243. };
  18244. this.setDepthTest = function ( depthTest ) {
  18245. if ( depthTest ) {
  18246. this.enable( gl.DEPTH_TEST );
  18247. } else {
  18248. this.disable( gl.DEPTH_TEST );
  18249. }
  18250. };
  18251. this.setDepthWrite = function ( depthWrite ) {
  18252. if ( currentDepthWrite !== depthWrite ) {
  18253. gl.depthMask( depthWrite );
  18254. currentDepthWrite = depthWrite;
  18255. }
  18256. };
  18257. this.setColorWrite = function ( colorWrite ) {
  18258. if ( currentColorWrite !== colorWrite ) {
  18259. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18260. currentColorWrite = colorWrite;
  18261. }
  18262. };
  18263. this.setFlipSided = function ( flipSided ) {
  18264. if ( currentFlipSided !== flipSided ) {
  18265. if ( flipSided ) {
  18266. gl.frontFace( gl.CW );
  18267. } else {
  18268. gl.frontFace( gl.CCW );
  18269. }
  18270. currentFlipSided = flipSided;
  18271. }
  18272. };
  18273. this.setLineWidth = function ( width ) {
  18274. if ( width !== currentLineWidth ) {
  18275. gl.lineWidth( width );
  18276. currentLineWidth = width;
  18277. }
  18278. };
  18279. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18280. if ( polygonOffset ) {
  18281. this.enable( gl.POLYGON_OFFSET_FILL );
  18282. } else {
  18283. this.disable( gl.POLYGON_OFFSET_FILL );
  18284. }
  18285. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18286. gl.polygonOffset( factor, units );
  18287. currentPolygonOffsetFactor = factor;
  18288. currentPolygonOffsetUnits = units;
  18289. }
  18290. };
  18291. this.getScissorTest = function () {
  18292. return currentScissorTest;
  18293. };
  18294. this.setScissorTest = function ( scissorTest ) {
  18295. currentScissorTest = scissorTest;
  18296. if ( scissorTest ) {
  18297. this.enable( gl.SCISSOR_TEST );
  18298. } else {
  18299. this.disable( gl.SCISSOR_TEST );
  18300. }
  18301. };
  18302. // texture
  18303. this.activeTexture = function ( webglSlot ) {
  18304. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18305. if ( currentTextureSlot !== webglSlot ) {
  18306. gl.activeTexture( webglSlot );
  18307. currentTextureSlot = webglSlot;
  18308. }
  18309. }
  18310. this.bindTexture = function ( webglType, webglTexture ) {
  18311. if ( currentTextureSlot === undefined ) {
  18312. _this.activeTexture();
  18313. }
  18314. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18315. if ( boundTexture === undefined ) {
  18316. boundTexture = { type: undefined, texture: undefined };
  18317. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18318. }
  18319. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18320. gl.bindTexture( webglType, webglTexture );
  18321. boundTexture.type = webglType;
  18322. boundTexture.texture = webglTexture;
  18323. }
  18324. };
  18325. this.compressedTexImage2D = function () {
  18326. try {
  18327. gl.compressedTexImage2D.apply( gl, arguments );
  18328. } catch ( error ) {
  18329. console.error( error );
  18330. }
  18331. };
  18332. this.texImage2D = function () {
  18333. try {
  18334. gl.texImage2D.apply( gl, arguments );
  18335. } catch ( error ) {
  18336. console.error( error );
  18337. }
  18338. };
  18339. //
  18340. this.reset = function () {
  18341. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18342. if ( enabledAttributes[ i ] === 1 ) {
  18343. gl.disableVertexAttribArray( i );
  18344. enabledAttributes[ i ] = 0;
  18345. }
  18346. }
  18347. capabilities = {};
  18348. compressedTextureFormats = null;
  18349. currentBlending = null;
  18350. currentDepthWrite = null;
  18351. currentColorWrite = null;
  18352. currentFlipSided = null;
  18353. };
  18354. };
  18355. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18356. /**
  18357. * @author mikael emtinger / http://gomo.se/
  18358. * @author alteredq / http://alteredqualia.com/
  18359. */
  18360. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18361. var gl = renderer.context;
  18362. var state = renderer.state;
  18363. var vertexBuffer, elementBuffer;
  18364. var program, attributes, uniforms;
  18365. var hasVertexTexture;
  18366. var tempTexture, occlusionTexture;
  18367. function init() {
  18368. var vertices = new Float32Array( [
  18369. - 1, - 1, 0, 0,
  18370. 1, - 1, 1, 0,
  18371. 1, 1, 1, 1,
  18372. - 1, 1, 0, 1
  18373. ] );
  18374. var faces = new Uint16Array( [
  18375. 0, 1, 2,
  18376. 0, 2, 3
  18377. ] );
  18378. // buffers
  18379. vertexBuffer = gl.createBuffer();
  18380. elementBuffer = gl.createBuffer();
  18381. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18382. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18383. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18384. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18385. // textures
  18386. tempTexture = gl.createTexture();
  18387. occlusionTexture = gl.createTexture();
  18388. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18389. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18390. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18391. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18392. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18393. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18394. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18395. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18396. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18397. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18398. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18399. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18400. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18401. var shader;
  18402. if ( hasVertexTexture ) {
  18403. shader = {
  18404. vertexShader: [
  18405. "uniform lowp int renderType;",
  18406. "uniform vec3 screenPosition;",
  18407. "uniform vec2 scale;",
  18408. "uniform float rotation;",
  18409. "uniform sampler2D occlusionMap;",
  18410. "attribute vec2 position;",
  18411. "attribute vec2 uv;",
  18412. "varying vec2 vUV;",
  18413. "varying float vVisibility;",
  18414. "void main() {",
  18415. "vUV = uv;",
  18416. "vec2 pos = position;",
  18417. "if ( renderType == 2 ) {",
  18418. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18419. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18420. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18421. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18422. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18423. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18424. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18425. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18426. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18427. "vVisibility = visibility.r / 9.0;",
  18428. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18429. "vVisibility *= visibility.b / 9.0;",
  18430. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18431. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18432. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18433. "}",
  18434. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18435. "}"
  18436. ].join( "\n" ),
  18437. fragmentShader: [
  18438. "uniform lowp int renderType;",
  18439. "uniform sampler2D map;",
  18440. "uniform float opacity;",
  18441. "uniform vec3 color;",
  18442. "varying vec2 vUV;",
  18443. "varying float vVisibility;",
  18444. "void main() {",
  18445. // pink square
  18446. "if ( renderType == 0 ) {",
  18447. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18448. // restore
  18449. "} else if ( renderType == 1 ) {",
  18450. "gl_FragColor = texture2D( map, vUV );",
  18451. // flare
  18452. "} else {",
  18453. "vec4 texture = texture2D( map, vUV );",
  18454. "texture.a *= opacity * vVisibility;",
  18455. "gl_FragColor = texture;",
  18456. "gl_FragColor.rgb *= color;",
  18457. "}",
  18458. "}"
  18459. ].join( "\n" )
  18460. };
  18461. } else {
  18462. shader = {
  18463. vertexShader: [
  18464. "uniform lowp int renderType;",
  18465. "uniform vec3 screenPosition;",
  18466. "uniform vec2 scale;",
  18467. "uniform float rotation;",
  18468. "attribute vec2 position;",
  18469. "attribute vec2 uv;",
  18470. "varying vec2 vUV;",
  18471. "void main() {",
  18472. "vUV = uv;",
  18473. "vec2 pos = position;",
  18474. "if ( renderType == 2 ) {",
  18475. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18476. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18477. "}",
  18478. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18479. "}"
  18480. ].join( "\n" ),
  18481. fragmentShader: [
  18482. "precision mediump float;",
  18483. "uniform lowp int renderType;",
  18484. "uniform sampler2D map;",
  18485. "uniform sampler2D occlusionMap;",
  18486. "uniform float opacity;",
  18487. "uniform vec3 color;",
  18488. "varying vec2 vUV;",
  18489. "void main() {",
  18490. // pink square
  18491. "if ( renderType == 0 ) {",
  18492. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18493. // restore
  18494. "} else if ( renderType == 1 ) {",
  18495. "gl_FragColor = texture2D( map, vUV );",
  18496. // flare
  18497. "} else {",
  18498. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18499. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18500. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18501. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18502. "visibility = ( 1.0 - visibility / 4.0 );",
  18503. "vec4 texture = texture2D( map, vUV );",
  18504. "texture.a *= opacity * visibility;",
  18505. "gl_FragColor = texture;",
  18506. "gl_FragColor.rgb *= color;",
  18507. "}",
  18508. "}"
  18509. ].join( "\n" )
  18510. };
  18511. }
  18512. program = createProgram( shader );
  18513. attributes = {
  18514. vertex: gl.getAttribLocation ( program, "position" ),
  18515. uv: gl.getAttribLocation ( program, "uv" )
  18516. };
  18517. uniforms = {
  18518. renderType: gl.getUniformLocation( program, "renderType" ),
  18519. map: gl.getUniformLocation( program, "map" ),
  18520. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18521. opacity: gl.getUniformLocation( program, "opacity" ),
  18522. color: gl.getUniformLocation( program, "color" ),
  18523. scale: gl.getUniformLocation( program, "scale" ),
  18524. rotation: gl.getUniformLocation( program, "rotation" ),
  18525. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18526. };
  18527. }
  18528. /*
  18529. * Render lens flares
  18530. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18531. * reads these back and calculates occlusion.
  18532. */
  18533. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  18534. if ( flares.length === 0 ) return;
  18535. var tempPosition = new THREE.Vector3();
  18536. var invAspect = viewportHeight / viewportWidth,
  18537. halfViewportWidth = viewportWidth * 0.5,
  18538. halfViewportHeight = viewportHeight * 0.5;
  18539. var size = 16 / viewportHeight,
  18540. scale = new THREE.Vector2( size * invAspect, size );
  18541. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18542. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18543. if ( program === undefined ) {
  18544. init();
  18545. }
  18546. gl.useProgram( program );
  18547. state.initAttributes();
  18548. state.enableAttribute( attributes.vertex );
  18549. state.enableAttribute( attributes.uv );
  18550. state.disableUnusedAttributes();
  18551. // loop through all lens flares to update their occlusion and positions
  18552. // setup gl and common used attribs/uniforms
  18553. gl.uniform1i( uniforms.occlusionMap, 0 );
  18554. gl.uniform1i( uniforms.map, 1 );
  18555. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18556. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18557. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18558. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18559. state.disable( gl.CULL_FACE );
  18560. gl.depthMask( false );
  18561. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18562. size = 16 / viewportHeight;
  18563. scale.set( size * invAspect, size );
  18564. // calc object screen position
  18565. var flare = flares[ i ];
  18566. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18567. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18568. tempPosition.applyProjection( camera.projectionMatrix );
  18569. // setup arrays for gl programs
  18570. screenPosition.copy( tempPosition );
  18571. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18572. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18573. // screen cull
  18574. if ( hasVertexTexture || (
  18575. screenPositionPixels.x > 0 &&
  18576. screenPositionPixels.x < viewportWidth &&
  18577. screenPositionPixels.y > 0 &&
  18578. screenPositionPixels.y < viewportHeight ) ) {
  18579. // save current RGB to temp texture
  18580. state.activeTexture( gl.TEXTURE0 );
  18581. state.bindTexture( gl.TEXTURE_2D, null );
  18582. state.activeTexture( gl.TEXTURE1 );
  18583. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18584. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  18585. // render pink quad
  18586. gl.uniform1i( uniforms.renderType, 0 );
  18587. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18588. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18589. state.disable( gl.BLEND );
  18590. state.enable( gl.DEPTH_TEST );
  18591. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18592. // copy result to occlusionMap
  18593. state.activeTexture( gl.TEXTURE0 );
  18594. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18595. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  18596. // restore graphics
  18597. gl.uniform1i( uniforms.renderType, 1 );
  18598. state.disable( gl.DEPTH_TEST );
  18599. state.activeTexture( gl.TEXTURE1 );
  18600. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18601. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18602. // update object positions
  18603. flare.positionScreen.copy( screenPosition );
  18604. if ( flare.customUpdateCallback ) {
  18605. flare.customUpdateCallback( flare );
  18606. } else {
  18607. flare.updateLensFlares();
  18608. }
  18609. // render flares
  18610. gl.uniform1i( uniforms.renderType, 2 );
  18611. state.enable( gl.BLEND );
  18612. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18613. var sprite = flare.lensFlares[ j ];
  18614. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18615. screenPosition.x = sprite.x;
  18616. screenPosition.y = sprite.y;
  18617. screenPosition.z = sprite.z;
  18618. size = sprite.size * sprite.scale / viewportHeight;
  18619. scale.x = size * invAspect;
  18620. scale.y = size;
  18621. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18622. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18623. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18624. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18625. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18626. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18627. renderer.setTexture( sprite.texture, 1 );
  18628. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18629. }
  18630. }
  18631. }
  18632. }
  18633. // restore gl
  18634. state.enable( gl.CULL_FACE );
  18635. state.enable( gl.DEPTH_TEST );
  18636. gl.depthMask( true );
  18637. renderer.resetGLState();
  18638. };
  18639. function createProgram ( shader ) {
  18640. var program = gl.createProgram();
  18641. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18642. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18643. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18644. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18645. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18646. gl.compileShader( fragmentShader );
  18647. gl.compileShader( vertexShader );
  18648. gl.attachShader( program, fragmentShader );
  18649. gl.attachShader( program, vertexShader );
  18650. gl.linkProgram( program );
  18651. return program;
  18652. }
  18653. };
  18654. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18655. /**
  18656. * @author mikael emtinger / http://gomo.se/
  18657. * @author alteredq / http://alteredqualia.com/
  18658. */
  18659. THREE.SpritePlugin = function ( renderer, sprites ) {
  18660. var gl = renderer.context;
  18661. var state = renderer.state;
  18662. var vertexBuffer, elementBuffer;
  18663. var program, attributes, uniforms;
  18664. var texture;
  18665. // decompose matrixWorld
  18666. var spritePosition = new THREE.Vector3();
  18667. var spriteRotation = new THREE.Quaternion();
  18668. var spriteScale = new THREE.Vector3();
  18669. function init() {
  18670. var vertices = new Float32Array( [
  18671. - 0.5, - 0.5, 0, 0,
  18672. 0.5, - 0.5, 1, 0,
  18673. 0.5, 0.5, 1, 1,
  18674. - 0.5, 0.5, 0, 1
  18675. ] );
  18676. var faces = new Uint16Array( [
  18677. 0, 1, 2,
  18678. 0, 2, 3
  18679. ] );
  18680. vertexBuffer = gl.createBuffer();
  18681. elementBuffer = gl.createBuffer();
  18682. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18683. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18684. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18685. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18686. program = createProgram();
  18687. attributes = {
  18688. position: gl.getAttribLocation ( program, 'position' ),
  18689. uv: gl.getAttribLocation ( program, 'uv' )
  18690. };
  18691. uniforms = {
  18692. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18693. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18694. rotation: gl.getUniformLocation( program, 'rotation' ),
  18695. scale: gl.getUniformLocation( program, 'scale' ),
  18696. color: gl.getUniformLocation( program, 'color' ),
  18697. map: gl.getUniformLocation( program, 'map' ),
  18698. opacity: gl.getUniformLocation( program, 'opacity' ),
  18699. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18700. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18701. fogType: gl.getUniformLocation( program, 'fogType' ),
  18702. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18703. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18704. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18705. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18706. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18707. };
  18708. var canvas = document.createElement( 'canvas' );
  18709. canvas.width = 8;
  18710. canvas.height = 8;
  18711. var context = canvas.getContext( '2d' );
  18712. context.fillStyle = 'white';
  18713. context.fillRect( 0, 0, 8, 8 );
  18714. texture = new THREE.Texture( canvas );
  18715. texture.needsUpdate = true;
  18716. }
  18717. this.render = function ( scene, camera ) {
  18718. if ( sprites.length === 0 ) return;
  18719. // setup gl
  18720. if ( program === undefined ) {
  18721. init();
  18722. }
  18723. gl.useProgram( program );
  18724. state.initAttributes();
  18725. state.enableAttribute( attributes.position );
  18726. state.enableAttribute( attributes.uv );
  18727. state.disableUnusedAttributes();
  18728. state.disable( gl.CULL_FACE );
  18729. state.enable( gl.BLEND );
  18730. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18731. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  18732. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18733. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18734. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  18735. state.activeTexture( gl.TEXTURE0 );
  18736. gl.uniform1i( uniforms.map, 0 );
  18737. var oldFogType = 0;
  18738. var sceneFogType = 0;
  18739. var fog = scene.fog;
  18740. if ( fog ) {
  18741. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  18742. if ( fog instanceof THREE.Fog ) {
  18743. gl.uniform1f( uniforms.fogNear, fog.near );
  18744. gl.uniform1f( uniforms.fogFar, fog.far );
  18745. gl.uniform1i( uniforms.fogType, 1 );
  18746. oldFogType = 1;
  18747. sceneFogType = 1;
  18748. } else if ( fog instanceof THREE.FogExp2 ) {
  18749. gl.uniform1f( uniforms.fogDensity, fog.density );
  18750. gl.uniform1i( uniforms.fogType, 2 );
  18751. oldFogType = 2;
  18752. sceneFogType = 2;
  18753. }
  18754. } else {
  18755. gl.uniform1i( uniforms.fogType, 0 );
  18756. oldFogType = 0;
  18757. sceneFogType = 0;
  18758. }
  18759. // update positions and sort
  18760. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18761. var sprite = sprites[ i ];
  18762. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  18763. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  18764. }
  18765. sprites.sort( painterSortStable );
  18766. // render all sprites
  18767. var scale = [];
  18768. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18769. var sprite = sprites[ i ];
  18770. var material = sprite.material;
  18771. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  18772. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  18773. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  18774. scale[ 0 ] = spriteScale.x;
  18775. scale[ 1 ] = spriteScale.y;
  18776. var fogType = 0;
  18777. if ( scene.fog && material.fog ) {
  18778. fogType = sceneFogType;
  18779. }
  18780. if ( oldFogType !== fogType ) {
  18781. gl.uniform1i( uniforms.fogType, fogType );
  18782. oldFogType = fogType;
  18783. }
  18784. if ( material.map !== null ) {
  18785. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  18786. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  18787. } else {
  18788. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  18789. gl.uniform2f( uniforms.uvScale, 1, 1 );
  18790. }
  18791. gl.uniform1f( uniforms.opacity, material.opacity );
  18792. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  18793. gl.uniform1f( uniforms.rotation, material.rotation );
  18794. gl.uniform2fv( uniforms.scale, scale );
  18795. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  18796. state.setDepthTest( material.depthTest );
  18797. state.setDepthWrite( material.depthWrite );
  18798. if ( material.map && material.map.image && material.map.image.width ) {
  18799. renderer.setTexture( material.map, 0 );
  18800. } else {
  18801. renderer.setTexture( texture, 0 );
  18802. }
  18803. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18804. }
  18805. // restore gl
  18806. state.enable( gl.CULL_FACE );
  18807. renderer.resetGLState();
  18808. };
  18809. function createProgram () {
  18810. var program = gl.createProgram();
  18811. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18812. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18813. gl.shaderSource( vertexShader, [
  18814. 'precision ' + renderer.getPrecision() + ' float;',
  18815. 'uniform mat4 modelViewMatrix;',
  18816. 'uniform mat4 projectionMatrix;',
  18817. 'uniform float rotation;',
  18818. 'uniform vec2 scale;',
  18819. 'uniform vec2 uvOffset;',
  18820. 'uniform vec2 uvScale;',
  18821. 'attribute vec2 position;',
  18822. 'attribute vec2 uv;',
  18823. 'varying vec2 vUV;',
  18824. 'void main() {',
  18825. 'vUV = uvOffset + uv * uvScale;',
  18826. 'vec2 alignedPosition = position * scale;',
  18827. 'vec2 rotatedPosition;',
  18828. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  18829. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  18830. 'vec4 finalPosition;',
  18831. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  18832. 'finalPosition.xy += rotatedPosition;',
  18833. 'finalPosition = projectionMatrix * finalPosition;',
  18834. 'gl_Position = finalPosition;',
  18835. '}'
  18836. ].join( '\n' ) );
  18837. gl.shaderSource( fragmentShader, [
  18838. 'precision ' + renderer.getPrecision() + ' float;',
  18839. 'uniform vec3 color;',
  18840. 'uniform sampler2D map;',
  18841. 'uniform float opacity;',
  18842. 'uniform int fogType;',
  18843. 'uniform vec3 fogColor;',
  18844. 'uniform float fogDensity;',
  18845. 'uniform float fogNear;',
  18846. 'uniform float fogFar;',
  18847. 'uniform float alphaTest;',
  18848. 'varying vec2 vUV;',
  18849. 'void main() {',
  18850. 'vec4 texture = texture2D( map, vUV );',
  18851. 'if ( texture.a < alphaTest ) discard;',
  18852. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  18853. 'if ( fogType > 0 ) {',
  18854. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  18855. 'float fogFactor = 0.0;',
  18856. 'if ( fogType == 1 ) {',
  18857. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  18858. '} else {',
  18859. 'const float LOG2 = 1.442695;',
  18860. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  18861. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  18862. '}',
  18863. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  18864. '}',
  18865. '}'
  18866. ].join( '\n' ) );
  18867. gl.compileShader( vertexShader );
  18868. gl.compileShader( fragmentShader );
  18869. gl.attachShader( program, vertexShader );
  18870. gl.attachShader( program, fragmentShader );
  18871. gl.linkProgram( program );
  18872. return program;
  18873. }
  18874. function painterSortStable ( a, b ) {
  18875. if ( a.z !== b.z ) {
  18876. return b.z - a.z;
  18877. } else {
  18878. return b.id - a.id;
  18879. }
  18880. }
  18881. };
  18882. // File:src/Three.Legacy.js
  18883. /**
  18884. * @author mrdoob / http://mrdoob.com/
  18885. */
  18886. Object.defineProperties( THREE.Box2.prototype, {
  18887. isIntersectionBox: {
  18888. value: function ( box ) {
  18889. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18890. return this.intersectsBox( box );
  18891. }
  18892. }
  18893. } );
  18894. Object.defineProperties( THREE.Box3.prototype, {
  18895. isIntersectionBox: {
  18896. value: function ( box ) {
  18897. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18898. return this.intersectsBox( box );
  18899. }
  18900. },
  18901. isIntersectionSphere: {
  18902. value: function ( sphere ) {
  18903. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18904. return this.intersectsSphere( sphere );
  18905. }
  18906. }
  18907. } );
  18908. Object.defineProperties( THREE.Matrix3.prototype, {
  18909. multiplyVector3: {
  18910. value: function ( vector ) {
  18911. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  18912. return vector.applyMatrix3( this );
  18913. }
  18914. },
  18915. multiplyVector3Array: {
  18916. value: function ( a ) {
  18917. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18918. return this.applyToVector3Array( a );
  18919. }
  18920. }
  18921. } );
  18922. Object.defineProperties( THREE.Matrix4.prototype, {
  18923. extractPosition: {
  18924. value: function ( m ) {
  18925. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  18926. return this.copyPosition( m );
  18927. }
  18928. },
  18929. setRotationFromQuaternion: {
  18930. value: function ( q ) {
  18931. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  18932. return this.makeRotationFromQuaternion( q );
  18933. }
  18934. },
  18935. multiplyVector3: {
  18936. value: function ( vector ) {
  18937. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  18938. return vector.applyProjection( this );
  18939. }
  18940. },
  18941. multiplyVector4: {
  18942. value: function ( vector ) {
  18943. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18944. return vector.applyMatrix4( this );
  18945. }
  18946. },
  18947. multiplyVector3Array: {
  18948. value: function ( a ) {
  18949. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18950. return this.applyToVector3Array( a );
  18951. }
  18952. },
  18953. rotateAxis: {
  18954. value: function ( v ) {
  18955. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  18956. v.transformDirection( this );
  18957. }
  18958. },
  18959. crossVector: {
  18960. value: function ( vector ) {
  18961. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18962. return vector.applyMatrix4( this );
  18963. }
  18964. },
  18965. translate: {
  18966. value: function ( v ) {
  18967. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  18968. }
  18969. },
  18970. rotateX: {
  18971. value: function ( angle ) {
  18972. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  18973. }
  18974. },
  18975. rotateY: {
  18976. value: function ( angle ) {
  18977. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  18978. }
  18979. },
  18980. rotateZ: {
  18981. value: function ( angle ) {
  18982. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  18983. }
  18984. },
  18985. rotateByAxis: {
  18986. value: function ( axis, angle ) {
  18987. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  18988. }
  18989. }
  18990. } );
  18991. Object.defineProperties( THREE.Plane.prototype, {
  18992. isIntersectionLine: {
  18993. value: function ( line ) {
  18994. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  18995. return this.intersectsLine( line );
  18996. }
  18997. }
  18998. } );
  18999. Object.defineProperties( THREE.Quaternion.prototype, {
  19000. multiplyVector3: {
  19001. value: function ( vector ) {
  19002. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19003. return vector.applyQuaternion( this );
  19004. }
  19005. }
  19006. } );
  19007. Object.defineProperties( THREE.Ray.prototype, {
  19008. isIntersectionBox: {
  19009. value: function ( box ) {
  19010. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19011. return this.intersectsBox( box );
  19012. }
  19013. },
  19014. isIntersectionPlane: {
  19015. value: function ( plane ) {
  19016. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19017. return this.intersectsPlane( plane );
  19018. }
  19019. },
  19020. isIntersectionSphere: {
  19021. value: function ( sphere ) {
  19022. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19023. return this.intersectsSphere( sphere );
  19024. }
  19025. }
  19026. } );
  19027. Object.defineProperties( THREE.Vector3.prototype, {
  19028. setEulerFromRotationMatrix: {
  19029. value: function () {
  19030. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19031. }
  19032. },
  19033. setEulerFromQuaternion: {
  19034. value: function () {
  19035. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19036. }
  19037. },
  19038. getPositionFromMatrix: {
  19039. value: function ( m ) {
  19040. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19041. return this.setFromMatrixPosition( m );
  19042. }
  19043. },
  19044. getScaleFromMatrix: {
  19045. value: function ( m ) {
  19046. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19047. return this.setFromMatrixScale( m );
  19048. }
  19049. },
  19050. getColumnFromMatrix: {
  19051. value: function ( index, matrix ) {
  19052. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19053. return this.setFromMatrixColumn( index, matrix );
  19054. }
  19055. }
  19056. } );
  19057. //
  19058. Object.defineProperties( THREE.Object3D.prototype, {
  19059. eulerOrder: {
  19060. get: function () {
  19061. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19062. return this.rotation.order;
  19063. },
  19064. set: function ( value ) {
  19065. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19066. this.rotation.order = value;
  19067. }
  19068. },
  19069. getChildByName: {
  19070. value: function ( name ) {
  19071. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19072. return this.getObjectByName( name );
  19073. }
  19074. },
  19075. renderDepth: {
  19076. set: function ( value ) {
  19077. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19078. }
  19079. },
  19080. translate: {
  19081. value: function ( distance, axis ) {
  19082. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19083. return this.translateOnAxis( axis, distance );
  19084. }
  19085. },
  19086. useQuaternion: {
  19087. get: function () {
  19088. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19089. },
  19090. set: function ( value ) {
  19091. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19092. }
  19093. }
  19094. } );
  19095. //
  19096. Object.defineProperties( THREE, {
  19097. PointCloud: {
  19098. value: function ( geometry, material ) {
  19099. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19100. return new THREE.Points( geometry, material );
  19101. }
  19102. },
  19103. ParticleSystem: {
  19104. value: function ( geometry, material ) {
  19105. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19106. return new THREE.Points( geometry, material );
  19107. }
  19108. }
  19109. } );
  19110. //
  19111. Object.defineProperties( THREE.Light.prototype, {
  19112. onlyShadow: {
  19113. set: function ( value ) {
  19114. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19115. }
  19116. },
  19117. shadowCameraFov: {
  19118. set: function ( value ) {
  19119. this.shadow.camera.fov = value;
  19120. }
  19121. },
  19122. shadowCameraLeft: {
  19123. set: function ( value ) {
  19124. this.shadow.camera.left = value;
  19125. }
  19126. },
  19127. shadowCameraRight: {
  19128. set: function ( value ) {
  19129. this.shadow.camera.right = value;
  19130. }
  19131. },
  19132. shadowCameraTop: {
  19133. set: function ( value ) {
  19134. this.shadow.camera.top = value;
  19135. }
  19136. },
  19137. shadowCameraBottom: {
  19138. set: function ( value ) {
  19139. this.shadow.camera.bottom = value;
  19140. }
  19141. },
  19142. shadowCameraNear: {
  19143. set: function ( value ) {
  19144. this.shadow.camera.near = value;
  19145. }
  19146. },
  19147. shadowCameraFar: {
  19148. set: function ( value ) {
  19149. this.shadow.camera.far = value;
  19150. }
  19151. },
  19152. shadowCameraVisible: {
  19153. set: function ( value ) {
  19154. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19155. }
  19156. },
  19157. shadowBias: {
  19158. set: function ( value ) {
  19159. this.shadow.bias = value;
  19160. }
  19161. },
  19162. shadowDarkness: {
  19163. set: function ( value ) {
  19164. this.shadow.darkness = value;
  19165. }
  19166. },
  19167. shadowMapWidth: {
  19168. set: function ( value ) {
  19169. this.shadow.mapSize.width = value;
  19170. }
  19171. },
  19172. shadowMapHeight: {
  19173. set: function ( value ) {
  19174. this.shadow.mapSize.height = value;
  19175. }
  19176. }
  19177. } );
  19178. //
  19179. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19180. length: {
  19181. get: function () {
  19182. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19183. return this.array.length;
  19184. }
  19185. }
  19186. } );
  19187. //
  19188. Object.defineProperties( THREE.Material.prototype, {
  19189. wrapAround: {
  19190. get: function () {
  19191. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19192. },
  19193. set: function ( value ) {
  19194. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19195. }
  19196. },
  19197. wrapRGB: {
  19198. get: function () {
  19199. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19200. return new THREE.Color();
  19201. }
  19202. }
  19203. } );
  19204. Object.defineProperties( THREE, {
  19205. PointCloudMaterial: {
  19206. value: function ( parameters ) {
  19207. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19208. return new THREE.PointsMaterial( parameters );
  19209. }
  19210. },
  19211. ParticleBasicMaterial: {
  19212. value: function ( parameters ) {
  19213. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19214. return new THREE.PointsMaterial( parameters );
  19215. }
  19216. },
  19217. ParticleSystemMaterial:{
  19218. value: function ( parameters ) {
  19219. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19220. return new THREE.PointsMaterial( parameters );
  19221. }
  19222. }
  19223. } );
  19224. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19225. metal: {
  19226. get: function () {
  19227. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19228. return false;
  19229. },
  19230. set: function ( value ) {
  19231. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19232. }
  19233. }
  19234. } );
  19235. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19236. derivatives: {
  19237. get: function () {
  19238. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19239. return this.extensions.derivatives;
  19240. },
  19241. set: function ( value ) {
  19242. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19243. this.extensions.derivatives = value;
  19244. }
  19245. }
  19246. } );
  19247. //
  19248. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19249. supportsFloatTextures: {
  19250. value: function () {
  19251. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19252. return this.extensions.get( 'OES_texture_float' );
  19253. }
  19254. },
  19255. supportsHalfFloatTextures: {
  19256. value: function () {
  19257. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19258. return this.extensions.get( 'OES_texture_half_float' );
  19259. }
  19260. },
  19261. supportsStandardDerivatives: {
  19262. value: function () {
  19263. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19264. return this.extensions.get( 'OES_standard_derivatives' );
  19265. }
  19266. },
  19267. supportsCompressedTextureS3TC: {
  19268. value: function () {
  19269. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19270. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19271. }
  19272. },
  19273. supportsCompressedTexturePVRTC: {
  19274. value: function () {
  19275. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19276. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19277. }
  19278. },
  19279. supportsBlendMinMax: {
  19280. value: function () {
  19281. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19282. return this.extensions.get( 'EXT_blend_minmax' );
  19283. }
  19284. },
  19285. supportsVertexTextures: {
  19286. value: function () {
  19287. return this.capabilities.vertexTextures;
  19288. }
  19289. },
  19290. supportsInstancedArrays: {
  19291. value: function () {
  19292. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19293. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19294. }
  19295. },
  19296. initMaterial: {
  19297. value: function () {
  19298. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19299. }
  19300. },
  19301. addPrePlugin: {
  19302. value: function () {
  19303. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19304. }
  19305. },
  19306. addPostPlugin: {
  19307. value: function () {
  19308. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19309. }
  19310. },
  19311. updateShadowMap: {
  19312. value: function () {
  19313. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19314. }
  19315. },
  19316. shadowMapEnabled: {
  19317. get: function () {
  19318. return this.shadowMap.enabled;
  19319. },
  19320. set: function ( value ) {
  19321. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19322. this.shadowMap.enabled = value;
  19323. }
  19324. },
  19325. shadowMapType: {
  19326. get: function () {
  19327. return this.shadowMap.type;
  19328. },
  19329. set: function ( value ) {
  19330. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19331. this.shadowMap.type = value;
  19332. }
  19333. },
  19334. shadowMapCullFace: {
  19335. get: function () {
  19336. return this.shadowMap.cullFace;
  19337. },
  19338. set: function ( value ) {
  19339. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19340. this.shadowMap.cullFace = value;
  19341. }
  19342. },
  19343. shadowMapDebug: {
  19344. get: function () {
  19345. return this.shadowMap.debug;
  19346. },
  19347. set: function ( value ) {
  19348. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  19349. this.shadowMap.debug = value;
  19350. }
  19351. }
  19352. } );
  19353. //
  19354. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19355. wrapS: {
  19356. get: function () {
  19357. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19358. return this.texture.wrapS;
  19359. },
  19360. set: function ( value ) {
  19361. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19362. this.texture.wrapS = value;
  19363. }
  19364. },
  19365. wrapT: {
  19366. get: function () {
  19367. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19368. return this.texture.wrapT;
  19369. },
  19370. set: function ( value ) {
  19371. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19372. this.texture.wrapT = value;
  19373. }
  19374. },
  19375. magFilter: {
  19376. get: function () {
  19377. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19378. return this.texture.magFilter;
  19379. },
  19380. set: function ( value ) {
  19381. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19382. this.texture.magFilter = value;
  19383. }
  19384. },
  19385. minFilter: {
  19386. get: function () {
  19387. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19388. return this.texture.minFilter;
  19389. },
  19390. set: function ( value ) {
  19391. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19392. this.texture.minFilter = value;
  19393. }
  19394. },
  19395. anisotropy: {
  19396. get: function () {
  19397. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19398. return this.texture.anisotropy;
  19399. },
  19400. set: function ( value ) {
  19401. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19402. this.texture.anisotropy = value;
  19403. }
  19404. },
  19405. offset: {
  19406. get: function () {
  19407. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19408. return this.texture.offset;
  19409. },
  19410. set: function ( value ) {
  19411. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19412. this.texture.offset = value;
  19413. }
  19414. },
  19415. repeat: {
  19416. get: function () {
  19417. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19418. return this.texture.repeat;
  19419. },
  19420. set: function ( value ) {
  19421. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19422. this.texture.repeat = value;
  19423. }
  19424. },
  19425. format: {
  19426. get: function () {
  19427. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19428. return this.texture.format;
  19429. },
  19430. set: function ( value ) {
  19431. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19432. this.texture.format = value;
  19433. }
  19434. },
  19435. type: {
  19436. get: function () {
  19437. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19438. return this.texture.type;
  19439. },
  19440. set: function ( value ) {
  19441. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19442. this.texture.type = value;
  19443. }
  19444. },
  19445. generateMipmaps: {
  19446. get: function () {
  19447. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19448. return this.texture.generateMipmaps;
  19449. },
  19450. set: function ( value ) {
  19451. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19452. this.texture.generateMipmaps = value;
  19453. }
  19454. }
  19455. } );
  19456. //
  19457. THREE.GeometryUtils = {
  19458. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19459. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19460. var matrix;
  19461. if ( geometry2 instanceof THREE.Mesh ) {
  19462. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19463. matrix = geometry2.matrix;
  19464. geometry2 = geometry2.geometry;
  19465. }
  19466. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19467. },
  19468. center: function ( geometry ) {
  19469. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19470. return geometry.center();
  19471. }
  19472. };
  19473. THREE.ImageUtils = {
  19474. crossOrigin: undefined,
  19475. loadTexture: function ( url, mapping, onLoad, onError ) {
  19476. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19477. var loader = new THREE.TextureLoader();
  19478. loader.setCrossOrigin( this.crossOrigin );
  19479. var texture = loader.load( url, onLoad, undefined, onError );
  19480. if ( mapping ) texture.mapping = mapping;
  19481. return texture;
  19482. },
  19483. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19484. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19485. var loader = new THREE.CubeTextureLoader();
  19486. loader.setCrossOrigin( this.crossOrigin );
  19487. var texture = loader.load( urls, onLoad, undefined, onError );
  19488. if ( mapping ) texture.mapping = mapping;
  19489. return texture;
  19490. },
  19491. loadCompressedTexture: function () {
  19492. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  19493. },
  19494. loadCompressedTextureCube: function () {
  19495. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  19496. }
  19497. };
  19498. //
  19499. THREE.Projector = function () {
  19500. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19501. this.projectVector = function ( vector, camera ) {
  19502. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19503. vector.project( camera );
  19504. };
  19505. this.unprojectVector = function ( vector, camera ) {
  19506. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19507. vector.unproject( camera );
  19508. };
  19509. this.pickingRay = function ( vector, camera ) {
  19510. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19511. };
  19512. };
  19513. //
  19514. THREE.CanvasRenderer = function () {
  19515. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19516. this.domElement = document.createElement( 'canvas' );
  19517. this.clear = function () {};
  19518. this.render = function () {};
  19519. this.setClearColor = function () {};
  19520. this.setSize = function () {};
  19521. };
  19522. //
  19523. THREE.TextGeometry = function () {
  19524. console.error( 'THREE.TextGeometry has been moved to /examples/js/geometries/TextGeometry.js' );
  19525. console.error( 'THREE.FontUtils has been moved to /examples/js/utils/FontUtils.js' );
  19526. };
  19527. // File:src/extras/CurveUtils.js
  19528. /**
  19529. * @author zz85 / http://www.lab4games.net/zz85/blog
  19530. */
  19531. THREE.CurveUtils = {
  19532. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19533. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19534. },
  19535. // Puay Bing, thanks for helping with this derivative!
  19536. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19537. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19538. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19539. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19540. 3 * t * t * p3;
  19541. },
  19542. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19543. // To check if my formulas are correct
  19544. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19545. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19546. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19547. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19548. return h00 + h10 + h01 + h11;
  19549. },
  19550. // Catmull-Rom
  19551. interpolate: function( p0, p1, p2, p3, t ) {
  19552. var v0 = ( p2 - p0 ) * 0.5;
  19553. var v1 = ( p3 - p1 ) * 0.5;
  19554. var t2 = t * t;
  19555. var t3 = t * t2;
  19556. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19557. }
  19558. };
  19559. // File:src/extras/SceneUtils.js
  19560. /**
  19561. * @author alteredq / http://alteredqualia.com/
  19562. */
  19563. THREE.SceneUtils = {
  19564. createMultiMaterialObject: function ( geometry, materials ) {
  19565. var group = new THREE.Group();
  19566. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19567. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19568. }
  19569. return group;
  19570. },
  19571. detach: function ( child, parent, scene ) {
  19572. child.applyMatrix( parent.matrixWorld );
  19573. parent.remove( child );
  19574. scene.add( child );
  19575. },
  19576. attach: function ( child, scene, parent ) {
  19577. var matrixWorldInverse = new THREE.Matrix4();
  19578. matrixWorldInverse.getInverse( parent.matrixWorld );
  19579. child.applyMatrix( matrixWorldInverse );
  19580. scene.remove( child );
  19581. parent.add( child );
  19582. }
  19583. };
  19584. // File:src/extras/ShapeUtils.js
  19585. /**
  19586. * @author zz85 / http://www.lab4games.net/zz85/blog
  19587. */
  19588. THREE.ShapeUtils = {
  19589. // calculate area of the contour polygon
  19590. area: function ( contour ) {
  19591. var n = contour.length;
  19592. var a = 0.0;
  19593. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19594. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19595. }
  19596. return a * 0.5;
  19597. },
  19598. triangulate: ( function () {
  19599. /**
  19600. * This code is a quick port of code written in C++ which was submitted to
  19601. * flipcode.com by John W. Ratcliff // July 22, 2000
  19602. * See original code and more information here:
  19603. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19604. *
  19605. * ported to actionscript by Zevan Rosser
  19606. * www.actionsnippet.com
  19607. *
  19608. * ported to javascript by Joshua Koo
  19609. * http://www.lab4games.net/zz85/blog
  19610. *
  19611. */
  19612. function snip( contour, u, v, w, n, verts ) {
  19613. var p;
  19614. var ax, ay, bx, by;
  19615. var cx, cy, px, py;
  19616. ax = contour[ verts[ u ] ].x;
  19617. ay = contour[ verts[ u ] ].y;
  19618. bx = contour[ verts[ v ] ].x;
  19619. by = contour[ verts[ v ] ].y;
  19620. cx = contour[ verts[ w ] ].x;
  19621. cy = contour[ verts[ w ] ].y;
  19622. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19623. var aX, aY, bX, bY, cX, cY;
  19624. var apx, apy, bpx, bpy, cpx, cpy;
  19625. var cCROSSap, bCROSScp, aCROSSbp;
  19626. aX = cx - bx; aY = cy - by;
  19627. bX = ax - cx; bY = ay - cy;
  19628. cX = bx - ax; cY = by - ay;
  19629. for ( p = 0; p < n; p ++ ) {
  19630. px = contour[ verts[ p ] ].x;
  19631. py = contour[ verts[ p ] ].y;
  19632. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19633. ( ( px === bx ) && ( py === by ) ) ||
  19634. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19635. apx = px - ax; apy = py - ay;
  19636. bpx = px - bx; bpy = py - by;
  19637. cpx = px - cx; cpy = py - cy;
  19638. // see if p is inside triangle abc
  19639. aCROSSbp = aX * bpy - aY * bpx;
  19640. cCROSSap = cX * apy - cY * apx;
  19641. bCROSScp = bX * cpy - bY * cpx;
  19642. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19643. }
  19644. return true;
  19645. }
  19646. // takes in an contour array and returns
  19647. return function ( contour, indices ) {
  19648. var n = contour.length;
  19649. if ( n < 3 ) return null;
  19650. var result = [],
  19651. verts = [],
  19652. vertIndices = [];
  19653. /* we want a counter-clockwise polygon in verts */
  19654. var u, v, w;
  19655. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19656. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19657. } else {
  19658. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19659. }
  19660. var nv = n;
  19661. /* remove nv - 2 vertices, creating 1 triangle every time */
  19662. var count = 2 * nv; /* error detection */
  19663. for ( v = nv - 1; nv > 2; ) {
  19664. /* if we loop, it is probably a non-simple polygon */
  19665. if ( ( count -- ) <= 0 ) {
  19666. //** Triangulate: ERROR - probable bad polygon!
  19667. //throw ( "Warning, unable to triangulate polygon!" );
  19668. //return null;
  19669. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  19670. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  19671. if ( indices ) return vertIndices;
  19672. return result;
  19673. }
  19674. /* three consecutive vertices in current polygon, <u,v,w> */
  19675. u = v; if ( nv <= u ) u = 0; /* previous */
  19676. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  19677. w = v + 1; if ( nv <= w ) w = 0; /* next */
  19678. if ( snip( contour, u, v, w, nv, verts ) ) {
  19679. var a, b, c, s, t;
  19680. /* true names of the vertices */
  19681. a = verts[ u ];
  19682. b = verts[ v ];
  19683. c = verts[ w ];
  19684. /* output Triangle */
  19685. result.push( [ contour[ a ],
  19686. contour[ b ],
  19687. contour[ c ] ] );
  19688. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  19689. /* remove v from the remaining polygon */
  19690. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  19691. verts[ s ] = verts[ t ];
  19692. }
  19693. nv --;
  19694. /* reset error detection counter */
  19695. count = 2 * nv;
  19696. }
  19697. }
  19698. if ( indices ) return vertIndices;
  19699. return result;
  19700. }
  19701. } )(),
  19702. triangulateShape: function ( contour, holes ) {
  19703. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  19704. // inOtherPt needs to be collinear to the inSegment
  19705. if ( inSegPt1.x !== inSegPt2.x ) {
  19706. if ( inSegPt1.x < inSegPt2.x ) {
  19707. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  19708. } else {
  19709. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  19710. }
  19711. } else {
  19712. if ( inSegPt1.y < inSegPt2.y ) {
  19713. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  19714. } else {
  19715. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  19716. }
  19717. }
  19718. }
  19719. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  19720. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  19721. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  19722. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  19723. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  19724. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  19725. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  19726. if ( Math.abs( limit ) > Number.EPSILON ) {
  19727. // not parallel
  19728. var perpSeg2;
  19729. if ( limit > 0 ) {
  19730. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  19731. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19732. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  19733. } else {
  19734. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  19735. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19736. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  19737. }
  19738. // i.e. to reduce rounding errors
  19739. // intersection at endpoint of segment#1?
  19740. if ( perpSeg2 === 0 ) {
  19741. if ( ( inExcludeAdjacentSegs ) &&
  19742. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19743. return [ inSeg1Pt1 ];
  19744. }
  19745. if ( perpSeg2 === limit ) {
  19746. if ( ( inExcludeAdjacentSegs ) &&
  19747. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19748. return [ inSeg1Pt2 ];
  19749. }
  19750. // intersection at endpoint of segment#2?
  19751. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  19752. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  19753. // return real intersection point
  19754. var factorSeg1 = perpSeg2 / limit;
  19755. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  19756. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  19757. } else {
  19758. // parallel or collinear
  19759. if ( ( perpSeg1 !== 0 ) ||
  19760. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  19761. // they are collinear or degenerate
  19762. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  19763. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  19764. // both segments are points
  19765. if ( seg1Pt && seg2Pt ) {
  19766. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  19767. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  19768. return [ inSeg1Pt1 ]; // they are the same point
  19769. }
  19770. // segment#1 is a single point
  19771. if ( seg1Pt ) {
  19772. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  19773. return [ inSeg1Pt1 ];
  19774. }
  19775. // segment#2 is a single point
  19776. if ( seg2Pt ) {
  19777. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  19778. return [ inSeg2Pt1 ];
  19779. }
  19780. // they are collinear segments, which might overlap
  19781. var seg1min, seg1max, seg1minVal, seg1maxVal;
  19782. var seg2min, seg2max, seg2minVal, seg2maxVal;
  19783. if ( seg1dx !== 0 ) {
  19784. // the segments are NOT on a vertical line
  19785. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  19786. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  19787. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  19788. } else {
  19789. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  19790. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  19791. }
  19792. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  19793. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  19794. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  19795. } else {
  19796. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  19797. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  19798. }
  19799. } else {
  19800. // the segments are on a vertical line
  19801. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  19802. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  19803. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  19804. } else {
  19805. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  19806. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  19807. }
  19808. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  19809. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  19810. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  19811. } else {
  19812. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  19813. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  19814. }
  19815. }
  19816. if ( seg1minVal <= seg2minVal ) {
  19817. if ( seg1maxVal < seg2minVal ) return [];
  19818. if ( seg1maxVal === seg2minVal ) {
  19819. if ( inExcludeAdjacentSegs ) return [];
  19820. return [ seg2min ];
  19821. }
  19822. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  19823. return [ seg2min, seg2max ];
  19824. } else {
  19825. if ( seg1minVal > seg2maxVal ) return [];
  19826. if ( seg1minVal === seg2maxVal ) {
  19827. if ( inExcludeAdjacentSegs ) return [];
  19828. return [ seg1min ];
  19829. }
  19830. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  19831. return [ seg1min, seg2max ];
  19832. }
  19833. }
  19834. }
  19835. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  19836. // The order of legs is important
  19837. // translation of all points, so that Vertex is at (0,0)
  19838. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  19839. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  19840. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  19841. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  19842. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  19843. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  19844. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  19845. // angle != 180 deg.
  19846. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  19847. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  19848. if ( from2toAngle > 0 ) {
  19849. // main angle < 180 deg.
  19850. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  19851. } else {
  19852. // main angle > 180 deg.
  19853. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  19854. }
  19855. } else {
  19856. // angle == 180 deg.
  19857. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  19858. return ( from2otherAngle > 0 );
  19859. }
  19860. }
  19861. function removeHoles( contour, holes ) {
  19862. var shape = contour.concat(); // work on this shape
  19863. var hole;
  19864. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  19865. // Check if hole point lies within angle around shape point
  19866. var lastShapeIdx = shape.length - 1;
  19867. var prevShapeIdx = inShapeIdx - 1;
  19868. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  19869. var nextShapeIdx = inShapeIdx + 1;
  19870. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  19871. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  19872. if ( ! insideAngle ) {
  19873. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  19874. return false;
  19875. }
  19876. // Check if shape point lies within angle around hole point
  19877. var lastHoleIdx = hole.length - 1;
  19878. var prevHoleIdx = inHoleIdx - 1;
  19879. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  19880. var nextHoleIdx = inHoleIdx + 1;
  19881. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  19882. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  19883. if ( ! insideAngle ) {
  19884. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  19885. return false;
  19886. }
  19887. return true;
  19888. }
  19889. function intersectsShapeEdge( inShapePt, inHolePt ) {
  19890. // checks for intersections with shape edges
  19891. var sIdx, nextIdx, intersection;
  19892. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  19893. nextIdx = sIdx + 1; nextIdx %= shape.length;
  19894. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  19895. if ( intersection.length > 0 ) return true;
  19896. }
  19897. return false;
  19898. }
  19899. var indepHoles = [];
  19900. function intersectsHoleEdge( inShapePt, inHolePt ) {
  19901. // checks for intersections with hole edges
  19902. var ihIdx, chkHole,
  19903. hIdx, nextIdx, intersection;
  19904. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  19905. chkHole = holes[ indepHoles[ ihIdx ]];
  19906. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  19907. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  19908. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  19909. if ( intersection.length > 0 ) return true;
  19910. }
  19911. }
  19912. return false;
  19913. }
  19914. var holeIndex, shapeIndex,
  19915. shapePt, holePt,
  19916. holeIdx, cutKey, failedCuts = [],
  19917. tmpShape1, tmpShape2,
  19918. tmpHole1, tmpHole2;
  19919. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19920. indepHoles.push( h );
  19921. }
  19922. var minShapeIndex = 0;
  19923. var counter = indepHoles.length * 2;
  19924. while ( indepHoles.length > 0 ) {
  19925. counter --;
  19926. if ( counter < 0 ) {
  19927. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  19928. break;
  19929. }
  19930. // search for shape-vertex and hole-vertex,
  19931. // which can be connected without intersections
  19932. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  19933. shapePt = shape[ shapeIndex ];
  19934. holeIndex = - 1;
  19935. // search for hole which can be reached without intersections
  19936. for ( var h = 0; h < indepHoles.length; h ++ ) {
  19937. holeIdx = indepHoles[ h ];
  19938. // prevent multiple checks
  19939. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  19940. if ( failedCuts[ cutKey ] !== undefined ) continue;
  19941. hole = holes[ holeIdx ];
  19942. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  19943. holePt = hole[ h2 ];
  19944. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  19945. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  19946. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  19947. holeIndex = h2;
  19948. indepHoles.splice( h, 1 );
  19949. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  19950. tmpShape2 = shape.slice( shapeIndex );
  19951. tmpHole1 = hole.slice( holeIndex );
  19952. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  19953. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  19954. minShapeIndex = shapeIndex;
  19955. // Debug only, to show the selected cuts
  19956. // glob_CutLines.push( [ shapePt, holePt ] );
  19957. break;
  19958. }
  19959. if ( holeIndex >= 0 ) break; // hole-vertex found
  19960. failedCuts[ cutKey ] = true; // remember failure
  19961. }
  19962. if ( holeIndex >= 0 ) break; // hole-vertex found
  19963. }
  19964. }
  19965. return shape; /* shape with no holes */
  19966. }
  19967. var i, il, f, face,
  19968. key, index,
  19969. allPointsMap = {};
  19970. // To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
  19971. var allpoints = contour.concat();
  19972. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19973. Array.prototype.push.apply( allpoints, holes[ h ] );
  19974. }
  19975. //console.log( "allpoints",allpoints, allpoints.length );
  19976. // prepare all points map
  19977. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  19978. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  19979. if ( allPointsMap[ key ] !== undefined ) {
  19980. console.warn( "THREE.Shape: Duplicate point", key );
  19981. }
  19982. allPointsMap[ key ] = i;
  19983. }
  19984. // remove holes by cutting paths to holes and adding them to the shape
  19985. var shapeWithoutHoles = removeHoles( contour, holes );
  19986. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  19987. //console.log( "triangles",triangles, triangles.length );
  19988. // check all face vertices against all points map
  19989. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  19990. face = triangles[ i ];
  19991. for ( f = 0; f < 3; f ++ ) {
  19992. key = face[ f ].x + ":" + face[ f ].y;
  19993. index = allPointsMap[ key ];
  19994. if ( index !== undefined ) {
  19995. face[ f ] = index;
  19996. }
  19997. }
  19998. }
  19999. return triangles.concat();
  20000. },
  20001. isClockWise: function ( pts ) {
  20002. return THREE.ShapeUtils.area( pts ) < 0;
  20003. },
  20004. // Bezier Curves formulas obtained from
  20005. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20006. // Quad Bezier Functions
  20007. b2: ( function () {
  20008. function b2p0( t, p ) {
  20009. var k = 1 - t;
  20010. return k * k * p;
  20011. }
  20012. function b2p1( t, p ) {
  20013. return 2 * ( 1 - t ) * t * p;
  20014. }
  20015. function b2p2( t, p ) {
  20016. return t * t * p;
  20017. }
  20018. return function ( t, p0, p1, p2 ) {
  20019. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20020. };
  20021. } )(),
  20022. // Cubic Bezier Functions
  20023. b3: ( function () {
  20024. function b3p0( t, p ) {
  20025. var k = 1 - t;
  20026. return k * k * k * p;
  20027. }
  20028. function b3p1( t, p ) {
  20029. var k = 1 - t;
  20030. return 3 * k * k * t * p;
  20031. }
  20032. function b3p2( t, p ) {
  20033. var k = 1 - t;
  20034. return 3 * k * t * t * p;
  20035. }
  20036. function b3p3( t, p ) {
  20037. return t * t * t * p;
  20038. }
  20039. return function ( t, p0, p1, p2, p3 ) {
  20040. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20041. };
  20042. } )()
  20043. };
  20044. // File:src/extras/core/Curve.js
  20045. /**
  20046. * @author zz85 / http://www.lab4games.net/zz85/blog
  20047. * Extensible curve object
  20048. *
  20049. * Some common of Curve methods
  20050. * .getPoint(t), getTangent(t)
  20051. * .getPointAt(u), getTagentAt(u)
  20052. * .getPoints(), .getSpacedPoints()
  20053. * .getLength()
  20054. * .updateArcLengths()
  20055. *
  20056. * This following classes subclasses THREE.Curve:
  20057. *
  20058. * -- 2d classes --
  20059. * THREE.LineCurve
  20060. * THREE.QuadraticBezierCurve
  20061. * THREE.CubicBezierCurve
  20062. * THREE.SplineCurve
  20063. * THREE.ArcCurve
  20064. * THREE.EllipseCurve
  20065. *
  20066. * -- 3d classes --
  20067. * THREE.LineCurve3
  20068. * THREE.QuadraticBezierCurve3
  20069. * THREE.CubicBezierCurve3
  20070. * THREE.SplineCurve3
  20071. * THREE.ClosedSplineCurve3
  20072. *
  20073. * A series of curves can be represented as a THREE.CurvePath
  20074. *
  20075. **/
  20076. /**************************************************************
  20077. * Abstract Curve base class
  20078. **************************************************************/
  20079. THREE.Curve = function () {
  20080. };
  20081. THREE.Curve.prototype = {
  20082. constructor: THREE.Curve,
  20083. // Virtual base class method to overwrite and implement in subclasses
  20084. // - t [0 .. 1]
  20085. getPoint: function ( t ) {
  20086. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20087. return null;
  20088. },
  20089. // Get point at relative position in curve according to arc length
  20090. // - u [0 .. 1]
  20091. getPointAt: function ( u ) {
  20092. var t = this.getUtoTmapping( u );
  20093. return this.getPoint( t );
  20094. },
  20095. // Get sequence of points using getPoint( t )
  20096. getPoints: function ( divisions ) {
  20097. if ( ! divisions ) divisions = 5;
  20098. var d, pts = [];
  20099. for ( d = 0; d <= divisions; d ++ ) {
  20100. pts.push( this.getPoint( d / divisions ) );
  20101. }
  20102. return pts;
  20103. },
  20104. // Get sequence of points using getPointAt( u )
  20105. getSpacedPoints: function ( divisions ) {
  20106. if ( ! divisions ) divisions = 5;
  20107. var d, pts = [];
  20108. for ( d = 0; d <= divisions; d ++ ) {
  20109. pts.push( this.getPointAt( d / divisions ) );
  20110. }
  20111. return pts;
  20112. },
  20113. // Get total curve arc length
  20114. getLength: function () {
  20115. var lengths = this.getLengths();
  20116. return lengths[ lengths.length - 1 ];
  20117. },
  20118. // Get list of cumulative segment lengths
  20119. getLengths: function ( divisions ) {
  20120. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20121. if ( this.cacheArcLengths
  20122. && ( this.cacheArcLengths.length === divisions + 1 )
  20123. && ! this.needsUpdate ) {
  20124. //console.log( "cached", this.cacheArcLengths );
  20125. return this.cacheArcLengths;
  20126. }
  20127. this.needsUpdate = false;
  20128. var cache = [];
  20129. var current, last = this.getPoint( 0 );
  20130. var p, sum = 0;
  20131. cache.push( 0 );
  20132. for ( p = 1; p <= divisions; p ++ ) {
  20133. current = this.getPoint ( p / divisions );
  20134. sum += current.distanceTo( last );
  20135. cache.push( sum );
  20136. last = current;
  20137. }
  20138. this.cacheArcLengths = cache;
  20139. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20140. },
  20141. updateArcLengths: function() {
  20142. this.needsUpdate = true;
  20143. this.getLengths();
  20144. },
  20145. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20146. getUtoTmapping: function ( u, distance ) {
  20147. var arcLengths = this.getLengths();
  20148. var i = 0, il = arcLengths.length;
  20149. var targetArcLength; // The targeted u distance value to get
  20150. if ( distance ) {
  20151. targetArcLength = distance;
  20152. } else {
  20153. targetArcLength = u * arcLengths[ il - 1 ];
  20154. }
  20155. //var time = Date.now();
  20156. // binary search for the index with largest value smaller than target u distance
  20157. var low = 0, high = il - 1, comparison;
  20158. while ( low <= high ) {
  20159. 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
  20160. comparison = arcLengths[ i ] - targetArcLength;
  20161. if ( comparison < 0 ) {
  20162. low = i + 1;
  20163. } else if ( comparison > 0 ) {
  20164. high = i - 1;
  20165. } else {
  20166. high = i;
  20167. break;
  20168. // DONE
  20169. }
  20170. }
  20171. i = high;
  20172. //console.log('b' , i, low, high, Date.now()- time);
  20173. if ( arcLengths[ i ] === targetArcLength ) {
  20174. var t = i / ( il - 1 );
  20175. return t;
  20176. }
  20177. // we could get finer grain at lengths, or use simple interpolation between two points
  20178. var lengthBefore = arcLengths[ i ];
  20179. var lengthAfter = arcLengths[ i + 1 ];
  20180. var segmentLength = lengthAfter - lengthBefore;
  20181. // determine where we are between the 'before' and 'after' points
  20182. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20183. // add that fractional amount to t
  20184. var t = ( i + segmentFraction ) / ( il - 1 );
  20185. return t;
  20186. },
  20187. // Returns a unit vector tangent at t
  20188. // In case any sub curve does not implement its tangent derivation,
  20189. // 2 points a small delta apart will be used to find its gradient
  20190. // which seems to give a reasonable approximation
  20191. getTangent: function( t ) {
  20192. var delta = 0.0001;
  20193. var t1 = t - delta;
  20194. var t2 = t + delta;
  20195. // Capping in case of danger
  20196. if ( t1 < 0 ) t1 = 0;
  20197. if ( t2 > 1 ) t2 = 1;
  20198. var pt1 = this.getPoint( t1 );
  20199. var pt2 = this.getPoint( t2 );
  20200. var vec = pt2.clone().sub( pt1 );
  20201. return vec.normalize();
  20202. },
  20203. getTangentAt: function ( u ) {
  20204. var t = this.getUtoTmapping( u );
  20205. return this.getTangent( t );
  20206. }
  20207. }
  20208. THREE.Curve.Utils = THREE.CurveUtils; // backwards compatibility
  20209. // TODO: Transformation for Curves?
  20210. /**************************************************************
  20211. * 3D Curves
  20212. **************************************************************/
  20213. // A Factory method for creating new curve subclasses
  20214. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20215. constructor.prototype = Object.create( THREE.Curve.prototype );
  20216. constructor.prototype.constructor = constructor;
  20217. constructor.prototype.getPoint = getPointFunc;
  20218. return constructor;
  20219. };
  20220. // File:src/extras/core/CurvePath.js
  20221. /**
  20222. * @author zz85 / http://www.lab4games.net/zz85/blog
  20223. *
  20224. **/
  20225. /**************************************************************
  20226. * Curved Path - a curve path is simply a array of connected
  20227. * curves, but retains the api of a curve
  20228. **************************************************************/
  20229. THREE.CurvePath = function () {
  20230. this.curves = [];
  20231. this.autoClose = false; // Automatically closes the path
  20232. };
  20233. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20234. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20235. THREE.CurvePath.prototype.add = function ( curve ) {
  20236. this.curves.push( curve );
  20237. };
  20238. /*
  20239. THREE.CurvePath.prototype.checkConnection = function() {
  20240. // TODO
  20241. // If the ending of curve is not connected to the starting
  20242. // or the next curve, then, this is not a real path
  20243. };
  20244. */
  20245. THREE.CurvePath.prototype.closePath = function() {
  20246. // TODO Test
  20247. // and verify for vector3 (needs to implement equals)
  20248. // Add a line curve if start and end of lines are not connected
  20249. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20250. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20251. if ( ! startPoint.equals( endPoint ) ) {
  20252. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20253. }
  20254. };
  20255. // To get accurate point with reference to
  20256. // entire path distance at time t,
  20257. // following has to be done:
  20258. // 1. Length of each sub path have to be known
  20259. // 2. Locate and identify type of curve
  20260. // 3. Get t for the curve
  20261. // 4. Return curve.getPointAt(t')
  20262. THREE.CurvePath.prototype.getPoint = function( t ) {
  20263. var d = t * this.getLength();
  20264. var curveLengths = this.getCurveLengths();
  20265. var i = 0;
  20266. // To think about boundaries points.
  20267. while ( i < curveLengths.length ) {
  20268. if ( curveLengths[ i ] >= d ) {
  20269. var diff = curveLengths[ i ] - d;
  20270. var curve = this.curves[ i ];
  20271. var u = 1 - diff / curve.getLength();
  20272. return curve.getPointAt( u );
  20273. }
  20274. i ++;
  20275. }
  20276. return null;
  20277. // loop where sum != 0, sum > d , sum+1 <d
  20278. };
  20279. /*
  20280. THREE.CurvePath.prototype.getTangent = function( t ) {
  20281. };
  20282. */
  20283. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20284. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20285. // getPoint() depends on getLength
  20286. THREE.CurvePath.prototype.getLength = function() {
  20287. var lens = this.getCurveLengths();
  20288. return lens[ lens.length - 1 ];
  20289. };
  20290. // Compute lengths and cache them
  20291. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20292. THREE.CurvePath.prototype.getCurveLengths = function() {
  20293. // We use cache values if curves and cache array are same length
  20294. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20295. return this.cacheLengths;
  20296. }
  20297. // Get length of sub-curve
  20298. // Push sums into cached array
  20299. var lengths = [], sums = 0;
  20300. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20301. sums += this.curves[ i ].getLength();
  20302. lengths.push( sums );
  20303. }
  20304. this.cacheLengths = lengths;
  20305. return lengths;
  20306. };
  20307. /**************************************************************
  20308. * Create Geometries Helpers
  20309. **************************************************************/
  20310. /// Generate geometry from path points (for Line or Points objects)
  20311. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20312. var pts = this.getPoints( divisions, true );
  20313. return this.createGeometry( pts );
  20314. };
  20315. // Generate geometry from equidistant sampling along the path
  20316. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20317. var pts = this.getSpacedPoints( divisions, true );
  20318. return this.createGeometry( pts );
  20319. };
  20320. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20321. var geometry = new THREE.Geometry();
  20322. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20323. var point = points[ i ];
  20324. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20325. }
  20326. return geometry;
  20327. };
  20328. // File:src/extras/core/Path.js
  20329. /**
  20330. * @author zz85 / http://www.lab4games.net/zz85/blog
  20331. * Creates free form 2d path using series of points, lines or curves.
  20332. *
  20333. **/
  20334. THREE.Path = function ( points ) {
  20335. THREE.CurvePath.call( this );
  20336. this.actions = [];
  20337. if ( points ) {
  20338. this.fromPoints( points );
  20339. }
  20340. };
  20341. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20342. THREE.Path.prototype.constructor = THREE.Path;
  20343. // TODO Clean up PATH API
  20344. // Create path using straight lines to connect all points
  20345. // - vectors: array of Vector2
  20346. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20347. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20348. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20349. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20350. }
  20351. };
  20352. // startPath() endPath()?
  20353. THREE.Path.prototype.moveTo = function ( x, y ) {
  20354. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20355. };
  20356. THREE.Path.prototype.lineTo = function ( x, y ) {
  20357. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20358. var x0 = lastargs[ lastargs.length - 2 ];
  20359. var y0 = lastargs[ lastargs.length - 1 ];
  20360. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20361. this.curves.push( curve );
  20362. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20363. };
  20364. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20365. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20366. var x0 = lastargs[ lastargs.length - 2 ];
  20367. var y0 = lastargs[ lastargs.length - 1 ];
  20368. var curve = new THREE.QuadraticBezierCurve(
  20369. new THREE.Vector2( x0, y0 ),
  20370. new THREE.Vector2( aCPx, aCPy ),
  20371. new THREE.Vector2( aX, aY )
  20372. );
  20373. this.curves.push( curve );
  20374. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20375. };
  20376. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20377. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20378. var x0 = lastargs[ lastargs.length - 2 ];
  20379. var y0 = lastargs[ lastargs.length - 1 ];
  20380. var curve = new THREE.CubicBezierCurve(
  20381. new THREE.Vector2( x0, y0 ),
  20382. new THREE.Vector2( aCP1x, aCP1y ),
  20383. new THREE.Vector2( aCP2x, aCP2y ),
  20384. new THREE.Vector2( aX, aY )
  20385. );
  20386. this.curves.push( curve );
  20387. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20388. };
  20389. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20390. var args = Array.prototype.slice.call( arguments );
  20391. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20392. var x0 = lastargs[ lastargs.length - 2 ];
  20393. var y0 = lastargs[ lastargs.length - 1 ];
  20394. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20395. Array.prototype.push.apply( npts, pts );
  20396. var curve = new THREE.SplineCurve( npts );
  20397. this.curves.push( curve );
  20398. this.actions.push( { action: 'splineThru', args: args } );
  20399. };
  20400. // FUTURE: Change the API or follow canvas API?
  20401. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20402. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20403. var x0 = lastargs[ lastargs.length - 2 ];
  20404. var y0 = lastargs[ lastargs.length - 1 ];
  20405. this.absarc( aX + x0, aY + y0, aRadius,
  20406. aStartAngle, aEndAngle, aClockwise );
  20407. };
  20408. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20409. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20410. };
  20411. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20412. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20413. var x0 = lastargs[ lastargs.length - 2 ];
  20414. var y0 = lastargs[ lastargs.length - 1 ];
  20415. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20416. };
  20417. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20418. var args = [
  20419. aX, aY,
  20420. xRadius, yRadius,
  20421. aStartAngle, aEndAngle,
  20422. aClockwise,
  20423. aRotation || 0 // aRotation is optional.
  20424. ];
  20425. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20426. this.curves.push( curve );
  20427. var lastPoint = curve.getPoint( 1 );
  20428. args.push( lastPoint.x );
  20429. args.push( lastPoint.y );
  20430. this.actions.push( { action: 'ellipse', args: args } );
  20431. };
  20432. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  20433. if ( ! divisions ) divisions = 40;
  20434. var points = [];
  20435. for ( var i = 0; i < divisions; i ++ ) {
  20436. points.push( this.getPoint( i / divisions ) );
  20437. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20438. }
  20439. // if ( closedPath ) {
  20440. //
  20441. // points.push( points[ 0 ] );
  20442. //
  20443. // }
  20444. return points;
  20445. };
  20446. /* Return an array of vectors based on contour of the path */
  20447. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  20448. divisions = divisions || 12;
  20449. var b2 = THREE.ShapeUtils.b2;
  20450. var b3 = THREE.ShapeUtils.b3;
  20451. var points = [];
  20452. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20453. laste, tx, ty;
  20454. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20455. var item = this.actions[ i ];
  20456. var action = item.action;
  20457. var args = item.args;
  20458. switch ( action ) {
  20459. case 'moveTo':
  20460. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20461. break;
  20462. case 'lineTo':
  20463. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20464. break;
  20465. case 'quadraticCurveTo':
  20466. cpx = args[ 2 ];
  20467. cpy = args[ 3 ];
  20468. cpx1 = args[ 0 ];
  20469. cpy1 = args[ 1 ];
  20470. if ( points.length > 0 ) {
  20471. laste = points[ points.length - 1 ];
  20472. cpx0 = laste.x;
  20473. cpy0 = laste.y;
  20474. } else {
  20475. laste = this.actions[ i - 1 ].args;
  20476. cpx0 = laste[ laste.length - 2 ];
  20477. cpy0 = laste[ laste.length - 1 ];
  20478. }
  20479. for ( var j = 1; j <= divisions; j ++ ) {
  20480. var t = j / divisions;
  20481. tx = b2( t, cpx0, cpx1, cpx );
  20482. ty = b2( t, cpy0, cpy1, cpy );
  20483. points.push( new THREE.Vector2( tx, ty ) );
  20484. }
  20485. break;
  20486. case 'bezierCurveTo':
  20487. cpx = args[ 4 ];
  20488. cpy = args[ 5 ];
  20489. cpx1 = args[ 0 ];
  20490. cpy1 = args[ 1 ];
  20491. cpx2 = args[ 2 ];
  20492. cpy2 = args[ 3 ];
  20493. if ( points.length > 0 ) {
  20494. laste = points[ points.length - 1 ];
  20495. cpx0 = laste.x;
  20496. cpy0 = laste.y;
  20497. } else {
  20498. laste = this.actions[ i - 1 ].args;
  20499. cpx0 = laste[ laste.length - 2 ];
  20500. cpy0 = laste[ laste.length - 1 ];
  20501. }
  20502. for ( var j = 1; j <= divisions; j ++ ) {
  20503. var t = j / divisions;
  20504. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20505. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20506. points.push( new THREE.Vector2( tx, ty ) );
  20507. }
  20508. break;
  20509. case 'splineThru':
  20510. laste = this.actions[ i - 1 ].args;
  20511. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20512. var spts = [ last ];
  20513. var n = divisions * args[ 0 ].length;
  20514. spts = spts.concat( args[ 0 ] );
  20515. var spline = new THREE.SplineCurve( spts );
  20516. for ( var j = 1; j <= n; j ++ ) {
  20517. points.push( spline.getPointAt( j / n ) );
  20518. }
  20519. break;
  20520. case 'arc':
  20521. var aX = args[ 0 ], aY = args[ 1 ],
  20522. aRadius = args[ 2 ],
  20523. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20524. aClockwise = !! args[ 5 ];
  20525. var deltaAngle = aEndAngle - aStartAngle;
  20526. var angle;
  20527. var tdivisions = divisions * 2;
  20528. for ( var j = 1; j <= tdivisions; j ++ ) {
  20529. var t = j / tdivisions;
  20530. if ( ! aClockwise ) {
  20531. t = 1 - t;
  20532. }
  20533. angle = aStartAngle + t * deltaAngle;
  20534. tx = aX + aRadius * Math.cos( angle );
  20535. ty = aY + aRadius * Math.sin( angle );
  20536. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20537. points.push( new THREE.Vector2( tx, ty ) );
  20538. }
  20539. //console.log(points);
  20540. break;
  20541. case 'ellipse':
  20542. var aX = args[ 0 ], aY = args[ 1 ],
  20543. xRadius = args[ 2 ],
  20544. yRadius = args[ 3 ],
  20545. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20546. aClockwise = !! args[ 6 ],
  20547. aRotation = args[ 7 ];
  20548. var deltaAngle = aEndAngle - aStartAngle;
  20549. var angle;
  20550. var tdivisions = divisions * 2;
  20551. var cos, sin;
  20552. if ( aRotation !== 0 ) {
  20553. cos = Math.cos( aRotation );
  20554. sin = Math.sin( aRotation );
  20555. }
  20556. for ( var j = 1; j <= tdivisions; j ++ ) {
  20557. var t = j / tdivisions;
  20558. if ( ! aClockwise ) {
  20559. t = 1 - t;
  20560. }
  20561. angle = aStartAngle + t * deltaAngle;
  20562. tx = aX + xRadius * Math.cos( angle );
  20563. ty = aY + yRadius * Math.sin( angle );
  20564. if ( aRotation !== 0 ) {
  20565. var x = tx, y = ty;
  20566. // Rotate the point about the center of the ellipse.
  20567. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  20568. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  20569. }
  20570. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20571. points.push( new THREE.Vector2( tx, ty ) );
  20572. }
  20573. //console.log(points);
  20574. break;
  20575. } // end switch
  20576. }
  20577. // Normalize to remove the closing point by default.
  20578. var lastPoint = points[ points.length - 1 ];
  20579. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  20580. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  20581. points.splice( points.length - 1, 1 );
  20582. if ( closedPath ) {
  20583. points.push( points[ 0 ] );
  20584. }
  20585. return points;
  20586. };
  20587. //
  20588. // Breaks path into shapes
  20589. //
  20590. // Assumptions (if parameter isCCW==true the opposite holds):
  20591. // - solid shapes are defined clockwise (CW)
  20592. // - holes are defined counterclockwise (CCW)
  20593. //
  20594. // If parameter noHoles==true:
  20595. // - all subPaths are regarded as solid shapes
  20596. // - definition order CW/CCW has no relevance
  20597. //
  20598. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  20599. function extractSubpaths( inActions ) {
  20600. var subPaths = [], lastPath = new THREE.Path();
  20601. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  20602. var item = inActions[ i ];
  20603. var args = item.args;
  20604. var action = item.action;
  20605. if ( action === 'moveTo' ) {
  20606. if ( lastPath.actions.length !== 0 ) {
  20607. subPaths.push( lastPath );
  20608. lastPath = new THREE.Path();
  20609. }
  20610. }
  20611. lastPath[ action ].apply( lastPath, args );
  20612. }
  20613. if ( lastPath.actions.length !== 0 ) {
  20614. subPaths.push( lastPath );
  20615. }
  20616. // console.log(subPaths);
  20617. return subPaths;
  20618. }
  20619. function toShapesNoHoles( inSubpaths ) {
  20620. var shapes = [];
  20621. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  20622. var tmpPath = inSubpaths[ i ];
  20623. var tmpShape = new THREE.Shape();
  20624. tmpShape.actions = tmpPath.actions;
  20625. tmpShape.curves = tmpPath.curves;
  20626. shapes.push( tmpShape );
  20627. }
  20628. //console.log("shape", shapes);
  20629. return shapes;
  20630. }
  20631. function isPointInsidePolygon( inPt, inPolygon ) {
  20632. var polyLen = inPolygon.length;
  20633. // inPt on polygon contour => immediate success or
  20634. // toggling of inside/outside at every single! intersection point of an edge
  20635. // with the horizontal line through inPt, left of inPt
  20636. // not counting lowerY endpoints of edges and whole edges on that line
  20637. var inside = false;
  20638. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  20639. var edgeLowPt = inPolygon[ p ];
  20640. var edgeHighPt = inPolygon[ q ];
  20641. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  20642. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  20643. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  20644. // not parallel
  20645. if ( edgeDy < 0 ) {
  20646. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  20647. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  20648. }
  20649. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  20650. if ( inPt.y === edgeLowPt.y ) {
  20651. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  20652. // continue; // no intersection or edgeLowPt => doesn't count !!!
  20653. } else {
  20654. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  20655. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  20656. if ( perpEdge < 0 ) continue;
  20657. inside = ! inside; // true intersection left of inPt
  20658. }
  20659. } else {
  20660. // parallel or collinear
  20661. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  20662. // edge lies on the same horizontal line as inPt
  20663. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  20664. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  20665. // continue;
  20666. }
  20667. }
  20668. return inside;
  20669. }
  20670. var isClockWise = THREE.ShapeUtils.isClockWise;
  20671. var subPaths = extractSubpaths( this.actions );
  20672. if ( subPaths.length === 0 ) return [];
  20673. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  20674. var solid, tmpPath, tmpShape, shapes = [];
  20675. if ( subPaths.length === 1 ) {
  20676. tmpPath = subPaths[ 0 ];
  20677. tmpShape = new THREE.Shape();
  20678. tmpShape.actions = tmpPath.actions;
  20679. tmpShape.curves = tmpPath.curves;
  20680. shapes.push( tmpShape );
  20681. return shapes;
  20682. }
  20683. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  20684. holesFirst = isCCW ? ! holesFirst : holesFirst;
  20685. // console.log("Holes first", holesFirst);
  20686. var betterShapeHoles = [];
  20687. var newShapes = [];
  20688. var newShapeHoles = [];
  20689. var mainIdx = 0;
  20690. var tmpPoints;
  20691. newShapes[ mainIdx ] = undefined;
  20692. newShapeHoles[ mainIdx ] = [];
  20693. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  20694. tmpPath = subPaths[ i ];
  20695. tmpPoints = tmpPath.getPoints();
  20696. solid = isClockWise( tmpPoints );
  20697. solid = isCCW ? ! solid : solid;
  20698. if ( solid ) {
  20699. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  20700. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  20701. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  20702. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  20703. if ( holesFirst ) mainIdx ++;
  20704. newShapeHoles[ mainIdx ] = [];
  20705. //console.log('cw', i);
  20706. } else {
  20707. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  20708. //console.log('ccw', i);
  20709. }
  20710. }
  20711. // only Holes? -> probably all Shapes with wrong orientation
  20712. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  20713. if ( newShapes.length > 1 ) {
  20714. var ambiguous = false;
  20715. var toChange = [];
  20716. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20717. betterShapeHoles[ sIdx ] = [];
  20718. }
  20719. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20720. var sho = newShapeHoles[ sIdx ];
  20721. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  20722. var ho = sho[ hIdx ];
  20723. var hole_unassigned = true;
  20724. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  20725. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  20726. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  20727. if ( hole_unassigned ) {
  20728. hole_unassigned = false;
  20729. betterShapeHoles[ s2Idx ].push( ho );
  20730. } else {
  20731. ambiguous = true;
  20732. }
  20733. }
  20734. }
  20735. if ( hole_unassigned ) {
  20736. betterShapeHoles[ sIdx ].push( ho );
  20737. }
  20738. }
  20739. }
  20740. // console.log("ambiguous: ", ambiguous);
  20741. if ( toChange.length > 0 ) {
  20742. // console.log("to change: ", toChange);
  20743. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  20744. }
  20745. }
  20746. var tmpHoles;
  20747. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  20748. tmpShape = newShapes[ i ].s;
  20749. shapes.push( tmpShape );
  20750. tmpHoles = newShapeHoles[ i ];
  20751. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  20752. tmpShape.holes.push( tmpHoles[ j ].h );
  20753. }
  20754. }
  20755. //console.log("shape", shapes);
  20756. return shapes;
  20757. };
  20758. // File:src/extras/core/Shape.js
  20759. /**
  20760. * @author zz85 / http://www.lab4games.net/zz85/blog
  20761. * Defines a 2d shape plane using paths.
  20762. **/
  20763. // STEP 1 Create a path.
  20764. // STEP 2 Turn path into shape.
  20765. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20766. // STEP 3a - Extract points from each shape, turn to vertices
  20767. // STEP 3b - Triangulate each shape, add faces.
  20768. THREE.Shape = function () {
  20769. THREE.Path.apply( this, arguments );
  20770. this.holes = [];
  20771. };
  20772. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  20773. THREE.Shape.prototype.constructor = THREE.Shape;
  20774. // Convenience method to return ExtrudeGeometry
  20775. THREE.Shape.prototype.extrude = function ( options ) {
  20776. return new THREE.ExtrudeGeometry( this, options );
  20777. };
  20778. // Convenience method to return ShapeGeometry
  20779. THREE.Shape.prototype.makeGeometry = function ( options ) {
  20780. return new THREE.ShapeGeometry( this, options );
  20781. };
  20782. // Get points of holes
  20783. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  20784. var holesPts = [];
  20785. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20786. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20787. }
  20788. return holesPts;
  20789. };
  20790. // Get points of shape and holes (keypoints based on segments parameter)
  20791. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  20792. return {
  20793. shape: this.getPoints( divisions ),
  20794. holes: this.getPointsHoles( divisions )
  20795. };
  20796. };
  20797. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  20798. return this.extractAllPoints( divisions );
  20799. };
  20800. THREE.Shape.Utils = THREE.ShapeUtils; // backwards compatibility
  20801. // File:src/extras/curves/LineCurve.js
  20802. /**************************************************************
  20803. * Line
  20804. **************************************************************/
  20805. THREE.LineCurve = function ( v1, v2 ) {
  20806. this.v1 = v1;
  20807. this.v2 = v2;
  20808. };
  20809. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  20810. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  20811. THREE.LineCurve.prototype.getPoint = function ( t ) {
  20812. var point = this.v2.clone().sub( this.v1 );
  20813. point.multiplyScalar( t ).add( this.v1 );
  20814. return point;
  20815. };
  20816. // Line curve is linear, so we can overwrite default getPointAt
  20817. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  20818. return this.getPoint( u );
  20819. };
  20820. THREE.LineCurve.prototype.getTangent = function( t ) {
  20821. var tangent = this.v2.clone().sub( this.v1 );
  20822. return tangent.normalize();
  20823. };
  20824. // File:src/extras/curves/QuadraticBezierCurve.js
  20825. /**************************************************************
  20826. * Quadratic Bezier curve
  20827. **************************************************************/
  20828. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  20829. this.v0 = v0;
  20830. this.v1 = v1;
  20831. this.v2 = v2;
  20832. };
  20833. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20834. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  20835. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  20836. var b2 = THREE.ShapeUtils.b2;
  20837. return new THREE.Vector2(
  20838. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20839. b2( t, this.v0.y, this.v1.y, this.v2.y )
  20840. );
  20841. };
  20842. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  20843. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  20844. return new THREE.Vector2(
  20845. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  20846. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  20847. ).normalize();
  20848. };
  20849. // File:src/extras/curves/CubicBezierCurve.js
  20850. /**************************************************************
  20851. * Cubic Bezier curve
  20852. **************************************************************/
  20853. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  20854. this.v0 = v0;
  20855. this.v1 = v1;
  20856. this.v2 = v2;
  20857. this.v3 = v3;
  20858. };
  20859. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20860. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  20861. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  20862. var b3 = THREE.ShapeUtils.b3;
  20863. return new THREE.Vector2(
  20864. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20865. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20866. );
  20867. };
  20868. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  20869. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  20870. return new THREE.Vector2(
  20871. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20872. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20873. ).normalize();
  20874. };
  20875. // File:src/extras/curves/SplineCurve.js
  20876. /**************************************************************
  20877. * Spline curve
  20878. **************************************************************/
  20879. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  20880. this.points = ( points == undefined ) ? [] : points;
  20881. };
  20882. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  20883. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  20884. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  20885. var points = this.points;
  20886. var point = ( points.length - 1 ) * t;
  20887. var intPoint = Math.floor( point );
  20888. var weight = point - intPoint;
  20889. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20890. var point1 = points[ intPoint ];
  20891. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20892. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20893. var interpolate = THREE.CurveUtils.interpolate;
  20894. return new THREE.Vector2(
  20895. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20896. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  20897. );
  20898. };
  20899. // File:src/extras/curves/EllipseCurve.js
  20900. /**************************************************************
  20901. * Ellipse curve
  20902. **************************************************************/
  20903. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20904. this.aX = aX;
  20905. this.aY = aY;
  20906. this.xRadius = xRadius;
  20907. this.yRadius = yRadius;
  20908. this.aStartAngle = aStartAngle;
  20909. this.aEndAngle = aEndAngle;
  20910. this.aClockwise = aClockwise;
  20911. this.aRotation = aRotation || 0;
  20912. };
  20913. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  20914. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  20915. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  20916. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20917. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  20918. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  20919. var angle;
  20920. if ( this.aClockwise === true ) {
  20921. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  20922. } else {
  20923. angle = this.aStartAngle + t * deltaAngle;
  20924. }
  20925. var x = this.aX + this.xRadius * Math.cos( angle );
  20926. var y = this.aY + this.yRadius * Math.sin( angle );
  20927. if ( this.aRotation !== 0 ) {
  20928. var cos = Math.cos( this.aRotation );
  20929. var sin = Math.sin( this.aRotation );
  20930. var tx = x, ty = y;
  20931. // Rotate the point about the center of the ellipse.
  20932. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  20933. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  20934. }
  20935. return new THREE.Vector2( x, y );
  20936. };
  20937. // File:src/extras/curves/ArcCurve.js
  20938. /**************************************************************
  20939. * Arc curve
  20940. **************************************************************/
  20941. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20942. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20943. };
  20944. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  20945. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  20946. // File:src/extras/curves/LineCurve3.js
  20947. /**************************************************************
  20948. * Line3D
  20949. **************************************************************/
  20950. THREE.LineCurve3 = THREE.Curve.create(
  20951. function ( v1, v2 ) {
  20952. this.v1 = v1;
  20953. this.v2 = v2;
  20954. },
  20955. function ( t ) {
  20956. var vector = new THREE.Vector3();
  20957. vector.subVectors( this.v2, this.v1 ); // diff
  20958. vector.multiplyScalar( t );
  20959. vector.add( this.v1 );
  20960. return vector;
  20961. }
  20962. );
  20963. // File:src/extras/curves/QuadraticBezierCurve3.js
  20964. /**************************************************************
  20965. * Quadratic Bezier 3D curve
  20966. **************************************************************/
  20967. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  20968. function ( v0, v1, v2 ) {
  20969. this.v0 = v0;
  20970. this.v1 = v1;
  20971. this.v2 = v2;
  20972. },
  20973. function ( t ) {
  20974. var b2 = THREE.ShapeUtils.b2;
  20975. return new THREE.Vector3(
  20976. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20977. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  20978. b2( t, this.v0.z, this.v1.z, this.v2.z )
  20979. );
  20980. }
  20981. );
  20982. // File:src/extras/curves/CubicBezierCurve3.js
  20983. /**************************************************************
  20984. * Cubic Bezier 3D curve
  20985. **************************************************************/
  20986. THREE.CubicBezierCurve3 = THREE.Curve.create(
  20987. function ( v0, v1, v2, v3 ) {
  20988. this.v0 = v0;
  20989. this.v1 = v1;
  20990. this.v2 = v2;
  20991. this.v3 = v3;
  20992. },
  20993. function ( t ) {
  20994. var b3 = THREE.ShapeUtils.b3;
  20995. return new THREE.Vector3(
  20996. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20997. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  20998. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  20999. );
  21000. }
  21001. );
  21002. // File:src/extras/curves/SplineCurve3.js
  21003. /**************************************************************
  21004. * Spline 3D curve
  21005. **************************************************************/
  21006. THREE.SplineCurve3 = THREE.Curve.create(
  21007. function ( points /* array of Vector3 */ ) {
  21008. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21009. this.points = ( points == undefined ) ? [] : points;
  21010. },
  21011. function ( t ) {
  21012. var points = this.points;
  21013. var point = ( points.length - 1 ) * t;
  21014. var intPoint = Math.floor( point );
  21015. var weight = point - intPoint;
  21016. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21017. var point1 = points[ intPoint ];
  21018. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21019. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21020. var interpolate = THREE.CurveUtils.interpolate;
  21021. return new THREE.Vector3(
  21022. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21023. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21024. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21025. );
  21026. }
  21027. );
  21028. // File:src/extras/curves/CatmullRomCurve3.js
  21029. /**
  21030. * @author zz85 https://github.com/zz85
  21031. *
  21032. * Centripetal CatmullRom Curve - which is useful for avoiding
  21033. * cusps and self-intersections in non-uniform catmull rom curves.
  21034. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21035. *
  21036. * curve.type accepts centripetal(default), chordal and catmullrom
  21037. * curve.tension is used for catmullrom which defaults to 0.5
  21038. */
  21039. THREE.CatmullRomCurve3 = ( function() {
  21040. var
  21041. tmp = new THREE.Vector3(),
  21042. px = new CubicPoly(),
  21043. py = new CubicPoly(),
  21044. pz = new CubicPoly();
  21045. /*
  21046. Based on an optimized c++ solution in
  21047. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21048. - http://ideone.com/NoEbVM
  21049. This CubicPoly class could be used for reusing some variables and calculations,
  21050. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21051. which can be placed in CurveUtils.
  21052. */
  21053. function CubicPoly() {
  21054. }
  21055. /*
  21056. * Compute coefficients for a cubic polynomial
  21057. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21058. * such that
  21059. * p(0) = x0, p(1) = x1
  21060. * and
  21061. * p'(0) = t0, p'(1) = t1.
  21062. */
  21063. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21064. this.c0 = x0;
  21065. this.c1 = t0;
  21066. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21067. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21068. };
  21069. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21070. // compute tangents when parameterized in [t1,t2]
  21071. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21072. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21073. // rescale tangents for parametrization in [0,1]
  21074. t1 *= dt1;
  21075. t2 *= dt1;
  21076. // initCubicPoly
  21077. this.init( x1, x2, t1, t2 );
  21078. };
  21079. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21080. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21081. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21082. };
  21083. CubicPoly.prototype.calc = function( t ) {
  21084. var t2 = t * t;
  21085. var t3 = t2 * t;
  21086. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21087. };
  21088. // Subclass Three.js curve
  21089. return THREE.Curve.create(
  21090. function ( p /* array of Vector3 */ ) {
  21091. this.points = p || [];
  21092. },
  21093. function ( t ) {
  21094. var points = this.points,
  21095. point, intPoint, weight, l;
  21096. l = points.length;
  21097. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21098. point = ( l - 1 ) * t;
  21099. intPoint = Math.floor( point );
  21100. weight = point - intPoint;
  21101. if ( weight === 0 && intPoint === l - 1 ) {
  21102. intPoint = l - 2;
  21103. weight = 1;
  21104. }
  21105. var p0, p1, p2, p3;
  21106. if ( intPoint === 0 ) {
  21107. // extrapolate first point
  21108. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21109. p0 = tmp;
  21110. } else {
  21111. p0 = points[ intPoint - 1 ];
  21112. }
  21113. p1 = points[ intPoint ];
  21114. p2 = points[ intPoint + 1 ];
  21115. if ( intPoint + 2 < l ) {
  21116. p3 = points[ intPoint + 2 ]
  21117. } else {
  21118. // extrapolate last point
  21119. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  21120. p3 = tmp;
  21121. }
  21122. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21123. // init Centripetal / Chordal Catmull-Rom
  21124. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21125. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21126. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21127. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21128. // safety check for repeated points
  21129. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21130. if ( dt0 < 1e-4 ) dt0 = dt1;
  21131. if ( dt2 < 1e-4 ) dt2 = dt1;
  21132. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21133. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21134. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21135. } else if ( this.type === 'catmullrom' ) {
  21136. var tension = this.tension !== undefined ? this.tension : 0.5;
  21137. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21138. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21139. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21140. }
  21141. var v = new THREE.Vector3(
  21142. px.calc( weight ),
  21143. py.calc( weight ),
  21144. pz.calc( weight )
  21145. );
  21146. return v;
  21147. }
  21148. );
  21149. } )();
  21150. // File:src/extras/curves/ClosedSplineCurve3.js
  21151. /**************************************************************
  21152. * Closed Spline 3D curve
  21153. **************************************************************/
  21154. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  21155. function ( points /* array of Vector3 */ ) {
  21156. this.points = ( points == undefined ) ? [] : points;
  21157. },
  21158. function ( t ) {
  21159. var points = this.points;
  21160. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  21161. var intPoint = Math.floor( point );
  21162. var weight = point - intPoint;
  21163. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21164. var point0 = points[ ( intPoint - 1 ) % points.length ];
  21165. var point1 = points[ ( intPoint ) % points.length ];
  21166. var point2 = points[ ( intPoint + 1 ) % points.length ];
  21167. var point3 = points[ ( intPoint + 2 ) % points.length ];
  21168. var interpolate = THREE.CurveUtils.interpolate;
  21169. return new THREE.Vector3(
  21170. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21171. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21172. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21173. );
  21174. }
  21175. );
  21176. // File:src/extras/geometries/BoxGeometry.js
  21177. /**
  21178. * @author mrdoob / http://mrdoob.com/
  21179. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21180. */
  21181. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21182. THREE.Geometry.call( this );
  21183. this.type = 'BoxGeometry';
  21184. this.parameters = {
  21185. width: width,
  21186. height: height,
  21187. depth: depth,
  21188. widthSegments: widthSegments,
  21189. heightSegments: heightSegments,
  21190. depthSegments: depthSegments
  21191. };
  21192. this.widthSegments = widthSegments || 1;
  21193. this.heightSegments = heightSegments || 1;
  21194. this.depthSegments = depthSegments || 1;
  21195. var scope = this;
  21196. var width_half = width / 2;
  21197. var height_half = height / 2;
  21198. var depth_half = depth / 2;
  21199. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  21200. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  21201. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  21202. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  21203. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  21204. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  21205. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  21206. var w, ix, iy,
  21207. gridX = scope.widthSegments,
  21208. gridY = scope.heightSegments,
  21209. width_half = width / 2,
  21210. height_half = height / 2,
  21211. offset = scope.vertices.length;
  21212. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  21213. w = 'z';
  21214. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  21215. w = 'y';
  21216. gridY = scope.depthSegments;
  21217. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  21218. w = 'x';
  21219. gridX = scope.depthSegments;
  21220. }
  21221. var gridX1 = gridX + 1,
  21222. gridY1 = gridY + 1,
  21223. segment_width = width / gridX,
  21224. segment_height = height / gridY,
  21225. normal = new THREE.Vector3();
  21226. normal[ w ] = depth > 0 ? 1 : - 1;
  21227. for ( iy = 0; iy < gridY1; iy ++ ) {
  21228. for ( ix = 0; ix < gridX1; ix ++ ) {
  21229. var vector = new THREE.Vector3();
  21230. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  21231. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  21232. vector[ w ] = depth;
  21233. scope.vertices.push( vector );
  21234. }
  21235. }
  21236. for ( iy = 0; iy < gridY; iy ++ ) {
  21237. for ( ix = 0; ix < gridX; ix ++ ) {
  21238. var a = ix + gridX1 * iy;
  21239. var b = ix + gridX1 * ( iy + 1 );
  21240. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  21241. var d = ( ix + 1 ) + gridX1 * iy;
  21242. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  21243. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  21244. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  21245. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  21246. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  21247. face.normal.copy( normal );
  21248. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  21249. face.materialIndex = materialIndex;
  21250. scope.faces.push( face );
  21251. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  21252. face = new THREE.Face3( b + offset, c + offset, d + offset );
  21253. face.normal.copy( normal );
  21254. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  21255. face.materialIndex = materialIndex;
  21256. scope.faces.push( face );
  21257. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  21258. }
  21259. }
  21260. }
  21261. this.mergeVertices();
  21262. };
  21263. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21264. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21265. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  21266. // File:src/extras/geometries/CircleGeometry.js
  21267. /**
  21268. * @author hughes
  21269. */
  21270. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21271. THREE.Geometry.call( this );
  21272. this.type = 'CircleGeometry';
  21273. this.parameters = {
  21274. radius: radius,
  21275. segments: segments,
  21276. thetaStart: thetaStart,
  21277. thetaLength: thetaLength
  21278. };
  21279. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21280. };
  21281. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21282. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21283. // File:src/extras/geometries/CircleBufferGeometry.js
  21284. /**
  21285. * @author benaadams / https://twitter.com/ben_a_adams
  21286. */
  21287. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21288. THREE.BufferGeometry.call( this );
  21289. this.type = 'CircleBufferGeometry';
  21290. this.parameters = {
  21291. radius: radius,
  21292. segments: segments,
  21293. thetaStart: thetaStart,
  21294. thetaLength: thetaLength
  21295. };
  21296. radius = radius || 50;
  21297. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21298. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21299. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21300. var vertices = segments + 2;
  21301. var positions = new Float32Array( vertices * 3 );
  21302. var normals = new Float32Array( vertices * 3 );
  21303. var uvs = new Float32Array( vertices * 2 );
  21304. // center data is already zero, but need to set a few extras
  21305. normals[ 2 ] = 1.0;
  21306. uvs[ 0 ] = 0.5;
  21307. uvs[ 1 ] = 0.5;
  21308. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21309. var segment = thetaStart + s / segments * thetaLength;
  21310. positions[ i ] = radius * Math.cos( segment );
  21311. positions[ i + 1 ] = radius * Math.sin( segment );
  21312. normals[ i + 2 ] = 1; // normal z
  21313. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21314. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21315. }
  21316. var indices = [];
  21317. for ( var i = 1; i <= segments; i ++ ) {
  21318. indices.push( i, i + 1, 0 );
  21319. }
  21320. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21321. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21322. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21323. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21324. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21325. };
  21326. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21327. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21328. // File:src/extras/geometries/CylinderGeometry.js
  21329. /**
  21330. * @author mrdoob / http://mrdoob.com/
  21331. */
  21332. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21333. THREE.Geometry.call( this );
  21334. this.type = 'CylinderGeometry';
  21335. this.parameters = {
  21336. radiusTop: radiusTop,
  21337. radiusBottom: radiusBottom,
  21338. height: height,
  21339. radialSegments: radialSegments,
  21340. heightSegments: heightSegments,
  21341. openEnded: openEnded,
  21342. thetaStart: thetaStart,
  21343. thetaLength: thetaLength
  21344. };
  21345. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21346. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21347. height = height !== undefined ? height : 100;
  21348. radialSegments = radialSegments || 8;
  21349. heightSegments = heightSegments || 1;
  21350. openEnded = openEnded !== undefined ? openEnded : false;
  21351. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21352. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21353. var heightHalf = height / 2;
  21354. var x, y, vertices = [], uvs = [];
  21355. for ( y = 0; y <= heightSegments; y ++ ) {
  21356. var verticesRow = [];
  21357. var uvsRow = [];
  21358. var v = y / heightSegments;
  21359. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21360. for ( x = 0; x <= radialSegments; x ++ ) {
  21361. var u = x / radialSegments;
  21362. var vertex = new THREE.Vector3();
  21363. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21364. vertex.y = - v * height + heightHalf;
  21365. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21366. this.vertices.push( vertex );
  21367. verticesRow.push( this.vertices.length - 1 );
  21368. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  21369. }
  21370. vertices.push( verticesRow );
  21371. uvs.push( uvsRow );
  21372. }
  21373. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21374. var na, nb;
  21375. for ( x = 0; x < radialSegments; x ++ ) {
  21376. if ( radiusTop !== 0 ) {
  21377. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  21378. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  21379. } else {
  21380. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  21381. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  21382. }
  21383. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  21384. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  21385. for ( y = 0; y < heightSegments; y ++ ) {
  21386. var v1 = vertices[ y ][ x ];
  21387. var v2 = vertices[ y + 1 ][ x ];
  21388. var v3 = vertices[ y + 1 ][ x + 1 ];
  21389. var v4 = vertices[ y ][ x + 1 ];
  21390. var n1 = na.clone();
  21391. var n2 = na.clone();
  21392. var n3 = nb.clone();
  21393. var n4 = nb.clone();
  21394. var uv1 = uvs[ y ][ x ].clone();
  21395. var uv2 = uvs[ y + 1 ][ x ].clone();
  21396. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  21397. var uv4 = uvs[ y ][ x + 1 ].clone();
  21398. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  21399. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  21400. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  21401. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  21402. }
  21403. }
  21404. // top cap
  21405. if ( openEnded === false && radiusTop > 0 ) {
  21406. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  21407. for ( x = 0; x < radialSegments; x ++ ) {
  21408. var v1 = vertices[ 0 ][ x ];
  21409. var v2 = vertices[ 0 ][ x + 1 ];
  21410. var v3 = this.vertices.length - 1;
  21411. var n1 = new THREE.Vector3( 0, 1, 0 );
  21412. var n2 = new THREE.Vector3( 0, 1, 0 );
  21413. var n3 = new THREE.Vector3( 0, 1, 0 );
  21414. var uv1 = uvs[ 0 ][ x ].clone();
  21415. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  21416. var uv3 = new THREE.Vector2( uv2.x, 0 );
  21417. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  21418. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21419. }
  21420. }
  21421. // bottom cap
  21422. if ( openEnded === false && radiusBottom > 0 ) {
  21423. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  21424. for ( x = 0; x < radialSegments; x ++ ) {
  21425. var v1 = vertices[ heightSegments ][ x + 1 ];
  21426. var v2 = vertices[ heightSegments ][ x ];
  21427. var v3 = this.vertices.length - 1;
  21428. var n1 = new THREE.Vector3( 0, - 1, 0 );
  21429. var n2 = new THREE.Vector3( 0, - 1, 0 );
  21430. var n3 = new THREE.Vector3( 0, - 1, 0 );
  21431. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  21432. var uv2 = uvs[ heightSegments ][ x ].clone();
  21433. var uv3 = new THREE.Vector2( uv2.x, 1 );
  21434. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  21435. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21436. }
  21437. }
  21438. this.computeFaceNormals();
  21439. };
  21440. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21441. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21442. // File:src/extras/geometries/EdgesGeometry.js
  21443. /**
  21444. * @author WestLangley / http://github.com/WestLangley
  21445. */
  21446. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21447. THREE.BufferGeometry.call( this );
  21448. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21449. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21450. var edge = [ 0, 0 ], hash = {};
  21451. function sortFunction( a, b ) {
  21452. return a - b;
  21453. }
  21454. var keys = [ 'a', 'b', 'c' ];
  21455. var geometry2;
  21456. if ( geometry instanceof THREE.BufferGeometry ) {
  21457. geometry2 = new THREE.Geometry();
  21458. geometry2.fromBufferGeometry( geometry );
  21459. } else {
  21460. geometry2 = geometry.clone();
  21461. }
  21462. geometry2.mergeVertices();
  21463. geometry2.computeFaceNormals();
  21464. var vertices = geometry2.vertices;
  21465. var faces = geometry2.faces;
  21466. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21467. var face = faces[ i ];
  21468. for ( var j = 0; j < 3; j ++ ) {
  21469. edge[ 0 ] = face[ keys[ j ] ];
  21470. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21471. edge.sort( sortFunction );
  21472. var key = edge.toString();
  21473. if ( hash[ key ] === undefined ) {
  21474. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21475. } else {
  21476. hash[ key ].face2 = i;
  21477. }
  21478. }
  21479. }
  21480. var coords = [];
  21481. for ( var key in hash ) {
  21482. var h = hash[ key ];
  21483. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21484. var vertex = vertices[ h.vert1 ];
  21485. coords.push( vertex.x );
  21486. coords.push( vertex.y );
  21487. coords.push( vertex.z );
  21488. vertex = vertices[ h.vert2 ];
  21489. coords.push( vertex.x );
  21490. coords.push( vertex.y );
  21491. coords.push( vertex.z );
  21492. }
  21493. }
  21494. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21495. };
  21496. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21497. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21498. // File:src/extras/geometries/ExtrudeGeometry.js
  21499. /**
  21500. * @author zz85 / http://www.lab4games.net/zz85/blog
  21501. *
  21502. * Creates extruded geometry from a path shape.
  21503. *
  21504. * parameters = {
  21505. *
  21506. * curveSegments: <int>, // number of points on the curves
  21507. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21508. * amount: <int>, // Depth to extrude the shape
  21509. *
  21510. * bevelEnabled: <bool>, // turn on bevel
  21511. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21512. * bevelSize: <float>, // how far from shape outline is bevel
  21513. * bevelSegments: <int>, // number of bevel layers
  21514. *
  21515. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21516. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21517. *
  21518. * uvGenerator: <Object> // object that provides UV generator functions
  21519. *
  21520. * }
  21521. **/
  21522. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21523. if ( typeof( shapes ) === "undefined" ) {
  21524. shapes = [];
  21525. return;
  21526. }
  21527. THREE.Geometry.call( this );
  21528. this.type = 'ExtrudeGeometry';
  21529. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21530. this.addShapeList( shapes, options );
  21531. this.computeFaceNormals();
  21532. // can't really use automatic vertex normals
  21533. // as then front and back sides get smoothed too
  21534. // should do separate smoothing just for sides
  21535. //this.computeVertexNormals();
  21536. //console.log( "took", ( Date.now() - startTime ) );
  21537. };
  21538. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21539. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21540. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21541. var sl = shapes.length;
  21542. for ( var s = 0; s < sl; s ++ ) {
  21543. var shape = shapes[ s ];
  21544. this.addShape( shape, options );
  21545. }
  21546. };
  21547. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21548. var amount = options.amount !== undefined ? options.amount : 100;
  21549. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21550. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21551. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21552. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21553. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21554. var steps = options.steps !== undefined ? options.steps : 1;
  21555. var extrudePath = options.extrudePath;
  21556. var extrudePts, extrudeByPath = false;
  21557. // Use default WorldUVGenerator if no UV generators are specified.
  21558. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21559. var splineTube, binormal, normal, position2;
  21560. if ( extrudePath ) {
  21561. extrudePts = extrudePath.getSpacedPoints( steps );
  21562. extrudeByPath = true;
  21563. bevelEnabled = false; // bevels not supported for path extrusion
  21564. // SETUP TNB variables
  21565. // Reuse TNB from TubeGeomtry for now.
  21566. // TODO1 - have a .isClosed in spline?
  21567. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21568. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21569. binormal = new THREE.Vector3();
  21570. normal = new THREE.Vector3();
  21571. position2 = new THREE.Vector3();
  21572. }
  21573. // Safeguards if bevels are not enabled
  21574. if ( ! bevelEnabled ) {
  21575. bevelSegments = 0;
  21576. bevelThickness = 0;
  21577. bevelSize = 0;
  21578. }
  21579. // Variables initialization
  21580. var ahole, h, hl; // looping of holes
  21581. var scope = this;
  21582. var shapesOffset = this.vertices.length;
  21583. var shapePoints = shape.extractPoints( curveSegments );
  21584. var vertices = shapePoints.shape;
  21585. var holes = shapePoints.holes;
  21586. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21587. if ( reverse ) {
  21588. vertices = vertices.reverse();
  21589. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  21590. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21591. ahole = holes[ h ];
  21592. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  21593. holes[ h ] = ahole.reverse();
  21594. }
  21595. }
  21596. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  21597. }
  21598. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21599. /* Vertices */
  21600. var contour = vertices; // vertices has all points but contour has only points of circumference
  21601. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21602. ahole = holes[ h ];
  21603. vertices = vertices.concat( ahole );
  21604. }
  21605. function scalePt2 ( pt, vec, size ) {
  21606. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  21607. return vec.clone().multiplyScalar( size ).add( pt );
  21608. }
  21609. var b, bs, t, z,
  21610. vert, vlen = vertices.length,
  21611. face, flen = faces.length;
  21612. // Find directions for point movement
  21613. function getBevelVec( inPt, inPrev, inNext ) {
  21614. // computes for inPt the corresponding point inPt' on a new contour
  21615. // shifted by 1 unit (length of normalized vector) to the left
  21616. // if we walk along contour clockwise, this new contour is outside the old one
  21617. //
  21618. // inPt' is the intersection of the two lines parallel to the two
  21619. // adjacent edges of inPt at a distance of 1 unit on the left side.
  21620. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  21621. // good reading for geometry algorithms (here: line-line intersection)
  21622. // http://geomalgorithms.com/a05-_intersect-1.html
  21623. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  21624. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  21625. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  21626. // check for collinear edges
  21627. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21628. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  21629. // not collinear
  21630. // length of vectors for normalizing
  21631. var v_prev_len = Math.sqrt( v_prev_lensq );
  21632. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  21633. // shift adjacent points by unit vectors to the left
  21634. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  21635. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  21636. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  21637. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  21638. // scaling factor for v_prev to intersection point
  21639. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  21640. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  21641. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21642. // vector from inPt to intersection point
  21643. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  21644. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  21645. // Don't normalize!, otherwise sharp corners become ugly
  21646. // but prevent crazy spikes
  21647. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  21648. if ( v_trans_lensq <= 2 ) {
  21649. return new THREE.Vector2( v_trans_x, v_trans_y );
  21650. } else {
  21651. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  21652. }
  21653. } else {
  21654. // handle special case of collinear edges
  21655. var direction_eq = false; // assumes: opposite
  21656. if ( v_prev_x > Number.EPSILON ) {
  21657. if ( v_next_x > Number.EPSILON ) {
  21658. direction_eq = true;
  21659. }
  21660. } else {
  21661. if ( v_prev_x < - Number.EPSILON ) {
  21662. if ( v_next_x < - Number.EPSILON ) {
  21663. direction_eq = true;
  21664. }
  21665. } else {
  21666. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  21667. direction_eq = true;
  21668. }
  21669. }
  21670. }
  21671. if ( direction_eq ) {
  21672. // console.log("Warning: lines are a straight sequence");
  21673. v_trans_x = - v_prev_y;
  21674. v_trans_y = v_prev_x;
  21675. shrink_by = Math.sqrt( v_prev_lensq );
  21676. } else {
  21677. // console.log("Warning: lines are a straight spike");
  21678. v_trans_x = v_prev_x;
  21679. v_trans_y = v_prev_y;
  21680. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  21681. }
  21682. }
  21683. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  21684. }
  21685. var contourMovements = [];
  21686. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21687. if ( j === il ) j = 0;
  21688. if ( k === il ) k = 0;
  21689. // (j)---(i)---(k)
  21690. // console.log('i,j,k', i, j , k)
  21691. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  21692. }
  21693. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  21694. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21695. ahole = holes[ h ];
  21696. oneHoleMovements = [];
  21697. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21698. if ( j === il ) j = 0;
  21699. if ( k === il ) k = 0;
  21700. // (j)---(i)---(k)
  21701. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  21702. }
  21703. holesMovements.push( oneHoleMovements );
  21704. verticesMovements = verticesMovements.concat( oneHoleMovements );
  21705. }
  21706. // Loop bevelSegments, 1 for the front, 1 for the back
  21707. for ( b = 0; b < bevelSegments; b ++ ) {
  21708. //for ( b = bevelSegments; b > 0; b -- ) {
  21709. t = b / bevelSegments;
  21710. z = bevelThickness * ( 1 - t );
  21711. //z = bevelThickness * t;
  21712. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  21713. //bs = bevelSize * t; // linear
  21714. // contract shape
  21715. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21716. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21717. v( vert.x, vert.y, - z );
  21718. }
  21719. // expand holes
  21720. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21721. ahole = holes[ h ];
  21722. oneHoleMovements = holesMovements[ h ];
  21723. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21724. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21725. v( vert.x, vert.y, - z );
  21726. }
  21727. }
  21728. }
  21729. bs = bevelSize;
  21730. // Back facing vertices
  21731. for ( i = 0; i < vlen; i ++ ) {
  21732. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21733. if ( ! extrudeByPath ) {
  21734. v( vert.x, vert.y, 0 );
  21735. } else {
  21736. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  21737. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  21738. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  21739. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  21740. v( position2.x, position2.y, position2.z );
  21741. }
  21742. }
  21743. // Add stepped vertices...
  21744. // Including front facing vertices
  21745. var s;
  21746. for ( s = 1; s <= steps; s ++ ) {
  21747. for ( i = 0; i < vlen; i ++ ) {
  21748. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21749. if ( ! extrudeByPath ) {
  21750. v( vert.x, vert.y, amount / steps * s );
  21751. } else {
  21752. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  21753. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  21754. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  21755. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  21756. v( position2.x, position2.y, position2.z );
  21757. }
  21758. }
  21759. }
  21760. // Add bevel segments planes
  21761. //for ( b = 1; b <= bevelSegments; b ++ ) {
  21762. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  21763. t = b / bevelSegments;
  21764. z = bevelThickness * ( 1 - t );
  21765. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  21766. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  21767. // contract shape
  21768. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21769. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21770. v( vert.x, vert.y, amount + z );
  21771. }
  21772. // expand holes
  21773. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21774. ahole = holes[ h ];
  21775. oneHoleMovements = holesMovements[ h ];
  21776. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21777. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21778. if ( ! extrudeByPath ) {
  21779. v( vert.x, vert.y, amount + z );
  21780. } else {
  21781. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  21782. }
  21783. }
  21784. }
  21785. }
  21786. /* Faces */
  21787. // Top and bottom faces
  21788. buildLidFaces();
  21789. // Sides faces
  21790. buildSideFaces();
  21791. ///// Internal functions
  21792. function buildLidFaces() {
  21793. if ( bevelEnabled ) {
  21794. var layer = 0; // steps + 1
  21795. var offset = vlen * layer;
  21796. // Bottom faces
  21797. for ( i = 0; i < flen; i ++ ) {
  21798. face = faces[ i ];
  21799. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  21800. }
  21801. layer = steps + bevelSegments * 2;
  21802. offset = vlen * layer;
  21803. // Top faces
  21804. for ( i = 0; i < flen; i ++ ) {
  21805. face = faces[ i ];
  21806. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  21807. }
  21808. } else {
  21809. // Bottom faces
  21810. for ( i = 0; i < flen; i ++ ) {
  21811. face = faces[ i ];
  21812. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  21813. }
  21814. // Top faces
  21815. for ( i = 0; i < flen; i ++ ) {
  21816. face = faces[ i ];
  21817. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  21818. }
  21819. }
  21820. }
  21821. // Create faces for the z-sides of the shape
  21822. function buildSideFaces() {
  21823. var layeroffset = 0;
  21824. sidewalls( contour, layeroffset );
  21825. layeroffset += contour.length;
  21826. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21827. ahole = holes[ h ];
  21828. sidewalls( ahole, layeroffset );
  21829. //, true
  21830. layeroffset += ahole.length;
  21831. }
  21832. }
  21833. function sidewalls( contour, layeroffset ) {
  21834. var j, k;
  21835. i = contour.length;
  21836. while ( -- i >= 0 ) {
  21837. j = i;
  21838. k = i - 1;
  21839. if ( k < 0 ) k = contour.length - 1;
  21840. //console.log('b', i,j, i-1, k,vertices.length);
  21841. var s = 0, sl = steps + bevelSegments * 2;
  21842. for ( s = 0; s < sl; s ++ ) {
  21843. var slen1 = vlen * s;
  21844. var slen2 = vlen * ( s + 1 );
  21845. var a = layeroffset + j + slen1,
  21846. b = layeroffset + k + slen1,
  21847. c = layeroffset + k + slen2,
  21848. d = layeroffset + j + slen2;
  21849. f4( a, b, c, d, contour, s, sl, j, k );
  21850. }
  21851. }
  21852. }
  21853. function v( x, y, z ) {
  21854. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  21855. }
  21856. function f3( a, b, c ) {
  21857. a += shapesOffset;
  21858. b += shapesOffset;
  21859. c += shapesOffset;
  21860. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  21861. var uvs = uvgen.generateTopUV( scope, a, b, c );
  21862. scope.faceVertexUvs[ 0 ].push( uvs );
  21863. }
  21864. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  21865. a += shapesOffset;
  21866. b += shapesOffset;
  21867. c += shapesOffset;
  21868. d += shapesOffset;
  21869. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  21870. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  21871. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  21872. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  21873. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  21874. }
  21875. };
  21876. THREE.ExtrudeGeometry.WorldUVGenerator = {
  21877. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  21878. var vertices = geometry.vertices;
  21879. var a = vertices[ indexA ];
  21880. var b = vertices[ indexB ];
  21881. var c = vertices[ indexC ];
  21882. return [
  21883. new THREE.Vector2( a.x, a.y ),
  21884. new THREE.Vector2( b.x, b.y ),
  21885. new THREE.Vector2( c.x, c.y )
  21886. ];
  21887. },
  21888. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  21889. var vertices = geometry.vertices;
  21890. var a = vertices[ indexA ];
  21891. var b = vertices[ indexB ];
  21892. var c = vertices[ indexC ];
  21893. var d = vertices[ indexD ];
  21894. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  21895. return [
  21896. new THREE.Vector2( a.x, 1 - a.z ),
  21897. new THREE.Vector2( b.x, 1 - b.z ),
  21898. new THREE.Vector2( c.x, 1 - c.z ),
  21899. new THREE.Vector2( d.x, 1 - d.z )
  21900. ];
  21901. } else {
  21902. return [
  21903. new THREE.Vector2( a.y, 1 - a.z ),
  21904. new THREE.Vector2( b.y, 1 - b.z ),
  21905. new THREE.Vector2( c.y, 1 - c.z ),
  21906. new THREE.Vector2( d.y, 1 - d.z )
  21907. ];
  21908. }
  21909. }
  21910. };
  21911. // File:src/extras/geometries/ShapeGeometry.js
  21912. /**
  21913. * @author jonobr1 / http://jonobr1.com
  21914. *
  21915. * Creates a one-sided polygonal geometry from a path shape. Similar to
  21916. * ExtrudeGeometry.
  21917. *
  21918. * parameters = {
  21919. *
  21920. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  21921. *
  21922. * material: <int> // material index for front and back faces
  21923. * uvGenerator: <Object> // object that provides UV generator functions
  21924. *
  21925. * }
  21926. **/
  21927. THREE.ShapeGeometry = function ( shapes, options ) {
  21928. THREE.Geometry.call( this );
  21929. this.type = 'ShapeGeometry';
  21930. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  21931. this.addShapeList( shapes, options );
  21932. this.computeFaceNormals();
  21933. };
  21934. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21935. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  21936. /**
  21937. * Add an array of shapes to THREE.ShapeGeometry.
  21938. */
  21939. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21940. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  21941. this.addShape( shapes[ i ], options );
  21942. }
  21943. return this;
  21944. };
  21945. /**
  21946. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  21947. */
  21948. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  21949. if ( options === undefined ) options = {};
  21950. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21951. var material = options.material;
  21952. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  21953. //
  21954. var i, l, hole;
  21955. var shapesOffset = this.vertices.length;
  21956. var shapePoints = shape.extractPoints( curveSegments );
  21957. var vertices = shapePoints.shape;
  21958. var holes = shapePoints.holes;
  21959. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21960. if ( reverse ) {
  21961. vertices = vertices.reverse();
  21962. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  21963. for ( i = 0, l = holes.length; i < l; i ++ ) {
  21964. hole = holes[ i ];
  21965. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  21966. holes[ i ] = hole.reverse();
  21967. }
  21968. }
  21969. reverse = false;
  21970. }
  21971. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21972. // Vertices
  21973. for ( i = 0, l = holes.length; i < l; i ++ ) {
  21974. hole = holes[ i ];
  21975. vertices = vertices.concat( hole );
  21976. }
  21977. //
  21978. var vert, vlen = vertices.length;
  21979. var face, flen = faces.length;
  21980. for ( i = 0; i < vlen; i ++ ) {
  21981. vert = vertices[ i ];
  21982. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  21983. }
  21984. for ( i = 0; i < flen; i ++ ) {
  21985. face = faces[ i ];
  21986. var a = face[ 0 ] + shapesOffset;
  21987. var b = face[ 1 ] + shapesOffset;
  21988. var c = face[ 2 ] + shapesOffset;
  21989. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  21990. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  21991. }
  21992. };
  21993. // File:src/extras/geometries/LatheGeometry.js
  21994. /**
  21995. * @author astrodud / http://astrodud.isgreat.org/
  21996. * @author zz85 / https://github.com/zz85
  21997. * @author bhouston / http://clara.io
  21998. */
  21999. // points - to create a closed torus, one must use a set of points
  22000. // like so: [ a, b, c, d, a ], see first is the same as last.
  22001. // segments - the number of circumference segments to create
  22002. // phiStart - the starting radian
  22003. // phiLength - the radian (0 to 2*PI) range of the lathed section
  22004. // 2*pi is a closed lathe, less than 2PI is a portion.
  22005. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22006. THREE.Geometry.call( this );
  22007. this.type = 'LatheGeometry';
  22008. this.parameters = {
  22009. points: points,
  22010. segments: segments,
  22011. phiStart: phiStart,
  22012. phiLength: phiLength
  22013. };
  22014. segments = segments || 12;
  22015. phiStart = phiStart || 0;
  22016. phiLength = phiLength || 2 * Math.PI;
  22017. var inversePointLength = 1.0 / ( points.length - 1 );
  22018. var inverseSegments = 1.0 / segments;
  22019. for ( var i = 0, il = segments; i <= il; i ++ ) {
  22020. var phi = phiStart + i * inverseSegments * phiLength;
  22021. var c = Math.cos( phi ),
  22022. s = Math.sin( phi );
  22023. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  22024. var pt = points[ j ];
  22025. var vertex = new THREE.Vector3();
  22026. vertex.x = c * pt.x - s * pt.y;
  22027. vertex.y = s * pt.x + c * pt.y;
  22028. vertex.z = pt.z;
  22029. this.vertices.push( vertex );
  22030. }
  22031. }
  22032. var np = points.length;
  22033. for ( var i = 0, il = segments; i < il; i ++ ) {
  22034. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  22035. var base = j + np * i;
  22036. var a = base;
  22037. var b = base + np;
  22038. var c = base + 1 + np;
  22039. var d = base + 1;
  22040. var u0 = i * inverseSegments;
  22041. var v0 = j * inversePointLength;
  22042. var u1 = u0 + inverseSegments;
  22043. var v1 = v0 + inversePointLength;
  22044. this.faces.push( new THREE.Face3( a, b, d ) );
  22045. this.faceVertexUvs[ 0 ].push( [
  22046. new THREE.Vector2( u0, v0 ),
  22047. new THREE.Vector2( u1, v0 ),
  22048. new THREE.Vector2( u0, v1 )
  22049. ] );
  22050. this.faces.push( new THREE.Face3( b, c, d ) );
  22051. this.faceVertexUvs[ 0 ].push( [
  22052. new THREE.Vector2( u1, v0 ),
  22053. new THREE.Vector2( u1, v1 ),
  22054. new THREE.Vector2( u0, v1 )
  22055. ] );
  22056. }
  22057. }
  22058. this.mergeVertices();
  22059. this.computeFaceNormals();
  22060. this.computeVertexNormals();
  22061. };
  22062. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22063. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22064. // File:src/extras/geometries/PlaneGeometry.js
  22065. /**
  22066. * @author mrdoob / http://mrdoob.com/
  22067. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22068. */
  22069. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22070. THREE.Geometry.call( this );
  22071. this.type = 'PlaneGeometry';
  22072. this.parameters = {
  22073. width: width,
  22074. height: height,
  22075. widthSegments: widthSegments,
  22076. heightSegments: heightSegments
  22077. };
  22078. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22079. };
  22080. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22081. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22082. // File:src/extras/geometries/PlaneBufferGeometry.js
  22083. /**
  22084. * @author mrdoob / http://mrdoob.com/
  22085. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22086. */
  22087. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22088. THREE.BufferGeometry.call( this );
  22089. this.type = 'PlaneBufferGeometry';
  22090. this.parameters = {
  22091. width: width,
  22092. height: height,
  22093. widthSegments: widthSegments,
  22094. heightSegments: heightSegments
  22095. };
  22096. var width_half = width / 2;
  22097. var height_half = height / 2;
  22098. var gridX = Math.floor( widthSegments ) || 1;
  22099. var gridY = Math.floor( heightSegments ) || 1;
  22100. var gridX1 = gridX + 1;
  22101. var gridY1 = gridY + 1;
  22102. var segment_width = width / gridX;
  22103. var segment_height = height / gridY;
  22104. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22105. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22106. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22107. var offset = 0;
  22108. var offset2 = 0;
  22109. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22110. var y = iy * segment_height - height_half;
  22111. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22112. var x = ix * segment_width - width_half;
  22113. vertices[ offset ] = x;
  22114. vertices[ offset + 1 ] = - y;
  22115. normals[ offset + 2 ] = 1;
  22116. uvs[ offset2 ] = ix / gridX;
  22117. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22118. offset += 3;
  22119. offset2 += 2;
  22120. }
  22121. }
  22122. offset = 0;
  22123. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22124. for ( var iy = 0; iy < gridY; iy ++ ) {
  22125. for ( var ix = 0; ix < gridX; ix ++ ) {
  22126. var a = ix + gridX1 * iy;
  22127. var b = ix + gridX1 * ( iy + 1 );
  22128. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22129. var d = ( ix + 1 ) + gridX1 * iy;
  22130. indices[ offset ] = a;
  22131. indices[ offset + 1 ] = b;
  22132. indices[ offset + 2 ] = d;
  22133. indices[ offset + 3 ] = b;
  22134. indices[ offset + 4 ] = c;
  22135. indices[ offset + 5 ] = d;
  22136. offset += 6;
  22137. }
  22138. }
  22139. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22140. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22141. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22142. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22143. };
  22144. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22145. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22146. // File:src/extras/geometries/RingGeometry.js
  22147. /**
  22148. * @author Kaleb Murphy
  22149. */
  22150. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22151. THREE.Geometry.call( this );
  22152. this.type = 'RingGeometry';
  22153. this.parameters = {
  22154. innerRadius: innerRadius,
  22155. outerRadius: outerRadius,
  22156. thetaSegments: thetaSegments,
  22157. phiSegments: phiSegments,
  22158. thetaStart: thetaStart,
  22159. thetaLength: thetaLength
  22160. };
  22161. innerRadius = innerRadius || 0;
  22162. outerRadius = outerRadius || 50;
  22163. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22164. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22165. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22166. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  22167. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22168. for ( i = 0; i < phiSegments + 1; i ++ ) {
  22169. // concentric circles inside ring
  22170. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  22171. // number of segments per circle
  22172. var vertex = new THREE.Vector3();
  22173. var segment = thetaStart + o / thetaSegments * thetaLength;
  22174. vertex.x = radius * Math.cos( segment );
  22175. vertex.y = radius * Math.sin( segment );
  22176. this.vertices.push( vertex );
  22177. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  22178. }
  22179. radius += radiusStep;
  22180. }
  22181. var n = new THREE.Vector3( 0, 0, 1 );
  22182. for ( i = 0; i < phiSegments; i ++ ) {
  22183. // concentric circles inside ring
  22184. var thetaSegment = i * ( thetaSegments + 1 );
  22185. for ( o = 0; o < thetaSegments ; o ++ ) {
  22186. // number of segments per circle
  22187. var segment = o + thetaSegment;
  22188. var v1 = segment;
  22189. var v2 = segment + thetaSegments + 1;
  22190. var v3 = segment + thetaSegments + 2;
  22191. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  22192. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  22193. v1 = segment;
  22194. v2 = segment + thetaSegments + 2;
  22195. v3 = segment + 1;
  22196. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  22197. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  22198. }
  22199. }
  22200. this.computeFaceNormals();
  22201. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22202. };
  22203. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22204. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  22205. // File:src/extras/geometries/SphereGeometry.js
  22206. /**
  22207. * @author mrdoob / http://mrdoob.com/
  22208. */
  22209. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22210. THREE.Geometry.call( this );
  22211. this.type = 'SphereGeometry';
  22212. this.parameters = {
  22213. radius: radius,
  22214. widthSegments: widthSegments,
  22215. heightSegments: heightSegments,
  22216. phiStart: phiStart,
  22217. phiLength: phiLength,
  22218. thetaStart: thetaStart,
  22219. thetaLength: thetaLength
  22220. };
  22221. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  22222. };
  22223. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22224. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  22225. // File:src/extras/geometries/SphereBufferGeometry.js
  22226. /**
  22227. * @author benaadams / https://twitter.com/ben_a_adams
  22228. * based on THREE.SphereGeometry
  22229. */
  22230. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22231. THREE.BufferGeometry.call( this );
  22232. this.type = 'SphereBufferGeometry';
  22233. this.parameters = {
  22234. radius: radius,
  22235. widthSegments: widthSegments,
  22236. heightSegments: heightSegments,
  22237. phiStart: phiStart,
  22238. phiLength: phiLength,
  22239. thetaStart: thetaStart,
  22240. thetaLength: thetaLength
  22241. };
  22242. radius = radius || 50;
  22243. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  22244. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  22245. phiStart = phiStart !== undefined ? phiStart : 0;
  22246. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  22247. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22248. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  22249. var thetaEnd = thetaStart + thetaLength;
  22250. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  22251. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22252. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22253. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22254. var index = 0, vertices = [], normal = new THREE.Vector3();
  22255. for ( var y = 0; y <= heightSegments; y ++ ) {
  22256. var verticesRow = [];
  22257. var v = y / heightSegments;
  22258. for ( var x = 0; x <= widthSegments; x ++ ) {
  22259. var u = x / widthSegments;
  22260. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22261. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22262. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22263. normal.set( px, py, pz ).normalize();
  22264. positions.setXYZ( index, px, py, pz );
  22265. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22266. uvs.setXY( index, u, 1 - v );
  22267. verticesRow.push( index );
  22268. index ++;
  22269. }
  22270. vertices.push( verticesRow );
  22271. }
  22272. var indices = [];
  22273. for ( var y = 0; y < heightSegments; y ++ ) {
  22274. for ( var x = 0; x < widthSegments; x ++ ) {
  22275. var v1 = vertices[ y ][ x + 1 ];
  22276. var v2 = vertices[ y ][ x ];
  22277. var v3 = vertices[ y + 1 ][ x ];
  22278. var v4 = vertices[ y + 1 ][ x + 1 ];
  22279. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22280. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22281. }
  22282. }
  22283. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22284. this.addAttribute( 'position', positions );
  22285. this.addAttribute( 'normal', normals );
  22286. this.addAttribute( 'uv', uvs );
  22287. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22288. };
  22289. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22290. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22291. // File:src/extras/geometries/TorusGeometry.js
  22292. /**
  22293. * @author oosmoxiecode
  22294. * @author mrdoob / http://mrdoob.com/
  22295. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22296. */
  22297. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22298. THREE.Geometry.call( this );
  22299. this.type = 'TorusGeometry';
  22300. this.parameters = {
  22301. radius: radius,
  22302. tube: tube,
  22303. radialSegments: radialSegments,
  22304. tubularSegments: tubularSegments,
  22305. arc: arc
  22306. };
  22307. radius = radius || 100;
  22308. tube = tube || 40;
  22309. radialSegments = radialSegments || 8;
  22310. tubularSegments = tubularSegments || 6;
  22311. arc = arc || Math.PI * 2;
  22312. var center = new THREE.Vector3(), uvs = [], normals = [];
  22313. for ( var j = 0; j <= radialSegments; j ++ ) {
  22314. for ( var i = 0; i <= tubularSegments; i ++ ) {
  22315. var u = i / tubularSegments * arc;
  22316. var v = j / radialSegments * Math.PI * 2;
  22317. center.x = radius * Math.cos( u );
  22318. center.y = radius * Math.sin( u );
  22319. var vertex = new THREE.Vector3();
  22320. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22321. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22322. vertex.z = tube * Math.sin( v );
  22323. this.vertices.push( vertex );
  22324. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  22325. normals.push( vertex.clone().sub( center ).normalize() );
  22326. }
  22327. }
  22328. for ( var j = 1; j <= radialSegments; j ++ ) {
  22329. for ( var i = 1; i <= tubularSegments; i ++ ) {
  22330. var a = ( tubularSegments + 1 ) * j + i - 1;
  22331. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22332. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22333. var d = ( tubularSegments + 1 ) * j + i;
  22334. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  22335. this.faces.push( face );
  22336. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  22337. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  22338. this.faces.push( face );
  22339. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  22340. }
  22341. }
  22342. this.computeFaceNormals();
  22343. };
  22344. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22345. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22346. // File:src/extras/geometries/TorusKnotGeometry.js
  22347. /**
  22348. * @author oosmoxiecode
  22349. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  22350. */
  22351. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  22352. THREE.Geometry.call( this );
  22353. this.type = 'TorusKnotGeometry';
  22354. this.parameters = {
  22355. radius: radius,
  22356. tube: tube,
  22357. radialSegments: radialSegments,
  22358. tubularSegments: tubularSegments,
  22359. p: p,
  22360. q: q,
  22361. heightScale: heightScale
  22362. };
  22363. radius = radius || 100;
  22364. tube = tube || 40;
  22365. radialSegments = radialSegments || 64;
  22366. tubularSegments = tubularSegments || 8;
  22367. p = p || 2;
  22368. q = q || 3;
  22369. heightScale = heightScale || 1;
  22370. var grid = new Array( radialSegments );
  22371. var tang = new THREE.Vector3();
  22372. var n = new THREE.Vector3();
  22373. var bitan = new THREE.Vector3();
  22374. for ( var i = 0; i < radialSegments; ++ i ) {
  22375. grid[ i ] = new Array( tubularSegments );
  22376. var u = i / radialSegments * 2 * p * Math.PI;
  22377. var p1 = getPos( u, q, p, radius, heightScale );
  22378. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  22379. tang.subVectors( p2, p1 );
  22380. n.addVectors( p2, p1 );
  22381. bitan.crossVectors( tang, n );
  22382. n.crossVectors( bitan, tang );
  22383. bitan.normalize();
  22384. n.normalize();
  22385. for ( var j = 0; j < tubularSegments; ++ j ) {
  22386. var v = j / tubularSegments * 2 * Math.PI;
  22387. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22388. var cy = tube * Math.sin( v );
  22389. var pos = new THREE.Vector3();
  22390. pos.x = p1.x + cx * n.x + cy * bitan.x;
  22391. pos.y = p1.y + cx * n.y + cy * bitan.y;
  22392. pos.z = p1.z + cx * n.z + cy * bitan.z;
  22393. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  22394. }
  22395. }
  22396. for ( var i = 0; i < radialSegments; ++ i ) {
  22397. for ( var j = 0; j < tubularSegments; ++ j ) {
  22398. var ip = ( i + 1 ) % radialSegments;
  22399. var jp = ( j + 1 ) % tubularSegments;
  22400. var a = grid[ i ][ j ];
  22401. var b = grid[ ip ][ j ];
  22402. var c = grid[ ip ][ jp ];
  22403. var d = grid[ i ][ jp ];
  22404. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  22405. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  22406. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  22407. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  22408. this.faces.push( new THREE.Face3( a, b, d ) );
  22409. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22410. this.faces.push( new THREE.Face3( b, c, d ) );
  22411. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22412. }
  22413. }
  22414. this.computeFaceNormals();
  22415. this.computeVertexNormals();
  22416. function getPos( u, in_q, in_p, radius, heightScale ) {
  22417. var cu = Math.cos( u );
  22418. var su = Math.sin( u );
  22419. var quOverP = in_q / in_p * u;
  22420. var cs = Math.cos( quOverP );
  22421. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  22422. var ty = radius * ( 2 + cs ) * su * 0.5;
  22423. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  22424. return new THREE.Vector3( tx, ty, tz );
  22425. }
  22426. };
  22427. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22428. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22429. // File:src/extras/geometries/TubeGeometry.js
  22430. /**
  22431. * @author WestLangley / https://github.com/WestLangley
  22432. * @author zz85 / https://github.com/zz85
  22433. * @author miningold / https://github.com/miningold
  22434. * @author jonobr1 / https://github.com/jonobr1
  22435. *
  22436. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22437. *
  22438. * Creates a tube which extrudes along a 3d spline
  22439. *
  22440. * Uses parallel transport frames as described in
  22441. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22442. */
  22443. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22444. THREE.Geometry.call( this );
  22445. this.type = 'TubeGeometry';
  22446. this.parameters = {
  22447. path: path,
  22448. segments: segments,
  22449. radius: radius,
  22450. radialSegments: radialSegments,
  22451. closed: closed,
  22452. taper: taper
  22453. };
  22454. segments = segments || 64;
  22455. radius = radius || 1;
  22456. radialSegments = radialSegments || 8;
  22457. closed = closed || false;
  22458. taper = taper || THREE.TubeGeometry.NoTaper;
  22459. var grid = [];
  22460. var scope = this,
  22461. tangent,
  22462. normal,
  22463. binormal,
  22464. numpoints = segments + 1,
  22465. u, v, r,
  22466. cx, cy,
  22467. pos, pos2 = new THREE.Vector3(),
  22468. i, j,
  22469. ip, jp,
  22470. a, b, c, d,
  22471. uva, uvb, uvc, uvd;
  22472. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22473. tangents = frames.tangents,
  22474. normals = frames.normals,
  22475. binormals = frames.binormals;
  22476. // proxy internals
  22477. this.tangents = tangents;
  22478. this.normals = normals;
  22479. this.binormals = binormals;
  22480. function vert( x, y, z ) {
  22481. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22482. }
  22483. // construct the grid
  22484. for ( i = 0; i < numpoints; i ++ ) {
  22485. grid[ i ] = [];
  22486. u = i / ( numpoints - 1 );
  22487. pos = path.getPointAt( u );
  22488. tangent = tangents[ i ];
  22489. normal = normals[ i ];
  22490. binormal = binormals[ i ];
  22491. r = radius * taper( u );
  22492. for ( j = 0; j < radialSegments; j ++ ) {
  22493. v = j / radialSegments * 2 * Math.PI;
  22494. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22495. cy = r * Math.sin( v );
  22496. pos2.copy( pos );
  22497. pos2.x += cx * normal.x + cy * binormal.x;
  22498. pos2.y += cx * normal.y + cy * binormal.y;
  22499. pos2.z += cx * normal.z + cy * binormal.z;
  22500. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22501. }
  22502. }
  22503. // construct the mesh
  22504. for ( i = 0; i < segments; i ++ ) {
  22505. for ( j = 0; j < radialSegments; j ++ ) {
  22506. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22507. jp = ( j + 1 ) % radialSegments;
  22508. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22509. b = grid[ ip ][ j ];
  22510. c = grid[ ip ][ jp ];
  22511. d = grid[ i ][ jp ];
  22512. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22513. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22514. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22515. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  22516. this.faces.push( new THREE.Face3( a, b, d ) );
  22517. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22518. this.faces.push( new THREE.Face3( b, c, d ) );
  22519. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22520. }
  22521. }
  22522. this.computeFaceNormals();
  22523. this.computeVertexNormals();
  22524. };
  22525. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22526. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  22527. THREE.TubeGeometry.NoTaper = function ( u ) {
  22528. return 1;
  22529. };
  22530. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  22531. return Math.sin( Math.PI * u );
  22532. };
  22533. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  22534. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  22535. var normal = new THREE.Vector3(),
  22536. tangents = [],
  22537. normals = [],
  22538. binormals = [],
  22539. vec = new THREE.Vector3(),
  22540. mat = new THREE.Matrix4(),
  22541. numpoints = segments + 1,
  22542. theta,
  22543. smallest,
  22544. tx, ty, tz,
  22545. i, u;
  22546. // expose internals
  22547. this.tangents = tangents;
  22548. this.normals = normals;
  22549. this.binormals = binormals;
  22550. // compute the tangent vectors for each segment on the path
  22551. for ( i = 0; i < numpoints; i ++ ) {
  22552. u = i / ( numpoints - 1 );
  22553. tangents[ i ] = path.getTangentAt( u );
  22554. tangents[ i ].normalize();
  22555. }
  22556. initialNormal3();
  22557. /*
  22558. function initialNormal1(lastBinormal) {
  22559. // fixed start binormal. Has dangers of 0 vectors
  22560. normals[ 0 ] = new THREE.Vector3();
  22561. binormals[ 0 ] = new THREE.Vector3();
  22562. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  22563. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  22564. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22565. }
  22566. function initialNormal2() {
  22567. // This uses the Frenet-Serret formula for deriving binormal
  22568. var t2 = path.getTangentAt( epsilon );
  22569. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  22570. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  22571. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  22572. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22573. }
  22574. */
  22575. function initialNormal3() {
  22576. // select an initial normal vector perpendicular to the first tangent vector,
  22577. // and in the direction of the smallest tangent xyz component
  22578. normals[ 0 ] = new THREE.Vector3();
  22579. binormals[ 0 ] = new THREE.Vector3();
  22580. smallest = Number.MAX_VALUE;
  22581. tx = Math.abs( tangents[ 0 ].x );
  22582. ty = Math.abs( tangents[ 0 ].y );
  22583. tz = Math.abs( tangents[ 0 ].z );
  22584. if ( tx <= smallest ) {
  22585. smallest = tx;
  22586. normal.set( 1, 0, 0 );
  22587. }
  22588. if ( ty <= smallest ) {
  22589. smallest = ty;
  22590. normal.set( 0, 1, 0 );
  22591. }
  22592. if ( tz <= smallest ) {
  22593. normal.set( 0, 0, 1 );
  22594. }
  22595. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22596. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22597. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22598. }
  22599. // compute the slowly-varying normal and binormal vectors for each segment on the path
  22600. for ( i = 1; i < numpoints; i ++ ) {
  22601. normals[ i ] = normals[ i - 1 ].clone();
  22602. binormals[ i ] = binormals[ i - 1 ].clone();
  22603. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22604. if ( vec.length() > Number.EPSILON ) {
  22605. vec.normalize();
  22606. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22607. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22608. }
  22609. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22610. }
  22611. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22612. if ( closed ) {
  22613. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  22614. theta /= ( numpoints - 1 );
  22615. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  22616. theta = - theta;
  22617. }
  22618. for ( i = 1; i < numpoints; i ++ ) {
  22619. // twist a little...
  22620. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22621. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22622. }
  22623. }
  22624. };
  22625. // File:src/extras/geometries/PolyhedronGeometry.js
  22626. /**
  22627. * @author clockworkgeek / https://github.com/clockworkgeek
  22628. * @author timothypratley / https://github.com/timothypratley
  22629. * @author WestLangley / http://github.com/WestLangley
  22630. */
  22631. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  22632. THREE.Geometry.call( this );
  22633. this.type = 'PolyhedronGeometry';
  22634. this.parameters = {
  22635. vertices: vertices,
  22636. indices: indices,
  22637. radius: radius,
  22638. detail: detail
  22639. };
  22640. radius = radius || 1;
  22641. detail = detail || 0;
  22642. var that = this;
  22643. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  22644. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  22645. }
  22646. var p = this.vertices;
  22647. var faces = [];
  22648. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  22649. var v1 = p[ indices[ i ] ];
  22650. var v2 = p[ indices[ i + 1 ] ];
  22651. var v3 = p[ indices[ i + 2 ] ];
  22652. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  22653. }
  22654. var centroid = new THREE.Vector3();
  22655. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22656. subdivide( faces[ i ], detail );
  22657. }
  22658. // Handle case when face straddles the seam
  22659. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  22660. var uvs = this.faceVertexUvs[ 0 ][ i ];
  22661. var x0 = uvs[ 0 ].x;
  22662. var x1 = uvs[ 1 ].x;
  22663. var x2 = uvs[ 2 ].x;
  22664. var max = Math.max( x0, x1, x2 );
  22665. var min = Math.min( x0, x1, x2 );
  22666. if ( max > 0.9 && min < 0.1 ) {
  22667. // 0.9 is somewhat arbitrary
  22668. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  22669. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  22670. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  22671. }
  22672. }
  22673. // Apply radius
  22674. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  22675. this.vertices[ i ].multiplyScalar( radius );
  22676. }
  22677. // Merge vertices
  22678. this.mergeVertices();
  22679. this.computeFaceNormals();
  22680. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22681. // Project vector onto sphere's surface
  22682. function prepare( vector ) {
  22683. var vertex = vector.normalize().clone();
  22684. vertex.index = that.vertices.push( vertex ) - 1;
  22685. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  22686. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  22687. var v = inclination( vector ) / Math.PI + 0.5;
  22688. vertex.uv = new THREE.Vector2( u, 1 - v );
  22689. return vertex;
  22690. }
  22691. // Approximate a curved face with recursively sub-divided triangles.
  22692. function make( v1, v2, v3, materialIndex ) {
  22693. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  22694. that.faces.push( face );
  22695. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  22696. var azi = azimuth( centroid );
  22697. that.faceVertexUvs[ 0 ].push( [
  22698. correctUV( v1.uv, v1, azi ),
  22699. correctUV( v2.uv, v2, azi ),
  22700. correctUV( v3.uv, v3, azi )
  22701. ] );
  22702. }
  22703. // Analytically subdivide a face to the required detail level.
  22704. function subdivide( face, detail ) {
  22705. var cols = Math.pow( 2, detail );
  22706. var a = prepare( that.vertices[ face.a ] );
  22707. var b = prepare( that.vertices[ face.b ] );
  22708. var c = prepare( that.vertices[ face.c ] );
  22709. var v = [];
  22710. var materialIndex = face.materialIndex;
  22711. // Construct all of the vertices for this subdivision.
  22712. for ( var i = 0 ; i <= cols; i ++ ) {
  22713. v[ i ] = [];
  22714. var aj = prepare( a.clone().lerp( c, i / cols ) );
  22715. var bj = prepare( b.clone().lerp( c, i / cols ) );
  22716. var rows = cols - i;
  22717. for ( var j = 0; j <= rows; j ++ ) {
  22718. if ( j === 0 && i === cols ) {
  22719. v[ i ][ j ] = aj;
  22720. } else {
  22721. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  22722. }
  22723. }
  22724. }
  22725. // Construct all of the faces.
  22726. for ( var i = 0; i < cols ; i ++ ) {
  22727. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  22728. var k = Math.floor( j / 2 );
  22729. if ( j % 2 === 0 ) {
  22730. make(
  22731. v[ i ][ k + 1 ],
  22732. v[ i + 1 ][ k ],
  22733. v[ i ][ k ],
  22734. materialIndex
  22735. );
  22736. } else {
  22737. make(
  22738. v[ i ][ k + 1 ],
  22739. v[ i + 1 ][ k + 1 ],
  22740. v[ i + 1 ][ k ],
  22741. materialIndex
  22742. );
  22743. }
  22744. }
  22745. }
  22746. }
  22747. // Angle around the Y axis, counter-clockwise when looking from above.
  22748. function azimuth( vector ) {
  22749. return Math.atan2( vector.z, - vector.x );
  22750. }
  22751. // Angle above the XZ plane.
  22752. function inclination( vector ) {
  22753. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  22754. }
  22755. // Texture fixing helper. Spheres have some odd behaviours.
  22756. function correctUV( uv, vector, azimuth ) {
  22757. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  22758. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  22759. return uv.clone();
  22760. }
  22761. };
  22762. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22763. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  22764. // File:src/extras/geometries/DodecahedronGeometry.js
  22765. /**
  22766. * @author Abe Pazos / https://hamoid.com
  22767. */
  22768. THREE.DodecahedronGeometry = function ( radius, detail ) {
  22769. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  22770. var r = 1 / t;
  22771. var vertices = [
  22772. // (±1, ±1, ±1)
  22773. - 1, - 1, - 1, - 1, - 1, 1,
  22774. - 1, 1, - 1, - 1, 1, 1,
  22775. 1, - 1, - 1, 1, - 1, 1,
  22776. 1, 1, - 1, 1, 1, 1,
  22777. // (0, ±1/φ, ±φ)
  22778. 0, - r, - t, 0, - r, t,
  22779. 0, r, - t, 0, r, t,
  22780. // (±1/φ, ±φ, 0)
  22781. - r, - t, 0, - r, t, 0,
  22782. r, - t, 0, r, t, 0,
  22783. // (±φ, 0, ±1/φ)
  22784. - t, 0, - r, t, 0, - r,
  22785. - t, 0, r, t, 0, r
  22786. ];
  22787. var indices = [
  22788. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  22789. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  22790. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  22791. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  22792. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  22793. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  22794. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  22795. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  22796. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  22797. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  22798. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  22799. 1, 12, 14, 1, 14, 5, 1, 5, 9
  22800. ];
  22801. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22802. this.type = 'DodecahedronGeometry';
  22803. this.parameters = {
  22804. radius: radius,
  22805. detail: detail
  22806. };
  22807. };
  22808. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22809. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  22810. // File:src/extras/geometries/IcosahedronGeometry.js
  22811. /**
  22812. * @author timothypratley / https://github.com/timothypratley
  22813. */
  22814. THREE.IcosahedronGeometry = function ( radius, detail ) {
  22815. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  22816. var vertices = [
  22817. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  22818. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  22819. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  22820. ];
  22821. var indices = [
  22822. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  22823. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  22824. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  22825. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  22826. ];
  22827. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22828. this.type = 'IcosahedronGeometry';
  22829. this.parameters = {
  22830. radius: radius,
  22831. detail: detail
  22832. };
  22833. };
  22834. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22835. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  22836. // File:src/extras/geometries/OctahedronGeometry.js
  22837. /**
  22838. * @author timothypratley / https://github.com/timothypratley
  22839. */
  22840. THREE.OctahedronGeometry = function ( radius, detail ) {
  22841. var vertices = [
  22842. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  22843. ];
  22844. var indices = [
  22845. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  22846. ];
  22847. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22848. this.type = 'OctahedronGeometry';
  22849. this.parameters = {
  22850. radius: radius,
  22851. detail: detail
  22852. };
  22853. };
  22854. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22855. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  22856. // File:src/extras/geometries/TetrahedronGeometry.js
  22857. /**
  22858. * @author timothypratley / https://github.com/timothypratley
  22859. */
  22860. THREE.TetrahedronGeometry = function ( radius, detail ) {
  22861. var vertices = [
  22862. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  22863. ];
  22864. var indices = [
  22865. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  22866. ];
  22867. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22868. this.type = 'TetrahedronGeometry';
  22869. this.parameters = {
  22870. radius: radius,
  22871. detail: detail
  22872. };
  22873. };
  22874. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22875. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  22876. // File:src/extras/geometries/ParametricGeometry.js
  22877. /**
  22878. * @author zz85 / https://github.com/zz85
  22879. * Parametric Surfaces Geometry
  22880. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  22881. *
  22882. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  22883. *
  22884. */
  22885. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  22886. THREE.Geometry.call( this );
  22887. this.type = 'ParametricGeometry';
  22888. this.parameters = {
  22889. func: func,
  22890. slices: slices,
  22891. stacks: stacks
  22892. };
  22893. var verts = this.vertices;
  22894. var faces = this.faces;
  22895. var uvs = this.faceVertexUvs[ 0 ];
  22896. var i, j, p;
  22897. var u, v;
  22898. var sliceCount = slices + 1;
  22899. for ( i = 0; i <= stacks; i ++ ) {
  22900. v = i / stacks;
  22901. for ( j = 0; j <= slices; j ++ ) {
  22902. u = j / slices;
  22903. p = func( u, v );
  22904. verts.push( p );
  22905. }
  22906. }
  22907. var a, b, c, d;
  22908. var uva, uvb, uvc, uvd;
  22909. for ( i = 0; i < stacks; i ++ ) {
  22910. for ( j = 0; j < slices; j ++ ) {
  22911. a = i * sliceCount + j;
  22912. b = i * sliceCount + j + 1;
  22913. c = ( i + 1 ) * sliceCount + j + 1;
  22914. d = ( i + 1 ) * sliceCount + j;
  22915. uva = new THREE.Vector2( j / slices, i / stacks );
  22916. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  22917. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  22918. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  22919. faces.push( new THREE.Face3( a, b, d ) );
  22920. uvs.push( [ uva, uvb, uvd ] );
  22921. faces.push( new THREE.Face3( b, c, d ) );
  22922. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  22923. }
  22924. }
  22925. // console.log(this);
  22926. // magic bullet
  22927. // var diff = this.mergeVertices();
  22928. // console.log('removed ', diff, ' vertices by merging');
  22929. this.computeFaceNormals();
  22930. this.computeVertexNormals();
  22931. };
  22932. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22933. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  22934. // File:src/extras/geometries/WireframeGeometry.js
  22935. /**
  22936. * @author mrdoob / http://mrdoob.com/
  22937. */
  22938. THREE.WireframeGeometry = function ( geometry ) {
  22939. THREE.BufferGeometry.call( this );
  22940. var edge = [ 0, 0 ], hash = {};
  22941. function sortFunction( a, b ) {
  22942. return a - b;
  22943. }
  22944. var keys = [ 'a', 'b', 'c' ];
  22945. if ( geometry instanceof THREE.Geometry ) {
  22946. var vertices = geometry.vertices;
  22947. var faces = geometry.faces;
  22948. var numEdges = 0;
  22949. // allocate maximal size
  22950. var edges = new Uint32Array( 6 * faces.length );
  22951. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22952. var face = faces[ i ];
  22953. for ( var j = 0; j < 3; j ++ ) {
  22954. edge[ 0 ] = face[ keys[ j ] ];
  22955. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22956. edge.sort( sortFunction );
  22957. var key = edge.toString();
  22958. if ( hash[ key ] === undefined ) {
  22959. edges[ 2 * numEdges ] = edge[ 0 ];
  22960. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  22961. hash[ key ] = true;
  22962. numEdges ++;
  22963. }
  22964. }
  22965. }
  22966. var coords = new Float32Array( numEdges * 2 * 3 );
  22967. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  22968. for ( var j = 0; j < 2; j ++ ) {
  22969. var vertex = vertices[ edges [ 2 * i + j ] ];
  22970. var index = 6 * i + 3 * j;
  22971. coords[ index + 0 ] = vertex.x;
  22972. coords[ index + 1 ] = vertex.y;
  22973. coords[ index + 2 ] = vertex.z;
  22974. }
  22975. }
  22976. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22977. } else if ( geometry instanceof THREE.BufferGeometry ) {
  22978. if ( geometry.index !== null ) {
  22979. // Indexed BufferGeometry
  22980. var indices = geometry.index.array;
  22981. var vertices = geometry.attributes.position;
  22982. var groups = geometry.groups;
  22983. var numEdges = 0;
  22984. if ( groups.length === 0 ) {
  22985. geometry.addGroup( 0, indices.length );
  22986. }
  22987. // allocate maximal size
  22988. var edges = new Uint32Array( 2 * indices.length );
  22989. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  22990. var group = groups[ o ];
  22991. var start = group.start;
  22992. var count = group.count;
  22993. for ( var i = start, il = start + count; i < il; i += 3 ) {
  22994. for ( var j = 0; j < 3; j ++ ) {
  22995. edge[ 0 ] = indices[ i + j ];
  22996. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  22997. edge.sort( sortFunction );
  22998. var key = edge.toString();
  22999. if ( hash[ key ] === undefined ) {
  23000. edges[ 2 * numEdges ] = edge[ 0 ];
  23001. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23002. hash[ key ] = true;
  23003. numEdges ++;
  23004. }
  23005. }
  23006. }
  23007. }
  23008. var coords = new Float32Array( numEdges * 2 * 3 );
  23009. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23010. for ( var j = 0; j < 2; j ++ ) {
  23011. var index = 6 * i + 3 * j;
  23012. var index2 = edges[ 2 * i + j ];
  23013. coords[ index + 0 ] = vertices.getX( index2 );
  23014. coords[ index + 1 ] = vertices.getY( index2 );
  23015. coords[ index + 2 ] = vertices.getZ( index2 );
  23016. }
  23017. }
  23018. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23019. } else {
  23020. // non-indexed BufferGeometry
  23021. var vertices = geometry.attributes.position.array;
  23022. var numEdges = vertices.length / 3;
  23023. var numTris = numEdges / 3;
  23024. var coords = new Float32Array( numEdges * 2 * 3 );
  23025. for ( var i = 0, l = numTris; i < l; i ++ ) {
  23026. for ( var j = 0; j < 3; j ++ ) {
  23027. var index = 18 * i + 6 * j;
  23028. var index1 = 9 * i + 3 * j;
  23029. coords[ index + 0 ] = vertices[ index1 ];
  23030. coords[ index + 1 ] = vertices[ index1 + 1 ];
  23031. coords[ index + 2 ] = vertices[ index1 + 2 ];
  23032. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  23033. coords[ index + 3 ] = vertices[ index2 ];
  23034. coords[ index + 4 ] = vertices[ index2 + 1 ];
  23035. coords[ index + 5 ] = vertices[ index2 + 2 ];
  23036. }
  23037. }
  23038. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23039. }
  23040. }
  23041. };
  23042. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23043. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  23044. // File:src/extras/helpers/AxisHelper.js
  23045. /**
  23046. * @author sroucheray / http://sroucheray.org/
  23047. * @author mrdoob / http://mrdoob.com/
  23048. */
  23049. THREE.AxisHelper = function ( size ) {
  23050. size = size || 1;
  23051. var vertices = new Float32Array( [
  23052. 0, 0, 0, size, 0, 0,
  23053. 0, 0, 0, 0, size, 0,
  23054. 0, 0, 0, 0, 0, size
  23055. ] );
  23056. var colors = new Float32Array( [
  23057. 1, 0, 0, 1, 0.6, 0,
  23058. 0, 1, 0, 0.6, 1, 0,
  23059. 0, 0, 1, 0, 0.6, 1
  23060. ] );
  23061. var geometry = new THREE.BufferGeometry();
  23062. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23063. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  23064. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23065. THREE.LineSegments.call( this, geometry, material );
  23066. };
  23067. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23068. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  23069. // File:src/extras/helpers/ArrowHelper.js
  23070. /**
  23071. * @author WestLangley / http://github.com/WestLangley
  23072. * @author zz85 / http://github.com/zz85
  23073. * @author bhouston / http://clara.io
  23074. *
  23075. * Creates an arrow for visualizing directions
  23076. *
  23077. * Parameters:
  23078. * dir - Vector3
  23079. * origin - Vector3
  23080. * length - Number
  23081. * color - color in hex value
  23082. * headLength - Number
  23083. * headWidth - Number
  23084. */
  23085. THREE.ArrowHelper = ( function () {
  23086. var lineGeometry = new THREE.Geometry();
  23087. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  23088. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  23089. coneGeometry.translate( 0, - 0.5, 0 );
  23090. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  23091. // dir is assumed to be normalized
  23092. THREE.Object3D.call( this );
  23093. if ( color === undefined ) color = 0xffff00;
  23094. if ( length === undefined ) length = 1;
  23095. if ( headLength === undefined ) headLength = 0.2 * length;
  23096. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23097. this.position.copy( origin );
  23098. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  23099. this.line.matrixAutoUpdate = false;
  23100. this.add( this.line );
  23101. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  23102. this.cone.matrixAutoUpdate = false;
  23103. this.add( this.cone );
  23104. this.setDirection( dir );
  23105. this.setLength( length, headLength, headWidth );
  23106. }
  23107. }() );
  23108. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  23109. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  23110. THREE.ArrowHelper.prototype.setDirection = ( function () {
  23111. var axis = new THREE.Vector3();
  23112. var radians;
  23113. return function setDirection( dir ) {
  23114. // dir is assumed to be normalized
  23115. if ( dir.y > 0.99999 ) {
  23116. this.quaternion.set( 0, 0, 0, 1 );
  23117. } else if ( dir.y < - 0.99999 ) {
  23118. this.quaternion.set( 1, 0, 0, 0 );
  23119. } else {
  23120. axis.set( dir.z, 0, - dir.x ).normalize();
  23121. radians = Math.acos( dir.y );
  23122. this.quaternion.setFromAxisAngle( axis, radians );
  23123. }
  23124. };
  23125. }() );
  23126. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  23127. if ( headLength === undefined ) headLength = 0.2 * length;
  23128. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23129. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  23130. this.line.updateMatrix();
  23131. this.cone.scale.set( headWidth, headLength, headWidth );
  23132. this.cone.position.y = length;
  23133. this.cone.updateMatrix();
  23134. };
  23135. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  23136. this.line.material.color.set( color );
  23137. this.cone.material.color.set( color );
  23138. };
  23139. // File:src/extras/helpers/BoxHelper.js
  23140. /**
  23141. * @author mrdoob / http://mrdoob.com/
  23142. */
  23143. THREE.BoxHelper = function ( object ) {
  23144. 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 ] );
  23145. var positions = new Float32Array( 8 * 3 );
  23146. var geometry = new THREE.BufferGeometry();
  23147. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23148. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  23149. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  23150. if ( object !== undefined ) {
  23151. this.update( object );
  23152. }
  23153. };
  23154. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23155. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  23156. THREE.BoxHelper.prototype.update = ( function () {
  23157. var box = new THREE.Box3();
  23158. return function ( object ) {
  23159. box.setFromObject( object );
  23160. if ( box.empty() ) return;
  23161. var min = box.min;
  23162. var max = box.max;
  23163. /*
  23164. 5____4
  23165. 1/___0/|
  23166. | 6__|_7
  23167. 2/___3/
  23168. 0: max.x, max.y, max.z
  23169. 1: min.x, max.y, max.z
  23170. 2: min.x, min.y, max.z
  23171. 3: max.x, min.y, max.z
  23172. 4: max.x, max.y, min.z
  23173. 5: min.x, max.y, min.z
  23174. 6: min.x, min.y, min.z
  23175. 7: max.x, min.y, min.z
  23176. */
  23177. var position = this.geometry.attributes.position;
  23178. var array = position.array;
  23179. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  23180. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  23181. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  23182. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  23183. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  23184. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  23185. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  23186. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  23187. position.needsUpdate = true;
  23188. this.geometry.computeBoundingSphere();
  23189. }
  23190. } )();
  23191. // File:src/extras/helpers/BoundingBoxHelper.js
  23192. /**
  23193. * @author WestLangley / http://github.com/WestLangley
  23194. */
  23195. // a helper to show the world-axis-aligned bounding box for an object
  23196. THREE.BoundingBoxHelper = function ( object, hex ) {
  23197. var color = ( hex !== undefined ) ? hex : 0x888888;
  23198. this.object = object;
  23199. this.box = new THREE.Box3();
  23200. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  23201. };
  23202. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  23203. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  23204. THREE.BoundingBoxHelper.prototype.update = function () {
  23205. this.box.setFromObject( this.object );
  23206. this.box.size( this.scale );
  23207. this.box.center( this.position );
  23208. };
  23209. // File:src/extras/helpers/CameraHelper.js
  23210. /**
  23211. * @author alteredq / http://alteredqualia.com/
  23212. *
  23213. * - shows frustum, line of sight and up of the camera
  23214. * - suitable for fast updates
  23215. * - based on frustum visualization in lightgl.js shadowmap example
  23216. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  23217. */
  23218. THREE.CameraHelper = function ( camera ) {
  23219. var geometry = new THREE.Geometry();
  23220. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  23221. var pointMap = {};
  23222. // colors
  23223. var hexFrustum = 0xffaa00;
  23224. var hexCone = 0xff0000;
  23225. var hexUp = 0x00aaff;
  23226. var hexTarget = 0xffffff;
  23227. var hexCross = 0x333333;
  23228. // near
  23229. addLine( "n1", "n2", hexFrustum );
  23230. addLine( "n2", "n4", hexFrustum );
  23231. addLine( "n4", "n3", hexFrustum );
  23232. addLine( "n3", "n1", hexFrustum );
  23233. // far
  23234. addLine( "f1", "f2", hexFrustum );
  23235. addLine( "f2", "f4", hexFrustum );
  23236. addLine( "f4", "f3", hexFrustum );
  23237. addLine( "f3", "f1", hexFrustum );
  23238. // sides
  23239. addLine( "n1", "f1", hexFrustum );
  23240. addLine( "n2", "f2", hexFrustum );
  23241. addLine( "n3", "f3", hexFrustum );
  23242. addLine( "n4", "f4", hexFrustum );
  23243. // cone
  23244. addLine( "p", "n1", hexCone );
  23245. addLine( "p", "n2", hexCone );
  23246. addLine( "p", "n3", hexCone );
  23247. addLine( "p", "n4", hexCone );
  23248. // up
  23249. addLine( "u1", "u2", hexUp );
  23250. addLine( "u2", "u3", hexUp );
  23251. addLine( "u3", "u1", hexUp );
  23252. // target
  23253. addLine( "c", "t", hexTarget );
  23254. addLine( "p", "c", hexCross );
  23255. // cross
  23256. addLine( "cn1", "cn2", hexCross );
  23257. addLine( "cn3", "cn4", hexCross );
  23258. addLine( "cf1", "cf2", hexCross );
  23259. addLine( "cf3", "cf4", hexCross );
  23260. function addLine( a, b, hex ) {
  23261. addPoint( a, hex );
  23262. addPoint( b, hex );
  23263. }
  23264. function addPoint( id, hex ) {
  23265. geometry.vertices.push( new THREE.Vector3() );
  23266. geometry.colors.push( new THREE.Color( hex ) );
  23267. if ( pointMap[ id ] === undefined ) {
  23268. pointMap[ id ] = [];
  23269. }
  23270. pointMap[ id ].push( geometry.vertices.length - 1 );
  23271. }
  23272. THREE.LineSegments.call( this, geometry, material );
  23273. this.camera = camera;
  23274. this.camera.updateProjectionMatrix();
  23275. this.matrix = camera.matrixWorld;
  23276. this.matrixAutoUpdate = false;
  23277. this.pointMap = pointMap;
  23278. this.update();
  23279. };
  23280. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23281. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23282. THREE.CameraHelper.prototype.update = function () {
  23283. var geometry, pointMap;
  23284. var vector = new THREE.Vector3();
  23285. var camera = new THREE.Camera();
  23286. function setPoint( point, x, y, z ) {
  23287. vector.set( x, y, z ).unproject( camera );
  23288. var points = pointMap[ point ];
  23289. if ( points !== undefined ) {
  23290. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23291. geometry.vertices[ points[ i ] ].copy( vector );
  23292. }
  23293. }
  23294. }
  23295. return function () {
  23296. geometry = this.geometry;
  23297. pointMap = this.pointMap;
  23298. var w = 1, h = 1;
  23299. // we need just camera projection matrix
  23300. // world matrix must be identity
  23301. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23302. // center / target
  23303. setPoint( "c", 0, 0, - 1 );
  23304. setPoint( "t", 0, 0, 1 );
  23305. // near
  23306. setPoint( "n1", - w, - h, - 1 );
  23307. setPoint( "n2", w, - h, - 1 );
  23308. setPoint( "n3", - w, h, - 1 );
  23309. setPoint( "n4", w, h, - 1 );
  23310. // far
  23311. setPoint( "f1", - w, - h, 1 );
  23312. setPoint( "f2", w, - h, 1 );
  23313. setPoint( "f3", - w, h, 1 );
  23314. setPoint( "f4", w, h, 1 );
  23315. // up
  23316. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23317. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23318. setPoint( "u3", 0, h * 2, - 1 );
  23319. // cross
  23320. setPoint( "cf1", - w, 0, 1 );
  23321. setPoint( "cf2", w, 0, 1 );
  23322. setPoint( "cf3", 0, - h, 1 );
  23323. setPoint( "cf4", 0, h, 1 );
  23324. setPoint( "cn1", - w, 0, - 1 );
  23325. setPoint( "cn2", w, 0, - 1 );
  23326. setPoint( "cn3", 0, - h, - 1 );
  23327. setPoint( "cn4", 0, h, - 1 );
  23328. geometry.verticesNeedUpdate = true;
  23329. };
  23330. }();
  23331. // File:src/extras/helpers/DirectionalLightHelper.js
  23332. /**
  23333. * @author alteredq / http://alteredqualia.com/
  23334. * @author mrdoob / http://mrdoob.com/
  23335. * @author WestLangley / http://github.com/WestLangley
  23336. */
  23337. THREE.DirectionalLightHelper = function ( light, size ) {
  23338. THREE.Object3D.call( this );
  23339. this.light = light;
  23340. this.light.updateMatrixWorld();
  23341. this.matrix = light.matrixWorld;
  23342. this.matrixAutoUpdate = false;
  23343. size = size || 1;
  23344. var geometry = new THREE.Geometry();
  23345. geometry.vertices.push(
  23346. new THREE.Vector3( - size, size, 0 ),
  23347. new THREE.Vector3( size, size, 0 ),
  23348. new THREE.Vector3( size, - size, 0 ),
  23349. new THREE.Vector3( - size, - size, 0 ),
  23350. new THREE.Vector3( - size, size, 0 )
  23351. );
  23352. var material = new THREE.LineBasicMaterial( { fog: false } );
  23353. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23354. this.lightPlane = new THREE.Line( geometry, material );
  23355. this.add( this.lightPlane );
  23356. geometry = new THREE.Geometry();
  23357. geometry.vertices.push(
  23358. new THREE.Vector3(),
  23359. new THREE.Vector3()
  23360. );
  23361. material = new THREE.LineBasicMaterial( { fog: false } );
  23362. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23363. this.targetLine = new THREE.Line( geometry, material );
  23364. this.add( this.targetLine );
  23365. this.update();
  23366. };
  23367. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23368. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23369. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23370. this.lightPlane.geometry.dispose();
  23371. this.lightPlane.material.dispose();
  23372. this.targetLine.geometry.dispose();
  23373. this.targetLine.material.dispose();
  23374. };
  23375. THREE.DirectionalLightHelper.prototype.update = function () {
  23376. var v1 = new THREE.Vector3();
  23377. var v2 = new THREE.Vector3();
  23378. var v3 = new THREE.Vector3();
  23379. return function () {
  23380. v1.setFromMatrixPosition( this.light.matrixWorld );
  23381. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23382. v3.subVectors( v2, v1 );
  23383. this.lightPlane.lookAt( v3 );
  23384. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23385. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23386. this.targetLine.geometry.verticesNeedUpdate = true;
  23387. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23388. };
  23389. }();
  23390. // File:src/extras/helpers/EdgesHelper.js
  23391. /**
  23392. * @author WestLangley / http://github.com/WestLangley
  23393. * @param object THREE.Mesh whose geometry will be used
  23394. * @param hex line color
  23395. * @param thresholdAngle the minimum angle (in degrees),
  23396. * between the face normals of adjacent faces,
  23397. * that is required to render an edge. A value of 10 means
  23398. * an edge is only rendered if the angle is at least 10 degrees.
  23399. */
  23400. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23401. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23402. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23403. this.matrix = object.matrixWorld;
  23404. this.matrixAutoUpdate = false;
  23405. };
  23406. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23407. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23408. // File:src/extras/helpers/FaceNormalsHelper.js
  23409. /**
  23410. * @author mrdoob / http://mrdoob.com/
  23411. * @author WestLangley / http://github.com/WestLangley
  23412. */
  23413. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23414. // FaceNormalsHelper only supports THREE.Geometry
  23415. this.object = object;
  23416. this.size = ( size !== undefined ) ? size : 1;
  23417. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23418. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23419. //
  23420. var nNormals = 0;
  23421. var objGeometry = this.object.geometry;
  23422. if ( objGeometry instanceof THREE.Geometry ) {
  23423. nNormals = objGeometry.faces.length;
  23424. } else {
  23425. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23426. }
  23427. //
  23428. var geometry = new THREE.BufferGeometry();
  23429. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23430. geometry.addAttribute( 'position', positions );
  23431. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23432. //
  23433. this.matrixAutoUpdate = false;
  23434. this.update();
  23435. };
  23436. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23437. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23438. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23439. var v1 = new THREE.Vector3();
  23440. var v2 = new THREE.Vector3();
  23441. var normalMatrix = new THREE.Matrix3();
  23442. return function update() {
  23443. this.object.updateMatrixWorld( true );
  23444. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23445. var matrixWorld = this.object.matrixWorld;
  23446. var position = this.geometry.attributes.position;
  23447. //
  23448. var objGeometry = this.object.geometry;
  23449. var vertices = objGeometry.vertices;
  23450. var faces = objGeometry.faces;
  23451. var idx = 0;
  23452. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23453. var face = faces[ i ];
  23454. var normal = face.normal;
  23455. v1.copy( vertices[ face.a ] )
  23456. .add( vertices[ face.b ] )
  23457. .add( vertices[ face.c ] )
  23458. .divideScalar( 3 )
  23459. .applyMatrix4( matrixWorld );
  23460. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23461. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23462. idx = idx + 1;
  23463. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23464. idx = idx + 1;
  23465. }
  23466. position.needsUpdate = true;
  23467. return this;
  23468. }
  23469. }() );
  23470. // File:src/extras/helpers/GridHelper.js
  23471. /**
  23472. * @author mrdoob / http://mrdoob.com/
  23473. */
  23474. THREE.GridHelper = function ( size, step ) {
  23475. var geometry = new THREE.Geometry();
  23476. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23477. this.color1 = new THREE.Color( 0x444444 );
  23478. this.color2 = new THREE.Color( 0x888888 );
  23479. for ( var i = - size; i <= size; i += step ) {
  23480. geometry.vertices.push(
  23481. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23482. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23483. );
  23484. var color = i === 0 ? this.color1 : this.color2;
  23485. geometry.colors.push( color, color, color, color );
  23486. }
  23487. THREE.LineSegments.call( this, geometry, material );
  23488. };
  23489. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23490. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23491. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23492. this.color1.set( colorCenterLine );
  23493. this.color2.set( colorGrid );
  23494. this.geometry.colorsNeedUpdate = true;
  23495. };
  23496. // File:src/extras/helpers/HemisphereLightHelper.js
  23497. /**
  23498. * @author alteredq / http://alteredqualia.com/
  23499. * @author mrdoob / http://mrdoob.com/
  23500. */
  23501. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23502. THREE.Object3D.call( this );
  23503. this.light = light;
  23504. this.light.updateMatrixWorld();
  23505. this.matrix = light.matrixWorld;
  23506. this.matrixAutoUpdate = false;
  23507. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23508. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23509. geometry.rotateX( - Math.PI / 2 );
  23510. for ( var i = 0, il = 8; i < il; i ++ ) {
  23511. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23512. }
  23513. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23514. this.lightSphere = new THREE.Mesh( geometry, material );
  23515. this.add( this.lightSphere );
  23516. this.update();
  23517. };
  23518. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23519. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  23520. THREE.HemisphereLightHelper.prototype.dispose = function () {
  23521. this.lightSphere.geometry.dispose();
  23522. this.lightSphere.material.dispose();
  23523. };
  23524. THREE.HemisphereLightHelper.prototype.update = function () {
  23525. var vector = new THREE.Vector3();
  23526. return function () {
  23527. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  23528. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  23529. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  23530. this.lightSphere.geometry.colorsNeedUpdate = true;
  23531. }
  23532. }();
  23533. // File:src/extras/helpers/PointLightHelper.js
  23534. /**
  23535. * @author alteredq / http://alteredqualia.com/
  23536. * @author mrdoob / http://mrdoob.com/
  23537. */
  23538. THREE.PointLightHelper = function ( light, sphereSize ) {
  23539. this.light = light;
  23540. this.light.updateMatrixWorld();
  23541. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23542. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23543. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23544. THREE.Mesh.call( this, geometry, material );
  23545. this.matrix = this.light.matrixWorld;
  23546. this.matrixAutoUpdate = false;
  23547. /*
  23548. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  23549. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  23550. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  23551. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  23552. var d = light.distance;
  23553. if ( d === 0.0 ) {
  23554. this.lightDistance.visible = false;
  23555. } else {
  23556. this.lightDistance.scale.set( d, d, d );
  23557. }
  23558. this.add( this.lightDistance );
  23559. */
  23560. };
  23561. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  23562. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  23563. THREE.PointLightHelper.prototype.dispose = function () {
  23564. this.geometry.dispose();
  23565. this.material.dispose();
  23566. };
  23567. THREE.PointLightHelper.prototype.update = function () {
  23568. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23569. /*
  23570. var d = this.light.distance;
  23571. if ( d === 0.0 ) {
  23572. this.lightDistance.visible = false;
  23573. } else {
  23574. this.lightDistance.visible = true;
  23575. this.lightDistance.scale.set( d, d, d );
  23576. }
  23577. */
  23578. };
  23579. // File:src/extras/helpers/SkeletonHelper.js
  23580. /**
  23581. * @author Sean Griffin / http://twitter.com/sgrif
  23582. * @author Michael Guerrero / http://realitymeltdown.com
  23583. * @author mrdoob / http://mrdoob.com/
  23584. * @author ikerr / http://verold.com
  23585. */
  23586. THREE.SkeletonHelper = function ( object ) {
  23587. this.bones = this.getBoneList( object );
  23588. var geometry = new THREE.Geometry();
  23589. for ( var i = 0; i < this.bones.length; i ++ ) {
  23590. var bone = this.bones[ i ];
  23591. if ( bone.parent instanceof THREE.Bone ) {
  23592. geometry.vertices.push( new THREE.Vector3() );
  23593. geometry.vertices.push( new THREE.Vector3() );
  23594. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  23595. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  23596. }
  23597. }
  23598. geometry.dynamic = true;
  23599. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  23600. THREE.LineSegments.call( this, geometry, material );
  23601. this.root = object;
  23602. this.matrix = object.matrixWorld;
  23603. this.matrixAutoUpdate = false;
  23604. this.update();
  23605. };
  23606. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23607. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  23608. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  23609. var boneList = [];
  23610. if ( object instanceof THREE.Bone ) {
  23611. boneList.push( object );
  23612. }
  23613. for ( var i = 0; i < object.children.length; i ++ ) {
  23614. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  23615. }
  23616. return boneList;
  23617. };
  23618. THREE.SkeletonHelper.prototype.update = function () {
  23619. var geometry = this.geometry;
  23620. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  23621. var boneMatrix = new THREE.Matrix4();
  23622. var j = 0;
  23623. for ( var i = 0; i < this.bones.length; i ++ ) {
  23624. var bone = this.bones[ i ];
  23625. if ( bone.parent instanceof THREE.Bone ) {
  23626. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  23627. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  23628. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  23629. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  23630. j += 2;
  23631. }
  23632. }
  23633. geometry.verticesNeedUpdate = true;
  23634. geometry.computeBoundingSphere();
  23635. };
  23636. // File:src/extras/helpers/SpotLightHelper.js
  23637. /**
  23638. * @author alteredq / http://alteredqualia.com/
  23639. * @author mrdoob / http://mrdoob.com/
  23640. * @author WestLangley / http://github.com/WestLangley
  23641. */
  23642. THREE.SpotLightHelper = function ( light ) {
  23643. THREE.Object3D.call( this );
  23644. this.light = light;
  23645. this.light.updateMatrixWorld();
  23646. this.matrix = light.matrixWorld;
  23647. this.matrixAutoUpdate = false;
  23648. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  23649. geometry.translate( 0, - 0.5, 0 );
  23650. geometry.rotateX( - Math.PI / 2 );
  23651. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23652. this.cone = new THREE.Mesh( geometry, material );
  23653. this.add( this.cone );
  23654. this.update();
  23655. };
  23656. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23657. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  23658. THREE.SpotLightHelper.prototype.dispose = function () {
  23659. this.cone.geometry.dispose();
  23660. this.cone.material.dispose();
  23661. };
  23662. THREE.SpotLightHelper.prototype.update = function () {
  23663. var vector = new THREE.Vector3();
  23664. var vector2 = new THREE.Vector3();
  23665. return function () {
  23666. var coneLength = this.light.distance ? this.light.distance : 10000;
  23667. var coneWidth = coneLength * Math.tan( this.light.angle );
  23668. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  23669. vector.setFromMatrixPosition( this.light.matrixWorld );
  23670. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  23671. this.cone.lookAt( vector2.sub( vector ) );
  23672. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23673. };
  23674. }();
  23675. // File:src/extras/helpers/VertexNormalsHelper.js
  23676. /**
  23677. * @author mrdoob / http://mrdoob.com/
  23678. * @author WestLangley / http://github.com/WestLangley
  23679. */
  23680. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  23681. this.object = object;
  23682. this.size = ( size !== undefined ) ? size : 1;
  23683. var color = ( hex !== undefined ) ? hex : 0xff0000;
  23684. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23685. //
  23686. var nNormals = 0;
  23687. var objGeometry = this.object.geometry;
  23688. if ( objGeometry instanceof THREE.Geometry ) {
  23689. nNormals = objGeometry.faces.length * 3;
  23690. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  23691. nNormals = objGeometry.attributes.normal.count
  23692. }
  23693. //
  23694. var geometry = new THREE.BufferGeometry();
  23695. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23696. geometry.addAttribute( 'position', positions );
  23697. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23698. //
  23699. this.matrixAutoUpdate = false;
  23700. this.update();
  23701. };
  23702. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23703. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  23704. THREE.VertexNormalsHelper.prototype.update = ( function () {
  23705. var v1 = new THREE.Vector3();
  23706. var v2 = new THREE.Vector3();
  23707. var normalMatrix = new THREE.Matrix3();
  23708. return function update() {
  23709. var keys = [ 'a', 'b', 'c' ];
  23710. this.object.updateMatrixWorld( true );
  23711. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23712. var matrixWorld = this.object.matrixWorld;
  23713. var position = this.geometry.attributes.position;
  23714. //
  23715. var objGeometry = this.object.geometry;
  23716. if ( objGeometry instanceof THREE.Geometry ) {
  23717. var vertices = objGeometry.vertices;
  23718. var faces = objGeometry.faces;
  23719. var idx = 0;
  23720. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23721. var face = faces[ i ];
  23722. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  23723. var vertex = vertices[ face[ keys[ j ] ] ];
  23724. var normal = face.vertexNormals[ j ];
  23725. v1.copy( vertex ).applyMatrix4( matrixWorld );
  23726. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23727. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23728. idx = idx + 1;
  23729. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23730. idx = idx + 1;
  23731. }
  23732. }
  23733. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  23734. var objPos = objGeometry.attributes.position;
  23735. var objNorm = objGeometry.attributes.normal;
  23736. var idx = 0;
  23737. // for simplicity, ignore index and drawcalls, and render every normal
  23738. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  23739. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  23740. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  23741. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23742. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23743. idx = idx + 1;
  23744. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23745. idx = idx + 1;
  23746. }
  23747. }
  23748. position.needsUpdate = true;
  23749. return this;
  23750. }
  23751. }() );
  23752. // File:src/extras/helpers/WireframeHelper.js
  23753. /**
  23754. * @author mrdoob / http://mrdoob.com/
  23755. */
  23756. THREE.WireframeHelper = function ( object, hex ) {
  23757. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23758. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  23759. this.matrix = object.matrixWorld;
  23760. this.matrixAutoUpdate = false;
  23761. };
  23762. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23763. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  23764. // File:src/extras/objects/ImmediateRenderObject.js
  23765. /**
  23766. * @author alteredq / http://alteredqualia.com/
  23767. */
  23768. THREE.ImmediateRenderObject = function ( material ) {
  23769. THREE.Object3D.call( this );
  23770. this.material = material;
  23771. this.render = function ( renderCallback ) {};
  23772. };
  23773. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  23774. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  23775. // File:src/extras/objects/MorphBlendMesh.js
  23776. /**
  23777. * @author alteredq / http://alteredqualia.com/
  23778. */
  23779. THREE.MorphBlendMesh = function( geometry, material ) {
  23780. THREE.Mesh.call( this, geometry, material );
  23781. this.animationsMap = {};
  23782. this.animationsList = [];
  23783. // prepare default animation
  23784. // (all frames played together in 1 second)
  23785. var numFrames = this.geometry.morphTargets.length;
  23786. var name = "__default";
  23787. var startFrame = 0;
  23788. var endFrame = numFrames - 1;
  23789. var fps = numFrames / 1;
  23790. this.createAnimation( name, startFrame, endFrame, fps );
  23791. this.setAnimationWeight( name, 1 );
  23792. };
  23793. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  23794. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  23795. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  23796. var animation = {
  23797. start: start,
  23798. end: end,
  23799. length: end - start + 1,
  23800. fps: fps,
  23801. duration: ( end - start ) / fps,
  23802. lastFrame: 0,
  23803. currentFrame: 0,
  23804. active: false,
  23805. time: 0,
  23806. direction: 1,
  23807. weight: 1,
  23808. directionBackwards: false,
  23809. mirroredLoop: false
  23810. };
  23811. this.animationsMap[ name ] = animation;
  23812. this.animationsList.push( animation );
  23813. };
  23814. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  23815. var pattern = /([a-z]+)_?(\d+)/i;
  23816. var firstAnimation, frameRanges = {};
  23817. var geometry = this.geometry;
  23818. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  23819. var morph = geometry.morphTargets[ i ];
  23820. var chunks = morph.name.match( pattern );
  23821. if ( chunks && chunks.length > 1 ) {
  23822. var name = chunks[ 1 ];
  23823. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  23824. var range = frameRanges[ name ];
  23825. if ( i < range.start ) range.start = i;
  23826. if ( i > range.end ) range.end = i;
  23827. if ( ! firstAnimation ) firstAnimation = name;
  23828. }
  23829. }
  23830. for ( var name in frameRanges ) {
  23831. var range = frameRanges[ name ];
  23832. this.createAnimation( name, range.start, range.end, fps );
  23833. }
  23834. this.firstAnimation = firstAnimation;
  23835. };
  23836. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  23837. var animation = this.animationsMap[ name ];
  23838. if ( animation ) {
  23839. animation.direction = 1;
  23840. animation.directionBackwards = false;
  23841. }
  23842. };
  23843. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  23844. var animation = this.animationsMap[ name ];
  23845. if ( animation ) {
  23846. animation.direction = - 1;
  23847. animation.directionBackwards = true;
  23848. }
  23849. };
  23850. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  23851. var animation = this.animationsMap[ name ];
  23852. if ( animation ) {
  23853. animation.fps = fps;
  23854. animation.duration = ( animation.end - animation.start ) / animation.fps;
  23855. }
  23856. };
  23857. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  23858. var animation = this.animationsMap[ name ];
  23859. if ( animation ) {
  23860. animation.duration = duration;
  23861. animation.fps = ( animation.end - animation.start ) / animation.duration;
  23862. }
  23863. };
  23864. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  23865. var animation = this.animationsMap[ name ];
  23866. if ( animation ) {
  23867. animation.weight = weight;
  23868. }
  23869. };
  23870. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  23871. var animation = this.animationsMap[ name ];
  23872. if ( animation ) {
  23873. animation.time = time;
  23874. }
  23875. };
  23876. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  23877. var time = 0;
  23878. var animation = this.animationsMap[ name ];
  23879. if ( animation ) {
  23880. time = animation.time;
  23881. }
  23882. return time;
  23883. };
  23884. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  23885. var duration = - 1;
  23886. var animation = this.animationsMap[ name ];
  23887. if ( animation ) {
  23888. duration = animation.duration;
  23889. }
  23890. return duration;
  23891. };
  23892. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  23893. var animation = this.animationsMap[ name ];
  23894. if ( animation ) {
  23895. animation.time = 0;
  23896. animation.active = true;
  23897. } else {
  23898. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  23899. }
  23900. };
  23901. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  23902. var animation = this.animationsMap[ name ];
  23903. if ( animation ) {
  23904. animation.active = false;
  23905. }
  23906. };
  23907. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  23908. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  23909. var animation = this.animationsList[ i ];
  23910. if ( ! animation.active ) continue;
  23911. var frameTime = animation.duration / animation.length;
  23912. animation.time += animation.direction * delta;
  23913. if ( animation.mirroredLoop ) {
  23914. if ( animation.time > animation.duration || animation.time < 0 ) {
  23915. animation.direction *= - 1;
  23916. if ( animation.time > animation.duration ) {
  23917. animation.time = animation.duration;
  23918. animation.directionBackwards = true;
  23919. }
  23920. if ( animation.time < 0 ) {
  23921. animation.time = 0;
  23922. animation.directionBackwards = false;
  23923. }
  23924. }
  23925. } else {
  23926. animation.time = animation.time % animation.duration;
  23927. if ( animation.time < 0 ) animation.time += animation.duration;
  23928. }
  23929. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  23930. var weight = animation.weight;
  23931. if ( keyframe !== animation.currentFrame ) {
  23932. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  23933. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  23934. this.morphTargetInfluences[ keyframe ] = 0;
  23935. animation.lastFrame = animation.currentFrame;
  23936. animation.currentFrame = keyframe;
  23937. }
  23938. var mix = ( animation.time % frameTime ) / frameTime;
  23939. if ( animation.directionBackwards ) mix = 1 - mix;
  23940. if ( animation.currentFrame !== animation.lastFrame ) {
  23941. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  23942. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  23943. } else {
  23944. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  23945. }
  23946. }
  23947. };