three.js 818 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '73dev' };
  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. if ( Math.sign === undefined ) {
  40. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  41. Math.sign = function ( x ) {
  42. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  43. };
  44. }
  45. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  46. // Missing in IE9-11.
  47. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  48. Object.defineProperty( Function.prototype, 'name', {
  49. get: function () {
  50. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  51. }
  52. } );
  53. }
  54. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  55. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  56. // GL STATE CONSTANTS
  57. THREE.CullFaceNone = 0;
  58. THREE.CullFaceBack = 1;
  59. THREE.CullFaceFront = 2;
  60. THREE.CullFaceFrontBack = 3;
  61. THREE.FrontFaceDirectionCW = 0;
  62. THREE.FrontFaceDirectionCCW = 1;
  63. // SHADOWING TYPES
  64. THREE.BasicShadowMap = 0;
  65. THREE.PCFShadowMap = 1;
  66. THREE.PCFSoftShadowMap = 2;
  67. // MATERIAL CONSTANTS
  68. // side
  69. THREE.FrontSide = 0;
  70. THREE.BackSide = 1;
  71. THREE.DoubleSide = 2;
  72. // shading
  73. THREE.FlatShading = 1;
  74. THREE.SmoothShading = 2;
  75. // colors
  76. THREE.NoColors = 0;
  77. THREE.FaceColors = 1;
  78. THREE.VertexColors = 2;
  79. // blending modes
  80. THREE.NoBlending = 0;
  81. THREE.NormalBlending = 1;
  82. THREE.AdditiveBlending = 2;
  83. THREE.SubtractiveBlending = 3;
  84. THREE.MultiplyBlending = 4;
  85. THREE.CustomBlending = 5;
  86. // custom blending equations
  87. // (numbers start from 100 not to clash with other
  88. // mappings to OpenGL constants defined in Texture.js)
  89. THREE.AddEquation = 100;
  90. THREE.SubtractEquation = 101;
  91. THREE.ReverseSubtractEquation = 102;
  92. THREE.MinEquation = 103;
  93. THREE.MaxEquation = 104;
  94. // custom blending destination factors
  95. THREE.ZeroFactor = 200;
  96. THREE.OneFactor = 201;
  97. THREE.SrcColorFactor = 202;
  98. THREE.OneMinusSrcColorFactor = 203;
  99. THREE.SrcAlphaFactor = 204;
  100. THREE.OneMinusSrcAlphaFactor = 205;
  101. THREE.DstAlphaFactor = 206;
  102. THREE.OneMinusDstAlphaFactor = 207;
  103. // custom blending source factors
  104. //THREE.ZeroFactor = 200;
  105. //THREE.OneFactor = 201;
  106. //THREE.SrcAlphaFactor = 204;
  107. //THREE.OneMinusSrcAlphaFactor = 205;
  108. //THREE.DstAlphaFactor = 206;
  109. //THREE.OneMinusDstAlphaFactor = 207;
  110. THREE.DstColorFactor = 208;
  111. THREE.OneMinusDstColorFactor = 209;
  112. THREE.SrcAlphaSaturateFactor = 210;
  113. // depth modes
  114. THREE.NeverDepth = 0;
  115. THREE.AlwaysDepth = 1;
  116. THREE.LessDepth = 2;
  117. THREE.LessEqualDepth = 3;
  118. THREE.EqualDepth = 4;
  119. THREE.GreaterEqualDepth = 5;
  120. THREE.GreaterDepth = 6;
  121. THREE.NotEqualDepth = 7;
  122. // TEXTURE CONSTANTS
  123. THREE.MultiplyOperation = 0;
  124. THREE.MixOperation = 1;
  125. THREE.AddOperation = 2;
  126. // Mapping modes
  127. THREE.UVMapping = 300;
  128. THREE.CubeReflectionMapping = 301;
  129. THREE.CubeRefractionMapping = 302;
  130. THREE.EquirectangularReflectionMapping = 303;
  131. THREE.EquirectangularRefractionMapping = 304;
  132. THREE.SphericalReflectionMapping = 305;
  133. // Wrapping modes
  134. THREE.RepeatWrapping = 1000;
  135. THREE.ClampToEdgeWrapping = 1001;
  136. THREE.MirroredRepeatWrapping = 1002;
  137. // Filters
  138. THREE.NearestFilter = 1003;
  139. THREE.NearestMipMapNearestFilter = 1004;
  140. THREE.NearestMipMapLinearFilter = 1005;
  141. THREE.LinearFilter = 1006;
  142. THREE.LinearMipMapNearestFilter = 1007;
  143. THREE.LinearMipMapLinearFilter = 1008;
  144. // Data types
  145. THREE.UnsignedByteType = 1009;
  146. THREE.ByteType = 1010;
  147. THREE.ShortType = 1011;
  148. THREE.UnsignedShortType = 1012;
  149. THREE.IntType = 1013;
  150. THREE.UnsignedIntType = 1014;
  151. THREE.FloatType = 1015;
  152. THREE.HalfFloatType = 1025;
  153. // Pixel types
  154. //THREE.UnsignedByteType = 1009;
  155. THREE.UnsignedShort4444Type = 1016;
  156. THREE.UnsignedShort5551Type = 1017;
  157. THREE.UnsignedShort565Type = 1018;
  158. // Pixel formats
  159. THREE.AlphaFormat = 1019;
  160. THREE.RGBFormat = 1020;
  161. THREE.RGBAFormat = 1021;
  162. THREE.LuminanceFormat = 1022;
  163. THREE.LuminanceAlphaFormat = 1023;
  164. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  165. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  166. // DDS / ST3C Compressed texture formats
  167. THREE.RGB_S3TC_DXT1_Format = 2001;
  168. THREE.RGBA_S3TC_DXT1_Format = 2002;
  169. THREE.RGBA_S3TC_DXT3_Format = 2003;
  170. THREE.RGBA_S3TC_DXT5_Format = 2004;
  171. // PVRTC compressed texture formats
  172. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  173. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  174. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  175. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  176. // Loop styles for AnimationAction
  177. THREE.LoopOnce = 2200;
  178. THREE.LoopRepeat = 2201;
  179. THREE.LoopPingPong = 2202;
  180. // DEPRECATED
  181. THREE.Projector = function () {
  182. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  183. this.projectVector = function ( vector, camera ) {
  184. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  185. vector.project( camera );
  186. };
  187. this.unprojectVector = function ( vector, camera ) {
  188. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  189. vector.unproject( camera );
  190. };
  191. this.pickingRay = function ( vector, camera ) {
  192. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  193. };
  194. };
  195. THREE.CanvasRenderer = function () {
  196. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  197. this.domElement = document.createElement( 'canvas' );
  198. this.clear = function () {};
  199. this.render = function () {};
  200. this.setClearColor = function () {};
  201. this.setSize = function () {};
  202. };
  203. // File:src/math/Color.js
  204. /**
  205. * @author mrdoob / http://mrdoob.com/
  206. */
  207. THREE.Color = function ( color ) {
  208. if ( arguments.length === 3 ) {
  209. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  210. }
  211. return this.set( color );
  212. };
  213. THREE.Color.prototype = {
  214. constructor: THREE.Color,
  215. r: 1, g: 1, b: 1,
  216. set: function ( value ) {
  217. if ( value instanceof THREE.Color ) {
  218. this.copy( value );
  219. } else if ( typeof value === 'number' ) {
  220. this.setHex( value );
  221. } else if ( typeof value === 'string' ) {
  222. this.setStyle( value );
  223. }
  224. return this;
  225. },
  226. setHex: function ( hex ) {
  227. hex = Math.floor( hex );
  228. this.r = ( hex >> 16 & 255 ) / 255;
  229. this.g = ( hex >> 8 & 255 ) / 255;
  230. this.b = ( hex & 255 ) / 255;
  231. return this;
  232. },
  233. setRGB: function ( r, g, b ) {
  234. this.r = r;
  235. this.g = g;
  236. this.b = b;
  237. return this;
  238. },
  239. setHSL: function () {
  240. function hue2rgb ( p, q, t ) {
  241. if ( t < 0 ) t += 1;
  242. if ( t > 1 ) t -= 1;
  243. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  244. if ( t < 1 / 2 ) return q;
  245. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  246. return p;
  247. }
  248. return function ( h, s, l ) {
  249. // h,s,l ranges are in 0.0 - 1.0
  250. h = THREE.Math.euclideanModulo( h, 1 );
  251. s = THREE.Math.clamp( s, 0, 1 );
  252. l = THREE.Math.clamp( l, 0, 1 );
  253. if ( s === 0 ) {
  254. this.r = this.g = this.b = l;
  255. } else {
  256. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  257. var q = ( 2 * l ) - p;
  258. this.r = hue2rgb( q, p, h + 1 / 3 );
  259. this.g = hue2rgb( q, p, h );
  260. this.b = hue2rgb( q, p, h - 1 / 3 );
  261. }
  262. return this;
  263. };
  264. }(),
  265. setStyle: function ( style ) {
  266. var parseAlpha = function ( strAlpha ) {
  267. var alpha = parseFloat( strAlpha );
  268. if ( alpha < 1 ) {
  269. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  270. }
  271. return alpha;
  272. }
  273. var m;
  274. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  275. // rgb / hsl
  276. var color;
  277. var name = m[ 1 ];
  278. var components = m[ 2 ];
  279. switch ( name ) {
  280. case 'rgb':
  281. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  282. // rgb(255,0,0)
  283. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  284. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  285. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  286. return this;
  287. }
  288. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  289. // rgb(100%,0%,0%)
  290. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  291. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  292. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  293. return this;
  294. }
  295. break;
  296. case 'rgba':
  297. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  298. // rgba(255,0,0,0.5)
  299. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  300. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  301. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  302. parseAlpha( color[ 4 ] );
  303. return this;
  304. }
  305. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  306. // rgba(100%,0%,0%,0.5)
  307. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  308. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  309. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  310. parseAlpha( color[ 4 ] );
  311. return this;
  312. }
  313. break;
  314. case 'hsl':
  315. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  316. // hsl(120,50%,50%)
  317. var h = parseFloat( color[ 1 ] );
  318. var s = parseInt( color[ 2 ], 10 ) / 100;
  319. var l = parseInt( color[ 3 ], 10 ) / 100;
  320. return this.setHSL( h, s, l );
  321. }
  322. break;
  323. case 'hsla':
  324. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  325. // hsla(120,50%,50%,0.5)
  326. var h = parseFloat( color[ 1 ] );
  327. var s = parseInt( color[ 2 ], 10 ) / 100;
  328. var l = parseInt( color[ 3 ], 10 ) / 100;
  329. parseAlpha( color[ 4 ] );
  330. return this.setHSL( h, s, l );
  331. }
  332. break;
  333. }
  334. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  335. // hex color
  336. var hex = m[ 1 ];
  337. var size = hex.length;
  338. if ( size === 3 ) {
  339. // #ff0
  340. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  341. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  342. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  343. return this;
  344. } else if ( size === 6 ) {
  345. // #ff0000
  346. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  347. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  348. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  349. return this;
  350. }
  351. }
  352. if ( style && style.length > 0 ) {
  353. // color keywords
  354. var hex = THREE.ColorKeywords[ style ];
  355. if ( hex !== undefined ) {
  356. // red
  357. this.setHex( hex );
  358. } else {
  359. // unknown color
  360. console.warn( 'THREE.Color: Unknown color ' + style );
  361. }
  362. }
  363. return this;
  364. },
  365. clone: function () {
  366. return new this.constructor( this.r, this.g, this.b );
  367. },
  368. copy: function ( color ) {
  369. this.r = color.r;
  370. this.g = color.g;
  371. this.b = color.b;
  372. return this;
  373. },
  374. copyGammaToLinear: function ( color, gammaFactor ) {
  375. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  376. this.r = Math.pow( color.r, gammaFactor );
  377. this.g = Math.pow( color.g, gammaFactor );
  378. this.b = Math.pow( color.b, gammaFactor );
  379. return this;
  380. },
  381. copyLinearToGamma: function ( color, gammaFactor ) {
  382. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  383. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  384. this.r = Math.pow( color.r, safeInverse );
  385. this.g = Math.pow( color.g, safeInverse );
  386. this.b = Math.pow( color.b, safeInverse );
  387. return this;
  388. },
  389. convertGammaToLinear: function () {
  390. var r = this.r, g = this.g, b = this.b;
  391. this.r = r * r;
  392. this.g = g * g;
  393. this.b = b * b;
  394. return this;
  395. },
  396. convertLinearToGamma: function () {
  397. this.r = Math.sqrt( this.r );
  398. this.g = Math.sqrt( this.g );
  399. this.b = Math.sqrt( this.b );
  400. return this;
  401. },
  402. getHex: function () {
  403. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  404. },
  405. getHexString: function () {
  406. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  407. },
  408. getHSL: function ( optionalTarget ) {
  409. // h,s,l ranges are in 0.0 - 1.0
  410. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  411. var r = this.r, g = this.g, b = this.b;
  412. var max = Math.max( r, g, b );
  413. var min = Math.min( r, g, b );
  414. var hue, saturation;
  415. var lightness = ( min + max ) / 2.0;
  416. if ( min === max ) {
  417. hue = 0;
  418. saturation = 0;
  419. } else {
  420. var delta = max - min;
  421. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  422. switch ( max ) {
  423. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  424. case g: hue = ( b - r ) / delta + 2; break;
  425. case b: hue = ( r - g ) / delta + 4; break;
  426. }
  427. hue /= 6;
  428. }
  429. hsl.h = hue;
  430. hsl.s = saturation;
  431. hsl.l = lightness;
  432. return hsl;
  433. },
  434. getStyle: function () {
  435. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  436. },
  437. offsetHSL: function ( h, s, l ) {
  438. var hsl = this.getHSL();
  439. hsl.h += h; hsl.s += s; hsl.l += l;
  440. this.setHSL( hsl.h, hsl.s, hsl.l );
  441. return this;
  442. },
  443. add: function ( color ) {
  444. this.r += color.r;
  445. this.g += color.g;
  446. this.b += color.b;
  447. return this;
  448. },
  449. addColors: function ( color1, color2 ) {
  450. this.r = color1.r + color2.r;
  451. this.g = color1.g + color2.g;
  452. this.b = color1.b + color2.b;
  453. return this;
  454. },
  455. addScalar: function ( s ) {
  456. this.r += s;
  457. this.g += s;
  458. this.b += s;
  459. return this;
  460. },
  461. multiply: function ( color ) {
  462. this.r *= color.r;
  463. this.g *= color.g;
  464. this.b *= color.b;
  465. return this;
  466. },
  467. multiplyScalar: function ( s ) {
  468. this.r *= s;
  469. this.g *= s;
  470. this.b *= s;
  471. return this;
  472. },
  473. lerp: function ( color, alpha ) {
  474. this.r += ( color.r - this.r ) * alpha;
  475. this.g += ( color.g - this.g ) * alpha;
  476. this.b += ( color.b - this.b ) * alpha;
  477. return this;
  478. },
  479. equals: function ( c ) {
  480. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  481. },
  482. fromArray: function ( array ) {
  483. this.r = array[ 0 ];
  484. this.g = array[ 1 ];
  485. this.b = array[ 2 ];
  486. return this;
  487. },
  488. toArray: function ( array, offset ) {
  489. if ( array === undefined ) array = [];
  490. if ( offset === undefined ) offset = 0;
  491. array[ offset ] = this.r;
  492. array[ offset + 1 ] = this.g;
  493. array[ offset + 2 ] = this.b;
  494. return array;
  495. }
  496. };
  497. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  498. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  499. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  500. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  501. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  502. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  503. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  504. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  505. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  506. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  507. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  508. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  509. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  510. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  511. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  512. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  513. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  514. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  515. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  516. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  517. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  518. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  519. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  520. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  521. // File:src/math/Quaternion.js
  522. /**
  523. * @author mikael emtinger / http://gomo.se/
  524. * @author alteredq / http://alteredqualia.com/
  525. * @author WestLangley / http://github.com/WestLangley
  526. * @author bhouston / http://clara.io
  527. */
  528. THREE.Quaternion = function ( x, y, z, w ) {
  529. this._x = x || 0;
  530. this._y = y || 0;
  531. this._z = z || 0;
  532. this._w = ( w !== undefined ) ? w : 1;
  533. };
  534. THREE.Quaternion.prototype = {
  535. constructor: THREE.Quaternion,
  536. get x () {
  537. return this._x;
  538. },
  539. set x ( value ) {
  540. this._x = value;
  541. this.onChangeCallback();
  542. },
  543. get y () {
  544. return this._y;
  545. },
  546. set y ( value ) {
  547. this._y = value;
  548. this.onChangeCallback();
  549. },
  550. get z () {
  551. return this._z;
  552. },
  553. set z ( value ) {
  554. this._z = value;
  555. this.onChangeCallback();
  556. },
  557. get w () {
  558. return this._w;
  559. },
  560. set w ( value ) {
  561. this._w = value;
  562. this.onChangeCallback();
  563. },
  564. set: function ( x, y, z, w ) {
  565. this._x = x;
  566. this._y = y;
  567. this._z = z;
  568. this._w = w;
  569. this.onChangeCallback();
  570. return this;
  571. },
  572. clone: function () {
  573. return new this.constructor( this._x, this._y, this._z, this._w );
  574. },
  575. copy: function ( quaternion ) {
  576. this._x = quaternion.x;
  577. this._y = quaternion.y;
  578. this._z = quaternion.z;
  579. this._w = quaternion.w;
  580. this.onChangeCallback();
  581. return this;
  582. },
  583. setFromEuler: function ( euler, update ) {
  584. if ( euler instanceof THREE.Euler === false ) {
  585. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  586. }
  587. // http://www.mathworks.com/matlabcentral/fileexchange/
  588. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  589. // content/SpinCalc.m
  590. var c1 = Math.cos( euler._x / 2 );
  591. var c2 = Math.cos( euler._y / 2 );
  592. var c3 = Math.cos( euler._z / 2 );
  593. var s1 = Math.sin( euler._x / 2 );
  594. var s2 = Math.sin( euler._y / 2 );
  595. var s3 = Math.sin( euler._z / 2 );
  596. var order = euler.order;
  597. if ( order === 'XYZ' ) {
  598. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  599. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  600. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  601. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  602. } else if ( order === 'YXZ' ) {
  603. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  604. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  605. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  606. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  607. } else if ( order === 'ZXY' ) {
  608. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  609. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  610. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  611. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  612. } else if ( order === 'ZYX' ) {
  613. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  614. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  615. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  616. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  617. } else if ( order === 'YZX' ) {
  618. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  619. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  620. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  621. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  622. } else if ( order === 'XZY' ) {
  623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  624. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  625. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  626. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  627. }
  628. if ( update !== false ) this.onChangeCallback();
  629. return this;
  630. },
  631. setFromAxisAngle: function ( axis, angle ) {
  632. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  633. // assumes axis is normalized
  634. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  635. this._x = axis.x * s;
  636. this._y = axis.y * s;
  637. this._z = axis.z * s;
  638. this._w = Math.cos( halfAngle );
  639. this.onChangeCallback();
  640. return this;
  641. },
  642. setFromRotationMatrix: function ( m ) {
  643. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  644. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  645. var te = m.elements,
  646. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  647. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  648. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  649. trace = m11 + m22 + m33,
  650. s;
  651. if ( trace > 0 ) {
  652. s = 0.5 / Math.sqrt( trace + 1.0 );
  653. this._w = 0.25 / s;
  654. this._x = ( m32 - m23 ) * s;
  655. this._y = ( m13 - m31 ) * s;
  656. this._z = ( m21 - m12 ) * s;
  657. } else if ( m11 > m22 && m11 > m33 ) {
  658. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  659. this._w = ( m32 - m23 ) / s;
  660. this._x = 0.25 * s;
  661. this._y = ( m12 + m21 ) / s;
  662. this._z = ( m13 + m31 ) / s;
  663. } else if ( m22 > m33 ) {
  664. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  665. this._w = ( m13 - m31 ) / s;
  666. this._x = ( m12 + m21 ) / s;
  667. this._y = 0.25 * s;
  668. this._z = ( m23 + m32 ) / s;
  669. } else {
  670. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  671. this._w = ( m21 - m12 ) / s;
  672. this._x = ( m13 + m31 ) / s;
  673. this._y = ( m23 + m32 ) / s;
  674. this._z = 0.25 * s;
  675. }
  676. this.onChangeCallback();
  677. return this;
  678. },
  679. setFromUnitVectors: function () {
  680. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  681. // assumes direction vectors vFrom and vTo are normalized
  682. var v1, r;
  683. var EPS = 0.000001;
  684. return function ( vFrom, vTo ) {
  685. if ( v1 === undefined ) v1 = new THREE.Vector3();
  686. r = vFrom.dot( vTo ) + 1;
  687. if ( r < EPS ) {
  688. r = 0;
  689. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  690. v1.set( - vFrom.y, vFrom.x, 0 );
  691. } else {
  692. v1.set( 0, - vFrom.z, vFrom.y );
  693. }
  694. } else {
  695. v1.crossVectors( vFrom, vTo );
  696. }
  697. this._x = v1.x;
  698. this._y = v1.y;
  699. this._z = v1.z;
  700. this._w = r;
  701. this.normalize();
  702. return this;
  703. }
  704. }(),
  705. inverse: function () {
  706. this.conjugate().normalize();
  707. return this;
  708. },
  709. conjugate: function () {
  710. this._x *= - 1;
  711. this._y *= - 1;
  712. this._z *= - 1;
  713. this.onChangeCallback();
  714. return this;
  715. },
  716. dot: function ( v ) {
  717. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  718. },
  719. lengthSq: function () {
  720. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  721. },
  722. length: function () {
  723. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  724. },
  725. normalize: function () {
  726. var l = this.length();
  727. if ( l === 0 ) {
  728. this._x = 0;
  729. this._y = 0;
  730. this._z = 0;
  731. this._w = 1;
  732. } else {
  733. l = 1 / l;
  734. this._x = this._x * l;
  735. this._y = this._y * l;
  736. this._z = this._z * l;
  737. this._w = this._w * l;
  738. }
  739. this.onChangeCallback();
  740. return this;
  741. },
  742. multiply: function ( q, p ) {
  743. if ( p !== undefined ) {
  744. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  745. return this.multiplyQuaternions( q, p );
  746. }
  747. return this.multiplyQuaternions( this, q );
  748. },
  749. multiplyQuaternions: function ( a, b ) {
  750. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  751. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  752. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  753. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  754. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  755. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  756. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  757. this.onChangeCallback();
  758. return this;
  759. },
  760. multiplyVector3: function ( vector ) {
  761. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  762. return vector.applyQuaternion( this );
  763. },
  764. slerp: function ( qb, t ) {
  765. if ( t === 0 ) return this;
  766. if ( t === 1 ) return this.copy( qb );
  767. var x = this._x, y = this._y, z = this._z, w = this._w;
  768. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  769. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  770. if ( cosHalfTheta < 0 ) {
  771. this._w = - qb._w;
  772. this._x = - qb._x;
  773. this._y = - qb._y;
  774. this._z = - qb._z;
  775. cosHalfTheta = - cosHalfTheta;
  776. } else {
  777. this.copy( qb );
  778. }
  779. if ( cosHalfTheta >= 1.0 ) {
  780. this._w = w;
  781. this._x = x;
  782. this._y = y;
  783. this._z = z;
  784. return this;
  785. }
  786. var halfTheta = Math.acos( cosHalfTheta );
  787. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  788. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  789. this._w = 0.5 * ( w + this._w );
  790. this._x = 0.5 * ( x + this._x );
  791. this._y = 0.5 * ( y + this._y );
  792. this._z = 0.5 * ( z + this._z );
  793. return this;
  794. }
  795. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  796. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  797. this._w = ( w * ratioA + this._w * ratioB );
  798. this._x = ( x * ratioA + this._x * ratioB );
  799. this._y = ( y * ratioA + this._y * ratioB );
  800. this._z = ( z * ratioA + this._z * ratioB );
  801. this.onChangeCallback();
  802. return this;
  803. },
  804. equals: function ( quaternion ) {
  805. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  806. },
  807. fromArray: function ( array, offset ) {
  808. if ( offset === undefined ) offset = 0;
  809. this._x = array[ offset ];
  810. this._y = array[ offset + 1 ];
  811. this._z = array[ offset + 2 ];
  812. this._w = array[ offset + 3 ];
  813. this.onChangeCallback();
  814. return this;
  815. },
  816. toArray: function ( array, offset ) {
  817. if ( array === undefined ) array = [];
  818. if ( offset === undefined ) offset = 0;
  819. array[ offset ] = this._x;
  820. array[ offset + 1 ] = this._y;
  821. array[ offset + 2 ] = this._z;
  822. array[ offset + 3 ] = this._w;
  823. return array;
  824. },
  825. onChange: function ( callback ) {
  826. this.onChangeCallback = callback;
  827. return this;
  828. },
  829. onChangeCallback: function () {}
  830. };
  831. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  832. return qm.copy( qa ).slerp( qb, t );
  833. };
  834. // File:src/math/Vector2.js
  835. /**
  836. * @author mrdoob / http://mrdoob.com/
  837. * @author philogb / http://blog.thejit.org/
  838. * @author egraether / http://egraether.com/
  839. * @author zz85 / http://www.lab4games.net/zz85/blog
  840. */
  841. THREE.Vector2 = function ( x, y ) {
  842. this.x = x || 0;
  843. this.y = y || 0;
  844. };
  845. THREE.Vector2.prototype = {
  846. constructor: THREE.Vector2,
  847. set: function ( x, y ) {
  848. this.x = x;
  849. this.y = y;
  850. return this;
  851. },
  852. setX: function ( x ) {
  853. this.x = x;
  854. return this;
  855. },
  856. setY: function ( y ) {
  857. this.y = y;
  858. return this;
  859. },
  860. setComponent: function ( index, value ) {
  861. switch ( index ) {
  862. case 0: this.x = value; break;
  863. case 1: this.y = value; break;
  864. default: throw new Error( 'index is out of range: ' + index );
  865. }
  866. },
  867. getComponent: function ( index ) {
  868. switch ( index ) {
  869. case 0: return this.x;
  870. case 1: return this.y;
  871. default: throw new Error( 'index is out of range: ' + index );
  872. }
  873. },
  874. clone: function () {
  875. return new this.constructor( this.x, this.y );
  876. },
  877. copy: function ( v ) {
  878. this.x = v.x;
  879. this.y = v.y;
  880. return this;
  881. },
  882. add: function ( v, w ) {
  883. if ( w !== undefined ) {
  884. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  885. return this.addVectors( v, w );
  886. }
  887. this.x += v.x;
  888. this.y += v.y;
  889. return this;
  890. },
  891. addScalar: function ( s ) {
  892. this.x += s;
  893. this.y += s;
  894. return this;
  895. },
  896. addVectors: function ( a, b ) {
  897. this.x = a.x + b.x;
  898. this.y = a.y + b.y;
  899. return this;
  900. },
  901. addScaledVector: function ( v, s ) {
  902. this.x += v.x * s;
  903. this.y += v.y * s;
  904. return this;
  905. },
  906. sub: function ( v, w ) {
  907. if ( w !== undefined ) {
  908. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  909. return this.subVectors( v, w );
  910. }
  911. this.x -= v.x;
  912. this.y -= v.y;
  913. return this;
  914. },
  915. subScalar: function ( s ) {
  916. this.x -= s;
  917. this.y -= s;
  918. return this;
  919. },
  920. subVectors: function ( a, b ) {
  921. this.x = a.x - b.x;
  922. this.y = a.y - b.y;
  923. return this;
  924. },
  925. multiply: function ( v ) {
  926. this.x *= v.x;
  927. this.y *= v.y;
  928. return this;
  929. },
  930. multiplyScalar: function ( s ) {
  931. this.x *= s;
  932. this.y *= s;
  933. return this;
  934. },
  935. divide: function ( v ) {
  936. this.x /= v.x;
  937. this.y /= v.y;
  938. return this;
  939. },
  940. divideScalar: function ( scalar ) {
  941. if ( scalar !== 0 ) {
  942. var invScalar = 1 / scalar;
  943. this.x *= invScalar;
  944. this.y *= invScalar;
  945. } else {
  946. this.x = 0;
  947. this.y = 0;
  948. }
  949. return this;
  950. },
  951. min: function ( v ) {
  952. if ( this.x > v.x ) {
  953. this.x = v.x;
  954. }
  955. if ( this.y > v.y ) {
  956. this.y = v.y;
  957. }
  958. return this;
  959. },
  960. max: function ( v ) {
  961. if ( this.x < v.x ) {
  962. this.x = v.x;
  963. }
  964. if ( this.y < v.y ) {
  965. this.y = v.y;
  966. }
  967. return this;
  968. },
  969. clamp: function ( min, max ) {
  970. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  971. if ( this.x < min.x ) {
  972. this.x = min.x;
  973. } else if ( this.x > max.x ) {
  974. this.x = max.x;
  975. }
  976. if ( this.y < min.y ) {
  977. this.y = min.y;
  978. } else if ( this.y > max.y ) {
  979. this.y = max.y;
  980. }
  981. return this;
  982. },
  983. clampScalar: function () {
  984. var min, max;
  985. return function clampScalar( minVal, maxVal ) {
  986. if ( min === undefined ) {
  987. min = new THREE.Vector2();
  988. max = new THREE.Vector2();
  989. }
  990. min.set( minVal, minVal );
  991. max.set( maxVal, maxVal );
  992. return this.clamp( min, max );
  993. };
  994. }(),
  995. floor: function () {
  996. this.x = Math.floor( this.x );
  997. this.y = Math.floor( this.y );
  998. return this;
  999. },
  1000. ceil: function () {
  1001. this.x = Math.ceil( this.x );
  1002. this.y = Math.ceil( this.y );
  1003. return this;
  1004. },
  1005. round: function () {
  1006. this.x = Math.round( this.x );
  1007. this.y = Math.round( this.y );
  1008. return this;
  1009. },
  1010. roundToZero: function () {
  1011. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1012. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1013. return this;
  1014. },
  1015. negate: function () {
  1016. this.x = - this.x;
  1017. this.y = - this.y;
  1018. return this;
  1019. },
  1020. dot: function ( v ) {
  1021. return this.x * v.x + this.y * v.y;
  1022. },
  1023. lengthSq: function () {
  1024. return this.x * this.x + this.y * this.y;
  1025. },
  1026. length: function () {
  1027. return Math.sqrt( this.x * this.x + this.y * this.y );
  1028. },
  1029. lengthManhattan: function() {
  1030. return Math.abs( this.x ) + Math.abs( this.y );
  1031. },
  1032. normalize: function () {
  1033. return this.divideScalar( this.length() );
  1034. },
  1035. distanceTo: function ( v ) {
  1036. return Math.sqrt( this.distanceToSquared( v ) );
  1037. },
  1038. distanceToSquared: function ( v ) {
  1039. var dx = this.x - v.x, dy = this.y - v.y;
  1040. return dx * dx + dy * dy;
  1041. },
  1042. setLength: function ( l ) {
  1043. var oldLength = this.length();
  1044. if ( oldLength !== 0 && l !== oldLength ) {
  1045. this.multiplyScalar( l / oldLength );
  1046. }
  1047. return this;
  1048. },
  1049. lerp: function ( v, alpha ) {
  1050. this.x += ( v.x - this.x ) * alpha;
  1051. this.y += ( v.y - this.y ) * alpha;
  1052. return this;
  1053. },
  1054. lerpVectors: function ( v1, v2, alpha ) {
  1055. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1056. return this;
  1057. },
  1058. equals: function ( v ) {
  1059. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1060. },
  1061. fromArray: function ( array, offset ) {
  1062. if ( offset === undefined ) offset = 0;
  1063. this.x = array[ offset ];
  1064. this.y = array[ offset + 1 ];
  1065. return this;
  1066. },
  1067. toArray: function ( array, offset ) {
  1068. if ( array === undefined ) array = [];
  1069. if ( offset === undefined ) offset = 0;
  1070. array[ offset ] = this.x;
  1071. array[ offset + 1 ] = this.y;
  1072. return array;
  1073. },
  1074. fromAttribute: function ( attribute, index, offset ) {
  1075. if ( offset === undefined ) offset = 0;
  1076. index = index * attribute.itemSize + offset;
  1077. this.x = attribute.array[ index ];
  1078. this.y = attribute.array[ index + 1 ];
  1079. return this;
  1080. }
  1081. };
  1082. // File:src/math/Vector3.js
  1083. /**
  1084. * @author mrdoob / http://mrdoob.com/
  1085. * @author *kile / http://kile.stravaganza.org/
  1086. * @author philogb / http://blog.thejit.org/
  1087. * @author mikael emtinger / http://gomo.se/
  1088. * @author egraether / http://egraether.com/
  1089. * @author WestLangley / http://github.com/WestLangley
  1090. */
  1091. THREE.Vector3 = function ( x, y, z ) {
  1092. this.x = x || 0;
  1093. this.y = y || 0;
  1094. this.z = z || 0;
  1095. };
  1096. THREE.Vector3.prototype = {
  1097. constructor: THREE.Vector3,
  1098. set: function ( x, y, z ) {
  1099. this.x = x;
  1100. this.y = y;
  1101. this.z = z;
  1102. return this;
  1103. },
  1104. setX: function ( x ) {
  1105. this.x = x;
  1106. return this;
  1107. },
  1108. setY: function ( y ) {
  1109. this.y = y;
  1110. return this;
  1111. },
  1112. setZ: function ( z ) {
  1113. this.z = z;
  1114. return this;
  1115. },
  1116. setComponent: function ( index, value ) {
  1117. switch ( index ) {
  1118. case 0: this.x = value; break;
  1119. case 1: this.y = value; break;
  1120. case 2: this.z = value; break;
  1121. default: throw new Error( 'index is out of range: ' + index );
  1122. }
  1123. },
  1124. getComponent: function ( index ) {
  1125. switch ( index ) {
  1126. case 0: return this.x;
  1127. case 1: return this.y;
  1128. case 2: return this.z;
  1129. default: throw new Error( 'index is out of range: ' + index );
  1130. }
  1131. },
  1132. clone: function () {
  1133. return new this.constructor( this.x, this.y, this.z );
  1134. },
  1135. copy: function ( v ) {
  1136. this.x = v.x;
  1137. this.y = v.y;
  1138. this.z = v.z;
  1139. return this;
  1140. },
  1141. add: function ( v, w ) {
  1142. if ( w !== undefined ) {
  1143. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1144. return this.addVectors( v, w );
  1145. }
  1146. this.x += v.x;
  1147. this.y += v.y;
  1148. this.z += v.z;
  1149. return this;
  1150. },
  1151. addScalar: function ( s ) {
  1152. this.x += s;
  1153. this.y += s;
  1154. this.z += s;
  1155. return this;
  1156. },
  1157. addVectors: function ( a, b ) {
  1158. this.x = a.x + b.x;
  1159. this.y = a.y + b.y;
  1160. this.z = a.z + b.z;
  1161. return this;
  1162. },
  1163. addScaledVector: function ( v, s ) {
  1164. this.x += v.x * s;
  1165. this.y += v.y * s;
  1166. this.z += v.z * s;
  1167. return this;
  1168. },
  1169. sub: function ( v, w ) {
  1170. if ( w !== undefined ) {
  1171. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1172. return this.subVectors( v, w );
  1173. }
  1174. this.x -= v.x;
  1175. this.y -= v.y;
  1176. this.z -= v.z;
  1177. return this;
  1178. },
  1179. subScalar: function ( s ) {
  1180. this.x -= s;
  1181. this.y -= s;
  1182. this.z -= s;
  1183. return this;
  1184. },
  1185. subVectors: function ( a, b ) {
  1186. this.x = a.x - b.x;
  1187. this.y = a.y - b.y;
  1188. this.z = a.z - b.z;
  1189. return this;
  1190. },
  1191. multiply: function ( v, w ) {
  1192. if ( w !== undefined ) {
  1193. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1194. return this.multiplyVectors( v, w );
  1195. }
  1196. this.x *= v.x;
  1197. this.y *= v.y;
  1198. this.z *= v.z;
  1199. return this;
  1200. },
  1201. multiplyScalar: function ( scalar ) {
  1202. this.x *= scalar;
  1203. this.y *= scalar;
  1204. this.z *= scalar;
  1205. return this;
  1206. },
  1207. multiplyVectors: function ( a, b ) {
  1208. this.x = a.x * b.x;
  1209. this.y = a.y * b.y;
  1210. this.z = a.z * b.z;
  1211. return this;
  1212. },
  1213. applyEuler: function () {
  1214. var quaternion;
  1215. return function applyEuler( euler ) {
  1216. if ( euler instanceof THREE.Euler === false ) {
  1217. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1218. }
  1219. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1220. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1221. return this;
  1222. };
  1223. }(),
  1224. applyAxisAngle: function () {
  1225. var quaternion;
  1226. return function applyAxisAngle( axis, angle ) {
  1227. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1228. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1229. return this;
  1230. };
  1231. }(),
  1232. applyMatrix3: function ( m ) {
  1233. var x = this.x;
  1234. var y = this.y;
  1235. var z = this.z;
  1236. var e = m.elements;
  1237. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1238. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1239. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1240. return this;
  1241. },
  1242. applyMatrix4: function ( m ) {
  1243. // input: THREE.Matrix4 affine matrix
  1244. var x = this.x, y = this.y, z = this.z;
  1245. var e = m.elements;
  1246. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1247. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1248. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1249. return this;
  1250. },
  1251. applyProjection: function ( m ) {
  1252. // input: THREE.Matrix4 projection matrix
  1253. var x = this.x, y = this.y, z = this.z;
  1254. var e = m.elements;
  1255. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1256. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1257. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1258. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1259. return this;
  1260. },
  1261. applyQuaternion: function ( q ) {
  1262. var x = this.x;
  1263. var y = this.y;
  1264. var z = this.z;
  1265. var qx = q.x;
  1266. var qy = q.y;
  1267. var qz = q.z;
  1268. var qw = q.w;
  1269. // calculate quat * vector
  1270. var ix = qw * x + qy * z - qz * y;
  1271. var iy = qw * y + qz * x - qx * z;
  1272. var iz = qw * z + qx * y - qy * x;
  1273. var iw = - qx * x - qy * y - qz * z;
  1274. // calculate result * inverse quat
  1275. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1276. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1277. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1278. return this;
  1279. },
  1280. project: function () {
  1281. var matrix;
  1282. return function project( camera ) {
  1283. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1284. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1285. return this.applyProjection( matrix );
  1286. };
  1287. }(),
  1288. unproject: function () {
  1289. var matrix;
  1290. return function unproject( camera ) {
  1291. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1292. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1293. return this.applyProjection( matrix );
  1294. };
  1295. }(),
  1296. transformDirection: function ( m ) {
  1297. // input: THREE.Matrix4 affine matrix
  1298. // vector interpreted as a direction
  1299. var x = this.x, y = this.y, z = this.z;
  1300. var e = m.elements;
  1301. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1302. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1303. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1304. this.normalize();
  1305. return this;
  1306. },
  1307. divide: function ( v ) {
  1308. this.x /= v.x;
  1309. this.y /= v.y;
  1310. this.z /= v.z;
  1311. return this;
  1312. },
  1313. divideScalar: function ( scalar ) {
  1314. if ( scalar !== 0 ) {
  1315. var invScalar = 1 / scalar;
  1316. this.x *= invScalar;
  1317. this.y *= invScalar;
  1318. this.z *= invScalar;
  1319. } else {
  1320. this.x = 0;
  1321. this.y = 0;
  1322. this.z = 0;
  1323. }
  1324. return this;
  1325. },
  1326. min: function ( v ) {
  1327. if ( this.x > v.x ) {
  1328. this.x = v.x;
  1329. }
  1330. if ( this.y > v.y ) {
  1331. this.y = v.y;
  1332. }
  1333. if ( this.z > v.z ) {
  1334. this.z = v.z;
  1335. }
  1336. return this;
  1337. },
  1338. max: function ( v ) {
  1339. if ( this.x < v.x ) {
  1340. this.x = v.x;
  1341. }
  1342. if ( this.y < v.y ) {
  1343. this.y = v.y;
  1344. }
  1345. if ( this.z < v.z ) {
  1346. this.z = v.z;
  1347. }
  1348. return this;
  1349. },
  1350. clamp: function ( min, max ) {
  1351. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1352. if ( this.x < min.x ) {
  1353. this.x = min.x;
  1354. } else if ( this.x > max.x ) {
  1355. this.x = max.x;
  1356. }
  1357. if ( this.y < min.y ) {
  1358. this.y = min.y;
  1359. } else if ( this.y > max.y ) {
  1360. this.y = max.y;
  1361. }
  1362. if ( this.z < min.z ) {
  1363. this.z = min.z;
  1364. } else if ( this.z > max.z ) {
  1365. this.z = max.z;
  1366. }
  1367. return this;
  1368. },
  1369. clampScalar: function () {
  1370. var min, max;
  1371. return function clampScalar( minVal, maxVal ) {
  1372. if ( min === undefined ) {
  1373. min = new THREE.Vector3();
  1374. max = new THREE.Vector3();
  1375. }
  1376. min.set( minVal, minVal, minVal );
  1377. max.set( maxVal, maxVal, maxVal );
  1378. return this.clamp( min, max );
  1379. };
  1380. }(),
  1381. floor: function () {
  1382. this.x = Math.floor( this.x );
  1383. this.y = Math.floor( this.y );
  1384. this.z = Math.floor( this.z );
  1385. return this;
  1386. },
  1387. ceil: function () {
  1388. this.x = Math.ceil( this.x );
  1389. this.y = Math.ceil( this.y );
  1390. this.z = Math.ceil( this.z );
  1391. return this;
  1392. },
  1393. round: function () {
  1394. this.x = Math.round( this.x );
  1395. this.y = Math.round( this.y );
  1396. this.z = Math.round( this.z );
  1397. return this;
  1398. },
  1399. roundToZero: function () {
  1400. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1401. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1402. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1403. return this;
  1404. },
  1405. negate: function () {
  1406. this.x = - this.x;
  1407. this.y = - this.y;
  1408. this.z = - this.z;
  1409. return this;
  1410. },
  1411. dot: function ( v ) {
  1412. return this.x * v.x + this.y * v.y + this.z * v.z;
  1413. },
  1414. lengthSq: function () {
  1415. return this.x * this.x + this.y * this.y + this.z * this.z;
  1416. },
  1417. length: function () {
  1418. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1419. },
  1420. lengthManhattan: function () {
  1421. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1422. },
  1423. normalize: function () {
  1424. return this.divideScalar( this.length() );
  1425. },
  1426. setLength: function ( l ) {
  1427. var oldLength = this.length();
  1428. if ( oldLength !== 0 && l !== oldLength ) {
  1429. this.multiplyScalar( l / oldLength );
  1430. }
  1431. return this;
  1432. },
  1433. lerp: function ( v, alpha ) {
  1434. this.x += ( v.x - this.x ) * alpha;
  1435. this.y += ( v.y - this.y ) * alpha;
  1436. this.z += ( v.z - this.z ) * alpha;
  1437. return this;
  1438. },
  1439. lerpVectors: function ( v1, v2, alpha ) {
  1440. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1441. return this;
  1442. },
  1443. cross: function ( v, w ) {
  1444. if ( w !== undefined ) {
  1445. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1446. return this.crossVectors( v, w );
  1447. }
  1448. var x = this.x, y = this.y, z = this.z;
  1449. this.x = y * v.z - z * v.y;
  1450. this.y = z * v.x - x * v.z;
  1451. this.z = x * v.y - y * v.x;
  1452. return this;
  1453. },
  1454. crossVectors: function ( a, b ) {
  1455. var ax = a.x, ay = a.y, az = a.z;
  1456. var bx = b.x, by = b.y, bz = b.z;
  1457. this.x = ay * bz - az * by;
  1458. this.y = az * bx - ax * bz;
  1459. this.z = ax * by - ay * bx;
  1460. return this;
  1461. },
  1462. projectOnVector: function () {
  1463. var v1, dot;
  1464. return function projectOnVector( vector ) {
  1465. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1466. v1.copy( vector ).normalize();
  1467. dot = this.dot( v1 );
  1468. return this.copy( v1 ).multiplyScalar( dot );
  1469. };
  1470. }(),
  1471. projectOnPlane: function () {
  1472. var v1;
  1473. return function projectOnPlane( planeNormal ) {
  1474. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1475. v1.copy( this ).projectOnVector( planeNormal );
  1476. return this.sub( v1 );
  1477. }
  1478. }(),
  1479. reflect: function () {
  1480. // reflect incident vector off plane orthogonal to normal
  1481. // normal is assumed to have unit length
  1482. var v1;
  1483. return function reflect( normal ) {
  1484. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1485. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1486. }
  1487. }(),
  1488. angleTo: function ( v ) {
  1489. var theta = this.dot( v ) / ( this.length() * v.length() );
  1490. // clamp, to handle numerical problems
  1491. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1492. },
  1493. distanceTo: function ( v ) {
  1494. return Math.sqrt( this.distanceToSquared( v ) );
  1495. },
  1496. distanceToSquared: function ( v ) {
  1497. var dx = this.x - v.x;
  1498. var dy = this.y - v.y;
  1499. var dz = this.z - v.z;
  1500. return dx * dx + dy * dy + dz * dz;
  1501. },
  1502. setEulerFromRotationMatrix: function ( m, order ) {
  1503. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1504. },
  1505. setEulerFromQuaternion: function ( q, order ) {
  1506. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1507. },
  1508. getPositionFromMatrix: function ( m ) {
  1509. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1510. return this.setFromMatrixPosition( m );
  1511. },
  1512. getScaleFromMatrix: function ( m ) {
  1513. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1514. return this.setFromMatrixScale( m );
  1515. },
  1516. getColumnFromMatrix: function ( index, matrix ) {
  1517. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1518. return this.setFromMatrixColumn( index, matrix );
  1519. },
  1520. setFromMatrixPosition: function ( m ) {
  1521. this.x = m.elements[ 12 ];
  1522. this.y = m.elements[ 13 ];
  1523. this.z = m.elements[ 14 ];
  1524. return this;
  1525. },
  1526. setFromMatrixScale: function ( m ) {
  1527. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1528. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1529. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1530. this.x = sx;
  1531. this.y = sy;
  1532. this.z = sz;
  1533. return this;
  1534. },
  1535. setFromMatrixColumn: function ( index, matrix ) {
  1536. var offset = index * 4;
  1537. var me = matrix.elements;
  1538. this.x = me[ offset ];
  1539. this.y = me[ offset + 1 ];
  1540. this.z = me[ offset + 2 ];
  1541. return this;
  1542. },
  1543. equals: function ( v ) {
  1544. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1545. },
  1546. fromArray: function ( array, offset ) {
  1547. if ( offset === undefined ) offset = 0;
  1548. this.x = array[ offset ];
  1549. this.y = array[ offset + 1 ];
  1550. this.z = array[ offset + 2 ];
  1551. return this;
  1552. },
  1553. toArray: function ( array, offset ) {
  1554. if ( array === undefined ) array = [];
  1555. if ( offset === undefined ) offset = 0;
  1556. array[ offset ] = this.x;
  1557. array[ offset + 1 ] = this.y;
  1558. array[ offset + 2 ] = this.z;
  1559. return array;
  1560. },
  1561. fromAttribute: function ( attribute, index, offset ) {
  1562. if ( offset === undefined ) offset = 0;
  1563. index = index * attribute.itemSize + offset;
  1564. this.x = attribute.array[ index ];
  1565. this.y = attribute.array[ index + 1 ];
  1566. this.z = attribute.array[ index + 2 ];
  1567. return this;
  1568. }
  1569. };
  1570. // File:src/math/Vector4.js
  1571. /**
  1572. * @author supereggbert / http://www.paulbrunt.co.uk/
  1573. * @author philogb / http://blog.thejit.org/
  1574. * @author mikael emtinger / http://gomo.se/
  1575. * @author egraether / http://egraether.com/
  1576. * @author WestLangley / http://github.com/WestLangley
  1577. */
  1578. THREE.Vector4 = function ( x, y, z, w ) {
  1579. this.x = x || 0;
  1580. this.y = y || 0;
  1581. this.z = z || 0;
  1582. this.w = ( w !== undefined ) ? w : 1;
  1583. };
  1584. THREE.Vector4.prototype = {
  1585. constructor: THREE.Vector4,
  1586. set: function ( x, y, z, w ) {
  1587. this.x = x;
  1588. this.y = y;
  1589. this.z = z;
  1590. this.w = w;
  1591. return this;
  1592. },
  1593. setX: function ( x ) {
  1594. this.x = x;
  1595. return this;
  1596. },
  1597. setY: function ( y ) {
  1598. this.y = y;
  1599. return this;
  1600. },
  1601. setZ: function ( z ) {
  1602. this.z = z;
  1603. return this;
  1604. },
  1605. setW: function ( w ) {
  1606. this.w = w;
  1607. return this;
  1608. },
  1609. setComponent: function ( index, value ) {
  1610. switch ( index ) {
  1611. case 0: this.x = value; break;
  1612. case 1: this.y = value; break;
  1613. case 2: this.z = value; break;
  1614. case 3: this.w = value; break;
  1615. default: throw new Error( 'index is out of range: ' + index );
  1616. }
  1617. },
  1618. getComponent: function ( index ) {
  1619. switch ( index ) {
  1620. case 0: return this.x;
  1621. case 1: return this.y;
  1622. case 2: return this.z;
  1623. case 3: return this.w;
  1624. default: throw new Error( 'index is out of range: ' + index );
  1625. }
  1626. },
  1627. clone: function () {
  1628. return new this.constructor( this.x, this.y, this.z, this.w );
  1629. },
  1630. copy: function ( v ) {
  1631. this.x = v.x;
  1632. this.y = v.y;
  1633. this.z = v.z;
  1634. this.w = ( v.w !== undefined ) ? v.w : 1;
  1635. return this;
  1636. },
  1637. add: function ( v, w ) {
  1638. if ( w !== undefined ) {
  1639. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1640. return this.addVectors( v, w );
  1641. }
  1642. this.x += v.x;
  1643. this.y += v.y;
  1644. this.z += v.z;
  1645. this.w += v.w;
  1646. return this;
  1647. },
  1648. addScalar: function ( s ) {
  1649. this.x += s;
  1650. this.y += s;
  1651. this.z += s;
  1652. this.w += s;
  1653. return this;
  1654. },
  1655. addVectors: function ( a, b ) {
  1656. this.x = a.x + b.x;
  1657. this.y = a.y + b.y;
  1658. this.z = a.z + b.z;
  1659. this.w = a.w + b.w;
  1660. return this;
  1661. },
  1662. addScaledVector: function ( v, s ) {
  1663. this.x += v.x * s;
  1664. this.y += v.y * s;
  1665. this.z += v.z * s;
  1666. this.w += v.w * s;
  1667. return this;
  1668. },
  1669. sub: function ( v, w ) {
  1670. if ( w !== undefined ) {
  1671. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1672. return this.subVectors( 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. subScalar: function ( s ) {
  1681. this.x -= s;
  1682. this.y -= s;
  1683. this.z -= s;
  1684. this.w -= s;
  1685. return this;
  1686. },
  1687. subVectors: 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. multiplyScalar: function ( scalar ) {
  1695. this.x *= scalar;
  1696. this.y *= scalar;
  1697. this.z *= scalar;
  1698. this.w *= scalar;
  1699. return this;
  1700. },
  1701. applyMatrix4: function ( m ) {
  1702. var x = this.x;
  1703. var y = this.y;
  1704. var z = this.z;
  1705. var w = this.w;
  1706. var e = m.elements;
  1707. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1708. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1709. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1710. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1711. return this;
  1712. },
  1713. divideScalar: function ( scalar ) {
  1714. if ( scalar !== 0 ) {
  1715. var invScalar = 1 / scalar;
  1716. this.x *= invScalar;
  1717. this.y *= invScalar;
  1718. this.z *= invScalar;
  1719. this.w *= invScalar;
  1720. } else {
  1721. this.x = 0;
  1722. this.y = 0;
  1723. this.z = 0;
  1724. this.w = 1;
  1725. }
  1726. return this;
  1727. },
  1728. setAxisAngleFromQuaternion: function ( q ) {
  1729. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1730. // q is assumed to be normalized
  1731. this.w = 2 * Math.acos( q.w );
  1732. var s = Math.sqrt( 1 - q.w * q.w );
  1733. if ( s < 0.0001 ) {
  1734. this.x = 1;
  1735. this.y = 0;
  1736. this.z = 0;
  1737. } else {
  1738. this.x = q.x / s;
  1739. this.y = q.y / s;
  1740. this.z = q.z / s;
  1741. }
  1742. return this;
  1743. },
  1744. setAxisAngleFromRotationMatrix: function ( m ) {
  1745. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1746. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1747. var angle, x, y, z, // variables for result
  1748. epsilon = 0.01, // margin to allow for rounding errors
  1749. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1750. te = m.elements,
  1751. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1752. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1753. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1754. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1755. && ( Math.abs( m13 - m31 ) < epsilon )
  1756. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1757. // singularity found
  1758. // first check for identity matrix which must have +1 for all terms
  1759. // in leading diagonal and zero in other terms
  1760. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1761. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1762. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1763. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1764. // this singularity is identity matrix so angle = 0
  1765. this.set( 1, 0, 0, 0 );
  1766. return this; // zero angle, arbitrary axis
  1767. }
  1768. // otherwise this singularity is angle = 180
  1769. angle = Math.PI;
  1770. var xx = ( m11 + 1 ) / 2;
  1771. var yy = ( m22 + 1 ) / 2;
  1772. var zz = ( m33 + 1 ) / 2;
  1773. var xy = ( m12 + m21 ) / 4;
  1774. var xz = ( m13 + m31 ) / 4;
  1775. var yz = ( m23 + m32 ) / 4;
  1776. if ( ( xx > yy ) && ( xx > zz ) ) {
  1777. // m11 is the largest diagonal term
  1778. if ( xx < epsilon ) {
  1779. x = 0;
  1780. y = 0.707106781;
  1781. z = 0.707106781;
  1782. } else {
  1783. x = Math.sqrt( xx );
  1784. y = xy / x;
  1785. z = xz / x;
  1786. }
  1787. } else if ( yy > zz ) {
  1788. // m22 is the largest diagonal term
  1789. if ( yy < epsilon ) {
  1790. x = 0.707106781;
  1791. y = 0;
  1792. z = 0.707106781;
  1793. } else {
  1794. y = Math.sqrt( yy );
  1795. x = xy / y;
  1796. z = yz / y;
  1797. }
  1798. } else {
  1799. // m33 is the largest diagonal term so base result on this
  1800. if ( zz < epsilon ) {
  1801. x = 0.707106781;
  1802. y = 0.707106781;
  1803. z = 0;
  1804. } else {
  1805. z = Math.sqrt( zz );
  1806. x = xz / z;
  1807. y = yz / z;
  1808. }
  1809. }
  1810. this.set( x, y, z, angle );
  1811. return this; // return 180 deg rotation
  1812. }
  1813. // as we have reached here there are no singularities so we can handle normally
  1814. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1815. + ( m13 - m31 ) * ( m13 - m31 )
  1816. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1817. if ( Math.abs( s ) < 0.001 ) s = 1;
  1818. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1819. // caught by singularity test above, but I've left it in just in case
  1820. this.x = ( m32 - m23 ) / s;
  1821. this.y = ( m13 - m31 ) / s;
  1822. this.z = ( m21 - m12 ) / s;
  1823. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1824. return this;
  1825. },
  1826. min: function ( v ) {
  1827. if ( this.x > v.x ) {
  1828. this.x = v.x;
  1829. }
  1830. if ( this.y > v.y ) {
  1831. this.y = v.y;
  1832. }
  1833. if ( this.z > v.z ) {
  1834. this.z = v.z;
  1835. }
  1836. if ( this.w > v.w ) {
  1837. this.w = v.w;
  1838. }
  1839. return this;
  1840. },
  1841. max: function ( v ) {
  1842. if ( this.x < v.x ) {
  1843. this.x = v.x;
  1844. }
  1845. if ( this.y < v.y ) {
  1846. this.y = v.y;
  1847. }
  1848. if ( this.z < v.z ) {
  1849. this.z = v.z;
  1850. }
  1851. if ( this.w < v.w ) {
  1852. this.w = v.w;
  1853. }
  1854. return this;
  1855. },
  1856. clamp: function ( min, max ) {
  1857. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1858. if ( this.x < min.x ) {
  1859. this.x = min.x;
  1860. } else if ( this.x > max.x ) {
  1861. this.x = max.x;
  1862. }
  1863. if ( this.y < min.y ) {
  1864. this.y = min.y;
  1865. } else if ( this.y > max.y ) {
  1866. this.y = max.y;
  1867. }
  1868. if ( this.z < min.z ) {
  1869. this.z = min.z;
  1870. } else if ( this.z > max.z ) {
  1871. this.z = max.z;
  1872. }
  1873. if ( this.w < min.w ) {
  1874. this.w = min.w;
  1875. } else if ( this.w > max.w ) {
  1876. this.w = max.w;
  1877. }
  1878. return this;
  1879. },
  1880. clampScalar: function () {
  1881. var min, max;
  1882. return function clampScalar( minVal, maxVal ) {
  1883. if ( min === undefined ) {
  1884. min = new THREE.Vector4();
  1885. max = new THREE.Vector4();
  1886. }
  1887. min.set( minVal, minVal, minVal, minVal );
  1888. max.set( maxVal, maxVal, maxVal, maxVal );
  1889. return this.clamp( min, max );
  1890. };
  1891. }(),
  1892. floor: function () {
  1893. this.x = Math.floor( this.x );
  1894. this.y = Math.floor( this.y );
  1895. this.z = Math.floor( this.z );
  1896. this.w = Math.floor( this.w );
  1897. return this;
  1898. },
  1899. ceil: function () {
  1900. this.x = Math.ceil( this.x );
  1901. this.y = Math.ceil( this.y );
  1902. this.z = Math.ceil( this.z );
  1903. this.w = Math.ceil( this.w );
  1904. return this;
  1905. },
  1906. round: function () {
  1907. this.x = Math.round( this.x );
  1908. this.y = Math.round( this.y );
  1909. this.z = Math.round( this.z );
  1910. this.w = Math.round( this.w );
  1911. return this;
  1912. },
  1913. roundToZero: function () {
  1914. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1915. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1916. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1917. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1918. return this;
  1919. },
  1920. negate: function () {
  1921. this.x = - this.x;
  1922. this.y = - this.y;
  1923. this.z = - this.z;
  1924. this.w = - this.w;
  1925. return this;
  1926. },
  1927. dot: function ( v ) {
  1928. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1929. },
  1930. lengthSq: function () {
  1931. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1932. },
  1933. length: function () {
  1934. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1935. },
  1936. lengthManhattan: function () {
  1937. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1938. },
  1939. normalize: function () {
  1940. return this.divideScalar( this.length() );
  1941. },
  1942. setLength: function ( l ) {
  1943. var oldLength = this.length();
  1944. if ( oldLength !== 0 && l !== oldLength ) {
  1945. this.multiplyScalar( l / oldLength );
  1946. }
  1947. return this;
  1948. },
  1949. lerp: function ( v, alpha ) {
  1950. this.x += ( v.x - this.x ) * alpha;
  1951. this.y += ( v.y - this.y ) * alpha;
  1952. this.z += ( v.z - this.z ) * alpha;
  1953. this.w += ( v.w - this.w ) * alpha;
  1954. return this;
  1955. },
  1956. lerpVectors: function ( v1, v2, alpha ) {
  1957. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1958. return this;
  1959. },
  1960. equals: function ( v ) {
  1961. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1962. },
  1963. fromArray: function ( array, offset ) {
  1964. if ( offset === undefined ) offset = 0;
  1965. this.x = array[ offset ];
  1966. this.y = array[ offset + 1 ];
  1967. this.z = array[ offset + 2 ];
  1968. this.w = array[ offset + 3 ];
  1969. return this;
  1970. },
  1971. toArray: function ( array, offset ) {
  1972. if ( array === undefined ) array = [];
  1973. if ( offset === undefined ) offset = 0;
  1974. array[ offset ] = this.x;
  1975. array[ offset + 1 ] = this.y;
  1976. array[ offset + 2 ] = this.z;
  1977. array[ offset + 3 ] = this.w;
  1978. return array;
  1979. },
  1980. fromAttribute: function ( attribute, index, offset ) {
  1981. if ( offset === undefined ) offset = 0;
  1982. index = index * attribute.itemSize + offset;
  1983. this.x = attribute.array[ index ];
  1984. this.y = attribute.array[ index + 1 ];
  1985. this.z = attribute.array[ index + 2 ];
  1986. this.w = attribute.array[ index + 3 ];
  1987. return this;
  1988. }
  1989. };
  1990. // File:src/math/Euler.js
  1991. /**
  1992. * @author mrdoob / http://mrdoob.com/
  1993. * @author WestLangley / http://github.com/WestLangley
  1994. * @author bhouston / http://clara.io
  1995. */
  1996. THREE.Euler = function ( x, y, z, order ) {
  1997. this._x = x || 0;
  1998. this._y = y || 0;
  1999. this._z = z || 0;
  2000. this._order = order || THREE.Euler.DefaultOrder;
  2001. };
  2002. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2003. THREE.Euler.DefaultOrder = 'XYZ';
  2004. THREE.Euler.prototype = {
  2005. constructor: THREE.Euler,
  2006. get x () {
  2007. return this._x;
  2008. },
  2009. set x ( value ) {
  2010. this._x = value;
  2011. this.onChangeCallback();
  2012. },
  2013. get y () {
  2014. return this._y;
  2015. },
  2016. set y ( value ) {
  2017. this._y = value;
  2018. this.onChangeCallback();
  2019. },
  2020. get z () {
  2021. return this._z;
  2022. },
  2023. set z ( value ) {
  2024. this._z = value;
  2025. this.onChangeCallback();
  2026. },
  2027. get order () {
  2028. return this._order;
  2029. },
  2030. set order ( value ) {
  2031. this._order = value;
  2032. this.onChangeCallback();
  2033. },
  2034. set: function ( x, y, z, order ) {
  2035. this._x = x;
  2036. this._y = y;
  2037. this._z = z;
  2038. this._order = order || this._order;
  2039. this.onChangeCallback();
  2040. return this;
  2041. },
  2042. clone: function () {
  2043. return new this.constructor( this._x, this._y, this._z, this._order);
  2044. },
  2045. copy: function ( euler ) {
  2046. this._x = euler._x;
  2047. this._y = euler._y;
  2048. this._z = euler._z;
  2049. this._order = euler._order;
  2050. this.onChangeCallback();
  2051. return this;
  2052. },
  2053. setFromRotationMatrix: function ( m, order, update ) {
  2054. var clamp = THREE.Math.clamp;
  2055. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2056. var te = m.elements;
  2057. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2058. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2059. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2060. order = order || this._order;
  2061. if ( order === 'XYZ' ) {
  2062. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2063. if ( Math.abs( m13 ) < 0.99999 ) {
  2064. this._x = Math.atan2( - m23, m33 );
  2065. this._z = Math.atan2( - m12, m11 );
  2066. } else {
  2067. this._x = Math.atan2( m32, m22 );
  2068. this._z = 0;
  2069. }
  2070. } else if ( order === 'YXZ' ) {
  2071. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2072. if ( Math.abs( m23 ) < 0.99999 ) {
  2073. this._y = Math.atan2( m13, m33 );
  2074. this._z = Math.atan2( m21, m22 );
  2075. } else {
  2076. this._y = Math.atan2( - m31, m11 );
  2077. this._z = 0;
  2078. }
  2079. } else if ( order === 'ZXY' ) {
  2080. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2081. if ( Math.abs( m32 ) < 0.99999 ) {
  2082. this._y = Math.atan2( - m31, m33 );
  2083. this._z = Math.atan2( - m12, m22 );
  2084. } else {
  2085. this._y = 0;
  2086. this._z = Math.atan2( m21, m11 );
  2087. }
  2088. } else if ( order === 'ZYX' ) {
  2089. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2090. if ( Math.abs( m31 ) < 0.99999 ) {
  2091. this._x = Math.atan2( m32, m33 );
  2092. this._z = Math.atan2( m21, m11 );
  2093. } else {
  2094. this._x = 0;
  2095. this._z = Math.atan2( - m12, m22 );
  2096. }
  2097. } else if ( order === 'YZX' ) {
  2098. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2099. if ( Math.abs( m21 ) < 0.99999 ) {
  2100. this._x = Math.atan2( - m23, m22 );
  2101. this._y = Math.atan2( - m31, m11 );
  2102. } else {
  2103. this._x = 0;
  2104. this._y = Math.atan2( m13, m33 );
  2105. }
  2106. } else if ( order === 'XZY' ) {
  2107. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2108. if ( Math.abs( m12 ) < 0.99999 ) {
  2109. this._x = Math.atan2( m32, m22 );
  2110. this._y = Math.atan2( m13, m11 );
  2111. } else {
  2112. this._x = Math.atan2( - m23, m33 );
  2113. this._y = 0;
  2114. }
  2115. } else {
  2116. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2117. }
  2118. this._order = order;
  2119. if ( update !== false ) this.onChangeCallback();
  2120. return this;
  2121. },
  2122. setFromQuaternion: function () {
  2123. var matrix;
  2124. return function ( q, order, update ) {
  2125. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2126. matrix.makeRotationFromQuaternion( q );
  2127. this.setFromRotationMatrix( matrix, order, update );
  2128. return this;
  2129. };
  2130. }(),
  2131. setFromVector3: function ( v, order ) {
  2132. return this.set( v.x, v.y, v.z, order || this._order );
  2133. },
  2134. reorder: function () {
  2135. // WARNING: this discards revolution information -bhouston
  2136. var q = new THREE.Quaternion();
  2137. return function ( newOrder ) {
  2138. q.setFromEuler( this );
  2139. this.setFromQuaternion( q, newOrder );
  2140. };
  2141. }(),
  2142. equals: function ( euler ) {
  2143. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2144. },
  2145. fromArray: function ( array ) {
  2146. this._x = array[ 0 ];
  2147. this._y = array[ 1 ];
  2148. this._z = array[ 2 ];
  2149. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2150. this.onChangeCallback();
  2151. return this;
  2152. },
  2153. toArray: function ( array, offset ) {
  2154. if ( array === undefined ) array = [];
  2155. if ( offset === undefined ) offset = 0;
  2156. array[ offset ] = this._x;
  2157. array[ offset + 1 ] = this._y;
  2158. array[ offset + 2 ] = this._z;
  2159. array[ offset + 3 ] = this._order;
  2160. return array;
  2161. },
  2162. toVector3: function ( optionalResult ) {
  2163. if ( optionalResult ) {
  2164. return optionalResult.set( this._x, this._y, this._z );
  2165. } else {
  2166. return new THREE.Vector3( this._x, this._y, this._z );
  2167. }
  2168. },
  2169. onChange: function ( callback ) {
  2170. this.onChangeCallback = callback;
  2171. return this;
  2172. },
  2173. onChangeCallback: function () {}
  2174. };
  2175. // File:src/math/Line3.js
  2176. /**
  2177. * @author bhouston / http://clara.io
  2178. */
  2179. THREE.Line3 = function ( start, end ) {
  2180. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2181. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2182. };
  2183. THREE.Line3.prototype = {
  2184. constructor: THREE.Line3,
  2185. set: function ( start, end ) {
  2186. this.start.copy( start );
  2187. this.end.copy( end );
  2188. return this;
  2189. },
  2190. clone: function () {
  2191. return new this.constructor().copy( this );
  2192. },
  2193. copy: function ( line ) {
  2194. this.start.copy( line.start );
  2195. this.end.copy( line.end );
  2196. return this;
  2197. },
  2198. center: function ( optionalTarget ) {
  2199. var result = optionalTarget || new THREE.Vector3();
  2200. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2201. },
  2202. delta: function ( optionalTarget ) {
  2203. var result = optionalTarget || new THREE.Vector3();
  2204. return result.subVectors( this.end, this.start );
  2205. },
  2206. distanceSq: function () {
  2207. return this.start.distanceToSquared( this.end );
  2208. },
  2209. distance: function () {
  2210. return this.start.distanceTo( this.end );
  2211. },
  2212. at: function ( t, optionalTarget ) {
  2213. var result = optionalTarget || new THREE.Vector3();
  2214. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2215. },
  2216. closestPointToPointParameter: function () {
  2217. var startP = new THREE.Vector3();
  2218. var startEnd = new THREE.Vector3();
  2219. return function ( point, clampToLine ) {
  2220. startP.subVectors( point, this.start );
  2221. startEnd.subVectors( this.end, this.start );
  2222. var startEnd2 = startEnd.dot( startEnd );
  2223. var startEnd_startP = startEnd.dot( startP );
  2224. var t = startEnd_startP / startEnd2;
  2225. if ( clampToLine ) {
  2226. t = THREE.Math.clamp( t, 0, 1 );
  2227. }
  2228. return t;
  2229. };
  2230. }(),
  2231. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2232. var t = this.closestPointToPointParameter( point, clampToLine );
  2233. var result = optionalTarget || new THREE.Vector3();
  2234. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2235. },
  2236. applyMatrix4: function ( matrix ) {
  2237. this.start.applyMatrix4( matrix );
  2238. this.end.applyMatrix4( matrix );
  2239. return this;
  2240. },
  2241. equals: function ( line ) {
  2242. return line.start.equals( this.start ) && line.end.equals( this.end );
  2243. }
  2244. };
  2245. // File:src/math/Box2.js
  2246. /**
  2247. * @author bhouston / http://clara.io
  2248. */
  2249. THREE.Box2 = function ( min, max ) {
  2250. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2251. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2252. };
  2253. THREE.Box2.prototype = {
  2254. constructor: THREE.Box2,
  2255. set: function ( min, max ) {
  2256. this.min.copy( min );
  2257. this.max.copy( max );
  2258. return this;
  2259. },
  2260. setFromPoints: function ( points ) {
  2261. this.makeEmpty();
  2262. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2263. this.expandByPoint( points[ i ] )
  2264. }
  2265. return this;
  2266. },
  2267. setFromCenterAndSize: function () {
  2268. var v1 = new THREE.Vector2();
  2269. return function ( center, size ) {
  2270. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2271. this.min.copy( center ).sub( halfSize );
  2272. this.max.copy( center ).add( halfSize );
  2273. return this;
  2274. };
  2275. }(),
  2276. clone: function () {
  2277. return new this.constructor().copy( this );
  2278. },
  2279. copy: function ( box ) {
  2280. this.min.copy( box.min );
  2281. this.max.copy( box.max );
  2282. return this;
  2283. },
  2284. makeEmpty: function () {
  2285. this.min.x = this.min.y = Infinity;
  2286. this.max.x = this.max.y = - Infinity;
  2287. return this;
  2288. },
  2289. empty: function () {
  2290. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2291. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2292. },
  2293. center: function ( optionalTarget ) {
  2294. var result = optionalTarget || new THREE.Vector2();
  2295. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2296. },
  2297. size: function ( optionalTarget ) {
  2298. var result = optionalTarget || new THREE.Vector2();
  2299. return result.subVectors( this.max, this.min );
  2300. },
  2301. expandByPoint: function ( point ) {
  2302. this.min.min( point );
  2303. this.max.max( point );
  2304. return this;
  2305. },
  2306. expandByVector: function ( vector ) {
  2307. this.min.sub( vector );
  2308. this.max.add( vector );
  2309. return this;
  2310. },
  2311. expandByScalar: function ( scalar ) {
  2312. this.min.addScalar( - scalar );
  2313. this.max.addScalar( scalar );
  2314. return this;
  2315. },
  2316. containsPoint: function ( point ) {
  2317. if ( point.x < this.min.x || point.x > this.max.x ||
  2318. point.y < this.min.y || point.y > this.max.y ) {
  2319. return false;
  2320. }
  2321. return true;
  2322. },
  2323. containsBox: function ( box ) {
  2324. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2325. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2326. return true;
  2327. }
  2328. return false;
  2329. },
  2330. getParameter: function ( point, optionalTarget ) {
  2331. // This can potentially have a divide by zero if the box
  2332. // has a size dimension of 0.
  2333. var result = optionalTarget || new THREE.Vector2();
  2334. return result.set(
  2335. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2336. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2337. );
  2338. },
  2339. isIntersectionBox: function ( box ) {
  2340. // using 6 splitting planes to rule out intersections.
  2341. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2342. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2343. return false;
  2344. }
  2345. return true;
  2346. },
  2347. clampPoint: function ( point, optionalTarget ) {
  2348. var result = optionalTarget || new THREE.Vector2();
  2349. return result.copy( point ).clamp( this.min, this.max );
  2350. },
  2351. distanceToPoint: function () {
  2352. var v1 = new THREE.Vector2();
  2353. return function ( point ) {
  2354. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2355. return clampedPoint.sub( point ).length();
  2356. };
  2357. }(),
  2358. intersect: function ( box ) {
  2359. this.min.max( box.min );
  2360. this.max.min( box.max );
  2361. return this;
  2362. },
  2363. union: function ( box ) {
  2364. this.min.min( box.min );
  2365. this.max.max( box.max );
  2366. return this;
  2367. },
  2368. translate: function ( offset ) {
  2369. this.min.add( offset );
  2370. this.max.add( offset );
  2371. return this;
  2372. },
  2373. equals: function ( box ) {
  2374. return box.min.equals( this.min ) && box.max.equals( this.max );
  2375. }
  2376. };
  2377. // File:src/math/Box3.js
  2378. /**
  2379. * @author bhouston / http://clara.io
  2380. * @author WestLangley / http://github.com/WestLangley
  2381. */
  2382. THREE.Box3 = function ( min, max ) {
  2383. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2384. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2385. };
  2386. THREE.Box3.prototype = {
  2387. constructor: THREE.Box3,
  2388. set: function ( min, max ) {
  2389. this.min.copy( min );
  2390. this.max.copy( max );
  2391. return this;
  2392. },
  2393. setFromPoints: function ( points ) {
  2394. this.makeEmpty();
  2395. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2396. this.expandByPoint( points[ i ] );
  2397. }
  2398. return this;
  2399. },
  2400. setFromCenterAndSize: function () {
  2401. var v1 = new THREE.Vector3();
  2402. return function ( center, size ) {
  2403. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2404. this.min.copy( center ).sub( halfSize );
  2405. this.max.copy( center ).add( halfSize );
  2406. return this;
  2407. };
  2408. }(),
  2409. setFromObject: function () {
  2410. // Computes the world-axis-aligned bounding box of an object (including its children),
  2411. // accounting for both the object's, and children's, world transforms
  2412. var v1 = new THREE.Vector3();
  2413. return function ( object ) {
  2414. var scope = this;
  2415. object.updateMatrixWorld( true );
  2416. this.makeEmpty();
  2417. object.traverse( function ( node ) {
  2418. var geometry = node.geometry;
  2419. if ( geometry !== undefined ) {
  2420. if ( geometry instanceof THREE.Geometry ) {
  2421. var vertices = geometry.vertices;
  2422. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2423. v1.copy( vertices[ i ] );
  2424. v1.applyMatrix4( node.matrixWorld );
  2425. scope.expandByPoint( v1 );
  2426. }
  2427. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2428. var positions = geometry.attributes[ 'position' ].array;
  2429. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2430. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2431. v1.applyMatrix4( node.matrixWorld );
  2432. scope.expandByPoint( v1 );
  2433. }
  2434. }
  2435. }
  2436. } );
  2437. return this;
  2438. };
  2439. }(),
  2440. clone: function () {
  2441. return new this.constructor().copy( this );
  2442. },
  2443. copy: function ( box ) {
  2444. this.min.copy( box.min );
  2445. this.max.copy( box.max );
  2446. return this;
  2447. },
  2448. makeEmpty: function () {
  2449. this.min.x = this.min.y = this.min.z = Infinity;
  2450. this.max.x = this.max.y = this.max.z = - Infinity;
  2451. return this;
  2452. },
  2453. empty: function () {
  2454. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2455. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2456. },
  2457. center: function ( optionalTarget ) {
  2458. var result = optionalTarget || new THREE.Vector3();
  2459. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2460. },
  2461. size: function ( optionalTarget ) {
  2462. var result = optionalTarget || new THREE.Vector3();
  2463. return result.subVectors( this.max, this.min );
  2464. },
  2465. expandByPoint: function ( point ) {
  2466. this.min.min( point );
  2467. this.max.max( point );
  2468. return this;
  2469. },
  2470. expandByVector: function ( vector ) {
  2471. this.min.sub( vector );
  2472. this.max.add( vector );
  2473. return this;
  2474. },
  2475. expandByScalar: function ( scalar ) {
  2476. this.min.addScalar( - scalar );
  2477. this.max.addScalar( scalar );
  2478. return this;
  2479. },
  2480. containsPoint: function ( point ) {
  2481. if ( point.x < this.min.x || point.x > this.max.x ||
  2482. point.y < this.min.y || point.y > this.max.y ||
  2483. point.z < this.min.z || point.z > this.max.z ) {
  2484. return false;
  2485. }
  2486. return true;
  2487. },
  2488. containsBox: function ( box ) {
  2489. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2490. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2491. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2492. return true;
  2493. }
  2494. return false;
  2495. },
  2496. getParameter: function ( point, optionalTarget ) {
  2497. // This can potentially have a divide by zero if the box
  2498. // has a size dimension of 0.
  2499. var result = optionalTarget || new THREE.Vector3();
  2500. return result.set(
  2501. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2502. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2503. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2504. );
  2505. },
  2506. isIntersectionBox: function ( box ) {
  2507. // using 6 splitting planes to rule out intersections.
  2508. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2509. box.max.y < this.min.y || box.min.y > this.max.y ||
  2510. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2511. return false;
  2512. }
  2513. return true;
  2514. },
  2515. clampPoint: function ( point, optionalTarget ) {
  2516. var result = optionalTarget || new THREE.Vector3();
  2517. return result.copy( point ).clamp( this.min, this.max );
  2518. },
  2519. distanceToPoint: function () {
  2520. var v1 = new THREE.Vector3();
  2521. return function ( point ) {
  2522. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2523. return clampedPoint.sub( point ).length();
  2524. };
  2525. }(),
  2526. getBoundingSphere: function () {
  2527. var v1 = new THREE.Vector3();
  2528. return function ( optionalTarget ) {
  2529. var result = optionalTarget || new THREE.Sphere();
  2530. result.center = this.center();
  2531. result.radius = this.size( v1 ).length() * 0.5;
  2532. return result;
  2533. };
  2534. }(),
  2535. intersect: function ( box ) {
  2536. this.min.max( box.min );
  2537. this.max.min( box.max );
  2538. return this;
  2539. },
  2540. union: function ( box ) {
  2541. this.min.min( box.min );
  2542. this.max.max( box.max );
  2543. return this;
  2544. },
  2545. applyMatrix4: function () {
  2546. var points = [
  2547. new THREE.Vector3(),
  2548. new THREE.Vector3(),
  2549. new THREE.Vector3(),
  2550. new THREE.Vector3(),
  2551. new THREE.Vector3(),
  2552. new THREE.Vector3(),
  2553. new THREE.Vector3(),
  2554. new THREE.Vector3()
  2555. ];
  2556. return function ( matrix ) {
  2557. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2558. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2559. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2560. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2561. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2562. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2563. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2564. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2565. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2566. this.makeEmpty();
  2567. this.setFromPoints( points );
  2568. return this;
  2569. };
  2570. }(),
  2571. translate: function ( offset ) {
  2572. this.min.add( offset );
  2573. this.max.add( offset );
  2574. return this;
  2575. },
  2576. equals: function ( box ) {
  2577. return box.min.equals( this.min ) && box.max.equals( this.max );
  2578. }
  2579. };
  2580. // File:src/math/Matrix3.js
  2581. /**
  2582. * @author alteredq / http://alteredqualia.com/
  2583. * @author WestLangley / http://github.com/WestLangley
  2584. * @author bhouston / http://clara.io
  2585. */
  2586. THREE.Matrix3 = function () {
  2587. this.elements = new Float32Array( [
  2588. 1, 0, 0,
  2589. 0, 1, 0,
  2590. 0, 0, 1
  2591. ] );
  2592. if ( arguments.length > 0 ) {
  2593. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2594. }
  2595. };
  2596. THREE.Matrix3.prototype = {
  2597. constructor: THREE.Matrix3,
  2598. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2599. var te = this.elements;
  2600. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2601. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2602. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2603. return this;
  2604. },
  2605. identity: function () {
  2606. this.set(
  2607. 1, 0, 0,
  2608. 0, 1, 0,
  2609. 0, 0, 1
  2610. );
  2611. return this;
  2612. },
  2613. clone: function () {
  2614. return new this.constructor().fromArray( this.elements );
  2615. },
  2616. copy: function ( m ) {
  2617. var me = m.elements;
  2618. this.set(
  2619. me[ 0 ], me[ 3 ], me[ 6 ],
  2620. me[ 1 ], me[ 4 ], me[ 7 ],
  2621. me[ 2 ], me[ 5 ], me[ 8 ]
  2622. );
  2623. return this;
  2624. },
  2625. multiplyVector3: function ( vector ) {
  2626. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2627. return vector.applyMatrix3( this );
  2628. },
  2629. multiplyVector3Array: function ( a ) {
  2630. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2631. return this.applyToVector3Array( a );
  2632. },
  2633. applyToVector3Array: function () {
  2634. var v1;
  2635. return function ( array, offset, length ) {
  2636. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2637. if ( offset === undefined ) offset = 0;
  2638. if ( length === undefined ) length = array.length;
  2639. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2640. v1.fromArray( array, j );
  2641. v1.applyMatrix3( this );
  2642. v1.toArray( array, j );
  2643. }
  2644. return array;
  2645. };
  2646. }(),
  2647. applyToBuffer: function () {
  2648. var v1;
  2649. return function applyToBuffer( buffer, offset, length ) {
  2650. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2651. if ( offset === undefined ) offset = 0;
  2652. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2653. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2654. v1.x = buffer.getX( j );
  2655. v1.y = buffer.getY( j );
  2656. v1.z = buffer.getZ( j );
  2657. v1.applyMatrix3( this );
  2658. buffer.setXYZ( v1.x, v1.y, v1.z );
  2659. }
  2660. return buffer;
  2661. };
  2662. }(),
  2663. multiplyScalar: function ( s ) {
  2664. var te = this.elements;
  2665. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2666. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2667. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2668. return this;
  2669. },
  2670. determinant: function () {
  2671. var te = this.elements;
  2672. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2673. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2674. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2675. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2676. },
  2677. getInverse: function ( matrix, throwOnInvertible ) {
  2678. // input: THREE.Matrix4
  2679. // ( based on http://code.google.com/p/webgl-mjs/ )
  2680. var me = matrix.elements;
  2681. var te = this.elements;
  2682. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2683. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2684. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2685. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2686. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2687. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2688. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2689. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2690. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2691. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2692. // no inverse
  2693. if ( det === 0 ) {
  2694. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2695. if ( throwOnInvertible || false ) {
  2696. throw new Error( msg );
  2697. } else {
  2698. console.warn( msg );
  2699. }
  2700. this.identity();
  2701. return this;
  2702. }
  2703. this.multiplyScalar( 1.0 / det );
  2704. return this;
  2705. },
  2706. transpose: function () {
  2707. var tmp, m = this.elements;
  2708. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2709. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2710. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2711. return this;
  2712. },
  2713. flattenToArrayOffset: function ( array, offset ) {
  2714. var te = this.elements;
  2715. array[ offset ] = te[ 0 ];
  2716. array[ offset + 1 ] = te[ 1 ];
  2717. array[ offset + 2 ] = te[ 2 ];
  2718. array[ offset + 3 ] = te[ 3 ];
  2719. array[ offset + 4 ] = te[ 4 ];
  2720. array[ offset + 5 ] = te[ 5 ];
  2721. array[ offset + 6 ] = te[ 6 ];
  2722. array[ offset + 7 ] = te[ 7 ];
  2723. array[ offset + 8 ] = te[ 8 ];
  2724. return array;
  2725. },
  2726. getNormalMatrix: function ( m ) {
  2727. // input: THREE.Matrix4
  2728. this.getInverse( m ).transpose();
  2729. return this;
  2730. },
  2731. transposeIntoArray: function ( r ) {
  2732. var m = this.elements;
  2733. r[ 0 ] = m[ 0 ];
  2734. r[ 1 ] = m[ 3 ];
  2735. r[ 2 ] = m[ 6 ];
  2736. r[ 3 ] = m[ 1 ];
  2737. r[ 4 ] = m[ 4 ];
  2738. r[ 5 ] = m[ 7 ];
  2739. r[ 6 ] = m[ 2 ];
  2740. r[ 7 ] = m[ 5 ];
  2741. r[ 8 ] = m[ 8 ];
  2742. return this;
  2743. },
  2744. fromArray: function ( array ) {
  2745. this.elements.set( array );
  2746. return this;
  2747. },
  2748. toArray: function () {
  2749. var te = this.elements;
  2750. return [
  2751. te[ 0 ], te[ 1 ], te[ 2 ],
  2752. te[ 3 ], te[ 4 ], te[ 5 ],
  2753. te[ 6 ], te[ 7 ], te[ 8 ]
  2754. ];
  2755. }
  2756. };
  2757. // File:src/math/Matrix4.js
  2758. /**
  2759. * @author mrdoob / http://mrdoob.com/
  2760. * @author supereggbert / http://www.paulbrunt.co.uk/
  2761. * @author philogb / http://blog.thejit.org/
  2762. * @author jordi_ros / http://plattsoft.com
  2763. * @author D1plo1d / http://github.com/D1plo1d
  2764. * @author alteredq / http://alteredqualia.com/
  2765. * @author mikael emtinger / http://gomo.se/
  2766. * @author timknip / http://www.floorplanner.com/
  2767. * @author bhouston / http://clara.io
  2768. * @author WestLangley / http://github.com/WestLangley
  2769. */
  2770. THREE.Matrix4 = function () {
  2771. this.elements = new Float32Array( [
  2772. 1, 0, 0, 0,
  2773. 0, 1, 0, 0,
  2774. 0, 0, 1, 0,
  2775. 0, 0, 0, 1
  2776. ] );
  2777. if ( arguments.length > 0 ) {
  2778. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2779. }
  2780. };
  2781. THREE.Matrix4.prototype = {
  2782. constructor: THREE.Matrix4,
  2783. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2784. var te = this.elements;
  2785. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2786. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2787. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2788. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2789. return this;
  2790. },
  2791. identity: function () {
  2792. this.set(
  2793. 1, 0, 0, 0,
  2794. 0, 1, 0, 0,
  2795. 0, 0, 1, 0,
  2796. 0, 0, 0, 1
  2797. );
  2798. return this;
  2799. },
  2800. clone: function () {
  2801. return new THREE.Matrix4().fromArray( this.elements );
  2802. },
  2803. copy: function ( m ) {
  2804. this.elements.set( m.elements );
  2805. return this;
  2806. },
  2807. extractPosition: function ( m ) {
  2808. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2809. return this.copyPosition( m );
  2810. },
  2811. copyPosition: function ( m ) {
  2812. var te = this.elements;
  2813. var me = m.elements;
  2814. te[ 12 ] = me[ 12 ];
  2815. te[ 13 ] = me[ 13 ];
  2816. te[ 14 ] = me[ 14 ];
  2817. return this;
  2818. },
  2819. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2820. var te = this.elements;
  2821. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2822. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2823. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2824. return this;
  2825. },
  2826. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2827. this.set(
  2828. xAxis.x, yAxis.x, zAxis.x, 0,
  2829. xAxis.y, yAxis.y, zAxis.y, 0,
  2830. xAxis.z, yAxis.z, zAxis.z, 0,
  2831. 0, 0, 0, 1
  2832. );
  2833. return this;
  2834. },
  2835. extractRotation: function () {
  2836. var v1;
  2837. return function ( m ) {
  2838. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2839. var te = this.elements;
  2840. var me = m.elements;
  2841. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2842. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2843. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2844. te[ 0 ] = me[ 0 ] * scaleX;
  2845. te[ 1 ] = me[ 1 ] * scaleX;
  2846. te[ 2 ] = me[ 2 ] * scaleX;
  2847. te[ 4 ] = me[ 4 ] * scaleY;
  2848. te[ 5 ] = me[ 5 ] * scaleY;
  2849. te[ 6 ] = me[ 6 ] * scaleY;
  2850. te[ 8 ] = me[ 8 ] * scaleZ;
  2851. te[ 9 ] = me[ 9 ] * scaleZ;
  2852. te[ 10 ] = me[ 10 ] * scaleZ;
  2853. return this;
  2854. };
  2855. }(),
  2856. makeRotationFromEuler: function ( euler ) {
  2857. if ( euler instanceof THREE.Euler === false ) {
  2858. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2859. }
  2860. var te = this.elements;
  2861. var x = euler.x, y = euler.y, z = euler.z;
  2862. var a = Math.cos( x ), b = Math.sin( x );
  2863. var c = Math.cos( y ), d = Math.sin( y );
  2864. var e = Math.cos( z ), f = Math.sin( z );
  2865. if ( euler.order === 'XYZ' ) {
  2866. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2867. te[ 0 ] = c * e;
  2868. te[ 4 ] = - c * f;
  2869. te[ 8 ] = d;
  2870. te[ 1 ] = af + be * d;
  2871. te[ 5 ] = ae - bf * d;
  2872. te[ 9 ] = - b * c;
  2873. te[ 2 ] = bf - ae * d;
  2874. te[ 6 ] = be + af * d;
  2875. te[ 10 ] = a * c;
  2876. } else if ( euler.order === 'YXZ' ) {
  2877. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2878. te[ 0 ] = ce + df * b;
  2879. te[ 4 ] = de * b - cf;
  2880. te[ 8 ] = a * d;
  2881. te[ 1 ] = a * f;
  2882. te[ 5 ] = a * e;
  2883. te[ 9 ] = - b;
  2884. te[ 2 ] = cf * b - de;
  2885. te[ 6 ] = df + ce * b;
  2886. te[ 10 ] = a * c;
  2887. } else if ( euler.order === 'ZXY' ) {
  2888. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2889. te[ 0 ] = ce - df * b;
  2890. te[ 4 ] = - a * f;
  2891. te[ 8 ] = de + cf * b;
  2892. te[ 1 ] = cf + de * b;
  2893. te[ 5 ] = a * e;
  2894. te[ 9 ] = df - ce * b;
  2895. te[ 2 ] = - a * d;
  2896. te[ 6 ] = b;
  2897. te[ 10 ] = a * c;
  2898. } else if ( euler.order === 'ZYX' ) {
  2899. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2900. te[ 0 ] = c * e;
  2901. te[ 4 ] = be * d - af;
  2902. te[ 8 ] = ae * d + bf;
  2903. te[ 1 ] = c * f;
  2904. te[ 5 ] = bf * d + ae;
  2905. te[ 9 ] = af * d - be;
  2906. te[ 2 ] = - d;
  2907. te[ 6 ] = b * c;
  2908. te[ 10 ] = a * c;
  2909. } else if ( euler.order === 'YZX' ) {
  2910. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2911. te[ 0 ] = c * e;
  2912. te[ 4 ] = bd - ac * f;
  2913. te[ 8 ] = bc * f + ad;
  2914. te[ 1 ] = f;
  2915. te[ 5 ] = a * e;
  2916. te[ 9 ] = - b * e;
  2917. te[ 2 ] = - d * e;
  2918. te[ 6 ] = ad * f + bc;
  2919. te[ 10 ] = ac - bd * f;
  2920. } else if ( euler.order === 'XZY' ) {
  2921. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2922. te[ 0 ] = c * e;
  2923. te[ 4 ] = - f;
  2924. te[ 8 ] = d * e;
  2925. te[ 1 ] = ac * f + bd;
  2926. te[ 5 ] = a * e;
  2927. te[ 9 ] = ad * f - bc;
  2928. te[ 2 ] = bc * f - ad;
  2929. te[ 6 ] = b * e;
  2930. te[ 10 ] = bd * f + ac;
  2931. }
  2932. // last column
  2933. te[ 3 ] = 0;
  2934. te[ 7 ] = 0;
  2935. te[ 11 ] = 0;
  2936. // bottom row
  2937. te[ 12 ] = 0;
  2938. te[ 13 ] = 0;
  2939. te[ 14 ] = 0;
  2940. te[ 15 ] = 1;
  2941. return this;
  2942. },
  2943. setRotationFromQuaternion: function ( q ) {
  2944. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2945. return this.makeRotationFromQuaternion( q );
  2946. },
  2947. makeRotationFromQuaternion: function ( q ) {
  2948. var te = this.elements;
  2949. var x = q.x, y = q.y, z = q.z, w = q.w;
  2950. var x2 = x + x, y2 = y + y, z2 = z + z;
  2951. var xx = x * x2, xy = x * y2, xz = x * z2;
  2952. var yy = y * y2, yz = y * z2, zz = z * z2;
  2953. var wx = w * x2, wy = w * y2, wz = w * z2;
  2954. te[ 0 ] = 1 - ( yy + zz );
  2955. te[ 4 ] = xy - wz;
  2956. te[ 8 ] = xz + wy;
  2957. te[ 1 ] = xy + wz;
  2958. te[ 5 ] = 1 - ( xx + zz );
  2959. te[ 9 ] = yz - wx;
  2960. te[ 2 ] = xz - wy;
  2961. te[ 6 ] = yz + wx;
  2962. te[ 10 ] = 1 - ( xx + yy );
  2963. // last column
  2964. te[ 3 ] = 0;
  2965. te[ 7 ] = 0;
  2966. te[ 11 ] = 0;
  2967. // bottom row
  2968. te[ 12 ] = 0;
  2969. te[ 13 ] = 0;
  2970. te[ 14 ] = 0;
  2971. te[ 15 ] = 1;
  2972. return this;
  2973. },
  2974. lookAt: function () {
  2975. var x, y, z;
  2976. return function ( eye, target, up ) {
  2977. if ( x === undefined ) x = new THREE.Vector3();
  2978. if ( y === undefined ) y = new THREE.Vector3();
  2979. if ( z === undefined ) z = new THREE.Vector3();
  2980. var te = this.elements;
  2981. z.subVectors( eye, target ).normalize();
  2982. if ( z.length() === 0 ) {
  2983. z.z = 1;
  2984. }
  2985. x.crossVectors( up, z ).normalize();
  2986. if ( x.length() === 0 ) {
  2987. z.x += 0.0001;
  2988. x.crossVectors( up, z ).normalize();
  2989. }
  2990. y.crossVectors( z, x );
  2991. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2992. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2993. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2994. return this;
  2995. };
  2996. }(),
  2997. multiply: function ( m, n ) {
  2998. if ( n !== undefined ) {
  2999. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3000. return this.multiplyMatrices( m, n );
  3001. }
  3002. return this.multiplyMatrices( this, m );
  3003. },
  3004. multiplyMatrices: function ( a, b ) {
  3005. var ae = a.elements;
  3006. var be = b.elements;
  3007. var te = this.elements;
  3008. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3009. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3010. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3011. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3012. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3013. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3014. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3015. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3016. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3017. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3018. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3019. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3020. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3021. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3022. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3023. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3024. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3025. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3026. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3027. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3028. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3029. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3030. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3031. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3032. return this;
  3033. },
  3034. multiplyToArray: function ( a, b, r ) {
  3035. var te = this.elements;
  3036. this.multiplyMatrices( a, b );
  3037. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3038. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3039. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3040. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3041. return this;
  3042. },
  3043. multiplyScalar: function ( s ) {
  3044. var te = this.elements;
  3045. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3046. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3047. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3048. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3049. return this;
  3050. },
  3051. multiplyVector3: function ( vector ) {
  3052. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3053. return vector.applyProjection( this );
  3054. },
  3055. multiplyVector4: function ( vector ) {
  3056. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3057. return vector.applyMatrix4( this );
  3058. },
  3059. multiplyVector3Array: function ( a ) {
  3060. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3061. return this.applyToVector3Array( a );
  3062. },
  3063. applyToVector3Array: function () {
  3064. var v1;
  3065. return function ( array, offset, length ) {
  3066. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3067. if ( offset === undefined ) offset = 0;
  3068. if ( length === undefined ) length = array.length;
  3069. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3070. v1.fromArray( array, j );
  3071. v1.applyMatrix4( this );
  3072. v1.toArray( array, j );
  3073. }
  3074. return array;
  3075. };
  3076. }(),
  3077. applyToBuffer: function () {
  3078. var v1;
  3079. return function applyToBuffer( buffer, offset, length ) {
  3080. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3081. if ( offset === undefined ) offset = 0;
  3082. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3083. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3084. v1.x = buffer.getX( j );
  3085. v1.y = buffer.getY( j );
  3086. v1.z = buffer.getZ( j );
  3087. v1.applyMatrix4( this );
  3088. buffer.setXYZ( v1.x, v1.y, v1.z );
  3089. }
  3090. return buffer;
  3091. };
  3092. }(),
  3093. rotateAxis: function ( v ) {
  3094. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3095. v.transformDirection( this );
  3096. },
  3097. crossVector: function ( vector ) {
  3098. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3099. return vector.applyMatrix4( this );
  3100. },
  3101. determinant: function () {
  3102. var te = this.elements;
  3103. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3104. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3105. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3106. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3107. //TODO: make this more efficient
  3108. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3109. return (
  3110. n41 * (
  3111. + n14 * n23 * n32
  3112. - n13 * n24 * n32
  3113. - n14 * n22 * n33
  3114. + n12 * n24 * n33
  3115. + n13 * n22 * n34
  3116. - n12 * n23 * n34
  3117. ) +
  3118. n42 * (
  3119. + n11 * n23 * n34
  3120. - n11 * n24 * n33
  3121. + n14 * n21 * n33
  3122. - n13 * n21 * n34
  3123. + n13 * n24 * n31
  3124. - n14 * n23 * n31
  3125. ) +
  3126. n43 * (
  3127. + n11 * n24 * n32
  3128. - n11 * n22 * n34
  3129. - n14 * n21 * n32
  3130. + n12 * n21 * n34
  3131. + n14 * n22 * n31
  3132. - n12 * n24 * n31
  3133. ) +
  3134. n44 * (
  3135. - n13 * n22 * n31
  3136. - n11 * n23 * n32
  3137. + n11 * n22 * n33
  3138. + n13 * n21 * n32
  3139. - n12 * n21 * n33
  3140. + n12 * n23 * n31
  3141. )
  3142. );
  3143. },
  3144. transpose: function () {
  3145. var te = this.elements;
  3146. var tmp;
  3147. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3148. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3149. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3150. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3151. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3152. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3153. return this;
  3154. },
  3155. flattenToArrayOffset: function ( array, offset ) {
  3156. var te = this.elements;
  3157. array[ offset ] = te[ 0 ];
  3158. array[ offset + 1 ] = te[ 1 ];
  3159. array[ offset + 2 ] = te[ 2 ];
  3160. array[ offset + 3 ] = te[ 3 ];
  3161. array[ offset + 4 ] = te[ 4 ];
  3162. array[ offset + 5 ] = te[ 5 ];
  3163. array[ offset + 6 ] = te[ 6 ];
  3164. array[ offset + 7 ] = te[ 7 ];
  3165. array[ offset + 8 ] = te[ 8 ];
  3166. array[ offset + 9 ] = te[ 9 ];
  3167. array[ offset + 10 ] = te[ 10 ];
  3168. array[ offset + 11 ] = te[ 11 ];
  3169. array[ offset + 12 ] = te[ 12 ];
  3170. array[ offset + 13 ] = te[ 13 ];
  3171. array[ offset + 14 ] = te[ 14 ];
  3172. array[ offset + 15 ] = te[ 15 ];
  3173. return array;
  3174. },
  3175. getPosition: function () {
  3176. var v1;
  3177. return function () {
  3178. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3179. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3180. var te = this.elements;
  3181. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3182. };
  3183. }(),
  3184. setPosition: function ( v ) {
  3185. var te = this.elements;
  3186. te[ 12 ] = v.x;
  3187. te[ 13 ] = v.y;
  3188. te[ 14 ] = v.z;
  3189. return this;
  3190. },
  3191. getInverse: function ( m, throwOnInvertible ) {
  3192. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3193. var te = this.elements;
  3194. var me = m.elements;
  3195. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3196. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3197. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3198. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3199. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3200. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3201. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3202. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3203. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3204. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3205. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3206. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3207. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3208. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3209. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3210. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3211. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3212. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3213. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3214. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3215. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3216. if ( det === 0 ) {
  3217. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3218. if ( throwOnInvertible || false ) {
  3219. throw new Error( msg );
  3220. } else {
  3221. console.warn( msg );
  3222. }
  3223. this.identity();
  3224. return this;
  3225. }
  3226. this.multiplyScalar( 1 / det );
  3227. return this;
  3228. },
  3229. translate: function ( v ) {
  3230. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3231. },
  3232. rotateX: function ( angle ) {
  3233. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3234. },
  3235. rotateY: function ( angle ) {
  3236. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3237. },
  3238. rotateZ: function ( angle ) {
  3239. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3240. },
  3241. rotateByAxis: function ( axis, angle ) {
  3242. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3243. },
  3244. scale: function ( v ) {
  3245. var te = this.elements;
  3246. var x = v.x, y = v.y, z = v.z;
  3247. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3248. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3249. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3250. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3251. return this;
  3252. },
  3253. getMaxScaleOnAxis: function () {
  3254. var te = this.elements;
  3255. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3256. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3257. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3258. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3259. },
  3260. makeTranslation: function ( x, y, z ) {
  3261. this.set(
  3262. 1, 0, 0, x,
  3263. 0, 1, 0, y,
  3264. 0, 0, 1, z,
  3265. 0, 0, 0, 1
  3266. );
  3267. return this;
  3268. },
  3269. makeRotationX: function ( theta ) {
  3270. var c = Math.cos( theta ), s = Math.sin( theta );
  3271. this.set(
  3272. 1, 0, 0, 0,
  3273. 0, c, - s, 0,
  3274. 0, s, c, 0,
  3275. 0, 0, 0, 1
  3276. );
  3277. return this;
  3278. },
  3279. makeRotationY: function ( theta ) {
  3280. var c = Math.cos( theta ), s = Math.sin( theta );
  3281. this.set(
  3282. c, 0, s, 0,
  3283. 0, 1, 0, 0,
  3284. - s, 0, c, 0,
  3285. 0, 0, 0, 1
  3286. );
  3287. return this;
  3288. },
  3289. makeRotationZ: function ( theta ) {
  3290. var c = Math.cos( theta ), s = Math.sin( theta );
  3291. this.set(
  3292. c, - s, 0, 0,
  3293. s, c, 0, 0,
  3294. 0, 0, 1, 0,
  3295. 0, 0, 0, 1
  3296. );
  3297. return this;
  3298. },
  3299. makeRotationAxis: function ( axis, angle ) {
  3300. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3301. var c = Math.cos( angle );
  3302. var s = Math.sin( angle );
  3303. var t = 1 - c;
  3304. var x = axis.x, y = axis.y, z = axis.z;
  3305. var tx = t * x, ty = t * y;
  3306. this.set(
  3307. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3308. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3309. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3310. 0, 0, 0, 1
  3311. );
  3312. return this;
  3313. },
  3314. makeScale: function ( x, y, z ) {
  3315. this.set(
  3316. x, 0, 0, 0,
  3317. 0, y, 0, 0,
  3318. 0, 0, z, 0,
  3319. 0, 0, 0, 1
  3320. );
  3321. return this;
  3322. },
  3323. compose: function ( position, quaternion, scale ) {
  3324. this.makeRotationFromQuaternion( quaternion );
  3325. this.scale( scale );
  3326. this.setPosition( position );
  3327. return this;
  3328. },
  3329. decompose: function () {
  3330. var vector, matrix;
  3331. return function ( position, quaternion, scale ) {
  3332. if ( vector === undefined ) vector = new THREE.Vector3();
  3333. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3334. var te = this.elements;
  3335. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3336. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3337. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3338. // if determine is negative, we need to invert one scale
  3339. var det = this.determinant();
  3340. if ( det < 0 ) {
  3341. sx = - sx;
  3342. }
  3343. position.x = te[ 12 ];
  3344. position.y = te[ 13 ];
  3345. position.z = te[ 14 ];
  3346. // scale the rotation part
  3347. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3348. var invSX = 1 / sx;
  3349. var invSY = 1 / sy;
  3350. var invSZ = 1 / sz;
  3351. matrix.elements[ 0 ] *= invSX;
  3352. matrix.elements[ 1 ] *= invSX;
  3353. matrix.elements[ 2 ] *= invSX;
  3354. matrix.elements[ 4 ] *= invSY;
  3355. matrix.elements[ 5 ] *= invSY;
  3356. matrix.elements[ 6 ] *= invSY;
  3357. matrix.elements[ 8 ] *= invSZ;
  3358. matrix.elements[ 9 ] *= invSZ;
  3359. matrix.elements[ 10 ] *= invSZ;
  3360. quaternion.setFromRotationMatrix( matrix );
  3361. scale.x = sx;
  3362. scale.y = sy;
  3363. scale.z = sz;
  3364. return this;
  3365. };
  3366. }(),
  3367. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3368. var te = this.elements;
  3369. var x = 2 * near / ( right - left );
  3370. var y = 2 * near / ( top - bottom );
  3371. var a = ( right + left ) / ( right - left );
  3372. var b = ( top + bottom ) / ( top - bottom );
  3373. var c = - ( far + near ) / ( far - near );
  3374. var d = - 2 * far * near / ( far - near );
  3375. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3376. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3377. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3378. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3379. return this;
  3380. },
  3381. makePerspective: function ( fov, aspect, near, far ) {
  3382. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3383. var ymin = - ymax;
  3384. var xmin = ymin * aspect;
  3385. var xmax = ymax * aspect;
  3386. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3387. },
  3388. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3389. var te = this.elements;
  3390. var w = right - left;
  3391. var h = top - bottom;
  3392. var p = far - near;
  3393. var x = ( right + left ) / w;
  3394. var y = ( top + bottom ) / h;
  3395. var z = ( far + near ) / p;
  3396. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3397. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3398. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3399. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3400. return this;
  3401. },
  3402. equals: function ( matrix ) {
  3403. var te = this.elements;
  3404. var me = matrix.elements;
  3405. for ( var i = 0; i < 16; i ++ ) {
  3406. if ( te[ i ] !== me[ i ] ) return false;
  3407. }
  3408. return true;
  3409. },
  3410. fromArray: function ( array ) {
  3411. this.elements.set( array );
  3412. return this;
  3413. },
  3414. toArray: function () {
  3415. var te = this.elements;
  3416. return [
  3417. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3418. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3419. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3420. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3421. ];
  3422. }
  3423. };
  3424. // File:src/math/Ray.js
  3425. /**
  3426. * @author bhouston / http://clara.io
  3427. */
  3428. THREE.Ray = function ( origin, direction ) {
  3429. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3430. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3431. };
  3432. THREE.Ray.prototype = {
  3433. constructor: THREE.Ray,
  3434. set: function ( origin, direction ) {
  3435. this.origin.copy( origin );
  3436. this.direction.copy( direction );
  3437. return this;
  3438. },
  3439. clone: function () {
  3440. return new this.constructor().copy( this );
  3441. },
  3442. copy: function ( ray ) {
  3443. this.origin.copy( ray.origin );
  3444. this.direction.copy( ray.direction );
  3445. return this;
  3446. },
  3447. at: function ( t, optionalTarget ) {
  3448. var result = optionalTarget || new THREE.Vector3();
  3449. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3450. },
  3451. recast: function () {
  3452. var v1 = new THREE.Vector3();
  3453. return function ( t ) {
  3454. this.origin.copy( this.at( t, v1 ) );
  3455. return this;
  3456. };
  3457. }(),
  3458. closestPointToPoint: function ( point, optionalTarget ) {
  3459. var result = optionalTarget || new THREE.Vector3();
  3460. result.subVectors( point, this.origin );
  3461. var directionDistance = result.dot( this.direction );
  3462. if ( directionDistance < 0 ) {
  3463. return result.copy( this.origin );
  3464. }
  3465. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3466. },
  3467. distanceToPoint: function ( point ) {
  3468. return Math.sqrt( this.distanceSqToPoint( point ) );
  3469. },
  3470. distanceSqToPoint: function () {
  3471. var v1 = new THREE.Vector3();
  3472. return function ( point ) {
  3473. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3474. // point behind the ray
  3475. if ( directionDistance < 0 ) {
  3476. return this.origin.distanceToSquared( point );
  3477. }
  3478. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3479. return v1.distanceToSquared( point );
  3480. };
  3481. }(),
  3482. distanceSqToSegment: function () {
  3483. var segCenter = new THREE.Vector3();
  3484. var segDir = new THREE.Vector3();
  3485. var diff = new THREE.Vector3();
  3486. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3487. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3488. // It returns the min distance between the ray and the segment
  3489. // defined by v0 and v1
  3490. // It can also set two optional targets :
  3491. // - The closest point on the ray
  3492. // - The closest point on the segment
  3493. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3494. segDir.copy( v1 ).sub( v0 ).normalize();
  3495. diff.copy( this.origin ).sub( segCenter );
  3496. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3497. var a01 = - this.direction.dot( segDir );
  3498. var b0 = diff.dot( this.direction );
  3499. var b1 = - diff.dot( segDir );
  3500. var c = diff.lengthSq();
  3501. var det = Math.abs( 1 - a01 * a01 );
  3502. var s0, s1, sqrDist, extDet;
  3503. if ( det > 0 ) {
  3504. // The ray and segment are not parallel.
  3505. s0 = a01 * b1 - b0;
  3506. s1 = a01 * b0 - b1;
  3507. extDet = segExtent * det;
  3508. if ( s0 >= 0 ) {
  3509. if ( s1 >= - extDet ) {
  3510. if ( s1 <= extDet ) {
  3511. // region 0
  3512. // Minimum at interior points of ray and segment.
  3513. var invDet = 1 / det;
  3514. s0 *= invDet;
  3515. s1 *= invDet;
  3516. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3517. } else {
  3518. // region 1
  3519. s1 = segExtent;
  3520. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3521. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3522. }
  3523. } else {
  3524. // region 5
  3525. s1 = - segExtent;
  3526. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3527. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3528. }
  3529. } else {
  3530. if ( s1 <= - extDet ) {
  3531. // region 4
  3532. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3533. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3535. } else if ( s1 <= extDet ) {
  3536. // region 3
  3537. s0 = 0;
  3538. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3539. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3540. } else {
  3541. // region 2
  3542. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3543. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3544. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3545. }
  3546. }
  3547. } else {
  3548. // Ray and segment are parallel.
  3549. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3550. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3551. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3552. }
  3553. if ( optionalPointOnRay ) {
  3554. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3555. }
  3556. if ( optionalPointOnSegment ) {
  3557. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3558. }
  3559. return sqrDist;
  3560. };
  3561. }(),
  3562. isIntersectionSphere: function ( sphere ) {
  3563. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3564. },
  3565. intersectSphere: function () {
  3566. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3567. var v1 = new THREE.Vector3();
  3568. return function ( sphere, optionalTarget ) {
  3569. v1.subVectors( sphere.center, this.origin );
  3570. var tca = v1.dot( this.direction );
  3571. var d2 = v1.dot( v1 ) - tca * tca;
  3572. var radius2 = sphere.radius * sphere.radius;
  3573. if ( d2 > radius2 ) return null;
  3574. var thc = Math.sqrt( radius2 - d2 );
  3575. // t0 = first intersect point - entrance on front of sphere
  3576. var t0 = tca - thc;
  3577. // t1 = second intersect point - exit point on back of sphere
  3578. var t1 = tca + thc;
  3579. // test to see if both t0 and t1 are behind the ray - if so, return null
  3580. if ( t0 < 0 && t1 < 0 ) return null;
  3581. // test to see if t0 is behind the ray:
  3582. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3583. // in order to always return an intersect point that is in front of the ray.
  3584. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3585. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3586. return this.at( t0, optionalTarget );
  3587. }
  3588. }(),
  3589. isIntersectionPlane: function ( plane ) {
  3590. // check if the ray lies on the plane first
  3591. var distToPoint = plane.distanceToPoint( this.origin );
  3592. if ( distToPoint === 0 ) {
  3593. return true;
  3594. }
  3595. var denominator = plane.normal.dot( this.direction );
  3596. if ( denominator * distToPoint < 0 ) {
  3597. return true;
  3598. }
  3599. // ray origin is behind the plane (and is pointing behind it)
  3600. return false;
  3601. },
  3602. distanceToPlane: function ( plane ) {
  3603. var denominator = plane.normal.dot( this.direction );
  3604. if ( denominator === 0 ) {
  3605. // line is coplanar, return origin
  3606. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3607. return 0;
  3608. }
  3609. // Null is preferable to undefined since undefined means.... it is undefined
  3610. return null;
  3611. }
  3612. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3613. // Return if the ray never intersects the plane
  3614. return t >= 0 ? t : null;
  3615. },
  3616. intersectPlane: function ( plane, optionalTarget ) {
  3617. var t = this.distanceToPlane( plane );
  3618. if ( t === null ) {
  3619. return null;
  3620. }
  3621. return this.at( t, optionalTarget );
  3622. },
  3623. isIntersectionBox: function () {
  3624. var v = new THREE.Vector3();
  3625. return function ( box ) {
  3626. return this.intersectBox( box, v ) !== null;
  3627. };
  3628. }(),
  3629. intersectBox: function ( box, optionalTarget ) {
  3630. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3631. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3632. var invdirx = 1 / this.direction.x,
  3633. invdiry = 1 / this.direction.y,
  3634. invdirz = 1 / this.direction.z;
  3635. var origin = this.origin;
  3636. if ( invdirx >= 0 ) {
  3637. tmin = ( box.min.x - origin.x ) * invdirx;
  3638. tmax = ( box.max.x - origin.x ) * invdirx;
  3639. } else {
  3640. tmin = ( box.max.x - origin.x ) * invdirx;
  3641. tmax = ( box.min.x - origin.x ) * invdirx;
  3642. }
  3643. if ( invdiry >= 0 ) {
  3644. tymin = ( box.min.y - origin.y ) * invdiry;
  3645. tymax = ( box.max.y - origin.y ) * invdiry;
  3646. } else {
  3647. tymin = ( box.max.y - origin.y ) * invdiry;
  3648. tymax = ( box.min.y - origin.y ) * invdiry;
  3649. }
  3650. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3651. // These lines also handle the case where tmin or tmax is NaN
  3652. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3653. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3654. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3655. if ( invdirz >= 0 ) {
  3656. tzmin = ( box.min.z - origin.z ) * invdirz;
  3657. tzmax = ( box.max.z - origin.z ) * invdirz;
  3658. } else {
  3659. tzmin = ( box.max.z - origin.z ) * invdirz;
  3660. tzmax = ( box.min.z - origin.z ) * invdirz;
  3661. }
  3662. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3663. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3664. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3665. //return point closest to the ray (positive side)
  3666. if ( tmax < 0 ) return null;
  3667. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3668. },
  3669. intersectTriangle: function () {
  3670. // Compute the offset origin, edges, and normal.
  3671. var diff = new THREE.Vector3();
  3672. var edge1 = new THREE.Vector3();
  3673. var edge2 = new THREE.Vector3();
  3674. var normal = new THREE.Vector3();
  3675. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3676. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3677. edge1.subVectors( b, a );
  3678. edge2.subVectors( c, a );
  3679. normal.crossVectors( edge1, edge2 );
  3680. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3681. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3682. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3683. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3684. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3685. var DdN = this.direction.dot( normal );
  3686. var sign;
  3687. if ( DdN > 0 ) {
  3688. if ( backfaceCulling ) return null;
  3689. sign = 1;
  3690. } else if ( DdN < 0 ) {
  3691. sign = - 1;
  3692. DdN = - DdN;
  3693. } else {
  3694. return null;
  3695. }
  3696. diff.subVectors( this.origin, a );
  3697. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3698. // b1 < 0, no intersection
  3699. if ( DdQxE2 < 0 ) {
  3700. return null;
  3701. }
  3702. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3703. // b2 < 0, no intersection
  3704. if ( DdE1xQ < 0 ) {
  3705. return null;
  3706. }
  3707. // b1+b2 > 1, no intersection
  3708. if ( DdQxE2 + DdE1xQ > DdN ) {
  3709. return null;
  3710. }
  3711. // Line intersects triangle, check if ray does.
  3712. var QdN = - sign * diff.dot( normal );
  3713. // t < 0, no intersection
  3714. if ( QdN < 0 ) {
  3715. return null;
  3716. }
  3717. // Ray intersects triangle.
  3718. return this.at( QdN / DdN, optionalTarget );
  3719. };
  3720. }(),
  3721. applyMatrix4: function ( matrix4 ) {
  3722. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3723. this.origin.applyMatrix4( matrix4 );
  3724. this.direction.sub( this.origin );
  3725. this.direction.normalize();
  3726. return this;
  3727. },
  3728. equals: function ( ray ) {
  3729. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3730. }
  3731. };
  3732. // File:src/math/Sphere.js
  3733. /**
  3734. * @author bhouston / http://clara.io
  3735. * @author mrdoob / http://mrdoob.com/
  3736. */
  3737. THREE.Sphere = function ( center, radius ) {
  3738. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3739. this.radius = ( radius !== undefined ) ? radius : 0;
  3740. };
  3741. THREE.Sphere.prototype = {
  3742. constructor: THREE.Sphere,
  3743. set: function ( center, radius ) {
  3744. this.center.copy( center );
  3745. this.radius = radius;
  3746. return this;
  3747. },
  3748. setFromPoints: function () {
  3749. var box = new THREE.Box3();
  3750. return function ( points, optionalCenter ) {
  3751. var center = this.center;
  3752. if ( optionalCenter !== undefined ) {
  3753. center.copy( optionalCenter );
  3754. } else {
  3755. box.setFromPoints( points ).center( center );
  3756. }
  3757. var maxRadiusSq = 0;
  3758. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3759. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3760. }
  3761. this.radius = Math.sqrt( maxRadiusSq );
  3762. return this;
  3763. };
  3764. }(),
  3765. clone: function () {
  3766. return new this.constructor().copy( this );
  3767. },
  3768. copy: function ( sphere ) {
  3769. this.center.copy( sphere.center );
  3770. this.radius = sphere.radius;
  3771. return this;
  3772. },
  3773. empty: function () {
  3774. return ( this.radius <= 0 );
  3775. },
  3776. containsPoint: function ( point ) {
  3777. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3778. },
  3779. distanceToPoint: function ( point ) {
  3780. return ( point.distanceTo( this.center ) - this.radius );
  3781. },
  3782. intersectsSphere: function ( sphere ) {
  3783. var radiusSum = this.radius + sphere.radius;
  3784. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3785. },
  3786. clampPoint: function ( point, optionalTarget ) {
  3787. var deltaLengthSq = this.center.distanceToSquared( point );
  3788. var result = optionalTarget || new THREE.Vector3();
  3789. result.copy( point );
  3790. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3791. result.sub( this.center ).normalize();
  3792. result.multiplyScalar( this.radius ).add( this.center );
  3793. }
  3794. return result;
  3795. },
  3796. getBoundingBox: function ( optionalTarget ) {
  3797. var box = optionalTarget || new THREE.Box3();
  3798. box.set( this.center, this.center );
  3799. box.expandByScalar( this.radius );
  3800. return box;
  3801. },
  3802. applyMatrix4: function ( matrix ) {
  3803. this.center.applyMatrix4( matrix );
  3804. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3805. return this;
  3806. },
  3807. translate: function ( offset ) {
  3808. this.center.add( offset );
  3809. return this;
  3810. },
  3811. equals: function ( sphere ) {
  3812. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3813. }
  3814. };
  3815. // File:src/math/Frustum.js
  3816. /**
  3817. * @author mrdoob / http://mrdoob.com/
  3818. * @author alteredq / http://alteredqualia.com/
  3819. * @author bhouston / http://clara.io
  3820. */
  3821. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3822. this.planes = [
  3823. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3824. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3825. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3826. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3827. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3828. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3829. ];
  3830. };
  3831. THREE.Frustum.prototype = {
  3832. constructor: THREE.Frustum,
  3833. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3834. var planes = this.planes;
  3835. planes[ 0 ].copy( p0 );
  3836. planes[ 1 ].copy( p1 );
  3837. planes[ 2 ].copy( p2 );
  3838. planes[ 3 ].copy( p3 );
  3839. planes[ 4 ].copy( p4 );
  3840. planes[ 5 ].copy( p5 );
  3841. return this;
  3842. },
  3843. clone: function () {
  3844. return new this.constructor().copy( this );
  3845. },
  3846. copy: function ( frustum ) {
  3847. var planes = this.planes;
  3848. for ( var i = 0; i < 6; i ++ ) {
  3849. planes[ i ].copy( frustum.planes[ i ] );
  3850. }
  3851. return this;
  3852. },
  3853. setFromMatrix: function ( m ) {
  3854. var planes = this.planes;
  3855. var me = m.elements;
  3856. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3857. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3858. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3859. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3860. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3861. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3862. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3863. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3864. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3865. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3866. return this;
  3867. },
  3868. intersectsObject: function () {
  3869. var sphere = new THREE.Sphere();
  3870. return function ( object ) {
  3871. var geometry = object.geometry;
  3872. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3873. sphere.copy( geometry.boundingSphere );
  3874. sphere.applyMatrix4( object.matrixWorld );
  3875. return this.intersectsSphere( sphere );
  3876. };
  3877. }(),
  3878. intersectsSphere: function ( sphere ) {
  3879. var planes = this.planes;
  3880. var center = sphere.center;
  3881. var negRadius = - sphere.radius;
  3882. for ( var i = 0; i < 6; i ++ ) {
  3883. var distance = planes[ i ].distanceToPoint( center );
  3884. if ( distance < negRadius ) {
  3885. return false;
  3886. }
  3887. }
  3888. return true;
  3889. },
  3890. intersectsBox: function () {
  3891. var p1 = new THREE.Vector3(),
  3892. p2 = new THREE.Vector3();
  3893. return function ( box ) {
  3894. var planes = this.planes;
  3895. for ( var i = 0; i < 6 ; i ++ ) {
  3896. var plane = planes[ i ];
  3897. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3898. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3899. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3900. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3901. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3902. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3903. var d1 = plane.distanceToPoint( p1 );
  3904. var d2 = plane.distanceToPoint( p2 );
  3905. // if both outside plane, no intersection
  3906. if ( d1 < 0 && d2 < 0 ) {
  3907. return false;
  3908. }
  3909. }
  3910. return true;
  3911. };
  3912. }(),
  3913. containsPoint: function ( point ) {
  3914. var planes = this.planes;
  3915. for ( var i = 0; i < 6; i ++ ) {
  3916. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3917. return false;
  3918. }
  3919. }
  3920. return true;
  3921. }
  3922. };
  3923. // File:src/math/Plane.js
  3924. /**
  3925. * @author bhouston / http://clara.io
  3926. */
  3927. THREE.Plane = function ( normal, constant ) {
  3928. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3929. this.constant = ( constant !== undefined ) ? constant : 0;
  3930. };
  3931. THREE.Plane.prototype = {
  3932. constructor: THREE.Plane,
  3933. set: function ( normal, constant ) {
  3934. this.normal.copy( normal );
  3935. this.constant = constant;
  3936. return this;
  3937. },
  3938. setComponents: function ( x, y, z, w ) {
  3939. this.normal.set( x, y, z );
  3940. this.constant = w;
  3941. return this;
  3942. },
  3943. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3944. this.normal.copy( normal );
  3945. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3946. return this;
  3947. },
  3948. setFromCoplanarPoints: function () {
  3949. var v1 = new THREE.Vector3();
  3950. var v2 = new THREE.Vector3();
  3951. return function ( a, b, c ) {
  3952. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3953. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3954. this.setFromNormalAndCoplanarPoint( normal, a );
  3955. return this;
  3956. };
  3957. }(),
  3958. clone: function () {
  3959. return new this.constructor().copy( this );
  3960. },
  3961. copy: function ( plane ) {
  3962. this.normal.copy( plane.normal );
  3963. this.constant = plane.constant;
  3964. return this;
  3965. },
  3966. normalize: function () {
  3967. // Note: will lead to a divide by zero if the plane is invalid.
  3968. var inverseNormalLength = 1.0 / this.normal.length();
  3969. this.normal.multiplyScalar( inverseNormalLength );
  3970. this.constant *= inverseNormalLength;
  3971. return this;
  3972. },
  3973. negate: function () {
  3974. this.constant *= - 1;
  3975. this.normal.negate();
  3976. return this;
  3977. },
  3978. distanceToPoint: function ( point ) {
  3979. return this.normal.dot( point ) + this.constant;
  3980. },
  3981. distanceToSphere: function ( sphere ) {
  3982. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3983. },
  3984. projectPoint: function ( point, optionalTarget ) {
  3985. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3986. },
  3987. orthoPoint: function ( point, optionalTarget ) {
  3988. var perpendicularMagnitude = this.distanceToPoint( point );
  3989. var result = optionalTarget || new THREE.Vector3();
  3990. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3991. },
  3992. isIntersectionLine: function ( line ) {
  3993. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3994. var startSign = this.distanceToPoint( line.start );
  3995. var endSign = this.distanceToPoint( line.end );
  3996. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3997. },
  3998. intersectLine: function () {
  3999. var v1 = new THREE.Vector3();
  4000. return function ( line, optionalTarget ) {
  4001. var result = optionalTarget || new THREE.Vector3();
  4002. var direction = line.delta( v1 );
  4003. var denominator = this.normal.dot( direction );
  4004. if ( denominator === 0 ) {
  4005. // line is coplanar, return origin
  4006. if ( this.distanceToPoint( line.start ) === 0 ) {
  4007. return result.copy( line.start );
  4008. }
  4009. // Unsure if this is the correct method to handle this case.
  4010. return undefined;
  4011. }
  4012. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4013. if ( t < 0 || t > 1 ) {
  4014. return undefined;
  4015. }
  4016. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4017. };
  4018. }(),
  4019. coplanarPoint: function ( optionalTarget ) {
  4020. var result = optionalTarget || new THREE.Vector3();
  4021. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4022. },
  4023. applyMatrix4: function () {
  4024. var v1 = new THREE.Vector3();
  4025. var v2 = new THREE.Vector3();
  4026. var m1 = new THREE.Matrix3();
  4027. return function ( matrix, optionalNormalMatrix ) {
  4028. // compute new normal based on theory here:
  4029. // http://www.songho.ca/opengl/gl_normaltransform.html
  4030. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4031. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4032. var newCoplanarPoint = this.coplanarPoint( v2 );
  4033. newCoplanarPoint.applyMatrix4( matrix );
  4034. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4035. return this;
  4036. };
  4037. }(),
  4038. translate: function ( offset ) {
  4039. this.constant = this.constant - offset.dot( this.normal );
  4040. return this;
  4041. },
  4042. equals: function ( plane ) {
  4043. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4044. }
  4045. };
  4046. // File:src/math/Math.js
  4047. /**
  4048. * @author alteredq / http://alteredqualia.com/
  4049. * @author mrdoob / http://mrdoob.com/
  4050. */
  4051. THREE.Math = {
  4052. generateUUID: function () {
  4053. // http://www.broofa.com/Tools/Math.uuid.htm
  4054. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4055. var uuid = new Array( 36 );
  4056. var rnd = 0, r;
  4057. return function () {
  4058. for ( var i = 0; i < 36; i ++ ) {
  4059. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4060. uuid[ i ] = '-';
  4061. } else if ( i === 14 ) {
  4062. uuid[ i ] = '4';
  4063. } else {
  4064. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4065. r = rnd & 0xf;
  4066. rnd = rnd >> 4;
  4067. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4068. }
  4069. }
  4070. return uuid.join( '' );
  4071. };
  4072. }(),
  4073. // Clamp value to range <a, b>
  4074. clamp: function ( x, a, b ) {
  4075. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4076. },
  4077. // Clamp value to range <a, inf)
  4078. clampBottom: function ( x, a ) {
  4079. return x < a ? a : x;
  4080. },
  4081. // compute euclidian modulo of m % n
  4082. // https://en.wikipedia.org/wiki/Modulo_operation
  4083. euclideanModulo: function ( n, m ) {
  4084. return ( ( n % m ) + m ) % m;
  4085. },
  4086. // Linear mapping from range <a1, a2> to range <b1, b2>
  4087. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4088. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4089. },
  4090. // http://en.wikipedia.org/wiki/Smoothstep
  4091. smoothstep: function ( x, min, max ) {
  4092. if ( x <= min ) return 0;
  4093. if ( x >= max ) return 1;
  4094. x = ( x - min ) / ( max - min );
  4095. return x * x * ( 3 - 2 * x );
  4096. },
  4097. smootherstep: function ( x, min, max ) {
  4098. if ( x <= min ) return 0;
  4099. if ( x >= max ) return 1;
  4100. x = ( x - min ) / ( max - min );
  4101. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4102. },
  4103. // Random float from <0, 1> with 16 bits of randomness
  4104. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4105. random16: function () {
  4106. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4107. },
  4108. // Random integer from <low, high> interval
  4109. randInt: function ( low, high ) {
  4110. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4111. },
  4112. // Random float from <low, high> interval
  4113. randFloat: function ( low, high ) {
  4114. return low + Math.random() * ( high - low );
  4115. },
  4116. // Random float from <-range/2, range/2> interval
  4117. randFloatSpread: function ( range ) {
  4118. return range * ( 0.5 - Math.random() );
  4119. },
  4120. degToRad: function () {
  4121. var degreeToRadiansFactor = Math.PI / 180;
  4122. return function ( degrees ) {
  4123. return degrees * degreeToRadiansFactor;
  4124. };
  4125. }(),
  4126. radToDeg: function () {
  4127. var radianToDegreesFactor = 180 / Math.PI;
  4128. return function ( radians ) {
  4129. return radians * radianToDegreesFactor;
  4130. };
  4131. }(),
  4132. isPowerOfTwo: function ( value ) {
  4133. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4134. },
  4135. nextPowerOfTwo: function ( value ) {
  4136. value --;
  4137. value |= value >> 1;
  4138. value |= value >> 2;
  4139. value |= value >> 4;
  4140. value |= value >> 8;
  4141. value |= value >> 16;
  4142. value ++;
  4143. return value;
  4144. }
  4145. };
  4146. // File:src/math/Spline.js
  4147. /**
  4148. * Spline from Tween.js, slightly optimized (and trashed)
  4149. * http://sole.github.com/tween.js/examples/05_spline.html
  4150. *
  4151. * @author mrdoob / http://mrdoob.com/
  4152. * @author alteredq / http://alteredqualia.com/
  4153. */
  4154. THREE.Spline = function ( points ) {
  4155. this.points = points;
  4156. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4157. point, intPoint, weight, w2, w3,
  4158. pa, pb, pc, pd;
  4159. this.initFromArray = function ( a ) {
  4160. this.points = [];
  4161. for ( var i = 0; i < a.length; i ++ ) {
  4162. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4163. }
  4164. };
  4165. this.getPoint = function ( k ) {
  4166. point = ( this.points.length - 1 ) * k;
  4167. intPoint = Math.floor( point );
  4168. weight = point - intPoint;
  4169. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4170. c[ 1 ] = intPoint;
  4171. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4172. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4173. pa = this.points[ c[ 0 ] ];
  4174. pb = this.points[ c[ 1 ] ];
  4175. pc = this.points[ c[ 2 ] ];
  4176. pd = this.points[ c[ 3 ] ];
  4177. w2 = weight * weight;
  4178. w3 = weight * w2;
  4179. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4180. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4181. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4182. return v3;
  4183. };
  4184. this.getControlPointsArray = function () {
  4185. var i, p, l = this.points.length,
  4186. coords = [];
  4187. for ( i = 0; i < l; i ++ ) {
  4188. p = this.points[ i ];
  4189. coords[ i ] = [ p.x, p.y, p.z ];
  4190. }
  4191. return coords;
  4192. };
  4193. // approximate length by summing linear segments
  4194. this.getLength = function ( nSubDivisions ) {
  4195. var i, index, nSamples, position,
  4196. point = 0, intPoint = 0, oldIntPoint = 0,
  4197. oldPosition = new THREE.Vector3(),
  4198. tmpVec = new THREE.Vector3(),
  4199. chunkLengths = [],
  4200. totalLength = 0;
  4201. // first point has 0 length
  4202. chunkLengths[ 0 ] = 0;
  4203. if ( ! nSubDivisions ) nSubDivisions = 100;
  4204. nSamples = this.points.length * nSubDivisions;
  4205. oldPosition.copy( this.points[ 0 ] );
  4206. for ( i = 1; i < nSamples; i ++ ) {
  4207. index = i / nSamples;
  4208. position = this.getPoint( index );
  4209. tmpVec.copy( position );
  4210. totalLength += tmpVec.distanceTo( oldPosition );
  4211. oldPosition.copy( position );
  4212. point = ( this.points.length - 1 ) * index;
  4213. intPoint = Math.floor( point );
  4214. if ( intPoint !== oldIntPoint ) {
  4215. chunkLengths[ intPoint ] = totalLength;
  4216. oldIntPoint = intPoint;
  4217. }
  4218. }
  4219. // last point ends with total length
  4220. chunkLengths[ chunkLengths.length ] = totalLength;
  4221. return { chunks: chunkLengths, total: totalLength };
  4222. };
  4223. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4224. var i, j,
  4225. index, indexCurrent, indexNext,
  4226. realDistance,
  4227. sampling, position,
  4228. newpoints = [],
  4229. tmpVec = new THREE.Vector3(),
  4230. sl = this.getLength();
  4231. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4232. for ( i = 1; i < this.points.length; i ++ ) {
  4233. //tmpVec.copy( this.points[ i - 1 ] );
  4234. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4235. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4236. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4237. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4238. indexNext = i / ( this.points.length - 1 );
  4239. for ( j = 1; j < sampling - 1; j ++ ) {
  4240. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4241. position = this.getPoint( index );
  4242. newpoints.push( tmpVec.copy( position ).clone() );
  4243. }
  4244. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4245. }
  4246. this.points = newpoints;
  4247. };
  4248. // Catmull-Rom
  4249. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4250. var v0 = ( p2 - p0 ) * 0.5,
  4251. v1 = ( p3 - p1 ) * 0.5;
  4252. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4253. }
  4254. };
  4255. // File:src/math/Triangle.js
  4256. /**
  4257. * @author bhouston / http://clara.io
  4258. * @author mrdoob / http://mrdoob.com/
  4259. */
  4260. THREE.Triangle = function ( a, b, c ) {
  4261. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4262. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4263. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4264. };
  4265. THREE.Triangle.normal = function () {
  4266. var v0 = new THREE.Vector3();
  4267. return function ( a, b, c, optionalTarget ) {
  4268. var result = optionalTarget || new THREE.Vector3();
  4269. result.subVectors( c, b );
  4270. v0.subVectors( a, b );
  4271. result.cross( v0 );
  4272. var resultLengthSq = result.lengthSq();
  4273. if ( resultLengthSq > 0 ) {
  4274. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4275. }
  4276. return result.set( 0, 0, 0 );
  4277. };
  4278. }();
  4279. // static/instance method to calculate barycentric coordinates
  4280. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4281. THREE.Triangle.barycoordFromPoint = function () {
  4282. var v0 = new THREE.Vector3();
  4283. var v1 = new THREE.Vector3();
  4284. var v2 = new THREE.Vector3();
  4285. return function ( point, a, b, c, optionalTarget ) {
  4286. v0.subVectors( c, a );
  4287. v1.subVectors( b, a );
  4288. v2.subVectors( point, a );
  4289. var dot00 = v0.dot( v0 );
  4290. var dot01 = v0.dot( v1 );
  4291. var dot02 = v0.dot( v2 );
  4292. var dot11 = v1.dot( v1 );
  4293. var dot12 = v1.dot( v2 );
  4294. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4295. var result = optionalTarget || new THREE.Vector3();
  4296. // collinear or singular triangle
  4297. if ( denom === 0 ) {
  4298. // arbitrary location outside of triangle?
  4299. // not sure if this is the best idea, maybe should be returning undefined
  4300. return result.set( - 2, - 1, - 1 );
  4301. }
  4302. var invDenom = 1 / denom;
  4303. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4304. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4305. // barycentric coordinates must always sum to 1
  4306. return result.set( 1 - u - v, v, u );
  4307. };
  4308. }();
  4309. THREE.Triangle.containsPoint = function () {
  4310. var v1 = new THREE.Vector3();
  4311. return function ( point, a, b, c ) {
  4312. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4313. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4314. };
  4315. }();
  4316. THREE.Triangle.prototype = {
  4317. constructor: THREE.Triangle,
  4318. set: function ( a, b, c ) {
  4319. this.a.copy( a );
  4320. this.b.copy( b );
  4321. this.c.copy( c );
  4322. return this;
  4323. },
  4324. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4325. this.a.copy( points[ i0 ] );
  4326. this.b.copy( points[ i1 ] );
  4327. this.c.copy( points[ i2 ] );
  4328. return this;
  4329. },
  4330. clone: function () {
  4331. return new this.constructor().copy( this );
  4332. },
  4333. copy: function ( triangle ) {
  4334. this.a.copy( triangle.a );
  4335. this.b.copy( triangle.b );
  4336. this.c.copy( triangle.c );
  4337. return this;
  4338. },
  4339. area: function () {
  4340. var v0 = new THREE.Vector3();
  4341. var v1 = new THREE.Vector3();
  4342. return function () {
  4343. v0.subVectors( this.c, this.b );
  4344. v1.subVectors( this.a, this.b );
  4345. return v0.cross( v1 ).length() * 0.5;
  4346. };
  4347. }(),
  4348. midpoint: function ( optionalTarget ) {
  4349. var result = optionalTarget || new THREE.Vector3();
  4350. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4351. },
  4352. normal: function ( optionalTarget ) {
  4353. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4354. },
  4355. plane: function ( optionalTarget ) {
  4356. var result = optionalTarget || new THREE.Plane();
  4357. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4358. },
  4359. barycoordFromPoint: function ( point, optionalTarget ) {
  4360. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4361. },
  4362. containsPoint: function ( point ) {
  4363. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4364. },
  4365. equals: function ( triangle ) {
  4366. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4367. }
  4368. };
  4369. // File:src/core/Clock.js
  4370. /**
  4371. * @author alteredq / http://alteredqualia.com/
  4372. */
  4373. THREE.Clock = function ( autoStart ) {
  4374. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4375. this.startTime = 0;
  4376. this.oldTime = 0;
  4377. this.elapsedTime = 0;
  4378. this.running = false;
  4379. };
  4380. THREE.Clock.prototype = {
  4381. constructor: THREE.Clock,
  4382. _now: function () {
  4383. return self.performance !== undefined && self.performance.now !== undefined
  4384. ? self.performance.now()
  4385. : Date.now();
  4386. },
  4387. start: function () {
  4388. this.startTime = this._now();
  4389. this.oldTime = this.startTime;
  4390. this.running = true;
  4391. },
  4392. stop: function () {
  4393. this.getElapsedTime();
  4394. this.running = false;
  4395. },
  4396. getElapsedTime: function () {
  4397. this.getDelta();
  4398. return this.elapsedTime;
  4399. },
  4400. getDelta: function () {
  4401. var diff = 0;
  4402. if ( this.autoStart && ! this.running ) {
  4403. this.start();
  4404. }
  4405. if ( this.running ) {
  4406. var newTime = this._now();
  4407. diff = 0.001 * ( newTime - this.oldTime );
  4408. this.oldTime = newTime;
  4409. this.elapsedTime += diff;
  4410. }
  4411. return diff;
  4412. }
  4413. };
  4414. // File:src/core/EventDispatcher.js
  4415. /**
  4416. * https://github.com/mrdoob/eventdispatcher.js/
  4417. */
  4418. THREE.EventDispatcher = function () {};
  4419. THREE.EventDispatcher.prototype = {
  4420. constructor: THREE.EventDispatcher,
  4421. apply: function ( object ) {
  4422. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4423. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4424. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4425. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4426. },
  4427. addEventListener: function ( type, listener ) {
  4428. if ( this._listeners === undefined ) this._listeners = {};
  4429. var listeners = this._listeners;
  4430. if ( listeners[ type ] === undefined ) {
  4431. listeners[ type ] = [];
  4432. }
  4433. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4434. listeners[ type ].push( listener );
  4435. }
  4436. },
  4437. hasEventListener: function ( type, listener ) {
  4438. if ( this._listeners === undefined ) return false;
  4439. var listeners = this._listeners;
  4440. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4441. return true;
  4442. }
  4443. return false;
  4444. },
  4445. removeEventListener: function ( type, listener ) {
  4446. if ( this._listeners === undefined ) return;
  4447. var listeners = this._listeners;
  4448. var listenerArray = listeners[ type ];
  4449. if ( listenerArray !== undefined ) {
  4450. var index = listenerArray.indexOf( listener );
  4451. if ( index !== - 1 ) {
  4452. listenerArray.splice( index, 1 );
  4453. }
  4454. }
  4455. },
  4456. dispatchEvent: function ( event ) {
  4457. if ( this._listeners === undefined ) return;
  4458. var listeners = this._listeners;
  4459. var listenerArray = listeners[ event.type ];
  4460. if ( listenerArray !== undefined ) {
  4461. event.target = this;
  4462. var array = [];
  4463. var length = listenerArray.length;
  4464. for ( var i = 0; i < length; i ++ ) {
  4465. array[ i ] = listenerArray[ i ];
  4466. }
  4467. for ( var i = 0; i < length; i ++ ) {
  4468. array[ i ].call( this, event );
  4469. }
  4470. }
  4471. }
  4472. };
  4473. // File:src/core/Raycaster.js
  4474. /**
  4475. * @author mrdoob / http://mrdoob.com/
  4476. * @author bhouston / http://clara.io/
  4477. * @author stephomi / http://stephaneginier.com/
  4478. */
  4479. ( function ( THREE ) {
  4480. THREE.Raycaster = function ( origin, direction, near, far ) {
  4481. this.ray = new THREE.Ray( origin, direction );
  4482. // direction is assumed to be normalized (for accurate distance calculations)
  4483. this.near = near || 0;
  4484. this.far = far || Infinity;
  4485. this.params = {
  4486. Mesh: {},
  4487. Line: {},
  4488. LOD: {},
  4489. Points: { threshold: 1 },
  4490. Sprite: {}
  4491. };
  4492. Object.defineProperties( this.params, {
  4493. PointCloud: {
  4494. get: function () {
  4495. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4496. return this.Points;
  4497. }
  4498. }
  4499. } );
  4500. };
  4501. function descSort( a, b ) {
  4502. return a.distance - b.distance;
  4503. }
  4504. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4505. if ( object.visible === false ) return;
  4506. object.raycast( raycaster, intersects );
  4507. if ( recursive === true ) {
  4508. var children = object.children;
  4509. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4510. intersectObject( children[ i ], raycaster, intersects, true );
  4511. }
  4512. }
  4513. };
  4514. //
  4515. THREE.Raycaster.prototype = {
  4516. constructor: THREE.Raycaster,
  4517. linePrecision: 1,
  4518. set: function ( origin, direction ) {
  4519. // direction is assumed to be normalized (for accurate distance calculations)
  4520. this.ray.set( origin, direction );
  4521. },
  4522. setFromCamera: function ( coords, camera ) {
  4523. if ( camera instanceof THREE.PerspectiveCamera ) {
  4524. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4525. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4526. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4527. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4528. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4529. } else {
  4530. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4531. }
  4532. },
  4533. intersectObject: function ( object, recursive ) {
  4534. var intersects = [];
  4535. intersectObject( object, this, intersects, recursive );
  4536. intersects.sort( descSort );
  4537. return intersects;
  4538. },
  4539. intersectObjects: function ( objects, recursive ) {
  4540. var intersects = [];
  4541. if ( Array.isArray( objects ) === false ) {
  4542. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4543. return intersects;
  4544. }
  4545. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4546. intersectObject( objects[ i ], this, intersects, recursive );
  4547. }
  4548. intersects.sort( descSort );
  4549. return intersects;
  4550. }
  4551. };
  4552. }( THREE ) );
  4553. // File:src/core/Object3D.js
  4554. /**
  4555. * @author mrdoob / http://mrdoob.com/
  4556. * @author mikael emtinger / http://gomo.se/
  4557. * @author alteredq / http://alteredqualia.com/
  4558. * @author WestLangley / http://github.com/WestLangley
  4559. * @author elephantatwork / www.elephantatwork.ch
  4560. */
  4561. THREE.Object3D = function () {
  4562. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4563. this.uuid = THREE.Math.generateUUID();
  4564. this.name = '';
  4565. this.type = 'Object3D';
  4566. this.parent = null;
  4567. this.children = [];
  4568. this.up = THREE.Object3D.DefaultUp.clone();
  4569. var position = new THREE.Vector3();
  4570. var rotation = new THREE.Euler();
  4571. var quaternion = new THREE.Quaternion();
  4572. var scale = new THREE.Vector3( 1, 1, 1 );
  4573. var onRotationChange = function () {
  4574. quaternion.setFromEuler( rotation, false );
  4575. };
  4576. var onQuaternionChange = function () {
  4577. rotation.setFromQuaternion( quaternion, undefined, false );
  4578. };
  4579. rotation.onChange( onRotationChange );
  4580. quaternion.onChange( onQuaternionChange );
  4581. Object.defineProperties( this, {
  4582. position: {
  4583. enumerable: true,
  4584. value: position
  4585. },
  4586. rotation: {
  4587. enumerable: true,
  4588. value: rotation
  4589. },
  4590. quaternion: {
  4591. enumerable: true,
  4592. value: quaternion
  4593. },
  4594. scale: {
  4595. enumerable: true,
  4596. value: scale
  4597. },
  4598. modelViewMatrix: {
  4599. value: new THREE.Matrix4()
  4600. },
  4601. normalMatrix: {
  4602. value: new THREE.Matrix3()
  4603. }
  4604. } );
  4605. this.rotationAutoUpdate = true;
  4606. this.matrix = new THREE.Matrix4();
  4607. this.matrixWorld = new THREE.Matrix4();
  4608. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4609. this.matrixWorldNeedsUpdate = false;
  4610. this.visible = true;
  4611. this.castShadow = false;
  4612. this.receiveShadow = false;
  4613. this.frustumCulled = true;
  4614. this.renderOrder = 0;
  4615. this.userData = {};
  4616. };
  4617. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4618. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4619. THREE.Object3D.prototype = {
  4620. constructor: THREE.Object3D,
  4621. get eulerOrder () {
  4622. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4623. return this.rotation.order;
  4624. },
  4625. set eulerOrder ( value ) {
  4626. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4627. this.rotation.order = value;
  4628. },
  4629. get useQuaternion () {
  4630. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4631. },
  4632. set useQuaternion ( value ) {
  4633. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4634. },
  4635. set renderDepth ( value ) {
  4636. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4637. },
  4638. applyMatrix: function ( matrix ) {
  4639. this.matrix.multiplyMatrices( matrix, this.matrix );
  4640. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4641. },
  4642. setRotationFromAxisAngle: function ( axis, angle ) {
  4643. // assumes axis is normalized
  4644. this.quaternion.setFromAxisAngle( axis, angle );
  4645. },
  4646. setRotationFromEuler: function ( euler ) {
  4647. this.quaternion.setFromEuler( euler, true );
  4648. },
  4649. setRotationFromMatrix: function ( m ) {
  4650. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4651. this.quaternion.setFromRotationMatrix( m );
  4652. },
  4653. setRotationFromQuaternion: function ( q ) {
  4654. // assumes q is normalized
  4655. this.quaternion.copy( q );
  4656. },
  4657. rotateOnAxis: function () {
  4658. // rotate object on axis in object space
  4659. // axis is assumed to be normalized
  4660. var q1 = new THREE.Quaternion();
  4661. return function ( axis, angle ) {
  4662. q1.setFromAxisAngle( axis, angle );
  4663. this.quaternion.multiply( q1 );
  4664. return this;
  4665. };
  4666. }(),
  4667. rotateX: function () {
  4668. var v1 = new THREE.Vector3( 1, 0, 0 );
  4669. return function ( angle ) {
  4670. return this.rotateOnAxis( v1, angle );
  4671. };
  4672. }(),
  4673. rotateY: function () {
  4674. var v1 = new THREE.Vector3( 0, 1, 0 );
  4675. return function ( angle ) {
  4676. return this.rotateOnAxis( v1, angle );
  4677. };
  4678. }(),
  4679. rotateZ: function () {
  4680. var v1 = new THREE.Vector3( 0, 0, 1 );
  4681. return function ( angle ) {
  4682. return this.rotateOnAxis( v1, angle );
  4683. };
  4684. }(),
  4685. translateOnAxis: function () {
  4686. // translate object by distance along axis in object space
  4687. // axis is assumed to be normalized
  4688. var v1 = new THREE.Vector3();
  4689. return function ( axis, distance ) {
  4690. v1.copy( axis ).applyQuaternion( this.quaternion );
  4691. this.position.add( v1.multiplyScalar( distance ) );
  4692. return this;
  4693. };
  4694. }(),
  4695. translate: function ( distance, axis ) {
  4696. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4697. return this.translateOnAxis( axis, distance );
  4698. },
  4699. translateX: function () {
  4700. var v1 = new THREE.Vector3( 1, 0, 0 );
  4701. return function ( distance ) {
  4702. return this.translateOnAxis( v1, distance );
  4703. };
  4704. }(),
  4705. translateY: function () {
  4706. var v1 = new THREE.Vector3( 0, 1, 0 );
  4707. return function ( distance ) {
  4708. return this.translateOnAxis( v1, distance );
  4709. };
  4710. }(),
  4711. translateZ: function () {
  4712. var v1 = new THREE.Vector3( 0, 0, 1 );
  4713. return function ( distance ) {
  4714. return this.translateOnAxis( v1, distance );
  4715. };
  4716. }(),
  4717. localToWorld: function ( vector ) {
  4718. return vector.applyMatrix4( this.matrixWorld );
  4719. },
  4720. worldToLocal: function () {
  4721. var m1 = new THREE.Matrix4();
  4722. return function ( vector ) {
  4723. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4724. };
  4725. }(),
  4726. lookAt: function () {
  4727. // This routine does not support objects with rotated and/or translated parent(s)
  4728. var m1 = new THREE.Matrix4();
  4729. return function ( vector ) {
  4730. m1.lookAt( vector, this.position, this.up );
  4731. this.quaternion.setFromRotationMatrix( m1 );
  4732. };
  4733. }(),
  4734. add: function ( object ) {
  4735. if ( arguments.length > 1 ) {
  4736. for ( var i = 0; i < arguments.length; i ++ ) {
  4737. this.add( arguments[ i ] );
  4738. }
  4739. return this;
  4740. }
  4741. if ( object === this ) {
  4742. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4743. return this;
  4744. }
  4745. if ( object instanceof THREE.Object3D ) {
  4746. if ( object.parent !== null ) {
  4747. object.parent.remove( object );
  4748. }
  4749. object.parent = this;
  4750. object.dispatchEvent( { type: 'added' } );
  4751. this.children.push( object );
  4752. } else {
  4753. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4754. }
  4755. return this;
  4756. },
  4757. remove: function ( object ) {
  4758. if ( arguments.length > 1 ) {
  4759. for ( var i = 0; i < arguments.length; i ++ ) {
  4760. this.remove( arguments[ i ] );
  4761. }
  4762. }
  4763. var index = this.children.indexOf( object );
  4764. if ( index !== - 1 ) {
  4765. object.parent = null;
  4766. object.dispatchEvent( { type: 'removed' } );
  4767. this.children.splice( index, 1 );
  4768. }
  4769. },
  4770. getChildByName: function ( name ) {
  4771. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4772. return this.getObjectByName( name );
  4773. },
  4774. getObjectById: function ( id ) {
  4775. return this.getObjectByProperty( 'id', id );
  4776. },
  4777. getObjectByName: function ( name ) {
  4778. return this.getObjectByProperty( 'name', name );
  4779. },
  4780. getObjectByProperty: function ( name, value ) {
  4781. if ( this[ name ] === value ) return this;
  4782. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4783. var child = this.children[ i ];
  4784. var object = child.getObjectByProperty( name, value );
  4785. if ( object !== undefined ) {
  4786. return object;
  4787. }
  4788. }
  4789. return undefined;
  4790. },
  4791. getWorldPosition: function ( optionalTarget ) {
  4792. var result = optionalTarget || new THREE.Vector3();
  4793. this.updateMatrixWorld( true );
  4794. return result.setFromMatrixPosition( this.matrixWorld );
  4795. },
  4796. getWorldQuaternion: function () {
  4797. var position = new THREE.Vector3();
  4798. var scale = new THREE.Vector3();
  4799. return function ( optionalTarget ) {
  4800. var result = optionalTarget || new THREE.Quaternion();
  4801. this.updateMatrixWorld( true );
  4802. this.matrixWorld.decompose( position, result, scale );
  4803. return result;
  4804. };
  4805. }(),
  4806. getWorldRotation: function () {
  4807. var quaternion = new THREE.Quaternion();
  4808. return function ( optionalTarget ) {
  4809. var result = optionalTarget || new THREE.Euler();
  4810. this.getWorldQuaternion( quaternion );
  4811. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4812. };
  4813. }(),
  4814. getWorldScale: function () {
  4815. var position = new THREE.Vector3();
  4816. var quaternion = new THREE.Quaternion();
  4817. return function ( optionalTarget ) {
  4818. var result = optionalTarget || new THREE.Vector3();
  4819. this.updateMatrixWorld( true );
  4820. this.matrixWorld.decompose( position, quaternion, result );
  4821. return result;
  4822. };
  4823. }(),
  4824. getWorldDirection: function () {
  4825. var quaternion = new THREE.Quaternion();
  4826. return function ( optionalTarget ) {
  4827. var result = optionalTarget || new THREE.Vector3();
  4828. this.getWorldQuaternion( quaternion );
  4829. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4830. };
  4831. }(),
  4832. raycast: function () {},
  4833. traverse: function ( callback ) {
  4834. callback( this );
  4835. var children = this.children;
  4836. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4837. children[ i ].traverse( callback );
  4838. }
  4839. },
  4840. traverseVisible: function ( callback ) {
  4841. if ( this.visible === false ) return;
  4842. callback( this );
  4843. var children = this.children;
  4844. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4845. children[ i ].traverseVisible( callback );
  4846. }
  4847. },
  4848. traverseAncestors: function ( callback ) {
  4849. var parent = this.parent;
  4850. if ( parent !== null ) {
  4851. callback( parent );
  4852. parent.traverseAncestors( callback );
  4853. }
  4854. },
  4855. updateMatrix: function () {
  4856. this.matrix.compose( this.position, this.quaternion, this.scale );
  4857. this.matrixWorldNeedsUpdate = true;
  4858. },
  4859. updateMatrixWorld: function ( force ) {
  4860. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4861. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4862. if ( this.parent === null ) {
  4863. this.matrixWorld.copy( this.matrix );
  4864. } else {
  4865. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4866. }
  4867. this.matrixWorldNeedsUpdate = false;
  4868. force = true;
  4869. }
  4870. // update children
  4871. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4872. this.children[ i ].updateMatrixWorld( force );
  4873. }
  4874. },
  4875. toJSON: function ( meta ) {
  4876. var isRootObject = ( meta === undefined );
  4877. var data = {};
  4878. var output = { object: data };
  4879. // meta is a hash used to collect geometries, materials.
  4880. // not providing it implies that this is the root object
  4881. // being serialized.
  4882. if ( isRootObject ) {
  4883. // initialize meta obj
  4884. meta = {
  4885. geometries: {},
  4886. materials: {},
  4887. textures: {},
  4888. images: {}
  4889. };
  4890. output.metadata = {
  4891. version: 4.4,
  4892. type: 'Object',
  4893. generator: 'Object3D.toJSON'
  4894. };
  4895. }
  4896. // standard Object3D serialization
  4897. data.uuid = this.uuid;
  4898. data.type = this.type;
  4899. if ( this.name !== '' ) data.name = this.name;
  4900. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4901. if ( this.visible !== true ) data.visible = this.visible;
  4902. data.matrix = this.matrix.toArray();
  4903. if ( this.children.length > 0 ) {
  4904. data.children = [];
  4905. for ( var i = 0; i < this.children.length; i ++ ) {
  4906. data.children.push( this.children[ i ].toJSON( meta ).object );
  4907. }
  4908. }
  4909. if ( isRootObject ) {
  4910. var geometries = extractFromCache( meta.geometries );
  4911. var materials = extractFromCache( meta.materials );
  4912. var textures = extractFromCache( meta.textures );
  4913. var images = extractFromCache( meta.images );
  4914. if ( geometries.length > 0 ) output.geometries = geometries;
  4915. if ( materials.length > 0 ) output.materials = materials;
  4916. if ( textures.length > 0 ) output.textures = textures;
  4917. if ( images.length > 0 ) output.images = images;
  4918. }
  4919. return output;
  4920. // extract data from the cache hash
  4921. // remove metadata on each item
  4922. // and return as array
  4923. function extractFromCache ( cache ) {
  4924. var values = [];
  4925. for ( var key in cache ) {
  4926. var data = cache[ key ];
  4927. delete data.metadata;
  4928. values.push( data );
  4929. }
  4930. return values;
  4931. }
  4932. },
  4933. clone: function ( recursive ) {
  4934. return new this.constructor().copy( this, recursive );
  4935. },
  4936. copy: function ( source, recursive ) {
  4937. if ( recursive === undefined ) recursive = true;
  4938. this.name = source.name;
  4939. this.up.copy( source.up );
  4940. this.position.copy( source.position );
  4941. this.quaternion.copy( source.quaternion );
  4942. this.scale.copy( source.scale );
  4943. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4944. this.matrix.copy( source.matrix );
  4945. this.matrixWorld.copy( source.matrixWorld );
  4946. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4947. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4948. this.visible = source.visible;
  4949. this.castShadow = source.castShadow;
  4950. this.receiveShadow = source.receiveShadow;
  4951. this.frustumCulled = source.frustumCulled;
  4952. this.renderOrder = source.renderOrder;
  4953. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4954. if ( recursive === true ) {
  4955. for ( var i = 0; i < source.children.length; i ++ ) {
  4956. var child = source.children[ i ];
  4957. this.add( child.clone() );
  4958. }
  4959. }
  4960. return this;
  4961. }
  4962. };
  4963. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4964. THREE.Object3DIdCount = 0;
  4965. // File:src/core/Face3.js
  4966. /**
  4967. * @author mrdoob / http://mrdoob.com/
  4968. * @author alteredq / http://alteredqualia.com/
  4969. */
  4970. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4971. this.a = a;
  4972. this.b = b;
  4973. this.c = c;
  4974. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4975. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4976. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4977. this.vertexColors = Array.isArray( color ) ? color : [];
  4978. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4979. };
  4980. THREE.Face3.prototype = {
  4981. constructor: THREE.Face3,
  4982. clone: function () {
  4983. return new this.constructor().copy( this );
  4984. },
  4985. copy: function ( source ) {
  4986. this.a = source.a;
  4987. this.b = source.b;
  4988. this.c = source.c;
  4989. this.normal.copy( source.normal );
  4990. this.color.copy( source.color );
  4991. this.materialIndex = source.materialIndex;
  4992. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4993. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4994. }
  4995. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4996. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4997. }
  4998. return this;
  4999. }
  5000. };
  5001. // File:src/core/Face4.js
  5002. /**
  5003. * @author mrdoob / http://mrdoob.com/
  5004. */
  5005. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5006. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5007. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5008. };
  5009. // File:src/core/BufferAttribute.js
  5010. /**
  5011. * @author mrdoob / http://mrdoob.com/
  5012. */
  5013. THREE.BufferAttribute = function ( array, itemSize ) {
  5014. this.uuid = THREE.Math.generateUUID();
  5015. this.array = array;
  5016. this.itemSize = itemSize;
  5017. this.dynamic = false;
  5018. this.updateRange = { offset: 0, count: - 1 };
  5019. this.version = 0;
  5020. };
  5021. THREE.BufferAttribute.prototype = {
  5022. constructor: THREE.BufferAttribute,
  5023. get length() {
  5024. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5025. return this.array.length;
  5026. },
  5027. get count() {
  5028. return this.array.length / this.itemSize;
  5029. },
  5030. set needsUpdate( value ) {
  5031. if ( value === true ) this.version ++;
  5032. },
  5033. setDynamic: function ( value ) {
  5034. this.dynamic = value;
  5035. return this;
  5036. },
  5037. copy: function ( source ) {
  5038. this.array = new source.array.constructor( source.array );
  5039. this.itemSize = source.itemSize;
  5040. this.dynamic = source.dynamic;
  5041. return this;
  5042. },
  5043. copyAt: function ( index1, attribute, index2 ) {
  5044. index1 *= this.itemSize;
  5045. index2 *= attribute.itemSize;
  5046. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5047. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5048. }
  5049. return this;
  5050. },
  5051. copyArray: function ( array ) {
  5052. this.array.set( array );
  5053. return this;
  5054. },
  5055. copyColorsArray: function ( colors ) {
  5056. var array = this.array, offset = 0;
  5057. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5058. var color = colors[ i ];
  5059. if ( color === undefined ) {
  5060. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5061. color = new THREE.Color();
  5062. }
  5063. array[ offset ++ ] = color.r;
  5064. array[ offset ++ ] = color.g;
  5065. array[ offset ++ ] = color.b;
  5066. }
  5067. return this;
  5068. },
  5069. copyIndicesArray: function ( indices ) {
  5070. var array = this.array, offset = 0;
  5071. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5072. var index = indices[ i ];
  5073. array[ offset ++ ] = index.a;
  5074. array[ offset ++ ] = index.b;
  5075. array[ offset ++ ] = index.c;
  5076. }
  5077. return this;
  5078. },
  5079. copyVector2sArray: function ( vectors ) {
  5080. var array = this.array, offset = 0;
  5081. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5082. var vector = vectors[ i ];
  5083. if ( vector === undefined ) {
  5084. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5085. vector = new THREE.Vector2();
  5086. }
  5087. array[ offset ++ ] = vector.x;
  5088. array[ offset ++ ] = vector.y;
  5089. }
  5090. return this;
  5091. },
  5092. copyVector3sArray: function ( vectors ) {
  5093. var array = this.array, offset = 0;
  5094. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5095. var vector = vectors[ i ];
  5096. if ( vector === undefined ) {
  5097. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5098. vector = new THREE.Vector3();
  5099. }
  5100. array[ offset ++ ] = vector.x;
  5101. array[ offset ++ ] = vector.y;
  5102. array[ offset ++ ] = vector.z;
  5103. }
  5104. return this;
  5105. },
  5106. copyVector4sArray: function ( vectors ) {
  5107. var array = this.array, offset = 0;
  5108. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5109. var vector = vectors[ i ];
  5110. if ( vector === undefined ) {
  5111. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5112. vector = new THREE.Vector4();
  5113. }
  5114. array[ offset ++ ] = vector.x;
  5115. array[ offset ++ ] = vector.y;
  5116. array[ offset ++ ] = vector.z;
  5117. array[ offset ++ ] = vector.w;
  5118. }
  5119. return this;
  5120. },
  5121. set: function ( value, offset ) {
  5122. if ( offset === undefined ) offset = 0;
  5123. this.array.set( value, offset );
  5124. return this;
  5125. },
  5126. getX: function ( index ) {
  5127. return this.array[ index * this.itemSize ];
  5128. },
  5129. setX: function ( index, x ) {
  5130. this.array[ index * this.itemSize ] = x;
  5131. return this;
  5132. },
  5133. getY: function ( index ) {
  5134. return this.array[ index * this.itemSize + 1 ];
  5135. },
  5136. setY: function ( index, y ) {
  5137. this.array[ index * this.itemSize + 1 ] = y;
  5138. return this;
  5139. },
  5140. getZ: function ( index ) {
  5141. return this.array[ index * this.itemSize + 2 ];
  5142. },
  5143. setZ: function ( index, z ) {
  5144. this.array[ index * this.itemSize + 2 ] = z;
  5145. return this;
  5146. },
  5147. getW: function ( index ) {
  5148. return this.array[ index * this.itemSize + 3 ];
  5149. },
  5150. setW: function ( index, w ) {
  5151. this.array[ index * this.itemSize + 3 ] = w;
  5152. return this;
  5153. },
  5154. setXY: function ( index, x, y ) {
  5155. index *= this.itemSize;
  5156. this.array[ index + 0 ] = x;
  5157. this.array[ index + 1 ] = y;
  5158. return this;
  5159. },
  5160. setXYZ: function ( index, x, y, z ) {
  5161. index *= this.itemSize;
  5162. this.array[ index + 0 ] = x;
  5163. this.array[ index + 1 ] = y;
  5164. this.array[ index + 2 ] = z;
  5165. return this;
  5166. },
  5167. setXYZW: function ( index, x, y, z, w ) {
  5168. index *= this.itemSize;
  5169. this.array[ index + 0 ] = x;
  5170. this.array[ index + 1 ] = y;
  5171. this.array[ index + 2 ] = z;
  5172. this.array[ index + 3 ] = w;
  5173. return this;
  5174. },
  5175. clone: function () {
  5176. return new this.constructor().copy( this );
  5177. }
  5178. };
  5179. //
  5180. THREE.Int8Attribute = function ( array, itemSize ) {
  5181. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5182. };
  5183. THREE.Uint8Attribute = function ( array, itemSize ) {
  5184. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5185. };
  5186. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5187. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5188. };
  5189. THREE.Int16Attribute = function ( array, itemSize ) {
  5190. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5191. };
  5192. THREE.Uint16Attribute = function ( array, itemSize ) {
  5193. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5194. };
  5195. THREE.Int32Attribute = function ( array, itemSize ) {
  5196. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5197. };
  5198. THREE.Uint32Attribute = function ( array, itemSize ) {
  5199. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5200. };
  5201. THREE.Float32Attribute = function ( array, itemSize ) {
  5202. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5203. };
  5204. THREE.Float64Attribute = function ( array, itemSize ) {
  5205. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5206. };
  5207. // Deprecated
  5208. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5209. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5210. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5211. };
  5212. // File:src/core/InstancedBufferAttribute.js
  5213. /**
  5214. * @author benaadams / https://twitter.com/ben_a_adams
  5215. */
  5216. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5217. THREE.BufferAttribute.call( this, array, itemSize );
  5218. this.meshPerAttribute = meshPerAttribute || 1;
  5219. };
  5220. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5221. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5222. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5223. THREE.BufferAttribute.prototype.copy.call( this, source );
  5224. this.meshPerAttribute = source.meshPerAttribute;
  5225. return this;
  5226. };
  5227. // File:src/core/InterleavedBuffer.js
  5228. /**
  5229. * @author benaadams / https://twitter.com/ben_a_adams
  5230. */
  5231. THREE.InterleavedBuffer = function ( array, stride ) {
  5232. this.uuid = THREE.Math.generateUUID();
  5233. this.array = array;
  5234. this.stride = stride;
  5235. this.dynamic = false;
  5236. this.updateRange = { offset: 0, count: - 1 };
  5237. this.version = 0;
  5238. };
  5239. THREE.InterleavedBuffer.prototype = {
  5240. constructor: THREE.InterleavedBuffer,
  5241. get length () {
  5242. return this.array.length;
  5243. },
  5244. get count () {
  5245. return this.array.length / this.stride;
  5246. },
  5247. set needsUpdate( value ) {
  5248. if ( value === true ) this.version ++;
  5249. },
  5250. setDynamic: function ( value ) {
  5251. this.dynamic = value;
  5252. return this;
  5253. },
  5254. copy: function ( source ) {
  5255. this.array = new source.array.constructor( source.array );
  5256. this.stride = source.stride;
  5257. this.dynamic = source.dynamic;
  5258. },
  5259. copyAt: function ( index1, attribute, index2 ) {
  5260. index1 *= this.stride;
  5261. index2 *= attribute.stride;
  5262. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5263. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5264. }
  5265. return this;
  5266. },
  5267. set: function ( value, offset ) {
  5268. if ( offset === undefined ) offset = 0;
  5269. this.array.set( value, offset );
  5270. return this;
  5271. },
  5272. clone: function () {
  5273. return new this.constructor().copy( this );
  5274. }
  5275. };
  5276. // File:src/core/InstancedInterleavedBuffer.js
  5277. /**
  5278. * @author benaadams / https://twitter.com/ben_a_adams
  5279. */
  5280. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5281. THREE.InterleavedBuffer.call( this, array, stride );
  5282. this.meshPerAttribute = meshPerAttribute || 1;
  5283. };
  5284. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5285. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5286. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5287. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5288. this.meshPerAttribute = source.meshPerAttribute;
  5289. return this;
  5290. };
  5291. // File:src/core/InterleavedBufferAttribute.js
  5292. /**
  5293. * @author benaadams / https://twitter.com/ben_a_adams
  5294. */
  5295. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5296. this.uuid = THREE.Math.generateUUID();
  5297. this.data = interleavedBuffer;
  5298. this.itemSize = itemSize;
  5299. this.offset = offset;
  5300. };
  5301. THREE.InterleavedBufferAttribute.prototype = {
  5302. constructor: THREE.InterleavedBufferAttribute,
  5303. get length() {
  5304. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5305. return this.array.length;
  5306. },
  5307. get count() {
  5308. return this.data.array.length / this.data.stride;
  5309. },
  5310. setX: function ( index, x ) {
  5311. this.data.array[ index * this.data.stride + this.offset ] = x;
  5312. return this;
  5313. },
  5314. setY: function ( index, y ) {
  5315. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5316. return this;
  5317. },
  5318. setZ: function ( index, z ) {
  5319. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5320. return this;
  5321. },
  5322. setW: function ( index, w ) {
  5323. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5324. return this;
  5325. },
  5326. getX: function ( index ) {
  5327. return this.data.array[ index * this.data.stride + this.offset ];
  5328. },
  5329. getY: function ( index ) {
  5330. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5331. },
  5332. getZ: function ( index ) {
  5333. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5334. },
  5335. getW: function ( index ) {
  5336. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5337. },
  5338. setXY: function ( index, x, y ) {
  5339. index = index * this.data.stride + this.offset;
  5340. this.data.array[ index + 0 ] = x;
  5341. this.data.array[ index + 1 ] = y;
  5342. return this;
  5343. },
  5344. setXYZ: function ( index, x, y, z ) {
  5345. index = index * this.data.stride + this.offset;
  5346. this.data.array[ index + 0 ] = x;
  5347. this.data.array[ index + 1 ] = y;
  5348. this.data.array[ index + 2 ] = z;
  5349. return this;
  5350. },
  5351. setXYZW: function ( index, x, y, z, w ) {
  5352. index = index * this.data.stride + this.offset;
  5353. this.data.array[ index + 0 ] = x;
  5354. this.data.array[ index + 1 ] = y;
  5355. this.data.array[ index + 2 ] = z;
  5356. this.data.array[ index + 3 ] = w;
  5357. return this;
  5358. }
  5359. };
  5360. // File:src/core/Geometry.js
  5361. /**
  5362. * @author mrdoob / http://mrdoob.com/
  5363. * @author kile / http://kile.stravaganza.org/
  5364. * @author alteredq / http://alteredqualia.com/
  5365. * @author mikael emtinger / http://gomo.se/
  5366. * @author zz85 / http://www.lab4games.net/zz85/blog
  5367. * @author bhouston / http://clara.io
  5368. */
  5369. THREE.Geometry = function () {
  5370. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5371. this.uuid = THREE.Math.generateUUID();
  5372. this.name = '';
  5373. this.type = 'Geometry';
  5374. this.vertices = [];
  5375. this.colors = [];
  5376. this.faces = [];
  5377. this.faceVertexUvs = [ [] ];
  5378. this.morphTargets = [];
  5379. this.morphColors = [];
  5380. this.morphNormals = [];
  5381. this.skinWeights = [];
  5382. this.skinIndices = [];
  5383. this.lineDistances = [];
  5384. this.boundingBox = null;
  5385. this.boundingSphere = null;
  5386. // update flags
  5387. this.verticesNeedUpdate = false;
  5388. this.elementsNeedUpdate = false;
  5389. this.uvsNeedUpdate = false;
  5390. this.normalsNeedUpdate = false;
  5391. this.colorsNeedUpdate = false;
  5392. this.lineDistancesNeedUpdate = false;
  5393. this.groupsNeedUpdate = false;
  5394. };
  5395. THREE.Geometry.prototype = {
  5396. constructor: THREE.Geometry,
  5397. applyMatrix: function ( matrix ) {
  5398. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5399. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5400. var vertex = this.vertices[ i ];
  5401. vertex.applyMatrix4( matrix );
  5402. }
  5403. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5404. var face = this.faces[ i ];
  5405. face.normal.applyMatrix3( normalMatrix ).normalize();
  5406. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5407. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5408. }
  5409. }
  5410. if ( this.boundingBox !== null ) {
  5411. this.computeBoundingBox();
  5412. }
  5413. if ( this.boundingSphere !== null ) {
  5414. this.computeBoundingSphere();
  5415. }
  5416. this.verticesNeedUpdate = true;
  5417. this.normalsNeedUpdate = true;
  5418. },
  5419. rotateX: function () {
  5420. // rotate geometry around world x-axis
  5421. var m1;
  5422. return function rotateX( angle ) {
  5423. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5424. m1.makeRotationX( angle );
  5425. this.applyMatrix( m1 );
  5426. return this;
  5427. };
  5428. }(),
  5429. rotateY: function () {
  5430. // rotate geometry around world y-axis
  5431. var m1;
  5432. return function rotateY( angle ) {
  5433. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5434. m1.makeRotationY( angle );
  5435. this.applyMatrix( m1 );
  5436. return this;
  5437. };
  5438. }(),
  5439. rotateZ: function () {
  5440. // rotate geometry around world z-axis
  5441. var m1;
  5442. return function rotateZ( angle ) {
  5443. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5444. m1.makeRotationZ( angle );
  5445. this.applyMatrix( m1 );
  5446. return this;
  5447. };
  5448. }(),
  5449. translate: function () {
  5450. // translate geometry
  5451. var m1;
  5452. return function translate( x, y, z ) {
  5453. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5454. m1.makeTranslation( x, y, z );
  5455. this.applyMatrix( m1 );
  5456. return this;
  5457. };
  5458. }(),
  5459. scale: function () {
  5460. // scale geometry
  5461. var m1;
  5462. return function scale( x, y, z ) {
  5463. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5464. m1.makeScale( x, y, z );
  5465. this.applyMatrix( m1 );
  5466. return this;
  5467. };
  5468. }(),
  5469. lookAt: function () {
  5470. var obj;
  5471. return function lookAt( vector ) {
  5472. if ( obj === undefined ) obj = new THREE.Object3D();
  5473. obj.lookAt( vector );
  5474. obj.updateMatrix();
  5475. this.applyMatrix( obj.matrix );
  5476. };
  5477. }(),
  5478. fromBufferGeometry: function ( geometry ) {
  5479. var scope = this;
  5480. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5481. var attributes = geometry.attributes;
  5482. var vertices = attributes.position.array;
  5483. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5484. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5485. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5486. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5487. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5488. var tempNormals = [];
  5489. var tempUVs = [];
  5490. var tempUVs2 = [];
  5491. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5492. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5493. if ( normals !== undefined ) {
  5494. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5495. }
  5496. if ( colors !== undefined ) {
  5497. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5498. }
  5499. if ( uvs !== undefined ) {
  5500. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5501. }
  5502. if ( uvs2 !== undefined ) {
  5503. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5504. }
  5505. }
  5506. function addFace( a, b, c ) {
  5507. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5508. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5509. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5510. scope.faces.push( face );
  5511. if ( uvs !== undefined ) {
  5512. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5513. }
  5514. if ( uvs2 !== undefined ) {
  5515. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5516. }
  5517. };
  5518. if ( indices !== undefined ) {
  5519. var groups = geometry.groups;
  5520. if ( groups.length > 0 ) {
  5521. for ( var i = 0; i < groups.length; i ++ ) {
  5522. var group = groups[ i ];
  5523. var start = group.start;
  5524. var count = group.count;
  5525. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5526. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5527. }
  5528. }
  5529. } else {
  5530. for ( var i = 0; i < indices.length; i += 3 ) {
  5531. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5532. }
  5533. }
  5534. } else {
  5535. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5536. addFace( i, i + 1, i + 2 );
  5537. }
  5538. }
  5539. this.computeFaceNormals();
  5540. if ( geometry.boundingBox !== null ) {
  5541. this.boundingBox = geometry.boundingBox.clone();
  5542. }
  5543. if ( geometry.boundingSphere !== null ) {
  5544. this.boundingSphere = geometry.boundingSphere.clone();
  5545. }
  5546. return this;
  5547. },
  5548. center: function () {
  5549. this.computeBoundingBox();
  5550. var offset = this.boundingBox.center().negate();
  5551. this.translate( offset.x, offset.y, offset.z );
  5552. return offset;
  5553. },
  5554. normalize: function () {
  5555. this.computeBoundingSphere();
  5556. var center = this.boundingSphere.center;
  5557. var radius = this.boundingSphere.radius;
  5558. var s = radius === 0 ? 1 : 1.0 / radius;
  5559. var matrix = new THREE.Matrix4();
  5560. matrix.set(
  5561. s, 0, 0, - s * center.x,
  5562. 0, s, 0, - s * center.y,
  5563. 0, 0, s, - s * center.z,
  5564. 0, 0, 0, 1
  5565. );
  5566. this.applyMatrix( matrix );
  5567. return this;
  5568. },
  5569. computeFaceNormals: function () {
  5570. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5571. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5572. var face = this.faces[ f ];
  5573. var vA = this.vertices[ face.a ];
  5574. var vB = this.vertices[ face.b ];
  5575. var vC = this.vertices[ face.c ];
  5576. cb.subVectors( vC, vB );
  5577. ab.subVectors( vA, vB );
  5578. cb.cross( ab );
  5579. cb.normalize();
  5580. face.normal.copy( cb );
  5581. }
  5582. },
  5583. computeVertexNormals: function ( areaWeighted ) {
  5584. var v, vl, f, fl, face, vertices;
  5585. vertices = new Array( this.vertices.length );
  5586. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5587. vertices[ v ] = new THREE.Vector3();
  5588. }
  5589. if ( areaWeighted ) {
  5590. // vertex normals weighted by triangle areas
  5591. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5592. var vA, vB, vC;
  5593. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5594. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5595. face = this.faces[ f ];
  5596. vA = this.vertices[ face.a ];
  5597. vB = this.vertices[ face.b ];
  5598. vC = this.vertices[ face.c ];
  5599. cb.subVectors( vC, vB );
  5600. ab.subVectors( vA, vB );
  5601. cb.cross( ab );
  5602. vertices[ face.a ].add( cb );
  5603. vertices[ face.b ].add( cb );
  5604. vertices[ face.c ].add( cb );
  5605. }
  5606. } else {
  5607. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5608. face = this.faces[ f ];
  5609. vertices[ face.a ].add( face.normal );
  5610. vertices[ face.b ].add( face.normal );
  5611. vertices[ face.c ].add( face.normal );
  5612. }
  5613. }
  5614. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5615. vertices[ v ].normalize();
  5616. }
  5617. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5618. face = this.faces[ f ];
  5619. var vertexNormals = face.vertexNormals;
  5620. if ( vertexNormals.length === 3 ) {
  5621. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5622. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5623. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5624. } else {
  5625. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5626. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5627. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5628. }
  5629. }
  5630. },
  5631. computeMorphNormals: function () {
  5632. var i, il, f, fl, face;
  5633. // save original normals
  5634. // - create temp variables on first access
  5635. // otherwise just copy (for faster repeated calls)
  5636. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5637. face = this.faces[ f ];
  5638. if ( ! face.__originalFaceNormal ) {
  5639. face.__originalFaceNormal = face.normal.clone();
  5640. } else {
  5641. face.__originalFaceNormal.copy( face.normal );
  5642. }
  5643. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5644. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5645. if ( ! face.__originalVertexNormals[ i ] ) {
  5646. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5647. } else {
  5648. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5649. }
  5650. }
  5651. }
  5652. // use temp geometry to compute face and vertex normals for each morph
  5653. var tmpGeo = new THREE.Geometry();
  5654. tmpGeo.faces = this.faces;
  5655. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5656. // create on first access
  5657. if ( ! this.morphNormals[ i ] ) {
  5658. this.morphNormals[ i ] = {};
  5659. this.morphNormals[ i ].faceNormals = [];
  5660. this.morphNormals[ i ].vertexNormals = [];
  5661. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5662. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5663. var faceNormal, vertexNormals;
  5664. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5665. faceNormal = new THREE.Vector3();
  5666. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5667. dstNormalsFace.push( faceNormal );
  5668. dstNormalsVertex.push( vertexNormals );
  5669. }
  5670. }
  5671. var morphNormals = this.morphNormals[ i ];
  5672. // set vertices to morph target
  5673. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5674. // compute morph normals
  5675. tmpGeo.computeFaceNormals();
  5676. tmpGeo.computeVertexNormals();
  5677. // store morph normals
  5678. var faceNormal, vertexNormals;
  5679. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5680. face = this.faces[ f ];
  5681. faceNormal = morphNormals.faceNormals[ f ];
  5682. vertexNormals = morphNormals.vertexNormals[ f ];
  5683. faceNormal.copy( face.normal );
  5684. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5685. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5686. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5687. }
  5688. }
  5689. // restore original normals
  5690. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5691. face = this.faces[ f ];
  5692. face.normal = face.__originalFaceNormal;
  5693. face.vertexNormals = face.__originalVertexNormals;
  5694. }
  5695. },
  5696. computeTangents: function () {
  5697. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  5698. },
  5699. computeLineDistances: function () {
  5700. var d = 0;
  5701. var vertices = this.vertices;
  5702. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5703. if ( i > 0 ) {
  5704. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5705. }
  5706. this.lineDistances[ i ] = d;
  5707. }
  5708. },
  5709. computeBoundingBox: function () {
  5710. if ( this.boundingBox === null ) {
  5711. this.boundingBox = new THREE.Box3();
  5712. }
  5713. this.boundingBox.setFromPoints( this.vertices );
  5714. },
  5715. computeBoundingSphere: function () {
  5716. if ( this.boundingSphere === null ) {
  5717. this.boundingSphere = new THREE.Sphere();
  5718. }
  5719. this.boundingSphere.setFromPoints( this.vertices );
  5720. },
  5721. merge: function ( geometry, matrix, materialIndexOffset ) {
  5722. if ( geometry instanceof THREE.Geometry === false ) {
  5723. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5724. return;
  5725. }
  5726. var normalMatrix,
  5727. vertexOffset = this.vertices.length,
  5728. vertices1 = this.vertices,
  5729. vertices2 = geometry.vertices,
  5730. faces1 = this.faces,
  5731. faces2 = geometry.faces,
  5732. uvs1 = this.faceVertexUvs[ 0 ],
  5733. uvs2 = geometry.faceVertexUvs[ 0 ];
  5734. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5735. if ( matrix !== undefined ) {
  5736. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5737. }
  5738. // vertices
  5739. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5740. var vertex = vertices2[ i ];
  5741. var vertexCopy = vertex.clone();
  5742. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5743. vertices1.push( vertexCopy );
  5744. }
  5745. // faces
  5746. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5747. var face = faces2[ i ], faceCopy, normal, color,
  5748. faceVertexNormals = face.vertexNormals,
  5749. faceVertexColors = face.vertexColors;
  5750. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5751. faceCopy.normal.copy( face.normal );
  5752. if ( normalMatrix !== undefined ) {
  5753. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5754. }
  5755. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5756. normal = faceVertexNormals[ j ].clone();
  5757. if ( normalMatrix !== undefined ) {
  5758. normal.applyMatrix3( normalMatrix ).normalize();
  5759. }
  5760. faceCopy.vertexNormals.push( normal );
  5761. }
  5762. faceCopy.color.copy( face.color );
  5763. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5764. color = faceVertexColors[ j ];
  5765. faceCopy.vertexColors.push( color.clone() );
  5766. }
  5767. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5768. faces1.push( faceCopy );
  5769. }
  5770. // uvs
  5771. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5772. var uv = uvs2[ i ], uvCopy = [];
  5773. if ( uv === undefined ) {
  5774. continue;
  5775. }
  5776. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5777. uvCopy.push( uv[ j ].clone() );
  5778. }
  5779. uvs1.push( uvCopy );
  5780. }
  5781. },
  5782. mergeMesh: function ( mesh ) {
  5783. if ( mesh instanceof THREE.Mesh === false ) {
  5784. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5785. return;
  5786. }
  5787. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5788. this.merge( mesh.geometry, mesh.matrix );
  5789. },
  5790. /*
  5791. * Checks for duplicate vertices with hashmap.
  5792. * Duplicated vertices are removed
  5793. * and faces' vertices are updated.
  5794. */
  5795. mergeVertices: function () {
  5796. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5797. var unique = [], changes = [];
  5798. var v, key;
  5799. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5800. var precision = Math.pow( 10, precisionPoints );
  5801. var i, il, face;
  5802. var indices, j, jl;
  5803. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5804. v = this.vertices[ i ];
  5805. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5806. if ( verticesMap[ key ] === undefined ) {
  5807. verticesMap[ key ] = i;
  5808. unique.push( this.vertices[ i ] );
  5809. changes[ i ] = unique.length - 1;
  5810. } else {
  5811. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5812. changes[ i ] = changes[ verticesMap[ key ] ];
  5813. }
  5814. }
  5815. // if faces are completely degenerate after merging vertices, we
  5816. // have to remove them from the geometry.
  5817. var faceIndicesToRemove = [];
  5818. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5819. face = this.faces[ i ];
  5820. face.a = changes[ face.a ];
  5821. face.b = changes[ face.b ];
  5822. face.c = changes[ face.c ];
  5823. indices = [ face.a, face.b, face.c ];
  5824. var dupIndex = - 1;
  5825. // if any duplicate vertices are found in a Face3
  5826. // we have to remove the face as nothing can be saved
  5827. for ( var n = 0; n < 3; n ++ ) {
  5828. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5829. dupIndex = n;
  5830. faceIndicesToRemove.push( i );
  5831. break;
  5832. }
  5833. }
  5834. }
  5835. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5836. var idx = faceIndicesToRemove[ i ];
  5837. this.faces.splice( idx, 1 );
  5838. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5839. this.faceVertexUvs[ j ].splice( idx, 1 );
  5840. }
  5841. }
  5842. // Use unique set of vertices
  5843. var diff = this.vertices.length - unique.length;
  5844. this.vertices = unique;
  5845. return diff;
  5846. },
  5847. sortFacesByMaterialIndex: function () {
  5848. var faces = this.faces;
  5849. var length = faces.length;
  5850. // tag faces
  5851. for ( var i = 0; i < length; i ++ ) {
  5852. faces[ i ]._id = i;
  5853. }
  5854. // sort faces
  5855. function materialIndexSort( a, b ) {
  5856. return a.materialIndex - b.materialIndex;
  5857. }
  5858. faces.sort( materialIndexSort );
  5859. // sort uvs
  5860. var uvs1 = this.faceVertexUvs[ 0 ];
  5861. var uvs2 = this.faceVertexUvs[ 1 ];
  5862. var newUvs1, newUvs2;
  5863. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5864. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5865. for ( var i = 0; i < length; i ++ ) {
  5866. var id = faces[ i ]._id;
  5867. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5868. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5869. }
  5870. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5871. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5872. },
  5873. toJSON: function () {
  5874. var data = {
  5875. metadata: {
  5876. version: 4.4,
  5877. type: 'Geometry',
  5878. generator: 'Geometry.toJSON'
  5879. }
  5880. };
  5881. // standard Geometry serialization
  5882. data.uuid = this.uuid;
  5883. data.type = this.type;
  5884. if ( this.name !== '' ) data.name = this.name;
  5885. if ( this.parameters !== undefined ) {
  5886. var parameters = this.parameters;
  5887. for ( var key in parameters ) {
  5888. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5889. }
  5890. return data;
  5891. }
  5892. var vertices = [];
  5893. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5894. var vertex = this.vertices[ i ];
  5895. vertices.push( vertex.x, vertex.y, vertex.z );
  5896. }
  5897. var faces = [];
  5898. var normals = [];
  5899. var normalsHash = {};
  5900. var colors = [];
  5901. var colorsHash = {};
  5902. var uvs = [];
  5903. var uvsHash = {};
  5904. for ( var i = 0; i < this.faces.length; i ++ ) {
  5905. var face = this.faces[ i ];
  5906. var hasMaterial = false; // face.materialIndex !== undefined;
  5907. var hasFaceUv = false; // deprecated
  5908. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5909. var hasFaceNormal = face.normal.length() > 0;
  5910. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5911. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5912. var hasFaceVertexColor = face.vertexColors.length > 0;
  5913. var faceType = 0;
  5914. faceType = setBit( faceType, 0, 0 );
  5915. faceType = setBit( faceType, 1, hasMaterial );
  5916. faceType = setBit( faceType, 2, hasFaceUv );
  5917. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5918. faceType = setBit( faceType, 4, hasFaceNormal );
  5919. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5920. faceType = setBit( faceType, 6, hasFaceColor );
  5921. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5922. faces.push( faceType );
  5923. faces.push( face.a, face.b, face.c );
  5924. if ( hasFaceVertexUv ) {
  5925. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5926. faces.push(
  5927. getUvIndex( faceVertexUvs[ 0 ] ),
  5928. getUvIndex( faceVertexUvs[ 1 ] ),
  5929. getUvIndex( faceVertexUvs[ 2 ] )
  5930. );
  5931. }
  5932. if ( hasFaceNormal ) {
  5933. faces.push( getNormalIndex( face.normal ) );
  5934. }
  5935. if ( hasFaceVertexNormal ) {
  5936. var vertexNormals = face.vertexNormals;
  5937. faces.push(
  5938. getNormalIndex( vertexNormals[ 0 ] ),
  5939. getNormalIndex( vertexNormals[ 1 ] ),
  5940. getNormalIndex( vertexNormals[ 2 ] )
  5941. );
  5942. }
  5943. if ( hasFaceColor ) {
  5944. faces.push( getColorIndex( face.color ) );
  5945. }
  5946. if ( hasFaceVertexColor ) {
  5947. var vertexColors = face.vertexColors;
  5948. faces.push(
  5949. getColorIndex( vertexColors[ 0 ] ),
  5950. getColorIndex( vertexColors[ 1 ] ),
  5951. getColorIndex( vertexColors[ 2 ] )
  5952. );
  5953. }
  5954. }
  5955. function setBit( value, position, enabled ) {
  5956. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5957. }
  5958. function getNormalIndex( normal ) {
  5959. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5960. if ( normalsHash[ hash ] !== undefined ) {
  5961. return normalsHash[ hash ];
  5962. }
  5963. normalsHash[ hash ] = normals.length / 3;
  5964. normals.push( normal.x, normal.y, normal.z );
  5965. return normalsHash[ hash ];
  5966. }
  5967. function getColorIndex( color ) {
  5968. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5969. if ( colorsHash[ hash ] !== undefined ) {
  5970. return colorsHash[ hash ];
  5971. }
  5972. colorsHash[ hash ] = colors.length;
  5973. colors.push( color.getHex() );
  5974. return colorsHash[ hash ];
  5975. }
  5976. function getUvIndex( uv ) {
  5977. var hash = uv.x.toString() + uv.y.toString();
  5978. if ( uvsHash[ hash ] !== undefined ) {
  5979. return uvsHash[ hash ];
  5980. }
  5981. uvsHash[ hash ] = uvs.length / 2;
  5982. uvs.push( uv.x, uv.y );
  5983. return uvsHash[ hash ];
  5984. }
  5985. data.data = {};
  5986. data.data.vertices = vertices;
  5987. data.data.normals = normals;
  5988. if ( colors.length > 0 ) data.data.colors = colors;
  5989. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5990. data.data.faces = faces;
  5991. return data;
  5992. },
  5993. clone: function () {
  5994. return new this.constructor().copy( this );
  5995. },
  5996. copy: function ( source ) {
  5997. this.vertices = [];
  5998. this.faces = [];
  5999. this.faceVertexUvs = [ [] ];
  6000. var vertices = source.vertices;
  6001. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6002. this.vertices.push( vertices[ i ].clone() );
  6003. }
  6004. var faces = source.faces;
  6005. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6006. this.faces.push( faces[ i ].clone() );
  6007. }
  6008. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6009. var faceVertexUvs = source.faceVertexUvs[ i ];
  6010. if ( this.faceVertexUvs[ i ] === undefined ) {
  6011. this.faceVertexUvs[ i ] = [];
  6012. }
  6013. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6014. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6015. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6016. var uv = uvs[ k ];
  6017. uvsCopy.push( uv.clone() );
  6018. }
  6019. this.faceVertexUvs[ i ].push( uvsCopy );
  6020. }
  6021. }
  6022. return this;
  6023. },
  6024. dispose: function () {
  6025. this.dispatchEvent( { type: 'dispose' } );
  6026. }
  6027. };
  6028. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6029. THREE.GeometryIdCount = 0;
  6030. // File:src/core/DirectGeometry.js
  6031. /**
  6032. * @author mrdoob / http://mrdoob.com/
  6033. */
  6034. THREE.DirectGeometry = function () {
  6035. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6036. this.uuid = THREE.Math.generateUUID();
  6037. this.name = '';
  6038. this.type = 'DirectGeometry';
  6039. this.indices = [];
  6040. this.vertices = [];
  6041. this.normals = [];
  6042. this.colors = [];
  6043. this.uvs = [];
  6044. this.uvs2 = [];
  6045. this.groups = [];
  6046. this.morphTargets = {};
  6047. this.skinWeights = [];
  6048. this.skinIndices = [];
  6049. // this.lineDistances = [];
  6050. this.boundingBox = null;
  6051. this.boundingSphere = null;
  6052. // update flags
  6053. this.verticesNeedUpdate = false;
  6054. this.normalsNeedUpdate = false;
  6055. this.colorsNeedUpdate = false;
  6056. this.uvsNeedUpdate = false;
  6057. this.groupsNeedUpdate = false;
  6058. };
  6059. THREE.DirectGeometry.prototype = {
  6060. constructor: THREE.DirectGeometry,
  6061. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6062. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6063. computeFaceNormals: function () {
  6064. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6065. },
  6066. computeVertexNormals: function () {
  6067. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6068. },
  6069. computeGroups: function ( geometry ) {
  6070. var group;
  6071. var groups = [];
  6072. var materialIndex;
  6073. var faces = geometry.faces;
  6074. for ( var i = 0; i < faces.length; i ++ ) {
  6075. var face = faces[ i ];
  6076. // materials
  6077. if ( face.materialIndex !== materialIndex ) {
  6078. materialIndex = face.materialIndex;
  6079. if ( group !== undefined ) {
  6080. group.count = ( i * 3 ) - group.start;
  6081. groups.push( group );
  6082. }
  6083. group = {
  6084. start: i * 3,
  6085. materialIndex: materialIndex
  6086. };
  6087. }
  6088. }
  6089. if ( group !== undefined ) {
  6090. group.count = ( i * 3 ) - group.start;
  6091. groups.push( group );
  6092. }
  6093. this.groups = groups;
  6094. },
  6095. fromGeometry: function ( geometry ) {
  6096. var faces = geometry.faces;
  6097. var vertices = geometry.vertices;
  6098. var faceVertexUvs = geometry.faceVertexUvs;
  6099. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6100. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6101. // morphs
  6102. var morphTargets = geometry.morphTargets;
  6103. var morphTargetsLength = morphTargets.length;
  6104. if ( morphTargetsLength > 0 ) {
  6105. var morphTargetsPosition = [];
  6106. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6107. morphTargetsPosition[ i ] = [];
  6108. }
  6109. this.morphTargets.position = morphTargetsPosition;
  6110. }
  6111. var morphNormals = geometry.morphNormals;
  6112. var morphNormalsLength = morphNormals.length;
  6113. if ( morphNormalsLength > 0 ) {
  6114. var morphTargetsNormal = [];
  6115. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6116. morphTargetsNormal[ i ] = [];
  6117. }
  6118. this.morphTargets.normal = morphTargetsNormal;
  6119. }
  6120. // skins
  6121. var skinIndices = geometry.skinIndices;
  6122. var skinWeights = geometry.skinWeights;
  6123. var hasSkinIndices = skinIndices.length === vertices.length;
  6124. var hasSkinWeights = skinWeights.length === vertices.length;
  6125. //
  6126. for ( var i = 0; i < faces.length; i ++ ) {
  6127. var face = faces[ i ];
  6128. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6129. var vertexNormals = face.vertexNormals;
  6130. if ( vertexNormals.length === 3 ) {
  6131. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6132. } else {
  6133. var normal = face.normal;
  6134. this.normals.push( normal, normal, normal );
  6135. }
  6136. var vertexColors = face.vertexColors;
  6137. if ( vertexColors.length === 3 ) {
  6138. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6139. } else {
  6140. var color = face.color;
  6141. this.colors.push( color, color, color );
  6142. }
  6143. if ( hasFaceVertexUv === true ) {
  6144. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6145. if ( vertexUvs !== undefined ) {
  6146. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6147. } else {
  6148. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6149. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6150. }
  6151. }
  6152. if ( hasFaceVertexUv2 === true ) {
  6153. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6154. if ( vertexUvs !== undefined ) {
  6155. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6156. } else {
  6157. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6158. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6159. }
  6160. }
  6161. // morphs
  6162. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6163. var morphTarget = morphTargets[ j ].vertices;
  6164. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6165. }
  6166. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6167. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6168. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6169. }
  6170. // skins
  6171. if ( hasSkinIndices ) {
  6172. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6173. }
  6174. if ( hasSkinWeights ) {
  6175. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6176. }
  6177. }
  6178. this.computeGroups( geometry );
  6179. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6180. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6181. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6182. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6183. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6184. return this;
  6185. },
  6186. dispose: function () {
  6187. this.dispatchEvent( { type: 'dispose' } );
  6188. }
  6189. };
  6190. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6191. // File:src/core/BufferGeometry.js
  6192. /**
  6193. * @author alteredq / http://alteredqualia.com/
  6194. * @author mrdoob / http://mrdoob.com/
  6195. */
  6196. THREE.BufferGeometry = function () {
  6197. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6198. this.uuid = THREE.Math.generateUUID();
  6199. this.name = '';
  6200. this.type = 'BufferGeometry';
  6201. this.index = null;
  6202. this.attributes = {};
  6203. this.morphAttributes = {};
  6204. this.groups = [];
  6205. this.boundingBox = null;
  6206. this.boundingSphere = null;
  6207. this.drawRange = { start: 0, count: Infinity };
  6208. };
  6209. THREE.BufferGeometry.prototype = {
  6210. constructor: THREE.BufferGeometry,
  6211. addIndex: function ( index ) {
  6212. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6213. this.setIndex( index );
  6214. },
  6215. getIndex: function () {
  6216. return this.index;
  6217. },
  6218. setIndex: function ( index ) {
  6219. this.index = index;
  6220. },
  6221. addAttribute: function ( name, attribute ) {
  6222. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6223. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6224. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6225. return;
  6226. }
  6227. if ( name === 'index' ) {
  6228. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6229. this.setIndex( attribute );
  6230. return;
  6231. }
  6232. this.attributes[ name ] = attribute;
  6233. },
  6234. getAttribute: function ( name ) {
  6235. return this.attributes[ name ];
  6236. },
  6237. removeAttribute: function ( name ) {
  6238. delete this.attributes[ name ];
  6239. },
  6240. get drawcalls() {
  6241. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6242. return this.groups;
  6243. },
  6244. get offsets() {
  6245. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6246. return this.groups;
  6247. },
  6248. addDrawCall: function ( start, count, indexOffset ) {
  6249. if ( indexOffset !== undefined ) {
  6250. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6251. }
  6252. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6253. this.addGroup( start, count );
  6254. },
  6255. clearDrawCalls: function () {
  6256. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6257. this.clearGroups();
  6258. },
  6259. addGroup: function ( start, count, materialIndex ) {
  6260. this.groups.push( {
  6261. start: start,
  6262. count: count,
  6263. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6264. } );
  6265. },
  6266. clearGroups: function () {
  6267. this.groups = [];
  6268. },
  6269. setDrawRange: function ( start, count ) {
  6270. this.drawRange.start = start;
  6271. this.drawRange.count = count;
  6272. },
  6273. applyMatrix: function ( matrix ) {
  6274. var position = this.attributes.position;
  6275. if ( position !== undefined ) {
  6276. matrix.applyToVector3Array( position.array );
  6277. position.needsUpdate = true;
  6278. }
  6279. var normal = this.attributes.normal;
  6280. if ( normal !== undefined ) {
  6281. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6282. normalMatrix.applyToVector3Array( normal.array );
  6283. normal.needsUpdate = true;
  6284. }
  6285. if ( this.boundingBox !== null ) {
  6286. this.computeBoundingBox();
  6287. }
  6288. if ( this.boundingSphere !== null ) {
  6289. this.computeBoundingSphere();
  6290. }
  6291. },
  6292. rotateX: function () {
  6293. // rotate geometry around world x-axis
  6294. var m1;
  6295. return function rotateX( angle ) {
  6296. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6297. m1.makeRotationX( angle );
  6298. this.applyMatrix( m1 );
  6299. return this;
  6300. };
  6301. }(),
  6302. rotateY: function () {
  6303. // rotate geometry around world y-axis
  6304. var m1;
  6305. return function rotateY( angle ) {
  6306. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6307. m1.makeRotationY( angle );
  6308. this.applyMatrix( m1 );
  6309. return this;
  6310. };
  6311. }(),
  6312. rotateZ: function () {
  6313. // rotate geometry around world z-axis
  6314. var m1;
  6315. return function rotateZ( angle ) {
  6316. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6317. m1.makeRotationZ( angle );
  6318. this.applyMatrix( m1 );
  6319. return this;
  6320. };
  6321. }(),
  6322. translate: function () {
  6323. // translate geometry
  6324. var m1;
  6325. return function translate( x, y, z ) {
  6326. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6327. m1.makeTranslation( x, y, z );
  6328. this.applyMatrix( m1 );
  6329. return this;
  6330. };
  6331. }(),
  6332. scale: function () {
  6333. // scale geometry
  6334. var m1;
  6335. return function scale( x, y, z ) {
  6336. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6337. m1.makeScale( x, y, z );
  6338. this.applyMatrix( m1 );
  6339. return this;
  6340. };
  6341. }(),
  6342. lookAt: function () {
  6343. var obj;
  6344. return function lookAt( vector ) {
  6345. if ( obj === undefined ) obj = new THREE.Object3D();
  6346. obj.lookAt( vector );
  6347. obj.updateMatrix();
  6348. this.applyMatrix( obj.matrix );
  6349. };
  6350. }(),
  6351. center: function () {
  6352. this.computeBoundingBox();
  6353. var offset = this.boundingBox.center().negate();
  6354. this.translate( offset.x, offset.y, offset.z );
  6355. return offset;
  6356. },
  6357. setFromObject: function ( object ) {
  6358. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6359. var geometry = object.geometry;
  6360. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6361. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6362. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6363. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6364. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6365. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6366. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6367. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6368. }
  6369. if ( geometry.boundingSphere !== null ) {
  6370. this.boundingSphere = geometry.boundingSphere.clone();
  6371. }
  6372. if ( geometry.boundingBox !== null ) {
  6373. this.boundingBox = geometry.boundingBox.clone();
  6374. }
  6375. } else if ( object instanceof THREE.Mesh ) {
  6376. if ( geometry instanceof THREE.Geometry ) {
  6377. this.fromGeometry( geometry );
  6378. }
  6379. }
  6380. return this;
  6381. },
  6382. updateFromObject: function ( object ) {
  6383. var geometry = object.geometry;
  6384. if ( object instanceof THREE.Mesh ) {
  6385. var direct = geometry.__directGeometry;
  6386. if ( direct === undefined ) {
  6387. return this.fromGeometry( geometry );
  6388. }
  6389. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6390. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6391. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6392. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6393. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6394. geometry.verticesNeedUpdate = false;
  6395. geometry.normalsNeedUpdate = false;
  6396. geometry.colorsNeedUpdate = false;
  6397. geometry.uvsNeedUpdate = false;
  6398. geometry.groupsNeedUpdate = false;
  6399. geometry = direct;
  6400. }
  6401. if ( geometry.verticesNeedUpdate === true ) {
  6402. var attribute = this.attributes.position;
  6403. if ( attribute !== undefined ) {
  6404. attribute.copyVector3sArray( geometry.vertices );
  6405. attribute.needsUpdate = true;
  6406. }
  6407. geometry.verticesNeedUpdate = false;
  6408. }
  6409. if ( geometry.normalsNeedUpdate === true ) {
  6410. var attribute = this.attributes.normal;
  6411. if ( attribute !== undefined ) {
  6412. attribute.copyVector3sArray( geometry.normals );
  6413. attribute.needsUpdate = true;
  6414. }
  6415. geometry.normalsNeedUpdate = false;
  6416. }
  6417. if ( geometry.colorsNeedUpdate === true ) {
  6418. var attribute = this.attributes.color;
  6419. if ( attribute !== undefined ) {
  6420. attribute.copyColorsArray( geometry.colors );
  6421. attribute.needsUpdate = true;
  6422. }
  6423. geometry.colorsNeedUpdate = false;
  6424. }
  6425. if ( geometry.lineDistancesNeedUpdate ) {
  6426. var attribute = this.attributes.lineDistance;
  6427. if ( attribute !== undefined ) {
  6428. attribute.copyArray( geometry.lineDistances );
  6429. attribute.needsUpdate = true;
  6430. }
  6431. geometry.lineDistancesNeedUpdate = false;
  6432. }
  6433. if ( geometry.groupsNeedUpdate ) {
  6434. geometry.computeGroups( object.geometry );
  6435. this.groups = geometry.groups;
  6436. geometry.groupsNeedUpdate = false;
  6437. }
  6438. return this;
  6439. },
  6440. fromGeometry: function ( geometry ) {
  6441. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6442. return this.fromDirectGeometry( geometry.__directGeometry );
  6443. },
  6444. fromDirectGeometry: function ( geometry ) {
  6445. var positions = new Float32Array( geometry.vertices.length * 3 );
  6446. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6447. if ( geometry.normals.length > 0 ) {
  6448. var normals = new Float32Array( geometry.normals.length * 3 );
  6449. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6450. }
  6451. if ( geometry.colors.length > 0 ) {
  6452. var colors = new Float32Array( geometry.colors.length * 3 );
  6453. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6454. }
  6455. if ( geometry.uvs.length > 0 ) {
  6456. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6457. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6458. }
  6459. if ( geometry.uvs2.length > 0 ) {
  6460. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6461. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6462. }
  6463. if ( geometry.indices.length > 0 ) {
  6464. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6465. var indices = new TypeArray( geometry.indices.length * 3 );
  6466. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6467. }
  6468. // groups
  6469. this.groups = geometry.groups;
  6470. // morphs
  6471. for ( var name in geometry.morphTargets ) {
  6472. var array = [];
  6473. var morphTargets = geometry.morphTargets[ name ];
  6474. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6475. var morphTarget = morphTargets[ i ];
  6476. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6477. array.push( attribute.copyVector3sArray( morphTarget ) );
  6478. }
  6479. this.morphAttributes[ name ] = array;
  6480. }
  6481. // skinning
  6482. if ( geometry.skinIndices.length > 0 ) {
  6483. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6484. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6485. }
  6486. if ( geometry.skinWeights.length > 0 ) {
  6487. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6488. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6489. }
  6490. //
  6491. if ( geometry.boundingSphere !== null ) {
  6492. this.boundingSphere = geometry.boundingSphere.clone();
  6493. }
  6494. if ( geometry.boundingBox !== null ) {
  6495. this.boundingBox = geometry.boundingBox.clone();
  6496. }
  6497. return this;
  6498. },
  6499. computeBoundingBox: function () {
  6500. var vector = new THREE.Vector3();
  6501. return function () {
  6502. if ( this.boundingBox === null ) {
  6503. this.boundingBox = new THREE.Box3();
  6504. }
  6505. var positions = this.attributes.position.array;
  6506. if ( positions ) {
  6507. var bb = this.boundingBox;
  6508. bb.makeEmpty();
  6509. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6510. vector.fromArray( positions, i );
  6511. bb.expandByPoint( vector );
  6512. }
  6513. }
  6514. if ( positions === undefined || positions.length === 0 ) {
  6515. this.boundingBox.min.set( 0, 0, 0 );
  6516. this.boundingBox.max.set( 0, 0, 0 );
  6517. }
  6518. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6519. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6520. }
  6521. };
  6522. }(),
  6523. computeBoundingSphere: function () {
  6524. var box = new THREE.Box3();
  6525. var vector = new THREE.Vector3();
  6526. return function () {
  6527. if ( this.boundingSphere === null ) {
  6528. this.boundingSphere = new THREE.Sphere();
  6529. }
  6530. var positions = this.attributes.position.array;
  6531. if ( positions ) {
  6532. box.makeEmpty();
  6533. var center = this.boundingSphere.center;
  6534. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6535. vector.fromArray( positions, i );
  6536. box.expandByPoint( vector );
  6537. }
  6538. box.center( center );
  6539. // hoping to find a boundingSphere with a radius smaller than the
  6540. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6541. var maxRadiusSq = 0;
  6542. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6543. vector.fromArray( positions, i );
  6544. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6545. }
  6546. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6547. if ( isNaN( this.boundingSphere.radius ) ) {
  6548. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6549. }
  6550. }
  6551. };
  6552. }(),
  6553. computeFaceNormals: function () {
  6554. // backwards compatibility
  6555. },
  6556. computeVertexNormals: function () {
  6557. var index = this.index;
  6558. var attributes = this.attributes;
  6559. var groups = this.groups;
  6560. if ( attributes.position ) {
  6561. var positions = attributes.position.array;
  6562. if ( attributes.normal === undefined ) {
  6563. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6564. } else {
  6565. // reset existing normals to zero
  6566. var normals = attributes.normal.array;
  6567. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6568. normals[ i ] = 0;
  6569. }
  6570. }
  6571. var normals = attributes.normal.array;
  6572. var vA, vB, vC,
  6573. pA = new THREE.Vector3(),
  6574. pB = new THREE.Vector3(),
  6575. pC = new THREE.Vector3(),
  6576. cb = new THREE.Vector3(),
  6577. ab = new THREE.Vector3();
  6578. // indexed elements
  6579. if ( index ) {
  6580. var indices = index.array;
  6581. if ( groups.length === 0 ) {
  6582. this.addGroup( 0, indices.length );
  6583. }
  6584. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6585. var group = groups[ j ];
  6586. var start = group.start;
  6587. var count = group.count;
  6588. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6589. vA = indices[ i + 0 ] * 3;
  6590. vB = indices[ i + 1 ] * 3;
  6591. vC = indices[ i + 2 ] * 3;
  6592. pA.fromArray( positions, vA );
  6593. pB.fromArray( positions, vB );
  6594. pC.fromArray( positions, vC );
  6595. cb.subVectors( pC, pB );
  6596. ab.subVectors( pA, pB );
  6597. cb.cross( ab );
  6598. normals[ vA ] += cb.x;
  6599. normals[ vA + 1 ] += cb.y;
  6600. normals[ vA + 2 ] += cb.z;
  6601. normals[ vB ] += cb.x;
  6602. normals[ vB + 1 ] += cb.y;
  6603. normals[ vB + 2 ] += cb.z;
  6604. normals[ vC ] += cb.x;
  6605. normals[ vC + 1 ] += cb.y;
  6606. normals[ vC + 2 ] += cb.z;
  6607. }
  6608. }
  6609. } else {
  6610. // non-indexed elements (unconnected triangle soup)
  6611. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6612. pA.fromArray( positions, i );
  6613. pB.fromArray( positions, i + 3 );
  6614. pC.fromArray( positions, i + 6 );
  6615. cb.subVectors( pC, pB );
  6616. ab.subVectors( pA, pB );
  6617. cb.cross( ab );
  6618. normals[ i ] = cb.x;
  6619. normals[ i + 1 ] = cb.y;
  6620. normals[ i + 2 ] = cb.z;
  6621. normals[ i + 3 ] = cb.x;
  6622. normals[ i + 4 ] = cb.y;
  6623. normals[ i + 5 ] = cb.z;
  6624. normals[ i + 6 ] = cb.x;
  6625. normals[ i + 7 ] = cb.y;
  6626. normals[ i + 8 ] = cb.z;
  6627. }
  6628. }
  6629. this.normalizeNormals();
  6630. attributes.normal.needsUpdate = true;
  6631. }
  6632. },
  6633. computeTangents: function () {
  6634. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6635. },
  6636. computeOffsets: function ( size ) {
  6637. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
  6638. },
  6639. merge: function ( geometry, offset ) {
  6640. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6641. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6642. return;
  6643. }
  6644. if ( offset === undefined ) offset = 0;
  6645. var attributes = this.attributes;
  6646. for ( var key in attributes ) {
  6647. if ( geometry.attributes[ key ] === undefined ) continue;
  6648. var attribute1 = attributes[ key ];
  6649. var attributeArray1 = attribute1.array;
  6650. var attribute2 = geometry.attributes[ key ];
  6651. var attributeArray2 = attribute2.array;
  6652. var attributeSize = attribute2.itemSize;
  6653. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6654. attributeArray1[ j ] = attributeArray2[ i ];
  6655. }
  6656. }
  6657. return this;
  6658. },
  6659. normalizeNormals: function () {
  6660. var normals = this.attributes.normal.array;
  6661. var x, y, z, n;
  6662. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6663. x = normals[ i ];
  6664. y = normals[ i + 1 ];
  6665. z = normals[ i + 2 ];
  6666. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6667. normals[ i ] *= n;
  6668. normals[ i + 1 ] *= n;
  6669. normals[ i + 2 ] *= n;
  6670. }
  6671. },
  6672. toJSON: function () {
  6673. var data = {
  6674. metadata: {
  6675. version: 4.4,
  6676. type: 'BufferGeometry',
  6677. generator: 'BufferGeometry.toJSON'
  6678. }
  6679. };
  6680. // standard BufferGeometry serialization
  6681. data.uuid = this.uuid;
  6682. data.type = this.type;
  6683. if ( this.name !== '' ) data.name = this.name;
  6684. if ( this.parameters !== undefined ) {
  6685. var parameters = this.parameters;
  6686. for ( var key in parameters ) {
  6687. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6688. }
  6689. return data;
  6690. }
  6691. data.data = { attributes: {} };
  6692. var index = this.index;
  6693. if ( index !== null ) {
  6694. var array = Array.prototype.slice.call( index.array );
  6695. data.data.index = {
  6696. type: index.array.constructor.name,
  6697. array: array
  6698. };
  6699. }
  6700. var attributes = this.attributes;
  6701. for ( var key in attributes ) {
  6702. var attribute = attributes[ key ];
  6703. var array = Array.prototype.slice.call( attribute.array );
  6704. data.data.attributes[ key ] = {
  6705. itemSize: attribute.itemSize,
  6706. type: attribute.array.constructor.name,
  6707. array: array
  6708. };
  6709. }
  6710. var groups = this.groups;
  6711. if ( groups.length > 0 ) {
  6712. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6713. }
  6714. var boundingSphere = this.boundingSphere;
  6715. if ( boundingSphere !== null ) {
  6716. data.data.boundingSphere = {
  6717. center: boundingSphere.center.toArray(),
  6718. radius: boundingSphere.radius
  6719. };
  6720. }
  6721. return data;
  6722. },
  6723. clone: function () {
  6724. return new this.constructor().copy( this );
  6725. },
  6726. copy: function ( source ) {
  6727. var index = source.index;
  6728. if ( index !== null ) {
  6729. this.setIndex( index.clone() );
  6730. }
  6731. var attributes = source.attributes;
  6732. for ( var name in attributes ) {
  6733. var attribute = attributes[ name ];
  6734. this.addAttribute( name, attribute.clone() );
  6735. }
  6736. var groups = source.groups;
  6737. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6738. var group = groups[ i ];
  6739. this.addGroup( group.start, group.count );
  6740. }
  6741. return this;
  6742. },
  6743. dispose: function () {
  6744. this.dispatchEvent( { type: 'dispose' } );
  6745. }
  6746. };
  6747. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6748. THREE.BufferGeometry.MaxIndex = 65535;
  6749. // File:src/core/InstancedBufferGeometry.js
  6750. /**
  6751. * @author benaadams / https://twitter.com/ben_a_adams
  6752. */
  6753. THREE.InstancedBufferGeometry = function () {
  6754. THREE.BufferGeometry.call( this );
  6755. this.type = 'InstancedBufferGeometry';
  6756. this.maxInstancedCount = undefined;
  6757. };
  6758. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6759. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6760. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  6761. this.groups.push( {
  6762. start: start,
  6763. count: count,
  6764. instances: instances
  6765. } );
  6766. };
  6767. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  6768. var index = source.index;
  6769. if ( index !== null ) {
  6770. this.setIndex( index.clone() );
  6771. }
  6772. var attributes = source.attributes;
  6773. for ( var name in attributes ) {
  6774. var attribute = attributes[ name ];
  6775. this.addAttribute( name, attribute.clone() );
  6776. }
  6777. var groups = source.groups;
  6778. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6779. var group = groups[ i ];
  6780. this.addGroup( group.start, group.count, group.instances );
  6781. }
  6782. return this;
  6783. };
  6784. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6785. // File:src/animation/AnimationAction.js
  6786. /**
  6787. *
  6788. * A clip that has been explicitly scheduled.
  6789. *
  6790. * @author Ben Houston / http://clara.io/
  6791. * @author David Sarno / http://lighthaus.us/
  6792. */
  6793. THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
  6794. if( clip === undefined ) throw new Error( 'clip is null' );
  6795. this.clip = clip;
  6796. this.localRoot = null;
  6797. this.startTime = startTime || 0;
  6798. this.timeScale = timeScale || 1;
  6799. this.weight = weight || 1;
  6800. this.loop = loop || THREE.LoopRepeat;
  6801. this.loopCount = 0;
  6802. this.enabled = true; // allow for easy disabling of the action.
  6803. this.actionTime = - this.startTime;
  6804. this.clipTime = 0;
  6805. this.propertyBindings = [];
  6806. };
  6807. /*
  6808. THREE.LoopOnce = 2200;
  6809. THREE.LoopRepeat = 2201;
  6810. THREE.LoopPingPing = 2202;
  6811. */
  6812. THREE.AnimationAction.prototype = {
  6813. constructor: THREE.AnimationAction,
  6814. setLocalRoot: function( localRoot ) {
  6815. this.localRoot = localRoot;
  6816. return this;
  6817. },
  6818. updateTime: function( clipDeltaTime ) {
  6819. var previousClipTime = this.clipTime;
  6820. var previousLoopCount = this.loopCount;
  6821. var previousActionTime = this.actionTime;
  6822. var duration = this.clip.duration;
  6823. this.actionTime = this.actionTime + clipDeltaTime;
  6824. if( this.loop === THREE.LoopOnce ) {
  6825. this.loopCount = 0;
  6826. this.clipTime = Math.min( Math.max( this.actionTime, 0 ), duration );
  6827. // if time is changed since last time, see if we have hit a start/end limit
  6828. if( this.clipTime !== previousClipTime ) {
  6829. if( this.clipTime === duration ) {
  6830. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: 1 } );
  6831. }
  6832. else if( this.clipTime === 0 ) {
  6833. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: -1 } );
  6834. }
  6835. }
  6836. return this.clipTime;
  6837. }
  6838. this.loopCount = Math.floor( this.actionTime / duration );
  6839. var newClipTime = this.actionTime - this.loopCount * duration;
  6840. newClipTime = newClipTime % duration;
  6841. // if we are ping pong looping, ensure that we go backwards when appropriate
  6842. if( this.loop == THREE.LoopPingPong ) {
  6843. if( Math.abs( this.loopCount % 2 ) === 1 ) {
  6844. newClipTime = duration - newClipTime;
  6845. }
  6846. }
  6847. this.clipTime = newClipTime;
  6848. if( this.loopCount !== previousLoopCount ) {
  6849. this.mixer.dispatchEvent( { type: 'loop', action: this, loopDelta: ( this.loopCount - this.loopCount ) } );
  6850. }
  6851. return this.clipTime;
  6852. },
  6853. syncWith: function( action ) {
  6854. this.actionTime = action.actionTime;
  6855. this.timeScale = action.timeScale;
  6856. return this;
  6857. },
  6858. warpToDuration: function( duration ) {
  6859. this.timeScale = this.clip.duration / duration;
  6860. return this;
  6861. },
  6862. init: function( time ) {
  6863. this.clipTime = time - this.startTime;
  6864. return this;
  6865. },
  6866. update: function( clipDeltaTime ) {
  6867. this.updateTime( clipDeltaTime );
  6868. var clipResults = this.clip.getAt( this.clipTime );
  6869. return clipResults;
  6870. },
  6871. getTimeScaleAt: function( time ) {
  6872. if( this.timeScale.getAt ) {
  6873. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6874. return this.timeScale.getAt( time );
  6875. }
  6876. return this.timeScale;
  6877. },
  6878. getWeightAt: function( time ) {
  6879. if( this.weight.getAt ) {
  6880. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6881. return this.weight.getAt( time );
  6882. }
  6883. return this.weight;
  6884. }
  6885. };
  6886. // File:src/animation/AnimationClip.js
  6887. /**
  6888. *
  6889. * Reusable set of Tracks that represent an animation.
  6890. *
  6891. * @author Ben Houston / http://clara.io/
  6892. * @author David Sarno / http://lighthaus.us/
  6893. */
  6894. THREE.AnimationClip = function ( name, duration, tracks ) {
  6895. this.name = name;
  6896. this.tracks = tracks;
  6897. this.duration = ( duration !== undefined ) ? duration : -1;
  6898. // this means it should figure out its duration by scanning the tracks
  6899. if( this.duration < 0 ) {
  6900. for( var i = 0; i < this.tracks.length; i ++ ) {
  6901. var track = this.tracks[i];
  6902. this.duration = Math.max( track.keys[ track.keys.length - 1 ].time );
  6903. }
  6904. }
  6905. // maybe only do these on demand, as doing them here could potentially slow down loading
  6906. // but leaving these here during development as this ensures a lot of testing of these functions
  6907. this.trim();
  6908. this.optimize();
  6909. this.results = [];
  6910. };
  6911. THREE.AnimationClip.prototype = {
  6912. constructor: THREE.AnimationClip,
  6913. getAt: function( clipTime ) {
  6914. clipTime = Math.max( 0, Math.min( clipTime, this.duration ) );
  6915. for( var i = 0; i < this.tracks.length; i ++ ) {
  6916. var track = this.tracks[ i ];
  6917. this.results[ i ] = track.getAt( clipTime );
  6918. }
  6919. return this.results;
  6920. },
  6921. trim: function() {
  6922. for( var i = 0; i < this.tracks.length; i ++ ) {
  6923. this.tracks[ i ].trim( 0, this.duration );
  6924. }
  6925. return this;
  6926. },
  6927. optimize: function() {
  6928. for( var i = 0; i < this.tracks.length; i ++ ) {
  6929. this.tracks[ i ].optimize();
  6930. }
  6931. return this;
  6932. }
  6933. };
  6934. THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetSequence, fps ) {
  6935. var numMorphTargets = morphTargetSequence.length;
  6936. var tracks = [];
  6937. for( var i = 0; i < numMorphTargets; i ++ ) {
  6938. var keys = [];
  6939. keys.push( { time: ( i + numMorphTargets - 1 ) % numMorphTargets, value: 0 } );
  6940. keys.push( { time: i, value: 1 } );
  6941. keys.push( { time: ( i + 1 ) % numMorphTargets, value: 0 } );
  6942. keys.sort( THREE.KeyframeTrack.keyComparer );
  6943. // if there is a key at the first frame, duplicate it as the last frame as well for perfect loop.
  6944. if( keys[0].time === 0 ) {
  6945. keys.push( {
  6946. time: numMorphTargets,
  6947. value: keys[0].value
  6948. });
  6949. }
  6950. tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ).scale( 1.0 / fps ) );
  6951. }
  6952. return new THREE.AnimationClip( name, -1, tracks );
  6953. };
  6954. THREE.AnimationClip.findByName = function( clipArray, name ) {
  6955. for( var i = 0; i < clipArray.length; i ++ ) {
  6956. if( clipArray[i].name === name ) {
  6957. return clipArray[i];
  6958. }
  6959. }
  6960. return null;
  6961. };
  6962. THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets, fps ) {
  6963. var animationToMorphTargets = {};
  6964. // tested with https://regex101.com/ on trick sequences such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  6965. var pattern = /^([\w-]*?)([\d]+)$/;
  6966. // sort morph target names into animation groups based patterns like Walk_001, Walk_002, Run_001, Run_002
  6967. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  6968. var morphTarget = morphTargets[ i ];
  6969. var parts = morphTarget.name.match( pattern );
  6970. if ( parts && parts.length > 1 ) {
  6971. var name = parts[ 1 ];
  6972. var animationMorphTargets = animationToMorphTargets[ name ];
  6973. if( ! animationMorphTargets ) {
  6974. animationToMorphTargets[ name ] = animationMorphTargets = [];
  6975. }
  6976. animationMorphTargets.push( morphTarget );
  6977. }
  6978. }
  6979. var clips = [];
  6980. for( var name in animationToMorphTargets ) {
  6981. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  6982. }
  6983. return clips;
  6984. };
  6985. // parse the standard JSON format for clips
  6986. THREE.AnimationClip.parse = function( json ) {
  6987. var tracks = [];
  6988. for( var i = 0; i < json.tracks.length; i ++ ) {
  6989. tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
  6990. }
  6991. return new THREE.AnimationClip( json.name, json.duration, tracks );
  6992. };
  6993. // parse the animation.hierarchy format
  6994. THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
  6995. if( ! animation ) {
  6996. console.error( " no animation in JSONLoader data" );
  6997. return null;
  6998. }
  6999. var convertTrack = function( trackName, animationKeys, propertyName, trackType, animationKeyToValueFunc ) {
  7000. var keys = [];
  7001. for( var k = 0; k < animationKeys.length; k ++ ) {
  7002. var animationKey = animationKeys[k];
  7003. if( animationKey[propertyName] !== undefined ) {
  7004. keys.push( { time: animationKey.time, value: animationKeyToValueFunc( animationKey ) } );
  7005. }
  7006. }
  7007. // only return track if there are actually keys.
  7008. if( keys.length > 0 ) {
  7009. return new trackType( trackName, keys );
  7010. }
  7011. return null;
  7012. };
  7013. var tracks = [];
  7014. var clipName = animation.name || 'default';
  7015. var duration = animation.length || -1; // automatic length determination in AnimationClip.
  7016. var fps = animation.fps || 30;
  7017. var hierarchyTracks = animation.hierarchy || [];
  7018. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7019. var animationKeys = hierarchyTracks[ h ].keys;
  7020. // skip empty tracks
  7021. if( ! animationKeys || animationKeys.length == 0 ) {
  7022. continue;
  7023. }
  7024. // process morph targets in a way exactly compatible with AnimationHandler.init( animation )
  7025. if( animationKeys[0].morphTargets ) {
  7026. // figure out all morph targets used in this track
  7027. var morphTargetNames = {};
  7028. for( var k = 0; k < animationKeys.length; k ++ ) {
  7029. if( animationKeys[k].morphTargets ) {
  7030. for( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7031. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7032. }
  7033. }
  7034. }
  7035. // create a track for each morph target with all zero morphTargetInfluences except for the keys in which the morphTarget is named.
  7036. for( var morphTargetName in morphTargetNames ) {
  7037. var keys = [];
  7038. for( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7039. var animationKey = animationKeys[k];
  7040. keys.push( {
  7041. time: animationKey.time,
  7042. value: (( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7043. });
  7044. }
  7045. tracks.push( new THREE.NumberKeyframeTrack( nodeName + '.morphTargetInfluence[' + morphTargetName + ']', keys ) );
  7046. }
  7047. duration = morphTargetNames.length * ( fps || 1.0 );
  7048. }
  7049. else {
  7050. var boneName = nodeName + '.bones[' + bones[ h ].name + ']';
  7051. // track contains positions...
  7052. var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', THREE.VectorKeyframeTrack, function( animationKey ) {
  7053. return new THREE.Vector3().fromArray( animationKey.pos )
  7054. } );
  7055. if( positionTrack ) tracks.push( positionTrack );
  7056. // track contains quaternions...
  7057. var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', THREE.QuaternionKeyframeTrack, function( animationKey ) {
  7058. if( animationKey.rot.slerp ) {
  7059. return animationKey.rot.clone();
  7060. }
  7061. else {
  7062. return new THREE.Quaternion().fromArray( animationKey.rot );
  7063. }
  7064. } );
  7065. if( quaternionTrack ) tracks.push( quaternionTrack );
  7066. // track contains quaternions...
  7067. var scaleTrack = convertTrack( boneName + '.scale', animationKeys, 'scl', THREE.VectorKeyframeTrack, function( animationKey ) {
  7068. return new THREE.Vector3().fromArray( animationKey.scl )
  7069. } );
  7070. if( scaleTrack ) tracks.push( scaleTrack );
  7071. }
  7072. }
  7073. if( tracks.length === 0 ) {
  7074. return null;
  7075. }
  7076. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7077. return clip;
  7078. };
  7079. // File:src/animation/AnimationMixer.js
  7080. /**
  7081. *
  7082. * Mixes together the AnimationClips scheduled by AnimationActions and applies them to the root and subtree
  7083. *
  7084. *
  7085. * @author Ben Houston / http://clara.io/
  7086. * @author David Sarno / http://lighthaus.us/
  7087. */
  7088. THREE.AnimationMixer = function( root ) {
  7089. this.root = root;
  7090. this.time = 0;
  7091. this.timeScale = 1.0;
  7092. this.actions = [];
  7093. this.propertyBindingMap = {};
  7094. };
  7095. THREE.AnimationMixer.prototype = {
  7096. constructor: THREE.AnimationMixer,
  7097. addAction: function( action ) {
  7098. // TODO: check for duplicate action names? Or provide each action with a UUID?
  7099. this.actions.push( action );
  7100. action.init( this.time );
  7101. action.mixer = this;
  7102. var tracks = action.clip.tracks;
  7103. var root = action.localRoot || this.root;
  7104. for( var i = 0; i < tracks.length; i ++ ) {
  7105. var track = tracks[ i ];
  7106. var propertyBindingKey = root.uuid + '-' + track.name;
  7107. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7108. if( propertyBinding === undefined ) {
  7109. propertyBinding = new THREE.PropertyBinding( root, track.name );
  7110. this.propertyBindingMap[ propertyBindingKey ] = propertyBinding;
  7111. }
  7112. // push in the same order as the tracks.
  7113. action.propertyBindings.push( propertyBinding );
  7114. // track usages of shared property bindings, because if we leave too many around, the mixer can get slow
  7115. propertyBinding.referenceCount += 1;
  7116. }
  7117. },
  7118. removeAllActions: function() {
  7119. for( var i = 0; i < this.actions.length; i ++ ) {
  7120. this.actions[i].mixer = null;
  7121. }
  7122. // unbind all property bindings
  7123. for( var properyBindingKey in this.propertyBindingMap ) {
  7124. this.propertyBindingMap[ properyBindingKey ].unbind();
  7125. }
  7126. this.actions = [];
  7127. this.propertyBindingMap = {};
  7128. return this;
  7129. },
  7130. removeAction: function( action ) {
  7131. var index = this.actions.indexOf( action );
  7132. if ( index !== - 1 ) {
  7133. this.actions.splice( index, 1 );
  7134. action.mixer = null;
  7135. }
  7136. // remove unused property bindings because if we leave them around the mixer can get slow
  7137. var root = action.localRoot || this.root;
  7138. var tracks = action.clip.tracks;
  7139. for( var i = 0; i < tracks.length; i ++ ) {
  7140. var track = tracks[ i ];
  7141. var propertyBindingKey = root.uuid + '-' + track.name;
  7142. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7143. propertyBinding.referenceCount -= 1;
  7144. if( propertyBinding.referenceCount <= 0 ) {
  7145. propertyBinding.unbind();
  7146. delete this.propertyBindingMap[ propertyBindingKey ];
  7147. }
  7148. }
  7149. return this;
  7150. },
  7151. // can be optimized if needed
  7152. findActionByName: function( name ) {
  7153. for( var i = 0; i < this.actions.length; i ++ ) {
  7154. if( this.actions[i].name === name ) return this.actions[i];
  7155. }
  7156. return null;
  7157. },
  7158. play: function( action, optionalFadeInDuration ) {
  7159. action.startTime = this.time;
  7160. this.addAction( action );
  7161. return this;
  7162. },
  7163. fadeOut: function( action, duration ) {
  7164. var keys = [];
  7165. keys.push( { time: this.time, value: 1 } );
  7166. keys.push( { time: this.time + duration, value: 0 } );
  7167. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7168. return this;
  7169. },
  7170. fadeIn: function( action, duration ) {
  7171. var keys = [];
  7172. keys.push( { time: this.time, value: 0 } );
  7173. keys.push( { time: this.time + duration, value: 1 } );
  7174. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7175. return this;
  7176. },
  7177. warp: function( action, startTimeScale, endTimeScale, duration ) {
  7178. var keys = [];
  7179. keys.push( { time: this.time, value: startTimeScale } );
  7180. keys.push( { time: this.time + duration, value: endTimeScale } );
  7181. action.timeScale = new THREE.NumberKeyframeTrack( "timeScale", keys );
  7182. return this;
  7183. },
  7184. crossFade: function( fadeOutAction, fadeInAction, duration, warp ) {
  7185. this.fadeOut( fadeOutAction, duration );
  7186. this.fadeIn( fadeInAction, duration );
  7187. if( warp ) {
  7188. var startEndRatio = fadeOutAction.clip.duration / fadeInAction.clip.duration;
  7189. var endStartRatio = 1.0 / startEndRatio;
  7190. this.warp( fadeOutAction, 1.0, startEndRatio, duration );
  7191. this.warp( fadeInAction, endStartRatio, 1.0, duration );
  7192. }
  7193. return this;
  7194. },
  7195. update: function( deltaTime ) {
  7196. var mixerDeltaTime = deltaTime * this.timeScale;
  7197. this.time += mixerDeltaTime;
  7198. for( var i = 0; i < this.actions.length; i ++ ) {
  7199. var action = this.actions[i];
  7200. var weight = action.getWeightAt( this.time );
  7201. var actionTimeScale = action.getTimeScaleAt( this.time );
  7202. var actionDeltaTime = mixerDeltaTime * actionTimeScale;
  7203. var actionResults = action.update( actionDeltaTime );
  7204. if( action.weight <= 0 || ! action.enabled ) continue;
  7205. for( var j = 0; j < actionResults.length; j ++ ) {
  7206. var name = action.clip.tracks[j].name;
  7207. action.propertyBindings[ j ].accumulate( actionResults[j], weight );
  7208. }
  7209. }
  7210. // apply to nodes
  7211. for( var propertyBindingKey in this.propertyBindingMap ) {
  7212. this.propertyBindingMap[ propertyBindingKey ].apply();
  7213. }
  7214. return this;
  7215. }
  7216. };
  7217. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7218. // File:src/animation/AnimationUtils.js
  7219. /**
  7220. * @author Ben Houston / http://clara.io/
  7221. * @author David Sarno / http://lighthaus.us/
  7222. */
  7223. THREE.AnimationUtils = {
  7224. getEqualsFunc: function( exemplarValue ) {
  7225. if( exemplarValue.equals ) {
  7226. return function equals_object( a, b ) {
  7227. return a.equals( b );
  7228. }
  7229. }
  7230. return function equals_primitive( a, b ) {
  7231. return ( a === b );
  7232. };
  7233. },
  7234. clone: function( exemplarValue ) {
  7235. var typeName = typeof exemplarValue;
  7236. if( typeName === "object" ) {
  7237. if( exemplarValue.clone ) {
  7238. return exemplarValue.clone();
  7239. }
  7240. console.error( "can not figure out how to copy exemplarValue", exemplarValue );
  7241. }
  7242. return exemplarValue;
  7243. },
  7244. lerp: function( a, b, alpha, interTrack ) {
  7245. var lerpFunc = THREE.AnimationUtils.getLerpFunc( a, interTrack );
  7246. return lerpFunc( a, b, alpha );
  7247. },
  7248. lerp_object: function( a, b, alpha ) {
  7249. return a.lerp( b, alpha );
  7250. },
  7251. slerp_object: function( a, b, alpha ) {
  7252. return a.slerp( b, alpha );
  7253. },
  7254. lerp_number: function( a, b, alpha ) {
  7255. return a * ( 1 - alpha ) + b * alpha;
  7256. },
  7257. lerp_boolean: function( a, b, alpha ) {
  7258. return ( alpha < 0.5 ) ? a : b;
  7259. },
  7260. lerp_boolean_immediate: function( a, b, alpha ) {
  7261. return a;
  7262. },
  7263. lerp_string: function( a, b, alpha ) {
  7264. return ( alpha < 0.5 ) ? a : b;
  7265. },
  7266. lerp_string_immediate: function( a, b, alpha ) {
  7267. return a;
  7268. },
  7269. // NOTE: this is an accumulator function that modifies the first argument (e.g. a). This is to minimize memory alocations.
  7270. getLerpFunc: function( exemplarValue, interTrack ) {
  7271. if( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
  7272. var typeName = typeof exemplarValue;
  7273. switch( typeName ) {
  7274. case "object": {
  7275. if( exemplarValue.lerp ) {
  7276. return THREE.AnimationUtils.lerp_object;
  7277. }
  7278. if( exemplarValue.slerp ) {
  7279. return THREE.AnimationUtils.slerp_object;
  7280. }
  7281. break;
  7282. }
  7283. case "number": {
  7284. return THREE.AnimationUtils.lerp_number;
  7285. }
  7286. case "boolean": {
  7287. if( interTrack ) {
  7288. return THREE.AnimationUtils.lerp_boolean;
  7289. }
  7290. else {
  7291. return THREE.AnimationUtils.lerp_boolean_immediate;
  7292. }
  7293. }
  7294. case "string": {
  7295. if( interTrack ) {
  7296. return THREE.AnimationUtils.lerp_string;
  7297. }
  7298. else {
  7299. return THREE.AnimationUtils.lerp_string_immediate;
  7300. }
  7301. }
  7302. };
  7303. }
  7304. };
  7305. // File:src/animation/KeyframeTrack.js
  7306. /**
  7307. *
  7308. * A Track that returns a keyframe interpolated value, currently linearly interpolated
  7309. *
  7310. * @author Ben Houston / http://clara.io/
  7311. * @author David Sarno / http://lighthaus.us/
  7312. */
  7313. THREE.KeyframeTrack = function ( name, keys ) {
  7314. if( name === undefined ) throw new Error( "track name is undefined" );
  7315. if( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
  7316. this.name = name;
  7317. this.keys = keys; // time in seconds, value as value
  7318. // the index of the last result, used as a starting point for local search.
  7319. this.lastIndex = 0;
  7320. this.validate();
  7321. this.optimize();
  7322. };
  7323. THREE.KeyframeTrack.prototype = {
  7324. constructor: THREE.KeyframeTrack,
  7325. getAt: function( time ) {
  7326. // this can not go higher than this.keys.length.
  7327. while( ( this.lastIndex < this.keys.length ) && ( time >= this.keys[this.lastIndex].time ) ) {
  7328. this.lastIndex ++;
  7329. };
  7330. // this can not go lower than 0.
  7331. while( ( this.lastIndex > 0 ) && ( time < this.keys[this.lastIndex - 1].time ) ) {
  7332. this.lastIndex --;
  7333. }
  7334. if( this.lastIndex >= this.keys.length ) {
  7335. this.setResult( this.keys[ this.keys.length - 1 ].value );
  7336. return this.result;
  7337. }
  7338. if( this.lastIndex === 0 ) {
  7339. this.setResult( this.keys[ 0 ].value );
  7340. return this.result;
  7341. }
  7342. var prevKey = this.keys[ this.lastIndex - 1 ];
  7343. this.setResult( prevKey.value );
  7344. // if true, means that prev/current keys are identical, thus no interpolation required.
  7345. if( prevKey.constantToNext ) {
  7346. return this.result;
  7347. }
  7348. // linear interpolation to start with
  7349. var currentKey = this.keys[ this.lastIndex ];
  7350. var alpha = ( time - prevKey.time ) / ( currentKey.time - prevKey.time );
  7351. this.result = this.lerpValues( this.result, currentKey.value, alpha );
  7352. return this.result;
  7353. },
  7354. // move all keyframes either forwards or backwards in time
  7355. shift: function( timeOffset ) {
  7356. if( timeOffset !== 0.0 ) {
  7357. for( var i = 0; i < this.keys.length; i ++ ) {
  7358. this.keys[i].time += timeOffset;
  7359. }
  7360. }
  7361. return this;
  7362. },
  7363. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  7364. scale: function( timeScale ) {
  7365. if( timeScale !== 1.0 ) {
  7366. for( var i = 0; i < this.keys.length; i ++ ) {
  7367. this.keys[i].time *= timeScale;
  7368. }
  7369. }
  7370. return this;
  7371. },
  7372. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  7373. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  7374. trim: function( startTime, endTime ) {
  7375. var firstKeysToRemove = 0;
  7376. for( var i = 1; i < this.keys.length; i ++ ) {
  7377. if( this.keys[i] <= startTime ) {
  7378. firstKeysToRemove ++;
  7379. }
  7380. }
  7381. var lastKeysToRemove = 0;
  7382. for( var i = this.keys.length - 2; i > 0; i ++ ) {
  7383. if( this.keys[i] >= endTime ) {
  7384. lastKeysToRemove ++;
  7385. }
  7386. else {
  7387. break;
  7388. }
  7389. }
  7390. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  7391. if( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
  7392. this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
  7393. }
  7394. return this;
  7395. },
  7396. /* NOTE: This is commented out because we really shouldn't have to handle unsorted key lists
  7397. Tracks with out of order keys should be considered to be invalid. - bhouston
  7398. sort: function() {
  7399. this.keys.sort( THREE.KeyframeTrack.keyComparer );
  7400. return this;
  7401. },*/
  7402. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  7403. // One could eventually ensure that all key.values in a track are all of the same type (otherwise interpolation makes no sense.)
  7404. validate: function() {
  7405. var prevKey = null;
  7406. if( this.keys.length === 0 ) {
  7407. console.error( " track is empty, no keys", this );
  7408. return;
  7409. }
  7410. for( var i = 0; i < this.keys.length; i ++ ) {
  7411. var currKey = this.keys[i];
  7412. if( ! currKey ) {
  7413. console.error( " key is null in track", this, i );
  7414. return;
  7415. }
  7416. if( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
  7417. console.error( " key.time is not a valid number", this, i, currKey );
  7418. return;
  7419. }
  7420. if( currKey.value === undefined || currKey.value === null) {
  7421. console.error( " key.value is null in track", this, i, currKey );
  7422. return;
  7423. }
  7424. if( prevKey && prevKey.time > currKey.time ) {
  7425. console.error( " key.time is less than previous key time, out of order keys", this, i, currKey, prevKey );
  7426. return;
  7427. }
  7428. prevKey = currKey;
  7429. }
  7430. return this;
  7431. },
  7432. // currently only removes equivalent sequential keys (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0), which are common in morph target animations
  7433. optimize: function() {
  7434. var newKeys = [];
  7435. var prevKey = this.keys[0];
  7436. newKeys.push( prevKey );
  7437. var equalsFunc = THREE.AnimationUtils.getEqualsFunc( prevKey.value );
  7438. for( var i = 1; i < this.keys.length - 1; i ++ ) {
  7439. var currKey = this.keys[i];
  7440. var nextKey = this.keys[i+1];
  7441. // if prevKey & currKey are the same time, remove currKey. If you want immediate adjacent keys, use an epsilon offset
  7442. // it is not possible to have two keys at the same time as we sort them. The sort is not stable on keys with the same time.
  7443. if( ( prevKey.time === currKey.time ) ) {
  7444. continue;
  7445. }
  7446. // remove completely unnecessary keyframes that are the same as their prev and next keys
  7447. if( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
  7448. continue;
  7449. }
  7450. // determine if interpolation is required
  7451. prevKey.constantToNext = this.compareValues( prevKey.value, currKey.value );
  7452. newKeys.push( currKey );
  7453. prevKey = currKey;
  7454. }
  7455. newKeys.push( this.keys[ this.keys.length - 1 ] );
  7456. this.keys = newKeys;
  7457. return this;
  7458. }
  7459. };
  7460. THREE.KeyframeTrack.keyComparer = function keyComparator(key0, key1) {
  7461. return key0.time - key1.time;
  7462. };
  7463. THREE.KeyframeTrack.parse = function( json ) {
  7464. if( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
  7465. var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
  7466. return trackType.parse( json );
  7467. };
  7468. THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
  7469. switch( typeName.toLowerCase() ) {
  7470. case "vector":
  7471. case "vector2":
  7472. case "vector3":
  7473. case "vector4":
  7474. return THREE.VectorKeyframeTrack;
  7475. case "quaternion":
  7476. return THREE.QuaternionKeyframeTrack;
  7477. case "integer":
  7478. case "scalar":
  7479. case "double":
  7480. case "float":
  7481. case "number":
  7482. return THREE.NumberKeyframeTrack;
  7483. case "bool":
  7484. case "boolean":
  7485. return THREE.BooleanKeyframeTrack;
  7486. case "string":
  7487. return THREE.StringKeyframeTrack;
  7488. };
  7489. throw new Error( "Unsupported typeName: " + typeName );
  7490. };
  7491. // File:src/animation/PropertyBinding.js
  7492. /**
  7493. *
  7494. * A track bound to a real value in the scene graph.
  7495. *
  7496. * @author Ben Houston / http://clara.io/
  7497. * @author David Sarno / http://lighthaus.us/
  7498. */
  7499. THREE.PropertyBinding = function ( rootNode, trackName ) {
  7500. this.rootNode = rootNode;
  7501. this.trackName = trackName;
  7502. this.referenceCount = 0;
  7503. this.originalValue = null; // the value of the property before it was controlled by this binding
  7504. var parseResults = THREE.PropertyBinding.parseTrackName( trackName );
  7505. this.directoryName = parseResults.directoryName;
  7506. this.nodeName = parseResults.nodeName;
  7507. this.objectName = parseResults.objectName;
  7508. this.objectIndex = parseResults.objectIndex;
  7509. this.propertyName = parseResults.propertyName;
  7510. this.propertyIndex = parseResults.propertyIndex;
  7511. this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ) || rootNode;
  7512. this.cumulativeValue = null;
  7513. this.cumulativeWeight = 0;
  7514. };
  7515. THREE.PropertyBinding.prototype = {
  7516. constructor: THREE.PropertyBinding,
  7517. reset: function() {
  7518. this.cumulativeValue = null;
  7519. this.cumulativeWeight = 0;
  7520. },
  7521. accumulate: function( value, weight ) {
  7522. if( ! this.isBound ) this.bind();
  7523. if( this.cumulativeWeight === 0 ) {
  7524. if( weight > 0 ) {
  7525. if( this.cumulativeValue === null ) {
  7526. this.cumulativeValue = THREE.AnimationUtils.clone( value );
  7527. }
  7528. this.cumulativeWeight = weight;
  7529. }
  7530. }
  7531. else {
  7532. var lerpAlpha = weight / ( this.cumulativeWeight + weight );
  7533. this.cumulativeValue = this.lerpValue( this.cumulativeValue, value, lerpAlpha );
  7534. this.cumulativeWeight += weight;
  7535. }
  7536. },
  7537. unbind: function() {
  7538. if( ! this.isBound ) return;
  7539. this.setValue( this.originalValue );
  7540. this.setValue = null;
  7541. this.getValue = null;
  7542. this.lerpValue = null;
  7543. this.equalsValue = null;
  7544. this.triggerDirty = null;
  7545. this.isBound = false;
  7546. },
  7547. // bind to the real property in the scene graph, remember original value, memorize various accessors for speed/inefficiency
  7548. bind: function() {
  7549. if( this.isBound ) return;
  7550. var targetObject = this.node;
  7551. // ensure there is a value node
  7552. if( ! targetObject ) {
  7553. console.error( " trying to update node for track: " + this.trackName + " but it wasn't found." );
  7554. return;
  7555. }
  7556. if( this.objectName ) {
  7557. // special case were we need to reach deeper into the hierarchy to get the face materials....
  7558. if( this.objectName === "materials" ) {
  7559. if( ! targetObject.material ) {
  7560. console.error( ' can not bind to material as node does not have a material', this );
  7561. return;
  7562. }
  7563. if( ! targetObject.material.materials ) {
  7564. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  7565. return;
  7566. }
  7567. targetObject = targetObject.material.materials;
  7568. }
  7569. else if( this.objectName === "bones" ) {
  7570. if( ! targetObject.skeleton ) {
  7571. console.error( ' can not bind to bones as node does not have a skeleton', this );
  7572. return;
  7573. }
  7574. // potential future optimization: skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7575. targetObject = targetObject.skeleton.bones;
  7576. // support resolving morphTarget names into indices.
  7577. for( var i = 0; i < targetObject.length; i ++ ) {
  7578. if( targetObject[i].name === this.objectIndex ) {
  7579. this.objectIndex = i;
  7580. break;
  7581. }
  7582. }
  7583. }
  7584. else {
  7585. if( targetObject[ this.objectName ] === undefined ) {
  7586. console.error( ' can not bind to objectName of node, undefined', this );
  7587. return;
  7588. }
  7589. targetObject = targetObject[ this.objectName ];
  7590. }
  7591. if( this.objectIndex !== undefined ) {
  7592. if( targetObject[ this.objectIndex ] === undefined ) {
  7593. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  7594. return;
  7595. }
  7596. targetObject = targetObject[ this.objectIndex ];
  7597. }
  7598. }
  7599. // special case mappings
  7600. var nodeProperty = targetObject[ this.propertyName ];
  7601. if( ! nodeProperty ) {
  7602. console.error( " trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );
  7603. return;
  7604. }
  7605. // access a sub element of the property array (only primitives are supported right now)
  7606. if( this.propertyIndex !== undefined ) {
  7607. if( this.propertyName === "morphTargetInfluences" ) {
  7608. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7609. // support resolving morphTarget names into indices.
  7610. if( ! targetObject.geometry ) {
  7611. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  7612. }
  7613. if( ! targetObject.geometry.morphTargets ) {
  7614. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  7615. }
  7616. for( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  7617. if( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
  7618. this.propertyIndex = i;
  7619. break;
  7620. }
  7621. }
  7622. }
  7623. this.setValue = function setValue_propertyIndexed( value ) {
  7624. if( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
  7625. nodeProperty[ this.propertyIndex ] = value;
  7626. return true;
  7627. }
  7628. return false;
  7629. };
  7630. this.getValue = function getValue_propertyIndexed() {
  7631. return nodeProperty[ this.propertyIndex ];
  7632. };
  7633. }
  7634. // must use copy for Object3D.Euler/Quaternion
  7635. else if( nodeProperty.copy ) {
  7636. this.setValue = function setValue_propertyObject( value ) {
  7637. if( ! this.equalsValue( nodeProperty, value ) ) {
  7638. nodeProperty.copy( value );
  7639. return true;
  7640. }
  7641. return false;
  7642. }
  7643. this.getValue = function getValue_propertyObject() {
  7644. return nodeProperty;
  7645. };
  7646. }
  7647. // otherwise just set the property directly on the node (do not use nodeProperty as it may not be a reference object)
  7648. else {
  7649. this.setValue = function setValue_property( value ) {
  7650. if( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
  7651. targetObject[ this.propertyName ] = value;
  7652. return true;
  7653. }
  7654. return false;
  7655. }
  7656. this.getValue = function getValue_property() {
  7657. return targetObject[ this.propertyName ];
  7658. };
  7659. }
  7660. // trigger node dirty
  7661. if( targetObject.needsUpdate !== undefined ) { // material
  7662. this.triggerDirty = function triggerDirty_needsUpdate() {
  7663. this.node.needsUpdate = true;
  7664. }
  7665. }
  7666. else if( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  7667. this.triggerDirty = function triggerDirty_matrixWorldNeedsUpdate() {
  7668. targetObject.matrixWorldNeedsUpdate = true;
  7669. }
  7670. }
  7671. this.originalValue = this.getValue();
  7672. this.equalsValue = THREE.AnimationUtils.getEqualsFunc( this.originalValue );
  7673. this.lerpValue = THREE.AnimationUtils.getLerpFunc( this.originalValue, true );
  7674. this.isBound = true;
  7675. },
  7676. apply: function() {
  7677. // for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
  7678. if( ! this.isBound ) this.bind();
  7679. // early exit if there is nothing to apply.
  7680. if( this.cumulativeWeight > 0 ) {
  7681. // blend with original value
  7682. if( this.cumulativeWeight < 1 ) {
  7683. var remainingWeight = 1 - this.cumulativeWeight;
  7684. var lerpAlpha = remainingWeight / ( this.cumulativeWeight + remainingWeight );
  7685. this.cumulativeValue = this.lerpValue( this.cumulativeValue, this.originalValue, lerpAlpha );
  7686. }
  7687. var valueChanged = this.setValue( this.cumulativeValue );
  7688. if( valueChanged && this.triggerDirty ) {
  7689. this.triggerDirty();
  7690. }
  7691. // reset accumulator
  7692. this.cumulativeValue = null;
  7693. this.cumulativeWeight = 0;
  7694. }
  7695. }
  7696. };
  7697. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  7698. // matches strings in the form of:
  7699. // nodeName.property
  7700. // nodeName.property[accessor]
  7701. // nodeName.material.property[accessor]
  7702. // uuid.property[accessor]
  7703. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  7704. // parentName/nodeName.property
  7705. // parentName/parentName/nodeName.property[index]
  7706. // .bone[Armature.DEF_cog].position
  7707. // created and tested via https://regex101.com/#javascript
  7708. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  7709. var matches = re.exec(trackName);
  7710. if( ! matches ) {
  7711. throw new Error( "cannot parse trackName at all: " + trackName );
  7712. }
  7713. if (matches.index === re.lastIndex) {
  7714. re.lastIndex++;
  7715. }
  7716. var results = {
  7717. directoryName: matches[1],
  7718. nodeName: matches[3], // allowed to be null, specified root node.
  7719. objectName: matches[5],
  7720. objectIndex: matches[7],
  7721. propertyName: matches[9],
  7722. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  7723. };
  7724. if( results.propertyName === null || results.propertyName.length === 0 ) {
  7725. throw new Error( "can not parse propertyName from trackName: " + trackName );
  7726. }
  7727. return results;
  7728. };
  7729. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  7730. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  7731. return root;
  7732. }
  7733. // search into skeleton bones.
  7734. if( root.skeleton ) {
  7735. var searchSkeleton = function( skeleton ) {
  7736. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  7737. var bone = skeleton.bones[i];
  7738. if( bone.name === nodeName ) {
  7739. return bone;
  7740. }
  7741. }
  7742. return null;
  7743. };
  7744. var bone = searchSkeleton( root.skeleton );
  7745. if( bone ) {
  7746. return bone;
  7747. }
  7748. }
  7749. // search into node subtree.
  7750. if( root.children ) {
  7751. var searchNodeSubtree = function( children ) {
  7752. for( var i = 0; i < children.length; i ++ ) {
  7753. var childNode = children[i];
  7754. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  7755. return childNode;
  7756. }
  7757. var result = searchNodeSubtree( childNode.children );
  7758. if( result ) return result;
  7759. }
  7760. return null;
  7761. };
  7762. var subTreeNode = searchNodeSubtree( root.children );
  7763. if( subTreeNode ) {
  7764. return subTreeNode;
  7765. }
  7766. }
  7767. return null;
  7768. }
  7769. // File:src/animation/tracks/VectorKeyframeTrack.js
  7770. /**
  7771. *
  7772. * A Track that interpolates Vectors
  7773. *
  7774. * @author Ben Houston / http://clara.io/
  7775. * @author David Sarno / http://lighthaus.us/
  7776. */
  7777. THREE.VectorKeyframeTrack = function ( name, keys ) {
  7778. THREE.KeyframeTrack.call( this, name, keys );
  7779. // local cache of value type to avoid allocations during runtime.
  7780. this.result = this.keys[0].value.clone();
  7781. };
  7782. THREE.VectorKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7783. THREE.VectorKeyframeTrack.prototype.constructor = THREE.VectorKeyframeTrack;
  7784. THREE.VectorKeyframeTrack.prototype.setResult = function( value ) {
  7785. this.result.copy( value );
  7786. };
  7787. // memoization of the lerp function for speed.
  7788. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7789. THREE.VectorKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7790. return value0.lerp( value1, alpha );
  7791. };
  7792. THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7793. return value0.equals( value1 );
  7794. };
  7795. THREE.VectorKeyframeTrack.prototype.clone = function() {
  7796. var clonedKeys = [];
  7797. for( var i = 0; i < this.keys.length; i ++ ) {
  7798. var key = this.keys[i];
  7799. clonedKeys.push( {
  7800. time: key.time,
  7801. value: key.value.clone()
  7802. } );
  7803. }
  7804. return new THREE.VectorKeyframeTrack( this.name, clonedKeys );
  7805. };
  7806. THREE.VectorKeyframeTrack.parse = function( json ) {
  7807. var elementCount = json.keys[0].value.length;
  7808. var valueType = THREE[ 'Vector' + elementCount ];
  7809. var keys = [];
  7810. for( var i = 0; i < json.keys.length; i ++ ) {
  7811. var jsonKey = json.keys[i];
  7812. keys.push( {
  7813. value: new valueType().fromArray( jsonKey.value ),
  7814. time: jsonKey.time
  7815. } );
  7816. }
  7817. return new THREE.VectorKeyframeTrack( json.name, keys );
  7818. };
  7819. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  7820. /**
  7821. *
  7822. * A Track that interpolates Quaternion
  7823. *
  7824. * @author Ben Houston / http://clara.io/
  7825. * @author David Sarno / http://lighthaus.us/
  7826. */
  7827. THREE.QuaternionKeyframeTrack = function ( name, keys ) {
  7828. THREE.KeyframeTrack.call( this, name, keys );
  7829. // local cache of value type to avoid allocations during runtime.
  7830. this.result = this.keys[0].value.clone();
  7831. };
  7832. THREE.QuaternionKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7833. THREE.QuaternionKeyframeTrack.prototype.constructor = THREE.QuaternionKeyframeTrack;
  7834. THREE.QuaternionKeyframeTrack.prototype.setResult = function( value ) {
  7835. this.result.copy( value );
  7836. };
  7837. // memoization of the lerp function for speed.
  7838. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7839. THREE.QuaternionKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7840. return value0.slerp( value1, alpha );
  7841. };
  7842. THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7843. return value0.equals( value1 );
  7844. };
  7845. THREE.QuaternionKeyframeTrack.prototype.multiply = function( quat ) {
  7846. for( var i = 0; i < this.keys.length; i ++ ) {
  7847. this.keys[i].value.multiply( quat );
  7848. }
  7849. return this;
  7850. };
  7851. THREE.QuaternionKeyframeTrack.prototype.clone = function() {
  7852. var clonedKeys = [];
  7853. for( var i = 0; i < this.keys.length; i ++ ) {
  7854. var key = this.keys[i];
  7855. clonedKeys.push( {
  7856. time: key.time,
  7857. value: key.value.clone()
  7858. } );
  7859. }
  7860. return new THREE.QuaternionKeyframeTrack( this.name, clonedKeys );
  7861. };
  7862. THREE.QuaternionKeyframeTrack.parse = function( json ) {
  7863. var keys = [];
  7864. for( var i = 0; i < json.keys.length; i ++ ) {
  7865. var jsonKey = json.keys[i];
  7866. keys.push( {
  7867. value: new THREE.Quaternion().fromArray( jsonKey.value ),
  7868. time: jsonKey.time
  7869. } );
  7870. }
  7871. return new THREE.QuaternionKeyframeTrack( json.name, keys );
  7872. };
  7873. // File:src/animation/tracks/StringKeyframeTrack.js
  7874. /**
  7875. *
  7876. * A Track that interpolates Strings
  7877. *
  7878. * @author Ben Houston / http://clara.io/
  7879. * @author David Sarno / http://lighthaus.us/
  7880. */
  7881. THREE.StringKeyframeTrack = function ( name, keys ) {
  7882. THREE.KeyframeTrack.call( this, name, keys );
  7883. // local cache of value type to avoid allocations during runtime.
  7884. this.result = this.keys[0].value;
  7885. };
  7886. THREE.StringKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7887. THREE.StringKeyframeTrack.prototype.constructor = THREE.StringKeyframeTrack;
  7888. THREE.StringKeyframeTrack.prototype.setResult = function( value ) {
  7889. this.result = value;
  7890. };
  7891. // memoization of the lerp function for speed.
  7892. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7893. THREE.StringKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7894. return ( alpha < 1.0 ) ? value0 : value1;
  7895. };
  7896. THREE.StringKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7897. return ( value0 === value1 );
  7898. };
  7899. THREE.StringKeyframeTrack.prototype.clone = function() {
  7900. var clonedKeys = [];
  7901. for( var i = 0; i < this.keys.length; i ++ ) {
  7902. var key = this.keys[i];
  7903. clonedKeys.push( {
  7904. time: key.time,
  7905. value: key.value
  7906. } );
  7907. }
  7908. return new THREE.StringKeyframeTrack( this.name, clonedKeys );
  7909. };
  7910. THREE.StringKeyframeTrack.parse = function( json ) {
  7911. return new THREE.StringKeyframeTrack( json.name, json.keys );
  7912. };
  7913. // File:src/animation/tracks/BooleanKeyframeTrack.js
  7914. /**
  7915. *
  7916. * A Track that interpolates Boolean
  7917. *
  7918. * @author Ben Houston / http://clara.io/
  7919. * @author David Sarno / http://lighthaus.us/
  7920. */
  7921. THREE.BooleanKeyframeTrack = function ( name, keys ) {
  7922. THREE.KeyframeTrack.call( this, name, keys );
  7923. // local cache of value type to avoid allocations during runtime.
  7924. this.result = this.keys[0].value;
  7925. };
  7926. THREE.BooleanKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7927. THREE.BooleanKeyframeTrack.prototype.constructor = THREE.BooleanKeyframeTrack;
  7928. THREE.BooleanKeyframeTrack.prototype.setResult = function( value ) {
  7929. this.result = value;
  7930. };
  7931. // memoization of the lerp function for speed.
  7932. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7933. THREE.BooleanKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7934. return ( alpha < 1.0 ) ? value0 : value1;
  7935. };
  7936. THREE.BooleanKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7937. return ( value0 === value1 );
  7938. };
  7939. THREE.BooleanKeyframeTrack.prototype.clone = function() {
  7940. var clonedKeys = [];
  7941. for( var i = 0; i < this.keys.length; i ++ ) {
  7942. var key = this.keys[i];
  7943. clonedKeys.push( {
  7944. time: key.time,
  7945. value: key.value
  7946. } );
  7947. }
  7948. return new THREE.BooleanKeyframeTrack( this.name, clonedKeys );
  7949. };
  7950. THREE.BooleanKeyframeTrack.parse = function( json ) {
  7951. return new THREE.BooleanKeyframeTrack( json.name, json.keys );
  7952. };
  7953. // File:src/animation/tracks/NumberKeyframeTrack.js
  7954. /**
  7955. *
  7956. * A Track that interpolates Numbers
  7957. *
  7958. * @author Ben Houston / http://clara.io/
  7959. * @author David Sarno / http://lighthaus.us/
  7960. */
  7961. THREE.NumberKeyframeTrack = function ( name, keys ) {
  7962. THREE.KeyframeTrack.call( this, name, keys );
  7963. // local cache of value type to avoid allocations during runtime.
  7964. this.result = this.keys[0].value;
  7965. };
  7966. THREE.NumberKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7967. THREE.NumberKeyframeTrack.prototype.constructor = THREE.NumberKeyframeTrack;
  7968. THREE.NumberKeyframeTrack.prototype.setResult = function( value ) {
  7969. this.result = value;
  7970. };
  7971. // memoization of the lerp function for speed.
  7972. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7973. THREE.NumberKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7974. return value0 * ( 1 - alpha ) + value1 * alpha;
  7975. };
  7976. THREE.NumberKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7977. return ( value0 === value1 );
  7978. };
  7979. THREE.NumberKeyframeTrack.prototype.clone = function() {
  7980. var clonedKeys = [];
  7981. for( var i = 0; i < this.keys.length; i ++ ) {
  7982. var key = this.keys[i];
  7983. clonedKeys.push( {
  7984. time: key.time,
  7985. value: key.value
  7986. } );
  7987. }
  7988. return new THREE.NumberKeyframeTrack( this.name, clonedKeys );
  7989. };
  7990. THREE.NumberKeyframeTrack.parse = function( json ) {
  7991. return new THREE.NumberKeyframeTrack( json.name, json.keys );
  7992. };
  7993. // File:src/cameras/Camera.js
  7994. /**
  7995. * @author mrdoob / http://mrdoob.com/
  7996. * @author mikael emtinger / http://gomo.se/
  7997. * @author WestLangley / http://github.com/WestLangley
  7998. */
  7999. THREE.Camera = function () {
  8000. THREE.Object3D.call( this );
  8001. this.type = 'Camera';
  8002. this.matrixWorldInverse = new THREE.Matrix4();
  8003. this.projectionMatrix = new THREE.Matrix4();
  8004. };
  8005. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  8006. THREE.Camera.prototype.constructor = THREE.Camera;
  8007. THREE.Camera.prototype.getWorldDirection = function () {
  8008. var quaternion = new THREE.Quaternion();
  8009. return function ( optionalTarget ) {
  8010. var result = optionalTarget || new THREE.Vector3();
  8011. this.getWorldQuaternion( quaternion );
  8012. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  8013. };
  8014. }();
  8015. THREE.Camera.prototype.lookAt = function () {
  8016. // This routine does not support cameras with rotated and/or translated parent(s)
  8017. var m1 = new THREE.Matrix4();
  8018. return function ( vector ) {
  8019. m1.lookAt( this.position, vector, this.up );
  8020. this.quaternion.setFromRotationMatrix( m1 );
  8021. };
  8022. }();
  8023. THREE.Camera.prototype.clone = function () {
  8024. return new this.constructor().copy( this );
  8025. };
  8026. THREE.Camera.prototype.copy = function ( source ) {
  8027. THREE.Object3D.prototype.copy.call( this, source );
  8028. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8029. this.projectionMatrix.copy( source.projectionMatrix );
  8030. return this;
  8031. };
  8032. // File:src/cameras/CubeCamera.js
  8033. /**
  8034. * Camera for rendering cube maps
  8035. * - renders scene into axis-aligned cube
  8036. *
  8037. * @author alteredq / http://alteredqualia.com/
  8038. */
  8039. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  8040. THREE.Object3D.call( this );
  8041. this.type = 'CubeCamera';
  8042. var fov = 90, aspect = 1;
  8043. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8044. cameraPX.up.set( 0, - 1, 0 );
  8045. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  8046. this.add( cameraPX );
  8047. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8048. cameraNX.up.set( 0, - 1, 0 );
  8049. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  8050. this.add( cameraNX );
  8051. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8052. cameraPY.up.set( 0, 0, 1 );
  8053. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  8054. this.add( cameraPY );
  8055. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8056. cameraNY.up.set( 0, 0, - 1 );
  8057. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  8058. this.add( cameraNY );
  8059. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8060. cameraPZ.up.set( 0, - 1, 0 );
  8061. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  8062. this.add( cameraPZ );
  8063. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8064. cameraNZ.up.set( 0, - 1, 0 );
  8065. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  8066. this.add( cameraNZ );
  8067. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  8068. this.updateCubeMap = function ( renderer, scene ) {
  8069. if ( this.parent === null ) this.updateMatrixWorld();
  8070. var renderTarget = this.renderTarget;
  8071. var generateMipmaps = renderTarget.generateMipmaps;
  8072. renderTarget.generateMipmaps = false;
  8073. renderTarget.activeCubeFace = 0;
  8074. renderer.render( scene, cameraPX, renderTarget );
  8075. renderTarget.activeCubeFace = 1;
  8076. renderer.render( scene, cameraNX, renderTarget );
  8077. renderTarget.activeCubeFace = 2;
  8078. renderer.render( scene, cameraPY, renderTarget );
  8079. renderTarget.activeCubeFace = 3;
  8080. renderer.render( scene, cameraNY, renderTarget );
  8081. renderTarget.activeCubeFace = 4;
  8082. renderer.render( scene, cameraPZ, renderTarget );
  8083. renderTarget.generateMipmaps = generateMipmaps;
  8084. renderTarget.activeCubeFace = 5;
  8085. renderer.render( scene, cameraNZ, renderTarget );
  8086. renderer.setRenderTarget( null );
  8087. };
  8088. };
  8089. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  8090. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  8091. // File:src/cameras/OrthographicCamera.js
  8092. /**
  8093. * @author alteredq / http://alteredqualia.com/
  8094. */
  8095. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  8096. THREE.Camera.call( this );
  8097. this.type = 'OrthographicCamera';
  8098. this.zoom = 1;
  8099. this.left = left;
  8100. this.right = right;
  8101. this.top = top;
  8102. this.bottom = bottom;
  8103. this.near = ( near !== undefined ) ? near : 0.1;
  8104. this.far = ( far !== undefined ) ? far : 2000;
  8105. this.updateProjectionMatrix();
  8106. };
  8107. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  8108. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  8109. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  8110. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  8111. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  8112. var cx = ( this.right + this.left ) / 2;
  8113. var cy = ( this.top + this.bottom ) / 2;
  8114. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  8115. };
  8116. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  8117. THREE.Camera.prototype.copy.call( this, source );
  8118. this.left = source.left;
  8119. this.right = source.right;
  8120. this.top = source.top;
  8121. this.bottom = source.bottom;
  8122. this.near = source.near;
  8123. this.far = source.far;
  8124. this.zoom = source.zoom;
  8125. return this;
  8126. };
  8127. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  8128. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8129. data.object.zoom = this.zoom;
  8130. data.object.left = this.left;
  8131. data.object.right = this.right;
  8132. data.object.top = this.top;
  8133. data.object.bottom = this.bottom;
  8134. data.object.near = this.near;
  8135. data.object.far = this.far;
  8136. return data;
  8137. };
  8138. // File:src/cameras/PerspectiveCamera.js
  8139. /**
  8140. * @author mrdoob / http://mrdoob.com/
  8141. * @author greggman / http://games.greggman.com/
  8142. * @author zz85 / http://www.lab4games.net/zz85/blog
  8143. */
  8144. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  8145. THREE.Camera.call( this );
  8146. this.type = 'PerspectiveCamera';
  8147. this.zoom = 1;
  8148. this.fov = fov !== undefined ? fov : 50;
  8149. this.aspect = aspect !== undefined ? aspect : 1;
  8150. this.near = near !== undefined ? near : 0.1;
  8151. this.far = far !== undefined ? far : 2000;
  8152. this.updateProjectionMatrix();
  8153. };
  8154. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  8155. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  8156. /**
  8157. * Uses Focal Length (in mm) to estimate and set FOV
  8158. * 35mm (full-frame) camera is used if frame size is not specified;
  8159. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  8160. */
  8161. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  8162. if ( frameHeight === undefined ) frameHeight = 24;
  8163. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  8164. this.updateProjectionMatrix();
  8165. };
  8166. /**
  8167. * Sets an offset in a larger frustum. This is useful for multi-window or
  8168. * multi-monitor/multi-machine setups.
  8169. *
  8170. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8171. * the monitors are in grid like this
  8172. *
  8173. * +---+---+---+
  8174. * | A | B | C |
  8175. * +---+---+---+
  8176. * | D | E | F |
  8177. * +---+---+---+
  8178. *
  8179. * then for each monitor you would call it like this
  8180. *
  8181. * var w = 1920;
  8182. * var h = 1080;
  8183. * var fullWidth = w * 3;
  8184. * var fullHeight = h * 2;
  8185. *
  8186. * --A--
  8187. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8188. * --B--
  8189. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8190. * --C--
  8191. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8192. * --D--
  8193. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8194. * --E--
  8195. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8196. * --F--
  8197. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8198. *
  8199. * Note there is no reason monitors have to be the same size or in a grid.
  8200. */
  8201. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  8202. this.fullWidth = fullWidth;
  8203. this.fullHeight = fullHeight;
  8204. this.x = x;
  8205. this.y = y;
  8206. this.width = width;
  8207. this.height = height;
  8208. this.updateProjectionMatrix();
  8209. };
  8210. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  8211. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  8212. if ( this.fullWidth ) {
  8213. var aspect = this.fullWidth / this.fullHeight;
  8214. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  8215. var bottom = - top;
  8216. var left = aspect * bottom;
  8217. var right = aspect * top;
  8218. var width = Math.abs( right - left );
  8219. var height = Math.abs( top - bottom );
  8220. this.projectionMatrix.makeFrustum(
  8221. left + this.x * width / this.fullWidth,
  8222. left + ( this.x + this.width ) * width / this.fullWidth,
  8223. top - ( this.y + this.height ) * height / this.fullHeight,
  8224. top - this.y * height / this.fullHeight,
  8225. this.near,
  8226. this.far
  8227. );
  8228. } else {
  8229. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  8230. }
  8231. };
  8232. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  8233. THREE.Camera.prototype.copy.call( this, source );
  8234. this.fov = source.fov;
  8235. this.aspect = source.aspect;
  8236. this.near = source.near;
  8237. this.far = source.far;
  8238. this.zoom = source.zoom;
  8239. return this;
  8240. };
  8241. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  8242. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8243. data.object.zoom = this.zoom;
  8244. data.object.fov = this.fov;
  8245. data.object.aspect = this.aspect;
  8246. data.object.near = this.near;
  8247. data.object.far = this.far;
  8248. return data;
  8249. };
  8250. // File:src/lights/Light.js
  8251. /**
  8252. * @author mrdoob / http://mrdoob.com/
  8253. * @author alteredq / http://alteredqualia.com/
  8254. */
  8255. THREE.Light = function ( color ) {
  8256. THREE.Object3D.call( this );
  8257. this.type = 'Light';
  8258. this.color = new THREE.Color( color );
  8259. };
  8260. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  8261. THREE.Light.prototype.constructor = THREE.Light;
  8262. THREE.Light.prototype.copy = function ( source ) {
  8263. THREE.Object3D.prototype.copy.call( this, source );
  8264. this.color.copy( source.color );
  8265. return this;
  8266. };
  8267. // File:src/lights/AmbientLight.js
  8268. /**
  8269. * @author mrdoob / http://mrdoob.com/
  8270. */
  8271. THREE.AmbientLight = function ( color ) {
  8272. THREE.Light.call( this, color );
  8273. this.type = 'AmbientLight';
  8274. };
  8275. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  8276. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  8277. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  8278. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8279. data.object.color = this.color.getHex();
  8280. return data;
  8281. };
  8282. // File:src/lights/DirectionalLight.js
  8283. /**
  8284. * @author mrdoob / http://mrdoob.com/
  8285. * @author alteredq / http://alteredqualia.com/
  8286. */
  8287. THREE.DirectionalLight = function ( color, intensity ) {
  8288. THREE.Light.call( this, color );
  8289. this.type = 'DirectionalLight';
  8290. this.position.set( 0, 1, 0 );
  8291. this.updateMatrix();
  8292. this.target = new THREE.Object3D();
  8293. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8294. this.castShadow = false;
  8295. this.onlyShadow = false;
  8296. this.shadowCameraNear = 50;
  8297. this.shadowCameraFar = 5000;
  8298. this.shadowCameraLeft = - 500;
  8299. this.shadowCameraRight = 500;
  8300. this.shadowCameraTop = 500;
  8301. this.shadowCameraBottom = - 500;
  8302. this.shadowCameraVisible = false;
  8303. this.shadowBias = 0;
  8304. this.shadowDarkness = 0.5;
  8305. this.shadowMapWidth = 512;
  8306. this.shadowMapHeight = 512;
  8307. this.shadowMap = null;
  8308. this.shadowMapSize = null;
  8309. this.shadowCamera = null;
  8310. this.shadowMatrix = null;
  8311. };
  8312. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  8313. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  8314. THREE.DirectionalLight.prototype.copy = function ( source ) {
  8315. THREE.Light.prototype.copy.call( this, source );
  8316. this.intensity = source.intensity;
  8317. this.target = source.target.clone();
  8318. this.castShadow = source.castShadow;
  8319. this.onlyShadow = source.onlyShadow;
  8320. this.shadowCameraNear = source.shadowCameraNear;
  8321. this.shadowCameraFar = source.shadowCameraFar;
  8322. this.shadowCameraLeft = source.shadowCameraLeft;
  8323. this.shadowCameraRight = source.shadowCameraRight;
  8324. this.shadowCameraTop = source.shadowCameraTop;
  8325. this.shadowCameraBottom = source.shadowCameraBottom;
  8326. this.shadowCameraVisible = source.shadowCameraVisible;
  8327. this.shadowBias = source.shadowBias;
  8328. this.shadowDarkness = source.shadowDarkness;
  8329. this.shadowMapWidth = source.shadowMapWidth;
  8330. this.shadowMapHeight = source.shadowMapHeight;
  8331. return this;
  8332. };
  8333. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  8334. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8335. data.object.color = this.color.getHex();
  8336. data.object.intensity = this.intensity;
  8337. return data;
  8338. };
  8339. // File:src/lights/HemisphereLight.js
  8340. /**
  8341. * @author alteredq / http://alteredqualia.com/
  8342. */
  8343. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  8344. THREE.Light.call( this, skyColor );
  8345. this.type = 'HemisphereLight';
  8346. this.position.set( 0, 1, 0 );
  8347. this.updateMatrix();
  8348. this.groundColor = new THREE.Color( groundColor );
  8349. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8350. };
  8351. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  8352. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  8353. THREE.HemisphereLight.prototype.copy = function ( source ) {
  8354. THREE.Light.prototype.copy.call( this, source );
  8355. this.groundColor.copy( source.groundColor );
  8356. this.intensity = source.intensity;
  8357. return this;
  8358. };
  8359. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  8360. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8361. data.object.color = this.color.getHex();
  8362. data.object.groundColor = this.groundColor.getHex();
  8363. data.object.intensity = this.intensity;
  8364. return data;
  8365. };
  8366. // File:src/lights/PointLight.js
  8367. /**
  8368. * @author mrdoob / http://mrdoob.com/
  8369. */
  8370. THREE.PointLight = function ( color, intensity, distance, decay ) {
  8371. THREE.Light.call( this, color );
  8372. this.type = 'PointLight';
  8373. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8374. this.distance = ( distance !== undefined ) ? distance : 0;
  8375. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8376. this.castShadow = false;
  8377. this.onlyShadow = false;
  8378. //
  8379. this.shadowCameraNear = 1;
  8380. this.shadowCameraFar = 500;
  8381. this.shadowCameraFov = 90;
  8382. this.shadowCameraVisible = false;
  8383. this.shadowBias = 0;
  8384. this.shadowDarkness = 0.5;
  8385. this.shadowMapWidth = 512;
  8386. this.shadowMapHeight = 512;
  8387. //
  8388. this.shadowMap = null;
  8389. this.shadowMapSize = null;
  8390. this.shadowCamera = null;
  8391. this.shadowMatrix = null;
  8392. };
  8393. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  8394. THREE.PointLight.prototype.constructor = THREE.PointLight;
  8395. THREE.PointLight.prototype.copy = function ( source ) {
  8396. THREE.Light.prototype.copy.call( this, source );
  8397. this.intensity = source.intensity;
  8398. this.distance = source.distance;
  8399. this.decay = source.decay;
  8400. this.castShadow = source.castShadow;
  8401. this.onlyShadow = source.onlyShadow;
  8402. this.shadowCameraNear = source.shadowCameraNear;
  8403. this.shadowCameraFar = source.shadowCameraFar;
  8404. this.shadowCameraFov = source.shadowCameraFov;
  8405. this.shadowCameraVisible = source.shadowCameraVisible;
  8406. this.shadowBias = source.shadowBias;
  8407. this.shadowDarkness = source.shadowDarkness;
  8408. this.shadowMapWidth = source.shadowMapWidth;
  8409. this.shadowMapHeight = source.shadowMapHeight;
  8410. return this;
  8411. };
  8412. THREE.PointLight.prototype.toJSON = function ( meta ) {
  8413. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8414. data.object.color = this.color.getHex();
  8415. data.object.intensity = this.intensity;
  8416. data.object.distance = this.distance;
  8417. data.object.decay = this.decay;
  8418. return data;
  8419. };
  8420. // File:src/lights/SpotLight.js
  8421. /**
  8422. * @author alteredq / http://alteredqualia.com/
  8423. */
  8424. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  8425. THREE.Light.call( this, color );
  8426. this.type = 'SpotLight';
  8427. this.position.set( 0, 1, 0 );
  8428. this.updateMatrix();
  8429. this.target = new THREE.Object3D();
  8430. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8431. this.distance = ( distance !== undefined ) ? distance : 0;
  8432. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  8433. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  8434. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8435. this.castShadow = false;
  8436. this.onlyShadow = false;
  8437. this.shadowCameraNear = 50;
  8438. this.shadowCameraFar = 5000;
  8439. this.shadowCameraFov = 50;
  8440. this.shadowCameraVisible = false;
  8441. this.shadowBias = 0;
  8442. this.shadowDarkness = 0.5;
  8443. this.shadowMapWidth = 512;
  8444. this.shadowMapHeight = 512;
  8445. this.shadowMap = null;
  8446. this.shadowMapSize = null;
  8447. this.shadowCamera = null;
  8448. this.shadowMatrix = null;
  8449. };
  8450. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  8451. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  8452. THREE.SpotLight.prototype.copy = function ( source ) {
  8453. THREE.Light.prototype.copy.call( this, source );
  8454. this.intensity = source.intensity;
  8455. this.distance = source.distance;
  8456. this.angle = source.angle;
  8457. this.exponent = source.exponent;
  8458. this.decay = source.decay;
  8459. this.target = source.target.clone();
  8460. this.castShadow = source.castShadow;
  8461. this.onlyShadow = source.onlyShadow;
  8462. this.shadowCameraNear = source.shadowCameraNear;
  8463. this.shadowCameraFar = source.shadowCameraFar;
  8464. this.shadowCameraFov = source.shadowCameraFov;
  8465. this.shadowCameraVisible = source.shadowCameraVisible;
  8466. this.shadowBias = source.shadowBias;
  8467. this.shadowDarkness = source.shadowDarkness;
  8468. this.shadowMapWidth = source.shadowMapWidth;
  8469. this.shadowMapHeight = source.shadowMapHeight;
  8470. return this;
  8471. }
  8472. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  8473. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8474. data.object.color = this.color.getHex();
  8475. data.object.intensity = this.intensity;
  8476. data.object.distance = this.distance;
  8477. data.object.angle = this.angle;
  8478. data.object.exponent = this.exponent;
  8479. data.object.decay = this.decay;
  8480. return data;
  8481. };
  8482. // File:src/loaders/Cache.js
  8483. /**
  8484. * @author mrdoob / http://mrdoob.com/
  8485. */
  8486. THREE.Cache = {
  8487. enabled: false,
  8488. files: {},
  8489. add: function ( key, file ) {
  8490. if ( this.enabled === false ) return;
  8491. // console.log( 'THREE.Cache', 'Adding key:', key );
  8492. this.files[ key ] = file;
  8493. },
  8494. get: function ( key ) {
  8495. if ( this.enabled === false ) return;
  8496. // console.log( 'THREE.Cache', 'Checking key:', key );
  8497. return this.files[ key ];
  8498. },
  8499. remove: function ( key ) {
  8500. delete this.files[ key ];
  8501. },
  8502. clear: function () {
  8503. this.files = {};
  8504. }
  8505. };
  8506. // File:src/loaders/Loader.js
  8507. /**
  8508. * @author alteredq / http://alteredqualia.com/
  8509. */
  8510. THREE.Loader = function () {
  8511. this.onLoadStart = function () {};
  8512. this.onLoadProgress = function () {};
  8513. this.onLoadComplete = function () {};
  8514. };
  8515. THREE.Loader.prototype = {
  8516. constructor: THREE.Loader,
  8517. crossOrigin: undefined,
  8518. extractUrlBase: function ( url ) {
  8519. var parts = url.split( '/' );
  8520. if ( parts.length === 1 ) return './';
  8521. parts.pop();
  8522. return parts.join( '/' ) + '/';
  8523. },
  8524. initMaterials: function ( materials, texturePath, crossOrigin ) {
  8525. var array = [];
  8526. for ( var i = 0; i < materials.length; ++ i ) {
  8527. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  8528. }
  8529. return array;
  8530. },
  8531. createMaterial: ( function () {
  8532. var imageLoader;
  8533. return function createMaterial( m, texturePath, crossOrigin ) {
  8534. var scope = this;
  8535. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  8536. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  8537. function nearest_pow2( n ) {
  8538. var l = Math.log( n ) / Math.LN2;
  8539. return Math.pow( 2, Math.round( l ) );
  8540. }
  8541. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  8542. var fullPath = texturePath + sourceFile;
  8543. var texture;
  8544. var loader = THREE.Loader.Handlers.get( fullPath );
  8545. if ( loader !== null ) {
  8546. texture = loader.load( fullPath );
  8547. } else {
  8548. texture = new THREE.Texture();
  8549. loader = imageLoader;
  8550. loader.setCrossOrigin( crossOrigin );
  8551. loader.load( fullPath, function ( image ) {
  8552. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  8553. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  8554. var width = nearest_pow2( image.width );
  8555. var height = nearest_pow2( image.height );
  8556. var canvas = document.createElement( 'canvas' );
  8557. canvas.width = width;
  8558. canvas.height = height;
  8559. var context = canvas.getContext( '2d' );
  8560. context.drawImage( image, 0, 0, width, height );
  8561. texture.image = canvas;
  8562. } else {
  8563. texture.image = image;
  8564. }
  8565. texture.needsUpdate = true;
  8566. } );
  8567. }
  8568. texture.sourceFile = sourceFile;
  8569. if ( repeat ) {
  8570. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  8571. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  8572. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  8573. }
  8574. if ( offset ) {
  8575. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  8576. }
  8577. if ( wrap ) {
  8578. var wrapMap = {
  8579. 'repeat': THREE.RepeatWrapping,
  8580. 'mirror': THREE.MirroredRepeatWrapping
  8581. };
  8582. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  8583. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  8584. }
  8585. if ( anisotropy ) {
  8586. texture.anisotropy = anisotropy;
  8587. }
  8588. where[ name ] = texture;
  8589. }
  8590. function rgb2hex( rgb ) {
  8591. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  8592. }
  8593. // defaults
  8594. var mtype = 'MeshLambertMaterial';
  8595. var mpars = {};
  8596. // parameters from model file
  8597. if ( m.shading ) {
  8598. var shading = m.shading.toLowerCase();
  8599. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  8600. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  8601. }
  8602. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  8603. mpars.blending = THREE[ m.blending ];
  8604. }
  8605. if ( m.transparent !== undefined ) {
  8606. mpars.transparent = m.transparent;
  8607. }
  8608. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  8609. mpars.transparent = true;
  8610. }
  8611. if ( m.depthTest !== undefined ) {
  8612. mpars.depthTest = m.depthTest;
  8613. }
  8614. if ( m.depthWrite !== undefined ) {
  8615. mpars.depthWrite = m.depthWrite;
  8616. }
  8617. if ( m.visible !== undefined ) {
  8618. mpars.visible = m.visible;
  8619. }
  8620. if ( m.flipSided !== undefined ) {
  8621. mpars.side = THREE.BackSide;
  8622. }
  8623. if ( m.doubleSided !== undefined ) {
  8624. mpars.side = THREE.DoubleSide;
  8625. }
  8626. if ( m.wireframe !== undefined ) {
  8627. mpars.wireframe = m.wireframe;
  8628. }
  8629. if ( m.vertexColors !== undefined ) {
  8630. if ( m.vertexColors === 'face' ) {
  8631. mpars.vertexColors = THREE.FaceColors;
  8632. } else if ( m.vertexColors ) {
  8633. mpars.vertexColors = THREE.VertexColors;
  8634. }
  8635. }
  8636. // colors
  8637. if ( m.colorDiffuse ) {
  8638. mpars.color = rgb2hex( m.colorDiffuse );
  8639. } else if ( m.DbgColor ) {
  8640. mpars.color = m.DbgColor;
  8641. }
  8642. if ( m.colorEmissive ) {
  8643. mpars.emissive = rgb2hex( m.colorEmissive );
  8644. }
  8645. if ( mtype === 'MeshPhongMaterial' ) {
  8646. if ( m.colorSpecular ) {
  8647. mpars.specular = rgb2hex( m.colorSpecular );
  8648. }
  8649. if ( m.specularCoef ) {
  8650. mpars.shininess = m.specularCoef;
  8651. }
  8652. }
  8653. // modifiers
  8654. if ( m.transparency !== undefined ) {
  8655. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  8656. m.opacity = m.transparency;
  8657. }
  8658. if ( m.opacity !== undefined ) {
  8659. mpars.opacity = m.opacity;
  8660. }
  8661. // textures
  8662. if ( texturePath ) {
  8663. if ( m.mapDiffuse ) {
  8664. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  8665. }
  8666. if ( m.mapLight ) {
  8667. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  8668. }
  8669. if ( m.mapAO ) {
  8670. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  8671. }
  8672. if ( m.mapBump ) {
  8673. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  8674. }
  8675. if ( m.mapNormal ) {
  8676. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  8677. }
  8678. if ( m.mapSpecular ) {
  8679. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  8680. }
  8681. if ( m.mapAlpha ) {
  8682. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  8683. }
  8684. }
  8685. //
  8686. if ( m.mapBumpScale ) {
  8687. mpars.bumpScale = m.mapBumpScale;
  8688. }
  8689. if ( m.mapNormalFactor ) {
  8690. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  8691. }
  8692. var material = new THREE[ mtype ]( mpars );
  8693. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  8694. return material;
  8695. };
  8696. } )()
  8697. };
  8698. THREE.Loader.Handlers = {
  8699. handlers: [],
  8700. add: function ( regex, loader ) {
  8701. this.handlers.push( regex, loader );
  8702. },
  8703. get: function ( file ) {
  8704. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  8705. var regex = this.handlers[ i ];
  8706. var loader = this.handlers[ i + 1 ];
  8707. if ( regex.test( file ) ) {
  8708. return loader;
  8709. }
  8710. }
  8711. return null;
  8712. }
  8713. };
  8714. // File:src/loaders/XHRLoader.js
  8715. /**
  8716. * @author mrdoob / http://mrdoob.com/
  8717. */
  8718. THREE.XHRLoader = function ( manager ) {
  8719. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8720. };
  8721. THREE.XHRLoader.prototype = {
  8722. constructor: THREE.XHRLoader,
  8723. load: function ( url, onLoad, onProgress, onError ) {
  8724. var scope = this;
  8725. var cached = THREE.Cache.get( url );
  8726. if ( cached !== undefined ) {
  8727. if ( onLoad ) {
  8728. setTimeout( function () {
  8729. onLoad( cached );
  8730. }, 0 );
  8731. }
  8732. return cached;
  8733. }
  8734. var request = new XMLHttpRequest();
  8735. request.open( 'GET', url, true );
  8736. request.addEventListener( 'load', function ( event ) {
  8737. THREE.Cache.add( url, this.response );
  8738. if ( onLoad ) onLoad( this.response );
  8739. scope.manager.itemEnd( url );
  8740. }, false );
  8741. if ( onProgress !== undefined ) {
  8742. request.addEventListener( 'progress', function ( event ) {
  8743. onProgress( event );
  8744. }, false );
  8745. }
  8746. request.addEventListener( 'error', function ( event ) {
  8747. if ( onError ) onError( event );
  8748. scope.manager.itemError( url );
  8749. }, false );
  8750. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  8751. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  8752. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  8753. request.send( null );
  8754. scope.manager.itemStart( url );
  8755. return request;
  8756. },
  8757. setResponseType: function ( value ) {
  8758. this.responseType = value;
  8759. },
  8760. setCrossOrigin: function ( value ) {
  8761. this.crossOrigin = value;
  8762. },
  8763. setWithCredentials: function ( value ) {
  8764. this.withCredentials = value;
  8765. }
  8766. };
  8767. // File:src/loaders/ImageLoader.js
  8768. /**
  8769. * @author mrdoob / http://mrdoob.com/
  8770. */
  8771. THREE.ImageLoader = function ( manager ) {
  8772. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8773. };
  8774. THREE.ImageLoader.prototype = {
  8775. constructor: THREE.ImageLoader,
  8776. load: function ( url, onLoad, onProgress, onError ) {
  8777. var scope = this;
  8778. var cached = THREE.Cache.get( url );
  8779. if ( cached !== undefined ) {
  8780. if ( onLoad ) {
  8781. setTimeout( function () {
  8782. onLoad( cached );
  8783. }, 0 );
  8784. }
  8785. return cached;
  8786. }
  8787. var image = document.createElement( 'img' );
  8788. image.addEventListener( 'load', function ( event ) {
  8789. THREE.Cache.add( url, this );
  8790. if ( onLoad ) onLoad( this );
  8791. scope.manager.itemEnd( url );
  8792. }, false );
  8793. if ( onProgress !== undefined ) {
  8794. image.addEventListener( 'progress', function ( event ) {
  8795. onProgress( event );
  8796. }, false );
  8797. }
  8798. image.addEventListener( 'error', function ( event ) {
  8799. if ( onError ) onError( event );
  8800. scope.manager.itemError( url );
  8801. }, false );
  8802. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  8803. scope.manager.itemStart( url );
  8804. image.src = url;
  8805. return image;
  8806. },
  8807. setCrossOrigin: function ( value ) {
  8808. this.crossOrigin = value;
  8809. }
  8810. };
  8811. // File:src/loaders/JSONLoader.js
  8812. /**
  8813. * @author mrdoob / http://mrdoob.com/
  8814. * @author alteredq / http://alteredqualia.com/
  8815. */
  8816. THREE.JSONLoader = function ( manager ) {
  8817. if ( typeof manager === 'boolean' ) {
  8818. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  8819. manager = undefined;
  8820. }
  8821. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8822. this.withCredentials = false;
  8823. };
  8824. THREE.JSONLoader.prototype = {
  8825. constructor: THREE.JSONLoader,
  8826. // Deprecated
  8827. get statusDomElement () {
  8828. if ( this._statusDomElement === undefined ) {
  8829. this._statusDomElement = document.createElement( 'div' );
  8830. }
  8831. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  8832. return this._statusDomElement;
  8833. },
  8834. load: function( url, onLoad, onProgress, onError ) {
  8835. var scope = this;
  8836. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  8837. var loader = new THREE.XHRLoader( this.manager );
  8838. loader.setCrossOrigin( this.crossOrigin );
  8839. loader.setWithCredentials( this.withCredentials );
  8840. loader.load( url, function ( text ) {
  8841. var json = JSON.parse( text );
  8842. var metadata = json.metadata;
  8843. if ( metadata !== undefined ) {
  8844. if ( metadata.type === 'object' ) {
  8845. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  8846. return;
  8847. }
  8848. if ( metadata.type === 'scene' ) {
  8849. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  8850. return;
  8851. }
  8852. }
  8853. var object = scope.parse( json, texturePath );
  8854. onLoad( object.geometry, object.materials );
  8855. } );
  8856. },
  8857. setCrossOrigin: function ( value ) {
  8858. this.crossOrigin = value;
  8859. },
  8860. setTexturePath: function ( value ) {
  8861. this.texturePath = value;
  8862. },
  8863. parse: function ( json, texturePath ) {
  8864. var geometry = new THREE.Geometry(),
  8865. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  8866. parseModel( scale );
  8867. parseSkin();
  8868. parseMorphing( scale );
  8869. parseAnimations();
  8870. geometry.computeFaceNormals();
  8871. geometry.computeBoundingSphere();
  8872. function parseModel( scale ) {
  8873. function isBitSet( value, position ) {
  8874. return value & ( 1 << position );
  8875. }
  8876. var i, j, fi,
  8877. offset, zLength,
  8878. colorIndex, normalIndex, uvIndex, materialIndex,
  8879. type,
  8880. isQuad,
  8881. hasMaterial,
  8882. hasFaceVertexUv,
  8883. hasFaceNormal, hasFaceVertexNormal,
  8884. hasFaceColor, hasFaceVertexColor,
  8885. vertex, face, faceA, faceB, hex, normal,
  8886. uvLayer, uv, u, v,
  8887. faces = json.faces,
  8888. vertices = json.vertices,
  8889. normals = json.normals,
  8890. colors = json.colors,
  8891. nUvLayers = 0;
  8892. if ( json.uvs !== undefined ) {
  8893. // disregard empty arrays
  8894. for ( i = 0; i < json.uvs.length; i ++ ) {
  8895. if ( json.uvs[ i ].length ) nUvLayers ++;
  8896. }
  8897. for ( i = 0; i < nUvLayers; i ++ ) {
  8898. geometry.faceVertexUvs[ i ] = [];
  8899. }
  8900. }
  8901. offset = 0;
  8902. zLength = vertices.length;
  8903. while ( offset < zLength ) {
  8904. vertex = new THREE.Vector3();
  8905. vertex.x = vertices[ offset ++ ] * scale;
  8906. vertex.y = vertices[ offset ++ ] * scale;
  8907. vertex.z = vertices[ offset ++ ] * scale;
  8908. geometry.vertices.push( vertex );
  8909. }
  8910. offset = 0;
  8911. zLength = faces.length;
  8912. while ( offset < zLength ) {
  8913. type = faces[ offset ++ ];
  8914. isQuad = isBitSet( type, 0 );
  8915. hasMaterial = isBitSet( type, 1 );
  8916. hasFaceVertexUv = isBitSet( type, 3 );
  8917. hasFaceNormal = isBitSet( type, 4 );
  8918. hasFaceVertexNormal = isBitSet( type, 5 );
  8919. hasFaceColor = isBitSet( type, 6 );
  8920. hasFaceVertexColor = isBitSet( type, 7 );
  8921. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  8922. if ( isQuad ) {
  8923. faceA = new THREE.Face3();
  8924. faceA.a = faces[ offset ];
  8925. faceA.b = faces[ offset + 1 ];
  8926. faceA.c = faces[ offset + 3 ];
  8927. faceB = new THREE.Face3();
  8928. faceB.a = faces[ offset + 1 ];
  8929. faceB.b = faces[ offset + 2 ];
  8930. faceB.c = faces[ offset + 3 ];
  8931. offset += 4;
  8932. if ( hasMaterial ) {
  8933. materialIndex = faces[ offset ++ ];
  8934. faceA.materialIndex = materialIndex;
  8935. faceB.materialIndex = materialIndex;
  8936. }
  8937. // to get face <=> uv index correspondence
  8938. fi = geometry.faces.length;
  8939. if ( hasFaceVertexUv ) {
  8940. for ( i = 0; i < nUvLayers; i ++ ) {
  8941. uvLayer = json.uvs[ i ];
  8942. geometry.faceVertexUvs[ i ][ fi ] = [];
  8943. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  8944. for ( j = 0; j < 4; j ++ ) {
  8945. uvIndex = faces[ offset ++ ];
  8946. u = uvLayer[ uvIndex * 2 ];
  8947. v = uvLayer[ uvIndex * 2 + 1 ];
  8948. uv = new THREE.Vector2( u, v );
  8949. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8950. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  8951. }
  8952. }
  8953. }
  8954. if ( hasFaceNormal ) {
  8955. normalIndex = faces[ offset ++ ] * 3;
  8956. faceA.normal.set(
  8957. normals[ normalIndex ++ ],
  8958. normals[ normalIndex ++ ],
  8959. normals[ normalIndex ]
  8960. );
  8961. faceB.normal.copy( faceA.normal );
  8962. }
  8963. if ( hasFaceVertexNormal ) {
  8964. for ( i = 0; i < 4; i ++ ) {
  8965. normalIndex = faces[ offset ++ ] * 3;
  8966. normal = new THREE.Vector3(
  8967. normals[ normalIndex ++ ],
  8968. normals[ normalIndex ++ ],
  8969. normals[ normalIndex ]
  8970. );
  8971. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  8972. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  8973. }
  8974. }
  8975. if ( hasFaceColor ) {
  8976. colorIndex = faces[ offset ++ ];
  8977. hex = colors[ colorIndex ];
  8978. faceA.color.setHex( hex );
  8979. faceB.color.setHex( hex );
  8980. }
  8981. if ( hasFaceVertexColor ) {
  8982. for ( i = 0; i < 4; i ++ ) {
  8983. colorIndex = faces[ offset ++ ];
  8984. hex = colors[ colorIndex ];
  8985. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  8986. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  8987. }
  8988. }
  8989. geometry.faces.push( faceA );
  8990. geometry.faces.push( faceB );
  8991. } else {
  8992. face = new THREE.Face3();
  8993. face.a = faces[ offset ++ ];
  8994. face.b = faces[ offset ++ ];
  8995. face.c = faces[ offset ++ ];
  8996. if ( hasMaterial ) {
  8997. materialIndex = faces[ offset ++ ];
  8998. face.materialIndex = materialIndex;
  8999. }
  9000. // to get face <=> uv index correspondence
  9001. fi = geometry.faces.length;
  9002. if ( hasFaceVertexUv ) {
  9003. for ( i = 0; i < nUvLayers; i ++ ) {
  9004. uvLayer = json.uvs[ i ];
  9005. geometry.faceVertexUvs[ i ][ fi ] = [];
  9006. for ( j = 0; j < 3; j ++ ) {
  9007. uvIndex = faces[ offset ++ ];
  9008. u = uvLayer[ uvIndex * 2 ];
  9009. v = uvLayer[ uvIndex * 2 + 1 ];
  9010. uv = new THREE.Vector2( u, v );
  9011. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  9012. }
  9013. }
  9014. }
  9015. if ( hasFaceNormal ) {
  9016. normalIndex = faces[ offset ++ ] * 3;
  9017. face.normal.set(
  9018. normals[ normalIndex ++ ],
  9019. normals[ normalIndex ++ ],
  9020. normals[ normalIndex ]
  9021. );
  9022. }
  9023. if ( hasFaceVertexNormal ) {
  9024. for ( i = 0; i < 3; i ++ ) {
  9025. normalIndex = faces[ offset ++ ] * 3;
  9026. normal = new THREE.Vector3(
  9027. normals[ normalIndex ++ ],
  9028. normals[ normalIndex ++ ],
  9029. normals[ normalIndex ]
  9030. );
  9031. face.vertexNormals.push( normal );
  9032. }
  9033. }
  9034. if ( hasFaceColor ) {
  9035. colorIndex = faces[ offset ++ ];
  9036. face.color.setHex( colors[ colorIndex ] );
  9037. }
  9038. if ( hasFaceVertexColor ) {
  9039. for ( i = 0; i < 3; i ++ ) {
  9040. colorIndex = faces[ offset ++ ];
  9041. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  9042. }
  9043. }
  9044. geometry.faces.push( face );
  9045. }
  9046. }
  9047. };
  9048. function parseSkin() {
  9049. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  9050. if ( json.skinWeights ) {
  9051. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  9052. var x = json.skinWeights[ i ];
  9053. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  9054. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  9055. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  9056. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  9057. }
  9058. }
  9059. if ( json.skinIndices ) {
  9060. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  9061. var a = json.skinIndices[ i ];
  9062. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  9063. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  9064. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  9065. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  9066. }
  9067. }
  9068. geometry.bones = json.bones;
  9069. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  9070. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  9071. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  9072. }
  9073. };
  9074. function parseMorphing( scale ) {
  9075. if ( json.morphTargets !== undefined ) {
  9076. var i, l, v, vl, dstVertices, srcVertices;
  9077. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  9078. geometry.morphTargets[ i ] = {};
  9079. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  9080. geometry.morphTargets[ i ].vertices = [];
  9081. dstVertices = geometry.morphTargets[ i ].vertices;
  9082. srcVertices = json.morphTargets[ i ].vertices;
  9083. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  9084. var vertex = new THREE.Vector3();
  9085. vertex.x = srcVertices[ v ] * scale;
  9086. vertex.y = srcVertices[ v + 1 ] * scale;
  9087. vertex.z = srcVertices[ v + 2 ] * scale;
  9088. dstVertices.push( vertex );
  9089. }
  9090. }
  9091. }
  9092. if ( json.morphColors !== undefined ) {
  9093. var i, l, c, cl, dstColors, srcColors, color;
  9094. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  9095. geometry.morphColors[ i ] = {};
  9096. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  9097. geometry.morphColors[ i ].colors = [];
  9098. dstColors = geometry.morphColors[ i ].colors;
  9099. srcColors = json.morphColors[ i ].colors;
  9100. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  9101. color = new THREE.Color( 0xffaa00 );
  9102. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  9103. dstColors.push( color );
  9104. }
  9105. }
  9106. }
  9107. }
  9108. function parseAnimations() {
  9109. var outputAnimations = [];
  9110. // parse old style Bone/Hierarchy animations
  9111. var animations = [];
  9112. if( json.animation !== undefined ) {
  9113. animations.push( json.animation );
  9114. }
  9115. if( json.animations !== undefined ) {
  9116. if( json.animations.length ) {
  9117. animations = animations.concat( json.animations );
  9118. }
  9119. else {
  9120. animations.push( json.animations );
  9121. }
  9122. }
  9123. for( var i = 0; i < animations.length; i ++ ) {
  9124. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  9125. if( clip ) outputAnimations.push( clip );
  9126. }
  9127. // parse implicit morph animations
  9128. if( geometry.morphTargets ) {
  9129. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  9130. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  9131. outputAnimations = outputAnimations.concat( morphAnimationClips );
  9132. }
  9133. if( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  9134. };
  9135. if ( json.materials === undefined || json.materials.length === 0 ) {
  9136. return { geometry: geometry };
  9137. } else {
  9138. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  9139. return { geometry: geometry, materials: materials };
  9140. }
  9141. }
  9142. };
  9143. // File:src/loaders/LoadingManager.js
  9144. /**
  9145. * @author mrdoob / http://mrdoob.com/
  9146. */
  9147. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  9148. var scope = this;
  9149. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  9150. this.onStart = undefined;
  9151. this.onLoad = onLoad;
  9152. this.onProgress = onProgress;
  9153. this.onError = onError;
  9154. this.itemStart = function ( url ) {
  9155. itemsTotal ++;
  9156. if ( isLoading === false ) {
  9157. if ( scope.onStart !== undefined ) {
  9158. scope.onStart( url, itemsLoaded, itemsTotal );
  9159. }
  9160. }
  9161. isLoading = true;
  9162. };
  9163. this.itemEnd = function ( url ) {
  9164. itemsLoaded ++;
  9165. if ( scope.onProgress !== undefined ) {
  9166. scope.onProgress( url, itemsLoaded, itemsTotal );
  9167. }
  9168. if ( itemsLoaded === itemsTotal ) {
  9169. isLoading = false;
  9170. if ( scope.onLoad !== undefined ) {
  9171. scope.onLoad();
  9172. }
  9173. }
  9174. };
  9175. this.itemError = function ( url ) {
  9176. if ( scope.onError !== undefined ) {
  9177. scope.onError( url );
  9178. }
  9179. };
  9180. };
  9181. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  9182. // File:src/loaders/BufferGeometryLoader.js
  9183. /**
  9184. * @author mrdoob / http://mrdoob.com/
  9185. */
  9186. THREE.BufferGeometryLoader = function ( manager ) {
  9187. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9188. };
  9189. THREE.BufferGeometryLoader.prototype = {
  9190. constructor: THREE.BufferGeometryLoader,
  9191. load: function ( url, onLoad, onProgress, onError ) {
  9192. var scope = this;
  9193. var loader = new THREE.XHRLoader( scope.manager );
  9194. loader.setCrossOrigin( this.crossOrigin );
  9195. loader.load( url, function ( text ) {
  9196. onLoad( scope.parse( JSON.parse( text ) ) );
  9197. }, onProgress, onError );
  9198. },
  9199. setCrossOrigin: function ( value ) {
  9200. this.crossOrigin = value;
  9201. },
  9202. parse: function ( json ) {
  9203. var geometry = new THREE.BufferGeometry();
  9204. var index = json.data.index;
  9205. if ( index !== undefined ) {
  9206. var typedArray = new self[ index.type ]( index.array );
  9207. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  9208. }
  9209. var attributes = json.data.attributes;
  9210. for ( var key in attributes ) {
  9211. var attribute = attributes[ key ];
  9212. var typedArray = new self[ attribute.type ]( attribute.array );
  9213. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  9214. }
  9215. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  9216. if ( groups !== undefined ) {
  9217. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  9218. var group = groups[ i ];
  9219. geometry.addGroup( group.start, group.count );
  9220. }
  9221. }
  9222. var boundingSphere = json.data.boundingSphere;
  9223. if ( boundingSphere !== undefined ) {
  9224. var center = new THREE.Vector3();
  9225. if ( boundingSphere.center !== undefined ) {
  9226. center.fromArray( boundingSphere.center );
  9227. }
  9228. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  9229. }
  9230. return geometry;
  9231. }
  9232. };
  9233. // File:src/loaders/MaterialLoader.js
  9234. /**
  9235. * @author mrdoob / http://mrdoob.com/
  9236. */
  9237. THREE.MaterialLoader = function ( manager ) {
  9238. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9239. this.textures = {};
  9240. };
  9241. THREE.MaterialLoader.prototype = {
  9242. constructor: THREE.MaterialLoader,
  9243. load: function ( url, onLoad, onProgress, onError ) {
  9244. var scope = this;
  9245. var loader = new THREE.XHRLoader( scope.manager );
  9246. loader.setCrossOrigin( this.crossOrigin );
  9247. loader.load( url, function ( text ) {
  9248. onLoad( scope.parse( JSON.parse( text ) ) );
  9249. }, onProgress, onError );
  9250. },
  9251. setCrossOrigin: function ( value ) {
  9252. this.crossOrigin = value;
  9253. },
  9254. setTextures: function ( value ) {
  9255. this.textures = value;
  9256. },
  9257. getTexture: function ( name ) {
  9258. var textures = this.textures;
  9259. if ( textures[ name ] === undefined ) {
  9260. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  9261. }
  9262. return textures[ name ];
  9263. },
  9264. parse: function ( json ) {
  9265. var material = new THREE[ json.type ];
  9266. material.uuid = json.uuid;
  9267. if ( json.name !== undefined ) material.name = json.name;
  9268. if ( json.color !== undefined ) material.color.setHex( json.color );
  9269. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  9270. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  9271. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  9272. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  9273. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  9274. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  9275. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  9276. if ( json.shading !== undefined ) material.shading = json.shading;
  9277. if ( json.blending !== undefined ) material.blending = json.blending;
  9278. if ( json.side !== undefined ) material.side = json.side;
  9279. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  9280. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  9281. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  9282. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  9283. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  9284. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  9285. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  9286. // for PointsMaterial
  9287. if ( json.size !== undefined ) material.size = json.size;
  9288. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  9289. // maps
  9290. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  9291. if ( json.alphaMap !== undefined ) {
  9292. material.alphaMap = this.getTexture( json.alphaMap );
  9293. material.transparent = true;
  9294. }
  9295. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  9296. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  9297. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  9298. if ( json.normalScale ) material.normalScale = new THREE.Vector2( json.normalScale, json.normalScale );
  9299. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  9300. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  9301. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  9302. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  9303. if ( json.envMap !== undefined ) {
  9304. material.envMap = this.getTexture( json.envMap );
  9305. material.combine = THREE.MultiplyOperation;
  9306. }
  9307. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  9308. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  9309. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  9310. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  9311. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  9312. // MeshFaceMaterial
  9313. if ( json.materials !== undefined ) {
  9314. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  9315. material.materials.push( this.parse( json.materials[ i ] ) );
  9316. }
  9317. }
  9318. return material;
  9319. }
  9320. };
  9321. // File:src/loaders/ObjectLoader.js
  9322. /**
  9323. * @author mrdoob / http://mrdoob.com/
  9324. */
  9325. THREE.ObjectLoader = function ( manager ) {
  9326. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9327. this.texturePath = '';
  9328. };
  9329. THREE.ObjectLoader.prototype = {
  9330. constructor: THREE.ObjectLoader,
  9331. load: function ( url, onLoad, onProgress, onError ) {
  9332. if ( this.texturePath === '' ) {
  9333. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  9334. }
  9335. var scope = this;
  9336. var loader = new THREE.XHRLoader( scope.manager );
  9337. loader.setCrossOrigin( this.crossOrigin );
  9338. loader.load( url, function ( text ) {
  9339. scope.parse( JSON.parse( text ), onLoad );
  9340. }, onProgress, onError );
  9341. },
  9342. setTexturePath: function ( value ) {
  9343. this.texturePath = value;
  9344. },
  9345. setCrossOrigin: function ( value ) {
  9346. this.crossOrigin = value;
  9347. },
  9348. parse: function ( json, onLoad ) {
  9349. var geometries = this.parseGeometries( json.geometries );
  9350. var images = this.parseImages( json.images, function () {
  9351. if ( onLoad !== undefined ) onLoad( object );
  9352. } );
  9353. var textures = this.parseTextures( json.textures, images );
  9354. var materials = this.parseMaterials( json.materials, textures );
  9355. var object = this.parseObject( json.object, geometries, materials );
  9356. if( json.animations ) {
  9357. object.animations = this.parseAnimations( json.animations );
  9358. }
  9359. if ( json.images === undefined || json.images.length === 0 ) {
  9360. if ( onLoad !== undefined ) onLoad( object );
  9361. }
  9362. return object;
  9363. },
  9364. parseGeometries: function ( json ) {
  9365. var geometries = {};
  9366. if ( json !== undefined ) {
  9367. var geometryLoader = new THREE.JSONLoader();
  9368. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  9369. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9370. var geometry;
  9371. var data = json[ i ];
  9372. switch ( data.type ) {
  9373. case 'PlaneGeometry':
  9374. case 'PlaneBufferGeometry':
  9375. geometry = new THREE[ data.type ](
  9376. data.width,
  9377. data.height,
  9378. data.widthSegments,
  9379. data.heightSegments
  9380. );
  9381. break;
  9382. case 'BoxGeometry':
  9383. case 'CubeGeometry': // backwards compatible
  9384. geometry = new THREE.BoxGeometry(
  9385. data.width,
  9386. data.height,
  9387. data.depth,
  9388. data.widthSegments,
  9389. data.heightSegments,
  9390. data.depthSegments
  9391. );
  9392. break;
  9393. case 'CircleBufferGeometry':
  9394. geometry = new THREE.CircleBufferGeometry(
  9395. data.radius,
  9396. data.segments,
  9397. data.thetaStart,
  9398. data.thetaLength
  9399. );
  9400. break;
  9401. case 'CircleGeometry':
  9402. geometry = new THREE.CircleGeometry(
  9403. data.radius,
  9404. data.segments,
  9405. data.thetaStart,
  9406. data.thetaLength
  9407. );
  9408. break;
  9409. case 'CylinderGeometry':
  9410. geometry = new THREE.CylinderGeometry(
  9411. data.radiusTop,
  9412. data.radiusBottom,
  9413. data.height,
  9414. data.radialSegments,
  9415. data.heightSegments,
  9416. data.openEnded,
  9417. data.thetaStart,
  9418. data.thetaLength
  9419. );
  9420. break;
  9421. case 'SphereGeometry':
  9422. geometry = new THREE.SphereGeometry(
  9423. data.radius,
  9424. data.widthSegments,
  9425. data.heightSegments,
  9426. data.phiStart,
  9427. data.phiLength,
  9428. data.thetaStart,
  9429. data.thetaLength
  9430. );
  9431. break;
  9432. case 'SphereBufferGeometry':
  9433. geometry = new THREE.SphereBufferGeometry(
  9434. data.radius,
  9435. data.widthSegments,
  9436. data.heightSegments,
  9437. data.phiStart,
  9438. data.phiLength,
  9439. data.thetaStart,
  9440. data.thetaLength
  9441. );
  9442. break;
  9443. case 'DodecahedronGeometry':
  9444. geometry = new THREE.DodecahedronGeometry(
  9445. data.radius,
  9446. data.detail
  9447. );
  9448. break;
  9449. case 'IcosahedronGeometry':
  9450. geometry = new THREE.IcosahedronGeometry(
  9451. data.radius,
  9452. data.detail
  9453. );
  9454. break;
  9455. case 'OctahedronGeometry':
  9456. geometry = new THREE.OctahedronGeometry(
  9457. data.radius,
  9458. data.detail
  9459. );
  9460. break;
  9461. case 'TetrahedronGeometry':
  9462. geometry = new THREE.TetrahedronGeometry(
  9463. data.radius,
  9464. data.detail
  9465. );
  9466. break;
  9467. case 'RingGeometry':
  9468. geometry = new THREE.RingGeometry(
  9469. data.innerRadius,
  9470. data.outerRadius,
  9471. data.thetaSegments,
  9472. data.phiSegments,
  9473. data.thetaStart,
  9474. data.thetaLength
  9475. );
  9476. break;
  9477. case 'TorusGeometry':
  9478. geometry = new THREE.TorusGeometry(
  9479. data.radius,
  9480. data.tube,
  9481. data.radialSegments,
  9482. data.tubularSegments,
  9483. data.arc
  9484. );
  9485. break;
  9486. case 'TorusKnotGeometry':
  9487. geometry = new THREE.TorusKnotGeometry(
  9488. data.radius,
  9489. data.tube,
  9490. data.radialSegments,
  9491. data.tubularSegments,
  9492. data.p,
  9493. data.q,
  9494. data.heightScale
  9495. );
  9496. break;
  9497. case 'TextGeometry':
  9498. geometry = new THREE.TextGeometry(
  9499. data.text,
  9500. data.data
  9501. );
  9502. break;
  9503. case 'BufferGeometry':
  9504. geometry = bufferGeometryLoader.parse( data );
  9505. break;
  9506. case 'Geometry':
  9507. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  9508. break;
  9509. default:
  9510. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  9511. continue;
  9512. }
  9513. geometry.uuid = data.uuid;
  9514. if ( data.name !== undefined ) geometry.name = data.name;
  9515. geometries[ data.uuid ] = geometry;
  9516. }
  9517. }
  9518. return geometries;
  9519. },
  9520. parseMaterials: function ( json, textures ) {
  9521. var materials = {};
  9522. if ( json !== undefined ) {
  9523. var loader = new THREE.MaterialLoader();
  9524. loader.setTextures( textures );
  9525. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9526. var material = loader.parse( json[ i ] );
  9527. materials[ material.uuid ] = material;
  9528. }
  9529. }
  9530. return materials;
  9531. },
  9532. parseAnimations: function ( json ) {
  9533. var animations = [];
  9534. for( var i = 0; i < json.length; i ++ ) {
  9535. var clip = THREE.AnimationClip.parse( json[i] );
  9536. animations.push( clip );
  9537. }
  9538. return animations;
  9539. },
  9540. parseImages: function ( json, onLoad ) {
  9541. var scope = this;
  9542. var images = {};
  9543. function loadImage( url ) {
  9544. scope.manager.itemStart( url );
  9545. return loader.load( url, function () {
  9546. scope.manager.itemEnd( url );
  9547. } );
  9548. }
  9549. if ( json !== undefined && json.length > 0 ) {
  9550. var manager = new THREE.LoadingManager( onLoad );
  9551. var loader = new THREE.ImageLoader( manager );
  9552. loader.setCrossOrigin( this.crossOrigin );
  9553. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9554. var image = json[ i ];
  9555. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  9556. images[ image.uuid ] = loadImage( path );
  9557. }
  9558. }
  9559. return images;
  9560. },
  9561. parseTextures: function ( json, images ) {
  9562. function parseConstant( value ) {
  9563. if ( typeof( value ) === 'number' ) return value;
  9564. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  9565. return THREE[ value ];
  9566. }
  9567. var textures = {};
  9568. if ( json !== undefined ) {
  9569. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9570. var data = json[ i ];
  9571. if ( data.image === undefined ) {
  9572. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  9573. }
  9574. if ( images[ data.image ] === undefined ) {
  9575. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  9576. }
  9577. var texture = new THREE.Texture( images[ data.image ] );
  9578. texture.needsUpdate = true;
  9579. texture.uuid = data.uuid;
  9580. if ( data.name !== undefined ) texture.name = data.name;
  9581. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  9582. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  9583. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  9584. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  9585. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  9586. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  9587. if ( Array.isArray( data.wrap ) ) {
  9588. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  9589. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  9590. }
  9591. textures[ data.uuid ] = texture;
  9592. }
  9593. }
  9594. return textures;
  9595. },
  9596. parseObject: function () {
  9597. var matrix = new THREE.Matrix4();
  9598. return function ( data, geometries, materials ) {
  9599. var object;
  9600. var getGeometry = function ( name ) {
  9601. if ( geometries[ name ] === undefined ) {
  9602. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  9603. }
  9604. return geometries[ name ];
  9605. };
  9606. var getMaterial = function ( name ) {
  9607. if ( materials[ name ] === undefined ) {
  9608. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  9609. }
  9610. return materials[ name ];
  9611. };
  9612. switch ( data.type ) {
  9613. case 'Scene':
  9614. object = new THREE.Scene();
  9615. break;
  9616. case 'PerspectiveCamera':
  9617. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  9618. break;
  9619. case 'OrthographicCamera':
  9620. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  9621. break;
  9622. case 'AmbientLight':
  9623. object = new THREE.AmbientLight( data.color );
  9624. break;
  9625. case 'DirectionalLight':
  9626. object = new THREE.DirectionalLight( data.color, data.intensity );
  9627. break;
  9628. case 'PointLight':
  9629. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  9630. break;
  9631. case 'SpotLight':
  9632. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  9633. break;
  9634. case 'HemisphereLight':
  9635. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  9636. break;
  9637. case 'Mesh':
  9638. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  9639. break;
  9640. case 'LOD':
  9641. object = new THREE.LOD();
  9642. break;
  9643. case 'Line':
  9644. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  9645. break;
  9646. case 'PointCloud':
  9647. case 'Points':
  9648. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  9649. break;
  9650. case 'Sprite':
  9651. object = new THREE.Sprite( getMaterial( data.material ) );
  9652. break;
  9653. case 'Group':
  9654. object = new THREE.Group();
  9655. break;
  9656. default:
  9657. object = new THREE.Object3D();
  9658. }
  9659. object.uuid = data.uuid;
  9660. if ( data.name !== undefined ) object.name = data.name;
  9661. if ( data.matrix !== undefined ) {
  9662. matrix.fromArray( data.matrix );
  9663. matrix.decompose( object.position, object.quaternion, object.scale );
  9664. } else {
  9665. if ( data.position !== undefined ) object.position.fromArray( data.position );
  9666. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  9667. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  9668. }
  9669. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  9670. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  9671. if ( data.visible !== undefined ) object.visible = data.visible;
  9672. if ( data.userData !== undefined ) object.userData = data.userData;
  9673. if ( data.children !== undefined ) {
  9674. for ( var child in data.children ) {
  9675. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  9676. }
  9677. }
  9678. if ( data.type === 'LOD' ) {
  9679. var levels = data.levels;
  9680. for ( var l = 0; l < levels.length; l ++ ) {
  9681. var level = levels[ l ];
  9682. var child = object.getObjectByProperty( 'uuid', level.object );
  9683. if ( child !== undefined ) {
  9684. object.addLevel( child, level.distance );
  9685. }
  9686. }
  9687. }
  9688. return object;
  9689. }
  9690. }()
  9691. };
  9692. // File:src/loaders/TextureLoader.js
  9693. /**
  9694. * @author mrdoob / http://mrdoob.com/
  9695. */
  9696. THREE.TextureLoader = function ( manager ) {
  9697. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9698. };
  9699. THREE.TextureLoader.prototype = {
  9700. constructor: THREE.TextureLoader,
  9701. load: function ( url, onLoad, onProgress, onError ) {
  9702. var scope = this;
  9703. var loader = new THREE.ImageLoader( scope.manager );
  9704. loader.setCrossOrigin( this.crossOrigin );
  9705. loader.load( url, function ( image ) {
  9706. var texture = new THREE.Texture( image );
  9707. texture.needsUpdate = true;
  9708. if ( onLoad !== undefined ) {
  9709. onLoad( texture );
  9710. }
  9711. }, onProgress, onError );
  9712. },
  9713. setCrossOrigin: function ( value ) {
  9714. this.crossOrigin = value;
  9715. }
  9716. };
  9717. // File:src/loaders/BinaryTextureLoader.js
  9718. /**
  9719. * @author Nikos M. / https://github.com/foo123/
  9720. *
  9721. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  9722. */
  9723. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  9724. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9725. // override in sub classes
  9726. this._parser = null;
  9727. };
  9728. THREE.BinaryTextureLoader.prototype = {
  9729. constructor: THREE.BinaryTextureLoader,
  9730. load: function ( url, onLoad, onProgress, onError ) {
  9731. var scope = this;
  9732. var texture = new THREE.DataTexture();
  9733. var loader = new THREE.XHRLoader( this.manager );
  9734. loader.setCrossOrigin( this.crossOrigin );
  9735. loader.setResponseType( 'arraybuffer' );
  9736. loader.load( url, function ( buffer ) {
  9737. var texData = scope._parser( buffer );
  9738. if ( ! texData ) return;
  9739. if ( undefined !== texData.image ) {
  9740. texture.image = texData.image;
  9741. } else if ( undefined !== texData.data ) {
  9742. texture.image.width = texData.width;
  9743. texture.image.height = texData.height;
  9744. texture.image.data = texData.data;
  9745. }
  9746. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  9747. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  9748. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  9749. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  9750. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  9751. if ( undefined !== texData.format ) {
  9752. texture.format = texData.format;
  9753. }
  9754. if ( undefined !== texData.type ) {
  9755. texture.type = texData.type;
  9756. }
  9757. if ( undefined !== texData.mipmaps ) {
  9758. texture.mipmaps = texData.mipmaps;
  9759. }
  9760. if ( 1 === texData.mipmapCount ) {
  9761. texture.minFilter = THREE.LinearFilter;
  9762. }
  9763. texture.needsUpdate = true;
  9764. if ( onLoad ) onLoad( texture, texData );
  9765. }, onProgress, onError );
  9766. return texture;
  9767. },
  9768. setCrossOrigin: function ( value ) {
  9769. this.crossOrigin = value;
  9770. }
  9771. };
  9772. // File:src/loaders/CompressedTextureLoader.js
  9773. /**
  9774. * @author mrdoob / http://mrdoob.com/
  9775. *
  9776. * Abstract Base class to block based textures loader (dds, pvr, ...)
  9777. */
  9778. THREE.CompressedTextureLoader = function ( manager ) {
  9779. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9780. // override in sub classes
  9781. this._parser = null;
  9782. };
  9783. THREE.CompressedTextureLoader.prototype = {
  9784. constructor: THREE.CompressedTextureLoader,
  9785. load: function ( url, onLoad, onProgress, onError ) {
  9786. var scope = this;
  9787. var images = [];
  9788. var texture = new THREE.CompressedTexture();
  9789. texture.image = images;
  9790. var loader = new THREE.XHRLoader( this.manager );
  9791. loader.setCrossOrigin( this.crossOrigin );
  9792. loader.setResponseType( 'arraybuffer' );
  9793. if ( Array.isArray( url ) ) {
  9794. var loaded = 0;
  9795. var loadTexture = function ( i ) {
  9796. loader.load( url[ i ], function ( buffer ) {
  9797. var texDatas = scope._parser( buffer, true );
  9798. images[ i ] = {
  9799. width: texDatas.width,
  9800. height: texDatas.height,
  9801. format: texDatas.format,
  9802. mipmaps: texDatas.mipmaps
  9803. };
  9804. loaded += 1;
  9805. if ( loaded === 6 ) {
  9806. if ( texDatas.mipmapCount === 1 )
  9807. texture.minFilter = THREE.LinearFilter;
  9808. texture.format = texDatas.format;
  9809. texture.needsUpdate = true;
  9810. if ( onLoad ) onLoad( texture );
  9811. }
  9812. }, onProgress, onError );
  9813. };
  9814. for ( var i = 0, il = url.length; i < il; ++ i ) {
  9815. loadTexture( i );
  9816. }
  9817. } else {
  9818. // compressed cubemap texture stored in a single DDS file
  9819. loader.load( url, function ( buffer ) {
  9820. var texDatas = scope._parser( buffer, true );
  9821. if ( texDatas.isCubemap ) {
  9822. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  9823. for ( var f = 0; f < faces; f ++ ) {
  9824. images[ f ] = { mipmaps : [] };
  9825. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  9826. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  9827. images[ f ].format = texDatas.format;
  9828. images[ f ].width = texDatas.width;
  9829. images[ f ].height = texDatas.height;
  9830. }
  9831. }
  9832. } else {
  9833. texture.image.width = texDatas.width;
  9834. texture.image.height = texDatas.height;
  9835. texture.mipmaps = texDatas.mipmaps;
  9836. }
  9837. if ( texDatas.mipmapCount === 1 ) {
  9838. texture.minFilter = THREE.LinearFilter;
  9839. }
  9840. texture.format = texDatas.format;
  9841. texture.needsUpdate = true;
  9842. if ( onLoad ) onLoad( texture );
  9843. }, onProgress, onError );
  9844. }
  9845. return texture;
  9846. },
  9847. setCrossOrigin: function ( value ) {
  9848. this.crossOrigin = value;
  9849. }
  9850. };
  9851. // File:src/materials/Material.js
  9852. /**
  9853. * @author mrdoob / http://mrdoob.com/
  9854. * @author alteredq / http://alteredqualia.com/
  9855. */
  9856. THREE.Material = function () {
  9857. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  9858. this.uuid = THREE.Math.generateUUID();
  9859. this.name = '';
  9860. this.type = 'Material';
  9861. this.side = THREE.FrontSide;
  9862. this.opacity = 1;
  9863. this.transparent = false;
  9864. this.blending = THREE.NormalBlending;
  9865. this.blendSrc = THREE.SrcAlphaFactor;
  9866. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  9867. this.blendEquation = THREE.AddEquation;
  9868. this.blendSrcAlpha = null;
  9869. this.blendDstAlpha = null;
  9870. this.blendEquationAlpha = null;
  9871. this.depthFunc = THREE.LessEqualDepth;
  9872. this.depthTest = true;
  9873. this.depthWrite = true;
  9874. this.colorWrite = true;
  9875. this.precision = null; // override the renderer's default precision for this material
  9876. this.polygonOffset = false;
  9877. this.polygonOffsetFactor = 0;
  9878. this.polygonOffsetUnits = 0;
  9879. this.alphaTest = 0;
  9880. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9881. this.visible = true;
  9882. this._needsUpdate = true;
  9883. };
  9884. THREE.Material.prototype = {
  9885. constructor: THREE.Material,
  9886. get needsUpdate () {
  9887. return this._needsUpdate;
  9888. },
  9889. set needsUpdate ( value ) {
  9890. if ( value === true ) this.update();
  9891. this._needsUpdate = value;
  9892. },
  9893. setValues: function ( values ) {
  9894. if ( values === undefined ) return;
  9895. for ( var key in values ) {
  9896. var newValue = values[ key ];
  9897. if ( newValue === undefined ) {
  9898. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9899. continue;
  9900. }
  9901. var currentValue = this[ key ];
  9902. if ( currentValue === undefined ) {
  9903. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9904. continue;
  9905. }
  9906. if ( currentValue instanceof THREE.Color ) {
  9907. currentValue.set( newValue );
  9908. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  9909. currentValue.copy( newValue );
  9910. } else if ( key === 'overdraw' ) {
  9911. // ensure overdraw is backwards-compatible with legacy boolean type
  9912. this[ key ] = Number( newValue );
  9913. } else {
  9914. this[ key ] = newValue;
  9915. }
  9916. }
  9917. },
  9918. toJSON: function ( meta ) {
  9919. var data = {
  9920. metadata: {
  9921. version: 4.4,
  9922. type: 'Material',
  9923. generator: 'Material.toJSON'
  9924. }
  9925. };
  9926. // standard Material serialization
  9927. data.uuid = this.uuid;
  9928. data.type = this.type;
  9929. if ( this.name !== '' ) data.name = this.name;
  9930. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  9931. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  9932. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  9933. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9934. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  9935. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9936. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9937. if ( this.bumpMap instanceof THREE.Texture ) {
  9938. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9939. data.bumpScale = this.bumpScale;
  9940. }
  9941. if ( this.normalMap instanceof THREE.Texture ) {
  9942. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9943. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  9944. }
  9945. if ( this.displacementMap instanceof THREE.Texture ) {
  9946. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9947. data.displacementScale = this.displacementScale;
  9948. data.displacementBias = this.displacementBias;
  9949. }
  9950. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9951. if ( this.envMap instanceof THREE.Texture ) {
  9952. data.envMap = this.envMap.toJSON( meta ).uuid;
  9953. data.reflectivity = this.reflectivity; // Scale behind envMap
  9954. }
  9955. if ( this.size !== undefined ) data.size = this.size;
  9956. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9957. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  9958. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  9959. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  9960. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  9961. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9962. if ( this.transparent === true ) data.transparent = this.transparent;
  9963. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9964. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9965. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9966. return data;
  9967. },
  9968. clone: function () {
  9969. return new this.constructor().copy( this );
  9970. },
  9971. copy: function ( source ) {
  9972. this.name = source.name;
  9973. this.side = source.side;
  9974. this.opacity = source.opacity;
  9975. this.transparent = source.transparent;
  9976. this.blending = source.blending;
  9977. this.blendSrc = source.blendSrc;
  9978. this.blendDst = source.blendDst;
  9979. this.blendEquation = source.blendEquation;
  9980. this.blendSrcAlpha = source.blendSrcAlpha;
  9981. this.blendDstAlpha = source.blendDstAlpha;
  9982. this.blendEquationAlpha = source.blendEquationAlpha;
  9983. this.depthFunc = source.depthFunc;
  9984. this.depthTest = source.depthTest;
  9985. this.depthWrite = source.depthWrite;
  9986. this.precision = source.precision;
  9987. this.polygonOffset = source.polygonOffset;
  9988. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9989. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9990. this.alphaTest = source.alphaTest;
  9991. this.overdraw = source.overdraw;
  9992. this.visible = source.visible;
  9993. return this;
  9994. },
  9995. update: function () {
  9996. this.dispatchEvent( { type: 'update' } );
  9997. },
  9998. dispose: function () {
  9999. this.dispatchEvent( { type: 'dispose' } );
  10000. },
  10001. // Deprecated
  10002. get wrapAround () {
  10003. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  10004. },
  10005. set wrapAround ( boolean ) {
  10006. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  10007. },
  10008. get wrapRGB () {
  10009. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  10010. return new THREE.Color();
  10011. }
  10012. };
  10013. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  10014. THREE.MaterialIdCount = 0;
  10015. // File:src/materials/LineBasicMaterial.js
  10016. /**
  10017. * @author mrdoob / http://mrdoob.com/
  10018. * @author alteredq / http://alteredqualia.com/
  10019. *
  10020. * parameters = {
  10021. * color: <hex>,
  10022. * opacity: <float>,
  10023. *
  10024. * blending: THREE.NormalBlending,
  10025. * depthTest: <bool>,
  10026. * depthWrite: <bool>,
  10027. *
  10028. * linewidth: <float>,
  10029. * linecap: "round",
  10030. * linejoin: "round",
  10031. *
  10032. * vertexColors: <bool>
  10033. *
  10034. * fog: <bool>
  10035. * }
  10036. */
  10037. THREE.LineBasicMaterial = function ( parameters ) {
  10038. THREE.Material.call( this );
  10039. this.type = 'LineBasicMaterial';
  10040. this.color = new THREE.Color( 0xffffff );
  10041. this.linewidth = 1;
  10042. this.linecap = 'round';
  10043. this.linejoin = 'round';
  10044. this.vertexColors = THREE.NoColors;
  10045. this.fog = true;
  10046. this.setValues( parameters );
  10047. };
  10048. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10049. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  10050. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  10051. THREE.Material.prototype.copy.call( this, source );
  10052. this.color.copy( source.color );
  10053. this.linewidth = source.linewidth;
  10054. this.linecap = source.linecap;
  10055. this.linejoin = source.linejoin;
  10056. this.vertexColors = source.vertexColors;
  10057. this.fog = source.fog;
  10058. return this;
  10059. };
  10060. // File:src/materials/LineDashedMaterial.js
  10061. /**
  10062. * @author alteredq / http://alteredqualia.com/
  10063. *
  10064. * parameters = {
  10065. * color: <hex>,
  10066. * opacity: <float>,
  10067. *
  10068. * blending: THREE.NormalBlending,
  10069. * depthTest: <bool>,
  10070. * depthWrite: <bool>,
  10071. *
  10072. * linewidth: <float>,
  10073. *
  10074. * scale: <float>,
  10075. * dashSize: <float>,
  10076. * gapSize: <float>,
  10077. *
  10078. * vertexColors: <bool>
  10079. *
  10080. * fog: <bool>
  10081. * }
  10082. */
  10083. THREE.LineDashedMaterial = function ( parameters ) {
  10084. THREE.Material.call( this );
  10085. this.type = 'LineDashedMaterial';
  10086. this.color = new THREE.Color( 0xffffff );
  10087. this.linewidth = 1;
  10088. this.scale = 1;
  10089. this.dashSize = 3;
  10090. this.gapSize = 1;
  10091. this.vertexColors = false;
  10092. this.fog = true;
  10093. this.setValues( parameters );
  10094. };
  10095. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  10096. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  10097. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  10098. THREE.Material.prototype.copy.call( this, source );
  10099. this.color.copy( source.color );
  10100. this.linewidth = source.linewidth;
  10101. this.scale = source.scale;
  10102. this.dashSize = source.dashSize;
  10103. this.gapSize = source.gapSize;
  10104. this.vertexColors = source.vertexColors;
  10105. this.fog = source.fog;
  10106. return this;
  10107. };
  10108. // File:src/materials/MeshBasicMaterial.js
  10109. /**
  10110. * @author mrdoob / http://mrdoob.com/
  10111. * @author alteredq / http://alteredqualia.com/
  10112. *
  10113. * parameters = {
  10114. * color: <hex>,
  10115. * opacity: <float>,
  10116. * map: new THREE.Texture( <Image> ),
  10117. *
  10118. * aoMap: new THREE.Texture( <Image> ),
  10119. * aoMapIntensity: <float>
  10120. *
  10121. * specularMap: new THREE.Texture( <Image> ),
  10122. *
  10123. * alphaMap: new THREE.Texture( <Image> ),
  10124. *
  10125. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10126. * combine: THREE.Multiply,
  10127. * reflectivity: <float>,
  10128. * refractionRatio: <float>,
  10129. *
  10130. * shading: THREE.SmoothShading,
  10131. * blending: THREE.NormalBlending,
  10132. * depthTest: <bool>,
  10133. * depthWrite: <bool>,
  10134. *
  10135. * wireframe: <boolean>,
  10136. * wireframeLinewidth: <float>,
  10137. *
  10138. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10139. *
  10140. * skinning: <bool>,
  10141. * morphTargets: <bool>,
  10142. *
  10143. * fog: <bool>
  10144. * }
  10145. */
  10146. THREE.MeshBasicMaterial = function ( parameters ) {
  10147. THREE.Material.call( this );
  10148. this.type = 'MeshBasicMaterial';
  10149. this.color = new THREE.Color( 0xffffff ); // emissive
  10150. this.map = null;
  10151. this.aoMap = null;
  10152. this.aoMapIntensity = 1.0;
  10153. this.specularMap = null;
  10154. this.alphaMap = null;
  10155. this.envMap = null;
  10156. this.combine = THREE.MultiplyOperation;
  10157. this.reflectivity = 1;
  10158. this.refractionRatio = 0.98;
  10159. this.fog = true;
  10160. this.shading = THREE.SmoothShading;
  10161. this.wireframe = false;
  10162. this.wireframeLinewidth = 1;
  10163. this.wireframeLinecap = 'round';
  10164. this.wireframeLinejoin = 'round';
  10165. this.vertexColors = THREE.NoColors;
  10166. this.skinning = false;
  10167. this.morphTargets = false;
  10168. this.setValues( parameters );
  10169. };
  10170. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10171. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  10172. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  10173. THREE.Material.prototype.copy.call( this, source );
  10174. this.color.copy( source.color );
  10175. this.map = source.map;
  10176. this.aoMap = source.aoMap;
  10177. this.aoMapIntensity = source.aoMapIntensity;
  10178. this.specularMap = source.specularMap;
  10179. this.alphaMap = source.alphaMap;
  10180. this.envMap = source.envMap;
  10181. this.combine = source.combine;
  10182. this.reflectivity = source.reflectivity;
  10183. this.refractionRatio = source.refractionRatio;
  10184. this.fog = source.fog;
  10185. this.shading = source.shading;
  10186. this.wireframe = source.wireframe;
  10187. this.wireframeLinewidth = source.wireframeLinewidth;
  10188. this.wireframeLinecap = source.wireframeLinecap;
  10189. this.wireframeLinejoin = source.wireframeLinejoin;
  10190. this.vertexColors = source.vertexColors;
  10191. this.skinning = source.skinning;
  10192. this.morphTargets = source.morphTargets;
  10193. return this;
  10194. };
  10195. // File:src/materials/MeshLambertMaterial.js
  10196. /**
  10197. * @author mrdoob / http://mrdoob.com/
  10198. * @author alteredq / http://alteredqualia.com/
  10199. *
  10200. * parameters = {
  10201. * color: <hex>,
  10202. * emissive: <hex>,
  10203. * opacity: <float>,
  10204. *
  10205. * map: new THREE.Texture( <Image> ),
  10206. *
  10207. * specularMap: new THREE.Texture( <Image> ),
  10208. *
  10209. * alphaMap: new THREE.Texture( <Image> ),
  10210. *
  10211. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10212. * combine: THREE.Multiply,
  10213. * reflectivity: <float>,
  10214. * refractionRatio: <float>,
  10215. *
  10216. * blending: THREE.NormalBlending,
  10217. * depthTest: <bool>,
  10218. * depthWrite: <bool>,
  10219. *
  10220. * wireframe: <boolean>,
  10221. * wireframeLinewidth: <float>,
  10222. *
  10223. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10224. *
  10225. * skinning: <bool>,
  10226. * morphTargets: <bool>,
  10227. * morphNormals: <bool>,
  10228. *
  10229. * fog: <bool>
  10230. * }
  10231. */
  10232. THREE.MeshLambertMaterial = function ( parameters ) {
  10233. THREE.Material.call( this );
  10234. this.type = 'MeshLambertMaterial';
  10235. this.color = new THREE.Color( 0xffffff ); // diffuse
  10236. this.emissive = new THREE.Color( 0x000000 );
  10237. this.map = null;
  10238. this.specularMap = null;
  10239. this.alphaMap = null;
  10240. this.envMap = null;
  10241. this.combine = THREE.MultiplyOperation;
  10242. this.reflectivity = 1;
  10243. this.refractionRatio = 0.98;
  10244. this.fog = true;
  10245. this.wireframe = false;
  10246. this.wireframeLinewidth = 1;
  10247. this.wireframeLinecap = 'round';
  10248. this.wireframeLinejoin = 'round';
  10249. this.vertexColors = THREE.NoColors;
  10250. this.skinning = false;
  10251. this.morphTargets = false;
  10252. this.morphNormals = false;
  10253. this.setValues( parameters );
  10254. };
  10255. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  10256. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  10257. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  10258. THREE.Material.prototype.copy.call( this, source );
  10259. this.color.copy( source.color );
  10260. this.emissive.copy( source.emissive );
  10261. this.map = source.map;
  10262. this.specularMap = source.specularMap;
  10263. this.alphaMap = source.alphaMap;
  10264. this.envMap = source.envMap;
  10265. this.combine = source.combine;
  10266. this.reflectivity = source.reflectivity;
  10267. this.refractionRatio = source.refractionRatio;
  10268. this.fog = source.fog;
  10269. this.wireframe = source.wireframe;
  10270. this.wireframeLinewidth = source.wireframeLinewidth;
  10271. this.wireframeLinecap = source.wireframeLinecap;
  10272. this.wireframeLinejoin = source.wireframeLinejoin;
  10273. this.vertexColors = source.vertexColors;
  10274. this.skinning = source.skinning;
  10275. this.morphTargets = source.morphTargets;
  10276. this.morphNormals = source.morphNormals;
  10277. return this;
  10278. };
  10279. // File:src/materials/MeshPhongMaterial.js
  10280. /**
  10281. * @author mrdoob / http://mrdoob.com/
  10282. * @author alteredq / http://alteredqualia.com/
  10283. *
  10284. * parameters = {
  10285. * color: <hex>,
  10286. * emissive: <hex>,
  10287. * specular: <hex>,
  10288. * shininess: <float>,
  10289. * opacity: <float>,
  10290. *
  10291. * map: new THREE.Texture( <Image> ),
  10292. *
  10293. * lightMap: new THREE.Texture( <Image> ),
  10294. * lightMapIntensity: <float>
  10295. *
  10296. * aoMap: new THREE.Texture( <Image> ),
  10297. * aoMapIntensity: <float>
  10298. *
  10299. * emissiveMap: new THREE.Texture( <Image> ),
  10300. *
  10301. * bumpMap: new THREE.Texture( <Image> ),
  10302. * bumpScale: <float>,
  10303. *
  10304. * normalMap: new THREE.Texture( <Image> ),
  10305. * normalScale: <Vector2>,
  10306. *
  10307. * displacementMap: new THREE.Texture( <Image> ),
  10308. * displacementScale: <float>,
  10309. * displacementBias: <float>,
  10310. *
  10311. * specularMap: new THREE.Texture( <Image> ),
  10312. *
  10313. * alphaMap: new THREE.Texture( <Image> ),
  10314. *
  10315. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10316. * combine: THREE.Multiply,
  10317. * reflectivity: <float>,
  10318. * refractionRatio: <float>,
  10319. *
  10320. * shading: THREE.SmoothShading,
  10321. * blending: THREE.NormalBlending,
  10322. * depthTest: <bool>,
  10323. * depthWrite: <bool>,
  10324. *
  10325. * wireframe: <boolean>,
  10326. * wireframeLinewidth: <float>,
  10327. *
  10328. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10329. *
  10330. * skinning: <bool>,
  10331. * morphTargets: <bool>,
  10332. * morphNormals: <bool>,
  10333. *
  10334. * fog: <bool>
  10335. * }
  10336. */
  10337. THREE.MeshPhongMaterial = function ( parameters ) {
  10338. THREE.Material.call( this );
  10339. this.type = 'MeshPhongMaterial';
  10340. this.color = new THREE.Color( 0xffffff ); // diffuse
  10341. this.emissive = new THREE.Color( 0x000000 );
  10342. this.specular = new THREE.Color( 0x111111 );
  10343. this.shininess = 30;
  10344. this.metal = false;
  10345. this.map = null;
  10346. this.lightMap = null;
  10347. this.lightMapIntensity = 1.0;
  10348. this.aoMap = null;
  10349. this.aoMapIntensity = 1.0;
  10350. this.emissiveMap = null;
  10351. this.bumpMap = null;
  10352. this.bumpScale = 1;
  10353. this.normalMap = null;
  10354. this.normalScale = new THREE.Vector2( 1, 1 );
  10355. this.displacementMap = null;
  10356. this.displacementScale = 1;
  10357. this.displacementBias = 0;
  10358. this.specularMap = null;
  10359. this.alphaMap = null;
  10360. this.envMap = null;
  10361. this.combine = THREE.MultiplyOperation;
  10362. this.reflectivity = 1;
  10363. this.refractionRatio = 0.98;
  10364. this.fog = true;
  10365. this.shading = THREE.SmoothShading;
  10366. this.wireframe = false;
  10367. this.wireframeLinewidth = 1;
  10368. this.wireframeLinecap = 'round';
  10369. this.wireframeLinejoin = 'round';
  10370. this.vertexColors = THREE.NoColors;
  10371. this.skinning = false;
  10372. this.morphTargets = false;
  10373. this.morphNormals = false;
  10374. this.setValues( parameters );
  10375. };
  10376. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  10377. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  10378. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  10379. THREE.Material.prototype.copy.call( this, source );
  10380. this.color.copy( source.color );
  10381. this.emissive.copy( source.emissive );
  10382. this.specular.copy( source.specular );
  10383. this.shininess = source.shininess;
  10384. this.metal = source.metal;
  10385. this.map = source.map;
  10386. this.lightMap = source.lightMap;
  10387. this.lightMapIntensity = source.lightMapIntensity;
  10388. this.aoMap = source.aoMap;
  10389. this.aoMapIntensity = source.aoMapIntensity;
  10390. this.emissiveMap = source.emissiveMap;
  10391. this.bumpMap = source.bumpMap;
  10392. this.bumpScale = source.bumpScale;
  10393. this.normalMap = source.normalMap;
  10394. this.normalScale.copy( source.normalScale );
  10395. this.displacementMap = source.displacementMap;
  10396. this.displacementScale = source.displacementScale;
  10397. this.displacementBias = source.displacementBias;
  10398. this.specularMap = source.specularMap;
  10399. this.alphaMap = source.alphaMap;
  10400. this.envMap = source.envMap;
  10401. this.combine = source.combine;
  10402. this.reflectivity = source.reflectivity;
  10403. this.refractionRatio = source.refractionRatio;
  10404. this.fog = source.fog;
  10405. this.shading = source.shading;
  10406. this.wireframe = source.wireframe;
  10407. this.wireframeLinewidth = source.wireframeLinewidth;
  10408. this.wireframeLinecap = source.wireframeLinecap;
  10409. this.wireframeLinejoin = source.wireframeLinejoin;
  10410. this.vertexColors = source.vertexColors;
  10411. this.skinning = source.skinning;
  10412. this.morphTargets = source.morphTargets;
  10413. this.morphNormals = source.morphNormals;
  10414. return this;
  10415. };
  10416. // File:src/materials/MeshDepthMaterial.js
  10417. /**
  10418. * @author mrdoob / http://mrdoob.com/
  10419. * @author alteredq / http://alteredqualia.com/
  10420. *
  10421. * parameters = {
  10422. * opacity: <float>,
  10423. *
  10424. * blending: THREE.NormalBlending,
  10425. * depthTest: <bool>,
  10426. * depthWrite: <bool>,
  10427. *
  10428. * wireframe: <boolean>,
  10429. * wireframeLinewidth: <float>
  10430. * }
  10431. */
  10432. THREE.MeshDepthMaterial = function ( parameters ) {
  10433. THREE.Material.call( this );
  10434. this.type = 'MeshDepthMaterial';
  10435. this.morphTargets = false;
  10436. this.wireframe = false;
  10437. this.wireframeLinewidth = 1;
  10438. this.setValues( parameters );
  10439. };
  10440. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  10441. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  10442. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  10443. THREE.Material.prototype.copy.call( this, source );
  10444. this.wireframe = source.wireframe;
  10445. this.wireframeLinewidth = source.wireframeLinewidth;
  10446. return this;
  10447. };
  10448. // File:src/materials/MeshNormalMaterial.js
  10449. /**
  10450. * @author mrdoob / http://mrdoob.com/
  10451. *
  10452. * parameters = {
  10453. * opacity: <float>,
  10454. *
  10455. * shading: THREE.FlatShading,
  10456. * blending: THREE.NormalBlending,
  10457. * depthTest: <bool>,
  10458. * depthWrite: <bool>,
  10459. *
  10460. * wireframe: <boolean>,
  10461. * wireframeLinewidth: <float>
  10462. * }
  10463. */
  10464. THREE.MeshNormalMaterial = function ( parameters ) {
  10465. THREE.Material.call( this, parameters );
  10466. this.type = 'MeshNormalMaterial';
  10467. this.wireframe = false;
  10468. this.wireframeLinewidth = 1;
  10469. this.morphTargets = false;
  10470. this.setValues( parameters );
  10471. };
  10472. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  10473. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  10474. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  10475. THREE.Material.prototype.copy.call( this, source );
  10476. this.wireframe = source.wireframe;
  10477. this.wireframeLinewidth = source.wireframeLinewidth;
  10478. return this;
  10479. };
  10480. // File:src/materials/MultiMaterial.js
  10481. /**
  10482. * @author mrdoob / http://mrdoob.com/
  10483. */
  10484. THREE.MultiMaterial = function ( materials ) {
  10485. this.uuid = THREE.Math.generateUUID();
  10486. this.type = 'MultiMaterial';
  10487. this.materials = materials instanceof Array ? materials : [];
  10488. this.visible = true;
  10489. };
  10490. THREE.MultiMaterial.prototype = {
  10491. constructor: THREE.MultiMaterial,
  10492. toJSON: function () {
  10493. var output = {
  10494. metadata: {
  10495. version: 4.2,
  10496. type: 'material',
  10497. generator: 'MaterialExporter'
  10498. },
  10499. uuid: this.uuid,
  10500. type: this.type,
  10501. materials: []
  10502. };
  10503. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  10504. output.materials.push( this.materials[ i ].toJSON() );
  10505. }
  10506. output.visible = this.visible;
  10507. return output;
  10508. },
  10509. clone: function () {
  10510. var material = new this.constructor();
  10511. for ( var i = 0; i < this.materials.length; i ++ ) {
  10512. material.materials.push( this.materials[ i ].clone() );
  10513. }
  10514. material.visible = this.visible;
  10515. return material;
  10516. }
  10517. };
  10518. // backwards compatibility
  10519. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  10520. // File:src/materials/PointsMaterial.js
  10521. /**
  10522. * @author mrdoob / http://mrdoob.com/
  10523. * @author alteredq / http://alteredqualia.com/
  10524. *
  10525. * parameters = {
  10526. * color: <hex>,
  10527. * opacity: <float>,
  10528. * map: new THREE.Texture( <Image> ),
  10529. *
  10530. * size: <float>,
  10531. * sizeAttenuation: <bool>,
  10532. *
  10533. * blending: THREE.NormalBlending,
  10534. * depthTest: <bool>,
  10535. * depthWrite: <bool>,
  10536. *
  10537. * vertexColors: <bool>,
  10538. *
  10539. * fog: <bool>
  10540. * }
  10541. */
  10542. THREE.PointsMaterial = function ( parameters ) {
  10543. THREE.Material.call( this );
  10544. this.type = 'PointsMaterial';
  10545. this.color = new THREE.Color( 0xffffff );
  10546. this.map = null;
  10547. this.size = 1;
  10548. this.sizeAttenuation = true;
  10549. this.vertexColors = THREE.NoColors;
  10550. this.fog = true;
  10551. this.setValues( parameters );
  10552. };
  10553. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  10554. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  10555. THREE.PointsMaterial.prototype.copy = function ( source ) {
  10556. THREE.Material.prototype.copy.call( this, source );
  10557. this.color.copy( source.color );
  10558. this.map = source.map;
  10559. this.size = source.size;
  10560. this.sizeAttenuation = source.sizeAttenuation;
  10561. this.vertexColors = source.vertexColors;
  10562. this.fog = source.fog;
  10563. return this;
  10564. };
  10565. // backwards compatibility
  10566. THREE.PointCloudMaterial = function ( parameters ) {
  10567. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  10568. return new THREE.PointsMaterial( parameters );
  10569. };
  10570. THREE.ParticleBasicMaterial = function ( parameters ) {
  10571. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  10572. return new THREE.PointsMaterial( parameters );
  10573. };
  10574. THREE.ParticleSystemMaterial = function ( parameters ) {
  10575. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  10576. return new THREE.PointsMaterial( parameters );
  10577. };
  10578. // File:src/materials/ShaderMaterial.js
  10579. /**
  10580. * @author alteredq / http://alteredqualia.com/
  10581. *
  10582. * parameters = {
  10583. * defines: { "label" : "value" },
  10584. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  10585. *
  10586. * fragmentShader: <string>,
  10587. * vertexShader: <string>,
  10588. *
  10589. * shading: THREE.SmoothShading,
  10590. * blending: THREE.NormalBlending,
  10591. * depthTest: <bool>,
  10592. * depthWrite: <bool>,
  10593. *
  10594. * wireframe: <boolean>,
  10595. * wireframeLinewidth: <float>,
  10596. *
  10597. * lights: <bool>,
  10598. *
  10599. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10600. *
  10601. * skinning: <bool>,
  10602. * morphTargets: <bool>,
  10603. * morphNormals: <bool>,
  10604. *
  10605. * fog: <bool>
  10606. * }
  10607. */
  10608. THREE.ShaderMaterial = function ( parameters ) {
  10609. THREE.Material.call( this );
  10610. this.type = 'ShaderMaterial';
  10611. this.defines = {};
  10612. this.uniforms = {};
  10613. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  10614. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  10615. this.shading = THREE.SmoothShading;
  10616. this.linewidth = 1;
  10617. this.wireframe = false;
  10618. this.wireframeLinewidth = 1;
  10619. this.fog = false; // set to use scene fog
  10620. this.lights = false; // set to use scene lights
  10621. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  10622. this.skinning = false; // set to use skinning attribute streams
  10623. this.morphTargets = false; // set to use morph targets
  10624. this.morphNormals = false; // set to use morph normals
  10625. this.derivatives = false; // set to use derivatives
  10626. // When rendered geometry doesn't include these attributes but the material does,
  10627. // use these default values in WebGL. This avoids errors when buffer data is missing.
  10628. this.defaultAttributeValues = {
  10629. 'color': [ 1, 1, 1 ],
  10630. 'uv': [ 0, 0 ],
  10631. 'uv2': [ 0, 0 ]
  10632. };
  10633. this.index0AttributeName = undefined;
  10634. if ( parameters !== undefined ) {
  10635. if ( parameters.attributes !== undefined ) {
  10636. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  10637. }
  10638. this.setValues( parameters );
  10639. }
  10640. };
  10641. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  10642. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  10643. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  10644. THREE.Material.prototype.copy.call( this, source );
  10645. this.fragmentShader = source.fragmentShader;
  10646. this.vertexShader = source.vertexShader;
  10647. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  10648. this.attributes = source.attributes;
  10649. this.defines = source.defines;
  10650. this.shading = source.shading;
  10651. this.wireframe = source.wireframe;
  10652. this.wireframeLinewidth = source.wireframeLinewidth;
  10653. this.fog = source.fog;
  10654. this.lights = source.lights;
  10655. this.vertexColors = source.vertexColors;
  10656. this.skinning = source.skinning;
  10657. this.morphTargets = source.morphTargets;
  10658. this.morphNormals = source.morphNormals;
  10659. this.derivatives = source.derivatives;
  10660. return this;
  10661. };
  10662. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  10663. var data = THREE.Material.prototype.toJSON.call( this, meta );
  10664. data.uniforms = this.uniforms;
  10665. data.attributes = this.attributes;
  10666. data.vertexShader = this.vertexShader;
  10667. data.fragmentShader = this.fragmentShader;
  10668. return data;
  10669. };
  10670. // File:src/materials/RawShaderMaterial.js
  10671. /**
  10672. * @author mrdoob / http://mrdoob.com/
  10673. */
  10674. THREE.RawShaderMaterial = function ( parameters ) {
  10675. THREE.ShaderMaterial.call( this, parameters );
  10676. this.type = 'RawShaderMaterial';
  10677. };
  10678. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  10679. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  10680. // File:src/materials/SpriteMaterial.js
  10681. /**
  10682. * @author alteredq / http://alteredqualia.com/
  10683. *
  10684. * parameters = {
  10685. * color: <hex>,
  10686. * opacity: <float>,
  10687. * map: new THREE.Texture( <Image> ),
  10688. *
  10689. * blending: THREE.NormalBlending,
  10690. * depthTest: <bool>,
  10691. * depthWrite: <bool>,
  10692. *
  10693. * uvOffset: new THREE.Vector2(),
  10694. * uvScale: new THREE.Vector2(),
  10695. *
  10696. * fog: <bool>
  10697. * }
  10698. */
  10699. THREE.SpriteMaterial = function ( parameters ) {
  10700. THREE.Material.call( this );
  10701. this.type = 'SpriteMaterial';
  10702. this.color = new THREE.Color( 0xffffff );
  10703. this.map = null;
  10704. this.rotation = 0;
  10705. this.fog = false;
  10706. // set parameters
  10707. this.setValues( parameters );
  10708. };
  10709. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  10710. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  10711. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  10712. THREE.Material.prototype.copy.call( this, source );
  10713. this.color.copy( source.color );
  10714. this.map = source.map;
  10715. this.rotation = source.rotation;
  10716. this.fog = source.fog;
  10717. return this;
  10718. };
  10719. // File:src/textures/Texture.js
  10720. /**
  10721. * @author mrdoob / http://mrdoob.com/
  10722. * @author alteredq / http://alteredqualia.com/
  10723. * @author szimek / https://github.com/szimek/
  10724. */
  10725. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10726. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  10727. this.uuid = THREE.Math.generateUUID();
  10728. this.name = '';
  10729. this.sourceFile = '';
  10730. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  10731. this.mipmaps = [];
  10732. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  10733. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  10734. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  10735. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  10736. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  10737. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  10738. this.format = format !== undefined ? format : THREE.RGBAFormat;
  10739. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  10740. this.offset = new THREE.Vector2( 0, 0 );
  10741. this.repeat = new THREE.Vector2( 1, 1 );
  10742. this.generateMipmaps = true;
  10743. this.premultiplyAlpha = false;
  10744. this.flipY = true;
  10745. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  10746. this.version = 0;
  10747. this.onUpdate = null;
  10748. };
  10749. THREE.Texture.DEFAULT_IMAGE = undefined;
  10750. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  10751. THREE.Texture.prototype = {
  10752. constructor: THREE.Texture,
  10753. set needsUpdate ( value ) {
  10754. if ( value === true ) this.version ++;
  10755. },
  10756. clone: function () {
  10757. return new this.constructor().copy( this );
  10758. },
  10759. copy: function ( source ) {
  10760. this.image = source.image;
  10761. this.mipmaps = source.mipmaps.slice( 0 );
  10762. this.mapping = source.mapping;
  10763. this.wrapS = source.wrapS;
  10764. this.wrapT = source.wrapT;
  10765. this.magFilter = source.magFilter;
  10766. this.minFilter = source.minFilter;
  10767. this.anisotropy = source.anisotropy;
  10768. this.format = source.format;
  10769. this.type = source.type;
  10770. this.offset.copy( source.offset );
  10771. this.repeat.copy( source.repeat );
  10772. this.generateMipmaps = source.generateMipmaps;
  10773. this.premultiplyAlpha = source.premultiplyAlpha;
  10774. this.flipY = source.flipY;
  10775. this.unpackAlignment = source.unpackAlignment;
  10776. return this;
  10777. },
  10778. toJSON: function ( meta ) {
  10779. if ( meta.textures[ this.uuid ] !== undefined ) {
  10780. return meta.textures[ this.uuid ];
  10781. }
  10782. function getDataURL( image ) {
  10783. var canvas;
  10784. if ( image.toDataURL !== undefined ) {
  10785. canvas = image;
  10786. } else {
  10787. canvas = document.createElement( 'canvas' );
  10788. canvas.width = image.width;
  10789. canvas.height = image.height;
  10790. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  10791. }
  10792. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  10793. return canvas.toDataURL( 'image/jpeg', 0.6 );
  10794. } else {
  10795. return canvas.toDataURL( 'image/png' );
  10796. }
  10797. }
  10798. var output = {
  10799. metadata: {
  10800. version: 4.4,
  10801. type: 'Texture',
  10802. generator: 'Texture.toJSON'
  10803. },
  10804. uuid: this.uuid,
  10805. name: this.name,
  10806. mapping: this.mapping,
  10807. repeat: [ this.repeat.x, this.repeat.y ],
  10808. offset: [ this.offset.x, this.offset.y ],
  10809. wrap: [ this.wrapS, this.wrapT ],
  10810. minFilter: this.minFilter,
  10811. magFilter: this.magFilter,
  10812. anisotropy: this.anisotropy
  10813. };
  10814. if ( this.image !== undefined ) {
  10815. // TODO: Move to THREE.Image
  10816. var image = this.image;
  10817. if ( image.uuid === undefined ) {
  10818. image.uuid = THREE.Math.generateUUID(); // UGH
  10819. }
  10820. if ( meta.images[ image.uuid ] === undefined ) {
  10821. meta.images[ image.uuid ] = {
  10822. uuid: image.uuid,
  10823. url: getDataURL( image )
  10824. };
  10825. }
  10826. output.image = image.uuid;
  10827. }
  10828. meta.textures[ this.uuid ] = output;
  10829. return output;
  10830. },
  10831. dispose: function () {
  10832. this.dispatchEvent( { type: 'dispose' } );
  10833. },
  10834. transformUv: function ( uv ) {
  10835. if ( this.mapping !== THREE.UVMapping ) return;
  10836. uv.multiply( this.repeat );
  10837. uv.add( this.offset );
  10838. if ( uv.x < 0 || uv.x > 1 ) {
  10839. switch ( this.wrapS ) {
  10840. case THREE.RepeatWrapping:
  10841. uv.x = uv.x - Math.floor( uv.x );
  10842. break;
  10843. case THREE.ClampToEdgeWrapping:
  10844. uv.x = uv.x < 0 ? 0 : 1;
  10845. break;
  10846. case THREE.MirroredRepeatWrapping:
  10847. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  10848. uv.x = Math.ceil( uv.x ) - uv.x;
  10849. } else {
  10850. uv.x = uv.x - Math.floor( uv.x );
  10851. }
  10852. break;
  10853. }
  10854. }
  10855. if ( uv.y < 0 || uv.y > 1 ) {
  10856. switch ( this.wrapT ) {
  10857. case THREE.RepeatWrapping:
  10858. uv.y = uv.y - Math.floor( uv.y );
  10859. break;
  10860. case THREE.ClampToEdgeWrapping:
  10861. uv.y = uv.y < 0 ? 0 : 1;
  10862. break;
  10863. case THREE.MirroredRepeatWrapping:
  10864. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  10865. uv.y = Math.ceil( uv.y ) - uv.y;
  10866. } else {
  10867. uv.y = uv.y - Math.floor( uv.y );
  10868. }
  10869. break;
  10870. }
  10871. }
  10872. if ( this.flipY ) {
  10873. uv.y = 1 - uv.y;
  10874. }
  10875. }
  10876. };
  10877. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  10878. THREE.TextureIdCount = 0;
  10879. // File:src/textures/CanvasTexture.js
  10880. /**
  10881. * @author mrdoob / http://mrdoob.com/
  10882. */
  10883. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10884. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10885. this.needsUpdate = true;
  10886. };
  10887. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  10888. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  10889. // File:src/textures/CubeTexture.js
  10890. /**
  10891. * @author mrdoob / http://mrdoob.com/
  10892. */
  10893. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10894. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  10895. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10896. this.images = images;
  10897. this.flipY = false;
  10898. };
  10899. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  10900. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  10901. THREE.CubeTexture.prototype.copy = function ( source ) {
  10902. THREE.Texture.prototype.copy.call( this, source );
  10903. this.images = source.images;
  10904. return this;
  10905. };
  10906. // File:src/textures/CompressedTexture.js
  10907. /**
  10908. * @author alteredq / http://alteredqualia.com/
  10909. */
  10910. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10911. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10912. this.image = { width: width, height: height };
  10913. this.mipmaps = mipmaps;
  10914. // no flipping for cube textures
  10915. // (also flipping doesn't work for compressed textures )
  10916. this.flipY = false;
  10917. // can't generate mipmaps for compressed textures
  10918. // mips must be embedded in DDS files
  10919. this.generateMipmaps = false;
  10920. };
  10921. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  10922. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  10923. // File:src/textures/DataTexture.js
  10924. /**
  10925. * @author alteredq / http://alteredqualia.com/
  10926. */
  10927. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10928. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10929. this.image = { data: data, width: width, height: height };
  10930. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  10931. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  10932. this.flipY = false;
  10933. this.generateMipmaps = false;
  10934. };
  10935. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  10936. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  10937. // File:src/textures/VideoTexture.js
  10938. /**
  10939. * @author mrdoob / http://mrdoob.com/
  10940. */
  10941. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10942. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10943. this.generateMipmaps = false;
  10944. var scope = this;
  10945. var update = function () {
  10946. requestAnimationFrame( update );
  10947. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  10948. scope.needsUpdate = true;
  10949. }
  10950. };
  10951. update();
  10952. };
  10953. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  10954. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  10955. // File:src/objects/Group.js
  10956. /**
  10957. * @author mrdoob / http://mrdoob.com/
  10958. */
  10959. THREE.Group = function () {
  10960. THREE.Object3D.call( this );
  10961. this.type = 'Group';
  10962. };
  10963. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  10964. THREE.Group.prototype.constructor = THREE.Group;
  10965. // File:src/objects/Points.js
  10966. /**
  10967. * @author alteredq / http://alteredqualia.com/
  10968. */
  10969. THREE.Points = function ( geometry, material ) {
  10970. THREE.Object3D.call( this );
  10971. this.type = 'Points';
  10972. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10973. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  10974. };
  10975. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  10976. THREE.Points.prototype.constructor = THREE.Points;
  10977. THREE.Points.prototype.raycast = ( function () {
  10978. var inverseMatrix = new THREE.Matrix4();
  10979. var ray = new THREE.Ray();
  10980. return function raycast( raycaster, intersects ) {
  10981. var object = this;
  10982. var geometry = object.geometry;
  10983. var threshold = raycaster.params.Points.threshold;
  10984. inverseMatrix.getInverse( this.matrixWorld );
  10985. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10986. if ( geometry.boundingBox !== null ) {
  10987. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10988. return;
  10989. }
  10990. }
  10991. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10992. var localThresholdSq = localThreshold * localThreshold;
  10993. var position = new THREE.Vector3();
  10994. function testPoint( point, index ) {
  10995. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  10996. if ( rayPointDistanceSq < localThresholdSq ) {
  10997. var intersectPoint = ray.closestPointToPoint( point );
  10998. intersectPoint.applyMatrix4( object.matrixWorld );
  10999. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  11000. if ( distance < raycaster.near || distance > raycaster.far ) return;
  11001. intersects.push( {
  11002. distance: distance,
  11003. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  11004. point: intersectPoint.clone(),
  11005. index: index,
  11006. face: null,
  11007. object: object
  11008. } );
  11009. }
  11010. }
  11011. if ( geometry instanceof THREE.BufferGeometry ) {
  11012. var index = geometry.index;
  11013. var attributes = geometry.attributes;
  11014. var positions = attributes.position.array;
  11015. if ( index !== null ) {
  11016. var indices = index.array;
  11017. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  11018. var a = indices[ i ];
  11019. position.fromArray( positions, a * 3 );
  11020. testPoint( position, a );
  11021. }
  11022. } else {
  11023. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  11024. position.fromArray( positions, i * 3 );
  11025. testPoint( position, i );
  11026. }
  11027. }
  11028. } else {
  11029. var vertices = geometry.vertices;
  11030. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  11031. testPoint( vertices[ i ], i );
  11032. }
  11033. }
  11034. };
  11035. }() );
  11036. THREE.Points.prototype.clone = function () {
  11037. return new this.constructor( this.geometry, this.material ).copy( this );
  11038. };
  11039. THREE.Points.prototype.toJSON = function ( meta ) {
  11040. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11041. // only serialize if not in meta geometries cache
  11042. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  11043. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  11044. }
  11045. // only serialize if not in meta materials cache
  11046. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11047. meta.materials[ this.material.uuid ] = this.material.toJSON();
  11048. }
  11049. data.object.geometry = this.geometry.uuid;
  11050. data.object.material = this.material.uuid;
  11051. return data;
  11052. };
  11053. // Backwards compatibility
  11054. THREE.PointCloud = function ( geometry, material ) {
  11055. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  11056. return new THREE.Points( geometry, material );
  11057. };
  11058. THREE.ParticleSystem = function ( geometry, material ) {
  11059. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  11060. return new THREE.Points( geometry, material );
  11061. };
  11062. // File:src/objects/Line.js
  11063. /**
  11064. * @author mrdoob / http://mrdoob.com/
  11065. */
  11066. THREE.Line = function ( geometry, material, mode ) {
  11067. if ( mode === 1 ) {
  11068. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  11069. return new THREE.LineSegments( geometry, material );
  11070. }
  11071. THREE.Object3D.call( this );
  11072. this.type = 'Line';
  11073. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11074. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  11075. };
  11076. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  11077. THREE.Line.prototype.constructor = THREE.Line;
  11078. THREE.Line.prototype.raycast = ( function () {
  11079. var inverseMatrix = new THREE.Matrix4();
  11080. var ray = new THREE.Ray();
  11081. var sphere = new THREE.Sphere();
  11082. return function raycast( raycaster, intersects ) {
  11083. var precision = raycaster.linePrecision;
  11084. var precisionSq = precision * precision;
  11085. var geometry = this.geometry;
  11086. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11087. // Checking boundingSphere distance to ray
  11088. sphere.copy( geometry.boundingSphere );
  11089. sphere.applyMatrix4( this.matrixWorld );
  11090. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11091. return;
  11092. }
  11093. inverseMatrix.getInverse( this.matrixWorld );
  11094. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11095. var vStart = new THREE.Vector3();
  11096. var vEnd = new THREE.Vector3();
  11097. var interSegment = new THREE.Vector3();
  11098. var interRay = new THREE.Vector3();
  11099. var step = this instanceof THREE.LineSegments ? 2 : 1;
  11100. if ( geometry instanceof THREE.BufferGeometry ) {
  11101. var index = geometry.index;
  11102. var attributes = geometry.attributes;
  11103. if ( index !== null ) {
  11104. var indices = index.array;
  11105. var positions = attributes.position.array;
  11106. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  11107. var a = indices[ i ];
  11108. var b = indices[ i + 1 ];
  11109. vStart.fromArray( positions, a * 3 );
  11110. vEnd.fromArray( positions, b * 3 );
  11111. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11112. if ( distSq > precisionSq ) continue;
  11113. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11114. var distance = raycaster.ray.origin.distanceTo( interRay );
  11115. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11116. intersects.push( {
  11117. distance: distance,
  11118. // What do we want? intersection point on the ray or on the segment??
  11119. // point: raycaster.ray.at( distance ),
  11120. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11121. index: i,
  11122. face: null,
  11123. faceIndex: null,
  11124. object: this
  11125. } );
  11126. }
  11127. } else {
  11128. var positions = attributes.position.array;
  11129. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  11130. vStart.fromArray( positions, 3 * i );
  11131. vEnd.fromArray( positions, 3 * i + 3 );
  11132. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11133. if ( distSq > precisionSq ) continue;
  11134. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11135. var distance = raycaster.ray.origin.distanceTo( interRay );
  11136. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11137. intersects.push( {
  11138. distance: distance,
  11139. // What do we want? intersection point on the ray or on the segment??
  11140. // point: raycaster.ray.at( distance ),
  11141. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11142. index: i,
  11143. face: null,
  11144. faceIndex: null,
  11145. object: this
  11146. } );
  11147. }
  11148. }
  11149. } else if ( geometry instanceof THREE.Geometry ) {
  11150. var vertices = geometry.vertices;
  11151. var nbVertices = vertices.length;
  11152. for ( var i = 0; i < nbVertices - 1; i += step ) {
  11153. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  11154. if ( distSq > precisionSq ) continue;
  11155. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11156. var distance = raycaster.ray.origin.distanceTo( interRay );
  11157. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11158. intersects.push( {
  11159. distance: distance,
  11160. // What do we want? intersection point on the ray or on the segment??
  11161. // point: raycaster.ray.at( distance ),
  11162. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11163. index: i,
  11164. face: null,
  11165. faceIndex: null,
  11166. object: this
  11167. } );
  11168. }
  11169. }
  11170. };
  11171. }() );
  11172. THREE.Line.prototype.clone = function () {
  11173. return new this.constructor( this.geometry, this.material ).copy( this );
  11174. };
  11175. THREE.Line.prototype.toJSON = function ( meta ) {
  11176. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11177. // only serialize if not in meta geometries cache
  11178. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  11179. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  11180. }
  11181. // only serialize if not in meta materials cache
  11182. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11183. meta.materials[ this.material.uuid ] = this.material.toJSON();
  11184. }
  11185. data.object.geometry = this.geometry.uuid;
  11186. data.object.material = this.material.uuid;
  11187. return data;
  11188. };
  11189. // DEPRECATED
  11190. THREE.LineStrip = 0;
  11191. THREE.LinePieces = 1;
  11192. // File:src/objects/LineSegments.js
  11193. /**
  11194. * @author mrdoob / http://mrdoob.com/
  11195. */
  11196. THREE.LineSegments = function ( geometry, material ) {
  11197. THREE.Line.call( this, geometry, material );
  11198. this.type = 'LineSegments';
  11199. };
  11200. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  11201. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  11202. // File:src/objects/Mesh.js
  11203. /**
  11204. * @author mrdoob / http://mrdoob.com/
  11205. * @author alteredq / http://alteredqualia.com/
  11206. * @author mikael emtinger / http://gomo.se/
  11207. * @author jonobr1 / http://jonobr1.com/
  11208. */
  11209. THREE.Mesh = function ( geometry, material ) {
  11210. THREE.Object3D.call( this );
  11211. this.type = 'Mesh';
  11212. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11213. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  11214. this.updateMorphTargets();
  11215. };
  11216. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  11217. THREE.Mesh.prototype.constructor = THREE.Mesh;
  11218. THREE.Mesh.prototype.updateMorphTargets = function () {
  11219. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  11220. this.morphTargetBase = - 1;
  11221. this.morphTargetInfluences = [];
  11222. this.morphTargetDictionary = {};
  11223. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  11224. this.morphTargetInfluences.push( 0 );
  11225. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  11226. }
  11227. }
  11228. };
  11229. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  11230. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  11231. return this.morphTargetDictionary[ name ];
  11232. }
  11233. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  11234. return 0;
  11235. };
  11236. THREE.Mesh.prototype.raycast = ( function () {
  11237. var inverseMatrix = new THREE.Matrix4();
  11238. var ray = new THREE.Ray();
  11239. var sphere = new THREE.Sphere();
  11240. var vA = new THREE.Vector3();
  11241. var vB = new THREE.Vector3();
  11242. var vC = new THREE.Vector3();
  11243. var tempA = new THREE.Vector3();
  11244. var tempB = new THREE.Vector3();
  11245. var tempC = new THREE.Vector3();
  11246. var uvA = new THREE.Vector2();
  11247. var uvB = new THREE.Vector2();
  11248. var uvC = new THREE.Vector2();
  11249. var barycoord = new THREE.Vector3();
  11250. var intersectionPoint = new THREE.Vector3();
  11251. var intersectionPointWorld = new THREE.Vector3();
  11252. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  11253. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  11254. uv1.multiplyScalar( barycoord.x );
  11255. uv2.multiplyScalar( barycoord.y );
  11256. uv3.multiplyScalar( barycoord.z );
  11257. uv1.add( uv2 ).add( uv3 );
  11258. return uv1.clone();
  11259. }
  11260. return function raycast( raycaster, intersects ) {
  11261. var geometry = this.geometry;
  11262. var material = this.material;
  11263. if ( material === undefined ) return;
  11264. // Checking boundingSphere distance to ray
  11265. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11266. sphere.copy( geometry.boundingSphere );
  11267. sphere.applyMatrix4( this.matrixWorld );
  11268. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11269. return;
  11270. }
  11271. // Check boundingBox before continuing
  11272. inverseMatrix.getInverse( this.matrixWorld );
  11273. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11274. if ( geometry.boundingBox !== null ) {
  11275. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  11276. return;
  11277. }
  11278. }
  11279. var a, b, c;
  11280. if ( geometry instanceof THREE.BufferGeometry ) {
  11281. var index = geometry.index;
  11282. var attributes = geometry.attributes;
  11283. if ( index !== null ) {
  11284. var indices = index.array;
  11285. var positions = attributes.position.array;
  11286. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  11287. a = indices[ i ];
  11288. b = indices[ i + 1 ];
  11289. c = indices[ i + 2 ];
  11290. vA.fromArray( positions, a * 3 );
  11291. vB.fromArray( positions, b * 3 );
  11292. vC.fromArray( positions, c * 3 );
  11293. if ( material.side === THREE.BackSide ) {
  11294. if ( ray.intersectTriangle( vC, vB, vA, true, intersectionPoint ) === null ) continue;
  11295. } else {
  11296. if ( ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11297. }
  11298. intersectionPointWorld.copy( intersectionPoint );
  11299. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11300. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11301. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11302. var uv;
  11303. if ( attributes.uv !== undefined ) {
  11304. var uvs = attributes.uv.array;
  11305. uvA.fromArray( uvs, a * 2 );
  11306. uvB.fromArray( uvs, b * 2 );
  11307. uvC.fromArray( uvs, c * 2 );
  11308. uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11309. }
  11310. intersects.push( {
  11311. distance: distance,
  11312. point: intersectionPointWorld.clone(),
  11313. uv: uv,
  11314. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  11315. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  11316. object: this
  11317. } );
  11318. }
  11319. } else {
  11320. var positions = attributes.position.array;
  11321. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  11322. vA.fromArray( positions, i );
  11323. vB.fromArray( positions, i + 3 );
  11324. vC.fromArray( positions, i + 6 );
  11325. if ( material.side === THREE.BackSide ) {
  11326. if ( ray.intersectTriangle( vC, vB, vA, true, intersectionPoint ) === null ) continue;
  11327. } else {
  11328. if ( ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11329. }
  11330. intersectionPointWorld.copy( intersectionPoint );
  11331. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11332. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11333. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11334. var uv;
  11335. if ( attributes.uv !== undefined ) {
  11336. var uvs = attributes.uv.array;
  11337. uvA.fromArray( uvs, i );
  11338. uvB.fromArray( uvs, i + 2 );
  11339. uvC.fromArray( uvs, i + 4 );
  11340. uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11341. }
  11342. a = i / 3;
  11343. b = a + 1;
  11344. c = a + 2;
  11345. intersects.push( {
  11346. distance: distance,
  11347. point: intersectionPointWorld.clone(),
  11348. uv: uv,
  11349. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  11350. index: a, // triangle number in positions buffer semantics
  11351. object: this
  11352. } );
  11353. }
  11354. }
  11355. } else if ( geometry instanceof THREE.Geometry ) {
  11356. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  11357. var materials = isFaceMaterial === true ? material.materials : null;
  11358. var vertices = geometry.vertices;
  11359. var faces = geometry.faces;
  11360. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  11361. var face = faces[ f ];
  11362. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  11363. if ( faceMaterial === undefined ) continue;
  11364. a = vertices[ face.a ];
  11365. b = vertices[ face.b ];
  11366. c = vertices[ face.c ];
  11367. if ( faceMaterial.morphTargets === true ) {
  11368. var morphTargets = geometry.morphTargets;
  11369. var morphInfluences = this.morphTargetInfluences;
  11370. vA.set( 0, 0, 0 );
  11371. vB.set( 0, 0, 0 );
  11372. vC.set( 0, 0, 0 );
  11373. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  11374. var influence = morphInfluences[ t ];
  11375. if ( influence === 0 ) continue;
  11376. var targets = morphTargets[ t ].vertices;
  11377. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  11378. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  11379. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  11380. }
  11381. vA.add( a );
  11382. vB.add( b );
  11383. vC.add( c );
  11384. a = vA;
  11385. b = vB;
  11386. c = vC;
  11387. }
  11388. if ( faceMaterial.side === THREE.BackSide ) {
  11389. if ( ray.intersectTriangle( c, b, a, true, intersectionPoint ) === null ) continue;
  11390. } else {
  11391. if ( ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11392. }
  11393. intersectionPointWorld.copy( intersectionPoint );
  11394. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11395. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11396. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11397. var uv;
  11398. if ( geometry.faceVertexUvs[ 0 ].length > 0 ) {
  11399. var uvs = geometry.faceVertexUvs[ 0 ][ f ];
  11400. uvA.copy( uvs[ 0 ] );
  11401. uvB.copy( uvs[ 1 ] );
  11402. uvC.copy( uvs[ 2 ] );
  11403. uv = uvIntersection( intersectionPoint, a, b, c, uvA, uvB, uvC );
  11404. }
  11405. intersects.push( {
  11406. distance: distance,
  11407. point: intersectionPointWorld.clone(),
  11408. uv: uv,
  11409. face: face,
  11410. faceIndex: f,
  11411. object: this
  11412. } );
  11413. }
  11414. }
  11415. };
  11416. }() );
  11417. THREE.Mesh.prototype.clone = function () {
  11418. return new this.constructor( this.geometry, this.material ).copy( this );
  11419. };
  11420. THREE.Mesh.prototype.toJSON = function ( meta ) {
  11421. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11422. // only serialize if not in meta geometries cache
  11423. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  11424. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  11425. }
  11426. // only serialize if not in meta materials cache
  11427. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11428. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  11429. }
  11430. data.object.geometry = this.geometry.uuid;
  11431. data.object.material = this.material.uuid;
  11432. return data;
  11433. };
  11434. // File:src/objects/Bone.js
  11435. /**
  11436. * @author mikael emtinger / http://gomo.se/
  11437. * @author alteredq / http://alteredqualia.com/
  11438. * @author ikerr / http://verold.com
  11439. */
  11440. THREE.Bone = function ( skin ) {
  11441. THREE.Object3D.call( this );
  11442. this.type = 'Bone';
  11443. this.skin = skin;
  11444. };
  11445. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  11446. THREE.Bone.prototype.constructor = THREE.Bone;
  11447. THREE.Bone.prototype.copy = function ( source ) {
  11448. THREE.Object3D.prototype.copy.call( this, source );
  11449. this.skin = source.skin;
  11450. return this;
  11451. };
  11452. // File:src/objects/Skeleton.js
  11453. /**
  11454. * @author mikael emtinger / http://gomo.se/
  11455. * @author alteredq / http://alteredqualia.com/
  11456. * @author michael guerrero / http://realitymeltdown.com
  11457. * @author ikerr / http://verold.com
  11458. */
  11459. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  11460. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  11461. this.identityMatrix = new THREE.Matrix4();
  11462. // copy the bone array
  11463. bones = bones || [];
  11464. this.bones = bones.slice( 0 );
  11465. // create a bone texture or an array of floats
  11466. if ( this.useVertexTexture ) {
  11467. // layout (1 matrix = 4 pixels)
  11468. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  11469. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  11470. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  11471. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  11472. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  11473. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  11474. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  11475. size = Math.max( size, 4 );
  11476. this.boneTextureWidth = size;
  11477. this.boneTextureHeight = size;
  11478. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  11479. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  11480. } else {
  11481. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  11482. }
  11483. // use the supplied bone inverses or calculate the inverses
  11484. if ( boneInverses === undefined ) {
  11485. this.calculateInverses();
  11486. } else {
  11487. if ( this.bones.length === boneInverses.length ) {
  11488. this.boneInverses = boneInverses.slice( 0 );
  11489. } else {
  11490. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  11491. this.boneInverses = [];
  11492. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11493. this.boneInverses.push( new THREE.Matrix4() );
  11494. }
  11495. }
  11496. }
  11497. };
  11498. THREE.Skeleton.prototype.calculateInverses = function () {
  11499. this.boneInverses = [];
  11500. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11501. var inverse = new THREE.Matrix4();
  11502. if ( this.bones[ b ] ) {
  11503. inverse.getInverse( this.bones[ b ].matrixWorld );
  11504. }
  11505. this.boneInverses.push( inverse );
  11506. }
  11507. };
  11508. THREE.Skeleton.prototype.pose = function () {
  11509. var bone;
  11510. // recover the bind-time world matrices
  11511. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11512. bone = this.bones[ b ];
  11513. if ( bone ) {
  11514. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  11515. }
  11516. }
  11517. // compute the local matrices, positions, rotations and scales
  11518. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11519. bone = this.bones[ b ];
  11520. if ( bone ) {
  11521. if ( bone.parent ) {
  11522. bone.matrix.getInverse( bone.parent.matrixWorld );
  11523. bone.matrix.multiply( bone.matrixWorld );
  11524. } else {
  11525. bone.matrix.copy( bone.matrixWorld );
  11526. }
  11527. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  11528. }
  11529. }
  11530. };
  11531. THREE.Skeleton.prototype.update = ( function () {
  11532. var offsetMatrix = new THREE.Matrix4();
  11533. return function update() {
  11534. // flatten bone matrices to array
  11535. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11536. // compute the offset between the current and the original transform
  11537. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  11538. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  11539. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  11540. }
  11541. if ( this.useVertexTexture ) {
  11542. this.boneTexture.needsUpdate = true;
  11543. }
  11544. };
  11545. } )();
  11546. THREE.Skeleton.prototype.clone = function () {
  11547. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  11548. };
  11549. // File:src/objects/SkinnedMesh.js
  11550. /**
  11551. * @author mikael emtinger / http://gomo.se/
  11552. * @author alteredq / http://alteredqualia.com/
  11553. * @author ikerr / http://verold.com
  11554. */
  11555. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  11556. THREE.Mesh.call( this, geometry, material );
  11557. this.type = 'SkinnedMesh';
  11558. this.bindMode = "attached";
  11559. this.bindMatrix = new THREE.Matrix4();
  11560. this.bindMatrixInverse = new THREE.Matrix4();
  11561. // init bones
  11562. // TODO: remove bone creation as there is no reason (other than
  11563. // convenience) for THREE.SkinnedMesh to do this.
  11564. var bones = [];
  11565. if ( this.geometry && this.geometry.bones !== undefined ) {
  11566. var bone, gbone;
  11567. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11568. gbone = this.geometry.bones[ b ];
  11569. bone = new THREE.Bone( this );
  11570. bones.push( bone );
  11571. bone.name = gbone.name;
  11572. bone.position.fromArray( gbone.pos );
  11573. bone.quaternion.fromArray( gbone.rotq );
  11574. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  11575. }
  11576. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11577. gbone = this.geometry.bones[ b ];
  11578. if ( gbone.parent !== - 1 ) {
  11579. bones[ gbone.parent ].add( bones[ b ] );
  11580. } else {
  11581. this.add( bones[ b ] );
  11582. }
  11583. }
  11584. }
  11585. this.normalizeSkinWeights();
  11586. this.updateMatrixWorld( true );
  11587. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  11588. };
  11589. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  11590. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  11591. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  11592. this.skeleton = skeleton;
  11593. if ( bindMatrix === undefined ) {
  11594. this.updateMatrixWorld( true );
  11595. this.skeleton.calculateInverses();
  11596. bindMatrix = this.matrixWorld;
  11597. }
  11598. this.bindMatrix.copy( bindMatrix );
  11599. this.bindMatrixInverse.getInverse( bindMatrix );
  11600. };
  11601. THREE.SkinnedMesh.prototype.pose = function () {
  11602. this.skeleton.pose();
  11603. };
  11604. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  11605. if ( this.geometry instanceof THREE.Geometry ) {
  11606. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  11607. var sw = this.geometry.skinWeights[ i ];
  11608. var scale = 1.0 / sw.lengthManhattan();
  11609. if ( scale !== Infinity ) {
  11610. sw.multiplyScalar( scale );
  11611. } else {
  11612. sw.set( 1 ); // this will be normalized by the shader anyway
  11613. }
  11614. }
  11615. } else {
  11616. // skinning weights assumed to be normalized for THREE.BufferGeometry
  11617. }
  11618. };
  11619. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  11620. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  11621. if ( this.bindMode === "attached" ) {
  11622. this.bindMatrixInverse.getInverse( this.matrixWorld );
  11623. } else if ( this.bindMode === "detached" ) {
  11624. this.bindMatrixInverse.getInverse( this.bindMatrix );
  11625. } else {
  11626. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  11627. }
  11628. };
  11629. THREE.SkinnedMesh.prototype.clone = function() {
  11630. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  11631. };
  11632. // File:src/objects/LOD.js
  11633. /**
  11634. * @author mikael emtinger / http://gomo.se/
  11635. * @author alteredq / http://alteredqualia.com/
  11636. * @author mrdoob / http://mrdoob.com/
  11637. */
  11638. THREE.LOD = function () {
  11639. THREE.Object3D.call( this );
  11640. this.type = 'LOD';
  11641. Object.defineProperties( this, {
  11642. levels: {
  11643. enumerable: true,
  11644. value: []
  11645. },
  11646. objects: {
  11647. get: function () {
  11648. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  11649. return this.levels;
  11650. }
  11651. }
  11652. } );
  11653. };
  11654. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  11655. THREE.LOD.prototype.constructor = THREE.LOD;
  11656. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  11657. if ( distance === undefined ) distance = 0;
  11658. distance = Math.abs( distance );
  11659. var levels = this.levels;
  11660. for ( var l = 0; l < levels.length; l ++ ) {
  11661. if ( distance < levels[ l ].distance ) {
  11662. break;
  11663. }
  11664. }
  11665. levels.splice( l, 0, { distance: distance, object: object } );
  11666. this.add( object );
  11667. };
  11668. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  11669. var levels = this.levels;
  11670. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11671. if ( distance < levels[ i ].distance ) {
  11672. break;
  11673. }
  11674. }
  11675. return levels[ i - 1 ].object;
  11676. };
  11677. THREE.LOD.prototype.raycast = ( function () {
  11678. var matrixPosition = new THREE.Vector3();
  11679. return function raycast( raycaster, intersects ) {
  11680. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11681. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  11682. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  11683. };
  11684. }() );
  11685. THREE.LOD.prototype.update = function () {
  11686. var v1 = new THREE.Vector3();
  11687. var v2 = new THREE.Vector3();
  11688. return function update( camera ) {
  11689. var levels = this.levels;
  11690. if ( levels.length > 1 ) {
  11691. v1.setFromMatrixPosition( camera.matrixWorld );
  11692. v2.setFromMatrixPosition( this.matrixWorld );
  11693. var distance = v1.distanceTo( v2 );
  11694. levels[ 0 ].object.visible = true;
  11695. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11696. if ( distance >= levels[ i ].distance ) {
  11697. levels[ i - 1 ].object.visible = false;
  11698. levels[ i ].object.visible = true;
  11699. } else {
  11700. break;
  11701. }
  11702. }
  11703. for ( ; i < l; i ++ ) {
  11704. levels[ i ].object.visible = false;
  11705. }
  11706. }
  11707. };
  11708. }();
  11709. THREE.LOD.prototype.copy = function ( source ) {
  11710. THREE.Object3D.prototype.copy.call( this, source, false );
  11711. var levels = source.levels;
  11712. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11713. var level = levels[ i ];
  11714. this.addLevel( level.object.clone(), level.distance );
  11715. }
  11716. return this;
  11717. };
  11718. THREE.LOD.prototype.toJSON = function ( meta ) {
  11719. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11720. data.object.levels = [];
  11721. var levels = this.levels;
  11722. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11723. var level = levels[ i ];
  11724. data.object.levels.push( {
  11725. object: level.object.uuid,
  11726. distance: level.distance
  11727. } );
  11728. }
  11729. return data;
  11730. };
  11731. // File:src/objects/Sprite.js
  11732. /**
  11733. * @author mikael emtinger / http://gomo.se/
  11734. * @author alteredq / http://alteredqualia.com/
  11735. */
  11736. THREE.Sprite = ( function () {
  11737. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  11738. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  11739. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  11740. var geometry = new THREE.BufferGeometry();
  11741. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  11742. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  11743. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  11744. return function Sprite( material ) {
  11745. THREE.Object3D.call( this );
  11746. this.type = 'Sprite';
  11747. this.geometry = geometry;
  11748. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  11749. };
  11750. } )();
  11751. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  11752. THREE.Sprite.prototype.constructor = THREE.Sprite;
  11753. THREE.Sprite.prototype.raycast = ( function () {
  11754. var matrixPosition = new THREE.Vector3();
  11755. return function raycast( raycaster, intersects ) {
  11756. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11757. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  11758. var guessSizeSq = this.scale.x * this.scale.y;
  11759. if ( distanceSq > guessSizeSq ) {
  11760. return;
  11761. }
  11762. intersects.push( {
  11763. distance: Math.sqrt( distanceSq ),
  11764. point: this.position,
  11765. face: null,
  11766. object: this
  11767. } );
  11768. };
  11769. }() );
  11770. THREE.Sprite.prototype.clone = function () {
  11771. return new this.constructor( this.material ).copy( this );
  11772. };
  11773. THREE.Sprite.prototype.toJSON = function ( meta ) {
  11774. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11775. // only serialize if not in meta materials cache
  11776. if ( meta.materials[ this.material.uuid ] === undefined ) {
  11777. meta.materials[ this.material.uuid ] = this.material.toJSON();
  11778. }
  11779. data.object.material = this.material.uuid;
  11780. return data;
  11781. };
  11782. // Backwards compatibility
  11783. THREE.Particle = THREE.Sprite;
  11784. // File:src/objects/LensFlare.js
  11785. /**
  11786. * @author mikael emtinger / http://gomo.se/
  11787. * @author alteredq / http://alteredqualia.com/
  11788. */
  11789. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  11790. THREE.Object3D.call( this );
  11791. this.lensFlares = [];
  11792. this.positionScreen = new THREE.Vector3();
  11793. this.customUpdateCallback = undefined;
  11794. if ( texture !== undefined ) {
  11795. this.add( texture, size, distance, blending, color );
  11796. }
  11797. };
  11798. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  11799. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  11800. /*
  11801. * Add: adds another flare
  11802. */
  11803. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  11804. if ( size === undefined ) size = - 1;
  11805. if ( distance === undefined ) distance = 0;
  11806. if ( opacity === undefined ) opacity = 1;
  11807. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  11808. if ( blending === undefined ) blending = THREE.NormalBlending;
  11809. distance = Math.min( distance, Math.max( 0, distance ) );
  11810. this.lensFlares.push( {
  11811. texture: texture, // THREE.Texture
  11812. size: size, // size in pixels (-1 = use texture.width)
  11813. distance: distance, // distance (0-1) from light source (0=at light source)
  11814. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  11815. scale: 1, // scale
  11816. rotation: 0, // rotation
  11817. opacity: opacity, // opacity
  11818. color: color, // color
  11819. blending: blending // blending
  11820. } );
  11821. };
  11822. /*
  11823. * Update lens flares update positions on all flares based on the screen position
  11824. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  11825. */
  11826. THREE.LensFlare.prototype.updateLensFlares = function () {
  11827. var f, fl = this.lensFlares.length;
  11828. var flare;
  11829. var vecX = - this.positionScreen.x * 2;
  11830. var vecY = - this.positionScreen.y * 2;
  11831. for ( f = 0; f < fl; f ++ ) {
  11832. flare = this.lensFlares[ f ];
  11833. flare.x = this.positionScreen.x + vecX * flare.distance;
  11834. flare.y = this.positionScreen.y + vecY * flare.distance;
  11835. flare.wantedRotation = flare.x * Math.PI * 0.25;
  11836. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  11837. }
  11838. };
  11839. THREE.LensFlare.prototype.copy = function ( source ) {
  11840. THREE.Object3D.prototype.copy.call( this, source );
  11841. this.positionScreen.copy( source.positionScreen );
  11842. this.customUpdateCallback = source.customUpdateCallback;
  11843. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  11844. this.lensFlares.push( source.lensFlares[ i ] );
  11845. }
  11846. return this;
  11847. };
  11848. // File:src/scenes/Scene.js
  11849. /**
  11850. * @author mrdoob / http://mrdoob.com/
  11851. */
  11852. THREE.Scene = function () {
  11853. THREE.Object3D.call( this );
  11854. this.type = 'Scene';
  11855. this.fog = null;
  11856. this.overrideMaterial = null;
  11857. this.autoUpdate = true; // checked by the renderer
  11858. };
  11859. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  11860. THREE.Scene.prototype.constructor = THREE.Scene;
  11861. THREE.Scene.prototype.copy = function ( source ) {
  11862. THREE.Object3D.prototype.copy.call( this, source );
  11863. if ( source.fog !== null ) this.fog = source.fog.clone();
  11864. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  11865. this.autoUpdate = source.autoUpdate;
  11866. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11867. return this;
  11868. };
  11869. // File:src/scenes/Fog.js
  11870. /**
  11871. * @author mrdoob / http://mrdoob.com/
  11872. * @author alteredq / http://alteredqualia.com/
  11873. */
  11874. THREE.Fog = function ( color, near, far ) {
  11875. this.name = '';
  11876. this.color = new THREE.Color( color );
  11877. this.near = ( near !== undefined ) ? near : 1;
  11878. this.far = ( far !== undefined ) ? far : 1000;
  11879. };
  11880. THREE.Fog.prototype.clone = function () {
  11881. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  11882. };
  11883. // File:src/scenes/FogExp2.js
  11884. /**
  11885. * @author mrdoob / http://mrdoob.com/
  11886. * @author alteredq / http://alteredqualia.com/
  11887. */
  11888. THREE.FogExp2 = function ( color, density ) {
  11889. this.name = '';
  11890. this.color = new THREE.Color( color );
  11891. this.density = ( density !== undefined ) ? density : 0.00025;
  11892. };
  11893. THREE.FogExp2.prototype.clone = function () {
  11894. return new THREE.FogExp2( this.color.getHex(), this.density );
  11895. };
  11896. // File:src/renderers/shaders/ShaderChunk.js
  11897. THREE.ShaderChunk = {};
  11898. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  11899. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  11900. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  11901. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  11902. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  11903. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  11904. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  11905. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  11906. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  11907. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  11908. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  11909. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  11910. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  11911. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  11912. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  11913. THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n // Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\n // http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n\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\n return vec2( dBx, dBy );\n\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm; // normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 );\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n\n }\n\n#endif\n";
  11914. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  11915. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  11916. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  11917. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  11918. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  11919. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  11920. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  11921. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  11922. // File:src/renderers/shaders/ShaderChunk/common.glsl
  11923. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\n\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n\n}\n\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n\n}\n\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n float distance = dot( planeNormal, point - pointOnPlane );\n\n return - distance * planeNormal + point;\n\n}\n\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return sign( dot( point - pointOnPlane, planeNormal ) );\n\n}\n\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n\n}\n\nfloat calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {\n\n if ( decayExponent > 0.0 ) {\n\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\n }\n\n return 1.0;\n\n}\n\nvec3 F_Schlick( in vec3 specularColor, in float dotLH ) {\n\n // Original approximation by Christophe Schlick '94\n //;float fresnel = pow( 1.0 - dotLH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n float fresnel = exp2( ( -5.55437 * dotLH - 6.98316 ) * dotLH );\n\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n\n}\n\nfloat G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {\n\n // geometry term is (n⋅l)(n⋅v) / 4(n⋅l)(n⋅v)\n\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\n // factor of 1/PI in distribution term omitted\n\n return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal, in vec3 lightDir, in vec3 viewDir ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n //float dotNL = saturate( dot( normal, lightDir ) );\n //float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( lightDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, dotLH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * G * D;\n\n}\n\nvec3 inputToLinear( in vec3 a ) {\n\n #ifdef GAMMA_INPUT\n\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n\nvec3 linearToOutput( in vec3 a ) {\n\n #ifdef GAMMA_OUTPUT\n\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n";
  11924. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  11925. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  11926. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  11927. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n\n#endif\n";
  11928. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  11929. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n\n#endif\n";
  11930. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  11931. THREE.ShaderChunk[ 'emissivemap_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n\n emissiveColor.rgb = inputToLinear( emissiveColor.rgb );\n\n totalEmissiveLight *= emissiveColor.rgb;\n\n#endif\n";
  11932. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  11933. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  11934. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  11935. THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\n // Transforming Normal Vectors with the Inverse Transformation\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n #else\n\n vec3 reflectVec = vReflect;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\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\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\n envColor.xyz = inputToLinear( envColor.xyz );\n\n #ifdef ENVMAP_BLENDING_MULTIPLY\n\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_MIX )\n\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_ADD )\n\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n\n #endif\n\n#endif\n";
  11936. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  11937. THREE.ShaderChunk[ 'envmap_pars_fragment'] = "#ifdef USE_ENVMAP\n\n uniform float reflectivity;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n uniform float refractionRatio;\n\n #else\n\n varying vec3 vReflect;\n\n #endif\n\n#endif\n";
  11938. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  11939. THREE.ShaderChunk[ 'envmap_pars_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n varying vec3 vReflect;\n\n uniform float refractionRatio;\n\n#endif\n";
  11940. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  11941. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vReflect = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n#endif\n";
  11942. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  11943. THREE.ShaderChunk[ 'fog_fragment'] = "#ifdef USE_FOG\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n\n #else\n\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n\n #endif\n\n #ifdef FOG_EXP2\n\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n\n #else\n\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n\n #endif\n \n outgoingLight = mix( outgoingLight, fogColor, fogFactor );\n\n#endif";
  11944. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  11945. THREE.ShaderChunk[ 'fog_pars_fragment'] = "#ifdef USE_FOG\n\n uniform vec3 fogColor;\n\n #ifdef FOG_EXP2\n\n uniform float fogDensity;\n\n #else\n\n uniform float fogNear;\n uniform float fogFar;\n #endif\n\n#endif";
  11946. // File:src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl
  11947. THREE.ShaderChunk[ 'hemilight_fragment'] = "#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 lightColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n totalAmbientLight += lightColor;\n\n }\n\n#endif\n\n";
  11948. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  11949. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  11950. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  11951. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  11952. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  11953. THREE.ShaderChunk[ 'lights_lambert_pars_vertex'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n";
  11954. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  11955. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\nvec3 normal = normalize( transformedNormal );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lVector = pointLightPosition[ i ] - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec3 lVector = lightPosition - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = directionalLightDirection[ i ];\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n float hemiDiffuseWeightBack = - 0.5 * dotProduct + 0.5;\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n\nvLightFront += ambientLightColor;\n\n#ifdef DOUBLE_SIDED\n\n vLightBack += ambientLightColor;\n\n#endif\n";
  11956. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  11957. THREE.ShaderChunk[ 'lights_phong_fragment'] = "vec3 viewDir = normalize( vViewPosition );\n\nvec3 totalDiffuseLight = vec3( 0.0 );\nvec3 totalSpecularLight = vec3( 0.0 );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lightPosition = pointLightPosition[ i ];\n vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = directionalLightDirection[ i ];\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n\n#ifdef METAL\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;\n\n#else\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;\n\n#endif\n";
  11958. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  11959. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n";
  11960. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  11961. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n\n#endif\n";
  11962. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  11963. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif\n";
  11964. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  11965. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  11966. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  11967. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  11968. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  11969. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n#endif\n";
  11970. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  11971. THREE.ShaderChunk[ 'logdepthbuf_pars_vertex'] = "#ifdef USE_LOGDEPTHBUF\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n uniform float logDepthBufFC;\n\n#endif";
  11972. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  11973. THREE.ShaderChunk[ 'logdepthbuf_vertex'] = "#ifdef USE_LOGDEPTHBUF\n\n gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n vFragDepth = 1.0 + gl_Position.w;\n\n#else\n\n gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n\n #endif\n\n#endif";
  11974. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  11975. THREE.ShaderChunk[ 'map_fragment'] = "#ifdef USE_MAP\n\n vec4 texelColor = texture2D( map, vUv );\n\n texelColor.xyz = inputToLinear( texelColor.xyz );\n\n diffuseColor *= texelColor;\n\n#endif\n";
  11976. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  11977. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  11978. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  11979. THREE.ShaderChunk[ 'map_particle_fragment'] = "#ifdef USE_MAP\n\n diffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n\n#endif\n";
  11980. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  11981. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  11982. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  11983. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\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\n#endif\n";
  11984. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  11985. THREE.ShaderChunk[ 'morphtarget_pars_vertex'] = "#ifdef USE_MORPHTARGETS\n\n #ifndef USE_MORPHNORMALS\n\n uniform float morphTargetInfluences[ 8 ];\n\n #else\n\n uniform float morphTargetInfluences[ 4 ];\n\n #endif\n\n#endif";
  11986. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  11987. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\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\n #ifndef USE_MORPHNORMALS\n\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\n #endif\n\n#endif\n";
  11988. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  11989. THREE.ShaderChunk[ 'normal_phong_fragment'] = "#ifndef FLAT_SHADED\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n #endif\n\n#else\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\n";
  11990. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  11991. THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n // Per-Pixel Tangent Space Normal Mapping\n // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\n\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\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\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\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 }\n\n#endif\n";
  11992. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  11993. THREE.ShaderChunk[ 'project_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  11994. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  11995. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n #ifdef SHADOWMAP_DEBUG\n\n vec3 frustumColors[3];\n frustumColors[0] = vec3( 1.0, 0.5, 0.0 );\n frustumColors[1] = vec3( 0.0, 1.0, 0.8 );\n frustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n\n #endif\n\n float fDepth;\n vec3 shadowColor = vec3( 1.0 );\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n // to save on uniform space, we use the sign of @shadowDarkness[ i ] to determine\n // whether or not this light is a point light ( shadowDarkness[ i ] < 0 == point light)\n bool isPointLight = shadowDarkness[ i ] < 0.0;\n\n // get the real shadow darkness\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n\n // for point lights, the uniform @vShadowCoord is re-purposed to hold\n // the distance from the light to the world-space position of the fragment.\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n\n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n float shadow = 0.0;\n\n // if ( something && something ) breaks ATI OpenGL shader compiler\n // if ( all( something, something ) ) using this instead\n\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\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest || isPointLight ) { \n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n if( isPointLight ) {\n\n // bd3D = base direction 3D\n vec3 bd3D = normalize( lightToPosition );\n // dp = distance from light to fragment position\n float dp = length( lightToPosition );\n\n shadow = 0.0; \n\n // base measurement\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n // dr = disk radius\n const float dr = 1.25;\n // os = offset scale\n float os = dr * 2.0 * texelSizeY;\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd0 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd1 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd2 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd3 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd4 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd5 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd6 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd7 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd8 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd9 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd10 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd11 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd12 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd13 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd14 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd15 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd16 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd17 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd18 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd19 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadow /= 21.0;\n\n } else {\n\n #endif\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n \n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n }\n shadow /= 9.0;\n */\n\n shadowCoord.z += shadowBias[ i ];\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n\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\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n }\n\n #endif\n\n shadowColor = shadowColor * vec3( ( 1.0 - realShadowDarkness * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n if( isPointLight ) {\n\n // bd3D = base direction 3D\n vec3 bd3D = normalize( lightToPosition );\n // dp = distance from light to fragment position\n float dp = length( lightToPosition );\n\n shadow = 0.0; \n\n // base measurement\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n // dr = disk radius\n const float dr = 2.25;\n // os = offset scale\n float os = dr * 2.0 * texelSizeY;\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd0 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd1 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd2 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd3 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd4 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd5 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd6 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd7 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd8 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd9 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd10 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd11 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd12 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd13 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd14 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd15 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd16 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd17 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd18 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + gsd19 * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadow /= 21.0;\n\n } else {\n\n #endif\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n shadowCoord.z += shadowBias[ i ];\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n\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\n mat3 shadowKernel;\n mat3 depthKernel;\n\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\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));\n shadowKernel[0] *= vec3(0.25);\n\n shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));\n shadowKernel[1] *= vec3(0.25);\n\n shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));\n shadowKernel[2] *= vec3(0.25);\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );\n\n shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );\n shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );\n\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\n shadow = dot( shadowValues, vec4( 1.0 ) );\n\n #if defined(POINT_LIGHT_SHADOWS)\n \n }\n\n #endif\n\n shadowColor = shadowColor * vec3( ( 1.0 - realShadowDarkness * shadow ) );\n\n #else\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n if( isPointLight ) {\n\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n\n float shadow = 0.0;\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadowColor = shadowColor * vec3( 1.0 - realShadowDarkness * shadow );\n\n } else {\n\n #endif\n shadowCoord.z += shadowBias[ i ];\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n\n // spot with multiple shadows is darker\n\n shadowColor = shadowColor * vec3( 1.0 - realShadowDarkness );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( realShadowDarkness ) );\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n }\n\n #endif\n\n #endif\n\n }\n\n\n #ifdef SHADOWMAP_DEBUG\n\n if ( inFrustum ) outgoingLight *= frustumColors[ i ];\n\n #endif\n\n }\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  11996. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  11997. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\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 }\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n // adjustShadowValue1K() upacks the depth value stored in @textureData, adds @bias to it, and then\n // comapres the result with @testDepth. If @testDepth is larger than or equal to that result, then\n // @shadowValue is incremented by 1.0.\n\n void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {\n\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 }\n\n // cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D\n // vector suitable for 2D texture mapping. This code uses the following layout for the\n // 2D texture:\n //\n // xzXZ\n // y Y\n //\n // Y - Positive y direction\n // y - Negative y direction\n // X - Positive x direction\n // x - Negative x direction\n // Z - Positive z direction\n // z - Negative z direction\n //\n // Source and test bed:\n // https://gist.github.com/tschw/da10c43c467ce8afd0c4\n\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n\n // Number of texels to avoid at the edge of each square\n\n vec3 absV = abs( v );\n\n // Intersect unit cube\n\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n\n // Apply scale to avoid seams\n\n // two texels less per square (one texel will do for NEAREST)\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\n // Unwrap\n\n // space: -1 ... 1 range for each square\n //\n // #X## dim := ( 4 , 2 )\n // # # center := ( 1 , 1 )\n\n vec2 planar = v.xy;\n\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n\n if ( absV.z >= almostOne ) {\n\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n\n } else if ( absV.x >= almostOne ) {\n\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n\n } else if ( absV.y >= almostOne ) {\n\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 }\n\n // Transform to UV space\n\n // scale := 0.5 / dim\n // translate := ( center + 0.5 ) / dim\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\n }\n\n // gsdXX = grid sampling disk XX\n // these values are used when rendering PCF shadow maps for point lights\n \n const vec3 gsd0 = vec3( 1, 1, 1 );\n const vec3 gsd1 = vec3( 1, - 1, 1 );\n const vec3 gsd2 = vec3( - 1, - 1, 1 );\n const vec3 gsd3 = vec3( - 1, 1, 1 );\n const vec3 gsd4 = vec3( 1, 1, - 1 );\n const vec3 gsd5 = vec3( 1, - 1, - 1 );\n const vec3 gsd6 = vec3( - 1, - 1, - 1 );\n const vec3 gsd7 = vec3( -1, 1, - 1 );\n const vec3 gsd8 = vec3( 1, 1, 0 );\n const vec3 gsd9 = vec3( 1, - 1, 0 );\n const vec3 gsd10 = vec3( - 1, - 1, 0 );\n const vec3 gsd11 = vec3( - 1, 1, 0 );\n const vec3 gsd12 = vec3( 1, 0, 1 );\n const vec3 gsd13 = vec3( - 1, 0, 1 );\n const vec3 gsd14 = vec3( 1, 0, - 1 );\n const vec3 gsd15 = vec3( - 1, 0, - 1 );\n const vec3 gsd16 = vec3( 0, 1, 1 );\n const vec3 gsd17 = vec3( 0, - 1, 1 );\n const vec3 gsd18 = vec3( 0, - 1, - 1 );\n const vec3 gsd19 = vec3( 0, 1, - 1 );\n\n #endif\n\n#endif\n";
  11998. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  11999. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n#endif";
  12000. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  12001. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n // if shadowDarkness[ i ] < 0.0, that means we have a point light with a cube\n // shadow map\n if( shadowDarkness[ i ] < 0.0 ) {\n\n // calculate vector from light to vertex in view space\n\n vec3 fromLight = mvPosition.xyz - pointLightPosition[ i ];\n\n // Transform 'fromLight' into world space by multiplying it on the left\n // side of 'viewMatrix'. This is equivalent to multiplying it on the right\n // side of the transpose of 'viewMatrix'. Since 'viewMatrix' is orthogonal, \n // its transpose is the same as its inverse.\n\n fromLight = fromLight * mat3( viewMatrix );\n\n // We repurpose vShadowCoord to hold the distance in world space from the\n // light to the vertex. This value will be interpolated correctly in the fragment shader.\n\n vShadowCoord[ i ] = vec4( fromLight, 1.0 );\n\n } else {\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n }\n\n #else\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n #endif\n\n }\n\n#endif";
  12002. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  12003. THREE.ShaderChunk[ 'skinbase_vertex'] = "#ifdef USE_SKINNING\n\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\n#endif";
  12004. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  12005. THREE.ShaderChunk[ 'skinning_pars_vertex'] = "#ifdef USE_SKINNING\n\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n\n #ifdef BONE_TEXTURE\n\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n\n mat4 getBoneMatrix( const in float i ) {\n\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n\n y = dy * ( y + 0.5 );\n\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\n mat4 bone = mat4( v1, v2, v3, v4 );\n\n return bone;\n\n }\n\n #else\n\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n\n mat4 getBoneMatrix( const in float i ) {\n\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n\n }\n\n #endif\n\n#endif\n";
  12006. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  12007. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\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\n#endif\n";
  12008. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  12009. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\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\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\n#endif\n";
  12010. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  12011. THREE.ShaderChunk[ 'specularmap_fragment'] = "float specularStrength;\n\n#ifdef USE_SPECULARMAP\n\n vec4 texelSpecular = texture2D( specularMap, vUv );\n specularStrength = texelSpecular.r;\n\n#else\n\n specularStrength = 1.0;\n\n#endif";
  12012. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  12013. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  12014. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  12015. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  12016. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  12017. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  12018. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  12019. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  12020. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  12021. THREE.ShaderChunk[ 'uv_pars_fragment'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )\n\n varying vec2 vUv;\n\n#endif";
  12022. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  12023. THREE.ShaderChunk[ 'uv_pars_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )\n\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n\n#endif\n";
  12024. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  12025. THREE.ShaderChunk[ 'uv_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )\n\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n\n#endif";
  12026. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  12027. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n\n #endif\n\n#endif\n";
  12028. // File:src/renderers/shaders/UniformsUtils.js
  12029. /**
  12030. * Uniform Utilities
  12031. */
  12032. THREE.UniformsUtils = {
  12033. merge: function ( uniforms ) {
  12034. var merged = {};
  12035. for ( var u = 0; u < uniforms.length; u ++ ) {
  12036. var tmp = this.clone( uniforms[ u ] );
  12037. for ( var p in tmp ) {
  12038. merged[ p ] = tmp[ p ];
  12039. }
  12040. }
  12041. return merged;
  12042. },
  12043. clone: function ( uniforms_src ) {
  12044. var uniforms_dst = {};
  12045. for ( var u in uniforms_src ) {
  12046. uniforms_dst[ u ] = {};
  12047. for ( var p in uniforms_src[ u ] ) {
  12048. var parameter_src = uniforms_src[ u ][ p ];
  12049. if ( parameter_src instanceof THREE.Color ||
  12050. parameter_src instanceof THREE.Vector2 ||
  12051. parameter_src instanceof THREE.Vector3 ||
  12052. parameter_src instanceof THREE.Vector4 ||
  12053. parameter_src instanceof THREE.Matrix3 ||
  12054. parameter_src instanceof THREE.Matrix4 ||
  12055. parameter_src instanceof THREE.Texture ) {
  12056. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12057. } else if ( Array.isArray( parameter_src ) ) {
  12058. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12059. } else {
  12060. uniforms_dst[ u ][ p ] = parameter_src;
  12061. }
  12062. }
  12063. }
  12064. return uniforms_dst;
  12065. }
  12066. };
  12067. // File:src/renderers/shaders/UniformsLib.js
  12068. /**
  12069. * Uniforms library for shared webgl shaders
  12070. */
  12071. THREE.UniformsLib = {
  12072. common: {
  12073. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12074. "opacity" : { type: "f", value: 1.0 },
  12075. "map" : { type: "t", value: null },
  12076. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12077. "specularMap" : { type: "t", value: null },
  12078. "alphaMap" : { type: "t", value: null },
  12079. "envMap" : { type: "t", value: null },
  12080. "flipEnvMap" : { type: "f", value: - 1 },
  12081. "reflectivity" : { type: "f", value: 1.0 },
  12082. "refractionRatio" : { type: "f", value: 0.98 }
  12083. },
  12084. aomap: {
  12085. "aoMap" : { type: "t", value: null },
  12086. "aoMapIntensity" : { type: "f", value: 1 },
  12087. },
  12088. lightmap: {
  12089. "lightMap" : { type: "t", value: null },
  12090. "lightMapIntensity" : { type: "f", value: 1 },
  12091. },
  12092. emissivemap: {
  12093. "emissiveMap" : { type: "t", value: null },
  12094. },
  12095. bumpmap: {
  12096. "bumpMap" : { type: "t", value: null },
  12097. "bumpScale" : { type: "f", value: 1 }
  12098. },
  12099. normalmap: {
  12100. "normalMap" : { type: "t", value: null },
  12101. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  12102. },
  12103. displacementmap: {
  12104. "displacementMap" : { type: "t", value: null },
  12105. "displacementScale" : { type: "f", value: 1 },
  12106. "displacementBias" : { type: "f", value: 0 }
  12107. },
  12108. fog : {
  12109. "fogDensity" : { type: "f", value: 0.00025 },
  12110. "fogNear" : { type: "f", value: 1 },
  12111. "fogFar" : { type: "f", value: 2000 },
  12112. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12113. },
  12114. lights: {
  12115. "ambientLightColor" : { type: "fv", value: [] },
  12116. "directionalLightDirection" : { type: "fv", value: [] },
  12117. "directionalLightColor" : { type: "fv", value: [] },
  12118. "hemisphereLightDirection" : { type: "fv", value: [] },
  12119. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  12120. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  12121. "pointLightColor" : { type: "fv", value: [] },
  12122. "pointLightPosition" : { type: "fv", value: [] },
  12123. "pointLightDistance" : { type: "fv1", value: [] },
  12124. "pointLightDecay" : { type: "fv1", value: [] },
  12125. "spotLightColor" : { type: "fv", value: [] },
  12126. "spotLightPosition" : { type: "fv", value: [] },
  12127. "spotLightDirection" : { type: "fv", value: [] },
  12128. "spotLightDistance" : { type: "fv1", value: [] },
  12129. "spotLightAngleCos" : { type: "fv1", value: [] },
  12130. "spotLightExponent" : { type: "fv1", value: [] },
  12131. "spotLightDecay" : { type: "fv1", value: [] }
  12132. },
  12133. points: {
  12134. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12135. "opacity" : { type: "f", value: 1.0 },
  12136. "size" : { type: "f", value: 1.0 },
  12137. "scale" : { type: "f", value: 1.0 },
  12138. "map" : { type: "t", value: null },
  12139. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12140. "fogDensity" : { type: "f", value: 0.00025 },
  12141. "fogNear" : { type: "f", value: 1 },
  12142. "fogFar" : { type: "f", value: 2000 },
  12143. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12144. },
  12145. shadowmap: {
  12146. "shadowMap": { type: "tv", value: [] },
  12147. "shadowMapSize": { type: "v2v", value: [] },
  12148. "shadowBias" : { type: "fv1", value: [] },
  12149. "shadowDarkness": { type: "fv1", value: [] },
  12150. "shadowMatrix" : { type: "m4v", value: [] }
  12151. }
  12152. };
  12153. // File:src/renderers/shaders/ShaderLib.js
  12154. /**
  12155. * Webgl Shader Library for three.js
  12156. *
  12157. * @author alteredq / http://alteredqualia.com/
  12158. * @author mrdoob / http://mrdoob.com/
  12159. * @author mikael emtinger / http://gomo.se/
  12160. */
  12161. THREE.ShaderLib = {
  12162. 'basic': {
  12163. uniforms: THREE.UniformsUtils.merge( [
  12164. THREE.UniformsLib[ "common" ],
  12165. THREE.UniformsLib[ "aomap" ],
  12166. THREE.UniformsLib[ "fog" ],
  12167. THREE.UniformsLib[ "shadowmap" ]
  12168. ] ),
  12169. vertexShader: [
  12170. THREE.ShaderChunk[ "common" ],
  12171. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12172. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12173. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12174. THREE.ShaderChunk[ "color_pars_vertex" ],
  12175. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12176. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12177. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12178. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12179. "void main() {",
  12180. THREE.ShaderChunk[ "uv_vertex" ],
  12181. THREE.ShaderChunk[ "uv2_vertex" ],
  12182. THREE.ShaderChunk[ "color_vertex" ],
  12183. THREE.ShaderChunk[ "skinbase_vertex" ],
  12184. " #ifdef USE_ENVMAP",
  12185. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12186. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12187. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12188. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12189. " #endif",
  12190. THREE.ShaderChunk[ "begin_vertex" ],
  12191. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12192. THREE.ShaderChunk[ "skinning_vertex" ],
  12193. THREE.ShaderChunk[ "project_vertex" ],
  12194. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12195. THREE.ShaderChunk[ "worldpos_vertex" ],
  12196. THREE.ShaderChunk[ "envmap_vertex" ],
  12197. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12198. "}"
  12199. ].join( "\n" ),
  12200. fragmentShader: [
  12201. "uniform vec3 diffuse;",
  12202. "uniform float opacity;",
  12203. THREE.ShaderChunk[ "common" ],
  12204. THREE.ShaderChunk[ "color_pars_fragment" ],
  12205. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12206. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12207. THREE.ShaderChunk[ "map_pars_fragment" ],
  12208. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12209. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12210. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12211. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12212. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12213. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12214. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12215. "void main() {",
  12216. " vec3 outgoingLight = vec3( 0.0 );",
  12217. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12218. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  12219. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12220. THREE.ShaderChunk[ "map_fragment" ],
  12221. THREE.ShaderChunk[ "color_fragment" ],
  12222. THREE.ShaderChunk[ "alphamap_fragment" ],
  12223. THREE.ShaderChunk[ "alphatest_fragment" ],
  12224. THREE.ShaderChunk[ "specularmap_fragment" ],
  12225. THREE.ShaderChunk[ "aomap_fragment" ],
  12226. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  12227. THREE.ShaderChunk[ "envmap_fragment" ],
  12228. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  12229. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12230. THREE.ShaderChunk[ "fog_fragment" ],
  12231. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12232. "}"
  12233. ].join( "\n" )
  12234. },
  12235. 'lambert': {
  12236. uniforms: THREE.UniformsUtils.merge( [
  12237. THREE.UniformsLib[ "common" ],
  12238. THREE.UniformsLib[ "fog" ],
  12239. THREE.UniformsLib[ "lights" ],
  12240. THREE.UniformsLib[ "shadowmap" ],
  12241. {
  12242. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  12243. }
  12244. ] ),
  12245. vertexShader: [
  12246. "#define LAMBERT",
  12247. "varying vec3 vLightFront;",
  12248. "#ifdef DOUBLE_SIDED",
  12249. " varying vec3 vLightBack;",
  12250. "#endif",
  12251. THREE.ShaderChunk[ "common" ],
  12252. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12253. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12254. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12255. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  12256. THREE.ShaderChunk[ "color_pars_vertex" ],
  12257. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12258. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12259. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12260. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12261. "void main() {",
  12262. THREE.ShaderChunk[ "uv_vertex" ],
  12263. THREE.ShaderChunk[ "uv2_vertex" ],
  12264. THREE.ShaderChunk[ "color_vertex" ],
  12265. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12266. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12267. THREE.ShaderChunk[ "skinbase_vertex" ],
  12268. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12269. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12270. THREE.ShaderChunk[ "begin_vertex" ],
  12271. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12272. THREE.ShaderChunk[ "skinning_vertex" ],
  12273. THREE.ShaderChunk[ "project_vertex" ],
  12274. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12275. THREE.ShaderChunk[ "worldpos_vertex" ],
  12276. THREE.ShaderChunk[ "envmap_vertex" ],
  12277. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  12278. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12279. "}"
  12280. ].join( "\n" ),
  12281. fragmentShader: [
  12282. "uniform vec3 diffuse;",
  12283. "uniform vec3 emissive;",
  12284. "uniform float opacity;",
  12285. "varying vec3 vLightFront;",
  12286. "#ifdef DOUBLE_SIDED",
  12287. " varying vec3 vLightBack;",
  12288. "#endif",
  12289. THREE.ShaderChunk[ "common" ],
  12290. THREE.ShaderChunk[ "color_pars_fragment" ],
  12291. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12292. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12293. THREE.ShaderChunk[ "map_pars_fragment" ],
  12294. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12295. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12296. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12297. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12298. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12299. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12300. "void main() {",
  12301. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  12302. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12303. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12304. THREE.ShaderChunk[ "map_fragment" ],
  12305. THREE.ShaderChunk[ "color_fragment" ],
  12306. THREE.ShaderChunk[ "alphamap_fragment" ],
  12307. THREE.ShaderChunk[ "alphatest_fragment" ],
  12308. THREE.ShaderChunk[ "specularmap_fragment" ],
  12309. " #ifdef DOUBLE_SIDED",
  12310. " if ( gl_FrontFacing )",
  12311. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  12312. " else",
  12313. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  12314. " #else",
  12315. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  12316. " #endif",
  12317. THREE.ShaderChunk[ "envmap_fragment" ],
  12318. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12319. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12320. THREE.ShaderChunk[ "fog_fragment" ],
  12321. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12322. "}"
  12323. ].join( "\n" )
  12324. },
  12325. 'phong': {
  12326. uniforms: THREE.UniformsUtils.merge( [
  12327. THREE.UniformsLib[ "common" ],
  12328. THREE.UniformsLib[ "aomap" ],
  12329. THREE.UniformsLib[ "lightmap" ],
  12330. THREE.UniformsLib[ "emissivemap" ],
  12331. THREE.UniformsLib[ "bumpmap" ],
  12332. THREE.UniformsLib[ "normalmap" ],
  12333. THREE.UniformsLib[ "displacementmap" ],
  12334. THREE.UniformsLib[ "fog" ],
  12335. THREE.UniformsLib[ "lights" ],
  12336. THREE.UniformsLib[ "shadowmap" ],
  12337. {
  12338. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  12339. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  12340. "shininess": { type: "f", value: 30 }
  12341. }
  12342. ] ),
  12343. vertexShader: [
  12344. "#define PHONG",
  12345. "varying vec3 vViewPosition;",
  12346. "#ifndef FLAT_SHADED",
  12347. " varying vec3 vNormal;",
  12348. "#endif",
  12349. THREE.ShaderChunk[ "common" ],
  12350. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12351. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12352. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  12353. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12354. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  12355. THREE.ShaderChunk[ "color_pars_vertex" ],
  12356. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12357. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12358. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12359. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12360. "void main() {",
  12361. THREE.ShaderChunk[ "uv_vertex" ],
  12362. THREE.ShaderChunk[ "uv2_vertex" ],
  12363. THREE.ShaderChunk[ "color_vertex" ],
  12364. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12365. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12366. THREE.ShaderChunk[ "skinbase_vertex" ],
  12367. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12368. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12369. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  12370. " vNormal = normalize( transformedNormal );",
  12371. "#endif",
  12372. THREE.ShaderChunk[ "begin_vertex" ],
  12373. THREE.ShaderChunk[ "displacementmap_vertex" ],
  12374. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12375. THREE.ShaderChunk[ "skinning_vertex" ],
  12376. THREE.ShaderChunk[ "project_vertex" ],
  12377. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12378. " vViewPosition = - mvPosition.xyz;",
  12379. THREE.ShaderChunk[ "worldpos_vertex" ],
  12380. THREE.ShaderChunk[ "envmap_vertex" ],
  12381. THREE.ShaderChunk[ "lights_phong_vertex" ],
  12382. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12383. "}"
  12384. ].join( "\n" ),
  12385. fragmentShader: [
  12386. "#define PHONG",
  12387. "uniform vec3 diffuse;",
  12388. "uniform vec3 emissive;",
  12389. "uniform vec3 specular;",
  12390. "uniform float shininess;",
  12391. "uniform float opacity;",
  12392. THREE.ShaderChunk[ "common" ],
  12393. THREE.ShaderChunk[ "color_pars_fragment" ],
  12394. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12395. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12396. THREE.ShaderChunk[ "map_pars_fragment" ],
  12397. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12398. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12399. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  12400. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  12401. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12402. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12403. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  12404. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12405. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  12406. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  12407. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12408. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12409. "void main() {",
  12410. " vec3 outgoingLight = vec3( 0.0 );",
  12411. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12412. " vec3 totalAmbientLight = ambientLightColor;",
  12413. " vec3 totalEmissiveLight = emissive;",
  12414. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12415. THREE.ShaderChunk[ "map_fragment" ],
  12416. THREE.ShaderChunk[ "color_fragment" ],
  12417. THREE.ShaderChunk[ "alphamap_fragment" ],
  12418. THREE.ShaderChunk[ "alphatest_fragment" ],
  12419. THREE.ShaderChunk[ "specularmap_fragment" ],
  12420. THREE.ShaderChunk[ "normal_phong_fragment" ],
  12421. THREE.ShaderChunk[ "lightmap_fragment" ],
  12422. THREE.ShaderChunk[ "hemilight_fragment" ],
  12423. THREE.ShaderChunk[ "aomap_fragment" ],
  12424. THREE.ShaderChunk[ "emissivemap_fragment" ],
  12425. THREE.ShaderChunk[ "lights_phong_fragment" ],
  12426. THREE.ShaderChunk[ "envmap_fragment" ],
  12427. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12428. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12429. THREE.ShaderChunk[ "fog_fragment" ],
  12430. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12431. "}"
  12432. ].join( "\n" )
  12433. },
  12434. 'points': {
  12435. uniforms: THREE.UniformsUtils.merge( [
  12436. THREE.UniformsLib[ "points" ],
  12437. THREE.UniformsLib[ "shadowmap" ]
  12438. ] ),
  12439. vertexShader: [
  12440. "uniform float size;",
  12441. "uniform float scale;",
  12442. THREE.ShaderChunk[ "common" ],
  12443. THREE.ShaderChunk[ "color_pars_vertex" ],
  12444. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12445. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12446. "void main() {",
  12447. THREE.ShaderChunk[ "color_vertex" ],
  12448. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12449. " #ifdef USE_SIZEATTENUATION",
  12450. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  12451. " #else",
  12452. " gl_PointSize = size;",
  12453. " #endif",
  12454. " gl_Position = projectionMatrix * mvPosition;",
  12455. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12456. THREE.ShaderChunk[ "worldpos_vertex" ],
  12457. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12458. "}"
  12459. ].join( "\n" ),
  12460. fragmentShader: [
  12461. "uniform vec3 psColor;",
  12462. "uniform float opacity;",
  12463. THREE.ShaderChunk[ "common" ],
  12464. THREE.ShaderChunk[ "color_pars_fragment" ],
  12465. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  12466. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12467. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12468. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12469. "void main() {",
  12470. " vec3 outgoingLight = vec3( 0.0 );",
  12471. " vec4 diffuseColor = vec4( psColor, opacity );",
  12472. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12473. THREE.ShaderChunk[ "map_particle_fragment" ],
  12474. THREE.ShaderChunk[ "color_fragment" ],
  12475. THREE.ShaderChunk[ "alphatest_fragment" ],
  12476. " outgoingLight = diffuseColor.rgb;", // simple shader
  12477. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12478. THREE.ShaderChunk[ "fog_fragment" ],
  12479. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12480. "}"
  12481. ].join( "\n" )
  12482. },
  12483. 'dashed': {
  12484. uniforms: THREE.UniformsUtils.merge( [
  12485. THREE.UniformsLib[ "common" ],
  12486. THREE.UniformsLib[ "fog" ],
  12487. {
  12488. "scale" : { type: "f", value: 1 },
  12489. "dashSize" : { type: "f", value: 1 },
  12490. "totalSize": { type: "f", value: 2 }
  12491. }
  12492. ] ),
  12493. vertexShader: [
  12494. "uniform float scale;",
  12495. "attribute float lineDistance;",
  12496. "varying float vLineDistance;",
  12497. THREE.ShaderChunk[ "common" ],
  12498. THREE.ShaderChunk[ "color_pars_vertex" ],
  12499. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12500. "void main() {",
  12501. THREE.ShaderChunk[ "color_vertex" ],
  12502. " vLineDistance = scale * lineDistance;",
  12503. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12504. " gl_Position = projectionMatrix * mvPosition;",
  12505. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12506. "}"
  12507. ].join( "\n" ),
  12508. fragmentShader: [
  12509. "uniform vec3 diffuse;",
  12510. "uniform float opacity;",
  12511. "uniform float dashSize;",
  12512. "uniform float totalSize;",
  12513. "varying float vLineDistance;",
  12514. THREE.ShaderChunk[ "common" ],
  12515. THREE.ShaderChunk[ "color_pars_fragment" ],
  12516. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12517. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12518. "void main() {",
  12519. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  12520. " discard;",
  12521. " }",
  12522. " vec3 outgoingLight = vec3( 0.0 );",
  12523. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12524. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12525. THREE.ShaderChunk[ "color_fragment" ],
  12526. " outgoingLight = diffuseColor.rgb;", // simple shader
  12527. THREE.ShaderChunk[ "fog_fragment" ],
  12528. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12529. "}"
  12530. ].join( "\n" )
  12531. },
  12532. 'depth': {
  12533. uniforms: {
  12534. "mNear": { type: "f", value: 1.0 },
  12535. "mFar" : { type: "f", value: 2000.0 },
  12536. "opacity" : { type: "f", value: 1.0 }
  12537. },
  12538. vertexShader: [
  12539. THREE.ShaderChunk[ "common" ],
  12540. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12541. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12542. "void main() {",
  12543. THREE.ShaderChunk[ "begin_vertex" ],
  12544. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12545. THREE.ShaderChunk[ "project_vertex" ],
  12546. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12547. "}"
  12548. ].join( "\n" ),
  12549. fragmentShader: [
  12550. "uniform float mNear;",
  12551. "uniform float mFar;",
  12552. "uniform float opacity;",
  12553. THREE.ShaderChunk[ "common" ],
  12554. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12555. "void main() {",
  12556. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12557. " #ifdef USE_LOGDEPTHBUF_EXT",
  12558. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  12559. " #else",
  12560. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  12561. " #endif",
  12562. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  12563. " gl_FragColor = vec4( vec3( color ), opacity );",
  12564. "}"
  12565. ].join( "\n" )
  12566. },
  12567. 'normal': {
  12568. uniforms: {
  12569. "opacity" : { type: "f", value: 1.0 }
  12570. },
  12571. vertexShader: [
  12572. "varying vec3 vNormal;",
  12573. THREE.ShaderChunk[ "common" ],
  12574. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12575. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12576. "void main() {",
  12577. " vNormal = normalize( normalMatrix * normal );",
  12578. THREE.ShaderChunk[ "begin_vertex" ],
  12579. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12580. THREE.ShaderChunk[ "project_vertex" ],
  12581. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12582. "}"
  12583. ].join( "\n" ),
  12584. fragmentShader: [
  12585. "uniform float opacity;",
  12586. "varying vec3 vNormal;",
  12587. THREE.ShaderChunk[ "common" ],
  12588. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12589. "void main() {",
  12590. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  12591. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12592. "}"
  12593. ].join( "\n" )
  12594. },
  12595. /* -------------------------------------------------------------------------
  12596. // Cube map shader
  12597. ------------------------------------------------------------------------- */
  12598. 'cube': {
  12599. uniforms: { "tCube": { type: "t", value: null },
  12600. "tFlip": { type: "f", value: - 1 } },
  12601. vertexShader: [
  12602. "varying vec3 vWorldPosition;",
  12603. THREE.ShaderChunk[ "common" ],
  12604. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12605. "void main() {",
  12606. " vWorldPosition = transformDirection( position, modelMatrix );",
  12607. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12608. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12609. "}"
  12610. ].join( "\n" ),
  12611. fragmentShader: [
  12612. "uniform samplerCube tCube;",
  12613. "uniform float tFlip;",
  12614. "varying vec3 vWorldPosition;",
  12615. THREE.ShaderChunk[ "common" ],
  12616. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12617. "void main() {",
  12618. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12619. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12620. "}"
  12621. ].join( "\n" )
  12622. },
  12623. /* -------------------------------------------------------------------------
  12624. // Cube map shader
  12625. ------------------------------------------------------------------------- */
  12626. 'equirect': {
  12627. uniforms: { "tEquirect": { type: "t", value: null },
  12628. "tFlip": { type: "f", value: - 1 } },
  12629. vertexShader: [
  12630. "varying vec3 vWorldPosition;",
  12631. THREE.ShaderChunk[ "common" ],
  12632. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12633. "void main() {",
  12634. " vWorldPosition = transformDirection( position, modelMatrix );",
  12635. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12636. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12637. "}"
  12638. ].join( "\n" ),
  12639. fragmentShader: [
  12640. "uniform sampler2D tEquirect;",
  12641. "uniform float tFlip;",
  12642. "varying vec3 vWorldPosition;",
  12643. THREE.ShaderChunk[ "common" ],
  12644. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12645. "void main() {",
  12646. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12647. "vec3 direction = normalize( vWorldPosition );",
  12648. "vec2 sampleUV;",
  12649. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  12650. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  12651. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  12652. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12653. "}"
  12654. ].join( "\n" )
  12655. },
  12656. /* Depth encoding into RGBA texture
  12657. *
  12658. * based on SpiderGL shadow map example
  12659. * http://spidergl.org/example.php?id=6
  12660. *
  12661. * originally from
  12662. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  12663. *
  12664. * see also
  12665. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  12666. */
  12667. 'depthRGBA': {
  12668. uniforms: {},
  12669. vertexShader: [
  12670. THREE.ShaderChunk[ "common" ],
  12671. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12672. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12673. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12674. "void main() {",
  12675. THREE.ShaderChunk[ "skinbase_vertex" ],
  12676. THREE.ShaderChunk[ "begin_vertex" ],
  12677. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12678. THREE.ShaderChunk[ "skinning_vertex" ],
  12679. THREE.ShaderChunk[ "project_vertex" ],
  12680. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12681. "}"
  12682. ].join( "\n" ),
  12683. fragmentShader: [
  12684. THREE.ShaderChunk[ "common" ],
  12685. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12686. "vec4 pack_depth( const in float depth ) {",
  12687. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12688. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12689. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  12690. " res -= res.xxyz * bit_mask;",
  12691. " return res;",
  12692. "}",
  12693. "void main() {",
  12694. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12695. " #ifdef USE_LOGDEPTHBUF_EXT",
  12696. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  12697. " #else",
  12698. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  12699. " #endif",
  12700. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  12701. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  12702. //"gl_FragData[ 0 ] = pack_depth( z );",
  12703. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  12704. "}"
  12705. ].join( "\n" )
  12706. },
  12707. 'distanceRGBA': {
  12708. uniforms: {
  12709. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  12710. },
  12711. vertexShader: [
  12712. "varying vec4 vWorldPosition;",
  12713. THREE.ShaderChunk[ "common" ],
  12714. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12715. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12716. "void main() {",
  12717. THREE.ShaderChunk[ "skinbase_vertex" ],
  12718. THREE.ShaderChunk[ "begin_vertex" ],
  12719. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12720. THREE.ShaderChunk[ "skinning_vertex" ],
  12721. THREE.ShaderChunk[ "project_vertex" ],
  12722. THREE.ShaderChunk[ "worldpos_vertex" ],
  12723. "vWorldPosition = worldPosition;",
  12724. "}"
  12725. ].join( "\n" ),
  12726. fragmentShader: [
  12727. "uniform vec3 lightPos;",
  12728. "varying vec4 vWorldPosition;",
  12729. THREE.ShaderChunk[ "common" ],
  12730. "vec4 pack1K ( float depth ) {",
  12731. " depth /= 1000.0;",
  12732. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12733. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12734. " vec4 res = fract( depth * bitSh );",
  12735. " res -= res.xxyz * bitMsk;",
  12736. " return res; ",
  12737. "}",
  12738. "float unpack1K ( vec4 color ) {",
  12739. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  12740. " return dot( color, bitSh ) * 1000.0;",
  12741. "}",
  12742. "void main () {",
  12743. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  12744. "}"
  12745. ].join( "\n" )
  12746. }
  12747. };
  12748. // File:src/renderers/WebGLRenderer.js
  12749. /**
  12750. * @author supereggbert / http://www.paulbrunt.co.uk/
  12751. * @author mrdoob / http://mrdoob.com/
  12752. * @author alteredq / http://alteredqualia.com/
  12753. * @author szimek / https://github.com/szimek/
  12754. */
  12755. THREE.WebGLRenderer = function ( parameters ) {
  12756. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  12757. parameters = parameters || {};
  12758. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  12759. _context = parameters.context !== undefined ? parameters.context : null,
  12760. _width = _canvas.width,
  12761. _height = _canvas.height,
  12762. pixelRatio = 1,
  12763. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12764. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12765. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12766. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12767. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12768. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12769. _clearColor = new THREE.Color( 0x000000 ),
  12770. _clearAlpha = 0;
  12771. var lights = [];
  12772. var opaqueObjects = [];
  12773. var opaqueObjectsLastIndex = -1;
  12774. var transparentObjects = [];
  12775. var transparentObjectsLastIndex = -1;
  12776. var morphInfluences = new Float32Array( 8 );
  12777. var sprites = [];
  12778. var lensFlares = [];
  12779. // public properties
  12780. this.domElement = _canvas;
  12781. this.context = null;
  12782. // clearing
  12783. this.autoClear = true;
  12784. this.autoClearColor = true;
  12785. this.autoClearDepth = true;
  12786. this.autoClearStencil = true;
  12787. // scene graph
  12788. this.sortObjects = true;
  12789. // physically based shading
  12790. this.gammaFactor = 2.0; // for backwards compatibility
  12791. this.gammaInput = false;
  12792. this.gammaOutput = false;
  12793. // morphs
  12794. this.maxMorphTargets = 8;
  12795. this.maxMorphNormals = 4;
  12796. // flags
  12797. this.autoScaleCubemaps = true;
  12798. // internal properties
  12799. var _this = this,
  12800. // internal state cache
  12801. _currentProgram = null,
  12802. _currentFramebuffer = null,
  12803. _currentMaterialId = - 1,
  12804. _currentGeometryProgram = '',
  12805. _currentCamera = null,
  12806. _usedTextureUnits = 0,
  12807. _viewportX = 0,
  12808. _viewportY = 0,
  12809. _viewportWidth = _canvas.width,
  12810. _viewportHeight = _canvas.height,
  12811. _currentWidth = 0,
  12812. _currentHeight = 0,
  12813. // frustum
  12814. _frustum = new THREE.Frustum(),
  12815. // camera matrices cache
  12816. _projScreenMatrix = new THREE.Matrix4(),
  12817. _vector3 = new THREE.Vector3(),
  12818. // light arrays cache
  12819. _direction = new THREE.Vector3(),
  12820. _lightsNeedUpdate = true,
  12821. _lights = {
  12822. ambient: [ 0, 0, 0 ],
  12823. directional: { length: 0, colors: [], positions: [] },
  12824. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  12825. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  12826. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  12827. },
  12828. // info
  12829. _infoMemory = {
  12830. geometries: 0,
  12831. textures: 0
  12832. },
  12833. _infoRender = {
  12834. calls: 0,
  12835. vertices: 0,
  12836. faces: 0,
  12837. points: 0
  12838. };
  12839. this.info = {
  12840. render: _infoRender,
  12841. memory: _infoMemory,
  12842. programs: null
  12843. };
  12844. // initialize
  12845. var _gl;
  12846. try {
  12847. var attributes = {
  12848. alpha: _alpha,
  12849. depth: _depth,
  12850. stencil: _stencil,
  12851. antialias: _antialias,
  12852. premultipliedAlpha: _premultipliedAlpha,
  12853. preserveDrawingBuffer: _preserveDrawingBuffer
  12854. };
  12855. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  12856. if ( _gl === null ) {
  12857. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12858. throw 'Error creating WebGL context with your selected attributes.';
  12859. } else {
  12860. throw 'Error creating WebGL context.';
  12861. }
  12862. }
  12863. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12864. } catch ( error ) {
  12865. console.error( 'THREE.WebGLRenderer: ' + error );
  12866. }
  12867. var extensions = new THREE.WebGLExtensions( _gl );
  12868. extensions.get( 'OES_texture_float' );
  12869. extensions.get( 'OES_texture_float_linear' );
  12870. extensions.get( 'OES_texture_half_float' );
  12871. extensions.get( 'OES_texture_half_float_linear' );
  12872. extensions.get( 'OES_standard_derivatives' );
  12873. extensions.get( 'ANGLE_instanced_arrays' );
  12874. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12875. THREE.BufferGeometry.MaxIndex = 4294967296;
  12876. }
  12877. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  12878. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  12879. var properties = new THREE.WebGLProperties();
  12880. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  12881. var programCache = new THREE.WebGLPrograms( this, capabilities );
  12882. this.info.programs = programCache.programs;
  12883. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  12884. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12885. //
  12886. function glClearColor( r, g, b, a ) {
  12887. if ( _premultipliedAlpha === true ) {
  12888. r *= a; g *= a; b *= a;
  12889. }
  12890. _gl.clearColor( r, g, b, a );
  12891. }
  12892. function setDefaultGLState() {
  12893. state.init();
  12894. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12895. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12896. }
  12897. function resetGLState() {
  12898. _currentProgram = null;
  12899. _currentCamera = null;
  12900. _currentGeometryProgram = '';
  12901. _currentMaterialId = - 1;
  12902. _lightsNeedUpdate = true;
  12903. state.reset();
  12904. }
  12905. setDefaultGLState();
  12906. this.context = _gl;
  12907. this.capabilities = capabilities;
  12908. this.extensions = extensions;
  12909. this.state = state;
  12910. // shadow map
  12911. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  12912. this.shadowMap = shadowMap;
  12913. // Plugins
  12914. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  12915. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  12916. // API
  12917. this.getContext = function () {
  12918. return _gl;
  12919. };
  12920. this.getContextAttributes = function () {
  12921. return _gl.getContextAttributes();
  12922. };
  12923. this.forceContextLoss = function () {
  12924. extensions.get( 'WEBGL_lose_context' ).loseContext();
  12925. };
  12926. this.getMaxAnisotropy = ( function () {
  12927. var value;
  12928. return function getMaxAnisotropy() {
  12929. if ( value !== undefined ) return value;
  12930. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12931. if ( extension !== null ) {
  12932. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  12933. } else {
  12934. value = 0;
  12935. }
  12936. return value;
  12937. }
  12938. } )();
  12939. this.getPrecision = function () {
  12940. return capabilities.precision;
  12941. };
  12942. this.getPixelRatio = function () {
  12943. return pixelRatio;
  12944. };
  12945. this.setPixelRatio = function ( value ) {
  12946. if ( value !== undefined ) pixelRatio = value;
  12947. };
  12948. this.getSize = function () {
  12949. return {
  12950. width: _width,
  12951. height: _height
  12952. };
  12953. };
  12954. this.setSize = function ( width, height, updateStyle ) {
  12955. _width = width;
  12956. _height = height;
  12957. _canvas.width = width * pixelRatio;
  12958. _canvas.height = height * pixelRatio;
  12959. if ( updateStyle !== false ) {
  12960. _canvas.style.width = width + 'px';
  12961. _canvas.style.height = height + 'px';
  12962. }
  12963. this.setViewport( 0, 0, width, height );
  12964. };
  12965. this.setViewport = function ( x, y, width, height ) {
  12966. _viewportX = x * pixelRatio;
  12967. _viewportY = y * pixelRatio;
  12968. _viewportWidth = width * pixelRatio;
  12969. _viewportHeight = height * pixelRatio;
  12970. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12971. };
  12972. this.getViewport = function ( dimensions ) {
  12973. dimensions.x = _viewportX;
  12974. dimensions.y = _viewportY;
  12975. dimensions.z = _viewportWidth;
  12976. dimensions.w = _viewportHeight;
  12977. };
  12978. this.setScissor = function ( x, y, width, height ) {
  12979. _gl.scissor(
  12980. x * pixelRatio,
  12981. y * pixelRatio,
  12982. width * pixelRatio,
  12983. height * pixelRatio
  12984. );
  12985. };
  12986. this.enableScissorTest = function ( boolean ) {
  12987. state.setScissorTest( boolean );
  12988. };
  12989. // Clearing
  12990. this.getClearColor = function () {
  12991. return _clearColor;
  12992. };
  12993. this.setClearColor = function ( color, alpha ) {
  12994. _clearColor.set( color );
  12995. _clearAlpha = alpha !== undefined ? alpha : 1;
  12996. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12997. };
  12998. this.getClearAlpha = function () {
  12999. return _clearAlpha;
  13000. };
  13001. this.setClearAlpha = function ( alpha ) {
  13002. _clearAlpha = alpha;
  13003. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  13004. };
  13005. this.clear = function ( color, depth, stencil ) {
  13006. var bits = 0;
  13007. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  13008. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  13009. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  13010. _gl.clear( bits );
  13011. };
  13012. this.clearColor = function () {
  13013. _gl.clear( _gl.COLOR_BUFFER_BIT );
  13014. };
  13015. this.clearDepth = function () {
  13016. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  13017. };
  13018. this.clearStencil = function () {
  13019. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  13020. };
  13021. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  13022. this.setRenderTarget( renderTarget );
  13023. this.clear( color, depth, stencil );
  13024. };
  13025. // Reset
  13026. this.resetGLState = resetGLState;
  13027. this.dispose = function() {
  13028. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13029. };
  13030. // Events
  13031. function onContextLost( event ) {
  13032. event.preventDefault();
  13033. resetGLState();
  13034. setDefaultGLState();
  13035. properties.clear();
  13036. };
  13037. function onTextureDispose( event ) {
  13038. var texture = event.target;
  13039. texture.removeEventListener( 'dispose', onTextureDispose );
  13040. deallocateTexture( texture );
  13041. _infoMemory.textures --;
  13042. }
  13043. function onRenderTargetDispose( event ) {
  13044. var renderTarget = event.target;
  13045. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13046. deallocateRenderTarget( renderTarget );
  13047. _infoMemory.textures --;
  13048. }
  13049. function onMaterialDispose( event ) {
  13050. var material = event.target;
  13051. material.removeEventListener( 'dispose', onMaterialDispose );
  13052. deallocateMaterial( material );
  13053. }
  13054. // Buffer deallocation
  13055. function deallocateTexture( texture ) {
  13056. var textureProperties = properties.get( texture );
  13057. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  13058. // cube texture
  13059. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  13060. } else {
  13061. // 2D texture
  13062. if ( textureProperties.__webglInit === undefined ) return;
  13063. _gl.deleteTexture( textureProperties.__webglTexture );
  13064. }
  13065. // remove all webgl properties
  13066. properties.delete( texture );
  13067. }
  13068. function deallocateRenderTarget( renderTarget ) {
  13069. var renderTargetProperties = properties.get( renderTarget );
  13070. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  13071. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  13072. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13073. for ( var i = 0; i < 6; i ++ ) {
  13074. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13075. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  13076. }
  13077. } else {
  13078. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13079. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  13080. }
  13081. properties.delete( renderTarget );
  13082. }
  13083. function deallocateMaterial( material ) {
  13084. releaseMaterialProgramReference( material );
  13085. properties.delete( material );
  13086. }
  13087. function releaseMaterialProgramReference( material ) {
  13088. var programInfo = properties.get( material ).program;
  13089. material.program = undefined;
  13090. if ( programInfo !== undefined ) {
  13091. programCache.releaseProgram( programInfo );
  13092. }
  13093. }
  13094. // Buffer rendering
  13095. this.renderBufferImmediate = function ( object, program, material ) {
  13096. state.initAttributes();
  13097. var buffers = properties.get( object );
  13098. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13099. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13100. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13101. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13102. var attributes = program.getAttributes();
  13103. if ( object.hasPositions ) {
  13104. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  13105. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  13106. state.enableAttribute( attributes.position );
  13107. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  13108. }
  13109. if ( object.hasNormals ) {
  13110. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13111. if ( material.type !== 'MeshPhongMaterial' && material.shading === THREE.FlatShading ) {
  13112. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13113. var array = object.normalArray;
  13114. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13115. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13116. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13117. array[ i + 0 ] = nx;
  13118. array[ i + 1 ] = ny;
  13119. array[ i + 2 ] = nz;
  13120. array[ i + 3 ] = nx;
  13121. array[ i + 4 ] = ny;
  13122. array[ i + 5 ] = nz;
  13123. array[ i + 6 ] = nx;
  13124. array[ i + 7 ] = ny;
  13125. array[ i + 8 ] = nz;
  13126. }
  13127. }
  13128. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13129. state.enableAttribute( attributes.normal );
  13130. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13131. }
  13132. if ( object.hasUvs && material.map ) {
  13133. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13134. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13135. state.enableAttribute( attributes.uv );
  13136. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13137. }
  13138. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  13139. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13140. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13141. state.enableAttribute( attributes.color );
  13142. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13143. }
  13144. state.disableUnusedAttributes();
  13145. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13146. object.count = 0;
  13147. };
  13148. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  13149. setMaterial( material );
  13150. var program = setProgram( camera, lights, fog, material, object );
  13151. var updateBuffers = false;
  13152. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  13153. if ( geometryProgram !== _currentGeometryProgram ) {
  13154. _currentGeometryProgram = geometryProgram;
  13155. updateBuffers = true;
  13156. }
  13157. // morph targets
  13158. var morphTargetInfluences = object.morphTargetInfluences;
  13159. if ( morphTargetInfluences !== undefined ) {
  13160. var activeInfluences = [];
  13161. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13162. var influence = morphTargetInfluences[ i ];
  13163. activeInfluences.push( [ influence, i ] );
  13164. }
  13165. activeInfluences.sort( numericalSort );
  13166. if ( activeInfluences.length > 8 ) {
  13167. activeInfluences.length = 8;
  13168. }
  13169. var morphAttributes = geometry.morphAttributes;
  13170. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13171. var influence = activeInfluences[ i ];
  13172. morphInfluences[ i ] = influence[ 0 ];
  13173. if ( influence[ 0 ] !== 0 ) {
  13174. var index = influence[ 1 ];
  13175. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  13176. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  13177. } else {
  13178. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  13179. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  13180. }
  13181. }
  13182. var uniforms = program.getUniforms();
  13183. if ( uniforms.morphTargetInfluences !== null ) {
  13184. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13185. }
  13186. updateBuffers = true;
  13187. }
  13188. //
  13189. var index = geometry.index;
  13190. var position = geometry.attributes.position;
  13191. if ( material.wireframe === true ) {
  13192. index = objects.getWireframeAttribute( geometry );
  13193. }
  13194. var renderer;
  13195. if ( index !== null ) {
  13196. renderer = indexedBufferRenderer;
  13197. renderer.setIndex( index );
  13198. } else {
  13199. renderer = bufferRenderer;
  13200. }
  13201. if ( updateBuffers ) {
  13202. setupVertexAttributes( material, program, geometry );
  13203. if ( index !== null ) {
  13204. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  13205. }
  13206. }
  13207. if ( group === null ) {
  13208. var count;
  13209. if ( index !== null ) {
  13210. count = index.array.length;
  13211. } else {
  13212. count = position.count;
  13213. }
  13214. var drawRange = geometry.drawRange;
  13215. group = {
  13216. start: drawRange.start,
  13217. count: Math.min( drawRange.count, count )
  13218. };
  13219. }
  13220. if ( object instanceof THREE.Mesh ) {
  13221. if ( material.wireframe === true ) {
  13222. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  13223. renderer.setMode( _gl.LINES );
  13224. } else {
  13225. renderer.setMode( _gl.TRIANGLES );
  13226. }
  13227. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  13228. renderer.renderInstances( geometry );
  13229. } else {
  13230. renderer.render( group.start, group.count );
  13231. }
  13232. } else if ( object instanceof THREE.Line ) {
  13233. var lineWidth = material.linewidth;
  13234. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13235. state.setLineWidth( lineWidth * pixelRatio );
  13236. if ( object instanceof THREE.LineSegments ) {
  13237. renderer.setMode( _gl.LINES );
  13238. } else {
  13239. renderer.setMode( _gl.LINE_STRIP );
  13240. }
  13241. renderer.render( group.start, group.count );
  13242. } else if ( object instanceof THREE.Points ) {
  13243. renderer.setMode( _gl.POINTS );
  13244. renderer.render( group.start, group.count );
  13245. }
  13246. };
  13247. function setupVertexAttributes( material, program, geometry, startIndex ) {
  13248. var extension;
  13249. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  13250. extension = extensions.get( 'ANGLE_instanced_arrays' );
  13251. if ( extension === null ) {
  13252. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13253. return;
  13254. }
  13255. }
  13256. if ( startIndex === undefined ) startIndex = 0;
  13257. state.initAttributes();
  13258. var geometryAttributes = geometry.attributes;
  13259. var programAttributes = program.getAttributes();
  13260. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13261. for ( var name in programAttributes ) {
  13262. var programAttribute = programAttributes[ name ];
  13263. if ( programAttribute >= 0 ) {
  13264. var geometryAttribute = geometryAttributes[ name ];
  13265. if ( geometryAttribute !== undefined ) {
  13266. var size = geometryAttribute.itemSize;
  13267. var buffer = objects.getAttributeBuffer( geometryAttribute );
  13268. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  13269. var data = geometryAttribute.data;
  13270. var stride = data.stride;
  13271. var offset = geometryAttribute.offset;
  13272. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  13273. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  13274. if ( geometry.maxInstancedCount === undefined ) {
  13275. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13276. }
  13277. } else {
  13278. state.enableAttribute( programAttribute );
  13279. }
  13280. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13281. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  13282. } else {
  13283. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  13284. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  13285. if ( geometry.maxInstancedCount === undefined ) {
  13286. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13287. }
  13288. } else {
  13289. state.enableAttribute( programAttribute );
  13290. }
  13291. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13292. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  13293. }
  13294. } else if ( materialDefaultAttributeValues !== undefined ) {
  13295. var value = materialDefaultAttributeValues[ name ];
  13296. if ( value !== undefined ) {
  13297. switch ( value.length ) {
  13298. case 2:
  13299. _gl.vertexAttrib2fv( programAttribute, value );
  13300. break;
  13301. case 3:
  13302. _gl.vertexAttrib3fv( programAttribute, value );
  13303. break;
  13304. case 4:
  13305. _gl.vertexAttrib4fv( programAttribute, value );
  13306. break;
  13307. default:
  13308. _gl.vertexAttrib1fv( programAttribute, value );
  13309. }
  13310. }
  13311. }
  13312. }
  13313. }
  13314. state.disableUnusedAttributes();
  13315. }
  13316. // Sorting
  13317. function numericalSort ( a, b ) {
  13318. return b[ 0 ] - a[ 0 ];
  13319. }
  13320. function painterSortStable ( a, b ) {
  13321. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13322. return a.object.renderOrder - b.object.renderOrder;
  13323. } else if ( a.material.id !== b.material.id ) {
  13324. return a.material.id - b.material.id;
  13325. } else if ( a.z !== b.z ) {
  13326. return a.z - b.z;
  13327. } else {
  13328. return a.id - b.id;
  13329. }
  13330. }
  13331. function reversePainterSortStable ( a, b ) {
  13332. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13333. return a.object.renderOrder - b.object.renderOrder;
  13334. } if ( a.z !== b.z ) {
  13335. return b.z - a.z;
  13336. } else {
  13337. return a.id - b.id;
  13338. }
  13339. }
  13340. // Rendering
  13341. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13342. if ( camera instanceof THREE.Camera === false ) {
  13343. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13344. return;
  13345. }
  13346. var fog = scene.fog;
  13347. // reset caching for this frame
  13348. _currentGeometryProgram = '';
  13349. _currentMaterialId = - 1;
  13350. _currentCamera = null;
  13351. _lightsNeedUpdate = true;
  13352. // update scene graph
  13353. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13354. // update camera matrices and frustum
  13355. if ( camera.parent === null ) camera.updateMatrixWorld();
  13356. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13357. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13358. _frustum.setFromMatrix( _projScreenMatrix );
  13359. lights.length = 0;
  13360. opaqueObjectsLastIndex = -1;
  13361. transparentObjectsLastIndex = -1;
  13362. sprites.length = 0;
  13363. lensFlares.length = 0;
  13364. projectObject( scene );
  13365. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  13366. transparentObjects.length = transparentObjectsLastIndex + 1;
  13367. if ( _this.sortObjects === true ) {
  13368. opaqueObjects.sort( painterSortStable );
  13369. transparentObjects.sort( reversePainterSortStable );
  13370. }
  13371. //
  13372. shadowMap.render( scene );
  13373. //
  13374. _infoRender.calls = 0;
  13375. _infoRender.vertices = 0;
  13376. _infoRender.faces = 0;
  13377. _infoRender.points = 0;
  13378. this.setRenderTarget( renderTarget );
  13379. if ( this.autoClear || forceClear ) {
  13380. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  13381. }
  13382. //
  13383. if ( scene.overrideMaterial ) {
  13384. var overrideMaterial = scene.overrideMaterial;
  13385. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  13386. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  13387. } else {
  13388. // opaque pass (front-to-back order)
  13389. state.setBlending( THREE.NoBlending );
  13390. renderObjects( opaqueObjects, camera, lights, fog );
  13391. // transparent pass (back-to-front order)
  13392. renderObjects( transparentObjects, camera, lights, fog );
  13393. }
  13394. // custom render plugins (post pass)
  13395. spritePlugin.render( scene, camera );
  13396. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  13397. // Generate mipmap if we're using any kind of mipmap filtering
  13398. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  13399. updateRenderTargetMipmap( renderTarget );
  13400. }
  13401. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13402. state.setDepthTest( true );
  13403. state.setDepthWrite( true );
  13404. state.setColorWrite( true );
  13405. // _gl.finish();
  13406. };
  13407. function pushRenderItem( object, geometry, material, z, group ) {
  13408. var array, index;
  13409. // allocate the next position in the appropriate array
  13410. if ( material.transparent ) {
  13411. array = transparentObjects;
  13412. index = ++ transparentObjectsLastIndex;
  13413. } else {
  13414. array = opaqueObjects;
  13415. index = ++ opaqueObjectsLastIndex;
  13416. }
  13417. // recycle existing render item or grow the array
  13418. var renderItem = array[ index ];
  13419. if ( renderItem !== undefined ) {
  13420. renderItem.id = object.id;
  13421. renderItem.object = object;
  13422. renderItem.geometry = geometry;
  13423. renderItem.material = material;
  13424. renderItem.z = _vector3.z;
  13425. renderItem.group = group;
  13426. } else {
  13427. renderItem = {
  13428. id: object.id,
  13429. object: object,
  13430. geometry: geometry,
  13431. material: material,
  13432. z: _vector3.z,
  13433. group: group
  13434. };
  13435. // assert( index === array.length );
  13436. array.push( renderItem );
  13437. }
  13438. }
  13439. function projectObject( object ) {
  13440. if ( object.visible === false ) return;
  13441. if ( object instanceof THREE.Light ) {
  13442. lights.push( object );
  13443. } else if ( object instanceof THREE.Sprite ) {
  13444. sprites.push( object );
  13445. } else if ( object instanceof THREE.LensFlare ) {
  13446. lensFlares.push( object );
  13447. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  13448. if ( _this.sortObjects === true ) {
  13449. _vector3.setFromMatrixPosition( object.matrixWorld );
  13450. _vector3.applyProjection( _projScreenMatrix );
  13451. }
  13452. pushRenderItem( object, null, object.material, _vector3.z, null );
  13453. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  13454. if ( object instanceof THREE.SkinnedMesh ) {
  13455. object.skeleton.update();
  13456. }
  13457. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  13458. var material = object.material;
  13459. if ( material.visible === true ) {
  13460. if ( _this.sortObjects === true ) {
  13461. _vector3.setFromMatrixPosition( object.matrixWorld );
  13462. _vector3.applyProjection( _projScreenMatrix );
  13463. }
  13464. var geometry = objects.update( object );
  13465. if ( material instanceof THREE.MeshFaceMaterial ) {
  13466. var groups = geometry.groups;
  13467. var materials = material.materials;
  13468. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13469. var group = groups[ i ];
  13470. var groupMaterial = materials[ group.materialIndex ];
  13471. if ( groupMaterial.visible === true ) {
  13472. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  13473. }
  13474. }
  13475. } else {
  13476. pushRenderItem( object, geometry, material, _vector3.z, null );
  13477. }
  13478. }
  13479. }
  13480. }
  13481. var children = object.children;
  13482. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13483. projectObject( children[ i ] );
  13484. }
  13485. }
  13486. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  13487. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13488. var renderItem = renderList[ i ];
  13489. var object = renderItem.object;
  13490. var geometry = renderItem.geometry;
  13491. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13492. var group = renderItem.group;
  13493. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13494. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13495. if ( object instanceof THREE.ImmediateRenderObject ) {
  13496. setMaterial( material );
  13497. var program = setProgram( camera, lights, fog, material, object );
  13498. _currentGeometryProgram = '';
  13499. object.render( function ( object ) {
  13500. _this.renderBufferImmediate( object, program, material );
  13501. } );
  13502. } else {
  13503. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  13504. }
  13505. }
  13506. }
  13507. function initMaterial( material, lights, fog, object ) {
  13508. var materialProperties = properties.get( material );
  13509. var parameters = programCache.getParameters( material, lights, fog, object );
  13510. var code = programCache.getProgramCode( material, parameters );
  13511. var program = materialProperties.program;
  13512. var programChange = true;
  13513. if ( program === undefined ) {
  13514. // new material
  13515. material.addEventListener( 'dispose', onMaterialDispose );
  13516. } else if ( program.code !== code ) {
  13517. // changed glsl or parameters
  13518. releaseMaterialProgramReference( material );
  13519. } else if ( parameters.shaderID !== undefined ) {
  13520. // same glsl and uniform list
  13521. return;
  13522. } else {
  13523. // only rebuild uniform list
  13524. programChange = false;
  13525. }
  13526. if ( programChange ) {
  13527. if ( parameters.shaderID ) {
  13528. var shader = THREE.ShaderLib[ parameters.shaderID ];
  13529. materialProperties.__webglShader = {
  13530. name: material.type,
  13531. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  13532. vertexShader: shader.vertexShader,
  13533. fragmentShader: shader.fragmentShader
  13534. };
  13535. } else {
  13536. materialProperties.__webglShader = {
  13537. name: material.type,
  13538. uniforms: material.uniforms,
  13539. vertexShader: material.vertexShader,
  13540. fragmentShader: material.fragmentShader
  13541. };
  13542. }
  13543. material.__webglShader = materialProperties.__webglShader;
  13544. program = programCache.acquireProgram( material, parameters, code );
  13545. materialProperties.program = program;
  13546. material.program = program;
  13547. }
  13548. var attributes = program.getAttributes();
  13549. if ( material.morphTargets ) {
  13550. material.numSupportedMorphTargets = 0;
  13551. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13552. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  13553. material.numSupportedMorphTargets ++;
  13554. }
  13555. }
  13556. }
  13557. if ( material.morphNormals ) {
  13558. material.numSupportedMorphNormals = 0;
  13559. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  13560. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  13561. material.numSupportedMorphNormals ++;
  13562. }
  13563. }
  13564. }
  13565. materialProperties.uniformsList = [];
  13566. var uniformLocations = materialProperties.program.getUniforms();
  13567. for ( var u in materialProperties.__webglShader.uniforms ) {
  13568. var location = uniformLocations[ u ];
  13569. if ( location ) {
  13570. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  13571. }
  13572. }
  13573. }
  13574. function setMaterial( material ) {
  13575. setMaterialFaces( material );
  13576. if ( material.transparent === true ) {
  13577. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  13578. } else {
  13579. state.setBlending( THREE.NoBlending );
  13580. }
  13581. state.setDepthFunc( material.depthFunc );
  13582. state.setDepthTest( material.depthTest );
  13583. state.setDepthWrite( material.depthWrite );
  13584. state.setColorWrite( material.colorWrite );
  13585. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13586. }
  13587. function setMaterialFaces( material ) {
  13588. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  13589. state.setFlipSided( material.side === THREE.BackSide );
  13590. }
  13591. function setProgram( camera, lights, fog, material, object ) {
  13592. _usedTextureUnits = 0;
  13593. var materialProperties = properties.get( material );
  13594. if ( material.needsUpdate || ! materialProperties.program ) {
  13595. initMaterial( material, lights, fog, object );
  13596. material.needsUpdate = false;
  13597. }
  13598. var refreshProgram = false;
  13599. var refreshMaterial = false;
  13600. var refreshLights = false;
  13601. var program = materialProperties.program,
  13602. p_uniforms = program.getUniforms(),
  13603. m_uniforms = materialProperties.__webglShader.uniforms;
  13604. if ( program.id !== _currentProgram ) {
  13605. _gl.useProgram( program.program );
  13606. _currentProgram = program.id;
  13607. refreshProgram = true;
  13608. refreshMaterial = true;
  13609. refreshLights = true;
  13610. }
  13611. if ( material.id !== _currentMaterialId ) {
  13612. if ( _currentMaterialId === - 1 ) refreshLights = true;
  13613. _currentMaterialId = material.id;
  13614. refreshMaterial = true;
  13615. }
  13616. if ( refreshProgram || camera !== _currentCamera ) {
  13617. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  13618. if ( capabilities.logarithmicDepthBuffer ) {
  13619. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13620. }
  13621. if ( camera !== _currentCamera ) _currentCamera = camera;
  13622. // load material specific uniforms
  13623. // (shader material also gets them for the sake of genericity)
  13624. if ( material instanceof THREE.ShaderMaterial ||
  13625. material instanceof THREE.MeshPhongMaterial ||
  13626. material.envMap ) {
  13627. if ( p_uniforms.cameraPosition !== undefined ) {
  13628. _vector3.setFromMatrixPosition( camera.matrixWorld );
  13629. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  13630. }
  13631. }
  13632. if ( material instanceof THREE.MeshPhongMaterial ||
  13633. material instanceof THREE.MeshLambertMaterial ||
  13634. material instanceof THREE.MeshBasicMaterial ||
  13635. material instanceof THREE.ShaderMaterial ||
  13636. material.skinning ) {
  13637. if ( p_uniforms.viewMatrix !== undefined ) {
  13638. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  13639. }
  13640. }
  13641. }
  13642. // skinning uniforms must be set even if material didn't change
  13643. // auto-setting of texture unit for bone texture must go before other textures
  13644. // not sure why, but otherwise weird things happen
  13645. if ( material.skinning ) {
  13646. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  13647. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  13648. }
  13649. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  13650. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  13651. }
  13652. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  13653. if ( p_uniforms.boneTexture !== undefined ) {
  13654. var textureUnit = getTextureUnit();
  13655. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  13656. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  13657. }
  13658. if ( p_uniforms.boneTextureWidth !== undefined ) {
  13659. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  13660. }
  13661. if ( p_uniforms.boneTextureHeight !== undefined ) {
  13662. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  13663. }
  13664. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  13665. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  13666. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  13667. }
  13668. }
  13669. }
  13670. if ( refreshMaterial ) {
  13671. // refresh uniforms common to several materials
  13672. if ( fog && material.fog ) {
  13673. refreshUniformsFog( m_uniforms, fog );
  13674. }
  13675. if ( material instanceof THREE.MeshPhongMaterial ||
  13676. material instanceof THREE.MeshLambertMaterial ||
  13677. material.lights ) {
  13678. if ( _lightsNeedUpdate ) {
  13679. refreshLights = true;
  13680. setupLights( lights, camera );
  13681. _lightsNeedUpdate = false;
  13682. }
  13683. if ( refreshLights ) {
  13684. refreshUniformsLights( m_uniforms, _lights );
  13685. markUniformsLightsNeedsUpdate( m_uniforms, true );
  13686. } else {
  13687. markUniformsLightsNeedsUpdate( m_uniforms, false );
  13688. }
  13689. }
  13690. if ( material instanceof THREE.MeshBasicMaterial ||
  13691. material instanceof THREE.MeshLambertMaterial ||
  13692. material instanceof THREE.MeshPhongMaterial ) {
  13693. refreshUniformsCommon( m_uniforms, material );
  13694. }
  13695. // refresh single material specific uniforms
  13696. if ( material instanceof THREE.LineBasicMaterial ) {
  13697. refreshUniformsLine( m_uniforms, material );
  13698. } else if ( material instanceof THREE.LineDashedMaterial ) {
  13699. refreshUniformsLine( m_uniforms, material );
  13700. refreshUniformsDash( m_uniforms, material );
  13701. } else if ( material instanceof THREE.PointsMaterial ) {
  13702. refreshUniformsParticle( m_uniforms, material );
  13703. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  13704. refreshUniformsPhong( m_uniforms, material );
  13705. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  13706. m_uniforms.mNear.value = camera.near;
  13707. m_uniforms.mFar.value = camera.far;
  13708. m_uniforms.opacity.value = material.opacity;
  13709. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  13710. m_uniforms.opacity.value = material.opacity;
  13711. }
  13712. if ( object.receiveShadow && ! material._shadowPass ) {
  13713. refreshUniformsShadow( m_uniforms, lights, camera );
  13714. }
  13715. // load common uniforms
  13716. loadUniformsGeneric( materialProperties.uniformsList );
  13717. }
  13718. loadUniformsMatrices( p_uniforms, object );
  13719. if ( p_uniforms.modelMatrix !== undefined ) {
  13720. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  13721. }
  13722. return program;
  13723. }
  13724. // Uniforms (refresh uniforms objects)
  13725. function refreshUniformsCommon ( uniforms, material ) {
  13726. uniforms.opacity.value = material.opacity;
  13727. uniforms.diffuse.value = material.color;
  13728. if ( material.emissive ) {
  13729. uniforms.emissive.value = material.emissive;
  13730. }
  13731. uniforms.map.value = material.map;
  13732. uniforms.specularMap.value = material.specularMap;
  13733. uniforms.alphaMap.value = material.alphaMap;
  13734. if ( material.aoMap ) {
  13735. uniforms.aoMap.value = material.aoMap;
  13736. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13737. }
  13738. // uv repeat and offset setting priorities
  13739. // 1. color map
  13740. // 2. specular map
  13741. // 3. normal map
  13742. // 4. bump map
  13743. // 5. alpha map
  13744. // 6. emissive map
  13745. var uvScaleMap;
  13746. if ( material.map ) {
  13747. uvScaleMap = material.map;
  13748. } else if ( material.specularMap ) {
  13749. uvScaleMap = material.specularMap;
  13750. } else if ( material.displacementMap ) {
  13751. uvScaleMap = material.displacementMap;
  13752. } else if ( material.normalMap ) {
  13753. uvScaleMap = material.normalMap;
  13754. } else if ( material.bumpMap ) {
  13755. uvScaleMap = material.bumpMap;
  13756. } else if ( material.alphaMap ) {
  13757. uvScaleMap = material.alphaMap;
  13758. } else if ( material.emissiveMap ) {
  13759. uvScaleMap = material.emissiveMap;
  13760. }
  13761. if ( uvScaleMap !== undefined ) {
  13762. var offset = uvScaleMap.offset;
  13763. var repeat = uvScaleMap.repeat;
  13764. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13765. }
  13766. uniforms.envMap.value = material.envMap;
  13767. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13768. uniforms.reflectivity.value = material.reflectivity;
  13769. uniforms.refractionRatio.value = material.refractionRatio;
  13770. }
  13771. function refreshUniformsLine ( uniforms, material ) {
  13772. uniforms.diffuse.value = material.color;
  13773. uniforms.opacity.value = material.opacity;
  13774. }
  13775. function refreshUniformsDash ( uniforms, material ) {
  13776. uniforms.dashSize.value = material.dashSize;
  13777. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13778. uniforms.scale.value = material.scale;
  13779. }
  13780. function refreshUniformsParticle ( uniforms, material ) {
  13781. uniforms.psColor.value = material.color;
  13782. uniforms.opacity.value = material.opacity;
  13783. uniforms.size.value = material.size;
  13784. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13785. uniforms.map.value = material.map;
  13786. if ( material.map !== null ) {
  13787. var offset = material.map.offset;
  13788. var repeat = material.map.repeat;
  13789. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13790. }
  13791. }
  13792. function refreshUniformsFog ( uniforms, fog ) {
  13793. uniforms.fogColor.value = fog.color;
  13794. if ( fog instanceof THREE.Fog ) {
  13795. uniforms.fogNear.value = fog.near;
  13796. uniforms.fogFar.value = fog.far;
  13797. } else if ( fog instanceof THREE.FogExp2 ) {
  13798. uniforms.fogDensity.value = fog.density;
  13799. }
  13800. }
  13801. function refreshUniformsPhong ( uniforms, material ) {
  13802. uniforms.specular.value = material.specular;
  13803. uniforms.shininess.value = material.shininess;
  13804. if ( material.lightMap ) {
  13805. uniforms.lightMap.value = material.lightMap;
  13806. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13807. }
  13808. if ( material.emissiveMap ) {
  13809. uniforms.emissiveMap.value = material.emissiveMap;
  13810. }
  13811. if ( material.bumpMap ) {
  13812. uniforms.bumpMap.value = material.bumpMap;
  13813. uniforms.bumpScale.value = material.bumpScale;
  13814. }
  13815. if ( material.normalMap ) {
  13816. uniforms.normalMap.value = material.normalMap;
  13817. uniforms.normalScale.value.copy( material.normalScale );
  13818. }
  13819. if ( material.displacementMap ) {
  13820. uniforms.displacementMap.value = material.displacementMap;
  13821. uniforms.displacementScale.value = material.displacementScale;
  13822. uniforms.displacementBias.value = material.displacementBias;
  13823. }
  13824. }
  13825. function refreshUniformsLights ( uniforms, lights ) {
  13826. uniforms.ambientLightColor.value = lights.ambient;
  13827. uniforms.directionalLightColor.value = lights.directional.colors;
  13828. uniforms.directionalLightDirection.value = lights.directional.positions;
  13829. uniforms.pointLightColor.value = lights.point.colors;
  13830. uniforms.pointLightPosition.value = lights.point.positions;
  13831. uniforms.pointLightDistance.value = lights.point.distances;
  13832. uniforms.pointLightDecay.value = lights.point.decays;
  13833. uniforms.spotLightColor.value = lights.spot.colors;
  13834. uniforms.spotLightPosition.value = lights.spot.positions;
  13835. uniforms.spotLightDistance.value = lights.spot.distances;
  13836. uniforms.spotLightDirection.value = lights.spot.directions;
  13837. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13838. uniforms.spotLightExponent.value = lights.spot.exponents;
  13839. uniforms.spotLightDecay.value = lights.spot.decays;
  13840. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13841. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13842. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13843. }
  13844. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13845. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13846. uniforms.ambientLightColor.needsUpdate = value;
  13847. uniforms.directionalLightColor.needsUpdate = value;
  13848. uniforms.directionalLightDirection.needsUpdate = value;
  13849. uniforms.pointLightColor.needsUpdate = value;
  13850. uniforms.pointLightPosition.needsUpdate = value;
  13851. uniforms.pointLightDistance.needsUpdate = value;
  13852. uniforms.pointLightDecay.needsUpdate = value;
  13853. uniforms.spotLightColor.needsUpdate = value;
  13854. uniforms.spotLightPosition.needsUpdate = value;
  13855. uniforms.spotLightDistance.needsUpdate = value;
  13856. uniforms.spotLightDirection.needsUpdate = value;
  13857. uniforms.spotLightAngleCos.needsUpdate = value;
  13858. uniforms.spotLightExponent.needsUpdate = value;
  13859. uniforms.spotLightDecay.needsUpdate = value;
  13860. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13861. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13862. uniforms.hemisphereLightDirection.needsUpdate = value;
  13863. }
  13864. function refreshUniformsShadow ( uniforms, lights, camera ) {
  13865. if ( uniforms.shadowMatrix ) {
  13866. var j = 0;
  13867. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13868. var light = lights[ i ];
  13869. if ( ! light.castShadow ) continue;
  13870. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  13871. if ( light instanceof THREE.PointLight ) {
  13872. // for point lights we set the sign of the shadowDarkness uniform to be negative
  13873. uniforms.shadowDarkness.value[ j ] = - light.shadowDarkness;
  13874. } else {
  13875. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13876. }
  13877. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13878. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13879. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13880. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13881. j ++;
  13882. }
  13883. }
  13884. }
  13885. }
  13886. // Uniforms (load to GPU)
  13887. function loadUniformsMatrices ( uniforms, object ) {
  13888. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  13889. if ( uniforms.normalMatrix ) {
  13890. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  13891. }
  13892. }
  13893. function getTextureUnit() {
  13894. var textureUnit = _usedTextureUnits;
  13895. if ( textureUnit >= capabilities.maxTextures ) {
  13896. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13897. }
  13898. _usedTextureUnits += 1;
  13899. return textureUnit;
  13900. }
  13901. function loadUniformsGeneric ( uniforms ) {
  13902. var texture, textureUnit;
  13903. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13904. var uniform = uniforms[ j ][ 0 ];
  13905. // needsUpdate property is not added to all uniforms.
  13906. if ( uniform.needsUpdate === false ) continue;
  13907. var type = uniform.type;
  13908. var value = uniform.value;
  13909. var location = uniforms[ j ][ 1 ];
  13910. switch ( type ) {
  13911. case '1i':
  13912. _gl.uniform1i( location, value );
  13913. break;
  13914. case '1f':
  13915. _gl.uniform1f( location, value );
  13916. break;
  13917. case '2f':
  13918. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13919. break;
  13920. case '3f':
  13921. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13922. break;
  13923. case '4f':
  13924. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13925. break;
  13926. case '1iv':
  13927. _gl.uniform1iv( location, value );
  13928. break;
  13929. case '3iv':
  13930. _gl.uniform3iv( location, value );
  13931. break;
  13932. case '1fv':
  13933. _gl.uniform1fv( location, value );
  13934. break;
  13935. case '2fv':
  13936. _gl.uniform2fv( location, value );
  13937. break;
  13938. case '3fv':
  13939. _gl.uniform3fv( location, value );
  13940. break;
  13941. case '4fv':
  13942. _gl.uniform4fv( location, value );
  13943. break;
  13944. case 'Matrix3fv':
  13945. _gl.uniformMatrix3fv( location, false, value );
  13946. break;
  13947. case 'Matrix4fv':
  13948. _gl.uniformMatrix4fv( location, false, value );
  13949. break;
  13950. //
  13951. case 'i':
  13952. // single integer
  13953. _gl.uniform1i( location, value );
  13954. break;
  13955. case 'f':
  13956. // single float
  13957. _gl.uniform1f( location, value );
  13958. break;
  13959. case 'v2':
  13960. // single THREE.Vector2
  13961. _gl.uniform2f( location, value.x, value.y );
  13962. break;
  13963. case 'v3':
  13964. // single THREE.Vector3
  13965. _gl.uniform3f( location, value.x, value.y, value.z );
  13966. break;
  13967. case 'v4':
  13968. // single THREE.Vector4
  13969. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13970. break;
  13971. case 'c':
  13972. // single THREE.Color
  13973. _gl.uniform3f( location, value.r, value.g, value.b );
  13974. break;
  13975. case 'iv1':
  13976. // flat array of integers (JS or typed array)
  13977. _gl.uniform1iv( location, value );
  13978. break;
  13979. case 'iv':
  13980. // flat array of integers with 3 x N size (JS or typed array)
  13981. _gl.uniform3iv( location, value );
  13982. break;
  13983. case 'fv1':
  13984. // flat array of floats (JS or typed array)
  13985. _gl.uniform1fv( location, value );
  13986. break;
  13987. case 'fv':
  13988. // flat array of floats with 3 x N size (JS or typed array)
  13989. _gl.uniform3fv( location, value );
  13990. break;
  13991. case 'v2v':
  13992. // array of THREE.Vector2
  13993. if ( uniform._array === undefined ) {
  13994. uniform._array = new Float32Array( 2 * value.length );
  13995. }
  13996. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  13997. uniform._array[ i2 + 0 ] = value[ i ].x;
  13998. uniform._array[ i2 + 1 ] = value[ i ].y;
  13999. }
  14000. _gl.uniform2fv( location, uniform._array );
  14001. break;
  14002. case 'v3v':
  14003. // array of THREE.Vector3
  14004. if ( uniform._array === undefined ) {
  14005. uniform._array = new Float32Array( 3 * value.length );
  14006. }
  14007. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  14008. uniform._array[ i3 + 0 ] = value[ i ].x;
  14009. uniform._array[ i3 + 1 ] = value[ i ].y;
  14010. uniform._array[ i3 + 2 ] = value[ i ].z;
  14011. }
  14012. _gl.uniform3fv( location, uniform._array );
  14013. break;
  14014. case 'v4v':
  14015. // array of THREE.Vector4
  14016. if ( uniform._array === undefined ) {
  14017. uniform._array = new Float32Array( 4 * value.length );
  14018. }
  14019. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  14020. uniform._array[ i4 + 0 ] = value[ i ].x;
  14021. uniform._array[ i4 + 1 ] = value[ i ].y;
  14022. uniform._array[ i4 + 2 ] = value[ i ].z;
  14023. uniform._array[ i4 + 3 ] = value[ i ].w;
  14024. }
  14025. _gl.uniform4fv( location, uniform._array );
  14026. break;
  14027. case 'm3':
  14028. // single THREE.Matrix3
  14029. _gl.uniformMatrix3fv( location, false, value.elements );
  14030. break;
  14031. case 'm3v':
  14032. // array of THREE.Matrix3
  14033. if ( uniform._array === undefined ) {
  14034. uniform._array = new Float32Array( 9 * value.length );
  14035. }
  14036. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14037. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  14038. }
  14039. _gl.uniformMatrix3fv( location, false, uniform._array );
  14040. break;
  14041. case 'm4':
  14042. // single THREE.Matrix4
  14043. _gl.uniformMatrix4fv( location, false, value.elements );
  14044. break;
  14045. case 'm4v':
  14046. // array of THREE.Matrix4
  14047. if ( uniform._array === undefined ) {
  14048. uniform._array = new Float32Array( 16 * value.length );
  14049. }
  14050. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14051. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  14052. }
  14053. _gl.uniformMatrix4fv( location, false, uniform._array );
  14054. break;
  14055. case 't':
  14056. // single THREE.Texture (2d or cube)
  14057. texture = value;
  14058. textureUnit = getTextureUnit();
  14059. _gl.uniform1i( location, textureUnit );
  14060. if ( ! texture ) continue;
  14061. if ( texture instanceof THREE.CubeTexture ||
  14062. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14063. // CompressedTexture can have Array in image :/
  14064. setCubeTexture( texture, textureUnit );
  14065. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14066. setCubeTextureDynamic( texture, textureUnit );
  14067. } else {
  14068. _this.setTexture( texture, textureUnit );
  14069. }
  14070. break;
  14071. case 'tv':
  14072. // array of THREE.Texture (2d or cube)
  14073. if ( uniform._array === undefined ) {
  14074. uniform._array = [];
  14075. }
  14076. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14077. uniform._array[ i ] = getTextureUnit();
  14078. }
  14079. _gl.uniform1iv( location, uniform._array );
  14080. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14081. texture = uniform.value[ i ];
  14082. textureUnit = uniform._array[ i ];
  14083. if ( ! texture ) continue;
  14084. if ( texture instanceof THREE.CubeTexture ||
  14085. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  14086. // CompressedTexture can have Array in image :/
  14087. setCubeTexture( texture, textureUnit );
  14088. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14089. setCubeTextureDynamic( texture, textureUnit );
  14090. } else {
  14091. _this.setTexture( texture, textureUnit );
  14092. }
  14093. }
  14094. break;
  14095. default:
  14096. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  14097. }
  14098. }
  14099. }
  14100. function setColorLinear( array, offset, color, intensity ) {
  14101. array[ offset + 0 ] = color.r * intensity;
  14102. array[ offset + 1 ] = color.g * intensity;
  14103. array[ offset + 2 ] = color.b * intensity;
  14104. }
  14105. function setupLights ( lights, camera ) {
  14106. var l, ll, light,
  14107. r = 0, g = 0, b = 0,
  14108. color, skyColor, groundColor,
  14109. intensity,
  14110. distance,
  14111. zlights = _lights,
  14112. viewMatrix = camera.matrixWorldInverse,
  14113. dirColors = zlights.directional.colors,
  14114. dirPositions = zlights.directional.positions,
  14115. pointColors = zlights.point.colors,
  14116. pointPositions = zlights.point.positions,
  14117. pointDistances = zlights.point.distances,
  14118. pointDecays = zlights.point.decays,
  14119. spotColors = zlights.spot.colors,
  14120. spotPositions = zlights.spot.positions,
  14121. spotDistances = zlights.spot.distances,
  14122. spotDirections = zlights.spot.directions,
  14123. spotAnglesCos = zlights.spot.anglesCos,
  14124. spotExponents = zlights.spot.exponents,
  14125. spotDecays = zlights.spot.decays,
  14126. hemiSkyColors = zlights.hemi.skyColors,
  14127. hemiGroundColors = zlights.hemi.groundColors,
  14128. hemiPositions = zlights.hemi.positions,
  14129. dirLength = 0,
  14130. pointLength = 0,
  14131. spotLength = 0,
  14132. hemiLength = 0,
  14133. dirCount = 0,
  14134. pointCount = 0,
  14135. spotCount = 0,
  14136. hemiCount = 0,
  14137. dirOffset = 0,
  14138. pointOffset = 0,
  14139. spotOffset = 0,
  14140. hemiOffset = 0;
  14141. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  14142. light = lights[ l ];
  14143. if ( light.onlyShadow ) continue;
  14144. color = light.color;
  14145. intensity = light.intensity;
  14146. distance = light.distance;
  14147. if ( light instanceof THREE.AmbientLight ) {
  14148. if ( ! light.visible ) continue;
  14149. r += color.r;
  14150. g += color.g;
  14151. b += color.b;
  14152. } else if ( light instanceof THREE.DirectionalLight ) {
  14153. dirCount += 1;
  14154. if ( ! light.visible ) continue;
  14155. _direction.setFromMatrixPosition( light.matrixWorld );
  14156. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14157. _direction.sub( _vector3 );
  14158. _direction.transformDirection( viewMatrix );
  14159. dirOffset = dirLength * 3;
  14160. dirPositions[ dirOffset + 0 ] = _direction.x;
  14161. dirPositions[ dirOffset + 1 ] = _direction.y;
  14162. dirPositions[ dirOffset + 2 ] = _direction.z;
  14163. setColorLinear( dirColors, dirOffset, color, intensity );
  14164. dirLength += 1;
  14165. } else if ( light instanceof THREE.PointLight ) {
  14166. pointCount += 1;
  14167. if ( ! light.visible ) continue;
  14168. pointOffset = pointLength * 3;
  14169. setColorLinear( pointColors, pointOffset, color, intensity );
  14170. _vector3.setFromMatrixPosition( light.matrixWorld );
  14171. _vector3.applyMatrix4( viewMatrix );
  14172. pointPositions[ pointOffset + 0 ] = _vector3.x;
  14173. pointPositions[ pointOffset + 1 ] = _vector3.y;
  14174. pointPositions[ pointOffset + 2 ] = _vector3.z;
  14175. // distance is 0 if decay is 0, because there is no attenuation at all.
  14176. pointDistances[ pointLength ] = distance;
  14177. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14178. pointLength += 1;
  14179. } else if ( light instanceof THREE.SpotLight ) {
  14180. spotCount += 1;
  14181. if ( ! light.visible ) continue;
  14182. spotOffset = spotLength * 3;
  14183. setColorLinear( spotColors, spotOffset, color, intensity );
  14184. _direction.setFromMatrixPosition( light.matrixWorld );
  14185. _vector3.copy( _direction ).applyMatrix4( viewMatrix );
  14186. spotPositions[ spotOffset + 0 ] = _vector3.x;
  14187. spotPositions[ spotOffset + 1 ] = _vector3.y;
  14188. spotPositions[ spotOffset + 2 ] = _vector3.z;
  14189. spotDistances[ spotLength ] = distance;
  14190. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14191. _direction.sub( _vector3 );
  14192. _direction.transformDirection( viewMatrix );
  14193. spotDirections[ spotOffset + 0 ] = _direction.x;
  14194. spotDirections[ spotOffset + 1 ] = _direction.y;
  14195. spotDirections[ spotOffset + 2 ] = _direction.z;
  14196. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  14197. spotExponents[ spotLength ] = light.exponent;
  14198. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14199. spotLength += 1;
  14200. } else if ( light instanceof THREE.HemisphereLight ) {
  14201. hemiCount += 1;
  14202. if ( ! light.visible ) continue;
  14203. _direction.setFromMatrixPosition( light.matrixWorld );
  14204. _direction.transformDirection( viewMatrix );
  14205. hemiOffset = hemiLength * 3;
  14206. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  14207. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  14208. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  14209. skyColor = light.color;
  14210. groundColor = light.groundColor;
  14211. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  14212. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  14213. hemiLength += 1;
  14214. }
  14215. }
  14216. // null eventual remains from removed lights
  14217. // (this is to avoid if in shader)
  14218. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  14219. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  14220. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  14221. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  14222. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  14223. zlights.directional.length = dirLength;
  14224. zlights.point.length = pointLength;
  14225. zlights.spot.length = spotLength;
  14226. zlights.hemi.length = hemiLength;
  14227. zlights.ambient[ 0 ] = r;
  14228. zlights.ambient[ 1 ] = g;
  14229. zlights.ambient[ 2 ] = b;
  14230. }
  14231. // GL state setting
  14232. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  14233. if ( cullFace === THREE.CullFaceNone ) {
  14234. state.disable( _gl.CULL_FACE );
  14235. } else {
  14236. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  14237. _gl.frontFace( _gl.CW );
  14238. } else {
  14239. _gl.frontFace( _gl.CCW );
  14240. }
  14241. if ( cullFace === THREE.CullFaceBack ) {
  14242. _gl.cullFace( _gl.BACK );
  14243. } else if ( cullFace === THREE.CullFaceFront ) {
  14244. _gl.cullFace( _gl.FRONT );
  14245. } else {
  14246. _gl.cullFace( _gl.FRONT_AND_BACK );
  14247. }
  14248. state.enable( _gl.CULL_FACE );
  14249. }
  14250. };
  14251. // Textures
  14252. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  14253. var extension;
  14254. if ( isImagePowerOfTwo ) {
  14255. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  14256. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  14257. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  14258. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  14259. } else {
  14260. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  14261. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  14262. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  14263. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  14264. }
  14265. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  14266. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  14267. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  14268. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  14269. }
  14270. }
  14271. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14272. if ( extension ) {
  14273. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  14274. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  14275. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  14276. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  14277. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  14278. }
  14279. }
  14280. }
  14281. function uploadTexture( textureProperties, texture, slot ) {
  14282. if ( textureProperties.__webglInit === undefined ) {
  14283. textureProperties.__webglInit = true;
  14284. texture.__webglInit = true;
  14285. texture.addEventListener( 'dispose', onTextureDispose );
  14286. textureProperties.__webglTexture = _gl.createTexture();
  14287. _infoMemory.textures ++;
  14288. }
  14289. state.activeTexture( _gl.TEXTURE0 + slot );
  14290. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14291. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14292. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  14293. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  14294. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  14295. var image = texture.image,
  14296. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14297. glFormat = paramThreeToGL( texture.format ),
  14298. glType = paramThreeToGL( texture.type );
  14299. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  14300. var mipmap, mipmaps = texture.mipmaps;
  14301. if ( texture instanceof THREE.DataTexture ) {
  14302. // use manually created mipmaps if available
  14303. // if there are no manual mipmaps
  14304. // set 0 level mipmap and then use GL to generate other mipmap levels
  14305. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14306. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14307. mipmap = mipmaps[ i ];
  14308. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14309. }
  14310. texture.generateMipmaps = false;
  14311. } else {
  14312. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  14313. }
  14314. } else if ( texture instanceof THREE.CompressedTexture ) {
  14315. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14316. mipmap = mipmaps[ i ];
  14317. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14318. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14319. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14320. } else {
  14321. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  14322. }
  14323. } else {
  14324. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14325. }
  14326. }
  14327. } else {
  14328. // regular Texture (image, video, canvas)
  14329. // use manually created mipmaps if available
  14330. // if there are no manual mipmaps
  14331. // set 0 level mipmap and then use GL to generate other mipmap levels
  14332. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14333. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14334. mipmap = mipmaps[ i ];
  14335. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  14336. }
  14337. texture.generateMipmaps = false;
  14338. } else {
  14339. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  14340. }
  14341. }
  14342. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14343. textureProperties.__version = texture.version;
  14344. if ( texture.onUpdate ) texture.onUpdate( texture );
  14345. }
  14346. this.setTexture = function ( texture, slot ) {
  14347. var textureProperties = properties.get( texture );
  14348. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14349. var image = texture.image;
  14350. if ( image === undefined ) {
  14351. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  14352. return;
  14353. }
  14354. if ( image.complete === false ) {
  14355. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  14356. return;
  14357. }
  14358. uploadTexture( textureProperties, texture, slot );
  14359. return;
  14360. }
  14361. state.activeTexture( _gl.TEXTURE0 + slot );
  14362. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14363. };
  14364. function clampToMaxSize ( image, maxSize ) {
  14365. if ( image.width > maxSize || image.height > maxSize ) {
  14366. // Warning: Scaling through the canvas will only work with images that use
  14367. // premultiplied alpha.
  14368. var scale = maxSize / Math.max( image.width, image.height );
  14369. var canvas = document.createElement( 'canvas' );
  14370. canvas.width = Math.floor( image.width * scale );
  14371. canvas.height = Math.floor( image.height * scale );
  14372. var context = canvas.getContext( '2d' );
  14373. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  14374. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  14375. return canvas;
  14376. }
  14377. return image;
  14378. }
  14379. function setCubeTexture ( texture, slot ) {
  14380. var textureProperties = properties.get( texture );
  14381. if ( texture.image.length === 6 ) {
  14382. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14383. if ( ! textureProperties.__image__webglTextureCube ) {
  14384. texture.addEventListener( 'dispose', onTextureDispose );
  14385. textureProperties.__image__webglTextureCube = _gl.createTexture();
  14386. _infoMemory.textures ++;
  14387. }
  14388. state.activeTexture( _gl.TEXTURE0 + slot );
  14389. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14390. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14391. var isCompressed = texture instanceof THREE.CompressedTexture;
  14392. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  14393. var cubeImage = [];
  14394. for ( var i = 0; i < 6; i ++ ) {
  14395. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  14396. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  14397. } else {
  14398. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  14399. }
  14400. }
  14401. var image = cubeImage[ 0 ],
  14402. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14403. glFormat = paramThreeToGL( texture.format ),
  14404. glType = paramThreeToGL( texture.type );
  14405. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  14406. for ( var i = 0; i < 6; i ++ ) {
  14407. if ( ! isCompressed ) {
  14408. if ( isDataTexture ) {
  14409. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  14410. } else {
  14411. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  14412. }
  14413. } else {
  14414. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  14415. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  14416. mipmap = mipmaps[ j ];
  14417. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14418. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14419. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14420. } else {
  14421. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  14422. }
  14423. } else {
  14424. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14425. }
  14426. }
  14427. }
  14428. }
  14429. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  14430. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14431. }
  14432. textureProperties.__version = texture.version;
  14433. if ( texture.onUpdate ) texture.onUpdate( texture );
  14434. } else {
  14435. state.activeTexture( _gl.TEXTURE0 + slot );
  14436. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14437. }
  14438. }
  14439. }
  14440. function setCubeTextureDynamic ( texture, slot ) {
  14441. state.activeTexture( _gl.TEXTURE0 + slot );
  14442. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  14443. }
  14444. // Render targets
  14445. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  14446. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14447. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  14448. }
  14449. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  14450. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  14451. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14452. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  14453. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14454. /* For some reason this is not working. Defaulting to RGBA4.
  14455. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14456. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  14457. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14458. */
  14459. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14460. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  14461. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14462. } else {
  14463. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  14464. }
  14465. }
  14466. this.setRenderTarget = function ( renderTarget ) {
  14467. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  14468. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14469. var renderTargetProperties = properties.get( renderTarget );
  14470. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  14471. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  14472. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  14473. renderTargetProperties.__webglTexture = _gl.createTexture();
  14474. _infoMemory.textures ++;
  14475. // Setup texture, create render and frame buffers
  14476. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  14477. glFormat = paramThreeToGL( renderTarget.format ),
  14478. glType = paramThreeToGL( renderTarget.type );
  14479. if ( isCube ) {
  14480. renderTargetProperties.__webglFramebuffer = [];
  14481. renderTargetProperties.__webglRenderbuffer = [];
  14482. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  14483. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  14484. for ( var i = 0; i < 6; i ++ ) {
  14485. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  14486. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  14487. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14488. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  14489. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  14490. }
  14491. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14492. } else {
  14493. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  14494. if ( renderTarget.shareDepthFrom ) {
  14495. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  14496. } else {
  14497. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  14498. }
  14499. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  14500. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  14501. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14502. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  14503. if ( renderTarget.shareDepthFrom ) {
  14504. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14505. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14506. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14507. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14508. }
  14509. } else {
  14510. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  14511. }
  14512. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14513. }
  14514. // Release everything
  14515. if ( isCube ) {
  14516. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  14517. } else {
  14518. state.bindTexture( _gl.TEXTURE_2D, null );
  14519. }
  14520. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  14521. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  14522. }
  14523. var framebuffer, width, height, vx, vy;
  14524. if ( renderTarget ) {
  14525. var renderTargetProperties = properties.get( renderTarget );
  14526. if ( isCube ) {
  14527. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  14528. } else {
  14529. framebuffer = renderTargetProperties.__webglFramebuffer;
  14530. }
  14531. width = renderTarget.width;
  14532. height = renderTarget.height;
  14533. vx = 0;
  14534. vy = 0;
  14535. } else {
  14536. framebuffer = null;
  14537. width = _viewportWidth;
  14538. height = _viewportHeight;
  14539. vx = _viewportX;
  14540. vy = _viewportY;
  14541. }
  14542. if ( framebuffer !== _currentFramebuffer ) {
  14543. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14544. _gl.viewport( vx, vy, width, height );
  14545. _currentFramebuffer = framebuffer;
  14546. }
  14547. if ( isCube ) {
  14548. var renderTargetProperties = properties.get( renderTarget );
  14549. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, renderTargetProperties.__webglTexture, 0 );
  14550. }
  14551. _currentWidth = width;
  14552. _currentHeight = height;
  14553. };
  14554. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  14555. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  14556. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14557. return;
  14558. }
  14559. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  14560. var restore = false;
  14561. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  14562. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  14563. restore = true;
  14564. }
  14565. if ( renderTarget.format !== THREE.RGBAFormat && paramThreeToGL( renderTarget.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14566. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14567. return;
  14568. }
  14569. if ( renderTarget.type !== THREE.UnsignedByteType && paramThreeToGL( renderTarget.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) ) {
  14570. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14571. return;
  14572. }
  14573. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14574. _gl.readPixels( x, y, width, height, paramThreeToGL( renderTarget.format ), paramThreeToGL( renderTarget.type ), buffer );
  14575. } else {
  14576. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14577. }
  14578. if ( restore ) {
  14579. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14580. }
  14581. }
  14582. };
  14583. function updateRenderTargetMipmap( renderTarget ) {
  14584. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  14585. var texture = properties.get( renderTarget ).__webglTexture;
  14586. state.bindTexture( target, texture );
  14587. _gl.generateMipmap( target );
  14588. state.bindTexture( target, null );
  14589. }
  14590. // Fallback filters for non-power-of-2 textures
  14591. function filterFallback ( f ) {
  14592. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  14593. return _gl.NEAREST;
  14594. }
  14595. return _gl.LINEAR;
  14596. }
  14597. // Map three.js constants to WebGL constants
  14598. function paramThreeToGL ( p ) {
  14599. var extension;
  14600. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  14601. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  14602. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  14603. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  14604. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  14605. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  14606. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  14607. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  14608. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  14609. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  14610. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  14611. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  14612. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  14613. if ( p === THREE.ByteType ) return _gl.BYTE;
  14614. if ( p === THREE.ShortType ) return _gl.SHORT;
  14615. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  14616. if ( p === THREE.IntType ) return _gl.INT;
  14617. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  14618. if ( p === THREE.FloatType ) return _gl.FLOAT;
  14619. extension = extensions.get( 'OES_texture_half_float' );
  14620. if ( extension !== null ) {
  14621. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  14622. }
  14623. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  14624. if ( p === THREE.RGBFormat ) return _gl.RGB;
  14625. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  14626. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  14627. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  14628. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  14629. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  14630. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  14631. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  14632. if ( p === THREE.OneFactor ) return _gl.ONE;
  14633. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  14634. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  14635. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  14636. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  14637. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  14638. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  14639. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  14640. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  14641. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  14642. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14643. if ( extension !== null ) {
  14644. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14645. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14646. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14647. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14648. }
  14649. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14650. if ( extension !== null ) {
  14651. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14652. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14653. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14654. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14655. }
  14656. extension = extensions.get( 'EXT_blend_minmax' );
  14657. if ( extension !== null ) {
  14658. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  14659. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  14660. }
  14661. return 0;
  14662. }
  14663. // DEPRECATED
  14664. this.supportsFloatTextures = function () {
  14665. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  14666. return extensions.get( 'OES_texture_float' );
  14667. };
  14668. this.supportsHalfFloatTextures = function () {
  14669. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  14670. return extensions.get( 'OES_texture_half_float' );
  14671. };
  14672. this.supportsStandardDerivatives = function () {
  14673. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  14674. return extensions.get( 'OES_standard_derivatives' );
  14675. };
  14676. this.supportsCompressedTextureS3TC = function () {
  14677. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  14678. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14679. };
  14680. this.supportsCompressedTexturePVRTC = function () {
  14681. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  14682. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14683. };
  14684. this.supportsBlendMinMax = function () {
  14685. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  14686. return extensions.get( 'EXT_blend_minmax' );
  14687. };
  14688. this.supportsVertexTextures = function () {
  14689. return capabilities.vertexTextures;
  14690. };
  14691. this.supportsInstancedArrays = function () {
  14692. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  14693. return extensions.get( 'ANGLE_instanced_arrays' );
  14694. };
  14695. //
  14696. this.initMaterial = function () {
  14697. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  14698. };
  14699. this.addPrePlugin = function () {
  14700. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  14701. };
  14702. this.addPostPlugin = function () {
  14703. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  14704. };
  14705. this.updateShadowMap = function () {
  14706. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  14707. };
  14708. Object.defineProperties( this, {
  14709. shadowMapEnabled: {
  14710. get: function () {
  14711. return shadowMap.enabled;
  14712. },
  14713. set: function ( value ) {
  14714. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  14715. shadowMap.enabled = value;
  14716. }
  14717. },
  14718. shadowMapType: {
  14719. get: function () {
  14720. return shadowMap.type;
  14721. },
  14722. set: function ( value ) {
  14723. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  14724. shadowMap.type = value;
  14725. }
  14726. },
  14727. shadowMapCullFace: {
  14728. get: function () {
  14729. return shadowMap.cullFace;
  14730. },
  14731. set: function ( value ) {
  14732. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  14733. shadowMap.cullFace = value;
  14734. }
  14735. },
  14736. shadowMapDebug: {
  14737. get: function () {
  14738. return shadowMap.debug;
  14739. },
  14740. set: function ( value ) {
  14741. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  14742. shadowMap.debug = value;
  14743. }
  14744. }
  14745. } );
  14746. };
  14747. // File:src/renderers/WebGLRenderTarget.js
  14748. /**
  14749. * @author szimek / https://github.com/szimek/
  14750. * @author alteredq / http://alteredqualia.com/
  14751. */
  14752. THREE.WebGLRenderTarget = function ( width, height, options ) {
  14753. this.uuid = THREE.Math.generateUUID();
  14754. this.width = width;
  14755. this.height = height;
  14756. options = options || {};
  14757. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  14758. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  14759. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  14760. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  14761. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  14762. this.offset = new THREE.Vector2( 0, 0 );
  14763. this.repeat = new THREE.Vector2( 1, 1 );
  14764. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  14765. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  14766. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  14767. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  14768. this.generateMipmaps = true;
  14769. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14770. };
  14771. THREE.WebGLRenderTarget.prototype = {
  14772. constructor: THREE.WebGLRenderTarget,
  14773. setSize: function ( width, height ) {
  14774. if ( this.width !== width || this.height !== height ) {
  14775. this.width = width;
  14776. this.height = height;
  14777. this.dispose();
  14778. }
  14779. },
  14780. clone: function () {
  14781. return new this.constructor().copy( this );
  14782. },
  14783. copy: function ( source ) {
  14784. this.width = source.width;
  14785. this.height = source.height;
  14786. this.wrapS = source.wrapS;
  14787. this.wrapT = source.wrapT;
  14788. this.magFilter = source.magFilter;
  14789. this.minFilter = source.minFilter;
  14790. this.anisotropy = source.anisotropy;
  14791. this.offset.copy( source.offset );
  14792. this.repeat.copy( source.repeat );
  14793. this.format = source.format;
  14794. this.type = source.type;
  14795. this.depthBuffer = source.depthBuffer;
  14796. this.stencilBuffer = source.stencilBuffer;
  14797. this.generateMipmaps = source.generateMipmaps;
  14798. this.shareDepthFrom = source.shareDepthFrom;
  14799. return this;
  14800. },
  14801. dispose: function () {
  14802. this.dispatchEvent( { type: 'dispose' } );
  14803. }
  14804. };
  14805. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14806. // File:src/renderers/WebGLRenderTargetCube.js
  14807. /**
  14808. * @author alteredq / http://alteredqualia.com
  14809. */
  14810. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14811. THREE.WebGLRenderTarget.call( this, width, height, options );
  14812. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14813. };
  14814. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14815. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14816. // File:src/renderers/webgl/WebGLBufferRenderer.js
  14817. /**
  14818. * @author mrdoob / http://mrdoob.com/
  14819. */
  14820. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14821. var mode;
  14822. function setMode( value ) {
  14823. mode = value;
  14824. }
  14825. function render( start, count ) {
  14826. _gl.drawArrays( mode, start, count );
  14827. _infoRender.calls ++;
  14828. _infoRender.vertices += count;
  14829. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14830. }
  14831. function renderInstances( geometry ) {
  14832. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14833. if ( extension === null ) {
  14834. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14835. return;
  14836. }
  14837. var position = geometry.attributes.position;
  14838. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  14839. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  14840. } else {
  14841. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  14842. }
  14843. }
  14844. this.setMode = setMode;
  14845. this.render = render;
  14846. this.renderInstances = renderInstances;
  14847. };
  14848. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  14849. /**
  14850. * @author mrdoob / http://mrdoob.com/
  14851. */
  14852. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14853. var mode;
  14854. function setMode( value ) {
  14855. mode = value;
  14856. }
  14857. var type, size;
  14858. function setIndex( index ) {
  14859. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  14860. type = _gl.UNSIGNED_INT;
  14861. size = 4;
  14862. } else {
  14863. type = _gl.UNSIGNED_SHORT;
  14864. size = 2;
  14865. }
  14866. }
  14867. function render( start, count ) {
  14868. _gl.drawElements( mode, count, type, start * size );
  14869. _infoRender.calls ++;
  14870. _infoRender.vertices += count;
  14871. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14872. }
  14873. function renderInstances( geometry ) {
  14874. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14875. if ( extension === null ) {
  14876. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14877. return;
  14878. }
  14879. var index = geometry.index;
  14880. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  14881. }
  14882. this.setMode = setMode;
  14883. this.setIndex = setIndex;
  14884. this.render = render;
  14885. this.renderInstances = renderInstances;
  14886. };
  14887. // File:src/renderers/webgl/WebGLExtensions.js
  14888. /**
  14889. * @author mrdoob / http://mrdoob.com/
  14890. */
  14891. THREE.WebGLExtensions = function ( gl ) {
  14892. var extensions = {};
  14893. this.get = function ( name ) {
  14894. if ( extensions[ name ] !== undefined ) {
  14895. return extensions[ name ];
  14896. }
  14897. var extension;
  14898. switch ( name ) {
  14899. case 'EXT_texture_filter_anisotropic':
  14900. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14901. break;
  14902. case 'WEBGL_compressed_texture_s3tc':
  14903. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14904. break;
  14905. case 'WEBGL_compressed_texture_pvrtc':
  14906. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14907. break;
  14908. default:
  14909. extension = gl.getExtension( name );
  14910. }
  14911. if ( extension === null ) {
  14912. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14913. }
  14914. extensions[ name ] = extension;
  14915. return extension;
  14916. };
  14917. };
  14918. // File:src/renderers/webgl/WebGLCapabilities.js
  14919. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  14920. function getMaxPrecision( precision ) {
  14921. if ( precision === 'highp' ) {
  14922. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  14923. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  14924. return 'highp';
  14925. }
  14926. precision = 'mediump';
  14927. }
  14928. if ( precision === 'mediump' ) {
  14929. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  14930. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  14931. return 'mediump';
  14932. }
  14933. }
  14934. return 'lowp';
  14935. }
  14936. this.getMaxPrecision = getMaxPrecision;
  14937. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  14938. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  14939. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14940. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  14941. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  14942. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  14943. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  14944. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  14945. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  14946. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  14947. this.vertexTextures = this.maxVertexTextures > 0;
  14948. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  14949. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  14950. var _maxPrecision = getMaxPrecision( this.precision );
  14951. if ( _maxPrecision !== this.precision ) {
  14952. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  14953. this.precision = _maxPrecision;
  14954. }
  14955. if ( this.logarithmicDepthBuffer ) {
  14956. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  14957. }
  14958. };
  14959. // File:src/renderers/webgl/WebGLGeometries.js
  14960. /**
  14961. * @author mrdoob / http://mrdoob.com/
  14962. */
  14963. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14964. var geometries = {};
  14965. function get( object ) {
  14966. var geometry = object.geometry;
  14967. if ( geometries[ geometry.id ] !== undefined ) {
  14968. return geometries[ geometry.id ];
  14969. }
  14970. geometry.addEventListener( 'dispose', onGeometryDispose );
  14971. var buffergeometry;
  14972. if ( geometry instanceof THREE.BufferGeometry ) {
  14973. buffergeometry = geometry;
  14974. } else if ( geometry instanceof THREE.Geometry ) {
  14975. if ( geometry._bufferGeometry === undefined ) {
  14976. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14977. }
  14978. buffergeometry = geometry._bufferGeometry;
  14979. }
  14980. geometries[ geometry.id ] = buffergeometry;
  14981. info.memory.geometries ++;
  14982. return buffergeometry;
  14983. }
  14984. function onGeometryDispose( event ) {
  14985. var geometry = event.target;
  14986. var buffergeometry = geometries[ geometry.id ];
  14987. deleteAttributes( buffergeometry.attributes );
  14988. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14989. delete geometries[ geometry.id ];
  14990. var property = properties.get( geometry );
  14991. if ( property.wireframe ) deleteAttribute( property.wireframe );
  14992. info.memory.geometries --;
  14993. }
  14994. function getAttributeBuffer( attribute ) {
  14995. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14996. return properties.get( attribute.data ).__webglBuffer;
  14997. }
  14998. return properties.get( attribute ).__webglBuffer;
  14999. }
  15000. function deleteAttribute( attribute ) {
  15001. var buffer = getAttributeBuffer( attribute );
  15002. if ( buffer !== undefined ) {
  15003. gl.deleteBuffer( buffer );
  15004. removeAttributeBuffer( attribute );
  15005. }
  15006. }
  15007. function deleteAttributes( attributes ) {
  15008. for ( var name in attributes ) {
  15009. deleteAttribute( attributes[ name ] );
  15010. }
  15011. }
  15012. function removeAttributeBuffer( attribute ) {
  15013. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15014. properties.delete( attribute.data );
  15015. } else {
  15016. properties.delete( attribute );
  15017. }
  15018. }
  15019. this.get = get;
  15020. };
  15021. // File:src/renderers/webgl/WebGLObjects.js
  15022. /**
  15023. * @author mrdoob / http://mrdoob.com/
  15024. */
  15025. THREE.WebGLObjects = function ( gl, properties, info ) {
  15026. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  15027. //
  15028. function update( object ) {
  15029. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  15030. var geometry = geometries.get( object );
  15031. if ( object.geometry instanceof THREE.Geometry ) {
  15032. geometry.updateFromObject( object );
  15033. }
  15034. var index = geometry.index;
  15035. var attributes = geometry.attributes;
  15036. if ( index !== null ) {
  15037. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  15038. }
  15039. for ( var name in attributes ) {
  15040. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  15041. }
  15042. // morph targets
  15043. var morphAttributes = geometry.morphAttributes;
  15044. for ( var name in morphAttributes ) {
  15045. var array = morphAttributes[ name ];
  15046. for ( var i = 0, l = array.length; i < l; i ++ ) {
  15047. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  15048. }
  15049. }
  15050. return geometry;
  15051. }
  15052. function updateAttribute( attribute, bufferType ) {
  15053. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  15054. var attributeProperties = properties.get( data );
  15055. if ( attributeProperties.__webglBuffer === undefined ) {
  15056. createBuffer( attributeProperties, data, bufferType );
  15057. } else if ( attributeProperties.version !== data.version ) {
  15058. updateBuffer( attributeProperties, data, bufferType );
  15059. }
  15060. }
  15061. function createBuffer( attributeProperties, data, bufferType ) {
  15062. attributeProperties.__webglBuffer = gl.createBuffer();
  15063. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15064. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  15065. gl.bufferData( bufferType, data.array, usage );
  15066. attributeProperties.version = data.version;
  15067. }
  15068. function updateBuffer( attributeProperties, data, bufferType ) {
  15069. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15070. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  15071. // Not using update ranges
  15072. gl.bufferSubData( bufferType, 0, data.array );
  15073. } else if ( data.updateRange.count === 0 ) {
  15074. 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.' );
  15075. } else {
  15076. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  15077. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  15078. data.updateRange.count = 0; // reset range
  15079. }
  15080. attributeProperties.version = data.version;
  15081. }
  15082. function getAttributeBuffer( attribute ) {
  15083. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15084. return properties.get( attribute.data ).__webglBuffer;
  15085. }
  15086. return properties.get( attribute ).__webglBuffer;
  15087. }
  15088. function getWireframeAttribute( geometry ) {
  15089. var property = properties.get( geometry );
  15090. if ( property.wireframe !== undefined ) {
  15091. return property.wireframe;
  15092. }
  15093. var indices = [];
  15094. var index = geometry.index;
  15095. var attributes = geometry.attributes;
  15096. var position = attributes.position;
  15097. // console.time( 'wireframe' );
  15098. if ( index !== null ) {
  15099. var edges = {};
  15100. var array = index.array;
  15101. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  15102. var a = array[ i + 0 ];
  15103. var b = array[ i + 1 ];
  15104. var c = array[ i + 2 ];
  15105. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  15106. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  15107. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  15108. }
  15109. } else {
  15110. var array = attributes.position.array;
  15111. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  15112. var a = i + 0;
  15113. var b = i + 1;
  15114. var c = i + 2;
  15115. indices.push( a, b, b, c, c, a );
  15116. }
  15117. }
  15118. // console.timeEnd( 'wireframe' );
  15119. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  15120. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  15121. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  15122. property.wireframe = attribute;
  15123. return attribute;
  15124. }
  15125. function checkEdge( edges, a, b ) {
  15126. if ( a > b ) {
  15127. var tmp = a;
  15128. a = b;
  15129. b = tmp;
  15130. }
  15131. var list = edges[ a ];
  15132. if ( list === undefined ) {
  15133. edges[ a ] = [ b ];
  15134. return true;
  15135. } else if ( list.indexOf( b ) === -1 ) {
  15136. list.push( b );
  15137. return true;
  15138. }
  15139. return false;
  15140. }
  15141. this.getAttributeBuffer = getAttributeBuffer;
  15142. this.getWireframeAttribute = getWireframeAttribute;
  15143. this.update = update;
  15144. };
  15145. // File:src/renderers/webgl/WebGLProgram.js
  15146. THREE.WebGLProgram = ( function () {
  15147. var programIdCount = 0;
  15148. function generateDefines( defines ) {
  15149. var chunks = [];
  15150. for ( var name in defines ) {
  15151. var value = defines[ name ];
  15152. if ( value === false ) continue;
  15153. chunks.push( '#define ' + name + ' ' + value );
  15154. }
  15155. return chunks.join( '\n' );
  15156. }
  15157. function fetchUniformLocations( gl, program, identifiers ) {
  15158. var uniforms = {};
  15159. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  15160. for ( var i = 0; i < n; i ++ ) {
  15161. var info = gl.getActiveUniform( program, i );
  15162. var name = info.name;
  15163. var location = gl.getUniformLocation( program, name );
  15164. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  15165. var suffixPos = name.lastIndexOf( '[0]' );
  15166. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  15167. uniforms[ name.substr( 0, suffixPos ) ] = location;
  15168. }
  15169. uniforms[ name ] = location;
  15170. }
  15171. return uniforms;
  15172. }
  15173. function fetchAttributeLocations( gl, program, identifiers ) {
  15174. var attributes = {};
  15175. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  15176. for ( var i = 0; i < n; i ++ ) {
  15177. var info = gl.getActiveAttrib( program, i );
  15178. var name = info.name;
  15179. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  15180. attributes[ name ] = gl.getAttribLocation( program, name );
  15181. }
  15182. return attributes;
  15183. }
  15184. function filterEmptyLine( string ) {
  15185. return string !== '';
  15186. }
  15187. return function WebGLProgram( renderer, code, material, parameters ) {
  15188. var gl = renderer.context;
  15189. var defines = material.defines;
  15190. var vertexShader = material.__webglShader.vertexShader;
  15191. var fragmentShader = material.__webglShader.fragmentShader;
  15192. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  15193. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  15194. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  15195. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  15196. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  15197. }
  15198. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15199. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  15200. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15201. if ( parameters.envMap ) {
  15202. switch ( material.envMap.mapping ) {
  15203. case THREE.CubeReflectionMapping:
  15204. case THREE.CubeRefractionMapping:
  15205. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15206. break;
  15207. case THREE.EquirectangularReflectionMapping:
  15208. case THREE.EquirectangularRefractionMapping:
  15209. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  15210. break;
  15211. case THREE.SphericalReflectionMapping:
  15212. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  15213. break;
  15214. }
  15215. switch ( material.envMap.mapping ) {
  15216. case THREE.CubeRefractionMapping:
  15217. case THREE.EquirectangularRefractionMapping:
  15218. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  15219. break;
  15220. }
  15221. switch ( material.combine ) {
  15222. case THREE.MultiplyOperation:
  15223. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15224. break;
  15225. case THREE.MixOperation:
  15226. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  15227. break;
  15228. case THREE.AddOperation:
  15229. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  15230. break;
  15231. }
  15232. }
  15233. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  15234. // console.log( 'building new program ' );
  15235. //
  15236. var customDefines = generateDefines( defines );
  15237. //
  15238. var program = gl.createProgram();
  15239. var prefixVertex, prefixFragment;
  15240. if ( material instanceof THREE.RawShaderMaterial ) {
  15241. prefixVertex = '';
  15242. prefixFragment = '';
  15243. } else {
  15244. prefixVertex = [
  15245. 'precision ' + parameters.precision + ' float;',
  15246. 'precision ' + parameters.precision + ' int;',
  15247. '#define SHADER_NAME ' + material.__webglShader.name,
  15248. customDefines,
  15249. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  15250. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15251. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15252. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15253. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15254. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15255. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15256. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15257. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15258. '#define MAX_BONES ' + parameters.maxBones,
  15259. parameters.map ? '#define USE_MAP' : '',
  15260. parameters.envMap ? '#define USE_ENVMAP' : '',
  15261. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15262. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15263. parameters.aoMap ? '#define USE_AOMAP' : '',
  15264. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15265. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15266. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15267. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  15268. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15269. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15270. parameters.vertexColors ? '#define USE_COLOR' : '',
  15271. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15272. parameters.skinning ? '#define USE_SKINNING' : '',
  15273. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  15274. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  15275. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  15276. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15277. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15278. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15279. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15280. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15281. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15282. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  15283. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15284. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15285. 'uniform mat4 modelMatrix;',
  15286. 'uniform mat4 modelViewMatrix;',
  15287. 'uniform mat4 projectionMatrix;',
  15288. 'uniform mat4 viewMatrix;',
  15289. 'uniform mat3 normalMatrix;',
  15290. 'uniform vec3 cameraPosition;',
  15291. 'attribute vec3 position;',
  15292. 'attribute vec3 normal;',
  15293. 'attribute vec2 uv;',
  15294. '#ifdef USE_COLOR',
  15295. ' attribute vec3 color;',
  15296. '#endif',
  15297. '#ifdef USE_MORPHTARGETS',
  15298. ' attribute vec3 morphTarget0;',
  15299. ' attribute vec3 morphTarget1;',
  15300. ' attribute vec3 morphTarget2;',
  15301. ' attribute vec3 morphTarget3;',
  15302. ' #ifdef USE_MORPHNORMALS',
  15303. ' attribute vec3 morphNormal0;',
  15304. ' attribute vec3 morphNormal1;',
  15305. ' attribute vec3 morphNormal2;',
  15306. ' attribute vec3 morphNormal3;',
  15307. ' #else',
  15308. ' attribute vec3 morphTarget4;',
  15309. ' attribute vec3 morphTarget5;',
  15310. ' attribute vec3 morphTarget6;',
  15311. ' attribute vec3 morphTarget7;',
  15312. ' #endif',
  15313. '#endif',
  15314. '#ifdef USE_SKINNING',
  15315. ' attribute vec4 skinIndex;',
  15316. ' attribute vec4 skinWeight;',
  15317. '#endif',
  15318. '\n'
  15319. ].filter( filterEmptyLine ).join( '\n' );
  15320. prefixFragment = [
  15321. parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ? '#extension GL_OES_standard_derivatives : enable' : '',
  15322. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  15323. 'precision ' + parameters.precision + ' float;',
  15324. 'precision ' + parameters.precision + ' int;',
  15325. '#define SHADER_NAME ' + material.__webglShader.name,
  15326. customDefines,
  15327. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15328. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15329. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15330. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15331. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15332. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  15333. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15334. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15335. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15336. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  15337. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  15338. parameters.map ? '#define USE_MAP' : '',
  15339. parameters.envMap ? '#define USE_ENVMAP' : '',
  15340. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  15341. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15342. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  15343. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15344. parameters.aoMap ? '#define USE_AOMAP' : '',
  15345. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15346. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15347. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15348. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15349. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15350. parameters.vertexColors ? '#define USE_COLOR' : '',
  15351. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15352. parameters.metal ? '#define METAL' : '',
  15353. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15354. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15355. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15356. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15357. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15358. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15359. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15360. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15361. 'uniform mat4 viewMatrix;',
  15362. 'uniform vec3 cameraPosition;',
  15363. '\n'
  15364. ].filter( filterEmptyLine ).join( '\n' );
  15365. }
  15366. var vertexGlsl = prefixVertex + vertexShader;
  15367. var fragmentGlsl = prefixFragment + fragmentShader;
  15368. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  15369. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  15370. gl.attachShader( program, glVertexShader );
  15371. gl.attachShader( program, glFragmentShader );
  15372. // Force a particular attribute to index 0.
  15373. if ( material.index0AttributeName !== undefined ) {
  15374. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  15375. } else if ( parameters.morphTargets === true ) {
  15376. // programs with morphTargets displace position out of attribute 0
  15377. gl.bindAttribLocation( program, 0, 'position' );
  15378. }
  15379. gl.linkProgram( program );
  15380. var programLog = gl.getProgramInfoLog( program );
  15381. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  15382. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  15383. var runnable = true;
  15384. var haveDiagnostics = true;
  15385. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  15386. runnable = false;
  15387. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  15388. } else if ( programLog !== '' ) {
  15389. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  15390. } else if ( vertexLog === '' || fragmentLog === '' ) {
  15391. haveDiagnostics = false;
  15392. }
  15393. if ( haveDiagnostics ) {
  15394. this.diagnostics = {
  15395. runnable: runnable,
  15396. material: material,
  15397. programLog: programLog,
  15398. vertexShader: {
  15399. log: vertexLog,
  15400. prefix: prefixVertex
  15401. },
  15402. fragmentShader: {
  15403. log: fragmentLog,
  15404. prefix: prefixFragment
  15405. }
  15406. };
  15407. }
  15408. // clean up
  15409. gl.deleteShader( glVertexShader );
  15410. gl.deleteShader( glFragmentShader );
  15411. // set up caching for uniform locations
  15412. var cachedUniforms;
  15413. this.getUniforms = function() {
  15414. if ( cachedUniforms === undefined ) {
  15415. cachedUniforms = fetchUniformLocations( gl, program );
  15416. }
  15417. return cachedUniforms;
  15418. };
  15419. // set up caching for attribute locations
  15420. var cachedAttributes;
  15421. this.getAttributes = function() {
  15422. if ( cachedAttributes === undefined ) {
  15423. cachedAttributes = fetchAttributeLocations( gl, program );
  15424. }
  15425. return cachedAttributes;
  15426. };
  15427. // free resource
  15428. this.destroy = function() {
  15429. gl.deleteProgram( program );
  15430. this.program = undefined;
  15431. };
  15432. // DEPRECATED
  15433. Object.defineProperties( this, {
  15434. uniforms: {
  15435. get: function() {
  15436. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  15437. return this.getUniforms();
  15438. }
  15439. },
  15440. attributes: {
  15441. get: function() {
  15442. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  15443. return this.getAttributes();
  15444. }
  15445. }
  15446. } );
  15447. //
  15448. this.id = programIdCount ++;
  15449. this.code = code;
  15450. this.usedTimes = 1;
  15451. this.program = program;
  15452. this.vertexShader = glVertexShader;
  15453. this.fragmentShader = glFragmentShader;
  15454. return this;
  15455. };
  15456. } )();
  15457. // File:src/renderers/webgl/WebGLPrograms.js
  15458. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  15459. var programs = [];
  15460. var shaderIDs = {
  15461. MeshDepthMaterial: 'depth',
  15462. MeshNormalMaterial: 'normal',
  15463. MeshBasicMaterial: 'basic',
  15464. MeshLambertMaterial: 'lambert',
  15465. MeshPhongMaterial: 'phong',
  15466. LineBasicMaterial: 'basic',
  15467. LineDashedMaterial: 'dashed',
  15468. PointsMaterial: 'points'
  15469. };
  15470. var parameterNames = [
  15471. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  15472. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "specularMap",
  15473. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  15474. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  15475. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  15476. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  15477. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  15478. "shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
  15479. "flipSided"
  15480. ];
  15481. function allocateBones ( object ) {
  15482. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  15483. return 1024;
  15484. } else {
  15485. // default for when object is not specified
  15486. // ( for example when prebuilding shader to be used with multiple objects )
  15487. //
  15488. // - leave some extra space for other uniforms
  15489. // - limit here is ANGLE's 254 max uniform vectors
  15490. // (up to 54 should be safe)
  15491. var nVertexUniforms = capabilities.maxVertexUniforms;
  15492. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  15493. var maxBones = nVertexMatrices;
  15494. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  15495. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  15496. if ( maxBones < object.skeleton.bones.length ) {
  15497. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  15498. }
  15499. }
  15500. return maxBones;
  15501. }
  15502. }
  15503. function allocateLights( lights ) {
  15504. var dirLights = 0;
  15505. var pointLights = 0;
  15506. var spotLights = 0;
  15507. var hemiLights = 0;
  15508. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15509. var light = lights[ l ];
  15510. if ( light.onlyShadow || light.visible === false ) continue;
  15511. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  15512. if ( light instanceof THREE.PointLight ) pointLights ++;
  15513. if ( light instanceof THREE.SpotLight ) spotLights ++;
  15514. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  15515. }
  15516. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  15517. }
  15518. function allocateShadows( lights ) {
  15519. var maxShadows = 0;
  15520. var pointLightShadows = 0;
  15521. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15522. var light = lights[ l ];
  15523. if ( ! light.castShadow ) continue;
  15524. if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
  15525. if ( light instanceof THREE.PointLight ) {
  15526. maxShadows ++;
  15527. pointLightShadows ++;
  15528. }
  15529. }
  15530. return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
  15531. }
  15532. this.getParameters = function ( material, lights, fog, object ) {
  15533. var shaderID = shaderIDs[ material.type ];
  15534. // heuristics to create shader parameters according to lights in the scene
  15535. // (not to blow over maxLights budget)
  15536. var maxLightCount = allocateLights( lights );
  15537. var allocatedShadows = allocateShadows( lights );
  15538. var maxBones = allocateBones( object );
  15539. var precision = renderer.getPrecision();
  15540. if ( material.precision !== null ) {
  15541. precision = capabilities.getMaxPrecision( material.precision );
  15542. if ( precision !== material.precision ) {
  15543. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  15544. }
  15545. }
  15546. var parameters = {
  15547. shaderID: shaderID,
  15548. precision: precision,
  15549. supportsVertexTextures: capabilities.vertexTextures,
  15550. map: !! material.map,
  15551. envMap: !! material.envMap,
  15552. envMapMode: material.envMap && material.envMap.mapping,
  15553. lightMap: !! material.lightMap,
  15554. aoMap: !! material.aoMap,
  15555. emissiveMap: !! material.emissiveMap,
  15556. bumpMap: !! material.bumpMap,
  15557. normalMap: !! material.normalMap,
  15558. displacementMap: !! material.displacementMap,
  15559. specularMap: !! material.specularMap,
  15560. alphaMap: !! material.alphaMap,
  15561. combine: material.combine,
  15562. vertexColors: material.vertexColors,
  15563. fog: fog,
  15564. useFog: material.fog,
  15565. fogExp: fog instanceof THREE.FogExp2,
  15566. flatShading: material.shading === THREE.FlatShading,
  15567. sizeAttenuation: material.sizeAttenuation,
  15568. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  15569. skinning: material.skinning,
  15570. maxBones: maxBones,
  15571. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  15572. morphTargets: material.morphTargets,
  15573. morphNormals: material.morphNormals,
  15574. maxMorphTargets: renderer.maxMorphTargets,
  15575. maxMorphNormals: renderer.maxMorphNormals,
  15576. maxDirLights: maxLightCount.directional,
  15577. maxPointLights: maxLightCount.point,
  15578. maxSpotLights: maxLightCount.spot,
  15579. maxHemiLights: maxLightCount.hemi,
  15580. maxShadows: allocatedShadows.maxShadows,
  15581. pointLightShadows: allocatedShadows.pointLightShadows,
  15582. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
  15583. shadowMapType: renderer.shadowMap.type,
  15584. shadowMapDebug: renderer.shadowMap.debug,
  15585. alphaTest: material.alphaTest,
  15586. metal: material.metal,
  15587. doubleSided: material.side === THREE.DoubleSide,
  15588. flipSided: material.side === THREE.BackSide
  15589. };
  15590. return parameters;
  15591. };
  15592. this.getProgramCode = function ( material, parameters ) {
  15593. var chunks = [];
  15594. if ( parameters.shaderID ) {
  15595. chunks.push( parameters.shaderID );
  15596. } else {
  15597. chunks.push( material.fragmentShader );
  15598. chunks.push( material.vertexShader );
  15599. }
  15600. if ( material.defines !== undefined ) {
  15601. for ( var name in material.defines ) {
  15602. chunks.push( name );
  15603. chunks.push( material.defines[ name ] );
  15604. }
  15605. }
  15606. for ( var i = 0; i < parameterNames.length; i ++ ) {
  15607. var parameterName = parameterNames[ i ];
  15608. chunks.push( parameterName );
  15609. chunks.push( parameters[ parameterName ] );
  15610. }
  15611. return chunks.join();
  15612. };
  15613. this.acquireProgram = function ( material, parameters, code ) {
  15614. var program;
  15615. // Check if code has been already compiled
  15616. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  15617. var programInfo = programs[ p ];
  15618. if ( programInfo.code === code ) {
  15619. program = programInfo;
  15620. ++ program.usedTimes;
  15621. break;
  15622. }
  15623. }
  15624. if ( program === undefined ) {
  15625. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  15626. programs.push( program );
  15627. }
  15628. return program;
  15629. };
  15630. this.releaseProgram = function( program ) {
  15631. if ( -- program.usedTimes === 0 ) {
  15632. // Remove from unordered set
  15633. var i = programs.indexOf( program );
  15634. programs[ i ] = programs[ programs.length - 1 ];
  15635. programs.pop();
  15636. // Free WebGL resources
  15637. program.destroy();
  15638. }
  15639. };
  15640. // Exposed for resource monitoring & error feedback via renderer.info:
  15641. this.programs = programs;
  15642. };
  15643. // File:src/renderers/webgl/WebGLProperties.js
  15644. /**
  15645. * @author fordacious / fordacious.github.io
  15646. */
  15647. THREE.WebGLProperties = function () {
  15648. var properties = {};
  15649. this.get = function ( object ) {
  15650. var uuid = object.uuid;
  15651. var map = properties[ uuid ];
  15652. if ( map === undefined ) {
  15653. map = {};
  15654. properties[ uuid ] = map;
  15655. }
  15656. return map;
  15657. };
  15658. this.delete = function ( object ) {
  15659. delete properties[ object.uuid ];
  15660. };
  15661. this.clear = function () {
  15662. properties = {};
  15663. };
  15664. };
  15665. // File:src/renderers/webgl/WebGLShader.js
  15666. THREE.WebGLShader = ( function () {
  15667. var addLineNumbers = function ( string ) {
  15668. var lines = string.split( '\n' );
  15669. for ( var i = 0; i < lines.length; i ++ ) {
  15670. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  15671. }
  15672. return lines.join( '\n' );
  15673. };
  15674. return function WebGLShader( gl, type, string ) {
  15675. var shader = gl.createShader( type );
  15676. gl.shaderSource( shader, string );
  15677. gl.compileShader( shader );
  15678. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  15679. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  15680. }
  15681. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  15682. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  15683. }
  15684. // --enable-privileged-webgl-extension
  15685. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  15686. return shader;
  15687. };
  15688. } )();
  15689. // File:src/renderers/webgl/WebGLShadowMap.js
  15690. /**
  15691. * @author alteredq / http://alteredqualia.com/
  15692. * @author mrdoob / http://mrdoob.com/
  15693. */
  15694. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  15695. var _gl = _renderer.context,
  15696. _state = _renderer.state,
  15697. _frustum = new THREE.Frustum(),
  15698. _projScreenMatrix = new THREE.Matrix4(),
  15699. _min = new THREE.Vector3(),
  15700. _max = new THREE.Vector3(),
  15701. _lookTarget = new THREE.Vector3(),
  15702. _lightPositionWorld = new THREE.Vector3(),
  15703. _renderList = [],
  15704. _MorphingFlag = 1,
  15705. _SkinningFlag = 2,
  15706. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  15707. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  15708. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  15709. var cubeDirections = [
  15710. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  15711. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  15712. ];
  15713. var cubeUps = [
  15714. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  15715. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  15716. ];
  15717. var cube2DViewPorts = [
  15718. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  15719. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  15720. ];
  15721. var _vector4 = new THREE.Vector4();
  15722. // init
  15723. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  15724. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  15725. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  15726. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  15727. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  15728. var useMorphing = ( i & _MorphingFlag ) !== 0;
  15729. var useSkinning = ( i & _SkinningFlag ) !== 0;
  15730. var depthMaterial = new THREE.ShaderMaterial( {
  15731. uniforms: depthUniforms,
  15732. vertexShader: depthShader.vertexShader,
  15733. fragmentShader: depthShader.fragmentShader,
  15734. morphTargets: useMorphing,
  15735. skinning: useSkinning
  15736. } );
  15737. depthMaterial._shadowPass = true;
  15738. _depthMaterials[ i ] = depthMaterial;
  15739. var distanceMaterial = new THREE.ShaderMaterial( {
  15740. uniforms: distanceUniforms,
  15741. vertexShader: distanceShader.vertexShader,
  15742. fragmentShader: distanceShader.fragmentShader,
  15743. morphTargets: useMorphing,
  15744. skinning: useSkinning
  15745. } );
  15746. distanceMaterial._shadowPass = true;
  15747. _distanceMaterials[ i ] = distanceMaterial;
  15748. }
  15749. //
  15750. var scope = this;
  15751. this.enabled = false;
  15752. this.autoUpdate = true;
  15753. this.needsUpdate = false;
  15754. this.type = THREE.PCFShadowMap;
  15755. this.cullFace = THREE.CullFaceFront;
  15756. this.render = function ( scene ) {
  15757. var faceCount, isPointLight;
  15758. if ( scope.enabled === false ) return;
  15759. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  15760. // set GL state for depth map
  15761. _gl.clearColor( 1, 1, 1, 1 );
  15762. _state.disable( _gl.BLEND );
  15763. _state.enable( _gl.CULL_FACE );
  15764. _gl.frontFace( _gl.CCW );
  15765. if ( scope.cullFace === THREE.CullFaceFront ) {
  15766. _gl.cullFace( _gl.FRONT );
  15767. } else {
  15768. _gl.cullFace( _gl.BACK );
  15769. }
  15770. _state.setDepthTest( true );
  15771. // render depth map
  15772. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  15773. var light = _lights[ i ];
  15774. // save the existing viewport so it can be restored later
  15775. _renderer.getViewport( _vector4 );
  15776. if ( light instanceof THREE.PointLight ) {
  15777. faceCount = 6;
  15778. isPointLight = true;
  15779. var vpWidth = light.shadowMapWidth / 4.0;
  15780. var vpHeight = light.shadowMapHeight / 2.0;
  15781. // These viewports map a cube-map onto a 2D texture with the
  15782. // following orientation:
  15783. //
  15784. // xzXZ
  15785. // y Y
  15786. //
  15787. // X - Positive x direction
  15788. // x - Negative x direction
  15789. // Y - Positive y direction
  15790. // y - Negative y direction
  15791. // Z - Positive z direction
  15792. // z - Negative z direction
  15793. // positive X
  15794. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  15795. // negative X
  15796. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  15797. // positive Z
  15798. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  15799. // negative Z
  15800. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  15801. // positive Y
  15802. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  15803. // negative Y
  15804. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  15805. } else {
  15806. faceCount = 1;
  15807. isPointLight = false;
  15808. }
  15809. if ( ! light.castShadow ) continue;
  15810. if ( ! light.shadowMap ) {
  15811. var shadowFilter = THREE.LinearFilter;
  15812. if ( scope.type === THREE.PCFSoftShadowMap ) {
  15813. shadowFilter = THREE.NearestFilter;
  15814. }
  15815. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  15816. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  15817. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  15818. light.shadowMatrix = new THREE.Matrix4();
  15819. }
  15820. if ( ! light.shadowCamera ) {
  15821. if ( light instanceof THREE.SpotLight ) {
  15822. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  15823. } else if ( light instanceof THREE.DirectionalLight ) {
  15824. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  15825. } else {
  15826. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, 1.0, light.shadowCameraNear, light.shadowCameraFar );
  15827. }
  15828. scene.add( light.shadowCamera );
  15829. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15830. }
  15831. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  15832. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  15833. scene.add( light.cameraHelper );
  15834. }
  15835. var shadowMap = light.shadowMap;
  15836. var shadowMatrix = light.shadowMatrix;
  15837. var shadowCamera = light.shadowCamera;
  15838. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  15839. shadowCamera.position.copy( _lightPositionWorld );
  15840. _renderer.setRenderTarget( shadowMap );
  15841. _renderer.clear();
  15842. // render shadow map for each cube face (if omni-directional) or
  15843. // run a single pass if not
  15844. for ( var face = 0; face < faceCount; face ++ ) {
  15845. if ( isPointLight ) {
  15846. _lookTarget.copy( shadowCamera.position );
  15847. _lookTarget.add( cubeDirections[ face ] );
  15848. shadowCamera.up.copy( cubeUps[ face ] );
  15849. shadowCamera.lookAt( _lookTarget );
  15850. var vpDimensions = cube2DViewPorts[ face ];
  15851. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  15852. } else {
  15853. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  15854. shadowCamera.lookAt( _lookTarget );
  15855. }
  15856. shadowCamera.updateMatrixWorld();
  15857. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  15858. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  15859. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  15860. // compute shadow matrix
  15861. shadowMatrix.set(
  15862. 0.5, 0.0, 0.0, 0.5,
  15863. 0.0, 0.5, 0.0, 0.5,
  15864. 0.0, 0.0, 0.5, 0.5,
  15865. 0.0, 0.0, 0.0, 1.0
  15866. );
  15867. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  15868. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  15869. // update camera matrices and frustum
  15870. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  15871. _frustum.setFromMatrix( _projScreenMatrix );
  15872. // set object matrices & frustum culling
  15873. _renderList.length = 0;
  15874. projectObject( scene, shadowCamera );
  15875. // render shadow map
  15876. // render regular objects
  15877. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  15878. var object = _renderList[ j ];
  15879. var geometry = _objects.update( object );
  15880. var material = object.material;
  15881. if ( material instanceof THREE.MeshFaceMaterial ) {
  15882. var groups = geometry.groups;
  15883. var materials = material.materials;
  15884. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  15885. var group = groups[ k ];
  15886. var groupMaterial = materials[ group.materialIndex ];
  15887. if ( groupMaterial.visible === true ) {
  15888. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  15889. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  15890. }
  15891. }
  15892. } else {
  15893. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  15894. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  15895. }
  15896. }
  15897. }
  15898. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  15899. }
  15900. // restore GL state
  15901. var clearColor = _renderer.getClearColor(),
  15902. clearAlpha = _renderer.getClearAlpha();
  15903. _renderer.setClearColor( clearColor, clearAlpha );
  15904. _state.enable( _gl.BLEND );
  15905. if ( scope.cullFace === THREE.CullFaceFront ) {
  15906. _gl.cullFace( _gl.BACK );
  15907. }
  15908. _renderer.resetGLState();
  15909. scope.needsUpdate = false;
  15910. };
  15911. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  15912. var geometry = object.geometry;
  15913. var newMaterial = null;
  15914. var materialVariants = _depthMaterials;
  15915. var customMaterial = object.customDepthMaterial;
  15916. if ( isPointLight ) {
  15917. materialVariants = _distanceMaterials;
  15918. customMaterial = object.customDistanceMaterial;
  15919. }
  15920. if ( ! customMaterial ) {
  15921. var useMorphing = geometry.morphTargets !== undefined &&
  15922. geometry.morphTargets.length > 0 && material.morphTargets;
  15923. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  15924. var variantIndex = 0;
  15925. if ( useMorphing ) variantIndex |= _MorphingFlag;
  15926. if ( useSkinning ) variantIndex |= _SkinningFlag;
  15927. newMaterial = materialVariants[ variantIndex ];
  15928. } else {
  15929. newMaterial = customMaterial;
  15930. }
  15931. newMaterial.visible = material.visible;
  15932. newMaterial.wireframe = material.wireframe;
  15933. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  15934. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  15935. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  15936. }
  15937. return newMaterial;
  15938. }
  15939. function projectObject( object, camera ) {
  15940. if ( object.visible === false ) return;
  15941. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15942. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  15943. var material = object.material;
  15944. if ( material.visible === true ) {
  15945. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15946. _renderList.push( object );
  15947. }
  15948. }
  15949. }
  15950. var children = object.children;
  15951. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15952. projectObject( children[ i ], camera );
  15953. }
  15954. }
  15955. };
  15956. // File:src/renderers/webgl/WebGLState.js
  15957. /**
  15958. * @author mrdoob / http://mrdoob.com/
  15959. */
  15960. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  15961. var _this = this;
  15962. var newAttributes = new Uint8Array( 16 );
  15963. var enabledAttributes = new Uint8Array( 16 );
  15964. var attributeDivisors = new Uint8Array( 16 );
  15965. var capabilities = {};
  15966. var compressedTextureFormats = null;
  15967. var currentBlending = null;
  15968. var currentBlendEquation = null;
  15969. var currentBlendSrc = null;
  15970. var currentBlendDst = null;
  15971. var currentBlendEquationAlpha = null;
  15972. var currentBlendSrcAlpha = null;
  15973. var currentBlendDstAlpha = null;
  15974. var currentDepthFunc = null;
  15975. var currentDepthWrite = null;
  15976. var currentColorWrite = null;
  15977. var currentFlipSided = null;
  15978. var currentLineWidth = null;
  15979. var currentPolygonOffsetFactor = null;
  15980. var currentPolygonOffsetUnits = null;
  15981. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  15982. var currentTextureSlot = undefined;
  15983. var currentBoundTextures = {};
  15984. this.init = function () {
  15985. gl.clearColor( 0, 0, 0, 1 );
  15986. gl.clearDepth( 1 );
  15987. gl.clearStencil( 0 );
  15988. this.enable( gl.DEPTH_TEST );
  15989. gl.depthFunc( gl.LEQUAL );
  15990. gl.frontFace( gl.CCW );
  15991. gl.cullFace( gl.BACK );
  15992. this.enable( gl.CULL_FACE );
  15993. this.enable( gl.BLEND );
  15994. gl.blendEquation( gl.FUNC_ADD );
  15995. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  15996. };
  15997. this.initAttributes = function () {
  15998. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  15999. newAttributes[ i ] = 0;
  16000. }
  16001. };
  16002. this.enableAttribute = function ( attribute ) {
  16003. newAttributes[ attribute ] = 1;
  16004. if ( enabledAttributes[ attribute ] === 0 ) {
  16005. gl.enableVertexAttribArray( attribute );
  16006. enabledAttributes[ attribute ] = 1;
  16007. }
  16008. if ( attributeDivisors[ attribute ] !== 0 ) {
  16009. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16010. extension.vertexAttribDivisorANGLE( attribute, 0 );
  16011. attributeDivisors[ attribute ] = 0;
  16012. }
  16013. };
  16014. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  16015. newAttributes[ attribute ] = 1;
  16016. if ( enabledAttributes[ attribute ] === 0 ) {
  16017. gl.enableVertexAttribArray( attribute );
  16018. enabledAttributes[ attribute ] = 1;
  16019. }
  16020. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  16021. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  16022. attributeDivisors[ attribute ] = meshPerAttribute;
  16023. }
  16024. };
  16025. this.disableUnusedAttributes = function () {
  16026. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  16027. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  16028. gl.disableVertexAttribArray( i );
  16029. enabledAttributes[ i ] = 0;
  16030. }
  16031. }
  16032. };
  16033. this.enable = function ( id ) {
  16034. if ( capabilities[ id ] !== true ) {
  16035. gl.enable( id );
  16036. capabilities[ id ] = true;
  16037. }
  16038. };
  16039. this.disable = function ( id ) {
  16040. if ( capabilities[ id ] !== false ) {
  16041. gl.disable( id );
  16042. capabilities[ id ] = false;
  16043. }
  16044. };
  16045. this.getCompressedTextureFormats = function () {
  16046. if ( compressedTextureFormats === null ) {
  16047. compressedTextureFormats = [];
  16048. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  16049. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  16050. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  16051. for ( var i = 0; i < formats.length; i ++ ) {
  16052. compressedTextureFormats.push( formats[ i ] );
  16053. }
  16054. }
  16055. }
  16056. return compressedTextureFormats;
  16057. };
  16058. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  16059. if ( blending !== currentBlending ) {
  16060. if ( blending === THREE.NoBlending ) {
  16061. this.disable( gl.BLEND );
  16062. } else if ( blending === THREE.AdditiveBlending ) {
  16063. this.enable( gl.BLEND );
  16064. gl.blendEquation( gl.FUNC_ADD );
  16065. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  16066. } else if ( blending === THREE.SubtractiveBlending ) {
  16067. // TODO: Find blendFuncSeparate() combination
  16068. this.enable( gl.BLEND );
  16069. gl.blendEquation( gl.FUNC_ADD );
  16070. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  16071. } else if ( blending === THREE.MultiplyBlending ) {
  16072. // TODO: Find blendFuncSeparate() combination
  16073. this.enable( gl.BLEND );
  16074. gl.blendEquation( gl.FUNC_ADD );
  16075. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  16076. } else if ( blending === THREE.CustomBlending ) {
  16077. this.enable( gl.BLEND );
  16078. } else {
  16079. this.enable( gl.BLEND );
  16080. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  16081. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  16082. }
  16083. currentBlending = blending;
  16084. }
  16085. if ( blending === THREE.CustomBlending ) {
  16086. blendEquationAlpha = blendEquationAlpha || blendEquation;
  16087. blendSrcAlpha = blendSrcAlpha || blendSrc;
  16088. blendDstAlpha = blendDstAlpha || blendDst;
  16089. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  16090. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  16091. currentBlendEquation = blendEquation;
  16092. currentBlendEquationAlpha = blendEquationAlpha;
  16093. }
  16094. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  16095. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  16096. currentBlendSrc = blendSrc;
  16097. currentBlendDst = blendDst;
  16098. currentBlendSrcAlpha = blendSrcAlpha;
  16099. currentBlendDstAlpha = blendDstAlpha;
  16100. }
  16101. } else {
  16102. currentBlendEquation = null;
  16103. currentBlendSrc = null;
  16104. currentBlendDst = null;
  16105. currentBlendEquationAlpha = null;
  16106. currentBlendSrcAlpha = null;
  16107. currentBlendDstAlpha = null;
  16108. }
  16109. };
  16110. this.setDepthFunc = function ( depthFunc ) {
  16111. if ( currentDepthFunc !== depthFunc ) {
  16112. if ( depthFunc ) {
  16113. switch ( depthFunc ) {
  16114. case THREE.NeverDepth:
  16115. gl.depthFunc( gl.NEVER );
  16116. break;
  16117. case THREE.AlwaysDepth:
  16118. gl.depthFunc( gl.ALWAYS );
  16119. break;
  16120. case THREE.LessDepth:
  16121. gl.depthFunc( gl.LESS );
  16122. break;
  16123. case THREE.LessEqualDepth:
  16124. gl.depthFunc( gl.LEQUAL );
  16125. break;
  16126. case THREE.EqualDepth:
  16127. gl.depthFunc( gl.EQUAL );
  16128. break;
  16129. case THREE.GreaterEqualDepth:
  16130. gl.depthFunc( gl.GEQUAL );
  16131. break;
  16132. case THREE.GreaterDepth:
  16133. gl.depthFunc( gl.GREATER );
  16134. break;
  16135. case THREE.NotEqualDepth:
  16136. gl.depthFunc( gl.NOTEQUAL );
  16137. break;
  16138. default:
  16139. gl.depthFunc( gl.LEQUAL );
  16140. }
  16141. } else {
  16142. gl.depthFunc( gl.LEQUAL );
  16143. }
  16144. currentDepthFunc = depthFunc;
  16145. }
  16146. };
  16147. this.setDepthTest = function ( depthTest ) {
  16148. if ( depthTest ) {
  16149. this.enable( gl.DEPTH_TEST );
  16150. } else {
  16151. this.disable( gl.DEPTH_TEST );
  16152. }
  16153. };
  16154. this.setDepthWrite = function ( depthWrite ) {
  16155. if ( currentDepthWrite !== depthWrite ) {
  16156. gl.depthMask( depthWrite );
  16157. currentDepthWrite = depthWrite;
  16158. }
  16159. };
  16160. this.setColorWrite = function ( colorWrite ) {
  16161. if ( currentColorWrite !== colorWrite ) {
  16162. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  16163. currentColorWrite = colorWrite;
  16164. }
  16165. };
  16166. this.setFlipSided = function ( flipSided ) {
  16167. if ( currentFlipSided !== flipSided ) {
  16168. if ( flipSided ) {
  16169. gl.frontFace( gl.CW );
  16170. } else {
  16171. gl.frontFace( gl.CCW );
  16172. }
  16173. currentFlipSided = flipSided;
  16174. }
  16175. };
  16176. this.setLineWidth = function ( width ) {
  16177. if ( width !== currentLineWidth ) {
  16178. gl.lineWidth( width );
  16179. currentLineWidth = width;
  16180. }
  16181. };
  16182. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  16183. if ( polygonOffset ) {
  16184. this.enable( gl.POLYGON_OFFSET_FILL );
  16185. } else {
  16186. this.disable( gl.POLYGON_OFFSET_FILL );
  16187. }
  16188. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  16189. gl.polygonOffset( factor, units );
  16190. currentPolygonOffsetFactor = factor;
  16191. currentPolygonOffsetUnits = units;
  16192. }
  16193. };
  16194. this.setScissorTest = function ( scissorTest ) {
  16195. if ( scissorTest ) {
  16196. this.enable( gl.SCISSOR_TEST );
  16197. } else {
  16198. this.disable( gl.SCISSOR_TEST );
  16199. }
  16200. };
  16201. // texture
  16202. this.activeTexture = function ( webglSlot ) {
  16203. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  16204. if ( currentTextureSlot !== webglSlot ) {
  16205. gl.activeTexture( webglSlot );
  16206. currentTextureSlot = webglSlot;
  16207. }
  16208. }
  16209. this.bindTexture = function ( webglType, webglTexture ) {
  16210. if ( currentTextureSlot === undefined ) {
  16211. _this.activeTexture();
  16212. }
  16213. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  16214. if ( boundTexture === undefined ) {
  16215. boundTexture = { type: undefined, texture: undefined };
  16216. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  16217. }
  16218. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  16219. gl.bindTexture( webglType, webglTexture );
  16220. boundTexture.type = webglType;
  16221. boundTexture.texture = webglTexture;
  16222. }
  16223. };
  16224. this.compressedTexImage2D = function () {
  16225. try {
  16226. gl.compressedTexImage2D.apply( gl, arguments );
  16227. } catch ( error ) {
  16228. console.error( error );
  16229. }
  16230. };
  16231. this.texImage2D = function () {
  16232. try {
  16233. gl.texImage2D.apply( gl, arguments );
  16234. } catch ( error ) {
  16235. console.error( error );
  16236. }
  16237. };
  16238. //
  16239. this.reset = function () {
  16240. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  16241. if ( enabledAttributes[ i ] === 1 ) {
  16242. gl.disableVertexAttribArray( i );
  16243. enabledAttributes[ i ] = 0;
  16244. }
  16245. }
  16246. capabilities = {};
  16247. compressedTextureFormats = null;
  16248. currentBlending = null;
  16249. currentDepthWrite = null;
  16250. currentColorWrite = null;
  16251. currentFlipSided = null;
  16252. };
  16253. };
  16254. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  16255. /**
  16256. * @author mikael emtinger / http://gomo.se/
  16257. * @author alteredq / http://alteredqualia.com/
  16258. */
  16259. THREE.LensFlarePlugin = function ( renderer, flares ) {
  16260. var gl = renderer.context;
  16261. var state = renderer.state;
  16262. var vertexBuffer, elementBuffer;
  16263. var program, attributes, uniforms;
  16264. var hasVertexTexture;
  16265. var tempTexture, occlusionTexture;
  16266. var init = function () {
  16267. var vertices = new Float32Array( [
  16268. - 1, - 1, 0, 0,
  16269. 1, - 1, 1, 0,
  16270. 1, 1, 1, 1,
  16271. - 1, 1, 0, 1
  16272. ] );
  16273. var faces = new Uint16Array( [
  16274. 0, 1, 2,
  16275. 0, 2, 3
  16276. ] );
  16277. // buffers
  16278. vertexBuffer = gl.createBuffer();
  16279. elementBuffer = gl.createBuffer();
  16280. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16281. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16282. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16283. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16284. // textures
  16285. tempTexture = gl.createTexture();
  16286. occlusionTexture = gl.createTexture();
  16287. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16288. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  16289. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16290. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16291. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16292. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16293. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16294. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  16295. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16296. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16297. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16298. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16299. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  16300. var shader;
  16301. if ( hasVertexTexture ) {
  16302. shader = {
  16303. vertexShader: [
  16304. "uniform lowp int renderType;",
  16305. "uniform vec3 screenPosition;",
  16306. "uniform vec2 scale;",
  16307. "uniform float rotation;",
  16308. "uniform sampler2D occlusionMap;",
  16309. "attribute vec2 position;",
  16310. "attribute vec2 uv;",
  16311. "varying vec2 vUV;",
  16312. "varying float vVisibility;",
  16313. "void main() {",
  16314. "vUV = uv;",
  16315. "vec2 pos = position;",
  16316. "if( renderType == 2 ) {",
  16317. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  16318. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  16319. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  16320. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  16321. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  16322. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  16323. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  16324. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  16325. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  16326. "vVisibility = visibility.r / 9.0;",
  16327. "vVisibility *= 1.0 - visibility.g / 9.0;",
  16328. "vVisibility *= visibility.b / 9.0;",
  16329. "vVisibility *= 1.0 - visibility.a / 9.0;",
  16330. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16331. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16332. "}",
  16333. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16334. "}"
  16335. ].join( "\n" ),
  16336. fragmentShader: [
  16337. "uniform lowp int renderType;",
  16338. "uniform sampler2D map;",
  16339. "uniform float opacity;",
  16340. "uniform vec3 color;",
  16341. "varying vec2 vUV;",
  16342. "varying float vVisibility;",
  16343. "void main() {",
  16344. // pink square
  16345. "if( renderType == 0 ) {",
  16346. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  16347. // restore
  16348. "} else if( renderType == 1 ) {",
  16349. "gl_FragColor = texture2D( map, vUV );",
  16350. // flare
  16351. "} else {",
  16352. "vec4 texture = texture2D( map, vUV );",
  16353. "texture.a *= opacity * vVisibility;",
  16354. "gl_FragColor = texture;",
  16355. "gl_FragColor.rgb *= color;",
  16356. "}",
  16357. "}"
  16358. ].join( "\n" )
  16359. };
  16360. } else {
  16361. shader = {
  16362. vertexShader: [
  16363. "uniform lowp int renderType;",
  16364. "uniform vec3 screenPosition;",
  16365. "uniform vec2 scale;",
  16366. "uniform float rotation;",
  16367. "attribute vec2 position;",
  16368. "attribute vec2 uv;",
  16369. "varying vec2 vUV;",
  16370. "void main() {",
  16371. "vUV = uv;",
  16372. "vec2 pos = position;",
  16373. "if( renderType == 2 ) {",
  16374. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16375. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16376. "}",
  16377. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16378. "}"
  16379. ].join( "\n" ),
  16380. fragmentShader: [
  16381. "precision mediump float;",
  16382. "uniform lowp int renderType;",
  16383. "uniform sampler2D map;",
  16384. "uniform sampler2D occlusionMap;",
  16385. "uniform float opacity;",
  16386. "uniform vec3 color;",
  16387. "varying vec2 vUV;",
  16388. "void main() {",
  16389. // pink square
  16390. "if( renderType == 0 ) {",
  16391. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  16392. // restore
  16393. "} else if( renderType == 1 ) {",
  16394. "gl_FragColor = texture2D( map, vUV );",
  16395. // flare
  16396. "} else {",
  16397. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  16398. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  16399. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  16400. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  16401. "visibility = ( 1.0 - visibility / 4.0 );",
  16402. "vec4 texture = texture2D( map, vUV );",
  16403. "texture.a *= opacity * visibility;",
  16404. "gl_FragColor = texture;",
  16405. "gl_FragColor.rgb *= color;",
  16406. "}",
  16407. "}"
  16408. ].join( "\n" )
  16409. };
  16410. }
  16411. program = createProgram( shader );
  16412. attributes = {
  16413. vertex: gl.getAttribLocation ( program, "position" ),
  16414. uv: gl.getAttribLocation ( program, "uv" )
  16415. };
  16416. uniforms = {
  16417. renderType: gl.getUniformLocation( program, "renderType" ),
  16418. map: gl.getUniformLocation( program, "map" ),
  16419. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  16420. opacity: gl.getUniformLocation( program, "opacity" ),
  16421. color: gl.getUniformLocation( program, "color" ),
  16422. scale: gl.getUniformLocation( program, "scale" ),
  16423. rotation: gl.getUniformLocation( program, "rotation" ),
  16424. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  16425. };
  16426. };
  16427. /*
  16428. * Render lens flares
  16429. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  16430. * reads these back and calculates occlusion.
  16431. */
  16432. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  16433. if ( flares.length === 0 ) return;
  16434. var tempPosition = new THREE.Vector3();
  16435. var invAspect = viewportHeight / viewportWidth,
  16436. halfViewportWidth = viewportWidth * 0.5,
  16437. halfViewportHeight = viewportHeight * 0.5;
  16438. var size = 16 / viewportHeight,
  16439. scale = new THREE.Vector2( size * invAspect, size );
  16440. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  16441. screenPositionPixels = new THREE.Vector2( 1, 1 );
  16442. if ( program === undefined ) {
  16443. init();
  16444. }
  16445. gl.useProgram( program );
  16446. state.initAttributes();
  16447. state.enableAttribute( attributes.vertex );
  16448. state.enableAttribute( attributes.uv );
  16449. state.disableUnusedAttributes();
  16450. // loop through all lens flares to update their occlusion and positions
  16451. // setup gl and common used attribs/uniforms
  16452. gl.uniform1i( uniforms.occlusionMap, 0 );
  16453. gl.uniform1i( uniforms.map, 1 );
  16454. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16455. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  16456. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16457. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16458. state.disable( gl.CULL_FACE );
  16459. gl.depthMask( false );
  16460. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  16461. size = 16 / viewportHeight;
  16462. scale.set( size * invAspect, size );
  16463. // calc object screen position
  16464. var flare = flares[ i ];
  16465. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  16466. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  16467. tempPosition.applyProjection( camera.projectionMatrix );
  16468. // setup arrays for gl programs
  16469. screenPosition.copy( tempPosition );
  16470. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  16471. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  16472. // screen cull
  16473. if ( hasVertexTexture || (
  16474. screenPositionPixels.x > 0 &&
  16475. screenPositionPixels.x < viewportWidth &&
  16476. screenPositionPixels.y > 0 &&
  16477. screenPositionPixels.y < viewportHeight ) ) {
  16478. // save current RGB to temp texture
  16479. state.activeTexture( gl.TEXTURE0 );
  16480. state.bindTexture( gl.TEXTURE_2D, null );
  16481. state.activeTexture( gl.TEXTURE1 );
  16482. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16483. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16484. // render pink quad
  16485. gl.uniform1i( uniforms.renderType, 0 );
  16486. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16487. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16488. state.disable( gl.BLEND );
  16489. state.enable( gl.DEPTH_TEST );
  16490. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16491. // copy result to occlusionMap
  16492. state.activeTexture( gl.TEXTURE0 );
  16493. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16494. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16495. // restore graphics
  16496. gl.uniform1i( uniforms.renderType, 1 );
  16497. state.disable( gl.DEPTH_TEST );
  16498. state.activeTexture( gl.TEXTURE1 );
  16499. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16500. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16501. // update object positions
  16502. flare.positionScreen.copy( screenPosition );
  16503. if ( flare.customUpdateCallback ) {
  16504. flare.customUpdateCallback( flare );
  16505. } else {
  16506. flare.updateLensFlares();
  16507. }
  16508. // render flares
  16509. gl.uniform1i( uniforms.renderType, 2 );
  16510. state.enable( gl.BLEND );
  16511. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  16512. var sprite = flare.lensFlares[ j ];
  16513. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  16514. screenPosition.x = sprite.x;
  16515. screenPosition.y = sprite.y;
  16516. screenPosition.z = sprite.z;
  16517. size = sprite.size * sprite.scale / viewportHeight;
  16518. scale.x = size * invAspect;
  16519. scale.y = size;
  16520. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16521. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16522. gl.uniform1f( uniforms.rotation, sprite.rotation );
  16523. gl.uniform1f( uniforms.opacity, sprite.opacity );
  16524. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  16525. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  16526. renderer.setTexture( sprite.texture, 1 );
  16527. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16528. }
  16529. }
  16530. }
  16531. }
  16532. // restore gl
  16533. state.enable( gl.CULL_FACE );
  16534. state.enable( gl.DEPTH_TEST );
  16535. gl.depthMask( true );
  16536. renderer.resetGLState();
  16537. };
  16538. function createProgram ( shader ) {
  16539. var program = gl.createProgram();
  16540. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16541. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16542. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  16543. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  16544. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  16545. gl.compileShader( fragmentShader );
  16546. gl.compileShader( vertexShader );
  16547. gl.attachShader( program, fragmentShader );
  16548. gl.attachShader( program, vertexShader );
  16549. gl.linkProgram( program );
  16550. return program;
  16551. }
  16552. };
  16553. // File:src/renderers/webgl/plugins/SpritePlugin.js
  16554. /**
  16555. * @author mikael emtinger / http://gomo.se/
  16556. * @author alteredq / http://alteredqualia.com/
  16557. */
  16558. THREE.SpritePlugin = function ( renderer, sprites ) {
  16559. var gl = renderer.context;
  16560. var state = renderer.state;
  16561. var vertexBuffer, elementBuffer;
  16562. var program, attributes, uniforms;
  16563. var texture;
  16564. // decompose matrixWorld
  16565. var spritePosition = new THREE.Vector3();
  16566. var spriteRotation = new THREE.Quaternion();
  16567. var spriteScale = new THREE.Vector3();
  16568. var init = function () {
  16569. var vertices = new Float32Array( [
  16570. - 0.5, - 0.5, 0, 0,
  16571. 0.5, - 0.5, 1, 0,
  16572. 0.5, 0.5, 1, 1,
  16573. - 0.5, 0.5, 0, 1
  16574. ] );
  16575. var faces = new Uint16Array( [
  16576. 0, 1, 2,
  16577. 0, 2, 3
  16578. ] );
  16579. vertexBuffer = gl.createBuffer();
  16580. elementBuffer = gl.createBuffer();
  16581. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16582. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16583. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16584. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16585. program = createProgram();
  16586. attributes = {
  16587. position: gl.getAttribLocation ( program, 'position' ),
  16588. uv: gl.getAttribLocation ( program, 'uv' )
  16589. };
  16590. uniforms = {
  16591. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  16592. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  16593. rotation: gl.getUniformLocation( program, 'rotation' ),
  16594. scale: gl.getUniformLocation( program, 'scale' ),
  16595. color: gl.getUniformLocation( program, 'color' ),
  16596. map: gl.getUniformLocation( program, 'map' ),
  16597. opacity: gl.getUniformLocation( program, 'opacity' ),
  16598. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  16599. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  16600. fogType: gl.getUniformLocation( program, 'fogType' ),
  16601. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  16602. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  16603. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  16604. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  16605. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  16606. };
  16607. var canvas = document.createElement( 'canvas' );
  16608. canvas.width = 8;
  16609. canvas.height = 8;
  16610. var context = canvas.getContext( '2d' );
  16611. context.fillStyle = 'white';
  16612. context.fillRect( 0, 0, 8, 8 );
  16613. texture = new THREE.Texture( canvas );
  16614. texture.needsUpdate = true;
  16615. };
  16616. this.render = function ( scene, camera ) {
  16617. if ( sprites.length === 0 ) return;
  16618. // setup gl
  16619. if ( program === undefined ) {
  16620. init();
  16621. }
  16622. gl.useProgram( program );
  16623. state.initAttributes();
  16624. state.enableAttribute( attributes.position );
  16625. state.enableAttribute( attributes.uv );
  16626. state.disableUnusedAttributes();
  16627. state.disable( gl.CULL_FACE );
  16628. state.enable( gl.BLEND );
  16629. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16630. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  16631. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16632. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16633. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  16634. state.activeTexture( gl.TEXTURE0 );
  16635. gl.uniform1i( uniforms.map, 0 );
  16636. var oldFogType = 0;
  16637. var sceneFogType = 0;
  16638. var fog = scene.fog;
  16639. if ( fog ) {
  16640. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  16641. if ( fog instanceof THREE.Fog ) {
  16642. gl.uniform1f( uniforms.fogNear, fog.near );
  16643. gl.uniform1f( uniforms.fogFar, fog.far );
  16644. gl.uniform1i( uniforms.fogType, 1 );
  16645. oldFogType = 1;
  16646. sceneFogType = 1;
  16647. } else if ( fog instanceof THREE.FogExp2 ) {
  16648. gl.uniform1f( uniforms.fogDensity, fog.density );
  16649. gl.uniform1i( uniforms.fogType, 2 );
  16650. oldFogType = 2;
  16651. sceneFogType = 2;
  16652. }
  16653. } else {
  16654. gl.uniform1i( uniforms.fogType, 0 );
  16655. oldFogType = 0;
  16656. sceneFogType = 0;
  16657. }
  16658. // update positions and sort
  16659. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16660. var sprite = sprites[ i ];
  16661. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  16662. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  16663. }
  16664. sprites.sort( painterSortStable );
  16665. // render all sprites
  16666. var scale = [];
  16667. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16668. var sprite = sprites[ i ];
  16669. var material = sprite.material;
  16670. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  16671. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  16672. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  16673. scale[ 0 ] = spriteScale.x;
  16674. scale[ 1 ] = spriteScale.y;
  16675. var fogType = 0;
  16676. if ( scene.fog && material.fog ) {
  16677. fogType = sceneFogType;
  16678. }
  16679. if ( oldFogType !== fogType ) {
  16680. gl.uniform1i( uniforms.fogType, fogType );
  16681. oldFogType = fogType;
  16682. }
  16683. if ( material.map !== null ) {
  16684. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  16685. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  16686. } else {
  16687. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  16688. gl.uniform2f( uniforms.uvScale, 1, 1 );
  16689. }
  16690. gl.uniform1f( uniforms.opacity, material.opacity );
  16691. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  16692. gl.uniform1f( uniforms.rotation, material.rotation );
  16693. gl.uniform2fv( uniforms.scale, scale );
  16694. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  16695. state.setDepthTest( material.depthTest );
  16696. state.setDepthWrite( material.depthWrite );
  16697. if ( material.map && material.map.image && material.map.image.width ) {
  16698. renderer.setTexture( material.map, 0 );
  16699. } else {
  16700. renderer.setTexture( texture, 0 );
  16701. }
  16702. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16703. }
  16704. // restore gl
  16705. state.enable( gl.CULL_FACE );
  16706. renderer.resetGLState();
  16707. };
  16708. function createProgram () {
  16709. var program = gl.createProgram();
  16710. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16711. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16712. gl.shaderSource( vertexShader, [
  16713. 'precision ' + renderer.getPrecision() + ' float;',
  16714. 'uniform mat4 modelViewMatrix;',
  16715. 'uniform mat4 projectionMatrix;',
  16716. 'uniform float rotation;',
  16717. 'uniform vec2 scale;',
  16718. 'uniform vec2 uvOffset;',
  16719. 'uniform vec2 uvScale;',
  16720. 'attribute vec2 position;',
  16721. 'attribute vec2 uv;',
  16722. 'varying vec2 vUV;',
  16723. 'void main() {',
  16724. 'vUV = uvOffset + uv * uvScale;',
  16725. 'vec2 alignedPosition = position * scale;',
  16726. 'vec2 rotatedPosition;',
  16727. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  16728. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  16729. 'vec4 finalPosition;',
  16730. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  16731. 'finalPosition.xy += rotatedPosition;',
  16732. 'finalPosition = projectionMatrix * finalPosition;',
  16733. 'gl_Position = finalPosition;',
  16734. '}'
  16735. ].join( '\n' ) );
  16736. gl.shaderSource( fragmentShader, [
  16737. 'precision ' + renderer.getPrecision() + ' float;',
  16738. 'uniform vec3 color;',
  16739. 'uniform sampler2D map;',
  16740. 'uniform float opacity;',
  16741. 'uniform int fogType;',
  16742. 'uniform vec3 fogColor;',
  16743. 'uniform float fogDensity;',
  16744. 'uniform float fogNear;',
  16745. 'uniform float fogFar;',
  16746. 'uniform float alphaTest;',
  16747. 'varying vec2 vUV;',
  16748. 'void main() {',
  16749. 'vec4 texture = texture2D( map, vUV );',
  16750. 'if ( texture.a < alphaTest ) discard;',
  16751. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  16752. 'if ( fogType > 0 ) {',
  16753. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  16754. 'float fogFactor = 0.0;',
  16755. 'if ( fogType == 1 ) {',
  16756. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  16757. '} else {',
  16758. 'const float LOG2 = 1.442695;',
  16759. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  16760. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  16761. '}',
  16762. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  16763. '}',
  16764. '}'
  16765. ].join( '\n' ) );
  16766. gl.compileShader( vertexShader );
  16767. gl.compileShader( fragmentShader );
  16768. gl.attachShader( program, vertexShader );
  16769. gl.attachShader( program, fragmentShader );
  16770. gl.linkProgram( program );
  16771. return program;
  16772. }
  16773. function painterSortStable ( a, b ) {
  16774. if ( a.z !== b.z ) {
  16775. return b.z - a.z;
  16776. } else {
  16777. return b.id - a.id;
  16778. }
  16779. }
  16780. };
  16781. // File:src/extras/GeometryUtils.js
  16782. /**
  16783. * @author mrdoob / http://mrdoob.com/
  16784. */
  16785. THREE.GeometryUtils = {
  16786. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  16787. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  16788. var matrix;
  16789. if ( geometry2 instanceof THREE.Mesh ) {
  16790. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  16791. matrix = geometry2.matrix;
  16792. geometry2 = geometry2.geometry;
  16793. }
  16794. geometry1.merge( geometry2, matrix, materialIndexOffset );
  16795. },
  16796. center: function ( geometry ) {
  16797. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  16798. return geometry.center();
  16799. }
  16800. };
  16801. // File:src/extras/ImageUtils.js
  16802. /**
  16803. * @author alteredq / http://alteredqualia.com/
  16804. * @author mrdoob / http://mrdoob.com/
  16805. * @author Daosheng Mu / https://github.com/DaoshengMu/
  16806. */
  16807. THREE.ImageUtils = {
  16808. crossOrigin: undefined,
  16809. loadTexture: function ( url, mapping, onLoad, onError ) {
  16810. var loader = new THREE.ImageLoader();
  16811. loader.crossOrigin = this.crossOrigin;
  16812. var texture = new THREE.Texture( undefined, mapping );
  16813. loader.load( url, function ( image ) {
  16814. texture.image = image;
  16815. texture.needsUpdate = true;
  16816. if ( onLoad ) onLoad( texture );
  16817. }, undefined, function ( event ) {
  16818. if ( onError ) onError( event );
  16819. } );
  16820. texture.sourceFile = url;
  16821. return texture;
  16822. },
  16823. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  16824. var images = [];
  16825. var loader = new THREE.ImageLoader();
  16826. loader.crossOrigin = this.crossOrigin;
  16827. var texture = new THREE.CubeTexture( images, mapping );
  16828. var loaded = 0;
  16829. var loadTexture = function ( i ) {
  16830. loader.load( array[ i ], function ( image ) {
  16831. texture.images[ i ] = image;
  16832. loaded += 1;
  16833. if ( loaded === 6 ) {
  16834. texture.needsUpdate = true;
  16835. if ( onLoad ) onLoad( texture );
  16836. }
  16837. }, undefined, onError );
  16838. };
  16839. for ( var i = 0, il = array.length; i < il; ++ i ) {
  16840. loadTexture( i );
  16841. }
  16842. return texture;
  16843. },
  16844. loadCompressedTexture: function () {
  16845. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  16846. },
  16847. loadCompressedTextureCube: function () {
  16848. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  16849. },
  16850. getNormalMap: function ( image, depth ) {
  16851. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  16852. var cross = function ( a, b ) {
  16853. return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ];
  16854. };
  16855. var subtract = function ( a, b ) {
  16856. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  16857. };
  16858. var normalize = function ( a ) {
  16859. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  16860. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  16861. };
  16862. depth = depth | 1;
  16863. var width = image.width;
  16864. var height = image.height;
  16865. var canvas = document.createElement( 'canvas' );
  16866. canvas.width = width;
  16867. canvas.height = height;
  16868. var context = canvas.getContext( '2d' );
  16869. context.drawImage( image, 0, 0 );
  16870. var data = context.getImageData( 0, 0, width, height ).data;
  16871. var imageData = context.createImageData( width, height );
  16872. var output = imageData.data;
  16873. for ( var x = 0; x < width; x ++ ) {
  16874. for ( var y = 0; y < height; y ++ ) {
  16875. var ly = y - 1 < 0 ? 0 : y - 1;
  16876. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  16877. var lx = x - 1 < 0 ? 0 : x - 1;
  16878. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  16879. var points = [];
  16880. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  16881. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  16882. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  16883. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  16884. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  16885. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  16886. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  16887. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  16888. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  16889. var normals = [];
  16890. var num_points = points.length;
  16891. for ( var i = 0; i < num_points; i ++ ) {
  16892. var v1 = points[ i ];
  16893. var v2 = points[ ( i + 1 ) % num_points ];
  16894. v1 = subtract( v1, origin );
  16895. v2 = subtract( v2, origin );
  16896. normals.push( normalize( cross( v1, v2 ) ) );
  16897. }
  16898. var normal = [ 0, 0, 0 ];
  16899. for ( var i = 0; i < normals.length; i ++ ) {
  16900. normal[ 0 ] += normals[ i ][ 0 ];
  16901. normal[ 1 ] += normals[ i ][ 1 ];
  16902. normal[ 2 ] += normals[ i ][ 2 ];
  16903. }
  16904. normal[ 0 ] /= normals.length;
  16905. normal[ 1 ] /= normals.length;
  16906. normal[ 2 ] /= normals.length;
  16907. var idx = ( y * width + x ) * 4;
  16908. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16909. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16910. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  16911. output[ idx + 3 ] = 255;
  16912. }
  16913. }
  16914. context.putImageData( imageData, 0, 0 );
  16915. return canvas;
  16916. },
  16917. generateDataTexture: function ( width, height, color ) {
  16918. var size = width * height;
  16919. var data = new Uint8Array( 3 * size );
  16920. var r = Math.floor( color.r * 255 );
  16921. var g = Math.floor( color.g * 255 );
  16922. var b = Math.floor( color.b * 255 );
  16923. for ( var i = 0; i < size; i ++ ) {
  16924. data[ i * 3 ] = r;
  16925. data[ i * 3 + 1 ] = g;
  16926. data[ i * 3 + 2 ] = b;
  16927. }
  16928. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  16929. texture.needsUpdate = true;
  16930. return texture;
  16931. }
  16932. };
  16933. // File:src/extras/SceneUtils.js
  16934. /**
  16935. * @author alteredq / http://alteredqualia.com/
  16936. */
  16937. THREE.SceneUtils = {
  16938. createMultiMaterialObject: function ( geometry, materials ) {
  16939. var group = new THREE.Group();
  16940. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  16941. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  16942. }
  16943. return group;
  16944. },
  16945. detach: function ( child, parent, scene ) {
  16946. child.applyMatrix( parent.matrixWorld );
  16947. parent.remove( child );
  16948. scene.add( child );
  16949. },
  16950. attach: function ( child, scene, parent ) {
  16951. var matrixWorldInverse = new THREE.Matrix4();
  16952. matrixWorldInverse.getInverse( parent.matrixWorld );
  16953. child.applyMatrix( matrixWorldInverse );
  16954. scene.remove( child );
  16955. parent.add( child );
  16956. }
  16957. };
  16958. // File:src/extras/FontUtils.js
  16959. /**
  16960. * @author zz85 / http://www.lab4games.net/zz85/blog
  16961. * @author alteredq / http://alteredqualia.com/
  16962. *
  16963. * For Text operations in three.js (See TextGeometry)
  16964. *
  16965. * It uses techniques used in:
  16966. *
  16967. * Triangulation ported from AS3
  16968. * Simple Polygon Triangulation
  16969. * http://actionsnippet.com/?p=1462
  16970. *
  16971. * A Method to triangulate shapes with holes
  16972. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  16973. *
  16974. */
  16975. THREE.FontUtils = {
  16976. faces: {},
  16977. // Just for now. face[weight][style]
  16978. face: 'helvetiker',
  16979. weight: 'normal',
  16980. style: 'normal',
  16981. size: 150,
  16982. divisions: 10,
  16983. getFace: function () {
  16984. try {
  16985. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  16986. } catch ( e ) {
  16987. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  16988. }
  16989. },
  16990. loadFace: function ( data ) {
  16991. var family = data.familyName.toLowerCase();
  16992. var ThreeFont = this;
  16993. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  16994. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  16995. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  16996. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  16997. return data;
  16998. },
  16999. drawText: function ( text ) {
  17000. // RenderText
  17001. var i,
  17002. face = this.getFace(),
  17003. scale = this.size / face.resolution,
  17004. offset = 0,
  17005. chars = String( text ).split( '' ),
  17006. length = chars.length;
  17007. var fontPaths = [];
  17008. for ( i = 0; i < length; i ++ ) {
  17009. var path = new THREE.Path();
  17010. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  17011. offset += ret.offset;
  17012. fontPaths.push( ret.path );
  17013. }
  17014. // get the width
  17015. var width = offset / 2;
  17016. //
  17017. // for ( p = 0; p < allPts.length; p++ ) {
  17018. //
  17019. // allPts[ p ].x -= width;
  17020. //
  17021. // }
  17022. //var extract = this.extractPoints( allPts, characterPts );
  17023. //extract.contour = allPts;
  17024. //extract.paths = fontPaths;
  17025. //extract.offset = width;
  17026. return { paths: fontPaths, offset: width };
  17027. },
  17028. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  17029. var pts = [];
  17030. var i, i2, divisions,
  17031. outline, action, length,
  17032. scaleX, scaleY,
  17033. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  17034. laste,
  17035. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  17036. if ( ! glyph ) return;
  17037. if ( glyph.o ) {
  17038. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  17039. length = outline.length;
  17040. scaleX = scale;
  17041. scaleY = scale;
  17042. for ( i = 0; i < length; ) {
  17043. action = outline[ i ++ ];
  17044. //console.log( action );
  17045. switch ( action ) {
  17046. case 'm':
  17047. // Move To
  17048. x = outline[ i ++ ] * scaleX + offset;
  17049. y = outline[ i ++ ] * scaleY;
  17050. path.moveTo( x, y );
  17051. break;
  17052. case 'l':
  17053. // Line To
  17054. x = outline[ i ++ ] * scaleX + offset;
  17055. y = outline[ i ++ ] * scaleY;
  17056. path.lineTo( x, y );
  17057. break;
  17058. case 'q':
  17059. // QuadraticCurveTo
  17060. cpx = outline[ i ++ ] * scaleX + offset;
  17061. cpy = outline[ i ++ ] * scaleY;
  17062. cpx1 = outline[ i ++ ] * scaleX + offset;
  17063. cpy1 = outline[ i ++ ] * scaleY;
  17064. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  17065. laste = pts[ pts.length - 1 ];
  17066. if ( laste ) {
  17067. cpx0 = laste.x;
  17068. cpy0 = laste.y;
  17069. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17070. var t = i2 / divisions;
  17071. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  17072. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  17073. }
  17074. }
  17075. break;
  17076. case 'b':
  17077. // Cubic Bezier Curve
  17078. cpx = outline[ i ++ ] * scaleX + offset;
  17079. cpy = outline[ i ++ ] * scaleY;
  17080. cpx1 = outline[ i ++ ] * scaleX + offset;
  17081. cpy1 = outline[ i ++ ] * scaleY;
  17082. cpx2 = outline[ i ++ ] * scaleX + offset;
  17083. cpy2 = outline[ i ++ ] * scaleY;
  17084. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  17085. laste = pts[ pts.length - 1 ];
  17086. if ( laste ) {
  17087. cpx0 = laste.x;
  17088. cpy0 = laste.y;
  17089. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17090. var t = i2 / divisions;
  17091. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  17092. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  17093. }
  17094. }
  17095. break;
  17096. }
  17097. }
  17098. }
  17099. return { offset: glyph.ha * scale, path: path };
  17100. }
  17101. };
  17102. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  17103. // Parameters
  17104. parameters = parameters || {};
  17105. var size = parameters.size !== undefined ? parameters.size : 100;
  17106. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  17107. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  17108. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  17109. var style = parameters.style !== undefined ? parameters.style : 'normal';
  17110. THREE.FontUtils.size = size;
  17111. THREE.FontUtils.divisions = curveSegments;
  17112. THREE.FontUtils.face = font;
  17113. THREE.FontUtils.weight = weight;
  17114. THREE.FontUtils.style = style;
  17115. // Get a Font data json object
  17116. var data = THREE.FontUtils.drawText( text );
  17117. var paths = data.paths;
  17118. var shapes = [];
  17119. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  17120. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  17121. }
  17122. return shapes;
  17123. };
  17124. /**
  17125. * This code is a quick port of code written in C++ which was submitted to
  17126. * flipcode.com by John W. Ratcliff // July 22, 2000
  17127. * See original code and more information here:
  17128. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  17129. *
  17130. * ported to actionscript by Zevan Rosser
  17131. * www.actionsnippet.com
  17132. *
  17133. * ported to javascript by Joshua Koo
  17134. * http://www.lab4games.net/zz85/blog
  17135. *
  17136. */
  17137. ( function ( namespace ) {
  17138. var EPSILON = 0.0000000001;
  17139. // takes in an contour array and returns
  17140. var process = function ( contour, indices ) {
  17141. var n = contour.length;
  17142. if ( n < 3 ) return null;
  17143. var result = [],
  17144. verts = [],
  17145. vertIndices = [];
  17146. /* we want a counter-clockwise polygon in verts */
  17147. var u, v, w;
  17148. if ( area( contour ) > 0.0 ) {
  17149. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  17150. } else {
  17151. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  17152. }
  17153. var nv = n;
  17154. /* remove nv - 2 vertices, creating 1 triangle every time */
  17155. var count = 2 * nv; /* error detection */
  17156. for ( v = nv - 1; nv > 2; ) {
  17157. /* if we loop, it is probably a non-simple polygon */
  17158. if ( ( count -- ) <= 0 ) {
  17159. //** Triangulate: ERROR - probable bad polygon!
  17160. //throw ( "Warning, unable to triangulate polygon!" );
  17161. //return null;
  17162. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  17163. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  17164. if ( indices ) return vertIndices;
  17165. return result;
  17166. }
  17167. /* three consecutive vertices in current polygon, <u,v,w> */
  17168. u = v; if ( nv <= u ) u = 0; /* previous */
  17169. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  17170. w = v + 1; if ( nv <= w ) w = 0; /* next */
  17171. if ( snip( contour, u, v, w, nv, verts ) ) {
  17172. var a, b, c, s, t;
  17173. /* true names of the vertices */
  17174. a = verts[ u ];
  17175. b = verts[ v ];
  17176. c = verts[ w ];
  17177. /* output Triangle */
  17178. result.push( [ contour[ a ],
  17179. contour[ b ],
  17180. contour[ c ] ] );
  17181. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  17182. /* remove v from the remaining polygon */
  17183. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  17184. verts[ s ] = verts[ t ];
  17185. }
  17186. nv --;
  17187. /* reset error detection counter */
  17188. count = 2 * nv;
  17189. }
  17190. }
  17191. if ( indices ) return vertIndices;
  17192. return result;
  17193. };
  17194. // calculate area of the contour polygon
  17195. var area = function ( contour ) {
  17196. var n = contour.length;
  17197. var a = 0.0;
  17198. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17199. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17200. }
  17201. return a * 0.5;
  17202. };
  17203. var snip = function ( contour, u, v, w, n, verts ) {
  17204. var p;
  17205. var ax, ay, bx, by;
  17206. var cx, cy, px, py;
  17207. ax = contour[ verts[ u ] ].x;
  17208. ay = contour[ verts[ u ] ].y;
  17209. bx = contour[ verts[ v ] ].x;
  17210. by = contour[ verts[ v ] ].y;
  17211. cx = contour[ verts[ w ] ].x;
  17212. cy = contour[ verts[ w ] ].y;
  17213. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  17214. var aX, aY, bX, bY, cX, cY;
  17215. var apx, apy, bpx, bpy, cpx, cpy;
  17216. var cCROSSap, bCROSScp, aCROSSbp;
  17217. aX = cx - bx; aY = cy - by;
  17218. bX = ax - cx; bY = ay - cy;
  17219. cX = bx - ax; cY = by - ay;
  17220. for ( p = 0; p < n; p ++ ) {
  17221. px = contour[ verts[ p ] ].x;
  17222. py = contour[ verts[ p ] ].y;
  17223. if ( ( ( px === ax ) && ( py === ay ) ) ||
  17224. ( ( px === bx ) && ( py === by ) ) ||
  17225. ( ( px === cx ) && ( py === cy ) ) ) continue;
  17226. apx = px - ax; apy = py - ay;
  17227. bpx = px - bx; bpy = py - by;
  17228. cpx = px - cx; cpy = py - cy;
  17229. // see if p is inside triangle abc
  17230. aCROSSbp = aX * bpy - aY * bpx;
  17231. cCROSSap = cX * apy - cY * apx;
  17232. bCROSScp = bX * cpy - bY * cpx;
  17233. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  17234. }
  17235. return true;
  17236. };
  17237. namespace.Triangulate = process;
  17238. namespace.Triangulate.area = area;
  17239. return namespace;
  17240. } )( THREE.FontUtils );
  17241. // To use the typeface.js face files, hook up the API
  17242. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  17243. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  17244. // File:src/extras/audio/Audio.js
  17245. /**
  17246. * @author mrdoob / http://mrdoob.com/
  17247. */
  17248. THREE.Audio = function ( listener ) {
  17249. THREE.Object3D.call( this );
  17250. this.type = 'Audio';
  17251. this.context = listener.context;
  17252. this.source = this.context.createBufferSource();
  17253. this.source.onended = this.onEnded.bind( this );
  17254. this.gain = this.context.createGain();
  17255. this.gain.connect( this.context.destination );
  17256. this.panner = this.context.createPanner();
  17257. this.panner.connect( this.gain );
  17258. this.autoplay = false;
  17259. this.startTime = 0;
  17260. this.playbackRate = 1;
  17261. this.isPlaying = false;
  17262. };
  17263. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  17264. THREE.Audio.prototype.constructor = THREE.Audio;
  17265. THREE.Audio.prototype.load = function ( file ) {
  17266. var scope = this;
  17267. var request = new XMLHttpRequest();
  17268. request.open( 'GET', file, true );
  17269. request.responseType = 'arraybuffer';
  17270. request.onload = function ( e ) {
  17271. scope.context.decodeAudioData( this.response, function ( buffer ) {
  17272. scope.source.buffer = buffer;
  17273. if ( scope.autoplay ) scope.play();
  17274. } );
  17275. };
  17276. request.send();
  17277. return this;
  17278. };
  17279. THREE.Audio.prototype.play = function () {
  17280. if ( this.isPlaying === true ) {
  17281. console.warn( 'THREE.Audio: Audio is already playing.' );
  17282. return;
  17283. }
  17284. var source = this.context.createBufferSource();
  17285. source.buffer = this.source.buffer;
  17286. source.loop = this.source.loop;
  17287. source.onended = this.source.onended;
  17288. source.start( 0, this.startTime );
  17289. source.playbackRate.value = this.playbackRate;
  17290. this.isPlaying = true;
  17291. this.source = source;
  17292. this.connect();
  17293. };
  17294. THREE.Audio.prototype.pause = function () {
  17295. this.source.stop();
  17296. this.startTime = this.context.currentTime;
  17297. };
  17298. THREE.Audio.prototype.stop = function () {
  17299. this.source.stop();
  17300. this.startTime = 0;
  17301. };
  17302. THREE.Audio.prototype.connect = function () {
  17303. if ( this.filter !== undefined ) {
  17304. this.source.connect( this.filter );
  17305. this.filter.connect( this.panner );
  17306. } else {
  17307. this.source.connect( this.panner );
  17308. }
  17309. };
  17310. THREE.Audio.prototype.disconnect = function () {
  17311. if ( this.filter !== undefined ) {
  17312. this.source.disconnect( this.filter );
  17313. this.filter.disconnect( this.panner );
  17314. } else {
  17315. this.source.disconnect( this.panner );
  17316. }
  17317. };
  17318. THREE.Audio.prototype.setFilter = function ( value ) {
  17319. if ( this.isPlaying === true ) {
  17320. this.disconnect();
  17321. this.filter = value;
  17322. this.connect();
  17323. } else {
  17324. this.filter = value;
  17325. }
  17326. };
  17327. THREE.Audio.prototype.getFilter = function () {
  17328. return this.filter;
  17329. };
  17330. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  17331. this.playbackRate = value;
  17332. if ( this.isPlaying === true ) {
  17333. this.source.playbackRate.value = this.playbackRate;
  17334. }
  17335. };
  17336. THREE.Audio.prototype.getPlaybackRate = function () {
  17337. return this.playbackRate;
  17338. };
  17339. THREE.Audio.prototype.onEnded = function() {
  17340. this.isPlaying = false;
  17341. };
  17342. THREE.Audio.prototype.setLoop = function ( value ) {
  17343. this.source.loop = value;
  17344. };
  17345. THREE.Audio.prototype.getLoop = function () {
  17346. return this.source.loop;
  17347. };
  17348. THREE.Audio.prototype.setRefDistance = function ( value ) {
  17349. this.panner.refDistance = value;
  17350. };
  17351. THREE.Audio.prototype.getRefDistance = function () {
  17352. return this.panner.refDistance;
  17353. };
  17354. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  17355. this.panner.rolloffFactor = value;
  17356. };
  17357. THREE.Audio.prototype.getRolloffFactor = function () {
  17358. return this.panner.rolloffFactor;
  17359. };
  17360. THREE.Audio.prototype.setVolume = function ( value ) {
  17361. this.gain.gain.value = value;
  17362. };
  17363. THREE.Audio.prototype.getVolume = function () {
  17364. return this.gain.gain.value;
  17365. };
  17366. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  17367. var position = new THREE.Vector3();
  17368. return function updateMatrixWorld( force ) {
  17369. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17370. position.setFromMatrixPosition( this.matrixWorld );
  17371. this.panner.setPosition( position.x, position.y, position.z );
  17372. };
  17373. } )();
  17374. // File:src/extras/audio/AudioListener.js
  17375. /**
  17376. * @author mrdoob / http://mrdoob.com/
  17377. */
  17378. THREE.AudioListener = function () {
  17379. THREE.Object3D.call( this );
  17380. this.type = 'AudioListener';
  17381. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  17382. };
  17383. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  17384. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  17385. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  17386. var position = new THREE.Vector3();
  17387. var quaternion = new THREE.Quaternion();
  17388. var scale = new THREE.Vector3();
  17389. var orientation = new THREE.Vector3();
  17390. return function updateMatrixWorld( force ) {
  17391. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17392. var listener = this.context.listener;
  17393. var up = this.up;
  17394. this.matrixWorld.decompose( position, quaternion, scale );
  17395. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  17396. listener.setPosition( position.x, position.y, position.z );
  17397. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  17398. };
  17399. } )();
  17400. // File:src/extras/core/Curve.js
  17401. /**
  17402. * @author zz85 / http://www.lab4games.net/zz85/blog
  17403. * Extensible curve object
  17404. *
  17405. * Some common of Curve methods
  17406. * .getPoint(t), getTangent(t)
  17407. * .getPointAt(u), getTagentAt(u)
  17408. * .getPoints(), .getSpacedPoints()
  17409. * .getLength()
  17410. * .updateArcLengths()
  17411. *
  17412. * This following classes subclasses THREE.Curve:
  17413. *
  17414. * -- 2d classes --
  17415. * THREE.LineCurve
  17416. * THREE.QuadraticBezierCurve
  17417. * THREE.CubicBezierCurve
  17418. * THREE.SplineCurve
  17419. * THREE.ArcCurve
  17420. * THREE.EllipseCurve
  17421. *
  17422. * -- 3d classes --
  17423. * THREE.LineCurve3
  17424. * THREE.QuadraticBezierCurve3
  17425. * THREE.CubicBezierCurve3
  17426. * THREE.SplineCurve3
  17427. * THREE.ClosedSplineCurve3
  17428. *
  17429. * A series of curves can be represented as a THREE.CurvePath
  17430. *
  17431. **/
  17432. /**************************************************************
  17433. * Abstract Curve base class
  17434. **************************************************************/
  17435. THREE.Curve = function () {
  17436. };
  17437. // Virtual base class method to overwrite and implement in subclasses
  17438. // - t [0 .. 1]
  17439. THREE.Curve.prototype.getPoint = function ( t ) {
  17440. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  17441. return null;
  17442. };
  17443. // Get point at relative position in curve according to arc length
  17444. // - u [0 .. 1]
  17445. THREE.Curve.prototype.getPointAt = function ( u ) {
  17446. var t = this.getUtoTmapping( u );
  17447. return this.getPoint( t );
  17448. };
  17449. // Get sequence of points using getPoint( t )
  17450. THREE.Curve.prototype.getPoints = function ( divisions ) {
  17451. if ( ! divisions ) divisions = 5;
  17452. var d, pts = [];
  17453. for ( d = 0; d <= divisions; d ++ ) {
  17454. pts.push( this.getPoint( d / divisions ) );
  17455. }
  17456. return pts;
  17457. };
  17458. // Get sequence of points using getPointAt( u )
  17459. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  17460. if ( ! divisions ) divisions = 5;
  17461. var d, pts = [];
  17462. for ( d = 0; d <= divisions; d ++ ) {
  17463. pts.push( this.getPointAt( d / divisions ) );
  17464. }
  17465. return pts;
  17466. };
  17467. // Get total curve arc length
  17468. THREE.Curve.prototype.getLength = function () {
  17469. var lengths = this.getLengths();
  17470. return lengths[ lengths.length - 1 ];
  17471. };
  17472. // Get list of cumulative segment lengths
  17473. THREE.Curve.prototype.getLengths = function ( divisions ) {
  17474. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  17475. if ( this.cacheArcLengths
  17476. && ( this.cacheArcLengths.length === divisions + 1 )
  17477. && ! this.needsUpdate ) {
  17478. //console.log( "cached", this.cacheArcLengths );
  17479. return this.cacheArcLengths;
  17480. }
  17481. this.needsUpdate = false;
  17482. var cache = [];
  17483. var current, last = this.getPoint( 0 );
  17484. var p, sum = 0;
  17485. cache.push( 0 );
  17486. for ( p = 1; p <= divisions; p ++ ) {
  17487. current = this.getPoint ( p / divisions );
  17488. sum += current.distanceTo( last );
  17489. cache.push( sum );
  17490. last = current;
  17491. }
  17492. this.cacheArcLengths = cache;
  17493. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  17494. };
  17495. THREE.Curve.prototype.updateArcLengths = function() {
  17496. this.needsUpdate = true;
  17497. this.getLengths();
  17498. };
  17499. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17500. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  17501. var arcLengths = this.getLengths();
  17502. var i = 0, il = arcLengths.length;
  17503. var targetArcLength; // The targeted u distance value to get
  17504. if ( distance ) {
  17505. targetArcLength = distance;
  17506. } else {
  17507. targetArcLength = u * arcLengths[ il - 1 ];
  17508. }
  17509. //var time = Date.now();
  17510. // binary search for the index with largest value smaller than target u distance
  17511. var low = 0, high = il - 1, comparison;
  17512. while ( low <= high ) {
  17513. 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
  17514. comparison = arcLengths[ i ] - targetArcLength;
  17515. if ( comparison < 0 ) {
  17516. low = i + 1;
  17517. } else if ( comparison > 0 ) {
  17518. high = i - 1;
  17519. } else {
  17520. high = i;
  17521. break;
  17522. // DONE
  17523. }
  17524. }
  17525. i = high;
  17526. //console.log('b' , i, low, high, Date.now()- time);
  17527. if ( arcLengths[ i ] === targetArcLength ) {
  17528. var t = i / ( il - 1 );
  17529. return t;
  17530. }
  17531. // we could get finer grain at lengths, or use simple interpolation between two points
  17532. var lengthBefore = arcLengths[ i ];
  17533. var lengthAfter = arcLengths[ i + 1 ];
  17534. var segmentLength = lengthAfter - lengthBefore;
  17535. // determine where we are between the 'before' and 'after' points
  17536. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17537. // add that fractional amount to t
  17538. var t = ( i + segmentFraction ) / ( il - 1 );
  17539. return t;
  17540. };
  17541. // Returns a unit vector tangent at t
  17542. // In case any sub curve does not implement its tangent derivation,
  17543. // 2 points a small delta apart will be used to find its gradient
  17544. // which seems to give a reasonable approximation
  17545. THREE.Curve.prototype.getTangent = function( t ) {
  17546. var delta = 0.0001;
  17547. var t1 = t - delta;
  17548. var t2 = t + delta;
  17549. // Capping in case of danger
  17550. if ( t1 < 0 ) t1 = 0;
  17551. if ( t2 > 1 ) t2 = 1;
  17552. var pt1 = this.getPoint( t1 );
  17553. var pt2 = this.getPoint( t2 );
  17554. var vec = pt2.clone().sub( pt1 );
  17555. return vec.normalize();
  17556. };
  17557. THREE.Curve.prototype.getTangentAt = function ( u ) {
  17558. var t = this.getUtoTmapping( u );
  17559. return this.getTangent( t );
  17560. };
  17561. /**************************************************************
  17562. * Utils
  17563. **************************************************************/
  17564. THREE.Curve.Utils = {
  17565. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  17566. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  17567. },
  17568. // Puay Bing, thanks for helping with this derivative!
  17569. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  17570. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  17571. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  17572. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  17573. 3 * t * t * p3;
  17574. },
  17575. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  17576. // To check if my formulas are correct
  17577. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  17578. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  17579. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  17580. var h11 = 3 * t * t - 2 * t; // t3 − t2
  17581. return h00 + h10 + h01 + h11;
  17582. },
  17583. // Catmull-Rom
  17584. interpolate: function( p0, p1, p2, p3, t ) {
  17585. var v0 = ( p2 - p0 ) * 0.5;
  17586. var v1 = ( p3 - p1 ) * 0.5;
  17587. var t2 = t * t;
  17588. var t3 = t * t2;
  17589. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17590. }
  17591. };
  17592. // TODO: Transformation for Curves?
  17593. /**************************************************************
  17594. * 3D Curves
  17595. **************************************************************/
  17596. // A Factory method for creating new curve subclasses
  17597. THREE.Curve.create = function ( constructor, getPointFunc ) {
  17598. constructor.prototype = Object.create( THREE.Curve.prototype );
  17599. constructor.prototype.constructor = constructor;
  17600. constructor.prototype.getPoint = getPointFunc;
  17601. return constructor;
  17602. };
  17603. // File:src/extras/core/CurvePath.js
  17604. /**
  17605. * @author zz85 / http://www.lab4games.net/zz85/blog
  17606. *
  17607. **/
  17608. /**************************************************************
  17609. * Curved Path - a curve path is simply a array of connected
  17610. * curves, but retains the api of a curve
  17611. **************************************************************/
  17612. THREE.CurvePath = function () {
  17613. this.curves = [];
  17614. this.bends = [];
  17615. this.autoClose = false; // Automatically closes the path
  17616. };
  17617. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  17618. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  17619. THREE.CurvePath.prototype.add = function ( curve ) {
  17620. this.curves.push( curve );
  17621. };
  17622. THREE.CurvePath.prototype.checkConnection = function() {
  17623. // TODO
  17624. // If the ending of curve is not connected to the starting
  17625. // or the next curve, then, this is not a real path
  17626. };
  17627. THREE.CurvePath.prototype.closePath = function() {
  17628. // TODO Test
  17629. // and verify for vector3 (needs to implement equals)
  17630. // Add a line curve if start and end of lines are not connected
  17631. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17632. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17633. if ( ! startPoint.equals( endPoint ) ) {
  17634. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  17635. }
  17636. };
  17637. // To get accurate point with reference to
  17638. // entire path distance at time t,
  17639. // following has to be done:
  17640. // 1. Length of each sub path have to be known
  17641. // 2. Locate and identify type of curve
  17642. // 3. Get t for the curve
  17643. // 4. Return curve.getPointAt(t')
  17644. THREE.CurvePath.prototype.getPoint = function( t ) {
  17645. var d = t * this.getLength();
  17646. var curveLengths = this.getCurveLengths();
  17647. var i = 0, diff, curve;
  17648. // To think about boundaries points.
  17649. while ( i < curveLengths.length ) {
  17650. if ( curveLengths[ i ] >= d ) {
  17651. diff = curveLengths[ i ] - d;
  17652. curve = this.curves[ i ];
  17653. var u = 1 - diff / curve.getLength();
  17654. return curve.getPointAt( u );
  17655. }
  17656. i ++;
  17657. }
  17658. return null;
  17659. // loop where sum != 0, sum > d , sum+1 <d
  17660. };
  17661. /*
  17662. THREE.CurvePath.prototype.getTangent = function( t ) {
  17663. };*/
  17664. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17665. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17666. // getPoint() depends on getLength
  17667. THREE.CurvePath.prototype.getLength = function() {
  17668. var lens = this.getCurveLengths();
  17669. return lens[ lens.length - 1 ];
  17670. };
  17671. // Compute lengths and cache them
  17672. // We cannot overwrite getLengths() because UtoT mapping uses it.
  17673. THREE.CurvePath.prototype.getCurveLengths = function() {
  17674. // We use cache values if curves and cache array are same length
  17675. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  17676. return this.cacheLengths;
  17677. }
  17678. // Get length of sub-curve
  17679. // Push sums into cached array
  17680. var lengths = [], sums = 0;
  17681. var i, il = this.curves.length;
  17682. for ( i = 0; i < il; i ++ ) {
  17683. sums += this.curves[ i ].getLength();
  17684. lengths.push( sums );
  17685. }
  17686. this.cacheLengths = lengths;
  17687. return lengths;
  17688. };
  17689. // Returns min and max coordinates
  17690. THREE.CurvePath.prototype.getBoundingBox = function () {
  17691. var points = this.getPoints();
  17692. var maxX, maxY, maxZ;
  17693. var minX, minY, minZ;
  17694. maxX = maxY = Number.NEGATIVE_INFINITY;
  17695. minX = minY = Number.POSITIVE_INFINITY;
  17696. var p, i, il, sum;
  17697. var v3 = points[ 0 ] instanceof THREE.Vector3;
  17698. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  17699. for ( i = 0, il = points.length; i < il; i ++ ) {
  17700. p = points[ i ];
  17701. if ( p.x > maxX ) maxX = p.x;
  17702. else if ( p.x < minX ) minX = p.x;
  17703. if ( p.y > maxY ) maxY = p.y;
  17704. else if ( p.y < minY ) minY = p.y;
  17705. if ( v3 ) {
  17706. if ( p.z > maxZ ) maxZ = p.z;
  17707. else if ( p.z < minZ ) minZ = p.z;
  17708. }
  17709. sum.add( p );
  17710. }
  17711. var ret = {
  17712. minX: minX,
  17713. minY: minY,
  17714. maxX: maxX,
  17715. maxY: maxY
  17716. };
  17717. if ( v3 ) {
  17718. ret.maxZ = maxZ;
  17719. ret.minZ = minZ;
  17720. }
  17721. return ret;
  17722. };
  17723. /**************************************************************
  17724. * Create Geometries Helpers
  17725. **************************************************************/
  17726. /// Generate geometry from path points (for Line or Points objects)
  17727. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  17728. var pts = this.getPoints( divisions, true );
  17729. return this.createGeometry( pts );
  17730. };
  17731. // Generate geometry from equidistant sampling along the path
  17732. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  17733. var pts = this.getSpacedPoints( divisions, true );
  17734. return this.createGeometry( pts );
  17735. };
  17736. THREE.CurvePath.prototype.createGeometry = function( points ) {
  17737. var geometry = new THREE.Geometry();
  17738. for ( var i = 0; i < points.length; i ++ ) {
  17739. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0 ) );
  17740. }
  17741. return geometry;
  17742. };
  17743. /**************************************************************
  17744. * Bend / Wrap Helper Methods
  17745. **************************************************************/
  17746. // Wrap path / Bend modifiers?
  17747. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  17748. this.bends.push( bendpath );
  17749. };
  17750. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  17751. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  17752. var i, il;
  17753. if ( ! bends ) {
  17754. bends = this.bends;
  17755. }
  17756. for ( i = 0, il = bends.length; i < il; i ++ ) {
  17757. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17758. }
  17759. return oldPts;
  17760. };
  17761. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  17762. var oldPts = this.getSpacedPoints( segments );
  17763. var i, il;
  17764. if ( ! bends ) {
  17765. bends = this.bends;
  17766. }
  17767. for ( i = 0, il = bends.length; i < il; i ++ ) {
  17768. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17769. }
  17770. return oldPts;
  17771. };
  17772. // This returns getPoints() bend/wrapped around the contour of a path.
  17773. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  17774. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  17775. var bounds = this.getBoundingBox();
  17776. var i, il, p, oldX, oldY, xNorm;
  17777. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  17778. p = oldPts[ i ];
  17779. oldX = p.x;
  17780. oldY = p.y;
  17781. xNorm = oldX / bounds.maxX;
  17782. // If using actual distance, for length > path, requires line extrusions
  17783. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  17784. xNorm = path.getUtoTmapping( xNorm, oldX );
  17785. // check for out of bounds?
  17786. var pathPt = path.getPoint( xNorm );
  17787. var normal = path.getTangent( xNorm );
  17788. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  17789. p.x = pathPt.x + normal.x;
  17790. p.y = pathPt.y + normal.y;
  17791. }
  17792. return oldPts;
  17793. };
  17794. // File:src/extras/core/Path.js
  17795. /**
  17796. * @author zz85 / http://www.lab4games.net/zz85/blog
  17797. * Creates free form 2d path using series of points, lines or curves.
  17798. *
  17799. **/
  17800. THREE.Path = function ( points ) {
  17801. THREE.CurvePath.call( this );
  17802. this.actions = [];
  17803. if ( points ) {
  17804. this.fromPoints( points );
  17805. }
  17806. };
  17807. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  17808. THREE.Path.prototype.constructor = THREE.Path;
  17809. THREE.PathActions = {
  17810. MOVE_TO: 'moveTo',
  17811. LINE_TO: 'lineTo',
  17812. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  17813. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  17814. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  17815. ARC: 'arc', // Circle
  17816. ELLIPSE: 'ellipse'
  17817. };
  17818. // TODO Clean up PATH API
  17819. // Create path using straight lines to connect all points
  17820. // - vectors: array of Vector2
  17821. THREE.Path.prototype.fromPoints = function ( vectors ) {
  17822. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  17823. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  17824. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  17825. }
  17826. };
  17827. // startPath() endPath()?
  17828. THREE.Path.prototype.moveTo = function ( x, y ) {
  17829. var args = Array.prototype.slice.call( arguments );
  17830. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  17831. };
  17832. THREE.Path.prototype.lineTo = function ( x, y ) {
  17833. var args = Array.prototype.slice.call( arguments );
  17834. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17835. var x0 = lastargs[ lastargs.length - 2 ];
  17836. var y0 = lastargs[ lastargs.length - 1 ];
  17837. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  17838. this.curves.push( curve );
  17839. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  17840. };
  17841. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  17842. var args = Array.prototype.slice.call( arguments );
  17843. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17844. var x0 = lastargs[ lastargs.length - 2 ];
  17845. var y0 = lastargs[ lastargs.length - 1 ];
  17846. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  17847. new THREE.Vector2( aCPx, aCPy ),
  17848. new THREE.Vector2( aX, aY ) );
  17849. this.curves.push( curve );
  17850. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  17851. };
  17852. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  17853. aCP2x, aCP2y,
  17854. aX, aY ) {
  17855. var args = Array.prototype.slice.call( arguments );
  17856. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17857. var x0 = lastargs[ lastargs.length - 2 ];
  17858. var y0 = lastargs[ lastargs.length - 1 ];
  17859. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  17860. new THREE.Vector2( aCP1x, aCP1y ),
  17861. new THREE.Vector2( aCP2x, aCP2y ),
  17862. new THREE.Vector2( aX, aY ) );
  17863. this.curves.push( curve );
  17864. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  17865. };
  17866. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  17867. var args = Array.prototype.slice.call( arguments );
  17868. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17869. var x0 = lastargs[ lastargs.length - 2 ];
  17870. var y0 = lastargs[ lastargs.length - 1 ];
  17871. //---
  17872. var npts = [ new THREE.Vector2( x0, y0 ) ];
  17873. Array.prototype.push.apply( npts, pts );
  17874. var curve = new THREE.SplineCurve( npts );
  17875. this.curves.push( curve );
  17876. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  17877. };
  17878. // FUTURE: Change the API or follow canvas API?
  17879. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  17880. aStartAngle, aEndAngle, aClockwise ) {
  17881. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17882. var x0 = lastargs[ lastargs.length - 2 ];
  17883. var y0 = lastargs[ lastargs.length - 1 ];
  17884. this.absarc( aX + x0, aY + y0, aRadius,
  17885. aStartAngle, aEndAngle, aClockwise );
  17886. };
  17887. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  17888. aStartAngle, aEndAngle, aClockwise ) {
  17889. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17890. };
  17891. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  17892. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17893. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17894. var x0 = lastargs[ lastargs.length - 2 ];
  17895. var y0 = lastargs[ lastargs.length - 1 ];
  17896. this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
  17897. aStartAngle, aEndAngle, aClockwise, aRotation );
  17898. };
  17899. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  17900. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17901. var args = [
  17902. aX, aY,
  17903. xRadius, yRadius,
  17904. aStartAngle, aEndAngle,
  17905. aClockwise,
  17906. aRotation || 0 // aRotation is optional.
  17907. ];
  17908. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  17909. aStartAngle, aEndAngle, aClockwise, aRotation );
  17910. this.curves.push( curve );
  17911. var lastPoint = curve.getPoint( 1 );
  17912. args.push( lastPoint.x );
  17913. args.push( lastPoint.y );
  17914. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  17915. };
  17916. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  17917. if ( ! divisions ) divisions = 40;
  17918. var points = [];
  17919. for ( var i = 0; i < divisions; i ++ ) {
  17920. points.push( this.getPoint( i / divisions ) );
  17921. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  17922. }
  17923. // if ( closedPath ) {
  17924. //
  17925. // points.push( points[ 0 ] );
  17926. //
  17927. // }
  17928. return points;
  17929. };
  17930. /* Return an array of vectors based on contour of the path */
  17931. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  17932. if ( this.useSpacedPoints ) {
  17933. return this.getSpacedPoints( divisions, closedPath );
  17934. }
  17935. divisions = divisions || 12;
  17936. var points = [];
  17937. var i, il, item, action, args;
  17938. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  17939. laste, j,
  17940. t, tx, ty;
  17941. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  17942. item = this.actions[ i ];
  17943. action = item.action;
  17944. args = item.args;
  17945. switch ( action ) {
  17946. case THREE.PathActions.MOVE_TO:
  17947. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17948. break;
  17949. case THREE.PathActions.LINE_TO:
  17950. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17951. break;
  17952. case THREE.PathActions.QUADRATIC_CURVE_TO:
  17953. cpx = args[ 2 ];
  17954. cpy = args[ 3 ];
  17955. cpx1 = args[ 0 ];
  17956. cpy1 = args[ 1 ];
  17957. if ( points.length > 0 ) {
  17958. laste = points[ points.length - 1 ];
  17959. cpx0 = laste.x;
  17960. cpy0 = laste.y;
  17961. } else {
  17962. laste = this.actions[ i - 1 ].args;
  17963. cpx0 = laste[ laste.length - 2 ];
  17964. cpy0 = laste[ laste.length - 1 ];
  17965. }
  17966. for ( j = 1; j <= divisions; j ++ ) {
  17967. t = j / divisions;
  17968. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  17969. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  17970. points.push( new THREE.Vector2( tx, ty ) );
  17971. }
  17972. break;
  17973. case THREE.PathActions.BEZIER_CURVE_TO:
  17974. cpx = args[ 4 ];
  17975. cpy = args[ 5 ];
  17976. cpx1 = args[ 0 ];
  17977. cpy1 = args[ 1 ];
  17978. cpx2 = args[ 2 ];
  17979. cpy2 = args[ 3 ];
  17980. if ( points.length > 0 ) {
  17981. laste = points[ points.length - 1 ];
  17982. cpx0 = laste.x;
  17983. cpy0 = laste.y;
  17984. } else {
  17985. laste = this.actions[ i - 1 ].args;
  17986. cpx0 = laste[ laste.length - 2 ];
  17987. cpy0 = laste[ laste.length - 1 ];
  17988. }
  17989. for ( j = 1; j <= divisions; j ++ ) {
  17990. t = j / divisions;
  17991. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  17992. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  17993. points.push( new THREE.Vector2( tx, ty ) );
  17994. }
  17995. break;
  17996. case THREE.PathActions.CSPLINE_THRU:
  17997. laste = this.actions[ i - 1 ].args;
  17998. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  17999. var spts = [ last ];
  18000. var n = divisions * args[ 0 ].length;
  18001. spts = spts.concat( args[ 0 ] );
  18002. var spline = new THREE.SplineCurve( spts );
  18003. for ( j = 1; j <= n; j ++ ) {
  18004. points.push( spline.getPointAt( j / n ) );
  18005. }
  18006. break;
  18007. case THREE.PathActions.ARC:
  18008. var aX = args[ 0 ], aY = args[ 1 ],
  18009. aRadius = args[ 2 ],
  18010. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  18011. aClockwise = !! args[ 5 ];
  18012. var deltaAngle = aEndAngle - aStartAngle;
  18013. var angle;
  18014. var tdivisions = divisions * 2;
  18015. for ( j = 1; j <= tdivisions; j ++ ) {
  18016. t = j / tdivisions;
  18017. if ( ! aClockwise ) {
  18018. t = 1 - t;
  18019. }
  18020. angle = aStartAngle + t * deltaAngle;
  18021. tx = aX + aRadius * Math.cos( angle );
  18022. ty = aY + aRadius * Math.sin( angle );
  18023. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18024. points.push( new THREE.Vector2( tx, ty ) );
  18025. }
  18026. //console.log(points);
  18027. break;
  18028. case THREE.PathActions.ELLIPSE:
  18029. var aX = args[ 0 ], aY = args[ 1 ],
  18030. xRadius = args[ 2 ],
  18031. yRadius = args[ 3 ],
  18032. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  18033. aClockwise = !! args[ 6 ],
  18034. aRotation = args[ 7 ];
  18035. var deltaAngle = aEndAngle - aStartAngle;
  18036. var angle;
  18037. var tdivisions = divisions * 2;
  18038. var cos, sin;
  18039. if ( aRotation !== 0 ) {
  18040. cos = Math.cos( aRotation );
  18041. sin = Math.sin( aRotation );
  18042. }
  18043. for ( j = 1; j <= tdivisions; j ++ ) {
  18044. t = j / tdivisions;
  18045. if ( ! aClockwise ) {
  18046. t = 1 - t;
  18047. }
  18048. angle = aStartAngle + t * deltaAngle;
  18049. tx = aX + xRadius * Math.cos( angle );
  18050. ty = aY + yRadius * Math.sin( angle );
  18051. if ( aRotation !== 0 ) {
  18052. var x = tx, y = ty;
  18053. // Rotate the point about the center of the ellipse.
  18054. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  18055. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  18056. }
  18057. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18058. points.push( new THREE.Vector2( tx, ty ) );
  18059. }
  18060. //console.log(points);
  18061. break;
  18062. } // end switch
  18063. }
  18064. // Normalize to remove the closing point by default.
  18065. var lastPoint = points[ points.length - 1 ];
  18066. var EPSILON = 0.0000000001;
  18067. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  18068. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  18069. points.splice( points.length - 1, 1 );
  18070. if ( closedPath ) {
  18071. points.push( points[ 0 ] );
  18072. }
  18073. return points;
  18074. };
  18075. //
  18076. // Breaks path into shapes
  18077. //
  18078. // Assumptions (if parameter isCCW==true the opposite holds):
  18079. // - solid shapes are defined clockwise (CW)
  18080. // - holes are defined counterclockwise (CCW)
  18081. //
  18082. // If parameter noHoles==true:
  18083. // - all subPaths are regarded as solid shapes
  18084. // - definition order CW/CCW has no relevance
  18085. //
  18086. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  18087. function extractSubpaths( inActions ) {
  18088. var i, il, item, action, args;
  18089. var subPaths = [], lastPath = new THREE.Path();
  18090. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  18091. item = inActions[ i ];
  18092. args = item.args;
  18093. action = item.action;
  18094. if ( action === THREE.PathActions.MOVE_TO ) {
  18095. if ( lastPath.actions.length !== 0 ) {
  18096. subPaths.push( lastPath );
  18097. lastPath = new THREE.Path();
  18098. }
  18099. }
  18100. lastPath[ action ].apply( lastPath, args );
  18101. }
  18102. if ( lastPath.actions.length !== 0 ) {
  18103. subPaths.push( lastPath );
  18104. }
  18105. // console.log(subPaths);
  18106. return subPaths;
  18107. }
  18108. function toShapesNoHoles( inSubpaths ) {
  18109. var shapes = [];
  18110. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  18111. var tmpPath = inSubpaths[ i ];
  18112. var tmpShape = new THREE.Shape();
  18113. tmpShape.actions = tmpPath.actions;
  18114. tmpShape.curves = tmpPath.curves;
  18115. shapes.push( tmpShape );
  18116. }
  18117. //console.log("shape", shapes);
  18118. return shapes;
  18119. }
  18120. function isPointInsidePolygon( inPt, inPolygon ) {
  18121. var EPSILON = 0.0000000001;
  18122. var polyLen = inPolygon.length;
  18123. // inPt on polygon contour => immediate success or
  18124. // toggling of inside/outside at every single! intersection point of an edge
  18125. // with the horizontal line through inPt, left of inPt
  18126. // not counting lowerY endpoints of edges and whole edges on that line
  18127. var inside = false;
  18128. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18129. var edgeLowPt = inPolygon[ p ];
  18130. var edgeHighPt = inPolygon[ q ];
  18131. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18132. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18133. if ( Math.abs( edgeDy ) > EPSILON ) {
  18134. // not parallel
  18135. if ( edgeDy < 0 ) {
  18136. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18137. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18138. }
  18139. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18140. if ( inPt.y === edgeLowPt.y ) {
  18141. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18142. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18143. } else {
  18144. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18145. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18146. if ( perpEdge < 0 ) continue;
  18147. inside = ! inside; // true intersection left of inPt
  18148. }
  18149. } else {
  18150. // parallel or collinear
  18151. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18152. // edge lies on the same horizontal line as inPt
  18153. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18154. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18155. // continue;
  18156. }
  18157. }
  18158. return inside;
  18159. }
  18160. var subPaths = extractSubpaths( this.actions );
  18161. if ( subPaths.length === 0 ) return [];
  18162. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18163. var solid, tmpPath, tmpShape, shapes = [];
  18164. if ( subPaths.length === 1 ) {
  18165. tmpPath = subPaths[ 0 ];
  18166. tmpShape = new THREE.Shape();
  18167. tmpShape.actions = tmpPath.actions;
  18168. tmpShape.curves = tmpPath.curves;
  18169. shapes.push( tmpShape );
  18170. return shapes;
  18171. }
  18172. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  18173. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18174. // console.log("Holes first", holesFirst);
  18175. var betterShapeHoles = [];
  18176. var newShapes = [];
  18177. var newShapeHoles = [];
  18178. var mainIdx = 0;
  18179. var tmpPoints;
  18180. newShapes[ mainIdx ] = undefined;
  18181. newShapeHoles[ mainIdx ] = [];
  18182. var i, il;
  18183. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  18184. tmpPath = subPaths[ i ];
  18185. tmpPoints = tmpPath.getPoints();
  18186. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  18187. solid = isCCW ? ! solid : solid;
  18188. if ( solid ) {
  18189. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18190. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  18191. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  18192. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18193. if ( holesFirst ) mainIdx ++;
  18194. newShapeHoles[ mainIdx ] = [];
  18195. //console.log('cw', i);
  18196. } else {
  18197. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18198. //console.log('ccw', i);
  18199. }
  18200. }
  18201. // only Holes? -> probably all Shapes with wrong orientation
  18202. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18203. if ( newShapes.length > 1 ) {
  18204. var ambiguous = false;
  18205. var toChange = [];
  18206. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18207. betterShapeHoles[ sIdx ] = [];
  18208. }
  18209. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18210. var sho = newShapeHoles[ sIdx ];
  18211. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18212. var ho = sho[ hIdx ];
  18213. var hole_unassigned = true;
  18214. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18215. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18216. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18217. if ( hole_unassigned ) {
  18218. hole_unassigned = false;
  18219. betterShapeHoles[ s2Idx ].push( ho );
  18220. } else {
  18221. ambiguous = true;
  18222. }
  18223. }
  18224. }
  18225. if ( hole_unassigned ) {
  18226. betterShapeHoles[ sIdx ].push( ho );
  18227. }
  18228. }
  18229. }
  18230. // console.log("ambiguous: ", ambiguous);
  18231. if ( toChange.length > 0 ) {
  18232. // console.log("to change: ", toChange);
  18233. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18234. }
  18235. }
  18236. var tmpHoles, j, jl;
  18237. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  18238. tmpShape = newShapes[ i ].s;
  18239. shapes.push( tmpShape );
  18240. tmpHoles = newShapeHoles[ i ];
  18241. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18242. tmpShape.holes.push( tmpHoles[ j ].h );
  18243. }
  18244. }
  18245. //console.log("shape", shapes);
  18246. return shapes;
  18247. };
  18248. // File:src/extras/core/Shape.js
  18249. /**
  18250. * @author zz85 / http://www.lab4games.net/zz85/blog
  18251. * Defines a 2d shape plane using paths.
  18252. **/
  18253. // STEP 1 Create a path.
  18254. // STEP 2 Turn path into shape.
  18255. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18256. // STEP 3a - Extract points from each shape, turn to vertices
  18257. // STEP 3b - Triangulate each shape, add faces.
  18258. THREE.Shape = function () {
  18259. THREE.Path.apply( this, arguments );
  18260. this.holes = [];
  18261. };
  18262. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  18263. THREE.Shape.prototype.constructor = THREE.Shape;
  18264. // Convenience method to return ExtrudeGeometry
  18265. THREE.Shape.prototype.extrude = function ( options ) {
  18266. var extruded = new THREE.ExtrudeGeometry( this, options );
  18267. return extruded;
  18268. };
  18269. // Convenience method to return ShapeGeometry
  18270. THREE.Shape.prototype.makeGeometry = function ( options ) {
  18271. var geometry = new THREE.ShapeGeometry( this, options );
  18272. return geometry;
  18273. };
  18274. // Get points of holes
  18275. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  18276. var i, il = this.holes.length, holesPts = [];
  18277. for ( i = 0; i < il; i ++ ) {
  18278. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  18279. }
  18280. return holesPts;
  18281. };
  18282. // Get points of holes (spaced by regular distance)
  18283. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  18284. var i, il = this.holes.length, holesPts = [];
  18285. for ( i = 0; i < il; i ++ ) {
  18286. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  18287. }
  18288. return holesPts;
  18289. };
  18290. // Get points of shape and holes (keypoints based on segments parameter)
  18291. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  18292. return {
  18293. shape: this.getTransformedPoints( divisions ),
  18294. holes: this.getPointsHoles( divisions )
  18295. };
  18296. };
  18297. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  18298. if ( this.useSpacedPoints ) {
  18299. return this.extractAllSpacedPoints( divisions );
  18300. }
  18301. return this.extractAllPoints( divisions );
  18302. };
  18303. //
  18304. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  18305. //
  18306. // return {
  18307. //
  18308. // shape: this.transform( bend, divisions ),
  18309. // holes: this.getPointsHoles( divisions, bend )
  18310. //
  18311. // };
  18312. //
  18313. // };
  18314. // Get points of shape and holes (spaced by regular distance)
  18315. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  18316. return {
  18317. shape: this.getTransformedSpacedPoints( divisions ),
  18318. holes: this.getSpacedPointsHoles( divisions )
  18319. };
  18320. };
  18321. /**************************************************************
  18322. * Utils
  18323. **************************************************************/
  18324. THREE.Shape.Utils = {
  18325. triangulateShape: function ( contour, holes ) {
  18326. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  18327. // inOtherPt needs to be collinear to the inSegment
  18328. if ( inSegPt1.x !== inSegPt2.x ) {
  18329. if ( inSegPt1.x < inSegPt2.x ) {
  18330. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  18331. } else {
  18332. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  18333. }
  18334. } else {
  18335. if ( inSegPt1.y < inSegPt2.y ) {
  18336. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  18337. } else {
  18338. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  18339. }
  18340. }
  18341. }
  18342. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  18343. var EPSILON = 0.0000000001;
  18344. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  18345. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  18346. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  18347. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  18348. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  18349. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  18350. if ( Math.abs( limit ) > EPSILON ) {
  18351. // not parallel
  18352. var perpSeg2;
  18353. if ( limit > 0 ) {
  18354. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  18355. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18356. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  18357. } else {
  18358. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  18359. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18360. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  18361. }
  18362. // i.e. to reduce rounding errors
  18363. // intersection at endpoint of segment#1?
  18364. if ( perpSeg2 === 0 ) {
  18365. if ( ( inExcludeAdjacentSegs ) &&
  18366. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18367. return [ inSeg1Pt1 ];
  18368. }
  18369. if ( perpSeg2 === limit ) {
  18370. if ( ( inExcludeAdjacentSegs ) &&
  18371. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18372. return [ inSeg1Pt2 ];
  18373. }
  18374. // intersection at endpoint of segment#2?
  18375. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  18376. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  18377. // return real intersection point
  18378. var factorSeg1 = perpSeg2 / limit;
  18379. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  18380. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  18381. } else {
  18382. // parallel or collinear
  18383. if ( ( perpSeg1 !== 0 ) ||
  18384. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  18385. // they are collinear or degenerate
  18386. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  18387. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  18388. // both segments are points
  18389. if ( seg1Pt && seg2Pt ) {
  18390. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  18391. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  18392. return [ inSeg1Pt1 ]; // they are the same point
  18393. }
  18394. // segment#1 is a single point
  18395. if ( seg1Pt ) {
  18396. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  18397. return [ inSeg1Pt1 ];
  18398. }
  18399. // segment#2 is a single point
  18400. if ( seg2Pt ) {
  18401. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  18402. return [ inSeg2Pt1 ];
  18403. }
  18404. // they are collinear segments, which might overlap
  18405. var seg1min, seg1max, seg1minVal, seg1maxVal;
  18406. var seg2min, seg2max, seg2minVal, seg2maxVal;
  18407. if ( seg1dx !== 0 ) {
  18408. // the segments are NOT on a vertical line
  18409. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  18410. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  18411. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  18412. } else {
  18413. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  18414. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  18415. }
  18416. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  18417. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  18418. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  18419. } else {
  18420. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  18421. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  18422. }
  18423. } else {
  18424. // the segments are on a vertical line
  18425. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  18426. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  18427. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  18428. } else {
  18429. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  18430. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  18431. }
  18432. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  18433. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  18434. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  18435. } else {
  18436. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  18437. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  18438. }
  18439. }
  18440. if ( seg1minVal <= seg2minVal ) {
  18441. if ( seg1maxVal < seg2minVal ) return [];
  18442. if ( seg1maxVal === seg2minVal ) {
  18443. if ( inExcludeAdjacentSegs ) return [];
  18444. return [ seg2min ];
  18445. }
  18446. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  18447. return [ seg2min, seg2max ];
  18448. } else {
  18449. if ( seg1minVal > seg2maxVal ) return [];
  18450. if ( seg1minVal === seg2maxVal ) {
  18451. if ( inExcludeAdjacentSegs ) return [];
  18452. return [ seg1min ];
  18453. }
  18454. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  18455. return [ seg1min, seg2max ];
  18456. }
  18457. }
  18458. }
  18459. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  18460. // The order of legs is important
  18461. var EPSILON = 0.0000000001;
  18462. // translation of all points, so that Vertex is at (0,0)
  18463. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  18464. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  18465. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  18466. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  18467. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  18468. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  18469. if ( Math.abs( from2toAngle ) > EPSILON ) {
  18470. // angle != 180 deg.
  18471. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  18472. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  18473. if ( from2toAngle > 0 ) {
  18474. // main angle < 180 deg.
  18475. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  18476. } else {
  18477. // main angle > 180 deg.
  18478. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  18479. }
  18480. } else {
  18481. // angle == 180 deg.
  18482. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  18483. return ( from2otherAngle > 0 );
  18484. }
  18485. }
  18486. function removeHoles( contour, holes ) {
  18487. var shape = contour.concat(); // work on this shape
  18488. var hole;
  18489. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  18490. // Check if hole point lies within angle around shape point
  18491. var lastShapeIdx = shape.length - 1;
  18492. var prevShapeIdx = inShapeIdx - 1;
  18493. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  18494. var nextShapeIdx = inShapeIdx + 1;
  18495. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  18496. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  18497. if ( ! insideAngle ) {
  18498. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  18499. return false;
  18500. }
  18501. // Check if shape point lies within angle around hole point
  18502. var lastHoleIdx = hole.length - 1;
  18503. var prevHoleIdx = inHoleIdx - 1;
  18504. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  18505. var nextHoleIdx = inHoleIdx + 1;
  18506. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  18507. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  18508. if ( ! insideAngle ) {
  18509. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  18510. return false;
  18511. }
  18512. return true;
  18513. }
  18514. function intersectsShapeEdge( inShapePt, inHolePt ) {
  18515. // checks for intersections with shape edges
  18516. var sIdx, nextIdx, intersection;
  18517. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  18518. nextIdx = sIdx + 1; nextIdx %= shape.length;
  18519. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  18520. if ( intersection.length > 0 ) return true;
  18521. }
  18522. return false;
  18523. }
  18524. var indepHoles = [];
  18525. function intersectsHoleEdge( inShapePt, inHolePt ) {
  18526. // checks for intersections with hole edges
  18527. var ihIdx, chkHole,
  18528. hIdx, nextIdx, intersection;
  18529. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  18530. chkHole = holes[ indepHoles[ ihIdx ]];
  18531. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  18532. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  18533. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  18534. if ( intersection.length > 0 ) return true;
  18535. }
  18536. }
  18537. return false;
  18538. }
  18539. var holeIndex, shapeIndex,
  18540. shapePt, holePt,
  18541. holeIdx, cutKey, failedCuts = [],
  18542. tmpShape1, tmpShape2,
  18543. tmpHole1, tmpHole2;
  18544. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18545. indepHoles.push( h );
  18546. }
  18547. var minShapeIndex = 0;
  18548. var counter = indepHoles.length * 2;
  18549. while ( indepHoles.length > 0 ) {
  18550. counter --;
  18551. if ( counter < 0 ) {
  18552. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  18553. break;
  18554. }
  18555. // search for shape-vertex and hole-vertex,
  18556. // which can be connected without intersections
  18557. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  18558. shapePt = shape[ shapeIndex ];
  18559. holeIndex = - 1;
  18560. // search for hole which can be reached without intersections
  18561. for ( var h = 0; h < indepHoles.length; h ++ ) {
  18562. holeIdx = indepHoles[ h ];
  18563. // prevent multiple checks
  18564. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  18565. if ( failedCuts[ cutKey ] !== undefined ) continue;
  18566. hole = holes[ holeIdx ];
  18567. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  18568. holePt = hole[ h2 ];
  18569. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  18570. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  18571. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  18572. holeIndex = h2;
  18573. indepHoles.splice( h, 1 );
  18574. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  18575. tmpShape2 = shape.slice( shapeIndex );
  18576. tmpHole1 = hole.slice( holeIndex );
  18577. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  18578. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  18579. minShapeIndex = shapeIndex;
  18580. // Debug only, to show the selected cuts
  18581. // glob_CutLines.push( [ shapePt, holePt ] );
  18582. break;
  18583. }
  18584. if ( holeIndex >= 0 ) break; // hole-vertex found
  18585. failedCuts[ cutKey ] = true; // remember failure
  18586. }
  18587. if ( holeIndex >= 0 ) break; // hole-vertex found
  18588. }
  18589. }
  18590. return shape; /* shape with no holes */
  18591. }
  18592. var i, il, f, face,
  18593. key, index,
  18594. allPointsMap = {};
  18595. // 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.
  18596. var allpoints = contour.concat();
  18597. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18598. Array.prototype.push.apply( allpoints, holes[ h ] );
  18599. }
  18600. //console.log( "allpoints",allpoints, allpoints.length );
  18601. // prepare all points map
  18602. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  18603. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  18604. if ( allPointsMap[ key ] !== undefined ) {
  18605. console.warn( "THREE.Shape: Duplicate point", key );
  18606. }
  18607. allPointsMap[ key ] = i;
  18608. }
  18609. // remove holes by cutting paths to holes and adding them to the shape
  18610. var shapeWithoutHoles = removeHoles( contour, holes );
  18611. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  18612. //console.log( "triangles",triangles, triangles.length );
  18613. // check all face vertices against all points map
  18614. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  18615. face = triangles[ i ];
  18616. for ( f = 0; f < 3; f ++ ) {
  18617. key = face[ f ].x + ":" + face[ f ].y;
  18618. index = allPointsMap[ key ];
  18619. if ( index !== undefined ) {
  18620. face[ f ] = index;
  18621. }
  18622. }
  18623. }
  18624. return triangles.concat();
  18625. },
  18626. isClockWise: function ( pts ) {
  18627. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  18628. },
  18629. // Bezier Curves formulas obtained from
  18630. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  18631. // Quad Bezier Functions
  18632. b2p0: function ( t, p ) {
  18633. var k = 1 - t;
  18634. return k * k * p;
  18635. },
  18636. b2p1: function ( t, p ) {
  18637. return 2 * ( 1 - t ) * t * p;
  18638. },
  18639. b2p2: function ( t, p ) {
  18640. return t * t * p;
  18641. },
  18642. b2: function ( t, p0, p1, p2 ) {
  18643. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  18644. },
  18645. // Cubic Bezier Functions
  18646. b3p0: function ( t, p ) {
  18647. var k = 1 - t;
  18648. return k * k * k * p;
  18649. },
  18650. b3p1: function ( t, p ) {
  18651. var k = 1 - t;
  18652. return 3 * k * k * t * p;
  18653. },
  18654. b3p2: function ( t, p ) {
  18655. var k = 1 - t;
  18656. return 3 * k * t * t * p;
  18657. },
  18658. b3p3: function ( t, p ) {
  18659. return t * t * t * p;
  18660. },
  18661. b3: function ( t, p0, p1, p2, p3 ) {
  18662. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  18663. }
  18664. };
  18665. // File:src/extras/curves/LineCurve.js
  18666. /**************************************************************
  18667. * Line
  18668. **************************************************************/
  18669. THREE.LineCurve = function ( v1, v2 ) {
  18670. this.v1 = v1;
  18671. this.v2 = v2;
  18672. };
  18673. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  18674. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  18675. THREE.LineCurve.prototype.getPoint = function ( t ) {
  18676. var point = this.v2.clone().sub( this.v1 );
  18677. point.multiplyScalar( t ).add( this.v1 );
  18678. return point;
  18679. };
  18680. // Line curve is linear, so we can overwrite default getPointAt
  18681. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  18682. return this.getPoint( u );
  18683. };
  18684. THREE.LineCurve.prototype.getTangent = function( t ) {
  18685. var tangent = this.v2.clone().sub( this.v1 );
  18686. return tangent.normalize();
  18687. };
  18688. // File:src/extras/curves/QuadraticBezierCurve.js
  18689. /**************************************************************
  18690. * Quadratic Bezier curve
  18691. **************************************************************/
  18692. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  18693. this.v0 = v0;
  18694. this.v1 = v1;
  18695. this.v2 = v2;
  18696. };
  18697. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18698. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  18699. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  18700. var vector = new THREE.Vector2();
  18701. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18702. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18703. return vector;
  18704. };
  18705. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  18706. var vector = new THREE.Vector2();
  18707. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  18708. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  18709. // returns unit vector
  18710. return vector.normalize();
  18711. };
  18712. // File:src/extras/curves/CubicBezierCurve.js
  18713. /**************************************************************
  18714. * Cubic Bezier curve
  18715. **************************************************************/
  18716. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  18717. this.v0 = v0;
  18718. this.v1 = v1;
  18719. this.v2 = v2;
  18720. this.v3 = v3;
  18721. };
  18722. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18723. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  18724. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  18725. var tx, ty;
  18726. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18727. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18728. return new THREE.Vector2( tx, ty );
  18729. };
  18730. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  18731. var tx, ty;
  18732. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18733. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18734. var tangent = new THREE.Vector2( tx, ty );
  18735. tangent.normalize();
  18736. return tangent;
  18737. };
  18738. // File:src/extras/curves/SplineCurve.js
  18739. /**************************************************************
  18740. * Spline curve
  18741. **************************************************************/
  18742. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  18743. this.points = ( points == undefined ) ? [] : points;
  18744. };
  18745. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  18746. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  18747. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  18748. var points = this.points;
  18749. var point = ( points.length - 1 ) * t;
  18750. var intPoint = Math.floor( point );
  18751. var weight = point - intPoint;
  18752. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18753. var point1 = points[ intPoint ];
  18754. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18755. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18756. var vector = new THREE.Vector2();
  18757. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18758. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18759. return vector;
  18760. };
  18761. // File:src/extras/curves/EllipseCurve.js
  18762. /**************************************************************
  18763. * Ellipse curve
  18764. **************************************************************/
  18765. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18766. this.aX = aX;
  18767. this.aY = aY;
  18768. this.xRadius = xRadius;
  18769. this.yRadius = yRadius;
  18770. this.aStartAngle = aStartAngle;
  18771. this.aEndAngle = aEndAngle;
  18772. this.aClockwise = aClockwise;
  18773. this.aRotation = aRotation || 0;
  18774. };
  18775. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  18776. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  18777. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  18778. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18779. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  18780. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  18781. var angle;
  18782. if ( this.aClockwise === true ) {
  18783. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  18784. } else {
  18785. angle = this.aStartAngle + t * deltaAngle;
  18786. }
  18787. var x = this.aX + this.xRadius * Math.cos( angle );
  18788. var y = this.aY + this.yRadius * Math.sin( angle );
  18789. if ( this.aRotation !== 0 ) {
  18790. var cos = Math.cos( this.aRotation );
  18791. var sin = Math.sin( this.aRotation );
  18792. var tx = x, ty = y;
  18793. // Rotate the point about the center of the ellipse.
  18794. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  18795. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  18796. }
  18797. return new THREE.Vector2( x, y );
  18798. };
  18799. // File:src/extras/curves/ArcCurve.js
  18800. /**************************************************************
  18801. * Arc curve
  18802. **************************************************************/
  18803. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18804. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18805. };
  18806. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  18807. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  18808. // File:src/extras/curves/LineCurve3.js
  18809. /**************************************************************
  18810. * Line3D
  18811. **************************************************************/
  18812. THREE.LineCurve3 = THREE.Curve.create(
  18813. function ( v1, v2 ) {
  18814. this.v1 = v1;
  18815. this.v2 = v2;
  18816. },
  18817. function ( t ) {
  18818. var vector = new THREE.Vector3();
  18819. vector.subVectors( this.v2, this.v1 ); // diff
  18820. vector.multiplyScalar( t );
  18821. vector.add( this.v1 );
  18822. return vector;
  18823. }
  18824. );
  18825. // File:src/extras/curves/QuadraticBezierCurve3.js
  18826. /**************************************************************
  18827. * Quadratic Bezier 3D curve
  18828. **************************************************************/
  18829. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  18830. function ( v0, v1, v2 ) {
  18831. this.v0 = v0;
  18832. this.v1 = v1;
  18833. this.v2 = v2;
  18834. },
  18835. function ( t ) {
  18836. var vector = new THREE.Vector3();
  18837. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18838. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18839. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  18840. return vector;
  18841. }
  18842. );
  18843. // File:src/extras/curves/CubicBezierCurve3.js
  18844. /**************************************************************
  18845. * Cubic Bezier 3D curve
  18846. **************************************************************/
  18847. THREE.CubicBezierCurve3 = THREE.Curve.create(
  18848. function ( v0, v1, v2, v3 ) {
  18849. this.v0 = v0;
  18850. this.v1 = v1;
  18851. this.v2 = v2;
  18852. this.v3 = v3;
  18853. },
  18854. function ( t ) {
  18855. var vector = new THREE.Vector3();
  18856. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18857. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18858. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  18859. return vector;
  18860. }
  18861. );
  18862. // File:src/extras/curves/SplineCurve3.js
  18863. /**************************************************************
  18864. * Spline 3D curve
  18865. **************************************************************/
  18866. THREE.SplineCurve3 = THREE.Curve.create(
  18867. function ( points /* array of Vector3 */ ) {
  18868. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  18869. this.points = ( points == undefined ) ? [] : points;
  18870. },
  18871. function ( t ) {
  18872. var points = this.points;
  18873. var point = ( points.length - 1 ) * t;
  18874. var intPoint = Math.floor( point );
  18875. var weight = point - intPoint;
  18876. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  18877. var point1 = points[ intPoint ];
  18878. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18879. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18880. var vector = new THREE.Vector3();
  18881. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18882. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18883. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  18884. return vector;
  18885. }
  18886. );
  18887. // File:src/extras/curves/CatmullRomCurve3.js
  18888. /**
  18889. * @author zz85 https://github.com/zz85
  18890. *
  18891. * Centripetal CatmullRom Curve - which is useful for avoiding
  18892. * cusps and self-intersections in non-uniform catmull rom curves.
  18893. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18894. *
  18895. * curve.type accepts centripetal(default), chordal and catmullrom
  18896. * curve.tension is used for catmullrom which defaults to 0.5
  18897. */
  18898. THREE.CatmullRomCurve3 = ( function() {
  18899. var
  18900. tmp = new THREE.Vector3(),
  18901. px = new CubicPoly(),
  18902. py = new CubicPoly(),
  18903. pz = new CubicPoly();
  18904. /*
  18905. Based on an optimized c++ solution in
  18906. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18907. - http://ideone.com/NoEbVM
  18908. This CubicPoly class could be used for reusing some variables and calculations,
  18909. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18910. which can be placed in CurveUtils.
  18911. */
  18912. function CubicPoly() {
  18913. }
  18914. /*
  18915. * Compute coefficients for a cubic polynomial
  18916. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18917. * such that
  18918. * p(0) = x0, p(1) = x1
  18919. * and
  18920. * p'(0) = t0, p'(1) = t1.
  18921. */
  18922. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  18923. this.c0 = x0;
  18924. this.c1 = t0;
  18925. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18926. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18927. };
  18928. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18929. // compute tangents when parameterized in [t1,t2]
  18930. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18931. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18932. // rescale tangents for parametrization in [0,1]
  18933. t1 *= dt1;
  18934. t2 *= dt1;
  18935. // initCubicPoly
  18936. this.init( x1, x2, t1, t2 );
  18937. };
  18938. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  18939. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  18940. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18941. };
  18942. CubicPoly.prototype.calc = function( t ) {
  18943. var t2 = t * t;
  18944. var t3 = t2 * t;
  18945. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  18946. };
  18947. // Subclass Three.js curve
  18948. return THREE.Curve.create(
  18949. function ( p /* array of Vector3 */ ) {
  18950. this.points = p || [];
  18951. },
  18952. function ( t ) {
  18953. var points = this.points,
  18954. point, intPoint, weight, l;
  18955. l = points.length;
  18956. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  18957. point = ( l - 1 ) * t;
  18958. intPoint = Math.floor( point );
  18959. weight = point - intPoint;
  18960. if ( weight === 0 && intPoint === l - 1 ) {
  18961. intPoint = l - 2;
  18962. weight = 1;
  18963. }
  18964. var p0, p1, p2, p3;
  18965. if ( intPoint === 0 ) {
  18966. // extrapolate first point
  18967. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18968. p0 = tmp;
  18969. } else {
  18970. p0 = points[ intPoint - 1 ];
  18971. }
  18972. p1 = points[ intPoint ];
  18973. p2 = points[ intPoint + 1 ];
  18974. if ( intPoint + 2 < l ) {
  18975. p3 = points[ intPoint + 2 ]
  18976. } else {
  18977. // extrapolate last point
  18978. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  18979. p3 = tmp;
  18980. }
  18981. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  18982. // init Centripetal / Chordal Catmull-Rom
  18983. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  18984. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18985. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18986. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18987. // safety check for repeated points
  18988. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18989. if ( dt0 < 1e-4 ) dt0 = dt1;
  18990. if ( dt2 < 1e-4 ) dt2 = dt1;
  18991. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18992. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18993. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18994. } else if ( this.type === 'catmullrom' ) {
  18995. var tension = this.tension !== undefined ? this.tension : 0.5;
  18996. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  18997. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  18998. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  18999. }
  19000. var v = new THREE.Vector3(
  19001. px.calc( weight ),
  19002. py.calc( weight ),
  19003. pz.calc( weight )
  19004. );
  19005. return v;
  19006. }
  19007. );
  19008. } )();
  19009. // File:src/extras/curves/ClosedSplineCurve3.js
  19010. /**************************************************************
  19011. * Closed Spline 3D curve
  19012. **************************************************************/
  19013. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  19014. function ( points /* array of Vector3 */ ) {
  19015. this.points = ( points == undefined ) ? [] : points;
  19016. },
  19017. function ( t ) {
  19018. var points = this.points;
  19019. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  19020. var intPoint = Math.floor( point );
  19021. var weight = point - intPoint;
  19022. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  19023. var point0 = points[ ( intPoint - 1 ) % points.length ];
  19024. var point1 = points[ ( intPoint ) % points.length ];
  19025. var point2 = points[ ( intPoint + 1 ) % points.length ];
  19026. var point3 = points[ ( intPoint + 2 ) % points.length ];
  19027. var vector = new THREE.Vector3();
  19028. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  19029. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  19030. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  19031. return vector;
  19032. }
  19033. );
  19034. // File:src/extras/geometries/BoxGeometry.js
  19035. /**
  19036. * @author mrdoob / http://mrdoob.com/
  19037. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  19038. */
  19039. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  19040. THREE.Geometry.call( this );
  19041. this.type = 'BoxGeometry';
  19042. this.parameters = {
  19043. width: width,
  19044. height: height,
  19045. depth: depth,
  19046. widthSegments: widthSegments,
  19047. heightSegments: heightSegments,
  19048. depthSegments: depthSegments
  19049. };
  19050. this.widthSegments = widthSegments || 1;
  19051. this.heightSegments = heightSegments || 1;
  19052. this.depthSegments = depthSegments || 1;
  19053. var scope = this;
  19054. var width_half = width / 2;
  19055. var height_half = height / 2;
  19056. var depth_half = depth / 2;
  19057. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  19058. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  19059. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  19060. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  19061. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  19062. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  19063. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  19064. var w, ix, iy,
  19065. gridX = scope.widthSegments,
  19066. gridY = scope.heightSegments,
  19067. width_half = width / 2,
  19068. height_half = height / 2,
  19069. offset = scope.vertices.length;
  19070. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  19071. w = 'z';
  19072. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  19073. w = 'y';
  19074. gridY = scope.depthSegments;
  19075. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  19076. w = 'x';
  19077. gridX = scope.depthSegments;
  19078. }
  19079. var gridX1 = gridX + 1,
  19080. gridY1 = gridY + 1,
  19081. segment_width = width / gridX,
  19082. segment_height = height / gridY,
  19083. normal = new THREE.Vector3();
  19084. normal[ w ] = depth > 0 ? 1 : - 1;
  19085. for ( iy = 0; iy < gridY1; iy ++ ) {
  19086. for ( ix = 0; ix < gridX1; ix ++ ) {
  19087. var vector = new THREE.Vector3();
  19088. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  19089. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  19090. vector[ w ] = depth;
  19091. scope.vertices.push( vector );
  19092. }
  19093. }
  19094. for ( iy = 0; iy < gridY; iy ++ ) {
  19095. for ( ix = 0; ix < gridX; ix ++ ) {
  19096. var a = ix + gridX1 * iy;
  19097. var b = ix + gridX1 * ( iy + 1 );
  19098. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19099. var d = ( ix + 1 ) + gridX1 * iy;
  19100. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  19101. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  19102. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  19103. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  19104. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  19105. face.normal.copy( normal );
  19106. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19107. face.materialIndex = materialIndex;
  19108. scope.faces.push( face );
  19109. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19110. face = new THREE.Face3( b + offset, c + offset, d + offset );
  19111. face.normal.copy( normal );
  19112. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19113. face.materialIndex = materialIndex;
  19114. scope.faces.push( face );
  19115. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19116. }
  19117. }
  19118. }
  19119. this.mergeVertices();
  19120. };
  19121. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19122. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  19123. THREE.BoxGeometry.prototype.clone = function () {
  19124. var geometry = new THREE.BoxGeometry(
  19125. this.parameters.width,
  19126. this.parameters.height,
  19127. this.parameters.depth,
  19128. this.parameters.widthSegments,
  19129. this.parameters.heightSegments,
  19130. this.parameters.depthSegments
  19131. );
  19132. return geometry;
  19133. };
  19134. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  19135. // File:src/extras/geometries/CircleGeometry.js
  19136. /**
  19137. * @author hughes
  19138. */
  19139. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19140. THREE.Geometry.call( this );
  19141. this.type = 'CircleGeometry';
  19142. this.parameters = {
  19143. radius: radius,
  19144. segments: segments,
  19145. thetaStart: thetaStart,
  19146. thetaLength: thetaLength
  19147. };
  19148. radius = radius || 50;
  19149. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19150. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19151. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19152. var i, uvs = [],
  19153. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  19154. this.vertices.push( center );
  19155. uvs.push( centerUV );
  19156. for ( i = 0; i <= segments; i ++ ) {
  19157. var vertex = new THREE.Vector3();
  19158. var segment = thetaStart + i / segments * thetaLength;
  19159. vertex.x = radius * Math.cos( segment );
  19160. vertex.y = radius * Math.sin( segment );
  19161. this.vertices.push( vertex );
  19162. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  19163. }
  19164. var n = new THREE.Vector3( 0, 0, 1 );
  19165. for ( i = 1; i <= segments; i ++ ) {
  19166. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  19167. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  19168. }
  19169. this.computeFaceNormals();
  19170. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19171. };
  19172. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19173. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  19174. THREE.CircleGeometry.prototype.clone = function () {
  19175. var geometry = new THREE.CircleGeometry(
  19176. this.parameters.radius,
  19177. this.parameters.segments,
  19178. this.parameters.thetaStart,
  19179. this.parameters.thetaLength
  19180. );
  19181. return geometry;
  19182. };
  19183. // File:src/extras/geometries/CircleBufferGeometry.js
  19184. /**
  19185. * @author benaadams / https://twitter.com/ben_a_adams
  19186. */
  19187. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19188. THREE.BufferGeometry.call( this );
  19189. this.type = 'CircleBufferGeometry';
  19190. this.parameters = {
  19191. radius: radius,
  19192. segments: segments,
  19193. thetaStart: thetaStart,
  19194. thetaLength: thetaLength
  19195. };
  19196. radius = radius || 50;
  19197. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19198. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19199. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19200. var vertices = segments + 2;
  19201. var positions = new Float32Array( vertices * 3 );
  19202. var normals = new Float32Array( vertices * 3 );
  19203. var uvs = new Float32Array( vertices * 2 );
  19204. // center data is already zero, but need to set a few extras
  19205. normals[ 2 ] = 1.0;
  19206. uvs[ 0 ] = 0.5;
  19207. uvs[ 1 ] = 0.5;
  19208. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  19209. var segment = thetaStart + s / segments * thetaLength;
  19210. positions[ i ] = radius * Math.cos( segment );
  19211. positions[ i + 1 ] = radius * Math.sin( segment );
  19212. normals[ i + 2 ] = 1; // normal z
  19213. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  19214. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  19215. }
  19216. var indices = [];
  19217. for ( var i = 1; i <= segments; i ++ ) {
  19218. indices.push( i );
  19219. indices.push( i + 1 );
  19220. indices.push( 0 );
  19221. }
  19222. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19223. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  19224. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19225. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19226. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19227. };
  19228. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19229. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  19230. THREE.CircleBufferGeometry.prototype.clone = function () {
  19231. var geometry = new THREE.CircleBufferGeometry(
  19232. this.parameters.radius,
  19233. this.parameters.segments,
  19234. this.parameters.thetaStart,
  19235. this.parameters.thetaLength
  19236. );
  19237. geometry.copy( this );
  19238. return geometry;
  19239. };
  19240. // File:src/extras/geometries/CylinderGeometry.js
  19241. /**
  19242. * @author mrdoob / http://mrdoob.com/
  19243. */
  19244. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19245. THREE.Geometry.call( this );
  19246. this.type = 'CylinderGeometry';
  19247. this.parameters = {
  19248. radiusTop: radiusTop,
  19249. radiusBottom: radiusBottom,
  19250. height: height,
  19251. radialSegments: radialSegments,
  19252. heightSegments: heightSegments,
  19253. openEnded: openEnded,
  19254. thetaStart: thetaStart,
  19255. thetaLength: thetaLength
  19256. };
  19257. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  19258. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  19259. height = height !== undefined ? height : 100;
  19260. radialSegments = radialSegments || 8;
  19261. heightSegments = heightSegments || 1;
  19262. openEnded = openEnded !== undefined ? openEnded : false;
  19263. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19264. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  19265. var heightHalf = height / 2;
  19266. var x, y, vertices = [], uvs = [];
  19267. for ( y = 0; y <= heightSegments; y ++ ) {
  19268. var verticesRow = [];
  19269. var uvsRow = [];
  19270. var v = y / heightSegments;
  19271. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19272. for ( x = 0; x <= radialSegments; x ++ ) {
  19273. var u = x / radialSegments;
  19274. var vertex = new THREE.Vector3();
  19275. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  19276. vertex.y = - v * height + heightHalf;
  19277. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  19278. this.vertices.push( vertex );
  19279. verticesRow.push( this.vertices.length - 1 );
  19280. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19281. }
  19282. vertices.push( verticesRow );
  19283. uvs.push( uvsRow );
  19284. }
  19285. var tanTheta = ( radiusBottom - radiusTop ) / height;
  19286. var na, nb;
  19287. for ( x = 0; x < radialSegments; x ++ ) {
  19288. if ( radiusTop !== 0 ) {
  19289. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  19290. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  19291. } else {
  19292. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  19293. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  19294. }
  19295. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  19296. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  19297. for ( y = 0; y < heightSegments; y ++ ) {
  19298. var v1 = vertices[ y ][ x ];
  19299. var v2 = vertices[ y + 1 ][ x ];
  19300. var v3 = vertices[ y + 1 ][ x + 1 ];
  19301. var v4 = vertices[ y ][ x + 1 ];
  19302. var n1 = na.clone();
  19303. var n2 = na.clone();
  19304. var n3 = nb.clone();
  19305. var n4 = nb.clone();
  19306. var uv1 = uvs[ y ][ x ].clone();
  19307. var uv2 = uvs[ y + 1 ][ x ].clone();
  19308. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  19309. var uv4 = uvs[ y ][ x + 1 ].clone();
  19310. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19311. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19312. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19313. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19314. }
  19315. }
  19316. // top cap
  19317. if ( openEnded === false && radiusTop > 0 ) {
  19318. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  19319. for ( x = 0; x < radialSegments; x ++ ) {
  19320. var v1 = vertices[ 0 ][ x ];
  19321. var v2 = vertices[ 0 ][ x + 1 ];
  19322. var v3 = this.vertices.length - 1;
  19323. var n1 = new THREE.Vector3( 0, 1, 0 );
  19324. var n2 = new THREE.Vector3( 0, 1, 0 );
  19325. var n3 = new THREE.Vector3( 0, 1, 0 );
  19326. var uv1 = uvs[ 0 ][ x ].clone();
  19327. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  19328. var uv3 = new THREE.Vector2( uv2.x, 0 );
  19329. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  19330. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19331. }
  19332. }
  19333. // bottom cap
  19334. if ( openEnded === false && radiusBottom > 0 ) {
  19335. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  19336. for ( x = 0; x < radialSegments; x ++ ) {
  19337. var v1 = vertices[ heightSegments ][ x + 1 ];
  19338. var v2 = vertices[ heightSegments ][ x ];
  19339. var v3 = this.vertices.length - 1;
  19340. var n1 = new THREE.Vector3( 0, - 1, 0 );
  19341. var n2 = new THREE.Vector3( 0, - 1, 0 );
  19342. var n3 = new THREE.Vector3( 0, - 1, 0 );
  19343. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  19344. var uv2 = uvs[ heightSegments ][ x ].clone();
  19345. var uv3 = new THREE.Vector2( uv2.x, 1 );
  19346. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  19347. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19348. }
  19349. }
  19350. this.computeFaceNormals();
  19351. };
  19352. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19353. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  19354. THREE.CylinderGeometry.prototype.clone = function () {
  19355. var geometry = new THREE.CylinderGeometry(
  19356. this.parameters.radiusTop,
  19357. this.parameters.radiusBottom,
  19358. this.parameters.height,
  19359. this.parameters.radialSegments,
  19360. this.parameters.heightSegments,
  19361. this.parameters.openEnded,
  19362. this.parameters.thetaStart,
  19363. this.parameters.thetaLength
  19364. );
  19365. return geometry;
  19366. };
  19367. // File:src/extras/geometries/EdgesGeometry.js
  19368. /**
  19369. * @author WestLangley / http://github.com/WestLangley
  19370. */
  19371. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  19372. THREE.BufferGeometry.call( this );
  19373. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19374. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  19375. var edge = [ 0, 0 ], hash = {};
  19376. var sortFunction = function ( a, b ) {
  19377. return a - b;
  19378. };
  19379. var keys = [ 'a', 'b', 'c' ];
  19380. var geometry2;
  19381. if ( geometry instanceof THREE.BufferGeometry ) {
  19382. geometry2 = new THREE.Geometry();
  19383. geometry2.fromBufferGeometry( geometry );
  19384. } else {
  19385. geometry2 = geometry.clone();
  19386. }
  19387. geometry2.mergeVertices();
  19388. geometry2.computeFaceNormals();
  19389. var vertices = geometry2.vertices;
  19390. var faces = geometry2.faces;
  19391. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19392. var face = faces[ i ];
  19393. for ( var j = 0; j < 3; j ++ ) {
  19394. edge[ 0 ] = face[ keys[ j ] ];
  19395. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  19396. edge.sort( sortFunction );
  19397. var key = edge.toString();
  19398. if ( hash[ key ] === undefined ) {
  19399. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  19400. } else {
  19401. hash[ key ].face2 = i;
  19402. }
  19403. }
  19404. }
  19405. var coords = [];
  19406. for ( var key in hash ) {
  19407. var h = hash[ key ];
  19408. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  19409. var vertex = vertices[ h.vert1 ];
  19410. coords.push( vertex.x );
  19411. coords.push( vertex.y );
  19412. coords.push( vertex.z );
  19413. vertex = vertices[ h.vert2 ];
  19414. coords.push( vertex.x );
  19415. coords.push( vertex.y );
  19416. coords.push( vertex.z );
  19417. }
  19418. }
  19419. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  19420. };
  19421. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19422. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  19423. // File:src/extras/geometries/ExtrudeGeometry.js
  19424. /**
  19425. * @author zz85 / http://www.lab4games.net/zz85/blog
  19426. *
  19427. * Creates extruded geometry from a path shape.
  19428. *
  19429. * parameters = {
  19430. *
  19431. * curveSegments: <int>, // number of points on the curves
  19432. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  19433. * amount: <int>, // Depth to extrude the shape
  19434. *
  19435. * bevelEnabled: <bool>, // turn on bevel
  19436. * bevelThickness: <float>, // how deep into the original shape bevel goes
  19437. * bevelSize: <float>, // how far from shape outline is bevel
  19438. * bevelSegments: <int>, // number of bevel layers
  19439. *
  19440. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  19441. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  19442. *
  19443. * uvGenerator: <Object> // object that provides UV generator functions
  19444. *
  19445. * }
  19446. **/
  19447. THREE.ExtrudeGeometry = function ( shapes, options ) {
  19448. if ( typeof( shapes ) === "undefined" ) {
  19449. shapes = [];
  19450. return;
  19451. }
  19452. THREE.Geometry.call( this );
  19453. this.type = 'ExtrudeGeometry';
  19454. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  19455. this.addShapeList( shapes, options );
  19456. this.computeFaceNormals();
  19457. // can't really use automatic vertex normals
  19458. // as then front and back sides get smoothed too
  19459. // should do separate smoothing just for sides
  19460. //this.computeVertexNormals();
  19461. //console.log( "took", ( Date.now() - startTime ) );
  19462. };
  19463. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19464. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  19465. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19466. var sl = shapes.length;
  19467. for ( var s = 0; s < sl; s ++ ) {
  19468. var shape = shapes[ s ];
  19469. this.addShape( shape, options );
  19470. }
  19471. };
  19472. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  19473. var amount = options.amount !== undefined ? options.amount : 100;
  19474. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  19475. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  19476. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  19477. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  19478. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19479. var steps = options.steps !== undefined ? options.steps : 1;
  19480. var extrudePath = options.extrudePath;
  19481. var extrudePts, extrudeByPath = false;
  19482. // Use default WorldUVGenerator if no UV generators are specified.
  19483. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  19484. var splineTube, binormal, normal, position2;
  19485. if ( extrudePath ) {
  19486. extrudePts = extrudePath.getSpacedPoints( steps );
  19487. extrudeByPath = true;
  19488. bevelEnabled = false; // bevels not supported for path extrusion
  19489. // SETUP TNB variables
  19490. // Reuse TNB from TubeGeomtry for now.
  19491. // TODO1 - have a .isClosed in spline?
  19492. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  19493. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  19494. binormal = new THREE.Vector3();
  19495. normal = new THREE.Vector3();
  19496. position2 = new THREE.Vector3();
  19497. }
  19498. // Safeguards if bevels are not enabled
  19499. if ( ! bevelEnabled ) {
  19500. bevelSegments = 0;
  19501. bevelThickness = 0;
  19502. bevelSize = 0;
  19503. }
  19504. // Variables initialization
  19505. var ahole, h, hl; // looping of holes
  19506. var scope = this;
  19507. var shapesOffset = this.vertices.length;
  19508. var shapePoints = shape.extractPoints( curveSegments );
  19509. var vertices = shapePoints.shape;
  19510. var holes = shapePoints.holes;
  19511. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19512. if ( reverse ) {
  19513. vertices = vertices.reverse();
  19514. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  19515. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19516. ahole = holes[ h ];
  19517. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  19518. holes[ h ] = ahole.reverse();
  19519. }
  19520. }
  19521. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  19522. }
  19523. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  19524. /* Vertices */
  19525. var contour = vertices; // vertices has all points but contour has only points of circumference
  19526. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19527. ahole = holes[ h ];
  19528. vertices = vertices.concat( ahole );
  19529. }
  19530. function scalePt2 ( pt, vec, size ) {
  19531. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  19532. return vec.clone().multiplyScalar( size ).add( pt );
  19533. }
  19534. var b, bs, t, z,
  19535. vert, vlen = vertices.length,
  19536. face, flen = faces.length;
  19537. // Find directions for point movement
  19538. function getBevelVec( inPt, inPrev, inNext ) {
  19539. var EPSILON = 0.0000000001;
  19540. // computes for inPt the corresponding point inPt' on a new contour
  19541. // shifted by 1 unit (length of normalized vector) to the left
  19542. // if we walk along contour clockwise, this new contour is outside the old one
  19543. //
  19544. // inPt' is the intersection of the two lines parallel to the two
  19545. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19546. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  19547. // good reading for geometry algorithms (here: line-line intersection)
  19548. // http://geomalgorithms.com/a05-_intersect-1.html
  19549. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  19550. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  19551. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19552. // check for collinear edges
  19553. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19554. if ( Math.abs( collinear0 ) > EPSILON ) {
  19555. // not collinear
  19556. // length of vectors for normalizing
  19557. var v_prev_len = Math.sqrt( v_prev_lensq );
  19558. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19559. // shift adjacent points by unit vectors to the left
  19560. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19561. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19562. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19563. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19564. // scaling factor for v_prev to intersection point
  19565. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19566. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19567. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19568. // vector from inPt to intersection point
  19569. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19570. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19571. // Don't normalize!, otherwise sharp corners become ugly
  19572. // but prevent crazy spikes
  19573. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19574. if ( v_trans_lensq <= 2 ) {
  19575. return new THREE.Vector2( v_trans_x, v_trans_y );
  19576. } else {
  19577. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19578. }
  19579. } else {
  19580. // handle special case of collinear edges
  19581. var direction_eq = false; // assumes: opposite
  19582. if ( v_prev_x > EPSILON ) {
  19583. if ( v_next_x > EPSILON ) {
  19584. direction_eq = true;
  19585. }
  19586. } else {
  19587. if ( v_prev_x < - EPSILON ) {
  19588. if ( v_next_x < - EPSILON ) {
  19589. direction_eq = true;
  19590. }
  19591. } else {
  19592. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19593. direction_eq = true;
  19594. }
  19595. }
  19596. }
  19597. if ( direction_eq ) {
  19598. // console.log("Warning: lines are a straight sequence");
  19599. v_trans_x = - v_prev_y;
  19600. v_trans_y = v_prev_x;
  19601. shrink_by = Math.sqrt( v_prev_lensq );
  19602. } else {
  19603. // console.log("Warning: lines are a straight spike");
  19604. v_trans_x = v_prev_x;
  19605. v_trans_y = v_prev_y;
  19606. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19607. }
  19608. }
  19609. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19610. }
  19611. var contourMovements = [];
  19612. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19613. if ( j === il ) j = 0;
  19614. if ( k === il ) k = 0;
  19615. // (j)---(i)---(k)
  19616. // console.log('i,j,k', i, j , k)
  19617. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19618. }
  19619. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  19620. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19621. ahole = holes[ h ];
  19622. oneHoleMovements = [];
  19623. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19624. if ( j === il ) j = 0;
  19625. if ( k === il ) k = 0;
  19626. // (j)---(i)---(k)
  19627. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19628. }
  19629. holesMovements.push( oneHoleMovements );
  19630. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19631. }
  19632. // Loop bevelSegments, 1 for the front, 1 for the back
  19633. for ( b = 0; b < bevelSegments; b ++ ) {
  19634. //for ( b = bevelSegments; b > 0; b -- ) {
  19635. t = b / bevelSegments;
  19636. z = bevelThickness * ( 1 - t );
  19637. //z = bevelThickness * t;
  19638. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  19639. //bs = bevelSize * t; // linear
  19640. // contract shape
  19641. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19642. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19643. v( vert.x, vert.y, - z );
  19644. }
  19645. // expand holes
  19646. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19647. ahole = holes[ h ];
  19648. oneHoleMovements = holesMovements[ h ];
  19649. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19650. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19651. v( vert.x, vert.y, - z );
  19652. }
  19653. }
  19654. }
  19655. bs = bevelSize;
  19656. // Back facing vertices
  19657. for ( i = 0; i < vlen; i ++ ) {
  19658. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19659. if ( ! extrudeByPath ) {
  19660. v( vert.x, vert.y, 0 );
  19661. } else {
  19662. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19663. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19664. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19665. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19666. v( position2.x, position2.y, position2.z );
  19667. }
  19668. }
  19669. // Add stepped vertices...
  19670. // Including front facing vertices
  19671. var s;
  19672. for ( s = 1; s <= steps; s ++ ) {
  19673. for ( i = 0; i < vlen; i ++ ) {
  19674. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19675. if ( ! extrudeByPath ) {
  19676. v( vert.x, vert.y, amount / steps * s );
  19677. } else {
  19678. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19679. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19680. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19681. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19682. v( position2.x, position2.y, position2.z );
  19683. }
  19684. }
  19685. }
  19686. // Add bevel segments planes
  19687. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19688. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19689. t = b / bevelSegments;
  19690. z = bevelThickness * ( 1 - t );
  19691. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19692. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19693. // contract shape
  19694. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19695. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19696. v( vert.x, vert.y, amount + z );
  19697. }
  19698. // expand holes
  19699. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19700. ahole = holes[ h ];
  19701. oneHoleMovements = holesMovements[ h ];
  19702. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19703. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19704. if ( ! extrudeByPath ) {
  19705. v( vert.x, vert.y, amount + z );
  19706. } else {
  19707. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19708. }
  19709. }
  19710. }
  19711. }
  19712. /* Faces */
  19713. // Top and bottom faces
  19714. buildLidFaces();
  19715. // Sides faces
  19716. buildSideFaces();
  19717. ///// Internal functions
  19718. function buildLidFaces() {
  19719. if ( bevelEnabled ) {
  19720. var layer = 0; // steps + 1
  19721. var offset = vlen * layer;
  19722. // Bottom faces
  19723. for ( i = 0; i < flen; i ++ ) {
  19724. face = faces[ i ];
  19725. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19726. }
  19727. layer = steps + bevelSegments * 2;
  19728. offset = vlen * layer;
  19729. // Top faces
  19730. for ( i = 0; i < flen; i ++ ) {
  19731. face = faces[ i ];
  19732. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19733. }
  19734. } else {
  19735. // Bottom faces
  19736. for ( i = 0; i < flen; i ++ ) {
  19737. face = faces[ i ];
  19738. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19739. }
  19740. // Top faces
  19741. for ( i = 0; i < flen; i ++ ) {
  19742. face = faces[ i ];
  19743. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19744. }
  19745. }
  19746. }
  19747. // Create faces for the z-sides of the shape
  19748. function buildSideFaces() {
  19749. var layeroffset = 0;
  19750. sidewalls( contour, layeroffset );
  19751. layeroffset += contour.length;
  19752. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19753. ahole = holes[ h ];
  19754. sidewalls( ahole, layeroffset );
  19755. //, true
  19756. layeroffset += ahole.length;
  19757. }
  19758. }
  19759. function sidewalls( contour, layeroffset ) {
  19760. var j, k;
  19761. i = contour.length;
  19762. while ( -- i >= 0 ) {
  19763. j = i;
  19764. k = i - 1;
  19765. if ( k < 0 ) k = contour.length - 1;
  19766. //console.log('b', i,j, i-1, k,vertices.length);
  19767. var s = 0, sl = steps + bevelSegments * 2;
  19768. for ( s = 0; s < sl; s ++ ) {
  19769. var slen1 = vlen * s;
  19770. var slen2 = vlen * ( s + 1 );
  19771. var a = layeroffset + j + slen1,
  19772. b = layeroffset + k + slen1,
  19773. c = layeroffset + k + slen2,
  19774. d = layeroffset + j + slen2;
  19775. f4( a, b, c, d, contour, s, sl, j, k );
  19776. }
  19777. }
  19778. }
  19779. function v( x, y, z ) {
  19780. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19781. }
  19782. function f3( a, b, c ) {
  19783. a += shapesOffset;
  19784. b += shapesOffset;
  19785. c += shapesOffset;
  19786. scope.faces.push( new THREE.Face3( a, b, c ) );
  19787. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19788. scope.faceVertexUvs[ 0 ].push( uvs );
  19789. }
  19790. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19791. a += shapesOffset;
  19792. b += shapesOffset;
  19793. c += shapesOffset;
  19794. d += shapesOffset;
  19795. scope.faces.push( new THREE.Face3( a, b, d ) );
  19796. scope.faces.push( new THREE.Face3( b, c, d ) );
  19797. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19798. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19799. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19800. }
  19801. };
  19802. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19803. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19804. var vertices = geometry.vertices;
  19805. var a = vertices[ indexA ];
  19806. var b = vertices[ indexB ];
  19807. var c = vertices[ indexC ];
  19808. return [
  19809. new THREE.Vector2( a.x, a.y ),
  19810. new THREE.Vector2( b.x, b.y ),
  19811. new THREE.Vector2( c.x, c.y )
  19812. ];
  19813. },
  19814. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19815. var vertices = geometry.vertices;
  19816. var a = vertices[ indexA ];
  19817. var b = vertices[ indexB ];
  19818. var c = vertices[ indexC ];
  19819. var d = vertices[ indexD ];
  19820. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19821. return [
  19822. new THREE.Vector2( a.x, 1 - a.z ),
  19823. new THREE.Vector2( b.x, 1 - b.z ),
  19824. new THREE.Vector2( c.x, 1 - c.z ),
  19825. new THREE.Vector2( d.x, 1 - d.z )
  19826. ];
  19827. } else {
  19828. return [
  19829. new THREE.Vector2( a.y, 1 - a.z ),
  19830. new THREE.Vector2( b.y, 1 - b.z ),
  19831. new THREE.Vector2( c.y, 1 - c.z ),
  19832. new THREE.Vector2( d.y, 1 - d.z )
  19833. ];
  19834. }
  19835. }
  19836. };
  19837. // File:src/extras/geometries/ShapeGeometry.js
  19838. /**
  19839. * @author jonobr1 / http://jonobr1.com
  19840. *
  19841. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19842. * ExtrudeGeometry.
  19843. *
  19844. * parameters = {
  19845. *
  19846. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19847. *
  19848. * material: <int> // material index for front and back faces
  19849. * uvGenerator: <Object> // object that provides UV generator functions
  19850. *
  19851. * }
  19852. **/
  19853. THREE.ShapeGeometry = function ( shapes, options ) {
  19854. THREE.Geometry.call( this );
  19855. this.type = 'ShapeGeometry';
  19856. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19857. this.addShapeList( shapes, options );
  19858. this.computeFaceNormals();
  19859. };
  19860. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19861. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19862. /**
  19863. * Add an array of shapes to THREE.ShapeGeometry.
  19864. */
  19865. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19866. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19867. this.addShape( shapes[ i ], options );
  19868. }
  19869. return this;
  19870. };
  19871. /**
  19872. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19873. */
  19874. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19875. if ( options === undefined ) options = {};
  19876. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19877. var material = options.material;
  19878. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19879. //
  19880. var i, l, hole;
  19881. var shapesOffset = this.vertices.length;
  19882. var shapePoints = shape.extractPoints( curveSegments );
  19883. var vertices = shapePoints.shape;
  19884. var holes = shapePoints.holes;
  19885. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19886. if ( reverse ) {
  19887. vertices = vertices.reverse();
  19888. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19889. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19890. hole = holes[ i ];
  19891. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19892. holes[ i ] = hole.reverse();
  19893. }
  19894. }
  19895. reverse = false;
  19896. }
  19897. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19898. // Vertices
  19899. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19900. hole = holes[ i ];
  19901. vertices = vertices.concat( hole );
  19902. }
  19903. //
  19904. var vert, vlen = vertices.length;
  19905. var face, flen = faces.length;
  19906. for ( i = 0; i < vlen; i ++ ) {
  19907. vert = vertices[ i ];
  19908. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19909. }
  19910. for ( i = 0; i < flen; i ++ ) {
  19911. face = faces[ i ];
  19912. var a = face[ 0 ] + shapesOffset;
  19913. var b = face[ 1 ] + shapesOffset;
  19914. var c = face[ 2 ] + shapesOffset;
  19915. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19916. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19917. }
  19918. };
  19919. // File:src/extras/geometries/LatheGeometry.js
  19920. /**
  19921. * @author astrodud / http://astrodud.isgreat.org/
  19922. * @author zz85 / https://github.com/zz85
  19923. * @author bhouston / http://clara.io
  19924. */
  19925. // points - to create a closed torus, one must use a set of points
  19926. // like so: [ a, b, c, d, a ], see first is the same as last.
  19927. // segments - the number of circumference segments to create
  19928. // phiStart - the starting radian
  19929. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19930. // 2*pi is a closed lathe, less than 2PI is a portion.
  19931. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19932. THREE.Geometry.call( this );
  19933. this.type = 'LatheGeometry';
  19934. this.parameters = {
  19935. points: points,
  19936. segments: segments,
  19937. phiStart: phiStart,
  19938. phiLength: phiLength
  19939. };
  19940. segments = segments || 12;
  19941. phiStart = phiStart || 0;
  19942. phiLength = phiLength || 2 * Math.PI;
  19943. var inversePointLength = 1.0 / ( points.length - 1 );
  19944. var inverseSegments = 1.0 / segments;
  19945. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19946. var phi = phiStart + i * inverseSegments * phiLength;
  19947. var c = Math.cos( phi ),
  19948. s = Math.sin( phi );
  19949. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19950. var pt = points[ j ];
  19951. var vertex = new THREE.Vector3();
  19952. vertex.x = c * pt.x - s * pt.y;
  19953. vertex.y = s * pt.x + c * pt.y;
  19954. vertex.z = pt.z;
  19955. this.vertices.push( vertex );
  19956. }
  19957. }
  19958. var np = points.length;
  19959. for ( var i = 0, il = segments; i < il; i ++ ) {
  19960. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19961. var base = j + np * i;
  19962. var a = base;
  19963. var b = base + np;
  19964. var c = base + 1 + np;
  19965. var d = base + 1;
  19966. var u0 = i * inverseSegments;
  19967. var v0 = j * inversePointLength;
  19968. var u1 = u0 + inverseSegments;
  19969. var v1 = v0 + inversePointLength;
  19970. this.faces.push( new THREE.Face3( a, b, d ) );
  19971. this.faceVertexUvs[ 0 ].push( [
  19972. new THREE.Vector2( u0, v0 ),
  19973. new THREE.Vector2( u1, v0 ),
  19974. new THREE.Vector2( u0, v1 )
  19975. ] );
  19976. this.faces.push( new THREE.Face3( b, c, d ) );
  19977. this.faceVertexUvs[ 0 ].push( [
  19978. new THREE.Vector2( u1, v0 ),
  19979. new THREE.Vector2( u1, v1 ),
  19980. new THREE.Vector2( u0, v1 )
  19981. ] );
  19982. }
  19983. }
  19984. this.mergeVertices();
  19985. this.computeFaceNormals();
  19986. this.computeVertexNormals();
  19987. };
  19988. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19989. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19990. // File:src/extras/geometries/PlaneGeometry.js
  19991. /**
  19992. * @author mrdoob / http://mrdoob.com/
  19993. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19994. */
  19995. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19996. THREE.Geometry.call( this );
  19997. this.type = 'PlaneGeometry';
  19998. this.parameters = {
  19999. width: width,
  20000. height: height,
  20001. widthSegments: widthSegments,
  20002. heightSegments: heightSegments
  20003. };
  20004. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  20005. };
  20006. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20007. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  20008. THREE.PlaneGeometry.prototype.clone = function () {
  20009. var geometry = new THREE.PlaneGeometry(
  20010. this.parameters.width,
  20011. this.parameters.height,
  20012. this.parameters.widthSegments,
  20013. this.parameters.heightSegments
  20014. );
  20015. return geometry;
  20016. };
  20017. // File:src/extras/geometries/PlaneBufferGeometry.js
  20018. /**
  20019. * @author mrdoob / http://mrdoob.com/
  20020. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  20021. */
  20022. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  20023. THREE.BufferGeometry.call( this );
  20024. this.type = 'PlaneBufferGeometry';
  20025. this.parameters = {
  20026. width: width,
  20027. height: height,
  20028. widthSegments: widthSegments,
  20029. heightSegments: heightSegments
  20030. };
  20031. var width_half = width / 2;
  20032. var height_half = height / 2;
  20033. var gridX = Math.floor( widthSegments ) || 1;
  20034. var gridY = Math.floor( heightSegments ) || 1;
  20035. var gridX1 = gridX + 1;
  20036. var gridY1 = gridY + 1;
  20037. var segment_width = width / gridX;
  20038. var segment_height = height / gridY;
  20039. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  20040. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  20041. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  20042. var offset = 0;
  20043. var offset2 = 0;
  20044. for ( var iy = 0; iy < gridY1; iy ++ ) {
  20045. var y = iy * segment_height - height_half;
  20046. for ( var ix = 0; ix < gridX1; ix ++ ) {
  20047. var x = ix * segment_width - width_half;
  20048. vertices[ offset ] = x;
  20049. vertices[ offset + 1 ] = - y;
  20050. normals[ offset + 2 ] = 1;
  20051. uvs[ offset2 ] = ix / gridX;
  20052. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  20053. offset += 3;
  20054. offset2 += 2;
  20055. }
  20056. }
  20057. offset = 0;
  20058. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  20059. for ( var iy = 0; iy < gridY; iy ++ ) {
  20060. for ( var ix = 0; ix < gridX; ix ++ ) {
  20061. var a = ix + gridX1 * iy;
  20062. var b = ix + gridX1 * ( iy + 1 );
  20063. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  20064. var d = ( ix + 1 ) + gridX1 * iy;
  20065. indices[ offset ] = a;
  20066. indices[ offset + 1 ] = b;
  20067. indices[ offset + 2 ] = d;
  20068. indices[ offset + 3 ] = b;
  20069. indices[ offset + 4 ] = c;
  20070. indices[ offset + 5 ] = d;
  20071. offset += 6;
  20072. }
  20073. }
  20074. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  20075. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20076. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  20077. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  20078. };
  20079. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20080. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  20081. THREE.PlaneBufferGeometry.prototype.clone = function () {
  20082. var geometry = new THREE.PlaneBufferGeometry(
  20083. this.parameters.width,
  20084. this.parameters.height,
  20085. this.parameters.widthSegments,
  20086. this.parameters.heightSegments
  20087. );
  20088. geometry.copy( this );
  20089. return geometry;
  20090. };
  20091. // File:src/extras/geometries/RingGeometry.js
  20092. /**
  20093. * @author Kaleb Murphy
  20094. */
  20095. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  20096. THREE.Geometry.call( this );
  20097. this.type = 'RingGeometry';
  20098. this.parameters = {
  20099. innerRadius: innerRadius,
  20100. outerRadius: outerRadius,
  20101. thetaSegments: thetaSegments,
  20102. phiSegments: phiSegments,
  20103. thetaStart: thetaStart,
  20104. thetaLength: thetaLength
  20105. };
  20106. innerRadius = innerRadius || 0;
  20107. outerRadius = outerRadius || 50;
  20108. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20109. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20110. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  20111. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  20112. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  20113. for ( i = 0; i < phiSegments + 1; i ++ ) {
  20114. // concentric circles inside ring
  20115. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  20116. // number of segments per circle
  20117. var vertex = new THREE.Vector3();
  20118. var segment = thetaStart + o / thetaSegments * thetaLength;
  20119. vertex.x = radius * Math.cos( segment );
  20120. vertex.y = radius * Math.sin( segment );
  20121. this.vertices.push( vertex );
  20122. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  20123. }
  20124. radius += radiusStep;
  20125. }
  20126. var n = new THREE.Vector3( 0, 0, 1 );
  20127. for ( i = 0; i < phiSegments; i ++ ) {
  20128. // concentric circles inside ring
  20129. var thetaSegment = i * ( thetaSegments + 1 );
  20130. for ( o = 0; o < thetaSegments ; o ++ ) {
  20131. // number of segments per circle
  20132. var segment = o + thetaSegment;
  20133. var v1 = segment;
  20134. var v2 = segment + thetaSegments + 1;
  20135. var v3 = segment + thetaSegments + 2;
  20136. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20137. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20138. v1 = segment;
  20139. v2 = segment + thetaSegments + 2;
  20140. v3 = segment + 1;
  20141. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20142. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20143. }
  20144. }
  20145. this.computeFaceNormals();
  20146. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20147. };
  20148. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20149. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  20150. THREE.RingGeometry.prototype.clone = function () {
  20151. var geometry = new THREE.RingGeometry(
  20152. this.parameters.innerRadius,
  20153. this.parameters.outerRadius,
  20154. this.parameters.thetaSegments,
  20155. this.parameters.phiSegments,
  20156. this.parameters.thetaStart,
  20157. this.parameters.thetaLength
  20158. );
  20159. return geometry;
  20160. };
  20161. // File:src/extras/geometries/SphereGeometry.js
  20162. /**
  20163. * @author mrdoob / http://mrdoob.com/
  20164. */
  20165. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20166. THREE.Geometry.call( this );
  20167. this.type = 'SphereGeometry';
  20168. this.parameters = {
  20169. radius: radius,
  20170. widthSegments: widthSegments,
  20171. heightSegments: heightSegments,
  20172. phiStart: phiStart,
  20173. phiLength: phiLength,
  20174. thetaStart: thetaStart,
  20175. thetaLength: thetaLength
  20176. };
  20177. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  20178. };
  20179. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20180. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  20181. THREE.SphereGeometry.prototype.clone = function () {
  20182. var geometry = new THREE.SphereGeometry(
  20183. this.parameters.radius,
  20184. this.parameters.widthSegments,
  20185. this.parameters.heightSegments,
  20186. this.parameters.phiStart,
  20187. this.parameters.phiLength,
  20188. this.parameters.thetaStart,
  20189. this.parameters.thetaLength
  20190. );
  20191. return geometry;
  20192. };
  20193. // File:src/extras/geometries/SphereBufferGeometry.js
  20194. /**
  20195. * @author benaadams / https://twitter.com/ben_a_adams
  20196. * based on THREE.SphereGeometry
  20197. */
  20198. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20199. THREE.BufferGeometry.call( this );
  20200. this.type = 'SphereBufferGeometry';
  20201. this.parameters = {
  20202. radius: radius,
  20203. widthSegments: widthSegments,
  20204. heightSegments: heightSegments,
  20205. phiStart: phiStart,
  20206. phiLength: phiLength,
  20207. thetaStart: thetaStart,
  20208. thetaLength: thetaLength
  20209. };
  20210. radius = radius || 50;
  20211. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  20212. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  20213. phiStart = phiStart !== undefined ? phiStart : 0;
  20214. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  20215. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20216. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  20217. var thetaEnd = thetaStart + thetaLength;
  20218. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  20219. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20220. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20221. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  20222. var index = 0, vertices = [], normal = new THREE.Vector3();
  20223. for ( var y = 0; y <= heightSegments; y ++ ) {
  20224. var verticesRow = [];
  20225. var v = y / heightSegments;
  20226. for ( var x = 0; x <= widthSegments; x ++ ) {
  20227. var u = x / widthSegments;
  20228. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20229. var py = radius * Math.cos( thetaStart + v * thetaLength );
  20230. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20231. normal.set( px, py, pz ).normalize();
  20232. positions.setXYZ( index, px, py, pz );
  20233. normals.setXYZ( index, normal.x, normal.y, normal.z );
  20234. uvs.setXY( index, u, 1 - v );
  20235. verticesRow.push( index );
  20236. index ++;
  20237. }
  20238. vertices.push( verticesRow );
  20239. }
  20240. var indices = [];
  20241. for ( var y = 0; y < heightSegments; y ++ ) {
  20242. for ( var x = 0; x < widthSegments; x ++ ) {
  20243. var v1 = vertices[ y ][ x + 1 ];
  20244. var v2 = vertices[ y ][ x ];
  20245. var v3 = vertices[ y + 1 ][ x ];
  20246. var v4 = vertices[ y + 1 ][ x + 1 ];
  20247. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  20248. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  20249. }
  20250. }
  20251. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  20252. this.addAttribute( 'position', positions );
  20253. this.addAttribute( 'normal', normals );
  20254. this.addAttribute( 'uv', uvs );
  20255. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20256. };
  20257. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20258. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  20259. THREE.SphereBufferGeometry.prototype.clone = function () {
  20260. var geometry = new THREE.SphereBufferGeometry(
  20261. this.parameters.radius,
  20262. this.parameters.widthSegments,
  20263. this.parameters.heightSegments,
  20264. this.parameters.phiStart,
  20265. this.parameters.phiLength,
  20266. this.parameters.thetaStart,
  20267. this.parameters.thetaLength
  20268. );
  20269. geometry.copy( this );
  20270. return geometry;
  20271. };
  20272. // File:src/extras/geometries/TextGeometry.js
  20273. /**
  20274. * @author zz85 / http://www.lab4games.net/zz85/blog
  20275. * @author alteredq / http://alteredqualia.com/
  20276. *
  20277. * For creating 3D text geometry in three.js
  20278. *
  20279. * Text = 3D Text
  20280. *
  20281. * parameters = {
  20282. * size: <float>, // size of the text
  20283. * height: <float>, // thickness to extrude text
  20284. * curveSegments: <int>, // number of points on the curves
  20285. *
  20286. * font: <string>, // font name
  20287. * weight: <string>, // font weight (normal, bold)
  20288. * style: <string>, // font style (normal, italics)
  20289. *
  20290. * bevelEnabled: <bool>, // turn on bevel
  20291. * bevelThickness: <float>, // how deep into text bevel goes
  20292. * bevelSize: <float>, // how far from text outline is bevel
  20293. * }
  20294. *
  20295. */
  20296. /* Usage Examples
  20297. // TextGeometry wrapper
  20298. var text3d = new TextGeometry( text, options );
  20299. // Complete manner
  20300. var textShapes = THREE.FontUtils.generateShapes( text, options );
  20301. var text3d = new ExtrudeGeometry( textShapes, options );
  20302. */
  20303. THREE.TextGeometry = function ( text, parameters ) {
  20304. parameters = parameters || {};
  20305. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  20306. // translate parameters to ExtrudeGeometry API
  20307. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  20308. // defaults
  20309. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  20310. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  20311. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  20312. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  20313. this.type = 'TextGeometry';
  20314. };
  20315. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  20316. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  20317. // File:src/extras/geometries/TorusGeometry.js
  20318. /**
  20319. * @author oosmoxiecode
  20320. * @author mrdoob / http://mrdoob.com/
  20321. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  20322. */
  20323. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  20324. THREE.Geometry.call( this );
  20325. this.type = 'TorusGeometry';
  20326. this.parameters = {
  20327. radius: radius,
  20328. tube: tube,
  20329. radialSegments: radialSegments,
  20330. tubularSegments: tubularSegments,
  20331. arc: arc
  20332. };
  20333. radius = radius || 100;
  20334. tube = tube || 40;
  20335. radialSegments = radialSegments || 8;
  20336. tubularSegments = tubularSegments || 6;
  20337. arc = arc || Math.PI * 2;
  20338. var center = new THREE.Vector3(), uvs = [], normals = [];
  20339. for ( var j = 0; j <= radialSegments; j ++ ) {
  20340. for ( var i = 0; i <= tubularSegments; i ++ ) {
  20341. var u = i / tubularSegments * arc;
  20342. var v = j / radialSegments * Math.PI * 2;
  20343. center.x = radius * Math.cos( u );
  20344. center.y = radius * Math.sin( u );
  20345. var vertex = new THREE.Vector3();
  20346. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  20347. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  20348. vertex.z = tube * Math.sin( v );
  20349. this.vertices.push( vertex );
  20350. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  20351. normals.push( vertex.clone().sub( center ).normalize() );
  20352. }
  20353. }
  20354. for ( var j = 1; j <= radialSegments; j ++ ) {
  20355. for ( var i = 1; i <= tubularSegments; i ++ ) {
  20356. var a = ( tubularSegments + 1 ) * j + i - 1;
  20357. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  20358. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  20359. var d = ( tubularSegments + 1 ) * j + i;
  20360. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  20361. this.faces.push( face );
  20362. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  20363. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  20364. this.faces.push( face );
  20365. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  20366. }
  20367. }
  20368. this.computeFaceNormals();
  20369. };
  20370. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20371. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  20372. THREE.TorusGeometry.prototype.clone = function () {
  20373. var geometry = new THREE.TorusGeometry(
  20374. this.parameters.radius,
  20375. this.parameters.tube,
  20376. this.parameters.radialSegments,
  20377. this.parameters.tubularSegments,
  20378. this.parameters.arc
  20379. );
  20380. return geometry;
  20381. };
  20382. // File:src/extras/geometries/TorusKnotGeometry.js
  20383. /**
  20384. * @author oosmoxiecode
  20385. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  20386. */
  20387. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  20388. THREE.Geometry.call( this );
  20389. this.type = 'TorusKnotGeometry';
  20390. this.parameters = {
  20391. radius: radius,
  20392. tube: tube,
  20393. radialSegments: radialSegments,
  20394. tubularSegments: tubularSegments,
  20395. p: p,
  20396. q: q,
  20397. heightScale: heightScale
  20398. };
  20399. radius = radius || 100;
  20400. tube = tube || 40;
  20401. radialSegments = radialSegments || 64;
  20402. tubularSegments = tubularSegments || 8;
  20403. p = p || 2;
  20404. q = q || 3;
  20405. heightScale = heightScale || 1;
  20406. var grid = new Array( radialSegments );
  20407. var tang = new THREE.Vector3();
  20408. var n = new THREE.Vector3();
  20409. var bitan = new THREE.Vector3();
  20410. for ( var i = 0; i < radialSegments; ++ i ) {
  20411. grid[ i ] = new Array( tubularSegments );
  20412. var u = i / radialSegments * 2 * p * Math.PI;
  20413. var p1 = getPos( u, q, p, radius, heightScale );
  20414. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  20415. tang.subVectors( p2, p1 );
  20416. n.addVectors( p2, p1 );
  20417. bitan.crossVectors( tang, n );
  20418. n.crossVectors( bitan, tang );
  20419. bitan.normalize();
  20420. n.normalize();
  20421. for ( var j = 0; j < tubularSegments; ++ j ) {
  20422. var v = j / tubularSegments * 2 * Math.PI;
  20423. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20424. var cy = tube * Math.sin( v );
  20425. var pos = new THREE.Vector3();
  20426. pos.x = p1.x + cx * n.x + cy * bitan.x;
  20427. pos.y = p1.y + cx * n.y + cy * bitan.y;
  20428. pos.z = p1.z + cx * n.z + cy * bitan.z;
  20429. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  20430. }
  20431. }
  20432. for ( var i = 0; i < radialSegments; ++ i ) {
  20433. for ( var j = 0; j < tubularSegments; ++ j ) {
  20434. var ip = ( i + 1 ) % radialSegments;
  20435. var jp = ( j + 1 ) % tubularSegments;
  20436. var a = grid[ i ][ j ];
  20437. var b = grid[ ip ][ j ];
  20438. var c = grid[ ip ][ jp ];
  20439. var d = grid[ i ][ jp ];
  20440. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  20441. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  20442. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  20443. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  20444. this.faces.push( new THREE.Face3( a, b, d ) );
  20445. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20446. this.faces.push( new THREE.Face3( b, c, d ) );
  20447. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20448. }
  20449. }
  20450. this.computeFaceNormals();
  20451. this.computeVertexNormals();
  20452. function getPos( u, in_q, in_p, radius, heightScale ) {
  20453. var cu = Math.cos( u );
  20454. var su = Math.sin( u );
  20455. var quOverP = in_q / in_p * u;
  20456. var cs = Math.cos( quOverP );
  20457. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  20458. var ty = radius * ( 2 + cs ) * su * 0.5;
  20459. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  20460. return new THREE.Vector3( tx, ty, tz );
  20461. }
  20462. };
  20463. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20464. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  20465. THREE.TorusKnotGeometry.prototype.clone = function () {
  20466. var geometry = new THREE.TorusKnotGeometry(
  20467. this.parameters.radius,
  20468. this.parameters.tube,
  20469. this.parameters.radialSegments,
  20470. this.parameters.tubularSegments,
  20471. this.parameters.p,
  20472. this.parameters.q,
  20473. this.parameters.heightScale
  20474. );
  20475. return geometry;
  20476. };
  20477. // File:src/extras/geometries/TubeGeometry.js
  20478. /**
  20479. * @author WestLangley / https://github.com/WestLangley
  20480. * @author zz85 / https://github.com/zz85
  20481. * @author miningold / https://github.com/miningold
  20482. * @author jonobr1 / https://github.com/jonobr1
  20483. *
  20484. * Modified from the TorusKnotGeometry by @oosmoxiecode
  20485. *
  20486. * Creates a tube which extrudes along a 3d spline
  20487. *
  20488. * Uses parallel transport frames as described in
  20489. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20490. */
  20491. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  20492. THREE.Geometry.call( this );
  20493. this.type = 'TubeGeometry';
  20494. this.parameters = {
  20495. path: path,
  20496. segments: segments,
  20497. radius: radius,
  20498. radialSegments: radialSegments,
  20499. closed: closed
  20500. };
  20501. segments = segments || 64;
  20502. radius = radius || 1;
  20503. radialSegments = radialSegments || 8;
  20504. closed = closed || false;
  20505. taper = taper || THREE.TubeGeometry.NoTaper;
  20506. var grid = [];
  20507. var scope = this,
  20508. tangent,
  20509. normal,
  20510. binormal,
  20511. numpoints = segments + 1,
  20512. u, v, r,
  20513. cx, cy,
  20514. pos, pos2 = new THREE.Vector3(),
  20515. i, j,
  20516. ip, jp,
  20517. a, b, c, d,
  20518. uva, uvb, uvc, uvd;
  20519. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  20520. tangents = frames.tangents,
  20521. normals = frames.normals,
  20522. binormals = frames.binormals;
  20523. // proxy internals
  20524. this.tangents = tangents;
  20525. this.normals = normals;
  20526. this.binormals = binormals;
  20527. function vert( x, y, z ) {
  20528. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  20529. }
  20530. // construct the grid
  20531. for ( i = 0; i < numpoints; i ++ ) {
  20532. grid[ i ] = [];
  20533. u = i / ( numpoints - 1 );
  20534. pos = path.getPointAt( u );
  20535. tangent = tangents[ i ];
  20536. normal = normals[ i ];
  20537. binormal = binormals[ i ];
  20538. r = radius * taper( u );
  20539. for ( j = 0; j < radialSegments; j ++ ) {
  20540. v = j / radialSegments * 2 * Math.PI;
  20541. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20542. cy = r * Math.sin( v );
  20543. pos2.copy( pos );
  20544. pos2.x += cx * normal.x + cy * binormal.x;
  20545. pos2.y += cx * normal.y + cy * binormal.y;
  20546. pos2.z += cx * normal.z + cy * binormal.z;
  20547. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  20548. }
  20549. }
  20550. // construct the mesh
  20551. for ( i = 0; i < segments; i ++ ) {
  20552. for ( j = 0; j < radialSegments; j ++ ) {
  20553. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  20554. jp = ( j + 1 ) % radialSegments;
  20555. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  20556. b = grid[ ip ][ j ];
  20557. c = grid[ ip ][ jp ];
  20558. d = grid[ i ][ jp ];
  20559. uva = new THREE.Vector2( i / segments, j / radialSegments );
  20560. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  20561. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  20562. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  20563. this.faces.push( new THREE.Face3( a, b, d ) );
  20564. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20565. this.faces.push( new THREE.Face3( b, c, d ) );
  20566. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20567. }
  20568. }
  20569. this.computeFaceNormals();
  20570. this.computeVertexNormals();
  20571. };
  20572. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20573. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  20574. THREE.TubeGeometry.NoTaper = function ( u ) {
  20575. return 1;
  20576. };
  20577. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  20578. return Math.sin( Math.PI * u );
  20579. };
  20580. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  20581. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  20582. var normal = new THREE.Vector3(),
  20583. tangents = [],
  20584. normals = [],
  20585. binormals = [],
  20586. vec = new THREE.Vector3(),
  20587. mat = new THREE.Matrix4(),
  20588. numpoints = segments + 1,
  20589. theta,
  20590. epsilon = 0.0001,
  20591. smallest,
  20592. tx, ty, tz,
  20593. i, u;
  20594. // expose internals
  20595. this.tangents = tangents;
  20596. this.normals = normals;
  20597. this.binormals = binormals;
  20598. // compute the tangent vectors for each segment on the path
  20599. for ( i = 0; i < numpoints; i ++ ) {
  20600. u = i / ( numpoints - 1 );
  20601. tangents[ i ] = path.getTangentAt( u );
  20602. tangents[ i ].normalize();
  20603. }
  20604. initialNormal3();
  20605. /*
  20606. function initialNormal1(lastBinormal) {
  20607. // fixed start binormal. Has dangers of 0 vectors
  20608. normals[ 0 ] = new THREE.Vector3();
  20609. binormals[ 0 ] = new THREE.Vector3();
  20610. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20611. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20612. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20613. }
  20614. function initialNormal2() {
  20615. // This uses the Frenet-Serret formula for deriving binormal
  20616. var t2 = path.getTangentAt( epsilon );
  20617. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20618. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20619. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20620. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20621. }
  20622. */
  20623. function initialNormal3() {
  20624. // select an initial normal vector perpendicular to the first tangent vector,
  20625. // and in the direction of the smallest tangent xyz component
  20626. normals[ 0 ] = new THREE.Vector3();
  20627. binormals[ 0 ] = new THREE.Vector3();
  20628. smallest = Number.MAX_VALUE;
  20629. tx = Math.abs( tangents[ 0 ].x );
  20630. ty = Math.abs( tangents[ 0 ].y );
  20631. tz = Math.abs( tangents[ 0 ].z );
  20632. if ( tx <= smallest ) {
  20633. smallest = tx;
  20634. normal.set( 1, 0, 0 );
  20635. }
  20636. if ( ty <= smallest ) {
  20637. smallest = ty;
  20638. normal.set( 0, 1, 0 );
  20639. }
  20640. if ( tz <= smallest ) {
  20641. normal.set( 0, 0, 1 );
  20642. }
  20643. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20644. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20645. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20646. }
  20647. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20648. for ( i = 1; i < numpoints; i ++ ) {
  20649. normals[ i ] = normals[ i - 1 ].clone();
  20650. binormals[ i ] = binormals[ i - 1 ].clone();
  20651. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20652. if ( vec.length() > epsilon ) {
  20653. vec.normalize();
  20654. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20655. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20656. }
  20657. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20658. }
  20659. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20660. if ( closed ) {
  20661. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20662. theta /= ( numpoints - 1 );
  20663. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20664. theta = - theta;
  20665. }
  20666. for ( i = 1; i < numpoints; i ++ ) {
  20667. // twist a little...
  20668. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20669. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20670. }
  20671. }
  20672. };
  20673. // File:src/extras/geometries/PolyhedronGeometry.js
  20674. /**
  20675. * @author clockworkgeek / https://github.com/clockworkgeek
  20676. * @author timothypratley / https://github.com/timothypratley
  20677. * @author WestLangley / http://github.com/WestLangley
  20678. */
  20679. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20680. THREE.Geometry.call( this );
  20681. this.type = 'PolyhedronGeometry';
  20682. this.parameters = {
  20683. vertices: vertices,
  20684. indices: indices,
  20685. radius: radius,
  20686. detail: detail
  20687. };
  20688. radius = radius || 1;
  20689. detail = detail || 0;
  20690. var that = this;
  20691. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20692. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20693. }
  20694. var p = this.vertices;
  20695. var faces = [];
  20696. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20697. var v1 = p[ indices[ i ] ];
  20698. var v2 = p[ indices[ i + 1 ] ];
  20699. var v3 = p[ indices[ i + 2 ] ];
  20700. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  20701. }
  20702. var centroid = new THREE.Vector3();
  20703. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20704. subdivide( faces[ i ], detail );
  20705. }
  20706. // Handle case when face straddles the seam
  20707. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20708. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20709. var x0 = uvs[ 0 ].x;
  20710. var x1 = uvs[ 1 ].x;
  20711. var x2 = uvs[ 2 ].x;
  20712. var max = Math.max( x0, Math.max( x1, x2 ) );
  20713. var min = Math.min( x0, Math.min( x1, x2 ) );
  20714. if ( max > 0.9 && min < 0.1 ) {
  20715. // 0.9 is somewhat arbitrary
  20716. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20717. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20718. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20719. }
  20720. }
  20721. // Apply radius
  20722. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20723. this.vertices[ i ].multiplyScalar( radius );
  20724. }
  20725. // Merge vertices
  20726. this.mergeVertices();
  20727. this.computeFaceNormals();
  20728. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20729. // Project vector onto sphere's surface
  20730. function prepare( vector ) {
  20731. var vertex = vector.normalize().clone();
  20732. vertex.index = that.vertices.push( vertex ) - 1;
  20733. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20734. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20735. var v = inclination( vector ) / Math.PI + 0.5;
  20736. vertex.uv = new THREE.Vector2( u, 1 - v );
  20737. return vertex;
  20738. }
  20739. // Approximate a curved face with recursively sub-divided triangles.
  20740. function make( v1, v2, v3, materialIndex ) {
  20741. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  20742. that.faces.push( face );
  20743. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20744. var azi = azimuth( centroid );
  20745. that.faceVertexUvs[ 0 ].push( [
  20746. correctUV( v1.uv, v1, azi ),
  20747. correctUV( v2.uv, v2, azi ),
  20748. correctUV( v3.uv, v3, azi )
  20749. ] );
  20750. }
  20751. // Analytically subdivide a face to the required detail level.
  20752. function subdivide( face, detail ) {
  20753. var cols = Math.pow( 2, detail );
  20754. var a = prepare( that.vertices[ face.a ] );
  20755. var b = prepare( that.vertices[ face.b ] );
  20756. var c = prepare( that.vertices[ face.c ] );
  20757. var v = [];
  20758. var materialIndex = face.materialIndex;
  20759. // Construct all of the vertices for this subdivision.
  20760. for ( var i = 0 ; i <= cols; i ++ ) {
  20761. v[ i ] = [];
  20762. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20763. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20764. var rows = cols - i;
  20765. for ( var j = 0; j <= rows; j ++ ) {
  20766. if ( j === 0 && i === cols ) {
  20767. v[ i ][ j ] = aj;
  20768. } else {
  20769. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20770. }
  20771. }
  20772. }
  20773. // Construct all of the faces.
  20774. for ( var i = 0; i < cols ; i ++ ) {
  20775. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20776. var k = Math.floor( j / 2 );
  20777. if ( j % 2 === 0 ) {
  20778. make(
  20779. v[ i ][ k + 1 ],
  20780. v[ i + 1 ][ k ],
  20781. v[ i ][ k ],
  20782. materialIndex
  20783. );
  20784. } else {
  20785. make(
  20786. v[ i ][ k + 1 ],
  20787. v[ i + 1 ][ k + 1 ],
  20788. v[ i + 1 ][ k ],
  20789. materialIndex
  20790. );
  20791. }
  20792. }
  20793. }
  20794. }
  20795. // Angle around the Y axis, counter-clockwise when looking from above.
  20796. function azimuth( vector ) {
  20797. return Math.atan2( vector.z, - vector.x );
  20798. }
  20799. // Angle above the XZ plane.
  20800. function inclination( vector ) {
  20801. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20802. }
  20803. // Texture fixing helper. Spheres have some odd behaviours.
  20804. function correctUV( uv, vector, azimuth ) {
  20805. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20806. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20807. return uv.clone();
  20808. }
  20809. };
  20810. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20811. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20812. THREE.PolyhedronGeometry.prototype.clone = function () {
  20813. var geometry = new THREE.PolyhedronGeometry(
  20814. this.parameters.vertices,
  20815. this.parameters.indices,
  20816. this.parameters.radius,
  20817. this.parameters.detail
  20818. );
  20819. return geometry.copy( this );
  20820. };
  20821. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20822. THREE.Geometry.prototype.copy.call( this, source );
  20823. return this;
  20824. };
  20825. // File:src/extras/geometries/DodecahedronGeometry.js
  20826. /**
  20827. * @author Abe Pazos / https://hamoid.com
  20828. */
  20829. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20830. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20831. var r = 1 / t;
  20832. var vertices = [
  20833. // (±1, ±1, ±1)
  20834. - 1, - 1, - 1, - 1, - 1, 1,
  20835. - 1, 1, - 1, - 1, 1, 1,
  20836. 1, - 1, - 1, 1, - 1, 1,
  20837. 1, 1, - 1, 1, 1, 1,
  20838. // (0, ±1/φ, ±φ)
  20839. 0, - r, - t, 0, - r, t,
  20840. 0, r, - t, 0, r, t,
  20841. // (±1/φ, ±φ, 0)
  20842. - r, - t, 0, - r, t, 0,
  20843. r, - t, 0, r, t, 0,
  20844. // (±φ, 0, ±1/φ)
  20845. - t, 0, - r, t, 0, - r,
  20846. - t, 0, r, t, 0, r
  20847. ];
  20848. var indices = [
  20849. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20850. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20851. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20852. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20853. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20854. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20855. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20856. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20857. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20858. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20859. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20860. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20861. ];
  20862. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20863. this.type = 'DodecahedronGeometry';
  20864. this.parameters = {
  20865. radius: radius,
  20866. detail: detail
  20867. };
  20868. };
  20869. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20870. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20871. THREE.DodecahedronGeometry.prototype.clone = function () {
  20872. var geometry = new THREE.DodecahedronGeometry(
  20873. this.parameters.radius,
  20874. this.parameters.detail
  20875. );
  20876. geometry.copy( this );
  20877. return geometry;
  20878. };
  20879. // File:src/extras/geometries/IcosahedronGeometry.js
  20880. /**
  20881. * @author timothypratley / https://github.com/timothypratley
  20882. */
  20883. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20884. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20885. var vertices = [
  20886. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20887. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20888. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20889. ];
  20890. var indices = [
  20891. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20892. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20893. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20894. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20895. ];
  20896. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20897. this.type = 'IcosahedronGeometry';
  20898. this.parameters = {
  20899. radius: radius,
  20900. detail: detail
  20901. };
  20902. };
  20903. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20904. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20905. THREE.IcosahedronGeometry.prototype.clone = function () {
  20906. var geometry = new THREE.IcosahedronGeometry(
  20907. this.parameters.radius,
  20908. this.parameters.detail
  20909. );
  20910. geometry.copy( this );
  20911. return geometry;
  20912. };
  20913. // File:src/extras/geometries/OctahedronGeometry.js
  20914. /**
  20915. * @author timothypratley / https://github.com/timothypratley
  20916. */
  20917. THREE.OctahedronGeometry = function ( radius, detail ) {
  20918. var vertices = [
  20919. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20920. ];
  20921. var indices = [
  20922. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20923. ];
  20924. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20925. this.type = 'OctahedronGeometry';
  20926. this.parameters = {
  20927. radius: radius,
  20928. detail: detail
  20929. };
  20930. };
  20931. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20932. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20933. THREE.OctahedronGeometry.prototype.clone = function () {
  20934. var geometry = new THREE.OctahedronGeometry(
  20935. this.parameters.radius,
  20936. this.parameters.detail
  20937. );
  20938. geometry.copy( this );
  20939. return geometry;
  20940. };
  20941. // File:src/extras/geometries/TetrahedronGeometry.js
  20942. /**
  20943. * @author timothypratley / https://github.com/timothypratley
  20944. */
  20945. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20946. var vertices = [
  20947. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20948. ];
  20949. var indices = [
  20950. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20951. ];
  20952. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20953. this.type = 'TetrahedronGeometry';
  20954. this.parameters = {
  20955. radius: radius,
  20956. detail: detail
  20957. };
  20958. };
  20959. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20960. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20961. THREE.TetrahedronGeometry.prototype.clone = function () {
  20962. var geometry = new THREE.TetrahedronGeometry(
  20963. this.parameters.radius,
  20964. this.parameters.detail
  20965. );
  20966. geometry.copy( this );
  20967. return geometry;
  20968. };
  20969. // File:src/extras/geometries/ParametricGeometry.js
  20970. /**
  20971. * @author zz85 / https://github.com/zz85
  20972. * Parametric Surfaces Geometry
  20973. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20974. *
  20975. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20976. *
  20977. */
  20978. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20979. THREE.Geometry.call( this );
  20980. this.type = 'ParametricGeometry';
  20981. this.parameters = {
  20982. func: func,
  20983. slices: slices,
  20984. stacks: stacks
  20985. };
  20986. var verts = this.vertices;
  20987. var faces = this.faces;
  20988. var uvs = this.faceVertexUvs[ 0 ];
  20989. var i, j, p;
  20990. var u, v;
  20991. var sliceCount = slices + 1;
  20992. for ( i = 0; i <= stacks; i ++ ) {
  20993. v = i / stacks;
  20994. for ( j = 0; j <= slices; j ++ ) {
  20995. u = j / slices;
  20996. p = func( u, v );
  20997. verts.push( p );
  20998. }
  20999. }
  21000. var a, b, c, d;
  21001. var uva, uvb, uvc, uvd;
  21002. for ( i = 0; i < stacks; i ++ ) {
  21003. for ( j = 0; j < slices; j ++ ) {
  21004. a = i * sliceCount + j;
  21005. b = i * sliceCount + j + 1;
  21006. c = ( i + 1 ) * sliceCount + j + 1;
  21007. d = ( i + 1 ) * sliceCount + j;
  21008. uva = new THREE.Vector2( j / slices, i / stacks );
  21009. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  21010. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  21011. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  21012. faces.push( new THREE.Face3( a, b, d ) );
  21013. uvs.push( [ uva, uvb, uvd ] );
  21014. faces.push( new THREE.Face3( b, c, d ) );
  21015. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  21016. }
  21017. }
  21018. // console.log(this);
  21019. // magic bullet
  21020. // var diff = this.mergeVertices();
  21021. // console.log('removed ', diff, ' vertices by merging');
  21022. this.computeFaceNormals();
  21023. this.computeVertexNormals();
  21024. };
  21025. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21026. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  21027. // File:src/extras/geometries/WireframeGeometry.js
  21028. /**
  21029. * @author mrdoob / http://mrdoob.com/
  21030. */
  21031. THREE.WireframeGeometry = function ( geometry ) {
  21032. THREE.BufferGeometry.call( this );
  21033. var edge = [ 0, 0 ], hash = {};
  21034. var sortFunction = function ( a, b ) {
  21035. return a - b;
  21036. };
  21037. var keys = [ 'a', 'b', 'c' ];
  21038. if ( geometry instanceof THREE.Geometry ) {
  21039. var vertices = geometry.vertices;
  21040. var faces = geometry.faces;
  21041. var numEdges = 0;
  21042. // allocate maximal size
  21043. var edges = new Uint32Array( 6 * faces.length );
  21044. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21045. var face = faces[ i ];
  21046. for ( var j = 0; j < 3; j ++ ) {
  21047. edge[ 0 ] = face[ keys[ j ] ];
  21048. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21049. edge.sort( sortFunction );
  21050. var key = edge.toString();
  21051. if ( hash[ key ] === undefined ) {
  21052. edges[ 2 * numEdges ] = edge[ 0 ];
  21053. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21054. hash[ key ] = true;
  21055. numEdges ++;
  21056. }
  21057. }
  21058. }
  21059. var coords = new Float32Array( numEdges * 2 * 3 );
  21060. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21061. for ( var j = 0; j < 2; j ++ ) {
  21062. var vertex = vertices[ edges [ 2 * i + j ] ];
  21063. var index = 6 * i + 3 * j;
  21064. coords[ index + 0 ] = vertex.x;
  21065. coords[ index + 1 ] = vertex.y;
  21066. coords[ index + 2 ] = vertex.z;
  21067. }
  21068. }
  21069. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21070. } else if ( geometry instanceof THREE.BufferGeometry ) {
  21071. if ( geometry.index !== null ) {
  21072. // Indexed BufferGeometry
  21073. var indices = geometry.index.array;
  21074. var vertices = geometry.attributes.position;
  21075. var drawcalls = geometry.drawcalls;
  21076. var numEdges = 0;
  21077. if ( drawcalls.length === 0 ) {
  21078. geometry.addGroup( 0, indices.length );
  21079. }
  21080. // allocate maximal size
  21081. var edges = new Uint32Array( 2 * indices.length );
  21082. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  21083. var drawcall = drawcalls[ o ];
  21084. var start = drawcall.start;
  21085. var count = drawcall.count;
  21086. for ( var i = start, il = start + count; i < il; i += 3 ) {
  21087. for ( var j = 0; j < 3; j ++ ) {
  21088. edge[ 0 ] = indices[ i + j ];
  21089. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  21090. edge.sort( sortFunction );
  21091. var key = edge.toString();
  21092. if ( hash[ key ] === undefined ) {
  21093. edges[ 2 * numEdges ] = edge[ 0 ];
  21094. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21095. hash[ key ] = true;
  21096. numEdges ++;
  21097. }
  21098. }
  21099. }
  21100. }
  21101. var coords = new Float32Array( numEdges * 2 * 3 );
  21102. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21103. for ( var j = 0; j < 2; j ++ ) {
  21104. var index = 6 * i + 3 * j;
  21105. var index2 = edges[ 2 * i + j ];
  21106. coords[ index + 0 ] = vertices.getX( index2 );
  21107. coords[ index + 1 ] = vertices.getY( index2 );
  21108. coords[ index + 2 ] = vertices.getZ( index2 );
  21109. }
  21110. }
  21111. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21112. } else {
  21113. // non-indexed BufferGeometry
  21114. var vertices = geometry.attributes.position.array;
  21115. var numEdges = vertices.length / 3;
  21116. var numTris = numEdges / 3;
  21117. var coords = new Float32Array( numEdges * 2 * 3 );
  21118. for ( var i = 0, l = numTris; i < l; i ++ ) {
  21119. for ( var j = 0; j < 3; j ++ ) {
  21120. var index = 18 * i + 6 * j;
  21121. var index1 = 9 * i + 3 * j;
  21122. coords[ index + 0 ] = vertices[ index1 ];
  21123. coords[ index + 1 ] = vertices[ index1 + 1 ];
  21124. coords[ index + 2 ] = vertices[ index1 + 2 ];
  21125. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  21126. coords[ index + 3 ] = vertices[ index2 ];
  21127. coords[ index + 4 ] = vertices[ index2 + 1 ];
  21128. coords[ index + 5 ] = vertices[ index2 + 2 ];
  21129. }
  21130. }
  21131. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21132. }
  21133. }
  21134. };
  21135. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21136. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  21137. // File:src/extras/helpers/AxisHelper.js
  21138. /**
  21139. * @author sroucheray / http://sroucheray.org/
  21140. * @author mrdoob / http://mrdoob.com/
  21141. */
  21142. THREE.AxisHelper = function ( size ) {
  21143. size = size || 1;
  21144. var vertices = new Float32Array( [
  21145. 0, 0, 0, size, 0, 0,
  21146. 0, 0, 0, 0, size, 0,
  21147. 0, 0, 0, 0, 0, size
  21148. ] );
  21149. var colors = new Float32Array( [
  21150. 1, 0, 0, 1, 0.6, 0,
  21151. 0, 1, 0, 0.6, 1, 0,
  21152. 0, 0, 1, 0, 0.6, 1
  21153. ] );
  21154. var geometry = new THREE.BufferGeometry();
  21155. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21156. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  21157. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21158. THREE.LineSegments.call( this, geometry, material );
  21159. };
  21160. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21161. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  21162. // File:src/extras/helpers/ArrowHelper.js
  21163. /**
  21164. * @author WestLangley / http://github.com/WestLangley
  21165. * @author zz85 / http://github.com/zz85
  21166. * @author bhouston / http://clara.io
  21167. *
  21168. * Creates an arrow for visualizing directions
  21169. *
  21170. * Parameters:
  21171. * dir - Vector3
  21172. * origin - Vector3
  21173. * length - Number
  21174. * color - color in hex value
  21175. * headLength - Number
  21176. * headWidth - Number
  21177. */
  21178. THREE.ArrowHelper = ( function () {
  21179. var lineGeometry = new THREE.Geometry();
  21180. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  21181. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21182. coneGeometry.translate( 0, - 0.5, 0 );
  21183. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  21184. // dir is assumed to be normalized
  21185. THREE.Object3D.call( this );
  21186. if ( color === undefined ) color = 0xffff00;
  21187. if ( length === undefined ) length = 1;
  21188. if ( headLength === undefined ) headLength = 0.2 * length;
  21189. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21190. this.position.copy( origin );
  21191. if ( headLength < length ) {
  21192. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  21193. this.line.matrixAutoUpdate = false;
  21194. this.add( this.line );
  21195. }
  21196. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  21197. this.cone.matrixAutoUpdate = false;
  21198. this.add( this.cone );
  21199. this.setDirection( dir );
  21200. this.setLength( length, headLength, headWidth );
  21201. }
  21202. }() );
  21203. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  21204. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  21205. THREE.ArrowHelper.prototype.setDirection = ( function () {
  21206. var axis = new THREE.Vector3();
  21207. var radians;
  21208. return function setDirection( dir ) {
  21209. // dir is assumed to be normalized
  21210. if ( dir.y > 0.99999 ) {
  21211. this.quaternion.set( 0, 0, 0, 1 );
  21212. } else if ( dir.y < - 0.99999 ) {
  21213. this.quaternion.set( 1, 0, 0, 0 );
  21214. } else {
  21215. axis.set( dir.z, 0, - dir.x ).normalize();
  21216. radians = Math.acos( dir.y );
  21217. this.quaternion.setFromAxisAngle( axis, radians );
  21218. }
  21219. };
  21220. }() );
  21221. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  21222. if ( headLength === undefined ) headLength = 0.2 * length;
  21223. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21224. if ( headLength < length ){
  21225. this.line.scale.set( 1, length - headLength, 1 );
  21226. this.line.updateMatrix();
  21227. }
  21228. this.cone.scale.set( headWidth, headLength, headWidth );
  21229. this.cone.position.y = length;
  21230. this.cone.updateMatrix();
  21231. };
  21232. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  21233. if ( this.line !== undefined ) this.line.material.color.set( color );
  21234. this.cone.material.color.set( color );
  21235. };
  21236. // File:src/extras/helpers/BoxHelper.js
  21237. /**
  21238. * @author mrdoob / http://mrdoob.com/
  21239. */
  21240. THREE.BoxHelper = function ( object ) {
  21241. 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 ] );
  21242. var positions = new Float32Array( 8 * 3 );
  21243. var geometry = new THREE.BufferGeometry();
  21244. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21245. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21246. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  21247. if ( object !== undefined ) {
  21248. this.update( object );
  21249. }
  21250. };
  21251. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21252. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  21253. THREE.BoxHelper.prototype.update = ( function () {
  21254. var box = new THREE.Box3();
  21255. return function ( object ) {
  21256. box.setFromObject( object );
  21257. if ( box.empty() ) return;
  21258. var min = box.min;
  21259. var max = box.max;
  21260. /*
  21261. 5____4
  21262. 1/___0/|
  21263. | 6__|_7
  21264. 2/___3/
  21265. 0: max.x, max.y, max.z
  21266. 1: min.x, max.y, max.z
  21267. 2: min.x, min.y, max.z
  21268. 3: max.x, min.y, max.z
  21269. 4: max.x, max.y, min.z
  21270. 5: min.x, max.y, min.z
  21271. 6: min.x, min.y, min.z
  21272. 7: max.x, min.y, min.z
  21273. */
  21274. var position = this.geometry.attributes.position;
  21275. var array = position.array;
  21276. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21277. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21278. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21279. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21280. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21281. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21282. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21283. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21284. position.needsUpdate = true;
  21285. this.geometry.computeBoundingSphere();
  21286. }
  21287. } )();
  21288. // File:src/extras/helpers/BoundingBoxHelper.js
  21289. /**
  21290. * @author WestLangley / http://github.com/WestLangley
  21291. */
  21292. // a helper to show the world-axis-aligned bounding box for an object
  21293. THREE.BoundingBoxHelper = function ( object, hex ) {
  21294. var color = ( hex !== undefined ) ? hex : 0x888888;
  21295. this.object = object;
  21296. this.box = new THREE.Box3();
  21297. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  21298. };
  21299. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  21300. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  21301. THREE.BoundingBoxHelper.prototype.update = function () {
  21302. this.box.setFromObject( this.object );
  21303. this.box.size( this.scale );
  21304. this.box.center( this.position );
  21305. };
  21306. // File:src/extras/helpers/CameraHelper.js
  21307. /**
  21308. * @author alteredq / http://alteredqualia.com/
  21309. *
  21310. * - shows frustum, line of sight and up of the camera
  21311. * - suitable for fast updates
  21312. * - based on frustum visualization in lightgl.js shadowmap example
  21313. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  21314. */
  21315. THREE.CameraHelper = function ( camera ) {
  21316. var geometry = new THREE.Geometry();
  21317. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  21318. var pointMap = {};
  21319. // colors
  21320. var hexFrustum = 0xffaa00;
  21321. var hexCone = 0xff0000;
  21322. var hexUp = 0x00aaff;
  21323. var hexTarget = 0xffffff;
  21324. var hexCross = 0x333333;
  21325. // near
  21326. addLine( "n1", "n2", hexFrustum );
  21327. addLine( "n2", "n4", hexFrustum );
  21328. addLine( "n4", "n3", hexFrustum );
  21329. addLine( "n3", "n1", hexFrustum );
  21330. // far
  21331. addLine( "f1", "f2", hexFrustum );
  21332. addLine( "f2", "f4", hexFrustum );
  21333. addLine( "f4", "f3", hexFrustum );
  21334. addLine( "f3", "f1", hexFrustum );
  21335. // sides
  21336. addLine( "n1", "f1", hexFrustum );
  21337. addLine( "n2", "f2", hexFrustum );
  21338. addLine( "n3", "f3", hexFrustum );
  21339. addLine( "n4", "f4", hexFrustum );
  21340. // cone
  21341. addLine( "p", "n1", hexCone );
  21342. addLine( "p", "n2", hexCone );
  21343. addLine( "p", "n3", hexCone );
  21344. addLine( "p", "n4", hexCone );
  21345. // up
  21346. addLine( "u1", "u2", hexUp );
  21347. addLine( "u2", "u3", hexUp );
  21348. addLine( "u3", "u1", hexUp );
  21349. // target
  21350. addLine( "c", "t", hexTarget );
  21351. addLine( "p", "c", hexCross );
  21352. // cross
  21353. addLine( "cn1", "cn2", hexCross );
  21354. addLine( "cn3", "cn4", hexCross );
  21355. addLine( "cf1", "cf2", hexCross );
  21356. addLine( "cf3", "cf4", hexCross );
  21357. function addLine( a, b, hex ) {
  21358. addPoint( a, hex );
  21359. addPoint( b, hex );
  21360. }
  21361. function addPoint( id, hex ) {
  21362. geometry.vertices.push( new THREE.Vector3() );
  21363. geometry.colors.push( new THREE.Color( hex ) );
  21364. if ( pointMap[ id ] === undefined ) {
  21365. pointMap[ id ] = [];
  21366. }
  21367. pointMap[ id ].push( geometry.vertices.length - 1 );
  21368. }
  21369. THREE.LineSegments.call( this, geometry, material );
  21370. this.camera = camera;
  21371. this.matrix = camera.matrixWorld;
  21372. this.matrixAutoUpdate = false;
  21373. this.pointMap = pointMap;
  21374. this.update();
  21375. };
  21376. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21377. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  21378. THREE.CameraHelper.prototype.update = function () {
  21379. var geometry, pointMap;
  21380. var vector = new THREE.Vector3();
  21381. var camera = new THREE.Camera();
  21382. var setPoint = function ( point, x, y, z ) {
  21383. vector.set( x, y, z ).unproject( camera );
  21384. var points = pointMap[ point ];
  21385. if ( points !== undefined ) {
  21386. for ( var i = 0, il = points.length; i < il; i ++ ) {
  21387. geometry.vertices[ points[ i ] ].copy( vector );
  21388. }
  21389. }
  21390. };
  21391. return function () {
  21392. geometry = this.geometry;
  21393. pointMap = this.pointMap;
  21394. var w = 1, h = 1;
  21395. // we need just camera projection matrix
  21396. // world matrix must be identity
  21397. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  21398. // center / target
  21399. setPoint( "c", 0, 0, - 1 );
  21400. setPoint( "t", 0, 0, 1 );
  21401. // near
  21402. setPoint( "n1", - w, - h, - 1 );
  21403. setPoint( "n2", w, - h, - 1 );
  21404. setPoint( "n3", - w, h, - 1 );
  21405. setPoint( "n4", w, h, - 1 );
  21406. // far
  21407. setPoint( "f1", - w, - h, 1 );
  21408. setPoint( "f2", w, - h, 1 );
  21409. setPoint( "f3", - w, h, 1 );
  21410. setPoint( "f4", w, h, 1 );
  21411. // up
  21412. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  21413. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  21414. setPoint( "u3", 0, h * 2, - 1 );
  21415. // cross
  21416. setPoint( "cf1", - w, 0, 1 );
  21417. setPoint( "cf2", w, 0, 1 );
  21418. setPoint( "cf3", 0, - h, 1 );
  21419. setPoint( "cf4", 0, h, 1 );
  21420. setPoint( "cn1", - w, 0, - 1 );
  21421. setPoint( "cn2", w, 0, - 1 );
  21422. setPoint( "cn3", 0, - h, - 1 );
  21423. setPoint( "cn4", 0, h, - 1 );
  21424. geometry.verticesNeedUpdate = true;
  21425. };
  21426. }();
  21427. // File:src/extras/helpers/DirectionalLightHelper.js
  21428. /**
  21429. * @author alteredq / http://alteredqualia.com/
  21430. * @author mrdoob / http://mrdoob.com/
  21431. * @author WestLangley / http://github.com/WestLangley
  21432. */
  21433. THREE.DirectionalLightHelper = function ( light, size ) {
  21434. THREE.Object3D.call( this );
  21435. this.light = light;
  21436. this.light.updateMatrixWorld();
  21437. this.matrix = light.matrixWorld;
  21438. this.matrixAutoUpdate = false;
  21439. size = size || 1;
  21440. var geometry = new THREE.Geometry();
  21441. geometry.vertices.push(
  21442. new THREE.Vector3( - size, size, 0 ),
  21443. new THREE.Vector3( size, size, 0 ),
  21444. new THREE.Vector3( size, - size, 0 ),
  21445. new THREE.Vector3( - size, - size, 0 ),
  21446. new THREE.Vector3( - size, size, 0 )
  21447. );
  21448. var material = new THREE.LineBasicMaterial( { fog: false } );
  21449. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21450. this.lightPlane = new THREE.Line( geometry, material );
  21451. this.add( this.lightPlane );
  21452. geometry = new THREE.Geometry();
  21453. geometry.vertices.push(
  21454. new THREE.Vector3(),
  21455. new THREE.Vector3()
  21456. );
  21457. material = new THREE.LineBasicMaterial( { fog: false } );
  21458. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21459. this.targetLine = new THREE.Line( geometry, material );
  21460. this.add( this.targetLine );
  21461. this.update();
  21462. };
  21463. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21464. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  21465. THREE.DirectionalLightHelper.prototype.dispose = function () {
  21466. this.lightPlane.geometry.dispose();
  21467. this.lightPlane.material.dispose();
  21468. this.targetLine.geometry.dispose();
  21469. this.targetLine.material.dispose();
  21470. };
  21471. THREE.DirectionalLightHelper.prototype.update = function () {
  21472. var v1 = new THREE.Vector3();
  21473. var v2 = new THREE.Vector3();
  21474. var v3 = new THREE.Vector3();
  21475. return function () {
  21476. v1.setFromMatrixPosition( this.light.matrixWorld );
  21477. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21478. v3.subVectors( v2, v1 );
  21479. this.lightPlane.lookAt( v3 );
  21480. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21481. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  21482. this.targetLine.geometry.verticesNeedUpdate = true;
  21483. this.targetLine.material.color.copy( this.lightPlane.material.color );
  21484. };
  21485. }();
  21486. // File:src/extras/helpers/EdgesHelper.js
  21487. /**
  21488. * @author WestLangley / http://github.com/WestLangley
  21489. * @param object THREE.Mesh whose geometry will be used
  21490. * @param hex line color
  21491. * @param thresholdAngle the minimum angle (in degrees),
  21492. * between the face normals of adjacent faces,
  21493. * that is required to render an edge. A value of 10 means
  21494. * an edge is only rendered if the angle is at least 10 degrees.
  21495. */
  21496. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  21497. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21498. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  21499. this.matrix = object.matrixWorld;
  21500. this.matrixAutoUpdate = false;
  21501. };
  21502. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21503. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  21504. // File:src/extras/helpers/FaceNormalsHelper.js
  21505. /**
  21506. * @author mrdoob / http://mrdoob.com/
  21507. * @author WestLangley / http://github.com/WestLangley
  21508. */
  21509. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  21510. // FaceNormalsHelper only supports THREE.Geometry
  21511. this.object = object;
  21512. this.size = ( size !== undefined ) ? size : 1;
  21513. var color = ( hex !== undefined ) ? hex : 0xffff00;
  21514. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21515. //
  21516. var nNormals = 0;
  21517. var objGeometry = this.object.geometry;
  21518. if ( objGeometry instanceof THREE.Geometry ) {
  21519. nNormals = objGeometry.faces.length;
  21520. } else {
  21521. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  21522. }
  21523. //
  21524. var geometry = new THREE.BufferGeometry();
  21525. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21526. geometry.addAttribute( 'position', positions );
  21527. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21528. //
  21529. this.matrixAutoUpdate = false;
  21530. this.update();
  21531. };
  21532. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21533. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  21534. THREE.FaceNormalsHelper.prototype.update = ( function () {
  21535. var v1 = new THREE.Vector3();
  21536. var v2 = new THREE.Vector3();
  21537. var normalMatrix = new THREE.Matrix3();
  21538. return function update() {
  21539. this.object.updateMatrixWorld( true );
  21540. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21541. var matrixWorld = this.object.matrixWorld;
  21542. var position = this.geometry.attributes.position;
  21543. //
  21544. var objGeometry = this.object.geometry;
  21545. var vertices = objGeometry.vertices;
  21546. var faces = objGeometry.faces;
  21547. var idx = 0;
  21548. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21549. var face = faces[ i ];
  21550. var normal = face.normal;
  21551. v1.copy( vertices[ face.a ] )
  21552. .add( vertices[ face.b ] )
  21553. .add( vertices[ face.c ] )
  21554. .divideScalar( 3 )
  21555. .applyMatrix4( matrixWorld );
  21556. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21557. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21558. idx = idx + 1;
  21559. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21560. idx = idx + 1;
  21561. }
  21562. position.needsUpdate = true;
  21563. return this;
  21564. }
  21565. }() );
  21566. // File:src/extras/helpers/GridHelper.js
  21567. /**
  21568. * @author mrdoob / http://mrdoob.com/
  21569. */
  21570. THREE.GridHelper = function ( size, step ) {
  21571. var geometry = new THREE.Geometry();
  21572. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21573. this.color1 = new THREE.Color( 0x444444 );
  21574. this.color2 = new THREE.Color( 0x888888 );
  21575. for ( var i = - size; i <= size; i += step ) {
  21576. geometry.vertices.push(
  21577. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  21578. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  21579. );
  21580. var color = i === 0 ? this.color1 : this.color2;
  21581. geometry.colors.push( color, color, color, color );
  21582. }
  21583. THREE.LineSegments.call( this, geometry, material );
  21584. };
  21585. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21586. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  21587. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  21588. this.color1.set( colorCenterLine );
  21589. this.color2.set( colorGrid );
  21590. this.geometry.colorsNeedUpdate = true;
  21591. };
  21592. // File:src/extras/helpers/HemisphereLightHelper.js
  21593. /**
  21594. * @author alteredq / http://alteredqualia.com/
  21595. * @author mrdoob / http://mrdoob.com/
  21596. */
  21597. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  21598. THREE.Object3D.call( this );
  21599. this.light = light;
  21600. this.light.updateMatrixWorld();
  21601. this.matrix = light.matrixWorld;
  21602. this.matrixAutoUpdate = false;
  21603. this.colors = [ new THREE.Color(), new THREE.Color() ];
  21604. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21605. geometry.rotateX( - Math.PI / 2 );
  21606. for ( var i = 0, il = 8; i < il; i ++ ) {
  21607. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21608. }
  21609. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21610. this.lightSphere = new THREE.Mesh( geometry, material );
  21611. this.add( this.lightSphere );
  21612. this.update();
  21613. };
  21614. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21615. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21616. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21617. this.lightSphere.geometry.dispose();
  21618. this.lightSphere.material.dispose();
  21619. };
  21620. THREE.HemisphereLightHelper.prototype.update = function () {
  21621. var vector = new THREE.Vector3();
  21622. return function () {
  21623. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21624. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21625. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21626. this.lightSphere.geometry.colorsNeedUpdate = true;
  21627. }
  21628. }();
  21629. // File:src/extras/helpers/PointLightHelper.js
  21630. /**
  21631. * @author alteredq / http://alteredqualia.com/
  21632. * @author mrdoob / http://mrdoob.com/
  21633. */
  21634. THREE.PointLightHelper = function ( light, sphereSize ) {
  21635. this.light = light;
  21636. this.light.updateMatrixWorld();
  21637. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21638. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21639. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21640. THREE.Mesh.call( this, geometry, material );
  21641. this.matrix = this.light.matrixWorld;
  21642. this.matrixAutoUpdate = false;
  21643. /*
  21644. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21645. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21646. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21647. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21648. var d = light.distance;
  21649. if ( d === 0.0 ) {
  21650. this.lightDistance.visible = false;
  21651. } else {
  21652. this.lightDistance.scale.set( d, d, d );
  21653. }
  21654. this.add( this.lightDistance );
  21655. */
  21656. };
  21657. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21658. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21659. THREE.PointLightHelper.prototype.dispose = function () {
  21660. this.geometry.dispose();
  21661. this.material.dispose();
  21662. };
  21663. THREE.PointLightHelper.prototype.update = function () {
  21664. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21665. /*
  21666. var d = this.light.distance;
  21667. if ( d === 0.0 ) {
  21668. this.lightDistance.visible = false;
  21669. } else {
  21670. this.lightDistance.visible = true;
  21671. this.lightDistance.scale.set( d, d, d );
  21672. }
  21673. */
  21674. };
  21675. // File:src/extras/helpers/SkeletonHelper.js
  21676. /**
  21677. * @author Sean Griffin / http://twitter.com/sgrif
  21678. * @author Michael Guerrero / http://realitymeltdown.com
  21679. * @author mrdoob / http://mrdoob.com/
  21680. * @author ikerr / http://verold.com
  21681. */
  21682. THREE.SkeletonHelper = function ( object ) {
  21683. this.bones = this.getBoneList( object );
  21684. var geometry = new THREE.Geometry();
  21685. for ( var i = 0; i < this.bones.length; i ++ ) {
  21686. var bone = this.bones[ i ];
  21687. if ( bone.parent instanceof THREE.Bone ) {
  21688. geometry.vertices.push( new THREE.Vector3() );
  21689. geometry.vertices.push( new THREE.Vector3() );
  21690. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21691. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21692. }
  21693. }
  21694. geometry.dynamic = true;
  21695. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21696. THREE.LineSegments.call( this, geometry, material );
  21697. this.root = object;
  21698. this.matrix = object.matrixWorld;
  21699. this.matrixAutoUpdate = false;
  21700. this.update();
  21701. };
  21702. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21703. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21704. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21705. var boneList = [];
  21706. if ( object instanceof THREE.Bone ) {
  21707. boneList.push( object );
  21708. }
  21709. for ( var i = 0; i < object.children.length; i ++ ) {
  21710. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21711. }
  21712. return boneList;
  21713. };
  21714. THREE.SkeletonHelper.prototype.update = function () {
  21715. var geometry = this.geometry;
  21716. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21717. var boneMatrix = new THREE.Matrix4();
  21718. var j = 0;
  21719. for ( var i = 0; i < this.bones.length; i ++ ) {
  21720. var bone = this.bones[ i ];
  21721. if ( bone.parent instanceof THREE.Bone ) {
  21722. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21723. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21724. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21725. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21726. j += 2;
  21727. }
  21728. }
  21729. geometry.verticesNeedUpdate = true;
  21730. geometry.computeBoundingSphere();
  21731. };
  21732. // File:src/extras/helpers/SpotLightHelper.js
  21733. /**
  21734. * @author alteredq / http://alteredqualia.com/
  21735. * @author mrdoob / http://mrdoob.com/
  21736. * @author WestLangley / http://github.com/WestLangley
  21737. */
  21738. THREE.SpotLightHelper = function ( light ) {
  21739. THREE.Object3D.call( this );
  21740. this.light = light;
  21741. this.light.updateMatrixWorld();
  21742. this.matrix = light.matrixWorld;
  21743. this.matrixAutoUpdate = false;
  21744. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21745. geometry.translate( 0, - 0.5, 0 );
  21746. geometry.rotateX( - Math.PI / 2 );
  21747. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21748. this.cone = new THREE.Mesh( geometry, material );
  21749. this.add( this.cone );
  21750. this.update();
  21751. };
  21752. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21753. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21754. THREE.SpotLightHelper.prototype.dispose = function () {
  21755. this.cone.geometry.dispose();
  21756. this.cone.material.dispose();
  21757. };
  21758. THREE.SpotLightHelper.prototype.update = function () {
  21759. var vector = new THREE.Vector3();
  21760. var vector2 = new THREE.Vector3();
  21761. return function () {
  21762. var coneLength = this.light.distance ? this.light.distance : 10000;
  21763. var coneWidth = coneLength * Math.tan( this.light.angle );
  21764. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21765. vector.setFromMatrixPosition( this.light.matrixWorld );
  21766. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21767. this.cone.lookAt( vector2.sub( vector ) );
  21768. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21769. };
  21770. }();
  21771. // File:src/extras/helpers/VertexNormalsHelper.js
  21772. /**
  21773. * @author mrdoob / http://mrdoob.com/
  21774. * @author WestLangley / http://github.com/WestLangley
  21775. */
  21776. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21777. this.object = object;
  21778. this.size = ( size !== undefined ) ? size : 1;
  21779. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21780. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21781. //
  21782. var nNormals = 0;
  21783. var objGeometry = this.object.geometry;
  21784. if ( objGeometry instanceof THREE.Geometry ) {
  21785. nNormals = objGeometry.faces.length * 3;
  21786. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21787. nNormals = objGeometry.attributes.normal.count
  21788. }
  21789. //
  21790. var geometry = new THREE.BufferGeometry();
  21791. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21792. geometry.addAttribute( 'position', positions );
  21793. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21794. //
  21795. this.matrixAutoUpdate = false;
  21796. this.update();
  21797. };
  21798. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21799. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21800. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21801. var v1 = new THREE.Vector3();
  21802. var v2 = new THREE.Vector3();
  21803. var normalMatrix = new THREE.Matrix3();
  21804. return function update() {
  21805. var keys = [ 'a', 'b', 'c' ];
  21806. this.object.updateMatrixWorld( true );
  21807. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21808. var matrixWorld = this.object.matrixWorld;
  21809. var position = this.geometry.attributes.position;
  21810. //
  21811. var objGeometry = this.object.geometry;
  21812. if ( objGeometry instanceof THREE.Geometry ) {
  21813. var vertices = objGeometry.vertices;
  21814. var faces = objGeometry.faces;
  21815. var idx = 0;
  21816. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21817. var face = faces[ i ];
  21818. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21819. var vertex = vertices[ face[ keys[ j ] ] ];
  21820. var normal = face.vertexNormals[ j ];
  21821. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21822. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21823. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21824. idx = idx + 1;
  21825. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21826. idx = idx + 1;
  21827. }
  21828. }
  21829. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21830. var objPos = objGeometry.attributes.position;
  21831. var objNorm = objGeometry.attributes.normal;
  21832. var idx = 0;
  21833. // for simplicity, ignore index and drawcalls, and render every normal
  21834. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21835. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21836. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21837. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21838. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21839. idx = idx + 1;
  21840. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21841. idx = idx + 1;
  21842. }
  21843. }
  21844. position.needsUpdate = true;
  21845. return this;
  21846. }
  21847. }() );
  21848. // File:src/extras/helpers/WireframeHelper.js
  21849. /**
  21850. * @author mrdoob / http://mrdoob.com/
  21851. */
  21852. THREE.WireframeHelper = function ( object, hex ) {
  21853. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21854. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21855. this.matrix = object.matrixWorld;
  21856. this.matrixAutoUpdate = false;
  21857. };
  21858. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21859. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21860. // File:src/extras/objects/ImmediateRenderObject.js
  21861. /**
  21862. * @author alteredq / http://alteredqualia.com/
  21863. */
  21864. THREE.ImmediateRenderObject = function ( material ) {
  21865. THREE.Object3D.call( this );
  21866. this.material = material;
  21867. this.render = function ( renderCallback ) {};
  21868. };
  21869. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21870. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21871. // File:src/extras/objects/MorphBlendMesh.js
  21872. /**
  21873. * @author alteredq / http://alteredqualia.com/
  21874. */
  21875. THREE.MorphBlendMesh = function( geometry, material ) {
  21876. THREE.Mesh.call( this, geometry, material );
  21877. this.animationsMap = {};
  21878. this.animationsList = [];
  21879. // prepare default animation
  21880. // (all frames played together in 1 second)
  21881. var numFrames = this.geometry.morphTargets.length;
  21882. var name = "__default";
  21883. var startFrame = 0;
  21884. var endFrame = numFrames - 1;
  21885. var fps = numFrames / 1;
  21886. this.createAnimation( name, startFrame, endFrame, fps );
  21887. this.setAnimationWeight( name, 1 );
  21888. };
  21889. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21890. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21891. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21892. var animation = {
  21893. start: start,
  21894. end: end,
  21895. length: end - start + 1,
  21896. fps: fps,
  21897. duration: ( end - start ) / fps,
  21898. lastFrame: 0,
  21899. currentFrame: 0,
  21900. active: false,
  21901. time: 0,
  21902. direction: 1,
  21903. weight: 1,
  21904. directionBackwards: false,
  21905. mirroredLoop: false
  21906. };
  21907. this.animationsMap[ name ] = animation;
  21908. this.animationsList.push( animation );
  21909. };
  21910. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21911. var pattern = /([a-z]+)_?(\d+)/;
  21912. var firstAnimation, frameRanges = {};
  21913. var geometry = this.geometry;
  21914. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21915. var morph = geometry.morphTargets[ i ];
  21916. var chunks = morph.name.match( pattern );
  21917. if ( chunks && chunks.length > 1 ) {
  21918. var name = chunks[ 1 ];
  21919. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21920. var range = frameRanges[ name ];
  21921. if ( i < range.start ) range.start = i;
  21922. if ( i > range.end ) range.end = i;
  21923. if ( ! firstAnimation ) firstAnimation = name;
  21924. }
  21925. }
  21926. for ( var name in frameRanges ) {
  21927. var range = frameRanges[ name ];
  21928. this.createAnimation( name, range.start, range.end, fps );
  21929. }
  21930. this.firstAnimation = firstAnimation;
  21931. };
  21932. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21933. var animation = this.animationsMap[ name ];
  21934. if ( animation ) {
  21935. animation.direction = 1;
  21936. animation.directionBackwards = false;
  21937. }
  21938. };
  21939. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21940. var animation = this.animationsMap[ name ];
  21941. if ( animation ) {
  21942. animation.direction = - 1;
  21943. animation.directionBackwards = true;
  21944. }
  21945. };
  21946. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21947. var animation = this.animationsMap[ name ];
  21948. if ( animation ) {
  21949. animation.fps = fps;
  21950. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21951. }
  21952. };
  21953. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21954. var animation = this.animationsMap[ name ];
  21955. if ( animation ) {
  21956. animation.duration = duration;
  21957. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21958. }
  21959. };
  21960. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21961. var animation = this.animationsMap[ name ];
  21962. if ( animation ) {
  21963. animation.weight = weight;
  21964. }
  21965. };
  21966. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21967. var animation = this.animationsMap[ name ];
  21968. if ( animation ) {
  21969. animation.time = time;
  21970. }
  21971. };
  21972. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21973. var time = 0;
  21974. var animation = this.animationsMap[ name ];
  21975. if ( animation ) {
  21976. time = animation.time;
  21977. }
  21978. return time;
  21979. };
  21980. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21981. var duration = - 1;
  21982. var animation = this.animationsMap[ name ];
  21983. if ( animation ) {
  21984. duration = animation.duration;
  21985. }
  21986. return duration;
  21987. };
  21988. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21989. var animation = this.animationsMap[ name ];
  21990. if ( animation ) {
  21991. animation.time = 0;
  21992. animation.active = true;
  21993. } else {
  21994. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21995. }
  21996. };
  21997. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21998. var animation = this.animationsMap[ name ];
  21999. if ( animation ) {
  22000. animation.active = false;
  22001. }
  22002. };
  22003. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  22004. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  22005. var animation = this.animationsList[ i ];
  22006. if ( ! animation.active ) continue;
  22007. var frameTime = animation.duration / animation.length;
  22008. animation.time += animation.direction * delta;
  22009. if ( animation.mirroredLoop ) {
  22010. if ( animation.time > animation.duration || animation.time < 0 ) {
  22011. animation.direction *= - 1;
  22012. if ( animation.time > animation.duration ) {
  22013. animation.time = animation.duration;
  22014. animation.directionBackwards = true;
  22015. }
  22016. if ( animation.time < 0 ) {
  22017. animation.time = 0;
  22018. animation.directionBackwards = false;
  22019. }
  22020. }
  22021. } else {
  22022. animation.time = animation.time % animation.duration;
  22023. if ( animation.time < 0 ) animation.time += animation.duration;
  22024. }
  22025. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  22026. var weight = animation.weight;
  22027. if ( keyframe !== animation.currentFrame ) {
  22028. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  22029. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  22030. this.morphTargetInfluences[ keyframe ] = 0;
  22031. animation.lastFrame = animation.currentFrame;
  22032. animation.currentFrame = keyframe;
  22033. }
  22034. var mix = ( animation.time % frameTime ) / frameTime;
  22035. if ( animation.directionBackwards ) mix = 1 - mix;
  22036. if ( animation.currentFrame !== animation.lastFrame ) {
  22037. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  22038. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  22039. } else {
  22040. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  22041. }
  22042. }
  22043. };